llmenugl.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLMENUGL_H
00033 #define LL_LLMENUGL_H
00034 
00035 #include <list>
00036 
00037 #include "llstring.h"
00038 #include "v4color.h"
00039 #include "llframetimer.h"
00040 #include "llevent.h"
00041 
00042 #include "llkeyboard.h"
00043 #include "llfloater.h"
00044 #include "lluistring.h"
00045 #include "llview.h"
00046 
00047 class LLMenuItemGL;
00048 class LLMenuHolderGL;
00049 
00050 extern S32 MENU_BAR_HEIGHT;
00051 extern S32 MENU_BAR_WIDTH;
00052 
00053 // These callbacks are used by the LLMenuItemCallGL and LLMenuItemCheckGL
00054 // classes during their work.
00055 typedef void (*menu_callback)(void*);
00056 
00057 // These callbacks are used by the LLMenuItemCallGL 
00058 // classes during their work.
00059 typedef void (*on_disabled_callback)(void*);
00060 
00061 // This callback is used by the LLMenuItemCallGL and LLMenuItemCheckGL
00062 // to determine if the current menu is enabled.
00063 typedef BOOL (*enabled_callback)(void*);
00064 
00065 // This callback is used by LLMenuItemCheckGL to determine it's
00066 // 'checked' state.
00067 typedef BOOL (*check_callback)(void*);
00068 
00069 // This callback is potentially used by LLMenuItemCallGL. If provided,
00070 // this function is called whenever it's time to determine the label's
00071 // contents. Put the contents of the label in the provided parameter.
00072 typedef void (*label_callback)(LLString&,void*);
00073 
00074 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00075 // Class LLMenuItemGL
00076 //
00077 // The LLMenuItemGL represents a single menu item in a menu. 
00078 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00079 
00080 class LLFontGL;
00081 class LLMenuGL;
00082 
00083 
00084 class LLMenuItemGL : public LLView
00085 {
00086 public:
00087         LLMenuItemGL( const LLString& name, const LLString& label, KEY key = KEY_NONE, MASK = MASK_NONE );
00088 
00089         virtual void setValue(const LLSD& value) { setLabel(value.asString()); }
00090         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_ITEM; }
00091         virtual LLString getWidgetTag() const { return LL_MENU_ITEM_TAG; }
00092 
00093         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00094 
00095         virtual LLString getType() const        { return "item"; }
00096 
00097         virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
00098         virtual BOOL handleHover(S32 x, S32 y, MASK mask);
00099 
00100         virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
00101 
00102         BOOL getHighlight() const                       { return mHighlight; }
00103 
00104         void setJumpKey(KEY key);
00105         KEY getJumpKey();
00106         
00107         // set the font used by this item.
00108         void setFont(LLFontGL* font);
00109         void setFontStyle(U8 style) { mStyle = style; }
00110 
00111         // returns the height in pixels for the current font.
00112         virtual U32 getNominalHeight( void );
00113 
00114         // functions to control the color scheme
00115         static void setEnabledColor( const LLColor4& color );
00116         static void setDisabledColor( const LLColor4& color );
00117         static void setHighlightBGColor( const LLColor4& color );
00118         static void setHighlightFGColor( const LLColor4& color );
00119         
00120         // Marks item as not needing space for check marks or accelerator keys
00121         virtual void setBriefItem(BOOL brief);
00122 
00123         virtual BOOL addToAcceleratorList(std::list<LLKeyBinding*> *listp);
00124         void setAllowKeyRepeat(BOOL allow) { mAllowKeyRepeat = allow; }
00125 
00126         // return the name label
00127         LLString getLabel( void ) const { return mLabel.getString(); }
00128 
00129         // change the label
00130         void setLabel( const LLStringExplicit& label );
00131         virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text );
00132 
00133         // Get the parent menu for this item
00134         virtual LLMenuGL*       getMenu();
00135 
00136         // returns the normal width of this control in pixels - this is
00137         // used for calculating the widest item, as well as for horizontal
00138         // arrangement.
00139         virtual U32 getNominalWidth( void );
00140 
00141         // buildDrawLabel() - constructs the string used during the draw()
00142         // function. This reduces the overall string manipulation, but can
00143         // lead to visual errors if the state of the object changes
00144         // without the knowledge of the menu item. For example, if a
00145         // boolean being watched is changed outside of the menu item's
00146         // doIt() function, the draw buffer will not be updated and will
00147         // reflect the wrong value. If this ever becomes an issue, there
00148         // are ways to fix this.
00149         // Returns the enabled state of the item.
00150         virtual void buildDrawLabel( void );
00151 
00152         // for branching menu items, bring sub menus up to root level of menu hierarchy
00153         virtual void updateBranchParent( LLView* parentp ){};
00154         
00155         // doIt() - do the primary funcationality of the menu item.
00156         virtual void doIt( void );
00157 
00158         // set the hover status (called by it's menu)
00159         virtual void setHighlight( BOOL highlight );
00160 
00161         // determine if this represents an active sub-menu
00162         virtual BOOL isActive( void ) const;
00163 
00164         // determine if this represents an open sub-menu
00165         virtual BOOL isOpen( void ) const;
00166 
00167         virtual void setEnabledSubMenus(BOOL enable){};
00168 
00169         // LLView Functionality
00170         virtual BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent );
00171         virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00172         virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00173         virtual void draw( void );
00174 
00175         BOOL getHover() { return mGotHover; }
00176 
00177         BOOL getDrawTextDisabled() const { return mDrawTextDisabled; }
00178 
00179 protected:
00180         // This function appends the character string representation of
00181         // the current accelerator key and mask to the provided string.
00182         void appendAcceleratorString( LLString& st );
00183 
00184 public:
00185         static LLColor4 sEnabledColor;
00186         static LLColor4 sDisabledColor;
00187         static LLColor4 sHighlightBackground;
00188         static LLColor4 sHighlightForeground;
00189 
00190 protected:
00191         static BOOL sDropShadowText;
00192 
00193         // mLabel contains the actual label specified by the user.
00194         LLUIString mLabel;
00195 
00196         // The draw labels contain some of the labels that we draw during
00197         // the draw() routine. This optimizes away some of the string
00198         // manipulation.
00199         LLUIString mDrawBoolLabel;
00200         LLUIString mDrawAccelLabel;
00201         LLUIString mDrawBranchLabel;
00202 
00203         // Keyboard and mouse variables
00204         KEY mJumpKey;
00205         KEY mAcceleratorKey;
00206         MASK mAcceleratorMask;
00207         BOOL mAllowKeyRepeat;
00208         BOOL mHighlight;
00209         BOOL mGotHover;
00210 
00211         // If true, suppress normal space for check marks on the left and accelerator
00212         // keys on the right.
00213         BOOL mBriefItem;
00214 
00215         // Font for this item
00216         LLFontGL* mFont;
00217 
00218         U8      mStyle;
00219         BOOL mDrawTextDisabled;
00220 };
00221 
00222 
00223 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00224 // Class LLMenuItemCallGL
00225 //
00226 // The LLMenuItemCallerGL represents a single menu item in a menu that
00227 // calls a user defined callback.
00228 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00229 
00230 class LLMenuItemCallGL : public LLMenuItemGL
00231 {
00232 protected:
00233         menu_callback                   mCallback;
00234         // mEnabledCallback should return TRUE if the item should be enabled
00235         enabled_callback                mEnabledCallback;       
00236         label_callback                  mLabelCallback;
00237         void*                                   mUserData;
00238         on_disabled_callback    mOnDisabledCallback;
00239 
00240 public:
00241         // normal constructor
00242         LLMenuItemCallGL( const LLString& name,
00243                                           menu_callback clicked_cb, 
00244                                           enabled_callback enabled_cb = NULL,
00245                                           void* user_data = NULL, 
00246                                           KEY key = KEY_NONE, MASK mask = MASK_NONE,
00247                                           BOOL enabled = TRUE,
00248                                           on_disabled_callback on_disabled_cb = NULL);
00249         LLMenuItemCallGL( const LLString& name,
00250                                           const LLString& label,
00251                                           menu_callback clicked_cb, 
00252                                           enabled_callback enabled_cb = NULL,
00253                                           void* user_data = NULL, 
00254                                           KEY key = KEY_NONE, MASK mask = MASK_NONE,
00255                                           BOOL enabled = TRUE,
00256                                           on_disabled_callback on_disabled_cb = NULL);
00257 
00258         // constructor for when you want to trap the arrange method.
00259         LLMenuItemCallGL( const LLString& name,
00260                                           const LLString& label,
00261                                           menu_callback clicked_cb,
00262                                           enabled_callback enabled_cb,
00263                                           label_callback label_cb,
00264                                           void* user_data,
00265                                           KEY key = KEY_NONE, MASK mask = MASK_NONE,
00266                                           BOOL enabled = TRUE,
00267                                           on_disabled_callback on_disabled_c = NULL);
00268         LLMenuItemCallGL( const LLString& name,
00269                                           menu_callback clicked_cb,
00270                                           enabled_callback enabled_cb,
00271                                           label_callback label_cb,
00272                                           void* user_data,
00273                                           KEY key = KEY_NONE, MASK mask = MASK_NONE,
00274                                           BOOL enabled = TRUE,
00275                                           on_disabled_callback on_disabled_c = NULL);
00276         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00277 
00278         virtual LLString getType() const        { return "call"; }
00279 
00280         virtual EWidgetType getWidgetType() const;
00281         virtual LLString getWidgetTag() const;
00282 
00283         void setEnabledControl(LLString enabled_control, LLView *context);
00284         void setVisibleControl(LLString enabled_control, LLView *context);
00285 
00286         void setMenuCallback(menu_callback callback, void* data) { mCallback = callback;  mUserData = data; };
00287         menu_callback getMenuCallback() const { return mCallback; }
00288 
00289         void setEnabledCallback(enabled_callback callback) { mEnabledCallback = callback; };
00290 
00291         void setUserData(void *userdata)        { mUserData = userdata; }
00292         void* getUserData() const { return mUserData; }
00293 
00294         // called to rebuild the draw label
00295         virtual void buildDrawLabel( void );
00296 
00297         // doIt() - do the primary funcationality of the menu item.
00298         virtual void doIt( void );
00299 
00300         virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
00301 
00302         //virtual void draw();
00303 
00304         virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
00305 };
00306 
00307 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00308 // Class LLMenuItemCheckGL
00309 //
00310 // The LLMenuItemCheckGL is an extension of the LLMenuItemCallGL
00311 // class, by allowing another method to be specified which determines
00312 // if the menu item should consider itself checked as true or not.  Be
00313 // careful that the check callback provided - it needs to be VERY
00314 // FUCKING EFFICIENT, because it may need to be checked a lot.
00315 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00316 
00317 class LLMenuItemCheckGL 
00318 :       public LLMenuItemCallGL
00319 {
00320 protected:
00321         check_callback mCheckCallback;
00322         BOOL mChecked;
00323 
00324 public:
00325         LLMenuItemCheckGL( const LLString& name, 
00326                                            const LLString& label,
00327                                            menu_callback callback,
00328                                            enabled_callback enabled_cb,
00329                                            check_callback check,
00330                                            void* user_data,
00331                                            KEY key = KEY_NONE, MASK mask = MASK_NONE );
00332         LLMenuItemCheckGL( const LLString& name, 
00333                                            menu_callback callback,
00334                                            enabled_callback enabled_cb,
00335                                            check_callback check,
00336                                            void* user_data,
00337                                            KEY key = KEY_NONE, MASK mask = MASK_NONE );
00338         LLMenuItemCheckGL( const LLString& name, 
00339                                            const LLString& label,
00340                                            menu_callback callback,
00341                                            enabled_callback enabled_cb,
00342                                            LLString control_name,
00343                                            LLView *context,
00344                                            void* user_data,
00345                                            KEY key = KEY_NONE, MASK mask = MASK_NONE );
00346         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00347 
00348         void setCheckedControl(LLString checked_control, LLView *context);
00349 
00350         virtual void setValue(const LLSD& value) { mChecked = value.asBoolean(); }
00351         virtual EWidgetType getWidgetType() const;
00352         virtual LLString getWidgetTag() const;
00353 
00354         virtual LLString getType() const        { return "check"; }
00355 
00356         // called to rebuild the draw label
00357         virtual void buildDrawLabel( void );
00358 
00359         virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
00360 
00361         // LLView Functionality
00362         //virtual void draw( void );
00363 };
00364 
00365 
00366 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00367 // Class LLMenuItemToggleGL
00368 //
00369 // The LLMenuItemToggleGL is a menu item that wraps around a user
00370 // specified and controlled boolean.
00371 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00372 
00373 class LLMenuItemToggleGL : public LLMenuItemGL
00374 {
00375 protected:
00376         BOOL* mToggle;
00377 
00378 public:
00379         LLMenuItemToggleGL( const LLString& name, const LLString& label,
00380                                                 BOOL* toggle, 
00381                                                 KEY key = KEY_NONE, MASK mask = MASK_NONE );
00382 
00383         LLMenuItemToggleGL( const LLString& name,
00384                                                 BOOL* toggle, 
00385                                                 KEY key = KEY_NONE, MASK mask = MASK_NONE );
00386 
00387         virtual LLString getType() const        { return "toggle"; }
00388 
00389         // called to rebuild the draw label
00390         virtual void buildDrawLabel( void );
00391 
00392         // doIt() - do the primary funcationality of the menu item.
00393         virtual void doIt( void );
00394 
00395         // LLView Functionality
00396         //virtual void draw( void );
00397 };
00398 
00399 
00400 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00401 // Class LLMenuGL
00402 //
00403 // The Menu class represents a normal rectangular menu somewhere on
00404 // screen. A Menu can have menu items (described above) or sub-menus
00405 // attached to it. Sub-menus are implemented via a specialized
00406 // menu-item type known as a branch. Since it's easy to do wrong, I've
00407 // taken the branch functionality out of public view, and encapsulate
00408 // it in the appendMenu() method.
00409 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00410 
00411 class LLMenuArrowGL;
00412 class LLMenuItemBranchGL;
00413 class LLMenuItemTearOffGL;
00414 
00415 class LLMenuGL 
00416 :       public LLUICtrl
00417 {
00418 public:
00419         LLMenuGL( const LLString& name, const LLString& label, LLViewHandle parent_floater = LLViewHandle::sDeadHandle );
00420         LLMenuGL( const LLString& label, LLViewHandle parent_floater = LLViewHandle::sDeadHandle );
00421         virtual ~LLMenuGL( void );
00422         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00423         static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00424 
00425         void parseChildXML(LLXMLNodePtr child, LLView *parent, LLUICtrlFactory *factory);
00426 
00427         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU; }
00428         virtual LLString getWidgetTag() const { return LL_MENU_GL_TAG; }
00429 
00430         // LLView Functionality
00431         virtual BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent );
00432         //virtual BOOL handleKeyHere( KEY key, MASK mask, BOOL called_from_parent );
00433         virtual BOOL handleUnicodeCharHere( llwchar uni_char, BOOL called_from_parent );
00434         virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00435         virtual void draw( void );
00436         virtual void drawBackground(LLMenuItemGL* itemp, LLColor4& color);
00437         virtual void setVisible(BOOL visible);
00438 
00439         virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
00440 
00441         LLMenuGL* getChildMenuByName(const LLString& name, BOOL recurse) const;
00442         
00443         BOOL clearHoverItem();
00444 
00445         // return the name label
00446         const LLString& getLabel( void ) const { return mLabel.getString(); }
00447         void setLabel(const LLStringExplicit& label) { mLabel = label; }
00448 
00449         static void setDefaultBackgroundColor( const LLColor4& color );
00450         void setBackgroundColor( const LLColor4& color );
00451         LLColor4 getBackgroundColor();
00452         void setBackgroundVisible( BOOL b )     { mBgVisible = b; }
00453         void setCanTearOff(BOOL tear_off, LLViewHandle parent_floater_handle = LLViewHandle::sDeadHandle);
00454 
00455         // Add the menu item to this menu.
00456         virtual BOOL append( LLMenuItemGL* item );
00457 
00458         // add a separator to this menu
00459         virtual BOOL appendSeparator( const LLString &separator_name = "separator" );
00460 
00461         // add a menu - this will create a cascading menu
00462         virtual BOOL appendMenu( LLMenuGL* menu );
00463 
00464         // for branching menu items, bring sub menus up to root level of menu hierarchy
00465         virtual void updateParent( LLView* parentp );
00466 
00467         // setItemEnabled() - pass the name and the enable flag for a
00468         // menu item. TRUE will make sure it's enabled, FALSE will disable
00469         // it.
00470         void setItemEnabled( const LLString& name, BOOL enable ); 
00471         
00472         // propagate message to submenus
00473         void setEnabledSubMenus(BOOL enable);
00474 
00475         void setItemVisible( const LLString& name, BOOL visible);
00476         
00477         // sets the left,bottom corner of menu, useful for popups
00478         void setLeftAndBottom(S32 left, S32 bottom);
00479 
00480         virtual BOOL handleJumpKey(KEY key);
00481 
00482         virtual BOOL jumpKeysActive();
00483 
00484         virtual BOOL isOpen();
00485 
00486         // Shape this menu to fit the current state of the children, and
00487         // adjust the child rects to fit. This is called automatically
00488         // when you add items. *FIX: We may need to deal with visibility
00489         // arrangement.
00490         virtual void arrange( void );
00491 
00492         // remove all items on the menu
00493         void empty( void );
00494 
00495         // Rearrange the components, and do the right thing if the menu doesn't
00496         // fit in the bounds.
00497         // virtual void arrangeWithBounds(LLRect bounds);
00498 
00499         void                    setItemLastSelected(LLMenuItemGL* item);        // must be in menu
00500         U32                             getItemCount();                         // number of menu items
00501         LLMenuItemGL*   getItem(S32 number);            // 0 = first item
00502         LLMenuItemGL*   getHighlightedItem();                           
00503 
00504         LLMenuItemGL*   highlightNextItem(LLMenuItemGL* cur_item, BOOL skip_disabled = TRUE);
00505         LLMenuItemGL*   highlightPrevItem(LLMenuItemGL* cur_item, BOOL skip_disabled = TRUE);
00506 
00507         void buildDrawLabels();
00508         void createJumpKeys();
00509 
00510         // Show popup in global screen space based on last mouse location.
00511         static void showPopup(LLMenuGL* menu);
00512 
00513         // Show popup at a specific location.
00514         static void showPopup(LLView* spawning_view, LLMenuGL* menu, S32 x, S32 y);
00515 
00516         // Whether to drop shadow menu bar 
00517         void setDropShadowed( const BOOL shadowed );
00518 
00519         void setParentMenuItem( LLMenuItemGL* parent_menu_item ) { mParentMenuItem = parent_menu_item; }
00520         LLMenuItemGL* getParentMenuItem() { return mParentMenuItem; }
00521 
00522         void setTornOff(BOOL torn_off);
00523         BOOL getTornOff() { return mTornOff; }
00524 
00525         BOOL getCanTearOff() { return mTearOffItem != NULL; }
00526 
00527         KEY getJumpKey() { return mJumpKey; }
00528         void setJumpKey(KEY key) { mJumpKey = key; }
00529 
00530         static void setKeyboardMode(BOOL mode) { sKeyboardMode = mode; }
00531         static BOOL getKeyboardMode() { return sKeyboardMode; }
00532 
00533         static void onFocusLost(LLView* old_focus);
00534 
00535         static LLMenuHolderGL* sMenuContainer;
00536         
00537 protected:
00538         void createSpilloverBranch();
00539         void cleanupSpilloverBranch();
00540 
00541 protected:
00542         static LLColor4 sDefaultBackgroundColor;
00543         static BOOL             sKeyboardMode;
00544 
00545         LLColor4                mBackgroundColor;
00546         BOOL                    mBgVisible;
00547         typedef std::list< LLMenuItemGL* > item_list_t;
00548         item_list_t mItems;
00549         typedef std::map<KEY, LLMenuItemGL*> navigation_key_map_t;
00550         navigation_key_map_t mJumpKeys;
00551         LLMenuItemGL*   mParentMenuItem;
00552         LLUIString              mLabel;
00553         BOOL mDropShadowed;     //  Whether to drop shadow 
00554         BOOL                    mHorizontalLayout;
00555         BOOL                    mKeepFixedSize;
00556         BOOL                    mHasSelection;
00557         LLFrameTimer    mFadeTimer;
00558         S32                             mLastMouseX;
00559         S32                             mLastMouseY;
00560         S32                             mMouseVelX;
00561         S32                             mMouseVelY;
00562         BOOL                    mTornOff;
00563         LLMenuItemTearOffGL* mTearOffItem;
00564         LLMenuItemBranchGL* mSpilloverBranch;
00565         LLMenuGL*               mSpilloverMenu;
00566         LLViewHandle    mParentFloaterHandle;
00567         KEY                             mJumpKey;
00568 };
00569 
00570 
00571 
00572 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00573 // Class LLMenuItemBranchGL
00574 //
00575 // The LLMenuItemBranchGL represents a menu item that has a
00576 // sub-menu. This is used to make cascading menus.
00577 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00578 
00579 class LLMenuItemBranchGL : public LLMenuItemGL
00580 {
00581 protected:
00582         LLMenuGL* mBranch;
00583 
00584 public:
00585         LLMenuItemBranchGL( const LLString& name, const LLString& label, LLMenuGL* branch,
00586                                                 KEY key = KEY_NONE, MASK mask = MASK_NONE );
00587         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00588 
00589         virtual LLView* getChildByName(const LLString& name, BOOL recurse) const;
00590 
00591         virtual LLString getType() const        { return "menu"; }
00592 
00593         virtual EWidgetType getWidgetType() const;
00594         virtual LLString getWidgetTag() const;
00595 
00596         virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
00597 
00598         virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
00599 
00600         // check if we've used these accelerators already
00601         virtual BOOL addToAcceleratorList(std::list <LLKeyBinding*> *listp);
00602 
00603         // called to rebuild the draw label
00604         virtual void buildDrawLabel( void );
00605 
00606         // doIt() - do the primary funcationality of the menu item.
00607         virtual void doIt( void );
00608 
00609         virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
00610         virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
00611 
00612         // set the hover status (called by it's menu) and if the object is
00613         // active. This is used for behavior transfer.
00614         virtual void setHighlight( BOOL highlight );
00615 
00616         virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00617 
00618         virtual BOOL isActive() const;
00619 
00620         virtual BOOL isOpen() const;
00621 
00622         LLMenuGL *getBranch() const { return mBranch; }
00623 
00624         virtual void updateBranchParent( LLView* parentp );
00625 
00626         // LLView Functionality
00627         virtual void onVisibilityChange( BOOL curVisibilityIn );
00628 
00629         virtual void draw();
00630 
00631         virtual void setEnabledSubMenus(BOOL enabled);
00632 
00633         virtual void openMenu();
00634 };
00635 
00636 
00637 
00638 
00639 //-----------------------------------------------------------------------------
00640 // class LLPieMenu
00641 // A circular menu of items, icons, etc.
00642 //-----------------------------------------------------------------------------
00643 
00644 class LLPieMenu
00645 : public LLMenuGL
00646 {
00647 public:
00648         LLPieMenu(const LLString& name, const LLString& label);
00649         LLPieMenu(const LLString& name);
00650         virtual ~LLPieMenu();
00651 
00652         virtual EWidgetType getWidgetType() const;
00653         virtual LLString getWidgetTag() const;
00654 
00655         void initXML(LLXMLNodePtr node, LLView *context, LLUICtrlFactory *factory);
00656 
00657         // LLView Functionality
00658         // can't set visibility directly, must call show or hide
00659         virtual void setVisible(BOOL visible);
00660         
00661         //virtual BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent );
00662         virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00663         virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00664         virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
00665         virtual BOOL handleRightMouseUp( S32 x, S32 y, MASK mask );
00666         virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00667         virtual void draw();
00668         virtual void drawBackground(LLMenuItemGL* itemp, LLColor4& color);
00669 
00670         virtual BOOL append(LLMenuItemGL* item);
00671         virtual BOOL appendSeparator( const LLString &separator_name = "separator" );
00672 
00673         // the enabled callback is meant for the submenu. The api works
00674         // this way because the menu branch item responsible for the pie
00675         // submenu is constructed here.
00676         virtual BOOL appendMenu(LLPieMenu *menu,
00677                                                         enabled_callback enabled_cb = NULL,
00678                                                         void* user_data = NULL );
00679         virtual void arrange( void );
00680 
00681         // Display the menu centered on this point on the screen.
00682         void show(S32 x, S32 y, BOOL mouse_down);
00683         void hide(BOOL item_selected);
00684 
00685 protected:
00686         LLMenuItemGL *pieItemFromXY(S32 x, S32 y);
00687         S32                       pieItemIndexFromXY(S32 x, S32 y);
00688 
00689 private:
00690         // These cause menu items to be spuriously selected by right-clicks
00691         // near the window edge at low frame rates.  I don't think they are
00692         // needed unless you shift the menu position in the draw() function. JC
00693         //S32                           mShiftHoriz;    // non-zero if menu had to shift this frame
00694         //S32                           mShiftVert;             // non-zero if menu had to shift this frame
00695         BOOL                    mFirstMouseDown;        // true from show until mouse up
00696         BOOL                    mUseInfiniteRadius;     // allow picking pie menu items anywhere outside of center circle
00697         LLMenuItemGL*   mHoverItem;
00698         BOOL                    mHoverThisFrame;
00699         BOOL                    mHoveredAnyItem;
00700         LLFrameTimer    mShrinkBorderTimer;
00701         F32                             mOuterRingAlpha; // for rendering pie menus as both bounded and unbounded
00702         F32                             mCurRadius;
00703         BOOL                    mRightMouseDown;
00704 };
00705 
00706 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00707 // Class LLMenuBarGL
00708 //
00709 // A menu bar displays menus horizontally.
00710 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00711 
00712 class LLMenuBarGL : public LLMenuGL
00713 {
00714 protected:
00715         std::list <LLKeyBinding*>       mAccelerators;
00716         BOOL                                            mAltKeyTrigger;
00717 
00718 public:
00719         LLMenuBarGL( const LLString& name );
00720         virtual ~LLMenuBarGL();
00721         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00722         static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00723 
00724         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_MENU_BAR; }
00725         virtual LLString getWidgetTag() const { return LL_MENU_BAR_GL_TAG; }
00726 
00727         virtual BOOL handleAcceleratorKey(KEY key, MASK mask);
00728         virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00729         virtual BOOL handleJumpKey(KEY key);
00730 
00731         // rearrange the child rects so they fit the shape of the menu
00732         // bar.
00733         virtual void arrange( void );
00734         virtual void draw();
00735         virtual BOOL jumpKeysActive();
00736 
00737         // add a vertical separator to this menu
00738         virtual BOOL appendSeparator( const LLString &separator_name = "separator" );
00739 
00740         // add a menu - this will create a drop down menu.
00741         virtual BOOL appendMenu( LLMenuGL* menu );
00742 
00743         // LLView Functionality
00744         virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00745 
00746         // Returns x position of rightmost child, usually Help menu
00747         S32 getRightmostMenuEdge();
00748 
00749         void resetMenuTrigger() { mAltKeyTrigger = FALSE; }
00750 
00751 protected:
00752         void checkMenuTrigger();
00753 
00754 };
00755 
00756 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00757 // Class LLMenuHolderGL
00758 //
00759 // High level view that serves as parent for all menus
00760 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00761 class LLMenuHolderGL : public LLPanel
00762 {
00763 public:
00764         LLMenuHolderGL();
00765         LLMenuHolderGL(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows = FOLLOWS_NONE);
00766         virtual ~LLMenuHolderGL();
00767 
00768         virtual EWidgetType getWidgetType() const;
00769         virtual LLString getWidgetTag() const;
00770 
00771         virtual BOOL hideMenus();
00772         void reshape(S32 width, S32 height, BOOL called_from_parent);
00773         void setCanHide(BOOL can_hide) { mCanHide = can_hide; }
00774 
00775         // LLView functionality
00776         virtual void draw();
00777         virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00778         virtual BOOL handleRightMouseDown( S32 x, S32 y, MASK mask );
00779 
00780         virtual const LLRect getMenuRect() const;
00781         virtual BOOL hasVisibleMenu() const;
00782 
00783         static void setActivatedItem(LLMenuItemGL* item);
00784 
00785 protected:
00786         static LLViewHandle sItemLastSelectedHandle;
00787         static LLFrameTimer sItemActivationTimer;
00788 
00789         BOOL mCanHide;
00790 };
00791 
00792 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00793 // Class LLTearOffMenu
00794 //
00795 // Floater that hosts a menu
00796 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00797 class LLTearOffMenu : public LLFloater
00798 {
00799 public:
00800         static LLTearOffMenu* create(LLMenuGL* menup);
00801         virtual ~LLTearOffMenu();
00802         virtual void onClose(bool app_quitting);
00803         virtual void draw(void);
00804         virtual void onFocusReceived();
00805         virtual void onFocusLost();
00806         virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
00807         virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
00808         virtual void translate(S32 x, S32 y);
00809 
00810 protected:
00811         LLTearOffMenu(LLMenuGL* menup);
00812 
00813 protected:
00814         LLView*         mOldParent;
00815         LLMenuGL*       mMenu;
00816         F32                     mTargetHeight;
00817 };
00818 
00819 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00820 // Class LLMenuItemTearOffGL
00821 //
00822 // This class represents a separator.
00823 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00824 
00825 class LLMenuItemTearOffGL : public LLMenuItemGL
00826 {
00827 public:
00828         LLMenuItemTearOffGL( LLViewHandle parent_floater_handle = (LLViewHandle)LLViewHandle::sDeadHandle );
00829 
00830         virtual EWidgetType getWidgetType() const;
00831         virtual LLString getWidgetTag() const;
00832 
00833         virtual LLString getType() const        { return "tearoff_menu"; }
00834 
00835         virtual void doIt(void);
00836         virtual void draw(void);
00837         virtual U32 getNominalHeight();
00838 
00839 protected:
00840         LLViewHandle mParentHandle;
00841 };
00842 
00843 
00844 // *TODO: this is currently working, so finish implementation
00845 class LLEditMenuHandlerMgr
00846 {
00847 public:
00848         LLEditMenuHandlerMgr& getInstance();
00849         virtual ~LLEditMenuHandlerMgr();
00850 protected:
00851         LLEditMenuHandlerMgr();
00852 
00853 };
00854 
00855 #endif // LL_LLMENUGL_H

Generated on Thu Jul 1 06:08:53 2010 for Second Life Viewer by  doxygen 1.4.7