nux-0.9.48

Nux/MenuBar.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef MENUBAR_H
00024 #define MENUBAR_H
00025 
00026 #include "ScrollView.h"
00027 #include "ToolButton.h"
00028 #include "MenuPage.h"
00029 #include "Painter.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class PopupBox;
00035   class BaseWindow;
00036   class MenuBar;
00037   class HLayout;
00038 
00039 
00040   class MenuBarItem: public Object
00041   {
00042   public:
00043     NUX_DECLARE_OBJECT_TYPE (MenuBarItem, Object);
00044 
00045     MenuBarItem (NUX_FILE_LINE_PROTO);
00046     ~MenuBarItem();
00047   private:
00048     InputArea   *area;
00049     MenuPage   *menu;
00050     BaseTexture   *icon; // should be 24x24
00051 
00052     friend class MenuBar;
00053   };
00054 
00055   class MenuBar: public View
00056   {
00057     NUX_DECLARE_OBJECT_TYPE (MenuBar, View);
00058 
00059   public:
00060     MenuBar (NUX_FILE_LINE_PROTO);
00061     ~MenuBar();
00062 
00063     virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00064     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00065     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00066     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00067 
00068     //void AddActionItem(ActionItem* actionItem);
00069 
00070     void AddMenu (const TCHAR *MenuLabel, MenuPage *popup);
00071     void AddMenu (const TCHAR *MenuLabel, MenuPage *menu, BaseTexture *icon);
00072 
00073 
00075     //  EMITERS    //
00077 
00078   private:
00079     void EmitItemMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags, MenuBarItem *menubar_item);
00080     void EmitItemMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags, MenuBarItem *menubar_item);
00081     void EmitItemMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, MenuBarItem *menubar_item);
00082     void EmitItemMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, MenuBarItem *menubar_item);
00083     void RecvItemMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags, MenuBarItem *menubar_item);
00084     void RecvSigActionTriggered (MenuPage *, ActionItem *);
00085     void RecvSigTerminateMenuCascade();
00086 
00088     /*
00089         Process a mouse down event outside of the menu cascade. The menu bar checks if the mouse down happened on one of its menu bar item.
00090         If yes, it let the menu bar item process the event. if no, it will initiate the closure of the menu cascade.
00091 
00092         \param menu menu item
00093         \param x    coordinate of the mouse down event
00094         \param y    coordinate of the mouse down event
00095     */
00096     void RecvSigMouseDownOutsideMenuCascade (MenuPage *menu, int x, int y);
00097 
00098   protected:
00099 
00100 
00101   private:
00102     std::list< MenuBarItem * > m_MenuBarItemList;
00103 
00104     HLayout *m_hlayout;
00105     bool m_MenuIsActive;
00106     MenuBarItem *m_CurrentMenu;
00107     bool m_IsOpeningMenu;
00108     BaseWindow *m_MenuBarWindow;
00109   };
00110 
00111 }
00112 
00113 #endif // MENUBAR_H