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

Generated on Fri May 16 08:32:54 2008 for SecondLife by  doxygen 1.5.5