llfloater.h

Go to the documentation of this file.
00001 
00032 // Floating "windows" within the GL display, like the inventory floater,
00033 // mini-map floater, etc.
00034 
00035 
00036 #ifndef LL_FLOATER_H
00037 #define LL_FLOATER_H
00038 
00039 #include "llpanel.h"
00040 #include "lluuid.h"
00041 #include "lltabcontainer.h"
00042 #include <set>
00043 
00044 class LLDragHandle;
00045 class LLResizeHandle;
00046 class LLResizeBar;
00047 class LLButton;
00048 class LLMultiFloater;
00049 
00050 const S32 LLFLOATER_VPAD = 6;
00051 const S32 LLFLOATER_HPAD = 6;
00052 const S32 LLFLOATER_CLOSE_BOX_SIZE = 16;
00053 const S32 LLFLOATER_HEADER_SIZE = 18;
00054 
00055 const BOOL RESIZE_YES = TRUE;
00056 const BOOL RESIZE_NO = FALSE;
00057 
00058 const S32 DEFAULT_MIN_WIDTH = 100;
00059 const S32 DEFAULT_MIN_HEIGHT = 100;
00060 
00061 const BOOL DRAG_ON_TOP = FALSE;
00062 const BOOL DRAG_ON_LEFT = TRUE;
00063 
00064 const BOOL MINIMIZE_YES = TRUE;
00065 const BOOL MINIMIZE_NO = FALSE;
00066 
00067 const BOOL CLOSE_YES = TRUE;
00068 const BOOL CLOSE_NO = FALSE;
00069 
00070 const BOOL ADJUST_VERTICAL_YES = TRUE;
00071 const BOOL ADJUST_VERTICAL_NO = FALSE;
00072 
00073 
00074 class LLFloater : public LLPanel
00075 {
00076 friend class LLFloaterView;
00077 public:
00078         enum EFloaterButtons
00079         {
00080                 BUTTON_CLOSE,
00081                 BUTTON_RESTORE,
00082                 BUTTON_MINIMIZE,
00083                 BUTTON_TEAR_OFF,
00084                 BUTTON_EDIT,
00085                 BUTTON_COUNT
00086         };
00087         
00088         LLFloater();
00089         LLFloater(const LLString& name); //simple constructor for data-driven initialization
00090         LLFloater(      const LLString& name, const LLRect& rect, const LLString& title,
00091                 BOOL resizable = FALSE,
00092                 S32 min_width = DEFAULT_MIN_WIDTH,
00093                 S32 min_height = DEFAULT_MIN_HEIGHT,
00094                 BOOL drag_on_left = FALSE,
00095                 BOOL minimizable = TRUE,
00096                 BOOL close_btn = TRUE,
00097                 BOOL bordered = BORDER_NO);
00098 
00099         LLFloater(      const LLString& name, const LLString& rect_control, const LLString& title,
00100                 BOOL resizable = FALSE,
00101                 S32 min_width = DEFAULT_MIN_WIDTH, 
00102                 S32 min_height = DEFAULT_MIN_HEIGHT,
00103                 BOOL drag_on_left = FALSE,
00104                 BOOL minimizable = TRUE,
00105                 BOOL close_btn = TRUE,
00106                 BOOL bordered = BORDER_NO);
00107 
00108         virtual ~LLFloater();
00109 
00110         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00111         static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00112         void initFloaterXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory, BOOL open = TRUE);
00113 
00114         /*virtual*/ void userSetShape(const LLRect& new_rect);
00115         /*virtual*/ BOOL canSnapTo(const LLView* other_view);
00116         /*virtual*/ void snappedTo(const LLView* snap_view);
00117         /*virtual*/ void setFocus( BOOL b );
00118         /*virtual*/ void setIsChrome(BOOL is_chrome);
00119 
00120         // Can be called multiple times to reset floater parameters.
00121         // Deletes all children of the floater.
00122         virtual void            initFloater(const LLString& title, BOOL resizable, 
00123                                                 S32 min_width, S32 min_height, BOOL drag_on_left,
00124                                                 BOOL minimizable, BOOL close_btn);
00125 
00126         virtual void    open(); /* Flawfinder: ignore */
00127 
00128         // If allowed, close the floater cleanly, releasing focus.
00129         // app_quitting is passed to onClose() below.
00130         virtual void    close(bool app_quitting = false);
00131 
00132         /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
00133         
00134         // Release keyboard and mouse focus
00135         void                    releaseFocus();
00136 
00137         // moves to center of gFloaterView
00138         void                    center();
00139         // applies rectangle stored in mRectControl, if any
00140         void                    applyRectControl();
00141 
00142 
00143         LLMultiFloater* getHost() { return (LLMultiFloater*)mHostHandle.get(); }
00144 
00145         void                    setTitle( const LLString& title );
00146         const LLString& getTitle() const;
00147         void                    setShortTitle( const LLString& short_title );
00148         LLString                getShortTitle();
00149         void                    setTitleVisible(bool visible);
00150         virtual void    setMinimized(BOOL b);
00151         void                    moveResizeHandlesToFront();
00152         void                    addDependentFloater(LLFloater* dependent, BOOL reposition = TRUE);
00153         void                    addDependentFloater(LLHandle<LLFloater> dependent_handle, BOOL reposition = TRUE);
00154         LLFloater*      getDependee() { return (LLFloater*)mDependeeHandle.get(); }
00155         void            removeDependentFloater(LLFloater* dependent);
00156         BOOL                    isMinimized()                                   { return mMinimized; }
00157         BOOL                    isFrontmost();
00158         BOOL                    isDependent()                                   { return !mDependeeHandle.isDead(); }
00159         void                    setCanMinimize(BOOL can_minimize);
00160         void                    setCanClose(BOOL can_close);
00161         void                    setCanTearOff(BOOL can_tear_off);
00162         virtual void    setCanResize(BOOL can_resize);
00163         void                    setCanDrag(BOOL can_drag);
00164         void                    setHost(LLMultiFloater* host);
00165         BOOL                    isResizable() const                             { return mResizable; }
00166         void                    setResizeLimits( S32 min_width, S32 min_height );
00167         void                    getResizeLimits( S32* min_width, S32* min_height ) { *min_width = mMinWidth; *min_height = mMinHeight; }
00168 
00169         bool                    isMinimizeable() const{ return mButtonsEnabled[BUTTON_MINIMIZE]; }
00170         // Does this window have a close button, NOT can we close it right now.
00171         bool                    isCloseable() const{ return (mButtonsEnabled[BUTTON_CLOSE]); }
00172         bool                    isDragOnLeft() const{ return mDragOnLeft; }
00173         S32                             getMinWidth() const{ return mMinWidth; }
00174         S32                             getMinHeight() const{ return mMinHeight; }
00175 
00176         virtual BOOL    handleMouseDown(S32 x, S32 y, MASK mask);
00177         virtual BOOL    handleRightMouseDown(S32 x, S32 y, MASK mask);
00178         virtual BOOL    handleDoubleClick(S32 x, S32 y, MASK mask);
00179 
00180         virtual void    draw();
00181 
00182         virtual void    onOpen() {}
00183 
00184         // Call destroy() to free memory, or setVisible(FALSE) to keep it
00185         // If app_quitting, you might not want to save your visibility.
00186         // Defaults to destroy().
00187         virtual void    onClose(bool app_quitting) { destroy(); }
00188 
00189         // This cannot be "const" until all derived floater canClose()
00190         // methods are const as well.  JC
00191         virtual BOOL    canClose() { return TRUE; }
00192 
00193         virtual void    setVisible(BOOL visible);
00194         void                    setFrontmost(BOOL take_focus = TRUE);
00195 
00196         // Defaults to false.
00197         virtual BOOL    canSaveAs() const { return FALSE; }
00198 
00199         virtual void    saveAs() {}
00200 
00201         void                    setSnapTarget(LLHandle<LLFloater> handle) { mSnappedTo = handle; }
00202         void                    clearSnapTarget() { mSnappedTo.markDead(); }
00203         LLHandle<LLFloater>     getSnapTarget() { return mSnappedTo; }
00204 
00205         LLHandle<LLFloater> getHandle() { return mHandle; }
00206 
00207         static void             closeFocusedFloater();
00208 
00209         static void             onClickClose(void *userdata);
00210         static void             onClickMinimize(void *userdata);
00211         static void             onClickTearOff(void *userdata);
00212         static void             onClickEdit(void *userdata);
00213 
00214         static void             setFloaterHost(LLMultiFloater* hostp) {sHostp = hostp; }
00215         static void             setEditModeEnabled(BOOL enable);
00216         static BOOL             getEditModeEnabled() { return sEditModeEnabled; }
00217         static LLMultiFloater*          getFloaterHost() {return sHostp; }
00218 
00219 protected:
00220 
00221         virtual void    bringToFront(S32 x, S32 y);
00222         virtual void    setVisibleAndFrontmost(BOOL take_focus=TRUE);    
00223         
00224         void            setExpandedRect(const LLRect& rect) { mExpandedRect = rect; } // size when not minimized
00225     const LLRect&    getExpandedRect() const { return mExpandedRect; }
00226 
00227         void                    setAutoFocus(BOOL focus) { mAutoFocus = focus; } // whether to automatically take focus when opened
00228         LLDragHandle*   getDragHandle() const { return mDragHandle; }
00229 
00230         void                    destroy() { die(); } // Don't call this directly.  You probably want to call close(). JC
00231 
00232 private:
00233         
00234         void                    setForeground(BOOL b);  // called only by floaterview
00235         void                    cleanupHandles(); // remove handles to dead floaters
00236         void                    createMinimizeButton();
00237         void                    updateButtons();
00238         void                    buildButtons();
00239 
00240         LLRect                  mExpandedRect;
00241         LLDragHandle*   mDragHandle;
00242         LLResizeBar*    mResizeBar[4];
00243         LLResizeHandle* mResizeHandle[4];
00244         LLButton                *mMinimizeButton;
00245         BOOL                    mCanTearOff;
00246         BOOL                    mMinimized;
00247         BOOL                    mForeground;
00248         LLHandle<LLFloater>     mDependeeHandle;
00249         LLString                mShortTitle;
00250 
00251         BOOL                    mFirstLook;                     // TRUE if the _next_ time this floater is visible will be the first time in the session that it is visible.
00252 
00253         BOOL                    mResizable;
00254         S32                             mMinWidth;
00255         S32                             mMinHeight;
00256 
00257         BOOL                    mEditing;
00258         
00259         typedef std::set<LLHandle<LLFloater> > handle_set_t;
00260         typedef std::set<LLHandle<LLFloater> >::iterator handle_set_iter_t;
00261         handle_set_t    mDependents;
00262         bool            mDragOnLeft;
00263 
00264         BOOL                    mButtonsEnabled[BUTTON_COUNT];
00265         LLButton*               mButtons[BUTTON_COUNT];
00266         F32                             mButtonScale;
00267         BOOL                    mAutoFocus;
00268         LLHandle<LLFloater> mSnappedTo;
00269         
00270         LLHandle<LLFloater> mHostHandle;
00271         LLHandle<LLFloater> mLastHostHandle;
00272 
00273         static LLMultiFloater* sHostp;
00274         static BOOL             sEditModeEnabled;
00275         static LLString sButtonActiveImageNames[BUTTON_COUNT];
00276         static LLString sButtonInactiveImageNames[BUTTON_COUNT];
00277         static LLString sButtonPressedImageNames[BUTTON_COUNT];
00278         static LLString sButtonNames[BUTTON_COUNT];
00279         static LLString sButtonToolTips[BUTTON_COUNT];
00280         typedef void (*click_callback)(void *);
00281         static click_callback sButtonCallbacks[BUTTON_COUNT];
00282 
00283         typedef std::map<LLHandle<LLFloater>, LLFloater*> handle_map_t;
00284         typedef std::map<LLHandle<LLFloater>, LLFloater*>::iterator handle_map_iter_t;
00285         static handle_map_t     sFloaterMap;
00286 
00287         std::vector<LLHandle<LLView> > mMinimizedHiddenChildren;
00288 
00289         BOOL                    mHasBeenDraggedWhileMinimized;
00290         S32                             mPreviousMinimizedBottom;
00291         S32                             mPreviousMinimizedLeft;
00292         
00293 private:
00294         LLRootHandle<LLFloater>         mHandle;        
00295 };
00296 
00298 // LLFloaterView
00299 // Parent of all floating panels
00300 
00301 class LLFloaterView : public LLUICtrl
00302 {
00303 public:
00304         LLFloaterView( const LLString& name, const LLRect& rect );
00305 
00306         /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
00307         void reshapeFloater(S32 width, S32 height, BOOL called_from_parent, BOOL adjust_vertical);
00308 
00309         /*virtual*/ void draw();
00310         /*virtual*/ LLRect getSnapRect() const;
00311         void refresh();
00312 
00313         void                    getNewFloaterPosition( S32* left, S32* top );
00314         void                    resetStartingFloaterPosition();
00315         LLRect                  findNeighboringPosition( LLFloater* reference_floater, LLFloater* neighbor );
00316 
00317         // Given a child of gFloaterView, make sure this view can fit entirely onscreen.
00318         void                    adjustToFitScreen(LLFloater* floater, BOOL allow_partial_outside);
00319 
00320         void                    getMinimizePosition( S32 *left, S32 *bottom);
00321         void                    restoreAll();           // un-minimize all floaters
00322         typedef std::set<LLView*> skip_list_t;
00323         void pushVisibleAll(BOOL visible, const skip_list_t& skip_list = skip_list_t());
00324         void popVisibleAll(const skip_list_t& skip_list = skip_list_t());
00325 
00326         void                    setCycleMode(BOOL mode) { mFocusCycleMode = mode; }
00327         BOOL                    getCycleMode() const { return mFocusCycleMode; }
00328         void                    bringToFront( LLFloater* child, BOOL give_focus = TRUE );
00329         void                    highlightFocusedFloater();
00330         void                    unhighlightFocusedFloater();
00331         void                    focusFrontFloater();
00332         void                    destroyAllChildren();
00333         // attempt to close all floaters
00334         void                    closeAllChildren(bool app_quitting);
00335         BOOL                    allChildrenClosed();
00336 
00337         LLFloater* getFrontmost();
00338         LLFloater* getBackmost();
00339         LLFloater* getParentFloater(LLView* viewp);
00340         LLFloater* getFocusedFloater();
00341         void            syncFloaterTabOrder();
00342 
00343         // Returns z order of child provided. 0 is closest, larger numbers
00344         // are deeper in the screen. If there is no such child, the return
00345         // value is not defined.
00346         S32 getZOrder(LLFloater* child);
00347 
00348         void setSnapOffsetBottom(S32 offset) { mSnapOffsetBottom = offset; }
00349 
00350 private:
00351         S32                             mColumn;
00352         S32                             mNextLeft;
00353         S32                             mNextTop;
00354         BOOL                    mFocusCycleMode;
00355         S32                             mSnapOffsetBottom;
00356 };
00357 
00358 // https://wiki.lindenlab.com/mediawiki/index.php?title=LLMultiFloater&oldid=81376
00359 class LLMultiFloater : public LLFloater
00360 {
00361 public:
00362         LLMultiFloater();
00363         LLMultiFloater(LLTabContainer::TabPosition tab_pos);
00364         LLMultiFloater(const LLString& name);
00365         LLMultiFloater(const LLString& name, const LLRect& rect, LLTabContainer::TabPosition tab_pos = LLTabContainer::TOP, BOOL auto_resize = TRUE);
00366         LLMultiFloater(const LLString& name, const LLString& rect_control, LLTabContainer::TabPosition tab_pos = LLTabContainer::TOP, BOOL auto_resize = TRUE);
00367         virtual ~LLMultiFloater() {};
00368 
00369         virtual BOOL postBuild();
00370         /*virtual*/ void open();        /* Flawfinder: ignore */
00371         /*virtual*/ void onClose(bool app_quitting);
00372         /*virtual*/ void draw();
00373         /*virtual*/ void setVisible(BOOL visible);
00374         /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask);
00375 
00376         virtual void setCanResize(BOOL can_resize);
00377         virtual void growToFit(S32 content_width, S32 content_height);
00378         virtual void addFloater(LLFloater* floaterp, BOOL select_added_floater, LLTabContainer::eInsertionPoint insertion_point = LLTabContainer::END);
00379 
00380         virtual void showFloater(LLFloater* floaterp);
00381         virtual void removeFloater(LLFloater* floaterp);
00382 
00383         virtual void tabOpen(LLFloater* opened_floater, bool from_click);
00384         virtual void tabClose();
00385 
00386         virtual BOOL selectFloater(LLFloater* floaterp);
00387         virtual void selectNextFloater();
00388         virtual void selectPrevFloater();
00389 
00390         virtual LLFloater* getActiveFloater();
00391         virtual BOOL       isFloaterFlashing(LLFloater* floaterp);
00392         virtual S32                     getFloaterCount();
00393 
00394         virtual void setFloaterFlashing(LLFloater* floaterp, BOOL flashing);
00395         virtual BOOL closeAllFloaters();        //Returns FALSE if the floater could not be closed due to pending confirmation dialogs
00396         void setTabContainer(LLTabContainer* tab_container) { if (!mTabContainer) mTabContainer = tab_container; }
00397         static void onTabSelected(void* userdata, bool);
00398 
00399         virtual void updateResizeLimits();
00400 
00401 protected:
00402         struct LLFloaterData
00403         {
00404                 S32             mWidth;
00405                 S32             mHeight;
00406                 BOOL    mCanMinimize;
00407                 BOOL    mCanResize;
00408         };
00409 
00410         LLTabContainer*         mTabContainer;
00411         
00412         typedef std::map<LLHandle<LLFloater>, LLFloaterData> floater_data_map_t;
00413         floater_data_map_t      mFloaterDataMap;
00414         
00415         LLTabContainer::TabPosition mTabPos;
00416         BOOL                            mAutoResize;
00417         S32                                     mOrigMinWidth, mOrigMinHeight;  // logically const but initialized late
00418 };
00419 
00420 // visibility policy specialized for floaters
00421 template<>
00422 class VisibilityPolicy<LLFloater>
00423 {
00424 public:
00425         // visibility methods
00426         static bool visible(LLFloater* instance, const LLSD& key)
00427         {
00428                 if (instance) 
00429                 {
00430                         return !instance->isMinimized() && instance->isInVisibleChain();
00431                 }
00432                 return FALSE;
00433         }
00434 
00435         static void show(LLFloater* instance, const LLSD& key)
00436         {
00437                 if (instance) 
00438                 {
00439                         instance->open();
00440                         if (instance->getHost())
00441                         {
00442                                 instance->getHost()->open();
00443                         }
00444                 }
00445         }
00446 
00447         static void hide(LLFloater* instance, const LLSD& key)
00448         {
00449                 if (instance) instance->close();
00450         }
00451 };
00452 
00453 
00454 // singleton implementation for floaters (provides visibility policy)
00455 // https://wiki.lindenlab.com/mediawiki/index.php?title=LLFloaterSingleton&oldid=79410
00456 
00457 template <class T> class LLFloaterSingleton : public LLUISingleton<T, VisibilityPolicy<LLFloater> >
00458 {
00459 };
00460 
00461 
00462 extern LLFloaterView* gFloaterView;
00463 
00464 #endif  // LL_FLOATER_H
00465 
00466 
00467 

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