llview.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /**
  2. * @file llview.h
  3. * @brief Container for other views, anything that draws.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEW_H
  33. #define LL_LLVIEW_H
  34. // A view is an area in a window that can draw. It might represent the HUD or a
  35. // dialog box or a button. It can also contain sub-views and child widgets.
  36. #include "boost/function.hpp"
  37. #include "boost/signals2.hpp"
  38. #include "llassettype.h"
  39. #include "llcoord.h"
  40. #include "llcursortypes.h"
  41. #include "llerror.h"
  42. #include "llevent.h"
  43. #include "hbfastmap.h"
  44. #include "llfocusmgr.h"
  45. #include "llfontgl.h"
  46. #include "llhandle.h"
  47. #include "llmortician.h"
  48. #include "llmousehandler.h"
  49. #include "llrect.h"
  50. #include "llui.h"
  51. #include "lluistring.h"
  52. #include "llviewquery.h"
  53. #include "llxmlnode.h"
  54. class LLFloater;
  55. class HBLuaFloater;
  56. class LLPanel;
  57. class LLUICrtl;
  58. class LLUICtrlFactory;
  59. constexpr U8 FOLLOWS_NONE = 0x00;
  60. constexpr U8 FOLLOWS_LEFT = 0x01;
  61. constexpr U8 FOLLOWS_RIGHT = 0x02;
  62. constexpr U8 FOLLOWS_TOP = 0x10;
  63. constexpr U8 FOLLOWS_BOTTOM = 0x20;
  64. constexpr U8 FOLLOWS_ALL = 0x33;
  65. constexpr U32 GL_NAME_UI_RESERVED = 2;
  66. // Maps XML strings to widget classes
  67. class LLWidgetClassRegistry : public LLSingleton<LLWidgetClassRegistry>
  68. {
  69. friend class LLSingleton<LLWidgetClassRegistry>;
  70. public:
  71. typedef LLView* (*factory_func_t)(LLXMLNodePtr node, LLView* parent,
  72. LLUICtrlFactory* factory);
  73. typedef fast_hmap<std::string, factory_func_t> factory_map_t;
  74. LL_INLINE void registerCtrl(const std::string& tag, factory_func_t func)
  75. {
  76. mCreatorFunctions.emplace(tag, func);
  77. }
  78. LL_INLINE bool isTagRegistered(const std::string& xml_tag)
  79. {
  80. return mCreatorFunctions.count(xml_tag) > 0;
  81. }
  82. LL_INLINE factory_func_t getCreatorFunc(const std::string& xml_tag)
  83. {
  84. factory_map_t::const_iterator it = mCreatorFunctions.find(xml_tag);
  85. return it != mCreatorFunctions.end() ? it->second : NULL;
  86. }
  87. // Gets (first) xml tag for a given class
  88. template<class T> const std::string& getTag()
  89. {
  90. for (factory_map_t::iterator it = mCreatorFunctions.begin(),
  91. end = mCreatorFunctions.end();
  92. it != end; ++it)
  93. {
  94. if (it->second == T::fromXML)
  95. {
  96. return it->first;
  97. }
  98. }
  99. return LLStringUtil::null;
  100. }
  101. private:
  102. LLWidgetClassRegistry() = default;
  103. virtual ~LLWidgetClassRegistry() = default;
  104. private:
  105. // Map of XML tags to widget creator functions
  106. factory_map_t mCreatorFunctions;
  107. };
  108. template<class T>
  109. class LLRegisterWidget
  110. {
  111. public:
  112. LLRegisterWidget(const std::string& tag)
  113. {
  114. LLWidgetClassRegistry* registry = LLWidgetClassRegistry::getInstance();
  115. if (registry->isTagRegistered(tag))
  116. {
  117. llerrs << "Widget named " << tag << " is already registered !"
  118. << llendl;
  119. }
  120. else
  121. {
  122. registry->registerCtrl(tag, T::fromXML);
  123. }
  124. }
  125. };
  126. class LLView : public LLMouseHandler, public LLFocusableElement,
  127. public LLMortician, public LLHandleProvider<LLView>,
  128. public boost::signals2::trackable
  129. {
  130. protected:
  131. LOG_CLASS(LLView);
  132. public:
  133. enum ESoundFlags
  134. {
  135. SILENT = 0,
  136. MOUSE_DOWN = 1,
  137. MOUSE_UP = 2
  138. };
  139. enum ESnapType
  140. {
  141. SNAP_PARENT,
  142. SNAP_SIBLINGS,
  143. SNAP_PARENT_AND_SIBLINGS
  144. };
  145. enum ESnapEdge
  146. {
  147. SNAP_LEFT,
  148. SNAP_TOP,
  149. SNAP_RIGHT,
  150. SNAP_BOTTOM
  151. };
  152. typedef std::list<LLView*> child_list_t;
  153. typedef child_list_t::iterator child_list_iter_t;
  154. typedef child_list_t::const_iterator child_list_const_iter_t;
  155. typedef child_list_t::reverse_iterator child_list_reverse_iter_t;
  156. typedef child_list_t::const_reverse_iterator child_list_const_reverse_iter_t;
  157. typedef std::vector<class LLUICtrl*> ctrl_list_t;
  158. typedef std::pair<S32, S32> tab_order_t;
  159. typedef std::pair<LLUICtrl*, tab_order_t> tab_order_pair_t;
  160. // This container primarily sorts by the tab group, secondarily by the
  161. // insertion ordinal (lastly by the value of the pointer)
  162. typedef std::map<const LLUICtrl*, tab_order_t> child_tab_order_t;
  163. typedef child_tab_order_t::iterator child_tab_order_iter_t;
  164. typedef child_tab_order_t::const_iterator child_tab_order_const_iter_t;
  165. LLView();
  166. LLView(const std::string& name, bool mouse_opaque);
  167. LLView(const std::string& name, const LLRect& rect, bool mouse_opaque,
  168. U8 follows = FOLLOWS_NONE);
  169. // UI elements are not copyable
  170. LLView(const LLView&) = delete;
  171. ~LLView() override;
  172. // Hack to support LLFocusMgr (from LLMouseHandler)
  173. LL_INLINE bool isView() const override { return true; }
  174. // Some UI widgets need to be added as controls. Others need to be added as
  175. // regular view children. isCtrl() should return true if a widget needs to
  176. // be added as a ctrl.
  177. LL_INLINE virtual bool isCtrl() const { return false; }
  178. LL_INLINE virtual LLFloater* asFloater() { return NULL; }
  179. LL_INLINE virtual LLPanel* asPanel() { return NULL; }
  180. LL_INLINE virtual HBLuaFloater* asLuaFloater() { return NULL; }
  181. LL_INLINE void setMouseOpaque(bool b) { mMouseOpaque = b; }
  182. LL_INLINE bool getMouseOpaque() const { return mMouseOpaque; }
  183. void setToolTip(const std::string& msg);
  184. bool setToolTipArg(const std::string& key, const std::string& text);
  185. void setToolTipArgs(const LLStringUtil::format_map_t& args);
  186. virtual void setRect(const LLRect& rect);
  187. void setFollows(U8 flags) { mReshapeFlags = flags; }
  188. LL_INLINE void setFollowsNone() { mReshapeFlags = FOLLOWS_NONE; }
  189. LL_INLINE void setFollowsLeft() { mReshapeFlags |= FOLLOWS_LEFT; }
  190. LL_INLINE void setFollowsTop() { mReshapeFlags |= FOLLOWS_TOP; }
  191. LL_INLINE void setFollowsRight() { mReshapeFlags |= FOLLOWS_RIGHT; }
  192. LL_INLINE void setFollowsBottom() { mReshapeFlags |= FOLLOWS_BOTTOM; }
  193. LL_INLINE void setFollowsAll() { mReshapeFlags = FOLLOWS_ALL; }
  194. LL_INLINE void setSoundFlags(U8 flags) { mSoundFlags = flags; }
  195. LL_INLINE void setName(const std::string& name) { mName = name; }
  196. void setUseBoundingRect(bool use_bounding_rect);
  197. LL_INLINE bool getUseBoundingRect() { return mUseBoundingRect; }
  198. const std::string& getToolTip() const;
  199. void sendChildToFront(LLView* child);
  200. void sendChildToBack(LLView* child);
  201. void moveChildToFrontOfTabGroup(LLUICtrl* child);
  202. void moveChildToBackOfTabGroup(LLUICtrl* child);
  203. void addChild(LLView* view, S32 tab_group = 0);
  204. void addChildAtEnd(LLView* view, S32 tab_group = 0);
  205. // Removes the specified child from the view, and sets its parent to NULL.
  206. void removeChild(LLView* view, bool delete_it = false);
  207. virtual void addCtrl(LLUICtrl* ctrl, S32 tab_group);
  208. virtual void addCtrlAtEnd(LLUICtrl* ctrl, S32 tab_group);
  209. virtual void removeCtrl(LLUICtrl* ctrl);
  210. LL_INLINE child_tab_order_t getCtrlOrder() const { return mCtrlOrder; }
  211. ctrl_list_t getCtrlList() const;
  212. ctrl_list_t getCtrlListSorted() const;
  213. void setDefaultTabGroup(S32 d) { mDefaultTabGroup = d; }
  214. LL_INLINE S32 getDefaultTabGroup() const { return mDefaultTabGroup; }
  215. bool isInVisibleChain() const;
  216. bool isInEnabledChain() const;
  217. LL_INLINE void setFocusRoot(bool b) { mIsFocusRoot = b; }
  218. LL_INLINE bool isFocusRoot() const { return mIsFocusRoot; }
  219. LL_INLINE virtual bool canFocusChildren() const { return true; }
  220. bool focusNextRoot();
  221. bool focusPrevRoot();
  222. // Deletes all children. Override this function if you need to perform any
  223. // extra clean up such as cached pointers to selected children, etc.
  224. virtual void deleteAllChildren();
  225. LL_INLINE virtual void setTentative(bool b) {}
  226. LL_INLINE virtual bool getTentative() const { return false; }
  227. void setAllChildrenEnabled(bool b);
  228. virtual void setVisible(bool visible);
  229. LL_INLINE bool getVisible() const { return mVisible; }
  230. LL_INLINE virtual void setEnabled(bool enabled) { mEnabled = enabled; }
  231. LL_INLINE bool getEnabled() const { return mEnabled; }
  232. LL_INLINE U8 getSoundFlags() const { return mSoundFlags; }
  233. LL_INLINE virtual bool setLabelArg(const std::string& key,
  234. const std::string& text)
  235. {
  236. return false;
  237. }
  238. virtual void onVisibilityChange(bool cur_visibility_in);
  239. LL_INLINE void pushVisible(bool visible)
  240. {
  241. mLastVisible = mVisible;
  242. setVisible(visible);
  243. }
  244. LL_INLINE void popVisible()
  245. {
  246. setVisible(mLastVisible);
  247. mLastVisible = true;
  248. }
  249. LL_INLINE U8 getFollows() const { return mReshapeFlags; }
  250. LL_INLINE bool followsLeft() const { return (mReshapeFlags & FOLLOWS_LEFT) != 0; }
  251. LL_INLINE bool followsRight() const { return (mReshapeFlags & FOLLOWS_RIGHT) != 0; }
  252. LL_INLINE bool followsTop() const { return (mReshapeFlags & FOLLOWS_TOP) != 0; }
  253. LL_INLINE bool followsBottom() const { return (mReshapeFlags & FOLLOWS_BOTTOM) != 0; }
  254. LL_INLINE bool followsAll() const { return mReshapeFlags == FOLLOWS_ALL; }
  255. LL_INLINE const LLRect& getRect() const { return mRect; }
  256. LL_INLINE const LLRect& getBoundingRect() const { return mBoundingRect; }
  257. LLRect getLocalBoundingRect() const;
  258. LLRect getScreenRect() const;
  259. LLRect getLocalRect() const;
  260. LL_INLINE virtual LLRect getSnapRect() const { return mRect; }
  261. LLRect getLocalSnapRect() const;
  262. // Override and return required size for this object. 0 for width/height
  263. // means do not care.
  264. LL_INLINE virtual LLRect getRequiredRect() { return mRect; }
  265. void updateBoundingRect();
  266. LLView* getRootView();
  267. LL_INLINE LLView* getParent() const { return mParentView; }
  268. // Return the parent floater, if any, or NULL. HB
  269. LLFloater* getParentFloater() const;
  270. LL_INLINE LLView* getFirstChild() const
  271. {
  272. return mChildList.empty() ? NULL : *(mChildList.begin());
  273. }
  274. LLView* findPrevSibling(LLView* child);
  275. LLView* findNextSibling(LLView* child);
  276. LL_INLINE S32 getChildCount() const { return mChildListSize; }
  277. template<class T> void sortChildren(T compare_fn) { mChildList.sort(compare_fn); }
  278. bool hasAncestor(const LLView* parentp) const;
  279. bool childHasKeyboardFocus(const char* childname) const;
  280. // Default behavior is to use reshape flags to resize child views
  281. virtual void reshape(S32 width, S32 height, bool from_parent = true);
  282. virtual void translate(S32 x, S32 y);
  283. LL_INLINE void setOrigin(S32 x, S32 y)
  284. {
  285. mRect.translate(x - mRect.mLeft, y - mRect.mBottom);
  286. }
  287. bool translateIntoRect(const LLRect& constraint, bool allow_part_outside);
  288. void centerWithin(const LLRect& bounds);
  289. virtual void userSetShape(const LLRect& new_rect);
  290. virtual LLView* findSnapRect(LLRect& new_rect, const LLCoordGL& mouse_dir,
  291. LLView::ESnapType snap_type, S32 threshold,
  292. S32 padding = 0);
  293. virtual LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir,
  294. ESnapEdge snap_edge, ESnapType snap_type,
  295. S32 threshold, S32 padding = 0);
  296. virtual bool canSnapTo(LLView* other_viewp);
  297. LL_INLINE virtual void snappedTo(LLView* viewp) {}
  298. LL_INLINE virtual bool getIsChrome() const { return false; }
  299. // Inherited from LLFocusableElement
  300. LL_INLINE bool isFocusableCtrl() const override { return false; }
  301. bool handleKey(KEY key, MASK mask, bool from_parent) override;
  302. bool handleKeyUp(KEY key, MASK mask, bool from_parent) override;
  303. bool handleUnicodeChar(llwchar uni_char, bool from_parent) override;
  304. virtual bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  305. EDragAndDropType cargo_type,
  306. void* cargo_data, EAcceptance* accept,
  307. std::string& tooltip_msg);
  308. std::string getShowNamesToolTip();
  309. virtual void draw();
  310. // Returns the "tag" this UI element is registered as via LLRegisterWidget,
  311. // which is the XML element name for this widget, as used in XUI files. HB
  312. virtual const std::string& getTag() const;
  313. virtual LLXMLNodePtr getXML(bool save_children = true) const;
  314. //FIXME: make LLView non-instantiable from XML
  315. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  316. class LLUICtrlFactory* factory);
  317. virtual void initFromXML(LLXMLNodePtr node, LLView* parent);
  318. void parseFollowsFlags(LLXMLNodePtr node);
  319. // Some widgets, like close box buttons, don't need to be saved
  320. LL_INLINE bool getSaveToXML() const { return mSaveToXML; }
  321. LL_INLINE void setSaveToXML(bool b) { mSaveToXML = b; }
  322. // Inherited from LLFocusableElement
  323. LL_INLINE void onFocusLost() override {}
  324. LL_INLINE void onFocusReceived() override {}
  325. typedef enum e_hit_test_type
  326. {
  327. HIT_TEST_USE_BOUNDING_RECT,
  328. HIT_TEST_IGNORE_BOUNDING_RECT
  329. } EHitTestType;
  330. bool parentPointInView(S32 x, S32 y,
  331. EHitTestType type = HIT_TEST_USE_BOUNDING_RECT) const;
  332. bool pointInView(S32 x, S32 y,
  333. EHitTestType type = HIT_TEST_USE_BOUNDING_RECT) const;
  334. bool blockMouseEvent(S32 x, S32 y) const;
  335. // See LLMouseHandler virtuals for screenPointToLocal and localPointToScreen
  336. bool localPointToOtherView(S32 x, S32 y, S32* other_x, S32* other_y,
  337. LLView* other_view) const;
  338. bool localRectToOtherView(const LLRect& local, LLRect* other,
  339. LLView* other_view) const;
  340. void screenRectToLocal(const LLRect& screen, LLRect* local) const;
  341. void localRectToScreen(const LLRect& local, LLRect* screen) const;
  342. // Listener dispatching functions (dispatcher deletes pointers to listeners
  343. // on deregistration or destruction)
  344. LLOldEvents::LLSimpleListener* getListenerByName(const std::string& cb_name);
  345. void registerEventListener(const std::string& name,
  346. LLOldEvents::LLSimpleListener* function);
  347. void deregisterEventListener(const std::string& name);
  348. std::string findEventListener(LLOldEvents::LLSimpleListener* listener) const;
  349. void addListenerToControl(LLOldEvents::LLEventDispatcher* observer,
  350. const std::string& name, LLSD filter,
  351. LLSD userdata);
  352. void addBoolControl(const std::string& name, bool initial_value);
  353. LLControlVariable* getControl(const std::string& name);
  354. LLControlVariable* findControl(const std::string& name);
  355. bool setControlValue(const LLSD& value);
  356. virtual void setControlName(const char* control, LLView* contextp);
  357. LL_INLINE virtual const std::string& getControlName() const
  358. {
  359. return mControlName;
  360. }
  361. #if 0
  362. virtual bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  363. const LLSD& userdata);
  364. #endif
  365. LL_INLINE virtual void setValue(const LLSD& value) {}
  366. LL_INLINE virtual LLSD getValue() const { return LLSD(); }
  367. LL_INLINE const child_list_t* getChildList() const { return &mChildList; }
  368. // LLMouseHandler functions
  369. // Default behavior is to pass events to children
  370. bool handleHover(S32 x, S32 y, MASK mask) override;
  371. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  372. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  373. bool handleMiddleMouseUp(S32 x, S32 y, MASK mask) override;
  374. bool handleMiddleMouseDown(S32 x, S32 y, MASK mask) override;
  375. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  376. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  377. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  378. bool handleRightMouseUp(S32 x, S32 y, MASK mask) override;
  379. // Display tooltip if no child handles it.
  380. bool handleToolTip(S32 x, S32 y, std::string& msg, LLRect* rect) override;
  381. std::string getName() const override;
  382. LL_INLINE void onMouseCaptureLost() override {}
  383. bool hasMouseCapture() override;
  384. void screenPointToLocal(S32 screen_x, S32 screen_y,
  385. S32* local_x, S32* local_y) const override;
  386. void localPointToScreen(S32 local_x, S32 local_y,
  387. S32* screen_x, S32* screen_y) const override;
  388. template<class T> T* getChild(const char* name, bool recurse = true,
  389. bool create_if_missing = true) const
  390. {
  391. LLView* child = getChildView(name, recurse, false);
  392. T* result = dynamic_cast<T*>(child);
  393. if (!result)
  394. {
  395. // Did we find *something* with that name ?
  396. if (child)
  397. {
  398. llwarns << "Found child named " << name
  399. << " but of wrong type " << typeid(child).name()
  400. << ", expecting " << typeid(T).name() << llendl;
  401. }
  402. if (create_if_missing)
  403. {
  404. // Create dummy widget instance here
  405. result = createDummyWidget<T>(name);
  406. }
  407. }
  408. return result;
  409. }
  410. virtual LLView* getChildView(const char* name, bool recurse = true,
  411. bool create_if_missing = true) const;
  412. template<class T> T* createDummyWidget(const char* name) const
  413. {
  414. T* widget = getDummyWidget<T>(name);
  415. if (!widget)
  416. {
  417. // Get xml tag name corresponding to requested widget type (e.g.
  418. // "button")
  419. std::string xml_tag =
  420. LLWidgetClassRegistry::getInstance()->getTag<T>();
  421. if (xml_tag.empty())
  422. {
  423. llwarns << "No xml tag registered for this class " << llendl;
  424. return NULL;
  425. }
  426. // Create dummy xml node (<button name="foo"/>)
  427. LLXMLNodePtr new_node_ptr = new LLXMLNode(xml_tag.c_str(), false);
  428. new_node_ptr->createChild("name", true)->setStringValue(name);
  429. widget = dynamic_cast<T*>(createWidget(new_node_ptr));
  430. if (widget)
  431. {
  432. // Need non-const to update private dummy widget cache
  433. llwarns << "Making dummy " << xml_tag << " named '" << name
  434. << "' in " << getName() << llendl;
  435. mDummyWidgets.emplace(name, widget);
  436. }
  437. else
  438. {
  439. // Dynamic cast will fail if T::fromXML only registered for
  440. // base class
  441. llwarns << "Failed to create dummy widget of requested type ("
  442. << xml_tag << ") named '" << name << "'" << " in "
  443. << getName() << llendl;
  444. return NULL;
  445. }
  446. }
  447. return widget;
  448. }
  449. template<class T> T* getDummyWidget(const char* wname) const
  450. {
  451. std::string name(wname);
  452. widget_map_t::const_iterator it = mDummyWidgets.find(name);
  453. if (it == mDummyWidgets.end())
  454. {
  455. return NULL;
  456. }
  457. return dynamic_cast<T*>(it->second);
  458. }
  459. LLView* createWidget(LLXMLNodePtr xml_node) const;
  460. static U32 createRect(LLXMLNodePtr node, LLRect& rect, LLView* parent_view,
  461. const LLRect& required_rect = LLRect());
  462. static LLFontGL* selectFont(LLXMLNodePtr node);
  463. static LLFontGL::HAlign selectFontHAlign(LLXMLNodePtr node);
  464. static LLFontGL::VAlign selectFontVAlign(LLXMLNodePtr node);
  465. static LLFontGL::StyleFlags selectFontStyle(LLXMLNodePtr node);
  466. // Only saves color if different from default setting.
  467. static void addColorXML(LLXMLNodePtr node, const LLColor4& color,
  468. const char* xml_name, const char* control_name);
  469. // Escapes " (quot) ' (apos) & (amp) < (lt) > (gt)
  470. static LLWString escapeXML(const LLWString& xml);
  471. // Same as above, but wraps multiple lines in quotes and prepends indent as
  472. // leading white space on each line
  473. static std::string escapeXML(const std::string& xml, std::string& indent);
  474. // Focuses the item in the list after the currently-focused item, wrapping
  475. // if necessary
  476. static bool focusNext(LLView::child_list_t& result);
  477. // Focuses the item in the list before the currently-focused item, wrapping
  478. // if necessary
  479. static bool focusPrev(LLView::child_list_t& result);
  480. // Returns query for iterating over controls in tab order
  481. static const LLCtrlQuery& getTabOrderQuery();
  482. // Returns query for iterating over focus roots in tab order
  483. static const LLCtrlQuery& getFocusRootsQuery();
  484. static bool deleteViewByHandle(LLHandle<LLView> handle);
  485. protected:
  486. LL_INLINE virtual bool handleKeyHere(KEY key, MASK mask)
  487. {
  488. // Checking parents and children happens in handleKey()
  489. return false;
  490. }
  491. LL_INLINE virtual bool handleKeyUpHere(KEY key, MASK mask)
  492. {
  493. return false;
  494. }
  495. LL_INLINE virtual bool handleUnicodeCharHere(llwchar uni_char)
  496. {
  497. return false;
  498. }
  499. void drawDebugRect();
  500. void drawChild(LLView* childp, S32 x_offset = 0, S32 y_offset = 0,
  501. bool force_draw = false);
  502. LLView* childrenHandleKey(KEY key, MASK mask);
  503. LLView* childrenHandleKeyUp(KEY key, MASK mask);
  504. LLView* childrenHandleUnicodeChar(llwchar uni_char);
  505. LLView* childrenHandleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  506. EDragAndDropType type, void* data,
  507. EAcceptance* accept,
  508. std::string& tooltip_msg);
  509. LLView* childrenHandleHover(S32 x, S32 y, MASK mask);
  510. LLView* childrenHandleMouseUp(S32 x, S32 y, MASK mask);
  511. LLView* childrenHandleMouseDown(S32 x, S32 y, MASK mask);
  512. LLView* childrenHandleMiddleMouseUp(S32 x, S32 y, MASK mask);
  513. LLView* childrenHandleMiddleMouseDown(S32 x, S32 y, MASK mask);
  514. LLView* childrenHandleDoubleClick(S32 x, S32 y, MASK mask);
  515. LLView* childrenHandleScrollWheel(S32 x, S32 y, S32 clicks);
  516. LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask);
  517. LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask);
  518. static bool controlListener(const LLSD& newvalue, LLHandle<LLView> handle,
  519. const std::string& type);
  520. protected:
  521. typedef fast_hmap<std::string, LLControlVariable*> control_map_t;
  522. control_map_t mControls;
  523. private:
  524. LLView* mParentView;
  525. LLUIString* mToolTipMsgPtr;
  526. std::string mName;
  527. std::string mControlName;
  528. child_list_t mChildList;
  529. child_tab_order_t mCtrlOrder;
  530. typedef boost::signals2::connection signal_connection_t;
  531. signal_connection_t mControlConnection;
  532. typedef fast_hmap<std::string,
  533. LLPointer<LLOldEvents::LLSimpleListener> > dispatch_list_t;
  534. dispatch_list_t mDispatchList;
  535. typedef fast_hmap<std::string, LLView*> widget_map_t;
  536. mutable widget_map_t mDummyWidgets;
  537. // Location in pixels, relative to surrounding structure, bottom,left=0,0
  538. LLRect mRect;
  539. LLRect mBoundingRect;
  540. ECursorType mHoverCursor;
  541. S32 mDefaultTabGroup;
  542. S32 mChildListSize;
  543. S32 mNextInsertionOrdinal;
  544. U8 mReshapeFlags;
  545. U8 mSoundFlags;
  546. bool mSaveToXML;
  547. bool mIsFocusRoot;
  548. // Hit test against bounding rectangle that includes all child elements
  549. bool mUseBoundingRect;
  550. bool mLastVisible;
  551. bool mVisible;
  552. // Enabled means 'accepts input that has an effect on the state of the
  553. // application.' A disabled view, for example, may still have a scrollbar
  554. // that responds to mouse events.
  555. bool mEnabled;
  556. // Opaque views handle all mouse events that are over their rect.
  557. bool mMouseOpaque;
  558. // All root views must know about their window.
  559. static LLWindow* sWindow;
  560. public:
  561. static LLView* sEditingUIView;
  562. static std::string sMouseHandlerMessage;
  563. static S32 sDepth;
  564. static S32 sSelectID;
  565. static S32 sLastLeftXML;
  566. static S32 sLastBottomXML;
  567. static bool sEditingUI;
  568. static bool sDebugRects; // Draw debug rects behind everything.
  569. static bool sDebugKeys;
  570. static bool sDebugMouseHandling;
  571. static bool sForceReshape;
  572. };
  573. class LLCompareByTabOrder
  574. {
  575. public:
  576. LL_INLINE LLCompareByTabOrder(LLView::child_tab_order_t order)
  577. : mTabOrder(order)
  578. {
  579. }
  580. virtual ~LLCompareByTabOrder() = default;
  581. bool operator()(const LLView* const a, const LLView* const b) const;
  582. private:
  583. LL_INLINE virtual bool compareTabOrders(const LLView::tab_order_t& a,
  584. const LLView::tab_order_t& b) const
  585. {
  586. return a < b;
  587. }
  588. private:
  589. LLView::child_tab_order_t mTabOrder;
  590. };
  591. // Used to be in its own llrootview.h/cpp module, but what for ?... HB
  592. class LLRootView : public LLView
  593. {
  594. public:
  595. LL_INLINE LLRootView(const std::string& name, const LLRect& rect,
  596. bool mouse_opaque, U32 follows = FOLLOWS_NONE)
  597. : LLView(name, rect, mouse_opaque, follows)
  598. {
  599. }
  600. };
  601. #endif //LL_LLVIEW_H