nux-0.9.46
|
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 MENUPAGE_H 00024 #define MENUPAGE_H 00025 00026 #include "ActionItem.h" 00027 #include "FloatingWindow.h" 00028 00029 namespace nux 00030 { 00031 class StaticText; 00032 class MenuPage; 00033 class VLayout; 00034 class MenuBar; 00035 00036 class MenuItem: public View 00037 { 00038 NUX_DECLARE_OBJECT_TYPE (MenuItem, View); 00039 public: 00040 MenuItem (const TCHAR *label, int UserValue, NUX_FILE_LINE_PROTO); 00041 ~MenuItem(); 00042 00043 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00044 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00045 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw) {}; 00046 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw) {}; 00047 00048 void DrawAsMenuItem (GraphicsEngine &GfxContext, const Color &textcolor, bool is_highlighted, bool isFirstItem, bool isLastItem, bool draw_icone); 00049 00050 //const ActionItem& GetItem() const {return m_ActionItem;} 00051 ActionItem *GetActionItem() const; 00052 //ActionItem* GetActionItem(); 00053 00054 int GetTextWidth (); 00055 int GetTextHeight (); 00056 00057 StaticText * GetStaticText () 00058 { 00059 return _pango_static_text; 00060 } 00061 00062 private: 00063 void SetChildMenu (MenuPage *menu); 00064 MenuPage *GetChildMenu() const; 00065 void SetActionItem (ActionItem *menu); 00066 00067 MenuPage *_child_menu; 00068 ActionItem *_action_item; 00069 StaticText *_pango_static_text; 00070 friend class MenuPage; 00071 }; 00072 00073 class MenuSeparator: public View 00074 { 00075 NUX_DECLARE_OBJECT_TYPE (MenuSeparator, View); 00076 public: 00077 MenuSeparator (NUX_FILE_LINE_PROTO); 00078 ~MenuSeparator(); 00079 00080 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00081 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00082 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw) {}; 00083 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw) {}; 00084 00085 private: 00086 friend class MenuPage; 00087 }; 00088 00089 class MenuPage: public View 00090 { 00091 NUX_DECLARE_OBJECT_TYPE (MenuPage, View); 00092 public: 00093 MenuPage (const TCHAR *title = TEXT (""), NUX_FILE_LINE_PROTO); 00094 ~MenuPage(); 00095 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) ; 00096 00097 00098 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00099 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00100 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00101 00102 // void SetName(const TCHAR* name); 00103 const TCHAR *GetName() const; 00104 00105 ActionItem *AddAction (const TCHAR *label = 0, int UserValue = 0); 00106 //void AddActionItem(ActionItem* actionItem); 00107 void AddSeparator(); 00108 MenuPage *AddMenu (const TCHAR *label); 00109 ActionItem *AddSubMenu (const TCHAR *label, MenuPage *menu); 00110 00111 void RemoveItem (ActionItem *item); 00112 void RemoveAllItem(); 00113 00114 bool CanClose() const; 00115 // emitters 00116 void EmitMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00117 void EmitMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00118 void EmitMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00119 void EmitMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00120 void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags); 00121 00122 //private: 00124 /* 00125 Start the MenuPage iteration and show it. 00126 When this function is called, the menu becomes visible and appear at position (MenuXPosition, MenuYPosition). 00127 The menu also assumes it has received a mouse down event at coordinates (x, y). 00128 \param MenuXPosition: the position of the menu. 00129 \param MenuYPosition: the position of the menu. 00130 \param x: the simulate position where the mouse down happened on the menu area. 00131 \param y: the simulate position where the mouse down happened on the menu area. 00132 \param TakeMousefocus: if true, the MenuPage area will take the mouse focus. 00133 */ 00134 void StartMenu (int MenuXPosition, int MenuYPosition, int x = 0, int y = 0, bool OverrideCurrentMenuChain = true); 00135 00137 /* 00138 Stop the MenuPage iteration and hide it. 00139 \param x: the simulate position where the mouse down happened on the menu area. 00140 \param y: the simulate position where the mouse down happened on the menu area. 00141 00142 */ 00143 void StopMenu (int x = 0, int y = 0); 00144 00145 void SetFontName (char *font_name); 00146 00147 public: 00148 void StopActionSubMenu(); 00149 void ExecuteActionItem (MenuItem *menuItem); 00150 00151 void NotifyActionTriggeredToParent (MenuPage *, MenuItem *menuItem); 00152 void NotifyTerminateMenuCascade(); 00153 void NotifyMouseDownOutsideMenuCascade (int x, int y); 00154 00155 void SetParentMenu (MenuPage *); 00156 MenuPage *GetParentMenu(); 00157 00158 void setShowItemIcon (bool b) 00159 { 00160 m_show_item_icon = b; 00161 } 00162 bool ShowItemIcon() 00163 { 00164 return m_show_item_icon; 00165 } 00166 bool TestMouseDown(); 00167 bool TestMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, bool &hit_inside_a_menu); 00168 00169 // Never call this function directly 00170 void Terminate (int x, int y, unsigned long button_flags, unsigned long key_flags); 00171 00172 // signals 00173 sigc::signal<void, int> sigItemSelected; 00175 /* 00176 The MenuPage object sends this signal when an action is triggered. 00177 \param MenuPage the menu object sending the signal. 00178 \param ActionItem the action object that was triggered in the menu. 00179 */ 00180 sigc::signal<void, MenuPage *, ActionItem * > sigActionTriggered; 00181 00183 /* 00184 The MenuPage object send this signal to inform that it needs to be close. 00185 The receiving object must close the MenuPage by calling the member function StopMenu(). 00186 Any object that controls a menu should intercept sigTerminateMenuCascade and sigMouseDownOutsideMenuCascade. 00187 */ 00188 sigc::signal<void> sigTerminateMenuCascade; 00189 00191 /* 00192 Notify that a mouse down event happened outside the menu cascade. This event is processed by the MenuPage bar. The menu bar 00193 checks if the mouse down happened on one of its menu bar item. If yes, it let the menu bar item process the event. 00194 if no, it will initiate the closure of the menu cascade. 00195 Any object that controls a menu should intercept sigTerminateMenuCascade and sigMouseDownOutsideMenuCascade. 00196 */ 00197 sigc::signal<void, MenuPage *, int, int> sigMouseDownOutsideMenuCascade; 00198 00199 void SetActive (bool b) 00200 { 00201 m_IsActive = b; 00202 00203 if (b) 00204 /*m_PopupArea.*/CaptureMouseDownAnyWhereElse (true); 00205 else 00206 /*m_PopupArea.*/CaptureMouseDownAnyWhereElse (false); 00207 } 00208 00209 bool IsActive() const 00210 { 00211 return m_IsActive; 00212 } 00213 00217 int GetNumItem() const 00218 { 00219 return m_numItem; 00220 } 00221 ActionItem *GetActionItem (int i) const; 00222 00227 int GetActionItemIndex (ActionItem *action) const; 00228 private: 00229 int m_numItem; 00230 int m_HighlightedItem; 00231 bool m_IsActive; 00232 VLayout *vlayout; 00233 bool m_NextMouseUpMeanStop; 00234 MenuItem *m_SubMenuAction; 00235 NString m_Name; 00236 00237 bool m_Action_Triggered; 00238 MenuPage *m_Parent; 00239 00240 // Set to TRUE if one of the MenuItem processed the mouse event. 00241 bool m_MouseEventProcessed; 00242 00243 int m_item_width; 00244 int m_item_height; 00245 bool m_show_item_icon; 00246 std::vector<MenuItem *> m_MenuItemVector; 00247 std::vector< MenuSeparator * > m_MenuSeparatorVector; 00248 BaseWindow *m_MenuWindow; 00249 00251 bool m_IsTopOfMenuChain; 00252 00253 char *_font_name; 00254 00255 public: 00257 // AbstractInterfaceObject 00259 00260 virtual long ComputeChildLayout(); 00261 virtual void SetGeometry (const Geometry &geo); 00262 00263 friend class MenuBar; 00264 }; 00265 00266 } 00267 00268 #endif // MENUPAGE_H