aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llview.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llui/llview.h')
-rw-r--r--linden/indra/llui/llview.h511
1 files changed, 511 insertions, 0 deletions
diff --git a/linden/indra/llui/llview.h b/linden/indra/llui/llview.h
new file mode 100644
index 0000000..268f157
--- /dev/null
+++ b/linden/indra/llui/llview.h
@@ -0,0 +1,511 @@
1/**
2 * @file llview.h
3 * @brief Container for other views, anything that draws.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLVIEW_H
29#define LL_LLVIEW_H
30
31// A view is an area in a window that can draw. It might represent
32// the HUD or a dialog box or a button. It can also contain sub-views
33// and child widgets
34
35#include <iosfwd>
36#include <list>
37
38#include "lluixmltags.h"
39#include "llrect.h"
40#include "llmousehandler.h"
41#include "stdenums.h"
42#include "llsd.h"
43#include "llstring.h"
44#include "llnametable.h"
45#include "llcoord.h"
46#include "llmortician.h"
47#include "llxmlnode.h"
48#include "llfontgl.h"
49#include "llviewquery.h"
50
51#include "llui.h"
52
53class LLColor4;
54class LLWindow;
55class LLUICtrl;
56class LLScrollListItem;
57
58const U32 FOLLOWS_NONE = 0x00;
59const U32 FOLLOWS_LEFT = 0x01;
60const U32 FOLLOWS_RIGHT = 0x02;
61const U32 FOLLOWS_TOP = 0x10;
62const U32 FOLLOWS_BOTTOM = 0x20;
63const U32 FOLLOWS_ALL = 0x33;
64
65const BOOL MOUSE_OPAQUE = TRUE;
66const BOOL NOT_MOUSE_OPAQUE = FALSE;
67
68const U32 GL_NAME_UI_RESERVED = 2;
69
70class LLSimpleListener;
71class LLEventDispatcher;
72
73class LLViewHandle
74{
75public:
76 LLViewHandle() { mID = 0; }
77
78 void init() { mID = ++sNextID; }
79 void markDead() { mID = 0; }
80 BOOL isDead() { return (mID == 0); }
81 friend bool operator==(const LLViewHandle& lhs, const LLViewHandle& rhs);
82 friend bool operator!=(const LLViewHandle& lhs, const LLViewHandle& rhs);
83 friend bool operator<(const LLViewHandle &a, const LLViewHandle &b);
84
85public:
86 static LLViewHandle sDeadHandle;
87
88protected:
89 S32 mID;
90
91 static S32 sNextID;
92};
93
94class LLView : public LLMouseHandler, public LLMortician, public LLSimpleListenerObservable
95{
96
97public:
98#if LL_DEBUG
99 static BOOL sIsDrawing;
100#endif
101 enum ESoundFlags
102 {
103 SILENT = 0,
104 MOUSE_DOWN = 1,
105 MOUSE_UP = 2
106 };
107
108 enum ESnapType
109 {
110 SNAP_PARENT,
111 SNAP_SIBLINGS,
112 SNAP_PARENT_AND_SIBLINGS
113 };
114
115 enum ESnapEdge
116 {
117 SNAP_LEFT,
118 SNAP_TOP,
119 SNAP_RIGHT,
120 SNAP_BOTTOM
121 };
122
123 typedef std::list<LLView*> child_list_t;
124 typedef child_list_t::iterator child_list_iter_t;
125 typedef child_list_t::const_iterator child_list_const_iter_t;
126 typedef child_list_t::reverse_iterator child_list_reverse_iter_t;
127 typedef child_list_t::const_reverse_iterator child_list_const_reverse_iter_t;
128
129 typedef std::vector<LLUICtrl *> ctrl_list_t;
130
131 typedef std::pair<S32, S32> tab_order_t;
132 typedef std::pair<LLUICtrl *, tab_order_t> tab_order_pair_t;
133 // this structure primarily sorts by the tab group, secondarily by the insertion ordinal (lastly by the value of the pointer)
134 typedef std::map<const LLUICtrl*, tab_order_t> child_tab_order_t;
135 typedef child_tab_order_t::iterator child_tab_order_iter_t;
136 typedef child_tab_order_t::const_iterator child_tab_order_const_iter_t;
137 typedef child_tab_order_t::reverse_iterator child_tab_order_reverse_iter_t;
138 typedef child_tab_order_t::const_reverse_iterator child_tab_order_const_reverse_iter_t;
139
140private:
141 LLView* mParentView;
142 child_list_t mChildList;
143
144protected:
145 LLString mName;
146 // location in pixels, relative to surrounding structure, bottom,left=0,0
147 LLRect mRect;
148
149 U32 mReshapeFlags;
150
151 child_tab_order_t mCtrlOrder;
152 S32 mDefaultTabGroup;
153
154 BOOL mEnabled; // Enabled means "accepts input that has an effect on the state of the application."
155 // A disabled view, for example, may still have a scrollbar that responds to mouse events.
156 BOOL mMouseOpaque; // Opaque views handle all mouse events that are over their rect.
157 LLString mToolTipMsg; // isNull() is true if none.
158
159 U8 mSoundFlags;
160 BOOL mSaveToXML;
161
162 BOOL mIsFocusRoot;
163
164public:
165 LLViewHandle mViewHandle;
166 BOOL mLastVisible;
167 BOOL mRenderInFastFrame;
168 BOOL mSpanChildren;
169
170private:
171 BOOL mVisible;
172 BOOL mHidden; // Never show (generally for replacement text only)
173
174 S32 mNextInsertionOrdinal;
175
176protected:
177 static LLWindow* sWindow; // All root views must know about their window.
178
179public:
180 static BOOL sDebugRects; // Draw debug rects behind everything.
181 static BOOL sDebugKeys;
182 static S32 sDepth;
183 static LLView* sFastFrameView;
184 static BOOL sDebugMouseHandling;
185 static LLString sMouseHandlerMessage;
186 static S32 sSelectID;
187 static BOOL sEditingUI;
188 static LLView* sEditingUIView;
189 static S32 sLastLeftXML;
190 static S32 sLastBottomXML;
191 static std::map<LLViewHandle,LLView*> sViewHandleMap;
192 static BOOL sForceReshape;
193
194public:
195 static LLView* getViewByHandle(LLViewHandle handle);
196 static BOOL deleteViewByHandle(LLViewHandle handle);
197
198public:
199 LLView();
200 LLView(const LLString& name, BOOL mouse_opaque);
201 LLView(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows=FOLLOWS_NONE);
202
203 virtual ~LLView();
204
205 // Hack to support LLFocusMgr
206 virtual BOOL isView();
207
208 // Some UI widgets need to be added as controls. Others need to
209 // be added as regular view children. isCtrl should return TRUE
210 // if a widget needs to be added as a ctrl
211 virtual BOOL isCtrl() const;
212
213 virtual BOOL isPanel();
214
215 //
216 // MANIPULATORS
217 //
218 void setMouseOpaque( BOOL b );
219 void setToolTip( const LLString& msg );
220
221 virtual void setRect(const LLRect &rect);
222 void setFollows(U32 flags);
223
224 // deprecated, use setFollows() with FOLLOWS_LEFT | FOLLOWS_TOP, etc.
225 void setFollowsNone();
226 void setFollowsLeft();
227 void setFollowsTop();
228 void setFollowsRight();
229 void setFollowsBottom();
230 void setFollowsAll();
231
232 void setSoundFlags(U8 flags);
233 void setName(LLString name);
234 void setSpanChildren( BOOL span_children );
235
236 const LLString& getToolTip();
237
238 void sendChildToFront(LLView* child);
239 void sendChildToBack(LLView* child);
240 void moveChildToFrontOfTabGroup(LLUICtrl* child);
241
242 void addChild(LLView* view, S32 tab_group = 0);
243 void addChildAtEnd(LLView* view, S32 tab_group = 0);
244 // remove the specified child from the view, and set it's parent to NULL.
245 void removeChild( LLView* view );
246
247 virtual void addCtrl( LLUICtrl* ctrl, S32 tab_group);
248 virtual void addCtrlAtEnd( LLUICtrl* ctrl, S32 tab_group);
249 virtual void removeCtrl( LLUICtrl* ctrl);
250
251 child_tab_order_t getCtrlOrder() const { return mCtrlOrder; }
252 ctrl_list_t getCtrlList() const;
253 ctrl_list_t getCtrlListSorted() const;
254 S32 getDefaultTabGroup() const;
255
256 BOOL isInVisibleChain() const;
257 BOOL isInEnabledChain() const;
258
259 BOOL isFocusRoot() const;
260 LLView* findRootMostFocusRoot();
261 virtual BOOL canFocusChildren() const;
262
263 class LLFocusRootsFilter : public LLQueryFilter, public LLSingleton<LLFocusRootsFilter>
264 {
265 /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const
266 {
267 return filterResult_t(view->isCtrl() && view->isFocusRoot(), !view->isFocusRoot());
268 }
269 };
270
271 virtual BOOL focusNextRoot();
272 virtual BOOL focusPrevRoot();
273
274 virtual BOOL focusNextItem(BOOL text_entry_only);
275 virtual BOOL focusPrevItem(BOOL text_entry_only);
276 virtual BOOL focusFirstItem(BOOL prefer_text_fields = FALSE );
277 virtual BOOL focusLastItem(BOOL prefer_text_fields = FALSE);
278
279 // delete all children. Override this function if you need to
280 // perform any extra clean up such as cached pointers to selected
281 // children, etc.
282 virtual void deleteAllChildren();
283
284 // by default, does nothing
285 virtual void setTentative(BOOL b);
286 // by default, returns false
287 virtual BOOL getTentative() const;
288 virtual void setAllChildrenEnabled(BOOL b);
289
290 virtual void setEnabled(BOOL enabled);
291 virtual void setVisible(BOOL visible);
292 virtual void setHidden(BOOL hidden); // Never show (replacement text)
293
294 // by default, does nothing and returns false
295 virtual BOOL setLabelArg( const LLString& key, const LLString& text );
296
297 virtual void onVisibilityChange ( BOOL curVisibilityIn );
298
299 void pushVisible(BOOL visible) { mLastVisible = mVisible; setVisible(visible); }
300 void popVisible() { setVisible(mLastVisible); mLastVisible = TRUE; }
301
302 //
303 // ACCESSORS
304 //
305 BOOL getMouseOpaque() const { return mMouseOpaque; }
306
307 U32 getFollows() const { return mReshapeFlags; }
308 BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; }
309 BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; }
310 BOOL followsTop() const { return mReshapeFlags & FOLLOWS_TOP; }
311 BOOL followsBottom() const { return mReshapeFlags & FOLLOWS_BOTTOM; }
312 BOOL followsAll() const { return mReshapeFlags & FOLLOWS_ALL; }
313
314 const LLRect& getRect() const { return mRect; }
315 const LLRect getScreenRect() const;
316 const LLRect getLocalRect() const;
317 virtual const LLRect getSnapRect() const { return mRect; }
318
319 virtual LLRect getRequiredRect(); // Get required size for this object. 0 for width/height means don't care.
320 virtual void updateRect(); // apply procedural updates to own rectangle
321
322 LLView* getRootView();
323 LLView* getParent() const { return mParentView; }
324 LLView* getFirstChild() { return (mChildList.empty()) ? NULL : *(mChildList.begin()); }
325 S32 getChildCount() const { return (S32)mChildList.size(); }
326 template<class _Pr3> void sortChildren(_Pr3 _Pred) { mChildList.sort(_Pred); }
327 BOOL hasAncestor(LLView* parentp);
328
329 BOOL hasChild(const LLString& childname, BOOL recurse = FALSE) const;
330
331 BOOL childHasKeyboardFocus( const LLString& childname ) const;
332
333 //
334 // UTILITIES
335 //
336
337 // Default behavior is to use reshape flags to resize child views
338 virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
339
340 virtual void translate( S32 x, S32 y );
341 BOOL translateIntoRect( const LLRect& constraint, BOOL allow_partial_outside );
342 void setOrigin( S32 x, S32 y ) { mRect.translate( x - mRect.mLeft, y - mRect.mBottom ); }
343 LLView* findSnapRect(LLRect& new_rect, const LLCoordGL& mouse_dir, LLView::ESnapType snap_type, S32 threshold, S32 padding = 0);
344 LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding = 0);
345
346 // Defaults to other_view->getVisible()
347 virtual BOOL canSnapTo(LLView* other_view);
348
349 virtual void snappedTo(LLView* snap_view);
350
351 virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
352 virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
353 virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
354 EDragAndDropType cargo_type,
355 void* cargo_data,
356 EAcceptance* accept,
357 LLString& tooltip_msg);
358
359 // LLMouseHandler functions
360 // Default behavior is to pass events to children
361
362 /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask);
363 /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
364 /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
365 /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
366 /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
367 /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
368 /*virtual*/ BOOL handleRightMouseUp(S32 x, S32 y, MASK mask);
369
370 // Default behavior is to pass the tooltip event to children,
371 // then display mToolTipMsg if no child handled it.
372 /*virtual*/ BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect);
373
374 LLString getShowNamesToolTip();
375
376 virtual void draw();
377
378 void drawDebugRect();
379 void drawChild(LLView* childp, S32 x_offset = 0, S32 y_offset = 0);
380
381 virtual const LLString& getName() const;
382
383 virtual EWidgetType getWidgetType() const = 0;
384 virtual LLString getWidgetTag() const = 0;
385 virtual LLXMLNodePtr getXML(bool save_children = true) const;
386
387 static U32 createRect(LLXMLNodePtr node, LLRect &rect, LLView* parent_view, const LLRect &required_rect = LLRect());
388 virtual void initFromXML(LLXMLNodePtr node, LLView* parent);
389
390 static LLFontGL* selectFont(LLXMLNodePtr node);
391 static LLFontGL::HAlign selectFontHAlign(LLXMLNodePtr node);
392 static LLFontGL::VAlign selectFontVAlign(LLXMLNodePtr node);
393 static LLFontGL::StyleFlags selectFontStyle(LLXMLNodePtr node);
394
395 // Some widgets, like close box buttons, don't need to be saved
396 BOOL getSaveToXML() const { return mSaveToXML; }
397 void setSaveToXML(BOOL b) { mSaveToXML = b; }
398
399 // Only saves color if different from default setting.
400 static void addColorXML(LLXMLNodePtr node, const LLColor4& color,
401 const LLString& xml_name, const LLString& control_name);
402 static void saveColorToXML(std::ostream& out, const LLColor4& color,
403 const LLString& xml_name, const LLString& control_name,
404 const LLString& indent); // DEPRECATED
405 // Escapes " (quot) ' (apos) & (amp) < (lt) > (gt)
406 //static LLString escapeXML(const LLString& xml);
407 static LLWString escapeXML(const LLWString& xml);
408
409 //same as above, but wraps multiple lines in quotes and prepends
410 //indent as leading white space on each line
411 static LLString escapeXML(const LLString& xml, LLString& indent);
412
413 // focuses the item in the list after the currently-focused item, wrapping if necessary
414 static BOOL focusNext(LLView::child_list_t & result);
415 // focuses the item in the list before the currently-focused item, wrapping if necessary
416 static BOOL focusPrev(LLView::child_list_t & result);
417
418 // returns query for iterating over controls in tab order
419 static const LLCtrlQuery & getTabOrderQuery();
420 // return query for iterating over focus roots in tab order
421 static const LLCtrlQuery & getFocusRootsQuery();
422
423 BOOL getEnabled() const { return mEnabled; }
424 BOOL getVisible() const { return mVisible && !mHidden; }
425 U8 getSoundFlags() const { return mSoundFlags; }
426
427 // Default to no action
428 virtual void onFocusLost();
429 virtual void onFocusReceived();
430
431 BOOL parentPointInView(S32 x, S32 y) const { return mRect.pointInRect( x, y ); }
432 BOOL pointInView(S32 x, S32 y) const { return mRect.localPointInRect( x, y ); }
433 virtual void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const;
434 virtual void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const;
435 virtual BOOL localPointToOtherView( S32 x, S32 y, S32 *other_x, S32 *other_y, LLView* other_view);
436 virtual void screenRectToLocal( const LLRect& screen, LLRect* local ) const;
437 virtual void localRectToScreen( const LLRect& local, LLRect* screen ) const;
438 virtual BOOL localRectToOtherView( const LLRect& local, LLRect* other, LLView* other_view ) const;
439
440 void setRenderInFastFrame(BOOL render) { mRenderInFastFrame = render; }
441 virtual LLView* getRootMostFastFrameView();
442
443 static LLWindow* getWindow(void);
444
445 // Listener dispatching functions (Dispatcher deletes pointers to listeners on deregistration or destruction)
446 LLSimpleListener* getListenerByName(const LLString &callback_name);
447 void registerEventListener(LLString name, LLSimpleListener* function);
448 void deregisterEventListener(LLString name);
449 LLString findEventListener(LLSimpleListener *listener) const;
450 void addListenerToControl(LLEventDispatcher *observer, const LLString& name, LLSD filter, LLSD userdata);
451
452 virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const;
453
454 void addBoolControl(LLString name, bool initial_value);
455 LLControlBase *getControl(LLString name);
456 virtual LLControlBase *findControl(LLString name);
457
458 void setControlValue(const LLSD& value);
459 virtual void setControlName(const LLString& control, LLView *context);
460 virtual LLString getControlName() const;
461 virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
462 virtual void setValue(const LLSD& value);
463 const child_list_t* getChildList() const { return &mChildList; }
464
465protected:
466 virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
467 virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
468
469 LLView* childrenHandleKey(KEY key, MASK mask);
470 LLView* childrenHandleUnicodeChar(llwchar uni_char);
471 LLView* childrenHandleDragAndDrop(S32 x, S32 y, MASK mask,
472 BOOL drop,
473 EDragAndDropType type,
474 void* data,
475 EAcceptance* accept,
476 LLString& tooltip_msg);
477
478 LLView* childrenHandleHover(S32 x, S32 y, MASK mask);
479 LLView* childrenHandleMouseUp(S32 x, S32 y, MASK mask);
480 LLView* childrenHandleMouseDown(S32 x, S32 y, MASK mask);
481 LLView* childrenHandleDoubleClick(S32 x, S32 y, MASK mask);
482 LLView* childrenHandleScrollWheel(S32 x, S32 y, S32 clicks);
483 LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask);
484 LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask);
485
486 typedef std::map<LLString, LLSimpleListener*> dispatch_list_t;
487 dispatch_list_t mDispatchList;
488
489protected:
490 typedef std::map<LLString, LLControlBase*> control_map_t;
491 control_map_t mFloaterControls;
492
493 LLString mControlName;
494 friend class LLUICtrlFactory;
495};
496
497
498
499
500class LLCompareByTabOrder
501{
502public:
503 LLCompareByTabOrder(LLView::child_tab_order_t order);
504 virtual ~LLCompareByTabOrder() {}
505 bool operator() (const LLView* const a, const LLView* const b) const;
506protected:
507 virtual bool compareTabOrders(const LLView::tab_order_t & a, const LLView::tab_order_t & b) const;
508 LLView::child_tab_order_t mTabOrder;
509};
510
511#endif