PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: TabBar.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLGUI_TABBAR_H__ 00024 #define __PLGUI_TABBAR_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/List.h> 00032 #include <PLCore/Base/Event/Event.h> 00033 #include "PLGui/Widgets/Widget.h" 00034 #include "PLGui/Widgets/Controls/TabBarEntry.h" 00035 00036 00037 //[-------------------------------------------------------] 00038 //[ Namespace ] 00039 //[-------------------------------------------------------] 00040 namespace PLGui { 00041 00042 00043 //[-------------------------------------------------------] 00044 //[ Classes ] 00045 //[-------------------------------------------------------] 00046 /** 00047 * @brief 00048 * Tab bar widget 00049 */ 00050 class TabBar : public Widget { 00051 00052 00053 //[-------------------------------------------------------] 00054 //[ Class definition ] 00055 //[-------------------------------------------------------] 00056 pl_class(PLGUI_RTTI_EXPORT, TabBar, "PLGui", PLGui::Widget, "Tab bar widget") 00057 pl_constructor_0(DefaultConstructor, "Default constructor", "") 00058 pl_class_end 00059 00060 00061 //[-------------------------------------------------------] 00062 //[ Friends ] 00063 //[-------------------------------------------------------] 00064 friend class TabBarEntry; 00065 friend class TabBarButton; 00066 00067 00068 //[-------------------------------------------------------] 00069 //[ Public events ] 00070 //[-------------------------------------------------------] 00071 public: 00072 PLCore::Event<TabBarEntry*> EventAddTab; /**< New tab is added */ 00073 PLCore::Event<TabBarEntry*> EventRemoveTab; /**< Tab is removed */ 00074 PLCore::Event<TabBarEntry*> EventCloseTab; /**< Tab is to be closed */ 00075 PLCore::Event<int> EventSelectTab; /**< Current selection has been changed */ 00076 PLCore::Event<> EventCreateTab; /**< New tab shall be created */ 00077 00078 00079 //[-------------------------------------------------------] 00080 //[ Public functions ] 00081 //[-------------------------------------------------------] 00082 public: 00083 /** 00084 * @brief 00085 * Constructor 00086 * 00087 * @param[in] pParent 00088 * Pointer to parent widget 00089 */ 00090 PLGUI_API TabBar(Widget *pParent = nullptr); 00091 00092 /** 00093 * @brief 00094 * Destructor 00095 */ 00096 PLGUI_API virtual ~TabBar(); 00097 00098 /** 00099 * @brief 00100 * Get side the tabbar is positioned on 00101 * 00102 * @return 00103 * Side 00104 */ 00105 PLGUI_API ESide GetSide() const; 00106 00107 /** 00108 * @brief 00109 * Set side the tabbar is positioned on 00110 * 00111 * @param[in] nSide 00112 * Side 00113 */ 00114 PLGUI_API void SetSide(ESide nSide); 00115 00116 /** 00117 * @brief 00118 * Get TabBar options 00119 * 00120 * @return 00121 * TabBar options (combination of ETabBarOption values) 00122 */ 00123 PLGUI_API PLCore::uint32 GetOptions() const; 00124 00125 /** 00126 * @brief 00127 * Set TabBar options 00128 * 00129 * @param[in] nOptions 00130 * TabBar options 00131 */ 00132 PLGUI_API void SetOptions(PLCore::uint32 nOptions); 00133 00134 /** 00135 * @brief 00136 * Get tab width 00137 * 00138 * @return 00139 * Tab width 00140 * 00141 * @remarks 00142 * see SetTabWidth() 00143 */ 00144 PLGUI_API PLCore::uint32 GetTabWidth() const; 00145 00146 /** 00147 * @brief 00148 * Set tab width 00149 * 00150 * @param[in] nWidth 00151 * Tab width 00152 * 00153 * @note 00154 * - If side is SideTop or SideBottom and StaticTabSize is *not* set, tabs have a floating size. 00155 * In that case, the width set by nWidth is the maximum size that a tab can have. 00156 * - If side is SideLeft or SideRight, or StaticTabSize is set, tabs have a static size. 00157 * In that case, every tab will get exactly the width set by nWidth. 00158 */ 00159 PLGUI_API void SetTabWidth(PLCore::uint32 nWidth); 00160 00161 /** 00162 * @brief 00163 * Get tab height 00164 * 00165 * @return 00166 * Tab height 00167 */ 00168 PLGUI_API PLCore::uint32 GetTabHeight() const; 00169 00170 /** 00171 * @brief 00172 * Set tab height 00173 * 00174 * @param[in] nHeight 00175 * Tab height 00176 */ 00177 PLGUI_API void SetTabHeight(PLCore::uint32 nHeight); 00178 00179 /** 00180 * @brief 00181 * Create a new tab 00182 * 00183 * @remarks 00184 * CreateTab creates an event saying that a new tab shall be created. 00185 * This does not do anything automatically, so you have to catch the 00186 * event and call AddTab() to actually create a new tab. 00187 */ 00188 PLGUI_API void CreateTab(); 00189 00190 /** 00191 * @brief 00192 * Close tab 00193 * 00194 * @param[in] pTab 00195 * Tab 00196 * 00197 * @remarks 00198 * See CloseTab(PLCore::uint32 nTab) 00199 */ 00200 PLGUI_API void CloseTab(TabBarEntry *pTab); 00201 00202 /** 00203 * @brief 00204 * Close tab 00205 * 00206 * @param[in] nTab 00207 * Tab index 00208 * 00209 * @remarks 00210 * CloseTab creates an event saying that the given tab shall 00211 * be closed (the same as when the used has actually clicked 00212 * on the tab's 'x'-button). This does not automatically remove 00213 * the tab but only generate the event. Do actually remove a tab, 00214 * use RemoveTab(). 00215 */ 00216 PLGUI_API void CloseTab(PLCore::uint32 nTab); 00217 00218 /** 00219 * @brief 00220 * Get list of tabs 00221 * 00222 * @return 00223 * List of tabs 00224 */ 00225 PLGUI_API const PLCore::Container<TabBarEntry*> &GetTabs() const; 00226 00227 /** 00228 * @brief 00229 * Add tab 00230 * 00231 * @param[in] sText 00232 * Tab text 00233 * 00234 * @return 00235 * New tab entry 00236 */ 00237 PLGUI_API TabBarEntry *AddTab(const PLCore::String &sText); 00238 00239 /** 00240 * @brief 00241 * Add tab 00242 * 00243 * @param[in] sText 00244 * Tab text 00245 * @param[in] cIcon 00246 * Image 00247 * 00248 * @return 00249 * New tab entry 00250 */ 00251 PLGUI_API TabBarEntry *AddTab(const PLCore::String &sText, const Image &cIcon); 00252 00253 /** 00254 * @brief 00255 * Remove tab 00256 * 00257 * @param[in] pTab 00258 * Tab 00259 * 00260 * @return 00261 * 'true' if all went fine, else 'false' 00262 */ 00263 PLGUI_API bool RemoveTab(TabBarEntry *pTab); 00264 00265 /** 00266 * @brief 00267 * Remove tab 00268 * 00269 * @param[in] nTab 00270 * Tab index 00271 * 00272 * @return 00273 * 'true' if all went fine, else 'false' 00274 */ 00275 PLGUI_API bool RemoveTab(PLCore::uint32 nTab); 00276 00277 /** 00278 * @brief 00279 * Get currently selected tab 00280 * 00281 * @return 00282 * Index of currently selected tab 00283 */ 00284 PLGUI_API int GetSelection() const; 00285 00286 /** 00287 * @brief 00288 * Set currently selected tab 00289 * 00290 * @param[in] nTab 00291 * Index of currently selected tab 00292 */ 00293 PLGUI_API void SetSelection(int nTab); 00294 00295 /** 00296 * @brief 00297 * Get scrolling position 00298 * 00299 * @return 00300 * Index of first visible tab 00301 */ 00302 PLGUI_API int GetScrollingPos() const; 00303 00304 /** 00305 * @brief 00306 * Set scrolling position 00307 * 00308 * @param[in] nTab 00309 * Index of first visible tab 00310 */ 00311 PLGUI_API void SetScrollingPos(int nTab); 00312 00313 /** 00314 * @brief 00315 * Get tab that is currently selected by the mouse 00316 * 00317 * @return 00318 * Index of currently selected tab 00319 */ 00320 PLGUI_API int GetMouseSelection() const; 00321 00322 00323 //[-------------------------------------------------------] 00324 //[ Protected functions ] 00325 //[-------------------------------------------------------] 00326 protected: 00327 /** 00328 * @brief 00329 * Redraw tab 00330 * 00331 * @param[in] nTab 00332 * Index of tab 00333 */ 00334 PLGUI_API void RedrawTab(int nTab); 00335 00336 /** 00337 * @brief 00338 * Set tab that is currently selected by the mouse 00339 * 00340 * @param[in] nTab 00341 * Index of currently selected tab 00342 */ 00343 PLGUI_API void SetMouseSelection(int nTab); 00344 00345 00346 //[-------------------------------------------------------] 00347 //[ Protected virtual Widget functions ] 00348 //[-------------------------------------------------------] 00349 protected: 00350 PLGUI_API virtual PLMath::Vector2i OnPreferredSize(const PLMath::Vector2i &vRefSize) const; 00351 PLGUI_API virtual void OnAdjustContent(); 00352 00353 00354 //[-------------------------------------------------------] 00355 //[ Protected virtual TabBar functions ] 00356 //[-------------------------------------------------------] 00357 protected: 00358 /** 00359 * @brief 00360 * Called when a new tab is added 00361 * 00362 * @param[in] pTab 00363 * Tab 00364 */ 00365 PLGUI_API virtual void OnAddTab(TabBarEntry *pTab); 00366 00367 /** 00368 * @brief 00369 * Called when a tab is removed 00370 * 00371 * @param[in] pTab 00372 * Tab 00373 */ 00374 PLGUI_API virtual void OnRemoveTab(TabBarEntry *pTab); 00375 00376 /** 00377 * @brief 00378 * Called when a tab shall be closed 00379 * 00380 * @param[in] pTab 00381 * Tab 00382 */ 00383 PLGUI_API virtual void OnCloseTab(TabBarEntry *pTab); 00384 00385 /** 00386 * @brief 00387 * Called when the current selection has been changed 00388 * 00389 * @param[in] nTab 00390 * Index of currently selected tab 00391 */ 00392 PLGUI_API virtual void OnSelectTab(int nTab); 00393 00394 /** 00395 * @brief 00396 * Called when a new tab shall be created 00397 */ 00398 PLGUI_API virtual void OnCreateTab(); 00399 00400 00401 //[-------------------------------------------------------] 00402 //[ Protected data ] 00403 //[-------------------------------------------------------] 00404 public: 00405 // TabBar data 00406 ESide m_nSide; /**< Side the tabbar is positioned on */ 00407 PLCore::uint32 m_nOptions; /**< TabBar options (ETabBarOption) */ 00408 PLCore::uint32 m_nTabWidth; /**< Tab width */ 00409 PLCore::uint32 m_nTabHeight; /**< Tab height */ 00410 PLCore::List<TabBarEntry*> m_lstTabs; /**< List of tabs */ 00411 int m_nSelection; /**< Index of currently selected tab */ 00412 int m_nMouseSelection; /**< Index of tab currently selected by the mouse */ 00413 int m_nScrollingPos; /**< First displayed tab (scrolling) */ 00414 00415 // Child widgets 00416 TabBarButton *m_pButtonCreate; /**< Button to create a new tab */ 00417 TabBarButton *m_pButtonNext; /**< Button to scroll (next) */ 00418 TabBarButton *m_pButtonPrev; /**< Button to scroll (previous) */ 00419 00420 00421 }; 00422 00423 00424 //[-------------------------------------------------------] 00425 //[ Namespace ] 00426 //[-------------------------------------------------------] 00427 } // PLGui 00428 00429 00430 #endif // __PLGUI_TABBAR_H__
|