00001
00032
00033
00034 #ifndef LL_TABCONTAINER_H
00035 #define LL_TABCONTAINER_H
00036
00037 #include "llpanel.h"
00038 #include "llframetimer.h"
00039
00040 class LLButton;
00041 class LLTextBox;
00042
00043
00044 class LLTabContainerCommon : public LLPanel
00045 {
00046 public:
00047 enum TabPosition
00048 {
00049 TOP,
00050 BOTTOM,
00051 LEFT
00052 };
00053 typedef enum e_insertion_point
00054 {
00055 START,
00056 END,
00057 RIGHT_OF_CURRENT
00058 } eInsertionPoint;
00059
00060 LLTabContainerCommon( const LLString& name,
00061 const LLRect& rect,
00062 TabPosition pos,
00063 void(*close_callback)(void*), void* callback_userdata,
00064 BOOL bordered = TRUE);
00065
00066 LLTabContainerCommon( const LLString& name,
00067 const LLString& rect_control,
00068 TabPosition pos,
00069 void(*close_callback)(void*), void* callback_userdata,
00070 BOOL bordered = TRUE);
00071
00072 virtual ~LLTabContainerCommon();
00073
00074 virtual void initButtons() = 0;
00075
00076 virtual void setValue(const LLSD& value) { selectTab((S32) value.asInteger()); }
00077 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_TAB_CONTAINER; }
00078 virtual LLString getWidgetTag() const { return LL_TAB_CONTAINER_COMMON_TAG; }
00079
00080 virtual LLView* getChildByName(const LLString& name, BOOL recurse = FALSE) const;
00081
00082 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00083
00084 virtual void addTabPanel(LLPanel* child,
00085 const LLString& label,
00086 BOOL select = FALSE,
00087 void (*on_tab_clicked)(void*, bool) = NULL,
00088 void* userdata = NULL,
00089 S32 indent = 0,
00090 BOOL placeholder = FALSE,
00091 eInsertionPoint insertion_point = END) = 0;
00092 virtual void addPlaceholder(LLPanel* child, const LLString& label);
00093 virtual void lockTabs(S32 num_tabs = 0);
00094
00095 virtual void enableTabButton(S32 which, BOOL enable);
00096
00097 virtual void removeTabPanel( LLPanel* child );
00098 virtual void deleteAllTabs();
00099 virtual LLPanel* getCurrentPanel();
00100 virtual S32 getCurrentPanelIndex();
00101 virtual S32 getTabCount();
00102 virtual S32 getPanelIndexByTitle(const LLString& title);
00103 virtual LLPanel* getPanelByIndex(S32 index);
00104 virtual LLPanel* getPanelByName(const LLString& name);
00105 virtual S32 getIndexForPanel(LLPanel* panel);
00106
00107 virtual void setCurrentTabName(const LLString& name);
00108
00109
00110 virtual void selectFirstTab();
00111 virtual void selectLastTab();
00112 virtual BOOL selectTabPanel( LLPanel* child );
00113 virtual BOOL selectTab(S32 which) = 0;
00114 virtual BOOL selectTabByName(const LLString& title);
00115 virtual void selectNextTab();
00116 virtual void selectPrevTab();
00117
00118 BOOL getTabPanelFlashing(LLPanel* child);
00119 void setTabPanelFlashing(LLPanel* child, BOOL state);
00120 virtual void setTabImage(LLPanel* child, std::string img_name, const LLColor4& color = LLColor4::white);
00121 void setTitle( const LLString& title );
00122 const LLString getPanelTitle(S32 index);
00123
00124 void setDragAndDropDelayTimer() { mDragAndDropDelayTimer.start(); }
00125
00126 virtual void setTopBorderHeight(S32 height);
00127
00128 virtual void setTabChangeCallback(LLPanel* tab, void (*on_tab_clicked)(void*,bool));
00129 virtual void setTabUserData(LLPanel* tab, void* userdata);
00130
00131 virtual void reshape(S32 width, S32 height, BOOL called_from_parent);
00132
00133 static void onCloseBtn(void* userdata);
00134 static void onTabBtn(void* userdata);
00135 static void onNextBtn(void* userdata);
00136 static void onNextBtnHeld(void* userdata);
00137 static void onPrevBtn(void* userdata);
00138 static void onPrevBtnHeld(void* userdata);
00139 static void onJumpFirstBtn( void* userdata );
00140 static void onJumpLastBtn( void* userdata );
00141
00142 virtual void setRightTabBtnOffset( S32 offset ) { }
00143 virtual void setPanelTitle(S32 index, const LLString& title) { }
00144
00145 virtual TabPosition getTabPosition() { return mTabPosition; }
00146
00147
00148 protected:
00149
00150 struct LLTabTuple
00151 {
00152 LLTabTuple( LLTabContainerCommon* c, LLPanel* p, LLButton* b,
00153 void (*cb)(void*,bool), void* userdata, LLTextBox* placeholder = NULL )
00154 :
00155 mTabContainer(c),
00156 mTabPanel(p),
00157 mButton(b),
00158 mOnChangeCallback( cb ),
00159 mUserData( userdata ),
00160 mOldState(FALSE),
00161 mPlaceholderText(placeholder),
00162 mPadding(0)
00163 {}
00164
00165 LLTabContainerCommon* mTabContainer;
00166 LLPanel* mTabPanel;
00167 LLButton* mButton;
00168 void (*mOnChangeCallback)(void*, bool);
00169 void* mUserData;
00170 BOOL mOldState;
00171 LLTextBox* mPlaceholderText;
00172 S32 mPadding;
00173 };
00174
00175 typedef std::vector<LLTabTuple*> tuple_list_t;
00176 tuple_list_t mTabList;
00177 S32 mCurrentTabIdx;
00178 BOOL mTabsHidden;
00179
00180 BOOL mScrolled;
00181 LLFrameTimer mScrollTimer;
00182 S32 mScrollPos;
00183 S32 mScrollPosPixels;
00184 S32 mMaxScrollPos;
00185
00186 LLFrameTimer mDragAndDropDelayTimer;
00187
00188 void (*mCloseCallback)(void*);
00189 void* mCallbackUserdata;
00190
00191 LLTextBox* mTitleBox;
00192
00193 S32 mTopBorderHeight;
00194 TabPosition mTabPosition;
00195 S32 mLockedTabCount;
00196
00197 protected:
00198 void scrollPrev();
00199 void scrollNext();
00200
00201 virtual void updateMaxScrollPos() = 0;
00202 virtual void commitHoveredButton(S32 x, S32 y) = 0;
00203 LLTabTuple* getTabByPanel(LLPanel* child);
00204 void insertTuple(LLTabTuple * tuple, eInsertionPoint insertion_point);
00205 };
00206
00207 class LLTabContainer : public LLTabContainerCommon
00208 {
00209 public:
00210 LLTabContainer( const LLString& name, const LLRect& rect, TabPosition pos,
00211 void(*close_callback)(void*), void* callback_userdata,
00212 const LLString& title=LLString::null, BOOL bordered = TRUE );
00213
00214 LLTabContainer( const LLString& name, const LLString& rect_control, TabPosition pos,
00215 void(*close_callback)(void*), void* callback_userdata,
00216 const LLString& title=LLString::null, BOOL bordered = TRUE );
00217
00218 ~LLTabContainer();
00219
00220 void initButtons();
00221
00222 void draw();
00223
00224 void addTabPanel(LLPanel* child,
00225 const LLString& label,
00226 BOOL select = FALSE,
00227 void (*on_tab_clicked)(void*, bool) = NULL,
00228 void* userdata = NULL,
00229 S32 indent = 0,
00230 BOOL placeholder = FALSE,
00231 eInsertionPoint insertion_point = END);
00232
00233 BOOL selectTab(S32 which);
00234 void removeTabPanel( LLPanel* child );
00235
00236 void setPanelTitle(S32 index, const LLString& title);
00237 void setTabImage(LLPanel* child, std::string img_name, const LLColor4& color = LLColor4::white);
00238 void setRightTabBtnOffset( S32 offset );
00239
00240 void setMinTabWidth(S32 width);
00241 void setMaxTabWidth(S32 width);
00242
00243 S32 getMinTabWidth() const;
00244 S32 getMaxTabWidth() const;
00245
00246 BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00247 BOOL handleHover( S32 x, S32 y, MASK mask );
00248 BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00249 BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect );
00250 BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00251 BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
00252 EDragAndDropType type, void* cargo_data,
00253 EAcceptance* accept, LLString& tooltip);
00254
00255 virtual LLXMLNodePtr getXML(bool save_children = true) const;
00256
00257
00258 protected:
00259
00260 LLButton* mLeftArrowBtn;
00261 LLButton* mJumpLeftArrowBtn;
00262 LLButton* mRightArrowBtn;
00263 LLButton* mJumpRightArrowBtn;
00264
00265 S32 mRightTabBtnOffset;
00266
00267 protected:
00268 virtual void updateMaxScrollPos();
00269 virtual void commitHoveredButton(S32 x, S32 y);
00270
00271 S32 mMinTabWidth;
00272 S32 mMaxTabWidth;
00273 S32 mTotalTabWidth;
00274 };
00275
00276 const S32 TABCNTR_CLOSE_BTN_SIZE = 16;
00277 const S32 TABCNTR_HEADER_HEIGHT = LLPANEL_BORDER_WIDTH + TABCNTR_CLOSE_BTN_SIZE;
00278
00279 #endif // LL_TABCONTAINER_H