/*
 ============================================================================
 xoblite -> an alternative shell based on Blackbox for Windows
 Copyright  2002-2005 Karl-Henrik Henriksson [qwilk]
 Copyright  2001-2004 The Blackbox for Windows Development Team
 http://xoblite.net/ - #bb4win on irc.freenode.net
 ============================================================================

  Blackbox for Windows is free software, released under the
  GNU General Public License (GPL version 2 or later), with an extension
  that allows linking of proprietary modules under a controlled interface.
  What this means is that plugins etc. are allowed to be released
  under any license the author wishes. Please note, however, that the
  original Blackbox gradient math code used in Blackbox for Windows
  is available under the BSD license.

  http://www.fsf.org/licenses/gpl.html
  http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
  http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  For additional license information, please read the included license.html

 ============================================================================
*/

#ifndef __MENU_H 
#define __MENU_H 

#include <windows.h> 
#include <vector> 

#define HIDE_CHILDREN 1 
#define HIDE_THIS 0 
#define HIDE_PARENTS  -1 

#define ALIGN_LEFT 1 
#define ALIGN_TOP 1 
#define ALIGN_CENTER 0 
#define ALIGN_RIGHT -1 
#define ALIGN_BOTTOM -1 

using namespace std;

class MenuItem;

typedef vector<MenuItem*>::iterator MENUITERATOR;

//===========================================================================

// Menu is a class that contains a set of MenuItems. This class manages
// the underlying _tsystem window that is used to render the menuitems.
class Menu  
{
public:

        Menu(HINSTANCE hInstance);
        virtual ~Menu();

        // Displays the popup with upper left corners at
        // @param x location on the screen
        // @param y location on the screen
        void Show(int x, int y);

        /// Displays the popup at a location that the popup consider to be reasonable
        void Show();

        // Adds the MenuItem m to the popup menu. Menu will free the object when
        // it is no longer needed
        // @param m pointer to a menuitem object to be added
        void AddMenuItem(MenuItem* m);

        // Sorted add
        void AddMenuItem(MenuItem *m, bool (*pfnSort)(void *, MenuItem *, MenuItem *), void *pvSortParam);

        // Deletes the entire list of menu items, and deletes the objects that it refers to
        void DeleteMenuItems();

        // Returns TRUE if this popupmenu is a pinned state
        // @return if the popup is pinned
        bool IsPinned(){return m_bPinned;};

        bool HasMoved() {return m_bMoved;};

        // Sets the pinned state of the popup
        // @param bPinned TRUE to set pinned, FALSE to un-pin
        void SetPinned(bool bPinned){m_bPinned = bPinned;};
        
        // Hides the popup menu
        // 1. this and all below this
        // 2. this and all above this
        // 3. only this popupmenu
        void Hide(int h);

        // Returns the associated window
        // @return handle to the associated window
        HWND GetWindow();

        // Calls paint on each menu item
        void Paint();

        // Calls mouse message on each menu item
        void Mouse(UINT nMsg, int x, int y);

        // This window is activated or de-activated
        void Activate(int fActive, HWND hWnd);

        /// Timer message has been sent to this window
        void Time(int nTimer);

        /// NC hit test has been sent to this window
        LRESULT NcHitTest(int x, int y);

        /// WM_COMMAND has been sent...
        LRESULT Command(WPARAM wParam, LPARAM lParam);

        // Paints a border around the popupmenu
        // @param hDC handle to a device context on which the Border is painted
        void PaintBorder(HDC hDC);

        // Sets the parent menu of this menu
        // @param pParent Menu pointer pointing at the parent object
        void SetParent(Menu* pParent);

        // Adds a child popup menu to this menu
        // @param pChild Menu pinter pointing at the child object
        void AddChild(Menu* pChild);

        // Removes a popupmenu from the vector of children
        // @param pChild pointer to the popupmenu object to be removed
        void RemoveChild(Menu* pChild);

        // Returns the parent object of this popupmenu
        // @return Returns the parent popupmenu object, NULL if there is no parent object
        Menu* GetParent();

        // The user is moving the popupmenu
        void Moving();

        bool IsActive();

        WIN32_FIND_DATA data;

        // Sorts the menuitems in this menu
        void Sort(int beginOffset, int endOffset);

        // Validate the width and transparency of this menu
        void Validate();

        // Do actually validate next time validate is called
        void Invalidate();

        // Called when the mouse leaves the menu
        void MouseLeave();

        // Respond to the WM_SHOWWINDOW message
        virtual void OnShow(bool fShow) { }

        // Respond to the WM_TIMER message
        virtual void OnTimer(int nTimer) { }

        // Respond to messages in the WM_USER range
        virtual bool OnUser(int nMessage, WPARAM wParam, LPARAM lParam, LRESULT &lResult);

//protected:    

        // Utility method used to find and deactivate the currently selected menu item
        // @param pMenuIterator will upon return point at the deselected menu item
        // @return true if one was deselected, false otherwuse
        bool FindActiveAndDeactivate(MENUITERATOR* pMenuIterator);

        // Utility method that reutrns true if hWnd is a children of this menue
        // @param hWnd the window to be checked
        // @return true if hWnd is a children, false otherwise
        bool IsChildWindow(HWND hWnd);

        // Timer callback used to monitor the position of the mouse
        static void CALLBACK TrackMouseProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);

        // True if the menu is validated for size and transparency, false otherwise
        bool m_bValidated;

        // The string title of the popupmenu
        char* m_pszTitle;

        // Handle to the window that is the popup menu
        HWND m_hWnd;

        // The parent popup menu. The root popup menue does not have any parent.
        Menu* m_pParent;

        // A vector of pointers to children menues
        vector<Menu*> m_Children;

        // A vector of menuitems that is associated with this popup menu
        vector<MenuItem*> m_MenuItems;

        // Handle to the instace of this process
        HINSTANCE m_hInstance;

        // The number of popupmenu objects loaded
        static int m_nInstances;

        HBITMAP bitmap;
        // If this popupmenu is pinned or not
        bool m_bPinned;

        bool m_bMoved;

        // If the mouse is currently over this window
        bool m_bMouseOver;

        // menu.frame gradient cache
        HDC cachedMenuFrame;
        bool cachedMenuFrameExists;
};

//====================

LRESULT CALLBACK MenuWindowProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam);

//===========================================================================

#endif /* __MENU_H */ 





syntax highlighting by

w e b c p p
web c plus plus