/indra/llui/llfloater.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 555 lines · 352 code · 125 blank · 78 comment · 2 complexity · e9c51a5055b92c6ca9f16a7011b99091 MD5 · raw file

  1. /**
  2. * @file llfloater.h
  3. * @brief LLFloater base class
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // Floating "windows" within the GL display, like the inventory floater,
  27. // mini-map floater, etc.
  28. #ifndef LL_FLOATER_H
  29. #define LL_FLOATER_H
  30. #include "llpanel.h"
  31. #include "lluuid.h"
  32. //#include "llnotificationsutil.h"
  33. #include <set>
  34. #include <boost/signals2.hpp>
  35. class LLDragHandle;
  36. class LLResizeHandle;
  37. class LLResizeBar;
  38. class LLButton;
  39. class LLMultiFloater;
  40. class LLFloater;
  41. const BOOL RESIZE_YES = TRUE;
  42. const BOOL RESIZE_NO = FALSE;
  43. const BOOL DRAG_ON_TOP = FALSE;
  44. const BOOL DRAG_ON_LEFT = TRUE;
  45. const BOOL MINIMIZE_YES = TRUE;
  46. const BOOL MINIMIZE_NO = FALSE;
  47. const BOOL CLOSE_YES = TRUE;
  48. const BOOL CLOSE_NO = FALSE;
  49. const BOOL ADJUST_VERTICAL_YES = TRUE;
  50. const BOOL ADJUST_VERTICAL_NO = FALSE;
  51. namespace LLFloaterEnums
  52. {
  53. enum EOpenPositioning
  54. {
  55. OPEN_POSITIONING_NONE,
  56. OPEN_POSITIONING_CASCADING,
  57. OPEN_POSITIONING_CASCADE_GROUP,
  58. OPEN_POSITIONING_CENTERED,
  59. OPEN_POSITIONING_SPECIFIED,
  60. OPEN_POSITIONING_COUNT
  61. };
  62. }
  63. namespace LLInitParam
  64. {
  65. template<>
  66. struct TypeValues<LLFloaterEnums::EOpenPositioning> : public TypeValuesHelper<LLFloaterEnums::EOpenPositioning>
  67. {
  68. static void declareValues();
  69. };
  70. }
  71. class LLFloater : public LLPanel, public LLInstanceTracker<LLFloater>
  72. {
  73. friend class LLFloaterView;
  74. friend class LLFloaterReg;
  75. friend class LLMultiFloater;
  76. public:
  77. struct KeyCompare
  78. {
  79. // static bool compare(const LLSD& a, const LLSD& b);
  80. static bool equate(const LLSD& a, const LLSD& b);
  81. /*==========================================================================*|
  82. bool operator()(const LLSD& a, const LLSD& b) const
  83. {
  84. return compare(a, b);
  85. }
  86. |*==========================================================================*/
  87. };
  88. enum EFloaterButton
  89. {
  90. BUTTON_CLOSE = 0,
  91. BUTTON_RESTORE,
  92. BUTTON_MINIMIZE,
  93. BUTTON_TEAR_OFF,
  94. BUTTON_DOCK,
  95. BUTTON_HELP,
  96. BUTTON_COUNT
  97. };
  98. struct Params
  99. : public LLInitParam::Block<Params, LLPanel::Params>
  100. {
  101. Optional<std::string> title,
  102. short_title;
  103. Optional<bool> single_instance,
  104. reuse_instance,
  105. can_resize,
  106. can_minimize,
  107. can_close,
  108. can_drag_on_left,
  109. can_tear_off,
  110. save_rect,
  111. save_visibility,
  112. save_dock_state,
  113. can_dock,
  114. show_title;
  115. Optional<LLFloaterEnums::EOpenPositioning> open_positioning;
  116. Optional<S32> specified_left;
  117. Optional<S32> specified_bottom;
  118. Optional<S32> header_height,
  119. legacy_header_height; // HACK see initFromXML()
  120. // Images for top-right controls
  121. Optional<LLUIImage*> close_image,
  122. restore_image,
  123. minimize_image,
  124. tear_off_image,
  125. dock_image,
  126. help_image;
  127. Optional<LLUIImage*> close_pressed_image,
  128. restore_pressed_image,
  129. minimize_pressed_image,
  130. tear_off_pressed_image,
  131. dock_pressed_image,
  132. help_pressed_image;
  133. Optional<CommitCallbackParam> open_callback,
  134. close_callback;
  135. Ignored follows;
  136. Params();
  137. };
  138. // use this to avoid creating your own default LLFloater::Param instance
  139. static const Params& getDefaultParams();
  140. // Load translations for tooltips for standard buttons
  141. static void initClass();
  142. LLFloater(const LLSD& key, const Params& params = getDefaultParams());
  143. virtual ~LLFloater();
  144. // Don't export top/left for rect, only height/width
  145. static void setupParamsForExport(Params& p, LLView* parent);
  146. bool buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL);
  147. boost::signals2::connection setMinimizeCallback( const commit_signal_t::slot_type& cb );
  148. boost::signals2::connection setOpenCallback( const commit_signal_t::slot_type& cb );
  149. boost::signals2::connection setCloseCallback( const commit_signal_t::slot_type& cb );
  150. void initFromParams(const LLFloater::Params& p);
  151. bool initFloaterXML(LLXMLNodePtr node, LLView *parent, const std::string& filename, LLXMLNodePtr output_node = NULL);
  152. /*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
  153. /*virtual*/ BOOL canSnapTo(const LLView* other_view);
  154. /*virtual*/ void setSnappedTo(const LLView* snap_view);
  155. /*virtual*/ void setFocus( BOOL b );
  156. /*virtual*/ void setIsChrome(BOOL is_chrome);
  157. /*virtual*/ void setRect(const LLRect &rect);
  158. void initFloater(const Params& p);
  159. void openFloater(const LLSD& key = LLSD());
  160. // If allowed, close the floater cleanly, releasing focus.
  161. void closeFloater(bool app_quitting = false);
  162. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  163. // Release keyboard and mouse focus
  164. void releaseFocus();
  165. // moves to center of gFloaterView
  166. void center();
  167. LLMultiFloater* getHost();
  168. void applyTitle();
  169. std::string getCurrentTitle() const;
  170. void setTitle( const std::string& title);
  171. std::string getTitle() const;
  172. void setShortTitle( const std::string& short_title );
  173. std::string getShortTitle() const;
  174. virtual void setMinimized(BOOL b);
  175. void moveResizeHandlesToFront();
  176. void addDependentFloater(LLFloater* dependent, BOOL reposition = TRUE);
  177. void addDependentFloater(LLHandle<LLFloater> dependent_handle, BOOL reposition = TRUE);
  178. LLFloater* getDependee() { return (LLFloater*)mDependeeHandle.get(); }
  179. void removeDependentFloater(LLFloater* dependent);
  180. BOOL isMinimized() const { return mMinimized; }
  181. /// isShown() differs from getVisible() in that isShown() also considers
  182. /// isMinimized(). isShown() is true only if visible and not minimized.
  183. bool isShown() const;
  184. /// The static isShown() can accept a NULL pointer (which of course
  185. /// returns false). When non-NULL, it calls the non-static isShown().
  186. static bool isShown(const LLFloater* floater);
  187. static bool isVisible(const LLFloater* floater);
  188. static bool isMinimized(const LLFloater* floater);
  189. BOOL isFirstLook() { return mFirstLook; } // EXT-2653: This function is necessary to prevent overlapping for secondary showed toasts
  190. BOOL isFrontmost();
  191. BOOL isDependent() { return !mDependeeHandle.isDead(); }
  192. void setCanMinimize(BOOL can_minimize);
  193. void setCanClose(BOOL can_close);
  194. void setCanTearOff(BOOL can_tear_off);
  195. virtual void setCanResize(BOOL can_resize);
  196. void setCanDrag(BOOL can_drag);
  197. bool getCanDrag();
  198. void setHost(LLMultiFloater* host);
  199. BOOL isResizable() const { return mResizable; }
  200. void setResizeLimits( S32 min_width, S32 min_height );
  201. void getResizeLimits( S32* min_width, S32* min_height ) { *min_width = mMinWidth; *min_height = mMinHeight; }
  202. LLRect getSavedRect() const;
  203. bool hasSavedRect() const;
  204. static std::string getControlName(const std::string& name, const LLSD& key);
  205. static LLControlGroup* getControlGroup();
  206. bool isMinimizeable() const{ return mCanMinimize; }
  207. bool isCloseable() const{ return mCanClose; }
  208. bool isDragOnLeft() const{ return mDragOnLeft; }
  209. S32 getMinWidth() const{ return mMinWidth; }
  210. S32 getMinHeight() const{ return mMinHeight; }
  211. S32 getHeaderHeight() const { return mHeaderHeight; }
  212. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  213. virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  214. virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
  215. virtual BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask);
  216. virtual BOOL handleScrollWheel(S32 x, S32 y, S32 mask);
  217. virtual void draw();
  218. virtual void drawShadow(LLPanel* panel);
  219. virtual void onOpen(const LLSD& key) {}
  220. virtual void onClose(bool app_quitting) {}
  221. // This cannot be "const" until all derived floater canClose()
  222. // methods are const as well. JC
  223. virtual BOOL canClose() { return TRUE; }
  224. /*virtual*/ void setVisible(BOOL visible); // do not override
  225. /*virtual*/ void handleVisibilityChange ( BOOL new_visibility ); // do not override
  226. void setFrontmost(BOOL take_focus = TRUE);
  227. // Defaults to false.
  228. virtual BOOL canSaveAs() const { return FALSE; }
  229. virtual void saveAs() {}
  230. void setSnapTarget(LLHandle<LLFloater> handle) { mSnappedTo = handle; }
  231. void clearSnapTarget() { mSnappedTo.markDead(); }
  232. LLHandle<LLFloater> getSnapTarget() const { return mSnappedTo; }
  233. LLHandle<LLFloater> getHandle() const { return getDerivedHandle<LLFloater>(); }
  234. const LLSD& getKey() { return mKey; }
  235. virtual bool matchesKey(const LLSD& key) { return mSingleInstance || KeyCompare::equate(key, mKey); }
  236. const std::string& getInstanceName() { return mInstanceName; }
  237. bool isDockable() const { return mCanDock; }
  238. void setCanDock(bool b);
  239. bool isDocked() const { return mDocked; }
  240. virtual void setDocked(bool docked, bool pop_on_undock = true);
  241. virtual void setTornOff(bool torn_off) { mTornOff = torn_off; }
  242. // Return a closeable floater, if any, given the current focus.
  243. static LLFloater* getClosableFloaterFromFocus();
  244. // Close the floater returned by getClosableFloaterFromFocus() and
  245. // handle refocusing.
  246. static void closeFocusedFloater();
  247. // LLNotification::Params contextualNotification(const std::string& name)
  248. // {
  249. // return LLNotification::Params(name).context(mNotificationContext);
  250. // }
  251. static void onClickClose(LLFloater* floater);
  252. static void onClickMinimize(LLFloater* floater);
  253. static void onClickTearOff(LLFloater* floater);
  254. static void onClickDock(LLFloater* floater);
  255. static void onClickHelp(LLFloater* floater);
  256. static void setFloaterHost(LLMultiFloater* hostp) {sHostp = hostp; }
  257. static LLMultiFloater* getFloaterHost() {return sHostp; }
  258. void updateTransparency(ETypeTransparency transparency_type);
  259. void enableResizeCtrls(bool enable, bool width = true, bool height = true);
  260. bool isPositioning(LLFloaterEnums::EOpenPositioning p) const { return (p == mOpenPositioning); }
  261. protected:
  262. void applyControlsAndPosition(LLFloater* other);
  263. void stackWith(LLFloater& other);
  264. virtual bool applyRectControl();
  265. bool applyDockState();
  266. void applyPositioning(LLFloater* other);
  267. void storeRectControl();
  268. void storeVisibilityControl();
  269. void storeDockStateControl();
  270. void setKey(const LLSD& key);
  271. void setInstanceName(const std::string& name);
  272. virtual void bringToFront(S32 x, S32 y);
  273. virtual void setVisibleAndFrontmost(BOOL take_focus=TRUE);
  274. void setExpandedRect(const LLRect& rect) { mExpandedRect = rect; } // size when not minimized
  275. const LLRect& getExpandedRect() const { return mExpandedRect; }
  276. void setAutoFocus(BOOL focus) { mAutoFocus = focus; } // whether to automatically take focus when opened
  277. BOOL getAutoFocus() const { return mAutoFocus; }
  278. LLDragHandle* getDragHandle() const { return mDragHandle; }
  279. void destroy(); // Don't call this directly. You probably want to call closeFloater()
  280. virtual void onClickCloseBtn();
  281. virtual void updateTitleButtons();
  282. private:
  283. void setForeground(BOOL b); // called only by floaterview
  284. void cleanupHandles(); // remove handles to dead floaters
  285. void createMinimizeButton();
  286. void buildButtons(const Params& p);
  287. // Images and tooltips are named in the XML, but we want to look them
  288. // up by index.
  289. static LLUIImage* getButtonImage(const Params& p, EFloaterButton e);
  290. static LLUIImage* getButtonPressedImage(const Params& p, EFloaterButton e);
  291. /**
  292. * @params is_chrome - if floater is Chrome it means that floater will never get focus.
  293. * Therefore it can't be closed with 'Ctrl+W'. So the tooltip text of close button( X )
  294. * should be 'Close' not 'Close(Ctrl+W)' as for usual floaters.
  295. */
  296. static std::string getButtonTooltip(const Params& p, EFloaterButton e, bool is_chrome);
  297. BOOL offerClickToButton(S32 x, S32 y, MASK mask, EFloaterButton index);
  298. void addResizeCtrls();
  299. void layoutResizeCtrls();
  300. void addDragHandle();
  301. void layoutDragHandle(); // repair layout
  302. static void updateActiveFloaterTransparency();
  303. static void updateInactiveFloaterTransparency();
  304. void updateTransparency(LLView* view, ETypeTransparency transparency_type);
  305. public:
  306. // Called when floater is opened, passes mKey
  307. // Public so external views or floaters can watch for this floater opening
  308. commit_signal_t mOpenSignal;
  309. // Called when floater is closed, passes app_qitting as LLSD()
  310. // Public so external views or floaters can watch for this floater closing
  311. commit_signal_t mCloseSignal;
  312. commit_signal_t* mMinimizeSignal;
  313. protected:
  314. std::string mRectControl;
  315. std::string mVisibilityControl;
  316. std::string mDocStateControl;
  317. LLSD mKey; // Key used for retrieving instances; set (for now) by LLFLoaterReg
  318. LLDragHandle* mDragHandle;
  319. LLResizeBar* mResizeBar[4];
  320. LLResizeHandle* mResizeHandle[4];
  321. LLButton* mButtons[BUTTON_COUNT];
  322. private:
  323. LLRect mExpandedRect;
  324. LLUIString mTitle;
  325. LLUIString mShortTitle;
  326. BOOL mSingleInstance; // TRUE if there is only ever one instance of the floater
  327. bool mReuseInstance; // true if we want to hide the floater when we close it instead of destroying it
  328. std::string mInstanceName; // Store the instance name so we can remove ourselves from the list
  329. BOOL mCanTearOff;
  330. BOOL mCanMinimize;
  331. BOOL mCanClose;
  332. BOOL mDragOnLeft;
  333. BOOL mResizable;
  334. LLFloaterEnums::EOpenPositioning mOpenPositioning;
  335. S32 mSpecifiedLeft;
  336. S32 mSpecifiedBottom;
  337. S32 mMinWidth;
  338. S32 mMinHeight;
  339. S32 mHeaderHeight; // height in pixels of header for title, drag bar
  340. S32 mLegacyHeaderHeight;// HACK see initFloaterXML()
  341. BOOL mMinimized;
  342. BOOL mForeground;
  343. LLHandle<LLFloater> mDependeeHandle;
  344. BOOL mFirstLook; // TRUE if the _next_ time this floater is visible will be the first time in the session that it is visible.
  345. typedef std::set<LLHandle<LLFloater> > handle_set_t;
  346. typedef std::set<LLHandle<LLFloater> >::iterator handle_set_iter_t;
  347. handle_set_t mDependents;
  348. bool mButtonsEnabled[BUTTON_COUNT];
  349. F32 mButtonScale;
  350. BOOL mAutoFocus;
  351. LLHandle<LLFloater> mSnappedTo;
  352. LLHandle<LLFloater> mHostHandle;
  353. LLHandle<LLFloater> mLastHostHandle;
  354. bool mCanDock;
  355. bool mDocked;
  356. bool mTornOff;
  357. static LLMultiFloater* sHostp;
  358. static BOOL sQuitting;
  359. static std::string sButtonNames[BUTTON_COUNT];
  360. static std::string sButtonToolTips[BUTTON_COUNT];
  361. static std::string sButtonToolTipsIndex[BUTTON_COUNT];
  362. typedef void(*click_callback)(LLFloater*);
  363. static click_callback sButtonCallbacks[BUTTON_COUNT];
  364. BOOL mHasBeenDraggedWhileMinimized;
  365. S32 mPreviousMinimizedBottom;
  366. S32 mPreviousMinimizedLeft;
  367. };
  368. /////////////////////////////////////////////////////////////
  369. // LLFloaterView
  370. // Parent of all floating panels
  371. class LLFloaterView : public LLUICtrl
  372. {
  373. public:
  374. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>{};
  375. protected:
  376. LLFloaterView (const Params& p);
  377. friend class LLUICtrlFactory;
  378. public:
  379. /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  380. /*virtual*/ void draw();
  381. /*virtual*/ LLRect getSnapRect() const;
  382. /*virtual*/ void refresh();
  383. LLRect findNeighboringPosition( LLFloater* reference_floater, LLFloater* neighbor );
  384. // Given a child of gFloaterView, make sure this view can fit entirely onscreen.
  385. void adjustToFitScreen(LLFloater* floater, BOOL allow_partial_outside);
  386. void setMinimizePositionVerticalOffset(S32 offset) { mMinimizePositionVOffset = offset; }
  387. void getMinimizePosition( S32 *left, S32 *bottom);
  388. void restoreAll(); // un-minimize all floaters
  389. typedef std::set<LLView*> skip_list_t;
  390. void pushVisibleAll(BOOL visible, const skip_list_t& skip_list = skip_list_t());
  391. void popVisibleAll(const skip_list_t& skip_list = skip_list_t());
  392. void setCycleMode(BOOL mode) { mFocusCycleMode = mode; }
  393. BOOL getCycleMode() const { return mFocusCycleMode; }
  394. void bringToFront( LLFloater* child, BOOL give_focus = TRUE );
  395. void highlightFocusedFloater();
  396. void unhighlightFocusedFloater();
  397. void focusFrontFloater();
  398. void destroyAllChildren();
  399. // attempt to close all floaters
  400. void closeAllChildren(bool app_quitting);
  401. BOOL allChildrenClosed();
  402. void shiftFloaters(S32 x_offset, S32 y_offset);
  403. void hideAllFloaters();
  404. void showHiddenFloaters();
  405. LLFloater* getFrontmost() const;
  406. LLFloater* getBackmost() const;
  407. LLFloater* getParentFloater(LLView* viewp) const;
  408. LLFloater* getFocusedFloater() const;
  409. void syncFloaterTabOrder();
  410. // Returns z order of child provided. 0 is closest, larger numbers
  411. // are deeper in the screen. If there is no such child, the return
  412. // value is not defined.
  413. S32 getZOrder(LLFloater* child);
  414. void setFloaterSnapView(LLHandle<LLView> snap_view) {mSnapView = snap_view; }
  415. private:
  416. void hiddenFloaterClosed(LLFloater* floater);
  417. LLRect mLastSnapRect;
  418. LLHandle<LLView> mSnapView;
  419. BOOL mFocusCycleMode;
  420. S32 mSnapOffsetBottom;
  421. S32 mSnapOffsetRight;
  422. S32 mMinimizePositionVOffset;
  423. typedef std::vector<std::pair<LLHandle<LLFloater>, boost::signals2::connection> > hidden_floaters_t;
  424. hidden_floaters_t mHiddenFloaters;
  425. };
  426. //
  427. // Globals
  428. //
  429. extern LLFloaterView* gFloaterView;
  430. #endif // LL_FLOATER_H