menu.cpp

来自「ncbi源码」· C++ 代码 · 共 221 行

CPP
221
字号
/* * =========================================================================== * PRODUCTION $Log: menu.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:09:08  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//*  $Id: menu.cpp,v 1000.1 2004/06/01 21:09:08 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Andrey Yazhuk *   */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <FL/Fl.H>#include <FL/fl_draw.H>//####include <FL/Fl_BMP_Image.H>#include <gui/widgets/fl/menu.hpp>BEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////////// class CMenuBaseCMenuBase::CMenuBase():   m_CmdTarget(NULL){}                 CMenuBase::~CMenuBase(){}void    CMenuBase::SetCmdTarget(CCommandTarget* target){    m_CmdTarget = target;}CCommandTarget*    CMenuBase::GetCmdTarget(){    return m_CmdTarget;}bool    CMenuBase::x_CreateFLTKMenu(const string& submenu_path, CMenuItem* submenu){    if(submenu  &&  submenu->IsSubmenu())    {        CMenuItem   *item = NULL, *next = NULL;        string path;        for(CMenuItem::TChildItem_I it = submenu->SubItemsBegin();            it != submenu->SubItemsEnd(); )    {            item = (*it)->GetValue();            ++it;            next = (it != submenu->SubItemsEnd()) ? (*it)->GetValue() : NULL;                        _ASSERT(item->IsValid());            bool b_skip = item->IsSeparator()  ||                              (item->IsSubmenu()  &&  item->IsSubmenuEmpty() /* &&                            (item->GetState() & CMenuItem::eHideIfEmpty) != 0*/ );            if(! b_skip)   { // create FLTK item                int fltk_flags = 0;                path = submenu_path;                if(path.size()) {                    path += '/';                }                path += item->GetLabel();                fltk_flags |= (next  &&  next->IsSeparator()) ? FL_MENU_DIVIDER : 0;                                if(item->IsCheckType()) {                    fltk_flags |= FL_MENU_TOGGLE;                    if(item->IsChecked())   {                        fltk_flags |= FL_MENU_VALUE;                    }                } else if(item->IsRadioType())  {                    fltk_flags |= FL_MENU_RADIO;                    if(item->IsChecked())   {                        fltk_flags |= FL_MENU_VALUE;                    }                }                                fltk_flags |= item->IsEnabled() ? 0 : FL_MENU_INACTIVE;                fltk_flags |= item->IsSubmenu() ? FL_SUBMENU : 0;                                x_AddFLTKItem(path, 0, & item->GetCommand(), fltk_flags);                if(item->IsSubmenu())   {                    x_CreateFLTKMenu(path, item);                }            }         }        return true;    } else return false;}////////////////////////////////////////////////////////////////////////////////// class CMenuBar CMenuBar::CMenuBar(int x, int y, int w, int h, const char *label):   Fl_Menu_Bar(x, y, w, h, label){    textfont(FL_HELVETICA);    textsize(12);     }/// Creates a menu described by array of SMenuItem-s. CMenuBar creates a separate/// copy of a menu, so that it can be modified at run-time.void    CMenuBar::SetItems(const SMenuItemRec* items){    clear();    CMenuItem* root = CreateMenuItems(items);    x_CreateFLTKMenu("", root);}void    CMenuBar::SetItems(CMenuItem* rootitem){    clear();    CMenuBase::x_CreateFLTKMenu("", rootitem);}void    CMenuBar::x_AddFLTKItem(const string& path, ulong shortcut,                                 const TCmdID* p_cmd, int flags){    add(path.c_str(), shortcut, CMD_TARGET_FL_CALLBACK(),(void*) p_cmd, flags);}////////////////////////////////////////////////////////////////////////////////// class CPopupMenuCPopupMenu::CPopupMenu(int x, int y, int w, int h, const char *label):   Fl_Menu_Button(x, y, w, h, label){    x_Init();}    void    CPopupMenu::x_Init(){    type(Fl_Menu_Button::POPUP3);    box(FL_NO_BOX);    textfont(FL_HELVETICA);    textsize(12);     }void    CPopupMenu::SetItems(const SMenuItemRec* items){    clear();    CMenuItem* root = CreateMenuItems(items);    x_CreateFLTKMenu("", root);}void    CPopupMenu::SetItems(CMenuItem* rootitem){    clear();    CMenuBase::x_CreateFLTKMenu("", rootitem);}void    CPopupMenu::x_AddFLTKItem(const string& path, ulong shortcut,                                 const TCmdID* p_cmd, int flags){    add(path.c_str(), shortcut, CMD_TARGET_FL_CALLBACK(),(void*) p_cmd, flags);}END_NCBI_SCOPE/* * =========================================================================== * $Log: menu.cpp,v $ * Revision 1000.1  2004/06/01 21:09:08  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * * Revision 1.5  2004/05/21 22:27:53  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.4  2004/05/13 17:30:48  yazhuk * Removed eHideIfEmpty support * * Revision 1.3  2004/04/22 16:57:29  yazhuk * Moved CMenuItem to menu_item.cpp * * Revision 1.2  2004/02/04 20:00:17  yazhuk * Moved CMenuBar constructor from hpp file, changed font * * Revision 1.1  2004/01/15 20:08:27  yazhuk * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?