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 __MENU_H 
    32: #define __MENU_H 
    33: 
    34: #include "MenuItem.h" 
    35: #include <windows.h> 
    36: #include <vector> 
    37: 
    38: #define HIDE_OTHERS 2 
    39: #define HIDE_CHILDREN 1 
    40: #define HIDE_THIS 0 
    41: #define HIDE_PARENTS  -1 
    42: 
    43: #define ALIGN_LEFT 1 
    44: #define ALIGN_TOP 1 
    45: #define ALIGN_CENTER 0 
    46: #define ALIGN_RIGHT -1 
    47: #define ALIGN_BOTTOM -1 
    48: 
    49: #define MENU_TRACK_MOUSE_TIMER 4437 
    50: 
    51: using namespace std;
    52: 
    53: typedef vector<MenuItem*>::iterator MENUITERATOR;
    54: 
    55: #ifndef GET_X_LPARAM 
    56: #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) 
    57: #endif 
    58: 
    59: #ifndef GET_Y_LPARAM 
    60: #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) 
    61: #endif 
    62: 
    63: //===========================================================================
    64: 
    65: class Menu  
    66: {
    67: public:
    68:     Menu(HINSTANCE hInstance);
    69:     ~Menu();
    70: 
    71:     friend LRESULT CALLBACK MenuWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    72: 
    73:     void UpdateMenuWindow();
    74:     void DrawMenuItem(HDC hdc, MenuItem* i, bool active);
    75: 
    76:     //====================
    77: 
    78:     void Show();
    79:     void Show(int x, int y);
    80:     bool Hide(int h);
    81: 
    82:     void Mouse(UINT nMsg, int x, int y);
    83:     static void CALLBACK TrackMouseProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
    84:     void MouseLeave();
    85: 
    86:     //====================
    87: 
    88:     void AddMenuItem(MenuItem* m);
    89:     void DeleteMenuItems();
    90: 
    91:     void TogglePinned();
    92:     bool IsPinned();
    93: 
    94:     LRESULT NcHitTest(int x, int y);
    95: 
    96:     void Timer(int nTimer);
    97: 
    98:     //====================
    99: 
   100:     HWND GetWindow();
   101: 
   102:     void SetParent(Menu* pParent);
   103:     Menu* GetParent();
   104: 
   105:     void AddChild(Menu* pChild);
   106:     void RemoveChild(Menu* pChild);
   107:     bool IsChildWindow(HWND hWnd);
   108: 
   109:     void SetMenuFolderPath(char* pszFolderPath);
   110: 
   111:     //====================
   112: 
   113:     void Moving();
   114: 
   115:     virtual bool OnUser(int nMessage, WPARAM wParam, LPARAM lParam, LRESULT& lResult); // Respond to messages in the WM_USER range
   116:     LRESULT Command(WPARAM wParam, LPARAM lParam); // WM_COMMAND has been sent...
   117:     virtual void OnShow(bool fShow) { } // Respond to the WM_SHOWWINDOW message
   118:     virtual void OnTimer(int nTimer) { } // Respond to the WM_TIMER message
   119: 
   120:     void Activate(int fActive, HWND hWnd);
   121:     bool IsActive();
   122: 
   123:     //====================
   124: 
   125:     void Sort(int beginOffset, int endOffset);
   126: 
   127:     void Invalidate();
   128:     void Validate();
   129: 
   130:     //====================
   131: 
   132:     void ClearSelectionGroup(int group);
   133: 
   134:     //====================
   135: 
   136:     HINSTANCE hMenuInstance;
   137:     static int m_nInstances;
   138: 
   139:     WIN32_FIND_DATA data;
   140: 
   141:     //====================
   142: 
   143:     HWND hMenuWnd;
   144: 
   145:     Menu* m_pParent; // The parent popup menu (nb. the root/main popup menu does not have a parent)
   146:     vector<MenuItem*> m_MenuItems; // A vector of menu items that are associated with this popup menu instance
   147:     vector<Menu*> m_Children; // A vector of pointers to children submenus
   148: 
   149:     char* m_pszTitle;
   150: 
   151:     bool isValidated;
   152:     bool isPinned;
   153:     bool mouseIsHovering;
   154:     bool keyboardNavigationInProgress;
   155: 
   156:     bool m_bMoved;
   157: 
   158:     char* m_pszFolderPath;
   159: 
   160:     //====================
   161: 
   162:     // Cached menu gradients
   163:     HDC menuHDC;
   164:     HDC cachedMenuBackground;
   165:     HDC cachedMenuActive;
   166:     bool cachedMenuGradientsExist;
   167: 
   168:     // Menu element rects
   169:     RECT menuRect;
   170:     RECT menuTitleRect;
   171:     RECT menuFrameRect;
   172:     RECT menuActiveRect;
   173:     RECT menuGripRect;
   174: 
   175:     // Menu position and metrics
   176:     int menuX, menuY;
   177:     int menuWidth, menuHeight;
   178:     int menuActiveWidth, menuActiveHeight;
   179: };
   180: 
   181: //===========================================================================
   182: 
   183: #endif /* __MENU_H */ 
   184: