1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base class for toolbar classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TBARBASE_H_
13 #define _WX_TBARBASE_H_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma interface "tbarbase.h"
25 #include "wx/bitmap.h"
27 #include "wx/control.h"
29 class WXDLLEXPORT wxToolBar
;
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 WXDLLEXPORT_DATA(extern const wxChar
*) wxToolBarNameStr
;
36 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
37 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
41 wxTOOL_STYLE_BUTTON
= 1,
42 wxTOOL_STYLE_SEPARATOR
= 2,
46 // ----------------------------------------------------------------------------
47 // wxToolBarTool is one button/separator/whatever in the toolbar
48 // ----------------------------------------------------------------------------
50 class WXDLLEXPORT wxToolBarTool
: public wxObject
59 wxToolBarTool(wxToolBar
*owner
,
61 const wxBitmap
& bitmap1
= wxNullBitmap
,
62 const wxBitmap
& bitmap2
= wxNullBitmap
,
64 wxObject
*clientData
= (wxObject
*) NULL
,
65 const wxString
& shortHelpString
= wxEmptyString
,
66 const wxString
& longHelpString
= wxEmptyString
,
67 GtkWidget
*pixmap
= (GtkWidget
*) NULL
);
69 wxToolBarTool(int theIndex
,
70 const wxBitmap
& bitmap1
= wxNullBitmap
,
71 const wxBitmap
& bitmap2
= wxNullBitmap
,
75 const wxString
& shortHelpString
= wxEmptyString
,
76 const wxString
& longHelpString
= wxEmptyString
);
79 wxToolBarTool(wxControl
*control
);
86 void SetSize( long w
, long h
) { m_width
= w
; m_height
= h
; }
87 long GetWidth() const { return m_width
; }
88 long GetHeight() const { return m_height
; }
90 wxControl
*GetControl() const
92 wxASSERT_MSG( m_toolStyle
== wxTOOL_STYLE_CONTROL
,
93 _T("this toolbar tool is not a control") );
102 // as controls have their own client data, no need to waste memory
105 wxObject
*m_clientData
;
106 wxControl
*m_control
;
117 bool m_isMenuCommand
;
119 bool m_deleteSecondBitmap
;
123 wxString m_shortHelpString
;
124 wxString m_longHelpString
;
133 DECLARE_DYNAMIC_CLASS(wxToolBarTool
)
136 // ----------------------------------------------------------------------------
137 // the base class for all toolbars
138 // ----------------------------------------------------------------------------
140 class WXDLLEXPORT wxToolBarBase
: public wxControl
146 // toolbar construction
147 // --------------------
149 // If pushedBitmap is NULL, a reversed version of bitmap is created and
150 // used as the pushed/toggled image. If toggle is TRUE, the button toggles
151 // between the two states.
152 virtual wxToolBarTool
*AddTool(int toolIndex
,
153 const wxBitmap
& bitmap
,
154 const wxBitmap
& pushedBitmap
= wxNullBitmap
,
158 wxObject
*clientData
= NULL
,
159 const wxString
& helpString1
= wxEmptyString
,
160 const wxString
& helpString2
= wxEmptyString
);
162 // add an arbitrary control to the toolbar at given index, return TRUE if
163 // ok (notice that the control will be deleted by the toolbar and that it
164 // will also adjust its position/size)
166 // NB: the control should have toolbar as its parent
167 virtual bool AddControl(wxControl
* WXUNUSED(control
)) { return FALSE
; }
169 virtual void AddSeparator();
170 virtual void ClearTools();
172 // must be called after all buttons have been created to finish toolbar
174 virtual bool Realize() = 0;
179 virtual void EnableTool(int toolIndex
, bool enable
);
181 // toggle is TRUE if toggled on
182 virtual void ToggleTool(int toolIndex
, bool toggle
);
184 // Set this to be togglable (or not)
185 virtual void SetToggle(int toolIndex
, bool toggle
);
186 virtual wxObject
*GetToolClientData(int index
) const;
188 virtual bool GetToolState(int toolIndex
) const;
189 virtual bool GetToolEnabled(int toolIndex
) const;
190 virtual wxToolBarTool
*FindToolForPosition(long x
, long y
) const;
192 virtual void SetToolShortHelp(int toolIndex
, const wxString
& helpString
);
193 virtual wxString
GetToolShortHelp(int toolIndex
) const;
194 virtual void SetToolLongHelp(int toolIndex
, const wxString
& helpString
);
195 virtual wxString
GetToolLongHelp(int toolIndex
) const;
197 // margins/packing/separation
198 // --------------------------
200 virtual void SetMargins(int x
, int y
);
201 void SetMargins(const wxSize
& size
)
202 { SetMargins((int) size
.x
, (int) size
.y
); }
203 virtual void SetToolPacking(int packing
);
204 virtual void SetToolSeparation(int separation
);
206 virtual wxSize
GetToolMargins() { return wxSize(m_xMargin
, m_yMargin
); }
207 virtual int GetToolPacking() { return m_toolPacking
; }
208 virtual int GetToolSeparation() { return m_toolSeparation
; }
210 void SetMaxRowsCols(int rows
, int cols
)
211 { m_maxRows
= rows
; m_maxCols
= cols
; }
212 int GetMaxRows() const { return m_maxRows
; }
213 int GetMaxCols() const { return m_maxCols
; }
218 virtual void SetToolBitmapSize(const wxSize
& size
)
219 { m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
; };
220 virtual wxSize
GetToolBitmapSize() const
221 { return wxSize(m_defaultWidth
, m_defaultHeight
); }
223 // After the toolbar has initialized, this is the size the tools take up
224 virtual wxSize
GetMaxSize() const;
226 // The button size (in some implementations) is bigger than the bitmap size: this returns
227 // the total button size.
228 virtual wxSize
GetToolSize() const
229 { return wxSize(m_defaultWidth
, m_defaultHeight
); } ;
231 // Handle wxToolBar events
232 // -----------------------
234 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
236 // Only allow toggle if returns TRUE. Call when left button up.
237 virtual bool OnLeftClick(int toolIndex
, bool toggleDown
);
239 // Call when right button down.
240 virtual void OnRightClick(int toolIndex
, long x
, long y
);
242 // Called when the mouse cursor enters a tool bitmap.
243 // Argument is -1 if mouse is exiting the toolbar.
244 virtual void OnMouseEnter(int toolIndex
);
246 // more deprecated functions
247 // -------------------------
249 #if WXWIN_COMPATIBILITY
250 void SetDefaultSize(int w
, int h
) { SetDefaultSize(wxSize(w
, h
)); }
251 long GetDefaultWidth() const { return m_defaultWidth
; }
252 long GetDefaultHeight() const { return m_defaultHeight
; }
253 int GetDefaultButtonWidth() const { return (int) GetDefaultButtonSize().x
; };
254 int GetDefaultButtonHeight() const { return (int) GetDefaultButtonSize().y
; };
255 virtual void SetDefaultSize(const wxSize
& size
) { SetToolBitmapSize(size
); }
256 virtual wxSize
GetDefaultSize() const { return GetToolBitmapSize(); }
257 virtual wxSize
GetDefaultButtonSize() const { return GetToolSize(); }
258 void GetMaxSize ( long * width
, long * height
) const
259 { wxSize
maxSize(GetMaxSize()); *width
= maxSize
.x
; *height
= maxSize
.y
; }
260 #endif // WXWIN_COMPATIBILITY
262 // implementation only from now on
263 // -------------------------------
265 wxList
& GetTools() const { return (wxList
&) m_tools
; }
268 virtual void LayoutTools();
270 // Add all the buttons: required for Win95.
271 virtual bool CreateTools() { return TRUE
; }
273 void Command(wxCommandEvent
& event
);
275 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
276 // inherits from wxControl. This could have been put into wxToolBarSimple,
277 // but we might want any derived toolbar class to be scrollable.
279 // Number of pixels per user unit (0 or -1 for no scrollbar)
280 // Length of virtual canvas in user units
281 virtual void SetScrollbars(int horizontal
, int vertical
,
282 int x_length
, int y_length
,
283 int x_pos
= 0, int y_pos
= 0);
285 // Physically scroll the window
286 virtual void Scroll(int x_pos
, int y_pos
);
287 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
288 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
289 virtual void AdjustScrollbars();
291 // Prepare the DC by translating it according to the current scroll position
292 virtual void PrepareDC(wxDC
& dc
);
294 int GetScrollPageSize(int orient
) const ;
295 void SetScrollPageSize(int orient
, int pageSize
);
297 // Get the view start
298 virtual void ViewStart(int *x
, int *y
) const;
300 // Actual size in pixels when scrolling is taken into account
301 virtual void GetVirtualSize(int *x
, int *y
) const;
303 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
304 virtual void DoToolbarUpdates();
307 void OnScroll(wxScrollEvent
& event
);
308 void OnSize(wxSizeEvent
& event
);
309 void OnIdle(wxIdleEvent
& event
);
319 int m_currentTool
; // Tool where mouse currently is
320 int m_pressedTool
; // Tool where mouse pressed
325 int m_toolSeparation
;
327 wxCoord m_defaultWidth
;
328 wxCoord m_defaultHeight
;
331 ////////////////////////////////////////////////////////////////////////
334 // Calculate scroll increment
335 virtual int CalcScrollInc(wxScrollEvent
& event
);
337 ////////////////////////////////////////////////////////////////////////
340 int m_xScrollPixelsPerLine
;
341 int m_yScrollPixelsPerLine
;
342 bool m_xScrollingEnabled
;
343 bool m_yScrollingEnabled
;
344 int m_xScrollPosition
;
345 int m_yScrollPosition
;
346 bool m_calcScrolledOffset
; // If TRUE, wxCanvasDC uses scrolled offsets
349 int m_xScrollLinesPerPage
;
350 int m_yScrollLinesPerPage
;
353 DECLARE_EVENT_TABLE()
354 DECLARE_ABSTRACT_CLASS(wxToolBarBase
)