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 = 16;
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(LLView* other_view);
00116         /*virtual*/ void snappedTo(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            init(const LLString& title, BOOL resizable, 
00123                                                 S32 min_width, S32 min_height, BOOL drag_on_left,
00124                                                 BOOL minimizable, BOOL close_btn);
00125         virtual EWidgetType getWidgetType() const;
00126         virtual LLString getWidgetTag() const;
00127 
00128         virtual void    open(); /* Flawfinder: ignore */
00129 
00130         // If allowed, close the floater cleanly, releasing focus.
00131         // app_quitting is passed to onClose() below.
00132         virtual void    close(bool app_quitting = false);
00133 
00134         void                    setAutoFocus(BOOL focus) { mAutoFocus = focus; setFocus(focus); }
00135         
00136         // Release keyboard and mouse focus
00137         void                    releaseFocus();
00138 
00139         // moves to center of gFloaterView
00140         void                    center();
00141         // applies rectangle stored in mRectControl, if any
00142         void                    applyRectControl();
00143 
00144 
00145         LLMultiFloater* getHost() { return (LLMultiFloater*)LLFloater::getFloaterByHandle(mHostHandle); }
00146 
00147         void                    setTitle( const LLString& title );
00148         const LLString&         getTitle() const;
00149         void                    setShortTitle( const LLString& short_title );
00150         LLString                getShortTitle();
00151         virtual void    setMinimized(BOOL b);
00152         void                    moveResizeHandlesToFront();
00153         void                    addDependentFloater(LLFloater* dependent, BOOL reposition = TRUE);
00154         void                    addDependentFloater(LLViewHandle dependent_handle, BOOL reposition = TRUE);
00155         LLFloater*              getDependee() { return (LLFloater*)LLFloater::getFloaterByHandle(mDependeeHandle); }
00156         void                    removeDependentFloater(LLFloater* dependent);
00157         BOOL                    isMinimized()                                   { return mMinimized; }
00158         BOOL                    isFrontmost();
00159         BOOL                    isDependent()                                   { return !mDependeeHandle.isDead(); }
00160         void                    setCanMinimize(BOOL can_minimize);
00161         void                    setCanClose(BOOL can_close);
00162         void                    setCanTearOff(BOOL can_tear_off);
00163         virtual void    setCanResize(BOOL can_resize);
00164         void                    setCanDrag(BOOL can_drag);
00165         void                    setHost(LLMultiFloater* host);
00166         BOOL                    isResizable() const                             { return mResizable; }
00167         void                    setResizeLimits( S32 min_width, S32 min_height );
00168         void                    getResizeLimits( S32* min_width, S32* min_height ) { *min_width = mMinWidth; *min_height = mMinHeight; }
00169 
00170 
00171         bool                    isMinimizeable() const{ return mButtonsEnabled[BUTTON_MINIMIZE]; }
00172         // Does this window have a close button, NOT can we close it right now.
00173         bool                    isCloseable() const{ return (mButtonsEnabled[BUTTON_CLOSE] ? true : false); }
00174         bool                    isDragOnLeft() const{ return mDragOnLeft; }
00175         S32                             getMinWidth() const{ return mMinWidth; }
00176         S32                             getMinHeight() const{ return mMinHeight; }
00177 
00178         virtual BOOL    handleMouseDown(S32 x, S32 y, MASK mask);
00179         virtual BOOL    handleRightMouseDown(S32 x, S32 y, MASK mask);
00180         virtual BOOL    handleDoubleClick(S32 x, S32 y, MASK mask);
00181 
00182         virtual void    draw();
00183 
00184         // does nothing by default
00185         virtual void    onOpen();
00186 
00187         // Call destroy() to free memory, or setVisible(FALSE) to keep it
00188         // If app_quitting, you might not want to save your visibility.
00189         // Defaults to destroy().
00190         virtual void    onClose(bool app_quitting);
00191 
00192         // Defaults to true.
00193         virtual BOOL    canClose();
00194 
00195         virtual void    setVisible(BOOL visible);
00196         void                    setFrontmost(BOOL take_focus = TRUE);
00197 
00198         // Defaults to false.
00199         virtual BOOL    canSaveAs();
00200 
00201         // Defaults to no-op.
00202         virtual void    saveAs();
00203 
00204         void                    setSnapTarget(LLViewHandle handle) { mSnappedTo = handle; }
00205         void                    clearSnapTarget() { mSnappedTo.markDead(); }
00206         LLViewHandle    getSnapTarget() { return mSnappedTo; }
00207 
00208         static void             closeFocusedFloater();
00209 
00210         static void             onClickClose(void *userdata);
00211         static void             onClickMinimize(void *userdata);
00212         static void             onClickTearOff(void *userdata);
00213         static void             onClickEdit(void *userdata);
00214 
00215         static void             setFloaterHost(LLMultiFloater* hostp) {sHostp = hostp; }
00216         static void             setEditModeEnabled(BOOL enable);
00217         static BOOL             getEditModeEnabled();
00218         static LLMultiFloater*          getFloaterHost() {return sHostp; }
00219 
00220         static void             show(LLFloater* floaterp);
00221         static void             hide(LLFloater* floaterp);
00222         static BOOL             visible(LLFloater* floaterp);
00223 
00224         static LLFloater* getFloaterByHandle(LLViewHandle handle);
00225 
00226 protected:
00227         // Don't call this directly.  You probably want to call close(). JC
00228         void                    destroy();
00229         virtual void    bringToFront(S32 x, S32 y);
00230         virtual void    setVisibleAndFrontmost(BOOL take_focus=TRUE);
00231         void                    setForeground(BOOL b);  // called only by floaterview
00232         void                    cleanupHandles(); // remove handles to dead floaters
00233         void                    createMinimizeButton();
00234         void                    updateButtons();
00235         void                    buildButtons();
00236 
00237 protected:
00238 //      static LLViewerImage*           sBackgroundImage;
00239 //      static LLViewerImage*           sShadowImage;
00240 
00241         LLDragHandle*   mDragHandle;
00242         LLResizeBar*    mResizeBar[4];
00243         LLResizeHandle* mResizeHandle[4];
00244         LLButton                *mMinimizeButton;
00245         BOOL                    mCanTearOff;
00246         BOOL                    mMinimized;
00247         LLRect                  mPreviousRect;
00248         BOOL                    mForeground;
00249         LLViewHandle    mDependeeHandle;
00250         LLString                mShortTitle;
00251 
00252         BOOL                    mFirstLook;                     // TRUE if the _next_ time this floater is visible will be the first time in the session that it is visible.
00253 
00254         BOOL                    mResizable;
00255         S32                             mMinWidth;
00256         S32                             mMinHeight;
00257 
00258         BOOL                    mAutoFocus;
00259         BOOL                    mEditing;
00260         
00261         typedef std::set<LLViewHandle> handle_set_t;
00262         typedef std::set<LLViewHandle>::iterator handle_set_iter_t;
00263         handle_set_t    mDependents;
00264         bool            mDragOnLeft;
00265 
00266         BOOL                    mButtonsEnabled[BUTTON_COUNT];
00267         LLButton*               mButtons[BUTTON_COUNT];
00268         F32                             mButtonScale;
00269 
00270         LLViewHandle    mSnappedTo;
00271         
00272         LLViewHandle mHostHandle;
00273         LLViewHandle mLastHostHandle;
00274 
00275         static BOOL             sEditModeEnabled;
00276         static LLMultiFloater* sHostp;
00277         static LLString sButtonActiveImageNames[BUTTON_COUNT];
00278         static LLString sButtonInactiveImageNames[BUTTON_COUNT];
00279         static LLString sButtonPressedImageNames[BUTTON_COUNT];
00280         static LLString sButtonNames[BUTTON_COUNT];
00281         static LLString sButtonToolTips[BUTTON_COUNT];
00282         typedef void (*click_callback)(void *);
00283         static click_callback sButtonCallbacks[BUTTON_COUNT];
00284 
00285         typedef std::map<LLViewHandle, LLFloater*> handle_map_t;
00286         typedef std::map<LLViewHandle, LLFloater*>::iterator handle_map_iter_t;
00287         static handle_map_t     sFloaterMap;
00288 
00289         std::vector<LLView*> mMinimizedHiddenChildren;
00290 
00291         BOOL                    mHasBeenDraggedWhileMinimized;
00292         S32                             mPreviousMinimizedBottom;
00293         S32                             mPreviousMinimizedLeft;
00294 };
00295 
00297 // LLFloaterView
00298 // Parent of all floating panels
00299 
00300 class LLFloaterView : public LLUICtrl
00301 {
00302 public:
00303         LLFloaterView( const LLString& name, const LLRect& rect );
00304 
00305         virtual EWidgetType getWidgetType() const;
00306         virtual LLString getWidgetTag() const;
00307 
00308         /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent);
00309         void reshape(S32 width, S32 height, BOOL called_from_parent, BOOL adjust_vertical);
00310 
00311         /*virtual*/ void draw();
00312         /*virtual*/ const LLRect getSnapRect() const;
00313         void refresh();
00314 
00315         void                    getNewFloaterPosition( S32* left, S32* top );
00316         void                    resetStartingFloaterPosition();
00317         LLRect                  findNeighboringPosition( LLFloater* reference_floater, LLFloater* neighbor );
00318 
00319         // Given a child of gFloaterView, make sure this view can fit entirely onscreen.
00320         void                    adjustToFitScreen(LLFloater* floater, BOOL allow_partial_outside);
00321 
00322         void                    getMinimizePosition( S32 *left, S32 *bottom);
00323         void                    restoreAll();           // un-minimize all floaters
00324         typedef std::set<LLView*> skip_list_t;
00325         void pushVisibleAll(BOOL visible, const skip_list_t& skip_list = skip_list_t());
00326         void popVisibleAll(const skip_list_t& skip_list = skip_list_t());
00327 
00328         void                    setCycleMode(BOOL mode);
00329         BOOL                    getCycleMode();
00330         void                    bringToFront( LLFloater* child, BOOL give_focus = TRUE );
00331         void                    highlightFocusedFloater();
00332         void                    unhighlightFocusedFloater();
00333         void                    focusFrontFloater();
00334         void                    destroyAllChildren();
00335         // attempt to close all floaters
00336         void                    closeAllChildren(bool app_quitting);
00337         BOOL                    allChildrenClosed();
00338 
00339         LLFloater* getFrontmost();
00340         LLFloater* getBackmost();
00341         LLFloater* getParentFloater(LLView* viewp);
00342         LLFloater* getFocusedFloater();
00343         void            syncFloaterTabOrder();
00344 
00345         // Get a floater based the handle. If this returns NULL, it is up
00346         // to the caller to discard the handle.
00347         LLFloater* getFloaterByHandle(LLViewHandle handle);
00348 
00349         // Returns z order of child provided. 0 is closest, larger numbers
00350         // are deeper in the screen. If there is no such child, the return
00351         // value is not defined.
00352         S32 getZOrder(LLFloater* child);
00353 
00354         void setSnapOffsetBottom(S32 offset) { mSnapOffsetBottom = offset; }
00355 
00356 private:
00357         S32                             mColumn;
00358         S32                             mNextLeft;
00359         S32                             mNextTop;
00360         BOOL                    mFocusCycleMode;
00361         S32                             mSnapOffsetBottom;
00362 };
00363 
00364 class LLMultiFloater : public LLFloater
00365 {
00366 public:
00367         LLMultiFloater();
00368         LLMultiFloater(LLTabContainerCommon::TabPosition tab_pos);
00369         LLMultiFloater(const LLString& name);
00370         LLMultiFloater(const LLString& name, const LLRect& rect, LLTabContainer::TabPosition tab_pos = LLTabContainer::TOP, BOOL auto_resize = TRUE);
00371         LLMultiFloater(const LLString& name, const LLString& rect_control, LLTabContainer::TabPosition tab_pos = LLTabContainer::TOP, BOOL auto_resize = TRUE);
00372         virtual ~LLMultiFloater();
00373 
00374         virtual BOOL postBuild();
00375         /*virtual*/ void open();        /* Flawfinder: ignore */
00376         /*virtual*/ void onClose(bool app_quitting);
00377         /*virtual*/ void draw();
00378         /*virtual*/ void setVisible(BOOL visible);
00379         /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00380         /*virtual*/ EWidgetType getWidgetType() const;
00381         /*virtual*/ LLString getWidgetTag() const;
00382 
00383         virtual void setCanResize(BOOL can_resize);
00384         virtual void growToFit(S32 content_width, S32 content_height);
00385         virtual void addFloater(LLFloater* floaterp, BOOL select_added_floater, LLTabContainerCommon::eInsertionPoint insertion_point = LLTabContainerCommon::END);
00386 
00387         virtual void showFloater(LLFloater* floaterp);
00388         virtual void removeFloater(LLFloater* floaterp);
00389 
00390         virtual void tabOpen(LLFloater* opened_floater, bool from_click);
00391         virtual void tabClose();
00392 
00393         virtual BOOL selectFloater(LLFloater* floaterp);
00394         virtual void selectNextFloater();
00395         virtual void selectPrevFloater();
00396 
00397         virtual LLFloater* getActiveFloater();
00398         virtual BOOL       isFloaterFlashing(LLFloater* floaterp);
00399         virtual S32                     getFloaterCount();
00400 
00401         virtual void setFloaterFlashing(LLFloater* floaterp, BOOL flashing);
00402         virtual BOOL closeAllFloaters();        //Returns FALSE if the floater could not be closed due to pending confirmation dialogs
00403         void setTabContainer(LLTabContainerCommon* tab_container) { if (!mTabContainer) mTabContainer = tab_container; }
00404         static void onTabSelected(void* userdata, bool);
00405 
00406         virtual void updateResizeLimits();
00407 
00408 protected:
00409         struct LLFloaterData
00410         {
00411                 S32             mWidth;
00412                 S32             mHeight;
00413                 BOOL    mCanMinimize;
00414                 BOOL    mCanResize;
00415         };
00416 
00417         LLTabContainerCommon*           mTabContainer;
00418         
00419         typedef std::map<LLViewHandle, LLFloaterData> floater_data_map_t;
00420         floater_data_map_t      mFloaterDataMap;
00421         
00422         LLTabContainerCommon::TabPosition mTabPos;
00423         BOOL                            mAutoResize;
00424 };
00425 
00426 
00427 extern LLFloaterView* gFloaterView;
00428 
00429 #endif  // LL_FLOATER_H
00430 
00431 

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