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_
16 #pragma interface "tbarbase.h"
22 #include "wx/bitmap.h"
24 #include "wx/control.h"
26 WXDLLEXPORT_DATA(extern const wxChar
*) wxToolBarNameStr
;
27 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
28 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
30 #define wxTOOL_STYLE_BUTTON 1
31 #define wxTOOL_STYLE_SEPARATOR 2
34 class WXDLLEXPORT wxToolBar
;
37 class WXDLLEXPORT wxToolBarTool
: public wxObject
39 DECLARE_DYNAMIC_CLASS(wxToolBarTool
)
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
*pixmap
= (GtkWidget
*) NULL
);
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
);
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
; }
60 wxObject
* m_clientData
;
68 bool m_deleteSecondBitmap
;
73 wxString m_shortHelpString
;
74 wxString m_longHelpString
;
82 class WXDLLEXPORT wxToolBarBase
: public wxControl
84 DECLARE_ABSTRACT_CLASS(wxToolBarBase
)
90 // Handle wxToolBar events
92 // Only allow toggle if returns TRUE. Call when left button up.
93 virtual bool OnLeftClick(int toolIndex
, bool toggleDown
);
95 // Call when right button down.
96 virtual void OnRightClick(int toolIndex
, long x
, long y
);
98 // Called when the mouse cursor enters a tool bitmap.
99 // Argument is -1 if mouse is exiting the toolbar.
100 virtual void OnMouseEnter(int toolIndex
);
102 // If pushedBitmap is NULL, a reversed version of bitmap is
103 // created and used as the pushed/toggled image.
104 // If toggle is TRUE, the button toggles between the two states.
105 virtual wxToolBarTool
*AddTool(int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
106 bool toggle
= FALSE
, long xPos
= -1, long yPos
= -1, wxObject
*clientData
= NULL
,
107 const wxString
& helpString1
= wxEmptyString
, const wxString
& helpString2
= wxEmptyString
);
108 virtual void AddSeparator();
109 virtual void ClearTools();
111 virtual void EnableTool(int toolIndex
, bool enable
);
112 virtual void ToggleTool(int toolIndex
, bool toggle
); // toggle is TRUE if toggled on
113 virtual void SetToggle(int toolIndex
, bool toggle
); // Set this to be togglable (or not)
114 virtual wxObject
*GetToolClientData(int index
) const;
115 inline wxList
& GetTools() const { return (wxList
&) m_tools
; }
117 // After the toolbar has initialized, this is the size the tools take up
118 #if WXWXIN_COMPATIBILITY
119 inline void GetMaxSize ( long * width
, long * height
) const
120 { wxSize
maxSize(GetMaxSize()); *width
= maxSize
.x
; *height
= maxSize
.y
; }
122 virtual wxSize
GetMaxSize ( void ) const;
124 virtual bool GetToolState(int toolIndex
) const;
125 virtual bool GetToolEnabled(int toolIndex
) const;
126 virtual wxToolBarTool
*FindToolForPosition(long x
, long y
) const;
128 virtual void SetToolShortHelp(int toolIndex
, const wxString
& helpString
);
129 virtual wxString
GetToolShortHelp(int toolIndex
) const;
130 virtual void SetToolLongHelp(int toolIndex
, const wxString
& helpString
);
131 virtual wxString
GetToolLongHelp(int toolIndex
) const;
133 virtual void SetMargins(int x
, int y
);
134 inline void SetMargins(const wxSize
& size
) { SetMargins((int) size
.x
, (int) size
.y
); }
135 virtual void SetToolPacking(int packing
);
136 virtual void SetToolSeparation(int separation
);
138 inline virtual wxSize
GetToolMargins() { return wxSize(m_xMargin
, m_yMargin
); }
139 inline virtual int GetToolPacking() { return m_toolPacking
; }
140 inline virtual int GetToolSeparation() { return m_toolSeparation
; }
142 virtual void SetToolBitmapSize(const wxSize
& size
) { m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
; };
143 virtual wxSize
GetToolBitmapSize() const { return wxSize(m_defaultWidth
, m_defaultHeight
); }
145 // The button size (in some implementations) is bigger than the bitmap size: this returns
146 // the total button size.
147 virtual wxSize
GetToolSize() const { return wxSize(m_defaultWidth
, m_defaultHeight
); } ;
150 #if WXWIN_COMPATIBILITY
151 void SetDefaultSize(int w
, int h
) { SetDefaultSize(wxSize(w
, h
)); }
152 long GetDefaultWidth() const { return m_defaultWidth
; }
153 long GetDefaultHeight() const { return m_defaultHeight
; }
154 int GetDefaultButtonWidth() const { return (int) GetDefaultButtonSize().x
; };
155 int GetDefaultButtonHeight() const { return (int) GetDefaultButtonSize().y
; };
156 virtual void SetDefaultSize(const wxSize
& size
) { SetToolBitmapSize(size
); }
157 virtual wxSize
GetDefaultSize() const { return GetToolBitmapSize(); }
158 virtual wxSize
GetDefaultButtonSize() const { return GetToolSize(); }
162 virtual void LayoutTools();
164 // Add all the buttons: required for Win95.
165 virtual bool CreateTools() { return TRUE
; }
167 // Calls the appropriate function after tools have been created.
168 // E.g. Layout, or CreateTools.
169 virtual bool Realize() = 0;
171 void Command(wxCommandEvent
& event
);
173 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
174 // inherits from wxControl. This could have been put into wxToolBarSimple,
175 // but we might want any derived toolbar class to be scrollable.
177 // Number of pixels per user unit (0 or -1 for no scrollbar)
178 // Length of virtual canvas in user units
179 virtual void SetScrollbars(int horizontal
, int vertical
,
180 int x_length
, int y_length
,
181 int x_pos
= 0, int y_pos
= 0);
183 // Physically scroll the window
184 virtual void Scroll(int x_pos
, int y_pos
);
185 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
186 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
187 virtual void AdjustScrollbars();
189 // Prepare the DC by translating it according to the current scroll position
190 virtual void PrepareDC(wxDC
& dc
);
192 int GetScrollPageSize(int orient
) const ;
193 void SetScrollPageSize(int orient
, int pageSize
);
195 // Get the view start
196 virtual void ViewStart(int *x
, int *y
) const;
198 // Actual size in pixels when scrolling is taken into account
199 virtual void GetVirtualSize(int *x
, int *y
) const;
201 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
202 virtual void DoToolbarUpdates();
204 inline void SetMaxRowsCols(int rows
, int cols
) { m_maxRows
= rows
; m_maxCols
= cols
; }
205 inline int GetMaxRows() const { return m_maxRows
; }
206 inline int GetMaxCols() const { return m_maxCols
; }
208 void OnScroll(wxScrollEvent
& event
);
209 void OnSize(wxSizeEvent
& event
);
210 void OnIdle(wxIdleEvent
& event
);
214 // int m_tilingDirection;
215 // int m_rowsOrColumns;
218 long m_maxWidth
, m_maxHeight
;
219 int m_currentTool
; // Tool where mouse currently is
220 int m_pressedTool
; // Tool where mouse pressed
224 int m_toolSeparation
;
226 wxCoord m_defaultWidth
;
227 wxCoord m_defaultHeight
;
230 ////////////////////////////////////////////////////////////////////////
233 // Calculate scroll increment
234 virtual int CalcScrollInc(wxScrollEvent
& event
);
236 ////////////////////////////////////////////////////////////////////////
239 int m_xScrollPixelsPerLine
;
240 int m_yScrollPixelsPerLine
;
241 bool m_xScrollingEnabled
;
242 bool m_yScrollingEnabled
;
243 int m_xScrollPosition
;
244 int m_yScrollPosition
;
245 bool m_calcScrolledOffset
; // If TRUE, wxCanvasDC uses scrolled offsets
248 int m_xScrollLinesPerPage
;
249 int m_yScrollLinesPerPage
;
252 DECLARE_EVENT_TABLE()