]> git.saurik.com Git - wxWidgets.git/blob - include/wx/tbarbase.h
One that got away
[wxWidgets.git] / include / wx / tbarbase.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbarbase.h
3 // Purpose: Base class for toolbar classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TBARBASE_H_
13 #define _WX_TBARBASE_H_
14
15 #ifdef __GNUG__
16 #pragma interface "tbarbase.h"
17 #endif
18
19 #include "wx/setup.h"
20 #include "wx/defs.h"
21
22 #include "wx/bitmap.h"
23 #include "wx/list.h"
24 #include "wx/control.h"
25
26 WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
27 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
28 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
29
30 #define wxTOOL_STYLE_BUTTON 1
31 #define wxTOOL_STYLE_SEPARATOR 2
32
33 class WXDLLEXPORT wxToolBarTool: public wxObject
34 {
35 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
36 public:
37 wxToolBarTool(int theIndex = 0, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap,
38 bool toggle = FALSE, long xPos = -1, long yPos = -1,
39 const wxString& shortHelpString = "", const wxString& longHelpString = "");
40 ~wxToolBarTool ();
41 inline void SetSize( long w, long h ) { m_width = w; m_height = h; }
42 inline long GetWidth () const { return m_width; }
43 inline long GetHeight () const { return m_height; }
44
45 public:
46 int m_toolStyle;
47 wxObject * m_clientData;
48 int m_index;
49 long m_x;
50 long m_y;
51 long m_width;
52 long m_height;
53 bool m_toggleState;
54 bool m_isToggle;
55 bool m_deleteSecondBitmap;
56 bool m_enabled;
57 wxBitmap m_bitmap1;
58 wxBitmap m_bitmap2;
59 bool m_isMenuCommand;
60 wxString m_shortHelpString;
61 wxString m_longHelpString;
62 };
63
64 class WXDLLEXPORT wxToolBarBase : public wxControl
65 {
66 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
67 public:
68
69 wxToolBarBase(void);
70 ~wxToolBarBase(void);
71
72 // Handle wxToolBar events
73
74 // Only allow toggle if returns TRUE. Call when left button up.
75 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
76
77 // Call when right button down.
78 virtual void OnRightClick(int toolIndex, long x, long y);
79
80 // Called when the mouse cursor enters a tool bitmap.
81 // Argument is -1 if mouse is exiting the toolbar.
82 virtual void OnMouseEnter(int toolIndex);
83
84 // If pushedBitmap is NULL, a reversed version of bitmap is
85 // created and used as the pushed/toggled image.
86 // If toggle is TRUE, the button toggles between the two states.
87 virtual wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
88 bool toggle = FALSE, long xPos = -1, long yPos = -1, wxObject *clientData = NULL,
89 const wxString& helpString1 = "", const wxString& helpString2 = "");
90 virtual void AddSeparator(void);
91 virtual void ClearTools(void);
92
93 virtual void EnableTool(int toolIndex, bool enable);
94 virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
95 virtual void SetToggle(int toolIndex, bool toggle); // Set this to be togglable (or not)
96 virtual wxObject *GetToolClientData(int index) const;
97 inline wxList& GetTools(void) const { return (wxList&) m_tools; }
98
99 // After the toolbar has initialized, this is the size the tools take up
100 #if WXWXIN_COMPATIBILITY
101 inline void GetMaxSize ( long * width, long * height ) const
102 { wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
103 #endif
104 virtual wxSize GetMaxSize ( void ) const;
105
106 virtual bool GetToolState(int toolIndex) const;
107 virtual bool GetToolEnabled(int toolIndex) const;
108 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
109
110 virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
111 virtual wxString GetToolShortHelp(int toolIndex) const;
112 virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
113 virtual wxString GetToolLongHelp(int toolIndex) const;
114
115 virtual void SetMargins(int x, int y);
116 inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); }
117 virtual void SetToolPacking(int packing);
118 virtual void SetToolSeparation(int separation);
119
120 inline virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
121 inline virtual int GetToolPacking(void) { return m_toolPacking; }
122 inline virtual int GetToolSeparation(void) { return m_toolSeparation; }
123
124 virtual void SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; };
125 virtual wxSize GetToolBitmapSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); }
126
127 // The button size (in some implementations) is bigger than the bitmap size: this returns
128 // the total button size.
129 virtual wxSize GetToolSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ;
130
131 // Compatibility
132 #if WXWIN_COMPATIBILITY
133 inline void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
134 inline long GetDefaultWidth(void) const { return m_defaultWidth; }
135 inline long GetDefaultHeight(void) const { return m_defaultHeight; }
136 inline int GetDefaultButtonWidth(void) const { return (int) GetDefaultButtonSize().x; };
137 inline int GetDefaultButtonHeight(void) const { return (int) GetDefaultButtonSize().y; };
138 virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
139 virtual wxSize GetDefaultSize(void) const { return GetToolBitmapSize(); }
140 virtual wxSize GetDefaultButtonSize(void) const { return GetToolSize(); }
141 #endif
142
143 // Lay the tools out
144 virtual void Layout(void);
145
146 // Add all the buttons: required for Win95.
147 virtual bool CreateTools(void) { return TRUE; }
148
149 // Calls the appropriate function after tools have been created.
150 // E.g. Layout, or CreateTools.
151 virtual bool Realize() = 0;
152
153 void Command(wxCommandEvent& event);
154
155 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
156 // inherits from wxControl. This could have been put into wxToolBarSimple,
157 // but we might want any derived toolbar class to be scrollable.
158
159 // Number of pixels per user unit (0 or -1 for no scrollbar)
160 // Length of virtual canvas in user units
161 virtual void SetScrollbars(int horizontal, int vertical,
162 int x_length, int y_length,
163 int x_pos = 0, int y_pos = 0);
164
165 // Physically scroll the window
166 virtual void Scroll(int x_pos, int y_pos);
167 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
168 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
169 virtual void AdjustScrollbars(void);
170
171 // Prepare the DC by translating it according to the current scroll position
172 virtual void PrepareDC(wxDC& dc);
173
174 int GetScrollPageSize(int orient) const ;
175 void SetScrollPageSize(int orient, int pageSize);
176
177 // Get the view start
178 virtual void ViewStart(int *x, int *y) const;
179
180 // Actual size in pixels when scrolling is taken into account
181 virtual void GetVirtualSize(int *x, int *y) const;
182
183 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
184 virtual void DoToolbarUpdates(void);
185
186 inline void SetMaxRowsCols(int rows, int cols) { m_maxRows = rows; m_maxCols = cols; }
187 inline int GetMaxRows() const { return m_maxRows; }
188 inline int GetMaxCols() const { return m_maxCols; }
189
190 void OnScroll(wxScrollEvent& event);
191 void OnSize(wxSizeEvent& event);
192 void OnIdle(wxIdleEvent& event);
193
194 // Required to force normal cursor-setting behaviour in Windows
195 #ifdef __WXMSW__
196 virtual void MSWOnMouseMove(int x, int y, WXUINT flags);
197 #endif
198
199 protected:
200 wxList m_tools;
201 // int m_tilingDirection;
202 // int m_rowsOrColumns;
203 int m_maxRows;
204 int m_maxCols;
205 long m_maxWidth, m_maxHeight;
206 int m_currentTool; // Tool where mouse currently is
207 int m_pressedTool; // Tool where mouse pressed
208 int m_xMargin;
209 int m_yMargin;
210 int m_toolPacking;
211 int m_toolSeparation;
212 long m_defaultWidth;
213 long m_defaultHeight;
214
215 public:
216 ////////////////////////////////////////////////////////////////////////
217 //// IMPLEMENTATION
218
219 // Calculate scroll increment
220 virtual int CalcScrollInc(wxScrollEvent& event);
221
222 ////////////////////////////////////////////////////////////////////////
223 //// PROTECTED DATA
224 protected:
225 int m_xScrollPixelsPerLine;
226 int m_yScrollPixelsPerLine;
227 bool m_xScrollingEnabled;
228 bool m_yScrollingEnabled;
229 int m_xScrollPosition;
230 int m_yScrollPosition;
231 bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
232 int m_xScrollLines;
233 int m_yScrollLines;
234 int m_xScrollLinesPerPage;
235 int m_yScrollLinesPerPage;
236
237 public:
238 DECLARE_EVENT_TABLE()
239 };
240
241 #endif
242 // _WX_TBARBASE_H_
243