PageRenderTime 26ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llview.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 731 lines | 478 code | 142 blank | 111 comment | 6 complexity | ea1a0c5570146bb8bdbcef763924667e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llview.h
  3. * @brief Container for other views, anything that draws.
  4. *
  5. * $LicenseInfo:firstyear=2001&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. #ifndef LL_LLVIEW_H
  27. #define LL_LLVIEW_H
  28. // A view is an area in a window that can draw. It might represent
  29. // the HUD or a dialog box or a button. It can also contain sub-views
  30. // and child widgets
  31. #include "stdtypes.h"
  32. #include "llcoord.h"
  33. #include "llfontgl.h"
  34. #include "llhandle.h"
  35. #include "llmortician.h"
  36. #include "llmousehandler.h"
  37. #include "llstring.h"
  38. #include "llrect.h"
  39. #include "llui.h"
  40. #include "lluistring.h"
  41. #include "llviewquery.h"
  42. #include "stdenums.h"
  43. #include "lluistring.h"
  44. #include "llcursortypes.h"
  45. #include "lluictrlfactory.h"
  46. #include "lltreeiterators.h"
  47. #include "llfocusmgr.h"
  48. #include <list>
  49. #include <boost/function.hpp>
  50. #include <boost/noncopyable.hpp>
  51. class LLSD;
  52. const U32 FOLLOWS_NONE = 0x00;
  53. const U32 FOLLOWS_LEFT = 0x01;
  54. const U32 FOLLOWS_RIGHT = 0x02;
  55. const U32 FOLLOWS_TOP = 0x10;
  56. const U32 FOLLOWS_BOTTOM = 0x20;
  57. const U32 FOLLOWS_ALL = 0x33;
  58. const BOOL MOUSE_OPAQUE = TRUE;
  59. const BOOL NOT_MOUSE_OPAQUE = FALSE;
  60. const U32 GL_NAME_UI_RESERVED = 2;
  61. // maintains render state during traversal of UI tree
  62. class LLViewDrawContext
  63. {
  64. public:
  65. F32 mAlpha;
  66. LLViewDrawContext(F32 alpha = 1.f)
  67. : mAlpha(alpha)
  68. {
  69. if (!sDrawContextStack.empty())
  70. {
  71. LLViewDrawContext* context_top = sDrawContextStack.back();
  72. // merge with top of stack
  73. mAlpha *= context_top->mAlpha;
  74. }
  75. sDrawContextStack.push_back(this);
  76. }
  77. ~LLViewDrawContext()
  78. {
  79. sDrawContextStack.pop_back();
  80. }
  81. static const LLViewDrawContext& getCurrentContext();
  82. private:
  83. static std::vector<LLViewDrawContext*> sDrawContextStack;
  84. };
  85. class LLView
  86. : public LLMouseHandler, // handles mouse events
  87. public LLFocusableElement, // handles keyboard events
  88. public LLMortician, // lazy deletion
  89. public LLHandleProvider<LLView> // passes out weak references to self
  90. {
  91. public:
  92. struct Follows : public LLInitParam::ChoiceBlock<Follows>
  93. {
  94. Alternative<std::string> string;
  95. Alternative<U32> flags;
  96. Follows();
  97. };
  98. struct Params : public LLInitParam::Block<Params>
  99. {
  100. Mandatory<std::string> name;
  101. Optional<bool> enabled,
  102. visible,
  103. mouse_opaque,
  104. use_bounding_rect,
  105. from_xui,
  106. focus_root;
  107. Optional<S32> tab_group,
  108. default_tab_group;
  109. Optional<std::string> tool_tip;
  110. Optional<S32> sound_flags;
  111. Optional<Follows> follows;
  112. Optional<std::string> hover_cursor;
  113. Optional<std::string> layout;
  114. Optional<LLRect> rect;
  115. // Historical bottom-left layout used bottom_delta and left_delta
  116. // for relative positioning. New layout "topleft" prefers specifying
  117. // based on top edge.
  118. Optional<S32> bottom_delta, // from last bottom to my bottom
  119. top_pad, // from last bottom to my top
  120. top_delta, // from last top to my top
  121. left_pad, // from last right to my left
  122. left_delta; // from last left to my left
  123. //FIXME: get parent context involved in parsing traversal
  124. Ignored needs_translate, // cue for translation tools
  125. xmlns, // xml namespace
  126. xmlns_xsi, // xml namespace
  127. xsi_schemaLocation, // xml schema
  128. xsi_type; // xml schema type
  129. Params();
  130. };
  131. // most widgets are valid children of LLView
  132. typedef LLDefaultChildRegistry child_registry_t;
  133. void initFromParams(const LLView::Params&);
  134. protected:
  135. LLView(const LLView::Params&);
  136. friend class LLUICtrlFactory;
  137. private:
  138. // widgets in general are not copyable
  139. LLView(const LLView& other) {};
  140. public:
  141. //#if LL_DEBUG
  142. static BOOL sIsDrawing;
  143. //#endif
  144. enum ESoundFlags
  145. {
  146. SILENT = 0,
  147. MOUSE_DOWN = 1,
  148. MOUSE_UP = 2
  149. };
  150. enum ESnapType
  151. {
  152. SNAP_PARENT,
  153. SNAP_SIBLINGS,
  154. SNAP_PARENT_AND_SIBLINGS
  155. };
  156. enum ESnapEdge
  157. {
  158. SNAP_LEFT,
  159. SNAP_TOP,
  160. SNAP_RIGHT,
  161. SNAP_BOTTOM
  162. };
  163. typedef std::list<LLView*> child_list_t;
  164. typedef child_list_t::iterator child_list_iter_t;
  165. typedef child_list_t::const_iterator child_list_const_iter_t;
  166. typedef child_list_t::reverse_iterator child_list_reverse_iter_t;
  167. typedef child_list_t::const_reverse_iterator child_list_const_reverse_iter_t;
  168. typedef std::vector<class LLUICtrl *> ctrl_list_t;
  169. typedef std::pair<S32, S32> tab_order_t;
  170. typedef std::pair<LLUICtrl *, tab_order_t> tab_order_pair_t;
  171. // this structure primarily sorts by the tab group, secondarily by the insertion ordinal (lastly by the value of the pointer)
  172. typedef std::map<const LLUICtrl*, tab_order_t> child_tab_order_t;
  173. typedef child_tab_order_t::iterator child_tab_order_iter_t;
  174. typedef child_tab_order_t::const_iterator child_tab_order_const_iter_t;
  175. typedef child_tab_order_t::reverse_iterator child_tab_order_reverse_iter_t;
  176. typedef child_tab_order_t::const_reverse_iterator child_tab_order_const_reverse_iter_t;
  177. virtual ~LLView();
  178. // Some UI widgets need to be added as controls. Others need to
  179. // be added as regular view children. isCtrl should return TRUE
  180. // if a widget needs to be added as a ctrl
  181. virtual BOOL isCtrl() const;
  182. virtual BOOL isPanel() const;
  183. //
  184. // MANIPULATORS
  185. //
  186. void setMouseOpaque( BOOL b ) { mMouseOpaque = b; }
  187. BOOL getMouseOpaque() const { return mMouseOpaque; }
  188. void setToolTip( const LLStringExplicit& msg );
  189. BOOL setToolTipArg( const LLStringExplicit& key, const LLStringExplicit& text );
  190. void setToolTipArgs( const LLStringUtil::format_map_t& args );
  191. virtual void setRect(const LLRect &rect);
  192. void setFollows(U32 flags) { mReshapeFlags = flags; }
  193. // deprecated, use setFollows() with FOLLOWS_LEFT | FOLLOWS_TOP, etc.
  194. void setFollowsNone() { mReshapeFlags = FOLLOWS_NONE; }
  195. void setFollowsLeft() { mReshapeFlags |= FOLLOWS_LEFT; }
  196. void setFollowsTop() { mReshapeFlags |= FOLLOWS_TOP; }
  197. void setFollowsRight() { mReshapeFlags |= FOLLOWS_RIGHT; }
  198. void setFollowsBottom() { mReshapeFlags |= FOLLOWS_BOTTOM; }
  199. void setFollowsAll() { mReshapeFlags |= FOLLOWS_ALL; }
  200. void setSoundFlags(U8 flags) { mSoundFlags = flags; }
  201. void setName(std::string name) { mName = name; }
  202. void setUseBoundingRect( BOOL use_bounding_rect );
  203. BOOL getUseBoundingRect() const;
  204. ECursorType getHoverCursor() { return mHoverCursor; }
  205. virtual const std::string getToolTip() const { return mToolTipMsg.getString(); }
  206. void sendChildToFront(LLView* child);
  207. void sendChildToBack(LLView* child);
  208. void moveChildToFrontOfTabGroup(LLUICtrl* child);
  209. void moveChildToBackOfTabGroup(LLUICtrl* child);
  210. virtual bool addChild(LLView* view, S32 tab_group = 0);
  211. // implemented in terms of addChild()
  212. bool addChildInBack(LLView* view, S32 tab_group = 0);
  213. // remove the specified child from the view, and set it's parent to NULL.
  214. virtual void removeChild(LLView* view);
  215. virtual BOOL postBuild() { return TRUE; }
  216. const child_tab_order_t& getCtrlOrder() const { return mCtrlOrder; }
  217. ctrl_list_t getCtrlList() const;
  218. ctrl_list_t getCtrlListSorted() const;
  219. void setDefaultTabGroup(S32 d) { mDefaultTabGroup = d; }
  220. S32 getDefaultTabGroup() const { return mDefaultTabGroup; }
  221. S32 getLastTabGroup() { return mLastTabGroup; }
  222. BOOL isInVisibleChain() const;
  223. BOOL isInEnabledChain() const;
  224. void setFocusRoot(BOOL b) { mIsFocusRoot = b; }
  225. BOOL isFocusRoot() const { return mIsFocusRoot; }
  226. virtual BOOL canFocusChildren() const;
  227. BOOL focusNextRoot();
  228. BOOL focusPrevRoot();
  229. // Normally we want the app menus to get priority on accelerated keys
  230. // However, sometimes we want to give specific views a first chance
  231. // iat handling them. (eg. the script editor)
  232. virtual bool hasAccelerators() const { return false; };
  233. // delete all children. Override this function if you need to
  234. // perform any extra clean up such as cached pointers to selected
  235. // children, etc.
  236. virtual void deleteAllChildren();
  237. void setAllChildrenEnabled(BOOL b);
  238. virtual void setVisible(BOOL visible);
  239. const BOOL& getVisible() const { return mVisible; }
  240. virtual void setEnabled(BOOL enabled);
  241. BOOL getEnabled() const { return mEnabled; }
  242. /// 'available' in this context means 'visible and enabled': in other
  243. /// words, can a user actually interact with this?
  244. virtual bool isAvailable() const;
  245. /// The static isAvailable() tests an LLView* that could be NULL.
  246. static bool isAvailable(const LLView* view);
  247. U8 getSoundFlags() const { return mSoundFlags; }
  248. virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text );
  249. virtual void handleVisibilityChange ( BOOL new_visibility );
  250. void pushVisible(BOOL visible) { mLastVisible = mVisible; setVisible(visible); }
  251. void popVisible() { setVisible(mLastVisible); }
  252. BOOL getLastVisible() const { return mLastVisible; }
  253. U32 getFollows() const { return mReshapeFlags; }
  254. BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; }
  255. BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; }
  256. BOOL followsTop() const { return mReshapeFlags & FOLLOWS_TOP; }
  257. BOOL followsBottom() const { return mReshapeFlags & FOLLOWS_BOTTOM; }
  258. BOOL followsAll() const { return mReshapeFlags & FOLLOWS_ALL; }
  259. const LLRect& getRect() const { return mRect; }
  260. const LLRect& getBoundingRect() const { return mBoundingRect; }
  261. LLRect getLocalBoundingRect() const;
  262. LLRect calcScreenRect() const;
  263. LLRect calcScreenBoundingRect() const;
  264. LLRect getLocalRect() const;
  265. virtual LLRect getSnapRect() const;
  266. LLRect getLocalSnapRect() const;
  267. std::string getLayout() { return mLayout; }
  268. // Override and return required size for this object. 0 for width/height means don't care.
  269. virtual LLRect getRequiredRect();
  270. LLRect calcBoundingRect();
  271. void updateBoundingRect();
  272. LLView* getRootView();
  273. LLView* getParent() const { return mParentView; }
  274. LLView* getFirstChild() const { return (mChildList.empty()) ? NULL : *(mChildList.begin()); }
  275. LLView* findPrevSibling(LLView* child);
  276. LLView* findNextSibling(LLView* child);
  277. S32 getChildCount() const { return (S32)mChildList.size(); }
  278. template<class _Pr3> void sortChildren(_Pr3 _Pred) { mChildList.sort(_Pred); }
  279. BOOL hasAncestor(const LLView* parentp) const;
  280. BOOL hasChild(const std::string& childname, BOOL recurse = FALSE) const;
  281. BOOL childHasKeyboardFocus( const std::string& childname ) const;
  282. // these iterators are used for collapsing various tree traversals into for loops
  283. typedef LLTreeDFSIter<LLView, child_list_const_iter_t> tree_iterator_t;
  284. tree_iterator_t beginTreeDFS();
  285. tree_iterator_t endTreeDFS();
  286. typedef LLTreeDFSPostIter<LLView, child_list_const_iter_t> tree_post_iterator_t;
  287. tree_post_iterator_t beginTreeDFSPost();
  288. tree_post_iterator_t endTreeDFSPost();
  289. typedef LLTreeBFSIter<LLView, child_list_const_iter_t> bfs_tree_iterator_t;
  290. bfs_tree_iterator_t beginTreeBFS();
  291. bfs_tree_iterator_t endTreeBFS();
  292. typedef LLTreeDownIter<LLView> root_to_view_iterator_t;
  293. root_to_view_iterator_t beginRootToView();
  294. root_to_view_iterator_t endRootToView();
  295. //
  296. // UTILITIES
  297. //
  298. // Default behavior is to use reshape flags to resize child views
  299. virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  300. virtual void translate( S32 x, S32 y );
  301. void setOrigin( S32 x, S32 y ) { mRect.translate( x - mRect.mLeft, y - mRect.mBottom ); }
  302. BOOL translateIntoRect( const LLRect& constraint, BOOL allow_partial_outside );
  303. BOOL translateIntoRectWithExclusion( const LLRect& inside, const LLRect& exclude, BOOL allow_partial_outside );
  304. void centerWithin(const LLRect& bounds);
  305. void setShape(const LLRect& new_rect, bool by_user = false);
  306. virtual LLView* findSnapRect(LLRect& new_rect, const LLCoordGL& mouse_dir, LLView::ESnapType snap_type, S32 threshold, S32 padding = 0);
  307. virtual LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding = 0);
  308. virtual BOOL canSnapTo(const LLView* other_view);
  309. virtual void setSnappedTo(const LLView* snap_view);
  310. // inherited from LLFocusableElement
  311. /* virtual */ BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
  312. /* virtual */ BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
  313. virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  314. EDragAndDropType cargo_type,
  315. void* cargo_data,
  316. EAcceptance* accept,
  317. std::string& tooltip_msg);
  318. virtual void draw();
  319. void parseFollowsFlags(const LLView::Params& params);
  320. // Some widgets, like close box buttons, don't need to be saved
  321. BOOL getFromXUI() const { return mFromXUI; }
  322. void setFromXUI(BOOL b) { mFromXUI = b; }
  323. typedef enum e_hit_test_type
  324. {
  325. HIT_TEST_USE_BOUNDING_RECT,
  326. HIT_TEST_IGNORE_BOUNDING_RECT
  327. }EHitTestType;
  328. BOOL parentPointInView(S32 x, S32 y, EHitTestType type = HIT_TEST_USE_BOUNDING_RECT) const;
  329. BOOL pointInView(S32 x, S32 y, EHitTestType type = HIT_TEST_USE_BOUNDING_RECT) const;
  330. BOOL blockMouseEvent(S32 x, S32 y) const;
  331. // See LLMouseHandler virtuals for screenPointToLocal and localPointToScreen
  332. BOOL localPointToOtherView( S32 x, S32 y, S32 *other_x, S32 *other_y, const LLView* other_view) const;
  333. BOOL localRectToOtherView( const LLRect& local, LLRect* other, const LLView* other_view ) const;
  334. void screenRectToLocal( const LLRect& screen, LLRect* local ) const;
  335. void localRectToScreen( const LLRect& local, LLRect* screen ) const;
  336. LLControlVariable *findControl(const std::string& name);
  337. const child_list_t* getChildList() const { return &mChildList; }
  338. child_list_const_iter_t beginChild() const { return mChildList.begin(); }
  339. child_list_const_iter_t endChild() const { return mChildList.end(); }
  340. // LLMouseHandler functions
  341. // Default behavior is to pass events to children
  342. /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask);
  343. /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
  344. /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  345. /*virtual*/ BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask);
  346. /*virtual*/ BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask);
  347. /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
  348. /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
  349. /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
  350. /*virtual*/ BOOL handleRightMouseUp(S32 x, S32 y, MASK mask);
  351. /*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask);
  352. /*virtual*/ const std::string& getName() const;
  353. /*virtual*/ void onMouseCaptureLost();
  354. /*virtual*/ BOOL hasMouseCapture();
  355. /*virtual*/ void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const;
  356. /*virtual*/ void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const;
  357. virtual LLView* childFromPoint(S32 x, S32 y, bool recur=false);
  358. // view-specific handlers
  359. virtual void onMouseEnter(S32 x, S32 y, MASK mask);
  360. virtual void onMouseLeave(S32 x, S32 y, MASK mask);
  361. std::string getPathname() const;
  362. // static method handles NULL pointer too
  363. static std::string getPathname(const LLView*);
  364. template <class T> T* findChild(const std::string& name, BOOL recurse = TRUE) const
  365. {
  366. LLView* child = findChildView(name, recurse);
  367. T* result = dynamic_cast<T*>(child);
  368. return result;
  369. }
  370. template <class T> T* getChild(const std::string& name, BOOL recurse = TRUE) const;
  371. template <class T> T& getChildRef(const std::string& name, BOOL recurse = TRUE) const
  372. {
  373. return *getChild<T>(name, recurse);
  374. }
  375. virtual LLView* getChildView(const std::string& name, BOOL recurse = TRUE) const;
  376. virtual LLView* findChildView(const std::string& name, BOOL recurse = TRUE) const;
  377. template <class T> T* getDefaultWidget(const std::string& name) const
  378. {
  379. LLView* widgetp = getDefaultWidgetContainer().findChildView(name);
  380. return dynamic_cast<T*>(widgetp);
  381. }
  382. template <class T> T* getParentByType() const
  383. {
  384. LLView* parent = getParent();
  385. while(parent)
  386. {
  387. if (dynamic_cast<T*>(parent))
  388. {
  389. return static_cast<T*>(parent);
  390. }
  391. parent = parent->getParent();
  392. }
  393. return NULL;
  394. }
  395. //////////////////////////////////////////////
  396. // statics
  397. //////////////////////////////////////////////
  398. //static LLFontGL::HAlign selectFontHAlign(LLXMLNodePtr node);
  399. // focuses the item in the list after the currently-focused item, wrapping if necessary
  400. static BOOL focusNext(LLView::child_list_t & result);
  401. // focuses the item in the list before the currently-focused item, wrapping if necessary
  402. static BOOL focusPrev(LLView::child_list_t & result);
  403. // returns query for iterating over controls in tab order
  404. static const LLCtrlQuery & getTabOrderQuery();
  405. // return query for iterating over focus roots in tab order
  406. static const LLCtrlQuery & getFocusRootsQuery();
  407. static LLWindow* getWindow(void) { return LLUI::sWindow; }
  408. // Set up params after XML load before calling new(),
  409. // usually to adjust layout.
  410. static void applyXUILayout(Params& p, LLView* parent);
  411. // For re-export of floaters and panels, convert the coordinate system
  412. // to be top-left based.
  413. static void setupParamsForExport(Params& p, LLView* parent);
  414. //virtual BOOL addChildFromParam(const LLInitParam::BaseBlock& params) { return TRUE; }
  415. virtual BOOL handleKeyHere(KEY key, MASK mask);
  416. virtual BOOL handleUnicodeCharHere(llwchar uni_char);
  417. virtual void handleReshape(const LLRect& rect, bool by_user);
  418. virtual void dirtyRect();
  419. //send custom notification to LLView parent
  420. virtual S32 notifyParent(const LLSD& info);
  421. //send custom notification to all view childrend
  422. // return true if _any_ children return true. otherwise false.
  423. virtual bool notifyChildren(const LLSD& info);
  424. //send custom notification to current view
  425. virtual S32 notify(const LLSD& info) { return 0;};
  426. static const LLViewDrawContext& getDrawContext();
  427. // Returns useful information about this ui widget.
  428. LLSD getInfo(void);
  429. protected:
  430. void drawDebugRect();
  431. void drawChild(LLView* childp, S32 x_offset = 0, S32 y_offset = 0, BOOL force_draw = FALSE);
  432. void drawChildren();
  433. bool visibleAndContains(S32 local_x, S32 local_Y);
  434. bool visibleEnabledAndContains(S32 local_x, S32 local_y);
  435. void logMouseEvent();
  436. LLView* childrenHandleKey(KEY key, MASK mask);
  437. LLView* childrenHandleUnicodeChar(llwchar uni_char);
  438. LLView* childrenHandleDragAndDrop(S32 x, S32 y, MASK mask,
  439. BOOL drop,
  440. EDragAndDropType type,
  441. void* data,
  442. EAcceptance* accept,
  443. std::string& tooltip_msg);
  444. LLView* childrenHandleHover(S32 x, S32 y, MASK mask);
  445. LLView* childrenHandleMouseUp(S32 x, S32 y, MASK mask);
  446. LLView* childrenHandleMouseDown(S32 x, S32 y, MASK mask);
  447. LLView* childrenHandleMiddleMouseUp(S32 x, S32 y, MASK mask);
  448. LLView* childrenHandleMiddleMouseDown(S32 x, S32 y, MASK mask);
  449. LLView* childrenHandleDoubleClick(S32 x, S32 y, MASK mask);
  450. LLView* childrenHandleScrollWheel(S32 x, S32 y, S32 clicks);
  451. LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask);
  452. LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask);
  453. LLView* childrenHandleToolTip(S32 x, S32 y, MASK mask);
  454. ECursorType mHoverCursor;
  455. virtual void addInfo(LLSD & info);
  456. private:
  457. template <typename METHOD, typename XDATA>
  458. LLView* childrenHandleMouseEvent(const METHOD& method, S32 x, S32 y, XDATA extra, bool allow_mouse_block = true);
  459. template <typename METHOD, typename CHARTYPE>
  460. LLView* childrenHandleCharEvent(const std::string& desc, const METHOD& method,
  461. CHARTYPE c, MASK mask);
  462. // adapter to blur distinction between handleKey() and handleUnicodeChar()
  463. // for childrenHandleCharEvent()
  464. BOOL handleUnicodeCharWithDummyMask(llwchar uni_char, MASK /* dummy */, BOOL from_parent)
  465. {
  466. return handleUnicodeChar(uni_char, from_parent);
  467. }
  468. LLView* mParentView;
  469. child_list_t mChildList;
  470. // location in pixels, relative to surrounding structure, bottom,left=0,0
  471. BOOL mVisible;
  472. LLRect mRect;
  473. LLRect mBoundingRect;
  474. std::string mLayout;
  475. std::string mName;
  476. U32 mReshapeFlags;
  477. child_tab_order_t mCtrlOrder;
  478. S32 mDefaultTabGroup;
  479. S32 mLastTabGroup;
  480. BOOL mEnabled; // Enabled means "accepts input that has an effect on the state of the application."
  481. // A disabled view, for example, may still have a scrollbar that responds to mouse events.
  482. BOOL mMouseOpaque; // Opaque views handle all mouse events that are over their rect.
  483. LLUIString mToolTipMsg; // isNull() is true if none.
  484. U8 mSoundFlags;
  485. BOOL mFromXUI;
  486. BOOL mIsFocusRoot;
  487. BOOL mUseBoundingRect; // hit test against bounding rectangle that includes all child elements
  488. BOOL mLastVisible;
  489. S32 mNextInsertionOrdinal;
  490. bool mInDraw;
  491. static LLWindow* sWindow; // All root views must know about their window.
  492. typedef std::map<std::string, LLView*> default_widget_map_t;
  493. // allocate this map no demand, as it is rarely needed
  494. mutable LLView* mDefaultWidgets;
  495. LLView& getDefaultWidgetContainer() const;
  496. // This allows special mouse-event targeting logic for testing.
  497. typedef boost::function<bool(const LLView*, S32 x, S32 y)> DrilldownFunc;
  498. static DrilldownFunc sDrilldown;
  499. public:
  500. // This is the only public accessor to alter sDrilldown. This is not
  501. // an accident. The intended usage pattern is like:
  502. // {
  503. // LLView::TemporaryDrilldownFunc scoped_func(myfunctor);
  504. // // ... test with myfunctor ...
  505. // } // exiting block restores original LLView::sDrilldown
  506. class TemporaryDrilldownFunc: public boost::noncopyable
  507. {
  508. public:
  509. TemporaryDrilldownFunc(const DrilldownFunc& func):
  510. mOldDrilldown(sDrilldown)
  511. {
  512. sDrilldown = func;
  513. }
  514. ~TemporaryDrilldownFunc()
  515. {
  516. sDrilldown = mOldDrilldown;
  517. }
  518. private:
  519. DrilldownFunc mOldDrilldown;
  520. };
  521. // Depth in view hierarchy during rendering
  522. static S32 sDepth;
  523. // Draw debug rectangles around widgets to help with alignment and spacing
  524. static bool sDebugRects;
  525. // Draw widget names and sizes when drawing debug rectangles, turning this
  526. // off is useful to make the rectangles themselves easier to see.
  527. static bool sDebugRectsShowNames;
  528. static bool sDebugKeys;
  529. static bool sDebugMouseHandling;
  530. static std::string sMouseHandlerMessage;
  531. static S32 sSelectID;
  532. static std::set<LLView*> sPreviewHighlightedElements; // DEV-16869
  533. static BOOL sHighlightingDiffs; // DEV-16869
  534. static LLView* sPreviewClickedElement; // DEV-16869
  535. static BOOL sDrawPreviewHighlights;
  536. static S32 sLastLeftXML;
  537. static S32 sLastBottomXML;
  538. static BOOL sForceReshape;
  539. };
  540. class LLCompareByTabOrder
  541. {
  542. public:
  543. LLCompareByTabOrder(const LLView::child_tab_order_t& order) : mTabOrder(order) {}
  544. virtual ~LLCompareByTabOrder() {}
  545. bool operator() (const LLView* const a, const LLView* const b) const;
  546. private:
  547. virtual bool compareTabOrders(const LLView::tab_order_t & a, const LLView::tab_order_t & b) const { return a < b; }
  548. // ok to store a reference, as this should only be allocated on stack during view query operations
  549. const LLView::child_tab_order_t& mTabOrder;
  550. };
  551. template <class T> T* LLView::getChild(const std::string& name, BOOL recurse) const
  552. {
  553. LLView* child = findChildView(name, recurse);
  554. T* result = dynamic_cast<T*>(child);
  555. if (!result)
  556. {
  557. // did we find *something* with that name?
  558. if (child)
  559. {
  560. llwarns << "Found child named \"" << name << "\" but of wrong type " << typeid(*child).name() << ", expecting " << typeid(T*).name() << llendl;
  561. }
  562. result = getDefaultWidget<T>(name);
  563. if (!result)
  564. {
  565. result = LLUICtrlFactory::getDefaultWidget<T>(name);
  566. if (result)
  567. {
  568. // *NOTE: You cannot call mFoo = getChild<LLFoo>("bar")
  569. // in a floater or panel constructor. The widgets will not
  570. // be ready. Instead, put it in postBuild().
  571. llwarns << "Making dummy " << typeid(T).name() << " named \"" << name << "\" in " << getName() << llendl;
  572. }
  573. else
  574. {
  575. llwarns << "Failed to create dummy " << typeid(T).name() << llendl;
  576. return NULL;
  577. }
  578. getDefaultWidgetContainer().addChild(result);
  579. }
  580. }
  581. return result;
  582. }
  583. // Compiler optimization - don't generate these specializations inline,
  584. // require explicit specialization. See llbutton.cpp for an example.
  585. #ifndef LLVIEW_CPP
  586. extern template class LLView* LLView::getChild<class LLView>(
  587. const std::string& name, BOOL recurse) const;
  588. #endif
  589. #endif //LL_LLVIEW_H