/*
 ============================================================================
 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 __MENUITEM_H 
#define __MENUITEM_H 

#include "../BImage.h" 

class Menu;
class Painter;

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

// This is an 'abstract' base class of menu items
class MenuItem
{
public:
        // Constructs a menu item object
        MenuItem();
        // Destroys the menu item object
        virtual ~MenuItem();

        bool m_bActive;

        // Paint the menu item att the dc.
        // @param hDC handle to the dc to be painted
        virtual void Paint(HDC hDC);

        // Execute the command that is associated with the menu item
        virtual void Invoke(int button);

        // Informs the menuitem that a mouse message have been sent
        // @param nMsg the mouse message type WM_MOUSEMOVE, WM_LBUTTON, etc.
        // @param x location of the mouse message
        // @param y location of the mouse message
        virtual void Mouse(UINT nMsg, int x, int y);

        // Timer callback, used by menuitems that implement anumation or
        // various waiting. examples are the TimeItem, FolderItem
        // @param nTimer the identity of the timer that caused the callback
        virtual void Timer(int nTimer);

        // Returns whether the item is a leaf or a node
        virtual inline bool IsLeaf(){return true;};

        // Returns the height of the menu item
        // @return the height of the menu item
        virtual inline int GetHeight(){return m_nHeight;};

        // Sets the (desired) height of the menu item
        // @param nHeight the (desired) height of the menu item
        virtual inline void SetHeight(int nHeight){m_nHeight=nHeight;};

        // Returns the width of the menu item
        // @return the width of the menu item
        virtual inline int GetWidth(){return m_nWidth;};

        // Sets the (desired) width of the menu item
        // @param nWidth the (desired) width of the menu item
        virtual inline void SetWidth(int nWidth){m_nWidth = nWidth;};

        // The menu asks the menu item if it is ok to hide the menu, default 
        // implementatin returns true
        // @return if this menu item accepts to be hidden
        virtual bool Hide(){return true;};

        // This item has been connected to a popup menu this happens _once_ during 
        // the lifetime of the object
        // @param pMenu pointer to the popupmenu object that this menuitem is connected to
        virtual void Attached(Menu* pMenu);

        // Sent to the menuitems when the mouse is moving. The menuitem may reply
        // to this message to inofrm windows that it is CLIENT area or NONCLIENT
        // @param x the location of the message
        // @param y the location of the message
        // @return the type of area that this menu item covers
        virtual LRESULT NcHitTest(int x, int y){return 0;};

        // Handles the WM_COMMAND messages
        // @param wParam the wParam that was sent with the WM_COMMAND
        // @param lParam the lParam that was sent with the WM_COMMAND
        virtual LRESULT Command(WPARAM wParam, LPARAM lParam);

        // Handle messages in the WM_USER range
        virtual bool OnUser(int nMessage, WPARAM wParam, LPARAM lParam, LRESULT &lResult) { return false; }

        // Gets the bounding box of this item in popupmenu space.
        // @param pRect pointer to a RECT that will receive the information
        virtual void GetItemRect(LPRECT pRect);

        // Sets the activation state of this menu item. The resulting activation 
        // state is returned. If this method returns false then it is impossible
        // to actuvate the meni item (TimeItem, Separatir, header,..)
        // @param bActive the new activation state
        // @return the resulting activation state, may be different than bActive
        virtual bool Active(bool bActive);

        // Sets the painter object to be used to paint the background of this menuitem
        // @param pBackground the new background painter object
        virtual void SetPainter(Painter* pBackground);

        // Returns the painter object that is currently used to paint the background
        // @return the current paitner object
        virtual Painter* GetPainter(){return m_pBackground;};

        // Sets the painter object to be used to paint the active background of this menuitem
        // @param pBackground the new active background painter object
        virtual void SetActivePainter(Painter* pBackground);

        // Notifies the menu item that the menu is moving
        virtual void Moving(){;};

        // Returns the current activation state of this menu itme
        // @return if this menu item is active or not
        virtual bool IsActive(){return m_bActive;};

        // Returns the y location of the menu item
        // @return the y location of the menu item
        virtual int GetTop(){return m_nTop;};

        // Returns handle to the window that is associated with this menu item.
        // NULL if there is no such window
        // @return the window handle to this menu item
        virtual HWND GetWindow();

        // this happes from time to time. it tells the object where it is located in 
        // client coordinates.
        virtual void SetPosition(int nLeft, int nTop){m_nLeft=nLeft;m_nTop=nTop;};

        // Sets the priority this menu item has when it is compared with other menuitems
        // @param nSortPriority the sort priority
        virtual void SetSortPriority(int nSortPriority){m_nSortPriority = nSortPriority;};

        // Returns the priority this menu item has when it is compared with other menuitems
        // @return the sort priority
        virtual int GetSortPriority(){return m_nSortPriority;};

        // Returns the string that is used to compare this menu item with others. this string
        // is typically the title text
        // @return the sort string
        virtual char* GetSortString(){return NULL;};

        // Sets the number of pixels to indent the contents of the menu item
        // when it is painted
        // @param nIndent the number of pixels to indent
        static void SetIndent(int nIndent) {m_nIndent = nIndent;};

        // Returns the number of pixels that menuitems will use to indexnt the contents
        // of the menu item while it is painted
        // @return the number of pixles to indent
        static int GetIndent(){return m_nIndent;};

        // Sets the number of pixels to indent the menu item's contents from the right side.
        // @param nRightIndent number of pixels to indent
        static void SetRightIndent( int nRightIndent ) { m_nRightIndent = nRightIndent; }

        // Returns the number of pixels that the menu item's contents will be
        // indented from the right side.
        // @return number of pixels to indent
        static int GetRightIndent() { return m_nRightIndent; }

        // Horizontal text alignment
        static void SetAlignment(int nAlignment) { m_nAlignment = nAlignment; }
        static int GetAlignment() { return m_nAlignment; }

        // Horizontal text alignment for titles
        static void SetTitleAlignment(UINT nTitleAlignment) { m_nTitleAlignment = nTitleAlignment; }
        static int GetTitleAlignment() { return m_nTitleAlignment; }

        // Compares pM1 with pM2 and returns 'true' if pM1 is 'larger' than pM2
        // it returns 'false' otherwise
        static bool Compare(MenuItem* pM1,MenuItem* pM2);

        // Mouse pointer position on last click
        POINT m_mousePos;

//protected:

        // Constant used when determining the menuitem location compared to other menuitems
        int m_nSortPriority;

        // Number of pixels to indent when painting the foreground on the popup
        static int m_nIndent;
        // Number of pixels to indent from the right side
        static int m_nRightIndent;

        // Horizontal text alignment (DT_*)
        static int m_nAlignment;
        static int m_nTitleAlignment;

        // Tests if the pont x,y is on the menu item
        // @param x the location
        // @param y the location
        // @return the point is over then returns 0
        int IsOver(int x, int y);

        // The popup menu that this item resides on
        Menu* m_pParent;

        // x location of the menuitem
        int m_nLeft;
        // y location of the menuitem
        int m_nTop;

        // The width of the menuitem
        int m_nWidth;
        // The height of the menuitem
        int m_nHeight;

        // The current active status of the menuitem
//      bool m_bActive;

        // Pointer to the painter object that paints the default foreground
        Painter* m_pForeground;
        // Pointer to the painter object that paints the default background
        Painter* m_pBackground;
        // Pointer to the painter object that paints the active foreground
        Painter* m_pActiveForeground;
        // Pointer to the painter object that paints the active background
        Painter* m_pActiveBackground;
};

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

#endif /* __MENUITEM_H */ 





syntax highlighting by

w e b c p p
web c plus plus