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