00001
00032 #ifndef LL_LLVIEW_H
00033 #define LL_LLVIEW_H
00034
00035
00036
00037
00038
00039 #include "llcoord.h"
00040 #include "llfontgl.h"
00041 #include "llmortician.h"
00042 #include "llmousehandler.h"
00043 #include "llnametable.h"
00044 #include "llsd.h"
00045 #include "llstring.h"
00046 #include "llrect.h"
00047 #include "llui.h"
00048 #include "lluixmltags.h"
00049 #include "llviewquery.h"
00050 #include "llxmlnode.h"
00051 #include "stdenums.h"
00052
00053 class LLColor4;
00054 class LLWindow;
00055 class LLUICtrl;
00056 class LLScrollListItem;
00057
00058 const U32 FOLLOWS_NONE = 0x00;
00059 const U32 FOLLOWS_LEFT = 0x01;
00060 const U32 FOLLOWS_RIGHT = 0x02;
00061 const U32 FOLLOWS_TOP = 0x10;
00062 const U32 FOLLOWS_BOTTOM = 0x20;
00063 const U32 FOLLOWS_ALL = 0x33;
00064
00065 const BOOL MOUSE_OPAQUE = TRUE;
00066 const BOOL NOT_MOUSE_OPAQUE = FALSE;
00067
00068 const U32 GL_NAME_UI_RESERVED = 2;
00069
00070 class LLSimpleListener;
00071 class LLEventDispatcher;
00072
00073 class LLViewHandle
00074 {
00075 public:
00076 LLViewHandle() { mID = 0; }
00077
00078 void init() { mID = ++sNextID; }
00079 void markDead() { mID = 0; }
00080 BOOL isDead() { return (mID == 0); }
00081 friend bool operator==(const LLViewHandle& lhs, const LLViewHandle& rhs);
00082 friend bool operator!=(const LLViewHandle& lhs, const LLViewHandle& rhs);
00083 friend bool operator<(const LLViewHandle &a, const LLViewHandle &b);
00084
00085 public:
00086 static LLViewHandle sDeadHandle;
00087
00088 protected:
00089 S32 mID;
00090
00091 static S32 sNextID;
00092 };
00093
00094 class LLView : public LLMouseHandler, public LLMortician, public LLSimpleListenerObservable
00095 {
00096
00097 public:
00098 #if LL_DEBUG
00099 static BOOL sIsDrawing;
00100 #endif
00101 enum ESoundFlags
00102 {
00103 SILENT = 0,
00104 MOUSE_DOWN = 1,
00105 MOUSE_UP = 2
00106 };
00107
00108 enum ESnapType
00109 {
00110 SNAP_PARENT,
00111 SNAP_SIBLINGS,
00112 SNAP_PARENT_AND_SIBLINGS
00113 };
00114
00115 enum ESnapEdge
00116 {
00117 SNAP_LEFT,
00118 SNAP_TOP,
00119 SNAP_RIGHT,
00120 SNAP_BOTTOM
00121 };
00122
00123 typedef std::list<LLView*> child_list_t;
00124 typedef child_list_t::iterator child_list_iter_t;
00125 typedef child_list_t::const_iterator child_list_const_iter_t;
00126 typedef child_list_t::reverse_iterator child_list_reverse_iter_t;
00127 typedef child_list_t::const_reverse_iterator child_list_const_reverse_iter_t;
00128
00129 typedef std::vector<LLUICtrl *> ctrl_list_t;
00130
00131 typedef std::pair<S32, S32> tab_order_t;
00132 typedef std::pair<LLUICtrl *, tab_order_t> tab_order_pair_t;
00133
00134 typedef std::map<const LLUICtrl*, tab_order_t> child_tab_order_t;
00135 typedef child_tab_order_t::iterator child_tab_order_iter_t;
00136 typedef child_tab_order_t::const_iterator child_tab_order_const_iter_t;
00137 typedef child_tab_order_t::reverse_iterator child_tab_order_reverse_iter_t;
00138 typedef child_tab_order_t::const_reverse_iterator child_tab_order_const_reverse_iter_t;
00139
00140 private:
00141 LLView* mParentView;
00142 child_list_t mChildList;
00143
00144 protected:
00145 LLString mName;
00146
00147 LLRect mRect;
00148
00149 U32 mReshapeFlags;
00150
00151 child_tab_order_t mCtrlOrder;
00152 S32 mDefaultTabGroup;
00153
00154 BOOL mEnabled;
00155
00156 BOOL mMouseOpaque;
00157 LLString mToolTipMsg;
00158
00159 U8 mSoundFlags;
00160 BOOL mSaveToXML;
00161
00162 BOOL mIsFocusRoot;
00163
00164 public:
00165 LLViewHandle mViewHandle;
00166 BOOL mLastVisible;
00167 BOOL mSpanChildren;
00168
00169 private:
00170 BOOL mVisible;
00171 BOOL mHidden;
00172
00173 S32 mNextInsertionOrdinal;
00174
00175 protected:
00176 static LLWindow* sWindow;
00177
00178 public:
00179 static BOOL sDebugRects;
00180 static BOOL sDebugKeys;
00181 static S32 sDepth;
00182 static BOOL sDebugMouseHandling;
00183 static LLString sMouseHandlerMessage;
00184 static S32 sSelectID;
00185 static BOOL sEditingUI;
00186 static LLView* sEditingUIView;
00187 static S32 sLastLeftXML;
00188 static S32 sLastBottomXML;
00189 static std::map<LLViewHandle,LLView*> sViewHandleMap;
00190 static BOOL sForceReshape;
00191
00192 public:
00193 static LLView* getViewByHandle(LLViewHandle handle);
00194 static BOOL deleteViewByHandle(LLViewHandle handle);
00195
00196 public:
00197 LLView();
00198 LLView(const LLString& name, BOOL mouse_opaque);
00199 LLView(const LLString& name, const LLRect& rect, BOOL mouse_opaque, U32 follows=FOLLOWS_NONE);
00200
00201 virtual ~LLView();
00202
00203
00204 virtual BOOL isView();
00205
00206
00207
00208
00209 virtual BOOL isCtrl() const;
00210
00211 virtual BOOL isPanel();
00212
00213
00214
00215
00216 void setMouseOpaque( BOOL b );
00217 void setToolTip( const LLString& msg );
00218
00219 virtual void setRect(const LLRect &rect);
00220 void setFollows(U32 flags);
00221
00222
00223 void setFollowsNone();
00224 void setFollowsLeft();
00225 void setFollowsTop();
00226 void setFollowsRight();
00227 void setFollowsBottom();
00228 void setFollowsAll();
00229
00230 void setSoundFlags(U8 flags);
00231 void setName(LLString name);
00232 void setSpanChildren( BOOL span_children );
00233
00234 const LLString& getToolTip();
00235
00236 void sendChildToFront(LLView* child);
00237 void sendChildToBack(LLView* child);
00238 void moveChildToFrontOfTabGroup(LLUICtrl* child);
00239
00240 void addChild(LLView* view, S32 tab_group = 0);
00241 void addChildAtEnd(LLView* view, S32 tab_group = 0);
00242
00243 void removeChild(LLView* view, BOOL deleteIt = FALSE);
00244
00245 virtual void addCtrl( LLUICtrl* ctrl, S32 tab_group);
00246 virtual void addCtrlAtEnd( LLUICtrl* ctrl, S32 tab_group);
00247 virtual void removeCtrl( LLUICtrl* ctrl);
00248
00249 child_tab_order_t getCtrlOrder() const { return mCtrlOrder; }
00250 ctrl_list_t getCtrlList() const;
00251 ctrl_list_t getCtrlListSorted() const;
00252 S32 getDefaultTabGroup() const;
00253
00254 BOOL isInVisibleChain() const;
00255 BOOL isInEnabledChain() const;
00256
00257 BOOL isFocusRoot() const;
00258 LLView* findRootMostFocusRoot();
00259 virtual BOOL canFocusChildren() const;
00260
00261 class LLFocusRootsFilter : public LLQueryFilter, public LLSingleton<LLFocusRootsFilter>
00262 {
00263 filterResult_t operator() (const LLView* const view, const viewList_t & children) const
00264 {
00265 return filterResult_t(view->isCtrl() && view->isFocusRoot(), !view->isFocusRoot());
00266 }
00267 };
00268
00269 virtual BOOL focusNextRoot();
00270 virtual BOOL focusPrevRoot();
00271
00272 virtual BOOL focusNextItem(BOOL text_entry_only);
00273 virtual BOOL focusPrevItem(BOOL text_entry_only);
00274 virtual BOOL focusFirstItem(BOOL prefer_text_fields = FALSE );
00275 virtual BOOL focusLastItem(BOOL prefer_text_fields = FALSE);
00276
00277
00278
00279
00280 virtual void deleteAllChildren();
00281
00282
00283 virtual void setTentative(BOOL b);
00284
00285 virtual BOOL getTentative() const;
00286 virtual void setAllChildrenEnabled(BOOL b);
00287
00288 virtual void setEnabled(BOOL enabled);
00289 virtual void setVisible(BOOL visible);
00290 virtual void setHidden(BOOL hidden);
00291
00292
00293 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text );
00294
00295 virtual void onVisibilityChange ( BOOL curVisibilityIn );
00296
00297 void pushVisible(BOOL visible) { mLastVisible = mVisible; setVisible(visible); }
00298 void popVisible() { setVisible(mLastVisible); mLastVisible = TRUE; }
00299
00300
00301
00302
00303 BOOL getMouseOpaque() const { return mMouseOpaque; }
00304
00305 U32 getFollows() const { return mReshapeFlags; }
00306 BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; }
00307 BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; }
00308 BOOL followsTop() const { return mReshapeFlags & FOLLOWS_TOP; }
00309 BOOL followsBottom() const { return mReshapeFlags & FOLLOWS_BOTTOM; }
00310 BOOL followsAll() const { return mReshapeFlags & FOLLOWS_ALL; }
00311
00312 const LLRect& getRect() const { return mRect; }
00313 const LLRect getScreenRect() const;
00314 const LLRect getLocalRect() const;
00315 virtual const LLRect getSnapRect() const { return mRect; }
00316 virtual const LLRect getLocalSnapRect() const;
00317
00318 virtual LLRect getRequiredRect();
00319 virtual void updateRect();
00320
00321 LLView* getRootView();
00322 LLView* getParent() const { return mParentView; }
00323 LLView* getFirstChild() { return (mChildList.empty()) ? NULL : *(mChildList.begin()); }
00324 S32 getChildCount() const { return (S32)mChildList.size(); }
00325 template<class _Pr3> void sortChildren(_Pr3 _Pred) { mChildList.sort(_Pred); }
00326 BOOL hasAncestor(LLView* parentp);
00327
00328 BOOL hasChild(const LLString& childname, BOOL recurse = FALSE) const;
00329
00330 BOOL childHasKeyboardFocus( const LLString& childname ) const;
00331
00332
00333
00334
00335
00336
00337 virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
00338 virtual void translate( S32 x, S32 y );
00339 virtual void setOrigin( S32 x, S32 y ) { mRect.translate( x - mRect.mLeft, y - mRect.mBottom ); }
00340 BOOL translateIntoRect( const LLRect& constraint, BOOL allow_partial_outside );
00341
00342 virtual void userSetShape(const LLRect& new_rect);
00343 virtual LLView* findSnapRect(LLRect& new_rect, const LLCoordGL& mouse_dir, LLView::ESnapType snap_type, S32 threshold, S32 padding = 0);
00344 virtual LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding = 0);
00345
00346
00347 virtual BOOL canSnapTo(LLView* other_view);
00348
00349 virtual void snappedTo(LLView* snap_view);
00350
00351 virtual BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent);
00352 virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
00353 virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
00354 EDragAndDropType cargo_type,
00355 void* cargo_data,
00356 EAcceptance* accept,
00357 LLString& tooltip_msg);
00358
00359
00360
00361
00362 BOOL handleHover(S32 x, S32 y, MASK mask);
00363 BOOL handleMouseUp(S32 x, S32 y, MASK mask);
00364 BOOL handleMouseDown(S32 x, S32 y, MASK mask);
00365 BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
00366 BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
00367 BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
00368 BOOL handleRightMouseUp(S32 x, S32 y, MASK mask);
00369 void onMouseCaptureLost();
00370 BOOL hasMouseCapture();
00371
00372
00373
00374 BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect);
00375
00376 LLString getShowNamesToolTip();
00377
00378 virtual void draw();
00379
00380 void drawDebugRect();
00381 void drawChild(LLView* childp, S32 x_offset = 0, S32 y_offset = 0, BOOL force_draw = FALSE);
00382
00383 virtual const LLString& getName() const;
00384
00385 virtual EWidgetType getWidgetType() const = 0;
00386 virtual LLString getWidgetTag() const = 0;
00387 virtual LLXMLNodePtr getXML(bool save_children = true) const;
00388
00389 static U32 createRect(LLXMLNodePtr node, LLRect &rect, LLView* parent_view, const LLRect &required_rect = LLRect());
00390 virtual void initFromXML(LLXMLNodePtr node, LLView* parent);
00391
00392 static LLFontGL* selectFont(LLXMLNodePtr node);
00393 static LLFontGL::HAlign selectFontHAlign(LLXMLNodePtr node);
00394 static LLFontGL::VAlign selectFontVAlign(LLXMLNodePtr node);
00395 static LLFontGL::StyleFlags selectFontStyle(LLXMLNodePtr node);
00396
00397
00398 BOOL getSaveToXML() const { return mSaveToXML; }
00399 void setSaveToXML(BOOL b) { mSaveToXML = b; }
00400
00401
00402 static void addColorXML(LLXMLNodePtr node, const LLColor4& color,
00403 const LLString& xml_name, const LLString& control_name);
00404 static void saveColorToXML(std::ostream& out, const LLColor4& color,
00405 const LLString& xml_name, const LLString& control_name,
00406 const LLString& indent);
00407
00408
00409 static LLWString escapeXML(const LLWString& xml);
00410
00411
00412
00413 static LLString escapeXML(const LLString& xml, LLString& indent);
00414
00415
00416 static BOOL focusNext(LLView::child_list_t & result);
00417
00418 static BOOL focusPrev(LLView::child_list_t & result);
00419
00420
00421 static const LLCtrlQuery & getTabOrderQuery();
00422
00423 static const LLCtrlQuery & getFocusRootsQuery();
00424
00425 BOOL getEnabled() const { return mEnabled; }
00426 BOOL getVisible() const { return mVisible && !mHidden; }
00427 U8 getSoundFlags() const { return mSoundFlags; }
00428
00429
00430 virtual void onFocusLost();
00431 virtual void onFocusReceived();
00432
00433 BOOL parentPointInView(S32 x, S32 y) const { return mRect.pointInRect( x, y ); }
00434 BOOL pointInView(S32 x, S32 y) const { return mRect.localPointInRect( x, y ); }
00435 virtual void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const;
00436 virtual void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const;
00437 virtual BOOL localPointToOtherView( S32 x, S32 y, S32 *other_x, S32 *other_y, LLView* other_view);
00438 virtual void screenRectToLocal( const LLRect& screen, LLRect* local ) const;
00439 virtual void localRectToScreen( const LLRect& local, LLRect* screen ) const;
00440 virtual BOOL localRectToOtherView( const LLRect& local, LLRect* other, LLView* other_view ) const;
00441
00442
00443 static LLWindow* getWindow(void);
00444
00445
00446 LLSimpleListener* getListenerByName(const LLString &callback_name);
00447 void registerEventListener(LLString name, LLSimpleListener* function);
00448 void deregisterEventListener(LLString name);
00449 LLString findEventListener(LLSimpleListener *listener) const;
00450 void addListenerToControl(LLEventDispatcher *observer, const LLString& name, LLSD filter, LLSD userdata);
00451
00452 virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const;
00453
00454 void addBoolControl(LLString name, bool initial_value);
00455 LLControlBase *getControl(LLString name);
00456 virtual LLControlBase *findControl(LLString name);
00457
00458 void setControlValue(const LLSD& value);
00459 virtual void setControlName(const LLString& control, LLView *context);
00460 virtual LLString getControlName() const;
00461 virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata);
00462 virtual void setValue(const LLSD& value);
00463 const child_list_t* getChildList() const { return &mChildList; }
00464
00465 protected:
00466 virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00467 virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
00468
00469 LLView* childrenHandleKey(KEY key, MASK mask);
00470 LLView* childrenHandleUnicodeChar(llwchar uni_char);
00471 LLView* childrenHandleDragAndDrop(S32 x, S32 y, MASK mask,
00472 BOOL drop,
00473 EDragAndDropType type,
00474 void* data,
00475 EAcceptance* accept,
00476 LLString& tooltip_msg);
00477
00478 LLView* childrenHandleHover(S32 x, S32 y, MASK mask);
00479 LLView* childrenHandleMouseUp(S32 x, S32 y, MASK mask);
00480 LLView* childrenHandleMouseDown(S32 x, S32 y, MASK mask);
00481 LLView* childrenHandleDoubleClick(S32 x, S32 y, MASK mask);
00482 LLView* childrenHandleScrollWheel(S32 x, S32 y, S32 clicks);
00483 LLView* childrenHandleRightMouseDown(S32 x, S32 y, MASK mask);
00484 LLView* childrenHandleRightMouseUp(S32 x, S32 y, MASK mask);
00485
00486 typedef std::map<LLString, LLPointer<LLSimpleListener> > dispatch_list_t;
00487 dispatch_list_t mDispatchList;
00488
00489 protected:
00490 typedef std::map<LLString, LLControlBase*> control_map_t;
00491 control_map_t mFloaterControls;
00492
00493 LLString mControlName;
00494 friend class LLUICtrlFactory;
00495 };
00496
00497
00498
00499
00500 class LLCompareByTabOrder
00501 {
00502 public:
00503 LLCompareByTabOrder(LLView::child_tab_order_t order);
00504 virtual ~LLCompareByTabOrder() {}
00505 bool operator() (const LLView* const a, const LLView* const b) const;
00506 protected:
00507 virtual bool compareTabOrders(const LLView::tab_order_t & a, const LLView::tab_order_t & b) const;
00508 LLView::child_tab_order_t mTabOrder;
00509 };
00510
00511 #endif