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
*item
= (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
;
81 class WXDLLEXPORT wxToolBarBase
: public wxControl
83 DECLARE_ABSTRACT_CLASS(wxToolBarBase
)
89 // Handle wxToolBar events
91 // Only allow toggle if returns TRUE. Call when left button up.
92 virtual bool OnLeftClick(int toolIndex
, bool toggleDown
);
94 // Call when right button down.
95 virtual void OnRightClick(int toolIndex
, long x
, long y
);
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
);
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);
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
; }
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
; }
121 virtual wxSize
GetMaxSize ( void ) const;
123 virtual bool GetToolState(int toolIndex
) const;
124 virtual bool GetToolEnabled(int toolIndex
) const;
125 virtual wxToolBarTool
*FindToolForPosition(long x
, long y
) const;
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;
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
);
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
; }
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
); }
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
); } ;
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(); }
161 virtual void LayoutTools();
163 // Add all the buttons: required for Win95.
164 virtual bool CreateTools(void) { return TRUE
; }
166 // Calls the appropriate function after tools have been created.
167 // E.g. Layout, or CreateTools.
168 virtual bool Realize() = 0;
170 void Command(wxCommandEvent
& event
);
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.
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);
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);
188 // Prepare the DC by translating it according to the current scroll position
189 virtual void PrepareDC(wxDC
& dc
);
191 int GetScrollPageSize(int orient
) const ;
192 void SetScrollPageSize(int orient
, int pageSize
);
194 // Get the view start
195 virtual void ViewStart(int *x
, int *y
) const;
197 // Actual size in pixels when scrolling is taken into account
198 virtual void GetVirtualSize(int *x
, int *y
) const;
200 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
201 virtual void DoToolbarUpdates(void);
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
; }
207 void OnScroll(wxScrollEvent
& event
);
208 void OnSize(wxSizeEvent
& event
);
209 void OnIdle(wxIdleEvent
& event
);
213 // int m_tilingDirection;
214 // int m_rowsOrColumns;
217 long m_maxWidth
, m_maxHeight
;
218 int m_currentTool
; // Tool where mouse currently is
219 int m_pressedTool
; // Tool where mouse pressed
223 int m_toolSeparation
;
225 long m_defaultHeight
;
228 ////////////////////////////////////////////////////////////////////////
231 // Calculate scroll increment
232 virtual int CalcScrollInc(wxScrollEvent
& event
);
234 ////////////////////////////////////////////////////////////////////////
237 int m_xScrollPixelsPerLine
;
238 int m_yScrollPixelsPerLine
;
239 bool m_xScrollingEnabled
;
240 bool m_yScrollingEnabled
;
241 int m_xScrollPosition
;
242 int m_yScrollPosition
;
243 bool m_calcScrolledOffset
; // If TRUE, wxCanvasDC uses scrolled offsets
246 int m_xScrollLinesPerPage
;
247 int m_yScrollLinesPerPage
;
250 DECLARE_EVENT_TABLE()