tabg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/tabg.h
  3. // Purpose: Generic tabbed dialogs; used by wxMotif's wxNotebook
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef __TABGH_G__
  11. #define __TABGH_G__
  12. #define WXTAB_VERSION 1.1
  13. #include "wx/hashmap.h"
  14. #include "wx/string.h"
  15. #include "wx/dialog.h"
  16. #include "wx/panel.h"
  17. #include "wx/list.h"
  18. class WXDLLIMPEXP_FWD_CORE wxTabView;
  19. /*
  20. * A wxTabControl is the internal and visual representation
  21. * of the tab.
  22. */
  23. class WXDLLIMPEXP_CORE wxTabControl: public wxObject
  24. {
  25. DECLARE_DYNAMIC_CLASS(wxTabControl)
  26. public:
  27. wxTabControl(wxTabView *v = NULL);
  28. virtual ~wxTabControl(void);
  29. virtual void OnDraw(wxDC& dc, bool lastInRow);
  30. void SetLabel(const wxString& str) { m_controlLabel = str; }
  31. wxString GetLabel(void) const { return m_controlLabel; }
  32. void SetFont(const wxFont& f) { m_labelFont = f; }
  33. wxFont *GetFont(void) const { return (wxFont*) & m_labelFont; }
  34. void SetSelected(bool sel) { m_isSelected = sel; }
  35. bool IsSelected(void) const { return m_isSelected; }
  36. void SetPosition(int x, int y) { m_offsetX = x; m_offsetY = y; }
  37. void SetSize(int x, int y) { m_width = x; m_height = y; }
  38. void SetRowPosition(int r) { m_rowPosition = r; }
  39. int GetRowPosition() const { return m_rowPosition; }
  40. void SetColPosition(int c) { m_colPosition = c; }
  41. int GetColPosition() const { return m_colPosition; }
  42. int GetX(void) const { return m_offsetX; }
  43. int GetY(void) const { return m_offsetY; }
  44. int GetWidth(void) const { return m_width; }
  45. int GetHeight(void) const { return m_height; }
  46. int GetId(void) const { return m_id; }
  47. void SetId(int i) { m_id = i; }
  48. virtual bool HitTest(int x, int y) const ;
  49. protected:
  50. wxTabView* m_view;
  51. wxString m_controlLabel;
  52. bool m_isSelected;
  53. wxFont m_labelFont;
  54. int m_offsetX; // Offsets from top-left of tab view area (the area below the tabs)
  55. int m_offsetY;
  56. int m_width;
  57. int m_height;
  58. int m_id;
  59. int m_rowPosition; // Position in row from 0
  60. int m_colPosition; // Position in col from 0
  61. };
  62. /*
  63. * Each wxTabLayer is a list of tabs. E.g. there
  64. * are 3 layers in the MS Word Options dialog.
  65. */
  66. class WXDLLIMPEXP_CORE wxTabLayer: public wxList
  67. {
  68. };
  69. /*
  70. * The wxTabView controls and draws the tabbed object
  71. */
  72. WX_DECLARE_LIST(wxTabLayer, wxTabLayerList);
  73. #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers
  74. #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline
  75. class WXDLLIMPEXP_CORE wxTabView: public wxObject
  76. {
  77. DECLARE_DYNAMIC_CLASS(wxTabView)
  78. public:
  79. wxTabView(long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
  80. virtual ~wxTabView();
  81. inline int GetNumberOfLayers() const { return m_layers.GetCount(); }
  82. inline wxTabLayerList& GetLayers() { return m_layers; }
  83. inline void SetWindow(wxWindow* wnd) { m_window = wnd; }
  84. inline wxWindow* GetWindow(void) const { return m_window; }
  85. // Automatically positions tabs
  86. wxTabControl *AddTab(int id, const wxString& label, wxTabControl *existingTab = NULL);
  87. // Remove the tab without deleting the window
  88. bool RemoveTab(int id);
  89. void ClearTabs(bool deleteTabs = true);
  90. bool SetTabText(int id, const wxString& label);
  91. wxString GetTabText(int id) const;
  92. // Layout tabs (optional, e.g. if resizing window)
  93. void LayoutTabs();
  94. // Draw all tabs
  95. virtual void Draw(wxDC& dc);
  96. // Process mouse event, return false if we didn't process it
  97. virtual bool OnEvent(wxMouseEvent& event);
  98. // Called when a tab is activated
  99. virtual void OnTabActivate(int activateId, int deactivateId);
  100. // Allows vetoing
  101. virtual bool OnTabPreActivate(int WXUNUSED(activateId), int WXUNUSED(deactivateId) ) { return true; }
  102. // Allows use of application-supplied wxTabControl classes.
  103. virtual wxTabControl *OnCreateTabControl(void) { return new wxTabControl(this); }
  104. void SetHighlightColour(const wxColour& col);
  105. void SetShadowColour(const wxColour& col);
  106. void SetBackgroundColour(const wxColour& col);
  107. inline void SetTextColour(const wxColour& col) { m_textColour = col; }
  108. inline wxColour GetHighlightColour(void) const { return m_highlightColour; }
  109. inline wxColour GetShadowColour(void) const { return m_shadowColour; }
  110. inline wxColour GetBackgroundColour(void) const { return m_backgroundColour; }
  111. inline wxColour GetTextColour(void) const { return m_textColour; }
  112. inline const wxPen *GetHighlightPen(void) const { return m_highlightPen; }
  113. inline const wxPen *GetShadowPen(void) const { return m_shadowPen; }
  114. inline const wxPen *GetBackgroundPen(void) const { return m_backgroundPen; }
  115. inline const wxBrush *GetBackgroundBrush(void) const { return m_backgroundBrush; }
  116. inline void SetViewRect(const wxRect& rect) { m_tabViewRect = rect; }
  117. inline wxRect GetViewRect(void) const { return m_tabViewRect; }
  118. // Calculate tab width to fit to view, and optionally adjust the view
  119. // to fit the tabs exactly.
  120. int CalculateTabWidth(int noTabs, bool adjustView = false);
  121. inline void SetTabStyle(long style) { m_tabStyle = style; }
  122. inline long GetTabStyle(void) const { return m_tabStyle; }
  123. inline void SetTabSize(int w, int h) { m_tabWidth = w; m_tabHeight = h; }
  124. inline int GetTabWidth(void) const { return m_tabWidth; }
  125. inline int GetTabHeight(void) const { return m_tabHeight; }
  126. inline void SetTabSelectionHeight(int h) { m_tabSelectionHeight = h; }
  127. inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight; }
  128. // Returns the total height of the tabs component -- this may be several
  129. // times the height of a tab, if there are several tab layers (rows).
  130. int GetTotalTabHeight();
  131. inline int GetTopMargin(void) const { return m_topMargin; }
  132. inline void SetTopMargin(int margin) { m_topMargin = margin; }
  133. void SetTabSelection(int sel, bool activateTool = true);
  134. inline int GetTabSelection() const { return m_tabSelection; }
  135. // Find tab control for id
  136. wxTabControl *FindTabControlForId(int id) const ;
  137. // Find tab control for layer, position (starting from zero)
  138. wxTabControl *FindTabControlForPosition(int layer, int position) const ;
  139. inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset; }
  140. inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing; }
  141. inline void SetHorizontalTabOffset(int sp) { m_tabHorizontalOffset = sp; }
  142. inline void SetHorizontalTabSpacing(int sp) { m_tabHorizontalSpacing = sp; }
  143. inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; }
  144. inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; }
  145. inline wxFont *GetTabFont() const { return (wxFont*) & m_tabFont; }
  146. inline void SetTabFont(const wxFont& f) { m_tabFont = f; }
  147. inline wxFont *GetSelectedTabFont() const { return (wxFont*) & m_tabSelectedFont; }
  148. inline void SetSelectedTabFont(const wxFont& f) { m_tabSelectedFont = f; }
  149. // Find the node and the column at which this control is positioned.
  150. wxList::compatibility_iterator FindTabNodeAndColumn(wxTabControl *control, int *col) const ;
  151. // Do the necessary to change to this tab
  152. virtual bool ChangeTab(wxTabControl *control);
  153. // Move the selected tab to the bottom layer, if necessary,
  154. // without calling app activation code
  155. bool MoveSelectionTab(wxTabControl *control);
  156. inline int GetNumberOfTabs() const { return m_noTabs; }
  157. protected:
  158. // List of layers, from front to back.
  159. wxTabLayerList m_layers;
  160. // Selected tab
  161. int m_tabSelection;
  162. // Usual tab height
  163. int m_tabHeight;
  164. // The height of the selected tab
  165. int m_tabSelectionHeight;
  166. // Usual tab width
  167. int m_tabWidth;
  168. // Space between tabs
  169. int m_tabHorizontalSpacing;
  170. // Space between top of normal tab and text
  171. int m_tabVerticalTextSpacing;
  172. // Horizontal offset of each tab row above the first
  173. int m_tabHorizontalOffset;
  174. // The distance between the bottom of the first tab row
  175. // and the top of the client area (i.e. the margin)
  176. int m_topMargin;
  177. // The position and size of the view above which the tabs are placed.
  178. // I.e., the internal client area of the sheet.
  179. wxRect m_tabViewRect;
  180. // Bitlist of styles
  181. long m_tabStyle;
  182. // Colours
  183. wxColour m_highlightColour;
  184. wxColour m_shadowColour;
  185. wxColour m_backgroundColour;
  186. wxColour m_textColour;
  187. // Pen and brush cache
  188. const wxPen* m_highlightPen;
  189. const wxPen* m_shadowPen;
  190. const wxPen* m_backgroundPen;
  191. const wxBrush* m_backgroundBrush;
  192. wxFont m_tabFont;
  193. wxFont m_tabSelectedFont;
  194. int m_noTabs;
  195. wxWindow* m_window;
  196. };
  197. /*
  198. * A dialog box class that is tab-friendly
  199. */
  200. class WXDLLIMPEXP_CORE wxTabbedDialog : public wxDialog
  201. {
  202. DECLARE_DYNAMIC_CLASS(wxTabbedDialog)
  203. public:
  204. wxTabbedDialog(wxWindow *parent,
  205. wxWindowID id,
  206. const wxString& title,
  207. const wxPoint& pos = wxDefaultPosition,
  208. const wxSize& size = wxDefaultSize,
  209. long windowStyle = wxDEFAULT_DIALOG_STYLE,
  210. const wxString& name = wxDialogNameStr);
  211. virtual ~wxTabbedDialog();
  212. wxTabView *GetTabView() const { return m_tabView; }
  213. void SetTabView(wxTabView *v) { m_tabView = v; }
  214. void OnCloseWindow(wxCloseEvent& event);
  215. void OnMouseEvent(wxMouseEvent& event);
  216. void OnPaint(wxPaintEvent& event);
  217. protected:
  218. wxTabView* m_tabView;
  219. private:
  220. DECLARE_EVENT_TABLE()
  221. };
  222. /*
  223. * A panel class that is tab-friendly
  224. */
  225. class WXDLLIMPEXP_CORE wxTabbedPanel : public wxPanel
  226. {
  227. DECLARE_DYNAMIC_CLASS(wxTabbedPanel)
  228. public:
  229. wxTabbedPanel(wxWindow *parent,
  230. wxWindowID id,
  231. const wxPoint& pos = wxDefaultPosition,
  232. const wxSize& size = wxDefaultSize,
  233. long windowStyle = 0,
  234. const wxString& name = wxPanelNameStr);
  235. virtual ~wxTabbedPanel();
  236. wxTabView *GetTabView() const { return m_tabView; }
  237. void SetTabView(wxTabView *v) { m_tabView = v; }
  238. void OnMouseEvent(wxMouseEvent& event);
  239. void OnPaint(wxPaintEvent& event);
  240. protected:
  241. wxTabView* m_tabView;
  242. private:
  243. DECLARE_EVENT_TABLE()
  244. };
  245. WX_DECLARE_HASH_MAP(int, wxWindow*, wxIntegerHash, wxIntegerEqual,
  246. wxIntToWindowHashMap);
  247. class WXDLLIMPEXP_CORE wxPanelTabView : public wxTabView
  248. {
  249. DECLARE_DYNAMIC_CLASS(wxPanelTabView)
  250. public:
  251. wxPanelTabView(wxPanel *pan, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
  252. virtual ~wxPanelTabView(void);
  253. // Called when a tab is activated
  254. virtual void OnTabActivate(int activateId, int deactivateId);
  255. // Specific to this class
  256. void AddTabWindow(int id, wxWindow *window);
  257. wxWindow *GetTabWindow(int id) const ;
  258. void ClearWindows(bool deleteWindows = true);
  259. wxWindow *GetCurrentWindow() const { return m_currentWindow; }
  260. void ShowWindowForTab(int id);
  261. // wxList& GetWindows() const { return (wxList&) m_tabWindows; }
  262. protected:
  263. // List of panels, one for each tab. Indexed
  264. // by tab ID.
  265. wxIntToWindowHashMap m_tabWindows;
  266. wxWindow* m_currentWindow;
  267. wxPanel* m_panel;
  268. };
  269. #endif