1: /*
     2:  ============================================================================
     3:  xoblite™ -> an advanced "extended shell" for Microsoft® Windows® 11
     4:  Copyright © 2002-2026 Karl Henrik Henriksson [qwilk/@xoblite]
     5:  Copyright © 2001-2004 The Blackbox for Windows Development Team
     6:  http://xoblite.net/ + https://github.com/xoblite/
     7:  ============================================================================
     8: 
     9:   Blackbox for Windows is free software, released under the
    10:   GNU General Public License (GPL version 2 or later), with an extension
    11:   that allows linking of proprietary modules under a controlled interface.
    12:   What this means is that plugins etc. are allowed to be released
    13:   under any license the author wishes. Please note, however, that the
    14:   original Blackbox gradient math code used in Blackbox for Windows
    15:   is available under the BSD license.
    16: 
    17:   http://www.fsf.org/licenses/gpl.html
    18:   http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
    19:   http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
    20: 
    21:   This program is distributed in the hope that it will be useful,
    22:   but WITHOUT ANY WARRANTY; without even the implied warranty of
    23:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    24:   GNU General Public License for more details.
    25: 
    26:   For additional license information, please read the included license.html.
    27: 
    28:  ============================================================================
    29: */
    30: 
    31: #ifndef __MENUITEM_H 
    32: #define __MENUITEM_H 
    33: 
    34: #include "..\API\BBApi.h" 
    35: 
    36: //===========================================================================
    37: 
    38: #define MENUITEM_HEADER 0       // Menu header == title item (only one per menu -> at the top of the list of items) 
    39: #define MENUITEM_MARGINPAD 1    // Menu marginWidth padding items (two per menu -> below header and above footer) 
    40: #define MENUITEM_FOOTER 2       // Menu footer/grip item (only one per menu -> at the bottom of the list of items) 
    41: 
    42: #define MENUITEM_COMMAND 3      // Regular menu items executing different commands 
    43: #define MENUITEM_EDITSTRING 4   // Menu string editing items (see StringItem.cpp/h) 
    44: #define MENUITEM_EDITINT 5      // Menu integer editing items 
    45: #define MENUITEM_BOOLEAN 6      // Menu boolean editing items (parsed as normal commands + indicator) 
    46: #define MENUITEM_NOP 7          // Menu NOP items (i.e. no command or hilite/active on mouseover) 
    47: #define MENUITEM_SEPARATOR 8    // Menu separator items (lower height than regular items, no hilite/active on mouseover) 
    48: #define MENUITEM_FOLDER 9       // Menu folder items 
    49: 
    50: //====================
    51: 
    52: // Priority when sorting menu items
    53: #define PRIORITY_HEADER 255 
    54: #define PRIORITY_MARGINPAD_TOP 254 
    55: #define PRIORITY_FOLDER 4 
    56: #define PRIORITY_SEPARATOR 3 
    57: #define PRIORITY_NORMAL 2 
    58: #define PRIORITY_MARGINPAD_BOTTOM 1 
    59: #define PRIORITY_FOOTER 0 
    60: 
    61: // Menu item group (used for item selection within a mutually exclusive group of items)
    62: #define GROUP_DEFAULT 0 
    63: 
    64: //===========================================================================
    65: 
    66: class MenuItem
    67: {
    68: public:
    69:     MenuItem(int type, char* pszTitleANSI, wchar_t* pszTitleUnicode, char* pszCommand, char* pszArgument, bool isSelected);
    70:     virtual ~MenuItem();
    71: 
    72:     virtual LRESULT NcHitTest(int x, int y);
    73:     int IsOver(int x, int y);
    74:     virtual void Mouse(UINT nMsg, POINT pt);
    75:     virtual void Invoke(int button);
    76:     virtual bool Active(bool bActive);
    77:     virtual bool IsActive() { return m_bActive; };
    78: 
    79:     virtual char* GetSortString() { return m_pszTitleANSI; };
    80: 
    81:     virtual void GetItemRect(RECT* r);
    82:     virtual void GetTitleRect(RECT* r);
    83: 
    84:     virtual UINT GetDrawTextFormat();
    85: 
    86:     virtual void SetTitleANSI(char* pszTitleANSI);
    87:     virtual void SetTitleUnicode(wchar_t* pszTitleUnicode);
    88: 
    89:     void AddToSelectionGroup(int group);
    90: 
    91:     //====================
    92: 
    93:     char* m_pszTitleANSI;
    94:     wchar_t* m_pszTitleUnicode;
    95:     int itemType;
    96: 
    97:     char* m_pszCommand;
    98:     char* m_pszArgument;
    99:     char* m_pszOriginalTitleANSI;
   100:     wchar_t* m_pszOriginalTitleUnicode;
   101:     bool m_isSelected;
   102:     int m_selectionGroup;
   103: 
   104:     int m_currentValue;
   105:     int m_minValue;
   106:     int m_maxValue;
   107: 
   108:     //====================
   109: 
   110:     // Timer callback, used by menu items that implement anumation or
   111:     // various waiting. examples are the TimeItem, FolderItem
   112:     // @param nTimer the identity of the timer that caused the callback
   113:     void ItemSetTimer();
   114:     virtual void Timer(int nTimer);
   115:     void ItemKillTimer();
   116: 
   117:     //====================
   118: 
   119:     virtual inline void SetWidth(int nWidth) { m_nWidth = nWidth; };
   120:     virtual inline int GetWidth() { return m_nWidth; };
   121:     virtual inline void SetHeight(int nHeight) { m_nHeight = nHeight; };
   122:     virtual inline int GetHeight() { return m_nHeight; };
   123: 
   124:     // Tells the object where it is located in client coordinates
   125:     virtual void SetPosition(int nLeft, int nTop) { m_nLeft = nLeft; m_nTop = nTop; };
   126: 
   127:     //====================
   128: 
   129:     // Sets the priority this menu item has when it is compared with other menuitems
   130:     // @param nSortPriority the sort priority
   131:     virtual void SetSortPriority(int nSortPriority) { m_nSortPriority = nSortPriority; };
   132: 
   133:     // Returns the priority this menu item has when it is compared with other menuitems
   134:     // @return the sort priority
   135:     virtual int GetSortPriority() { return m_nSortPriority; };
   136: 
   137:     // Compares two menu items pM1 and pM2 and returns
   138:     // 'true' if pM1 is 'larger' than pM2, otherwise 'false'
   139:     static bool Compare(MenuItem* pM1, MenuItem* pM2);
   140: 
   141:     //====================
   142: 
   143:     // This item has been connected to a popup menu this happens _once_ during 
   144:     // the lifetime of the object
   145:     // @param pMenu pointer to the popupmenu object that this menuitem is connected to
   146:     virtual void Attached(Menu* pMenu);
   147: 
   148:     // Handles WM_COMMAND messages
   149:     virtual LRESULT Command(WPARAM wParam, LPARAM lParam);
   150:     // Handle messages in the WM_USER range
   151:     virtual bool OnUser(int nMessage, WPARAM wParam, LPARAM lParam, LRESULT &lResult) { return false; }
   152: 
   153:     // Sets the activation state of this menu item. The resulting activation 
   154:     // state is returned. If this method returns false then it is impossible
   155:     // to activate the menu item (TimeItem, Separatir, header,..)
   156:     // @param bActive the new activation state
   157:     // @return the resulting activation state, may be different than bActive
   158: //  virtual bool Active(bool bActive);
   159: 
   160:     // Returns the current activation state of this menu item
   161: //  virtual bool IsActive() {return m_bActive;};
   162: 
   163:     // Notifies the menu item that the menu is moving
   164:     virtual void Moving() {;};
   165: 
   166:     // Returns handle to the window that is associated with this menu item.
   167:     // NULL if there is no such window
   168:     // @return the window handle to this menu item
   169:     virtual HWND GetWindow();
   170: 
   171:     // Toggles selection (m_isSelected) for the menu item
   172:     void ToggleSelected();
   173: 
   174:     //====================
   175: 
   176:     POINT m_mousePos;       // Mouse pointer position on last click
   177: 
   178:     int m_nSortPriority;    // Constant used when determining the menu item location compared to other menu items
   179: 
   180:     Menu* m_pParent;        // menu that this item belongs to
   181:     Menu* m_pSubMenu;       // submenu belonging to this item (FolderItem's only)
   182: 
   183:     int m_nLeft;            // x location of the menu item
   184:     int m_nTop;             // y location of the menu item
   185:     int m_nWidth;           // width of the menu item
   186:     int m_nHeight;          // height of the menu item
   187: 
   188:     bool m_bActive;         // current active status of the menu item
   189: 
   190:     UINT m_nTimerId;        // The current timer ID, 0 if not currently used
   191: 
   192:     int m_nLastMouseButton; // The last mouse button message that was received
   193: };
   194: 
   195: //===========================================================================
   196: 
   197: #endif /* __MENUITEM_H */ 
   198: