menu_item.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: menu_item.hpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 19:56:32 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.5
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_WIDGETS_FL___MENU_ITEM__HPP
- #define GUI_WIDGETS_FL___MENU_ITEM__HPP
- /* $Id: menu_item.hpp,v 1000.0 2004/06/01 19:56:32 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
- *
- */
- /// @file menu_item.hpp
-
- #include <corelib/ncbistd.hpp>
- #include <corelib/ncbi_tree.hpp>
- #include <gui/utils/command.hpp>
- #include <gui/widgets/fl/resource_manager.hpp>
- #include <FL/Fl_Menu_.H>
- #include <FL/Fl_Menu_Item.H>
- #include <FL/Fl_Image.H>
- /** @addtogroup GUI_FltkWidgets
- *
- * @{
- */
- BEGIN_NCBI_SCOPE
- struct SMenuItemRecRec;
- ////////////////////////////////////////////////////////////////////////////////
- /// CMenuItem - represents a menu items in IMenu-style menus.
- class NCBI_GUIWIDGETS_FL_EXPORT CMenuItem
- {
- public:
- /// Type of menu item
- enum EType {
- eItem, // command item (includes "checkbox" and "radio" items)
- eSubmenu,
- eSeparator,
- };
- /// State and subtype of menu item
- enum EState {
- eDefault = 0,
- eDisabled = 0x1, /// item is disabled (visible but inactive)
- eCheckItem = 0x2, /// "check-box" item
- eRadioItem = 0x4, /// "radio" item
- eSet = 0x8 /// indicates that chekbox is checked or radio item is selected
- // eHideIfEmpty = 0x10, /// hide submenu if it doesn't have subitems
- };
- protected:
- typedef CTreeNode<CMenuItem*> TItemNode;
- public:
- /// creates a separator item
- CMenuItem();
- /// creates a submenu item
- CMenuItem(const string& label, const string& image_alias = "");
-
- /// creates a command item
- CMenuItem(const string& label, TCmdID cmd, const string& image_alias = "", int state = eDefault);
-
- /// generic constructor, can be used to create any type of menuitem
- CMenuItem(EType type, const string& label = "", TCmdID cmd = eCmdNone,
- const string& image_alias = "", int state = eDefault);
- /// copy contsructor - copies attributes but not subitems
- CMenuItem(const CMenuItem& item);
-
- virtual ~CMenuItem();
-
- void Init(EType type, const string& label = "", TCmdID cmd = eCmdNone,
- const string& image_alias = "", int state = eDefault);
- void InitPopup(const string& label, const string& image_alias = "");
- void InitItem(const string& label, TCmdID cmd, const string& image_alias = "", int state = eDefault);
- void InitSeparator();
-
- bool Equal(const CMenuItem& item) const;
- /// clones item and its subitems
- CMenuItem* Clone() const;
- EType GetType() const;
- void SetType(EType type);
- bool IsItem() const;
- bool IsSubmenu() const;
- bool IsSeparator() const;
-
- const string& GetLabel() const;
- void SetLabel(const string& label);
-
- const TCmdID& GetCommand() const;
- void SetCommand(TCmdID cmd);
-
- bool HasImage() const;
- const string& GetImageAlias() const;
- void SetImageAlias(const string& image_alias);
- int GetState() const;
- void SetState(int state) ;
-
- bool IsEnabled() const;
- void Enable(bool b_en);
- bool IsCheckType() const;
- bool IsChecked() const;
- void SetCheck(bool b_set);
- bool IsRadioType() const;
- bool IsRadioSelected() const;
- void SelectRadio(bool b_set);
- bool IsValid() const;
- bool IsEnabledItem() const { return IsEnabled() && IsItem(); }
- bool IsEnabledSubmenu() const { return IsEnabled() && IsSubmenu(); }
- /// merges menu tree represented by "item" into menu tree represented by "this"
- void Merge(const CMenuItem& item);
- public:
- typedef TItemNode::TNodeList_I TChildItem_I;
- typedef TItemNode::TNodeList_CI TChildItem_CI;
-
- /// @name Operations with submenus
- /// @{
- CMenuItem* GetParent();
- const CMenuItem* GetParent() const;
-
- CMenuItem* AddSubItem(CMenuItem* item);
-
- /// adds separator
- CMenuItem* AddSubItem();
-
- /// adds submenu
- CMenuItem* AddSubMenu(const string& Label, const string& image_alias = "");
-
- /// adds command subitem
- CMenuItem* AddSubItem(const string& label, TCmdID cmd, const string& image_alias = "", int state = eDefault);
- bool IsSubmenuEmpty();
- TChildItem_I SubItemsBegin();
- TChildItem_I SubItemsEnd();
- TChildItem_CI SubItemsBegin() const;
- TChildItem_CI SubItemsEnd() const;
- CMenuItem* FindEqualSubItem(const CMenuItem& item);
- const CMenuItem* FindEqualSubItem(const CMenuItem& item) const;
- TChildItem_I FindSubItem(const CMenuItem& item);
- TChildItem_CI FindSubItem(const CMenuItem& item) const;
- TChildItem_I FindSubItem(const string& label);
- TChildItem_CI FindSubItem(const string& label) const;
- /// @}
- protected:
- inline void x_SetState(int mask, bool b_en)
- {
- if(b_en) {
- m_State |= mask;
- } else {
- m_State &= ~mask;
- }
- }
- inline void x_SetState(int mask, int values)
- {
- m_State &= ~mask;
- m_State |= values;
- }
- private:
- EType m_Type;
- string m_Label;
- TCmdID m_CommandID;
- string m_ImageAlias;
- int m_State;
-
- TItemNode m_ItemNode;
- };
- ////////////////////////////////////////////////////////////////////////////////
- ///
- struct NCBI_GUIWIDGETS_FL_EXPORT SMenuItemRec
- {
- int m_Type;
- const char* m_Label;
- TCmdID m_CommandID;
- const char* m_ImageAlias;
- int m_State;
- bool IsSubMenu() const
- {
- return m_Type == CMenuItem::eSubmenu && m_CommandID == eCmdNone;
- }
- bool IsSubMenuEnd() const
- {
- return m_Type == CMenuItem::eSubmenu && m_CommandID == eCmdInvalid;
- }
- };
- /// creates CMenuItem hierarchy from an array of SMenuItemRecRec
- NCBI_GUIWIDGETS_FL_EXPORT CMenuItem* CreateMenuItems(const SMenuItemRec* items);
- #define DEFINE_MENU(name)
- const SMenuItemRec name[] =
- { SUBMENU("Root")
- #define MENU_ITEM(cmd, label)
- { CMenuItem::eItem, label, cmd, "", CMenuItem::eDefault},
- #define MENU_ITEM_IM(cmd, label, image)
- { CMenuItem::eItem, label, cmd, image, CMenuItem::eDefault},
- #define MENU_SEPARATOR()
- { CMenuItem::eSeparator, "", eCmdNone, "", CMenuItem::eDefault},
- #define SUBMENU(label)
- { CMenuItem::eSubmenu, label, eCmdNone, "", CMenuItem::eDefault},
- #define SUBMENU_IM(label, image)
- { CMenuItem::eSubmenu, label, eCmdNone, image, CMenuItem::eDefault},
- #define END_SUBMENU()
- { CMenuItem::eSubmenu, "", eCmdInvalid, "", CMenuItem::eDefault},
- #define END_MENU()
- { CMenuItem::eSubmenu, "", eCmdInvalid, "", CMenuItem::eDefault},
- };
- END_NCBI_SCOPE
- /* @} */
- /*
- * ===========================================================================
- * $Log: menu_item.hpp,v $
- * Revision 1000.0 2004/06/01 19:56:32 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.5
- *
- * Revision 1.5 2004/05/13 17:30:02 yazhuk
- * Commented out eHideIfEmpty flag
- *
- * Revision 1.4 2004/05/11 18:55:14 dicuccio
- * Added doxygen modules info
- *
- * Revision 1.3 2004/05/07 14:18:28 yazhuk
- * Added Merge(), FindSubItem(string)
- *
- * Revision 1.2 2004/05/03 19:43:32 yazhuk
- * Refactoring
- *
- * Revision 1.1 2004/04/22 16:53:18 yazhuk
- * Initial revision: menu_window.hpp
- *
- * ===========================================================================
- */
- #endif // GUI_WIDGETS_FL___MENU_ITEM__HPP