nux-1.14.0
|
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 void DrawAsMenuItem (GraphicsEngine &GfxContext, const Color &textcolor, bool is_highlighted, bool isFirstItem, bool isLastItem, bool draw_icone); 00044 00045 //const ActionItem& GetItem() const {return m_ActionItem;} 00046 ActionItem *GetActionItem() const; 00047 //ActionItem* GetActionItem(); 00048 00049 int GetTextWidth (); 00050 int GetTextHeight (); 00051 00052 StaticText * GetStaticText () 00053 { 00054 return _pango_static_text; 00055 } 00056 00057 private: 00058 virtual long ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00059 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00060 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw) {}; 00061 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw) {}; 00062 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 00096 // void SetName(const TCHAR* name); 00097 const TCHAR *GetName() const; 00098 00099 ActionItem *AddAction (const TCHAR *label = 0, int UserValue = 0); 00100 //void AddActionItem(ActionItem* actionItem); 00101 void AddSeparator(); 00102 MenuPage *AddMenu (const TCHAR *label); 00103 ActionItem *AddSubMenu (const TCHAR *label, MenuPage *menu); 00104 00105 void RemoveItem (ActionItem *item); 00106 void RemoveAllItem(); 00107 00108 bool CanClose() const; 00109 // emitters 00110 void EmitMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00111 void EmitMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00112 void EmitMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00113 void EmitMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00114 void RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags); 00115 00116 //private: 00118 /* 00119 Start the MenuPage iteration and show it. 00120 When this function is called, the menu becomes visible and appear at position (MenuXPosition, MenuYPosition). 00121 The menu also assumes it has received a mouse down event at coordinates (x, y). 00122 \param MenuXPosition: the position of the menu. 00123 \param MenuYPosition: the position of the menu. 00124 \param x: the simulate position where the mouse down happened on the menu area. 00125 \param y: the simulate position where the mouse down happened on the menu area. 00126 \param TakeMousefocus: if true, the MenuPage area will take the mouse focus. 00127 */ 00128 void StartMenu (int MenuXPosition, int MenuYPosition, int x = 0, int y = 0, bool OverrideCurrentMenuChain = true); 00129 00131 /* 00132 Stop the MenuPage iteration and hide it. 00133 \param x: the simulate position where the mouse down happened on the menu area. 00134 \param y: the simulate position where the mouse down happened on the menu area. 00135 00136 */ 00137 void StopMenu (int x = 0, int y = 0); 00138 00139 void SetFontName (char *font_name); 00140 00142 00150 void SetOnClosureContinueEventCycle(bool on_closure_continue_with_event); 00151 00153 00161 bool OnClosureContinueEventCycle() const; 00162 00163 public: 00164 void StopActionSubMenu(); 00165 void ExecuteActionItem (MenuItem *menuItem); 00166 00167 void NotifyActionTriggeredToParent (MenuPage *, MenuItem *menuItem); 00168 void NotifyTerminateMenuCascade(); 00169 void NotifyMouseDownOutsideMenuCascade (int x, int y); 00170 00171 void SetParentMenu (MenuPage *); 00172 MenuPage *GetParentMenu(); 00173 00174 void setShowItemIcon (bool b) 00175 { 00176 m_show_item_icon = b; 00177 } 00178 bool ShowItemIcon() 00179 { 00180 return m_show_item_icon; 00181 } 00182 bool TestMouseDown(); 00183 bool TestMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, bool &hit_inside_a_menu); 00184 00185 // Never call this function directly 00186 void Terminate (int x, int y, unsigned long button_flags, unsigned long key_flags); 00187 00188 // signals 00189 sigc::signal<void, int> sigItemSelected; 00191 /* 00192 The MenuPage object sends this signal when an action is triggered. 00193 \param MenuPage the menu object sending the signal. 00194 \param ActionItem the action object that was triggered in the menu. 00195 */ 00196 sigc::signal<void, MenuPage *, ActionItem * > sigActionTriggered; 00197 00199 /* 00200 The MenuPage object send this signal to inform that it needs to be close. 00201 The receiving object must close the MenuPage by calling the member function StopMenu(). 00202 Any object that controls a menu should intercept sigTerminateMenuCascade and sigMouseDownOutsideMenuCascade. 00203 */ 00204 sigc::signal<void> sigTerminateMenuCascade; 00205 00207 /* 00208 Notify that a mouse down event happened outside the menu cascade. This event is processed by the MenuPage bar. The menu bar 00209 checks if the mouse down happened on one of its menu bar item. If yes, it let the menu bar item process the event. 00210 if no, it will initiate the closure of the menu cascade. 00211 Any object that controls a menu should intercept sigTerminateMenuCascade and sigMouseDownOutsideMenuCascade. 00212 */ 00213 sigc::signal<void, MenuPage *, int, int> sigMouseDownOutsideMenuCascade; 00214 00215 sigc::signal<void, MenuPage *> sigOpeningMenu; 00216 sigc::signal<void, MenuPage *> sigClosingMenu; 00217 00218 void SetActive (bool b) 00219 { 00220 m_IsActive = b; 00221 00222 if (b) 00223 /*m_PopupArea.*/CaptureMouseDownAnyWhereElse (true); 00224 else 00225 /*m_PopupArea.*/CaptureMouseDownAnyWhereElse (false); 00226 } 00227 00228 bool IsActive() const 00229 { 00230 return m_IsActive; 00231 } 00232 00236 int GetNumItem() const 00237 { 00238 return m_numItem; 00239 } 00240 ActionItem *GetActionItem (int i) const; 00241 00246 int GetActionItemIndex (ActionItem *action) const; 00247 00249 00256 virtual Geometry GetAbsoluteGeometry () const; 00257 00259 00263 virtual Geometry GetRootGeometry () const; 00264 00265 protected: 00266 virtual Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type); 00267 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) ; 00268 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00269 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00270 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00271 00272 private: 00273 00274 bool on_closure_continue_with_event_; 00275 int m_numItem; 00276 int m_HighlightedItem; 00277 bool m_IsActive; 00278 VLayout* _vlayout; 00279 bool m_NextMouseUpMeanStop; 00280 MenuItem *m_SubMenuAction; 00281 NString m_Name; 00282 00283 bool m_Action_Triggered; 00284 MenuPage *m_Parent; 00285 00286 // Set to TRUE if one of the MenuItem processed the mouse event. 00287 bool m_MouseEventProcessed; 00288 00289 int m_item_width; 00290 int m_item_height; 00291 bool m_show_item_icon; 00292 std::vector<MenuItem *> m_MenuItemVector; 00293 std::vector< MenuSeparator * > m_MenuSeparatorVector; 00294 BaseWindow *m_MenuWindow; 00295 00297 bool m_IsTopOfMenuChain; 00298 00299 char *_font_name; 00300 00301 public: 00303 // AbstractInterfaceObject 00305 00306 virtual long ComputeChildLayout(); 00307 virtual void SetGeometry (const Geometry &geo); 00308 00309 friend class MenuBar; 00310 friend class WindowCompositor; 00311 }; 00312 00313 } 00314 00315 #endif // MENUPAGE_H