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 char*) 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
33 class WXDLLEXPORT wxToolBarTool
: public wxObject
35 DECLARE_DYNAMIC_CLASS(wxToolBarTool
)
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
= "");
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
; }
47 wxObject
* m_clientData
;
55 bool m_deleteSecondBitmap
;
60 wxString m_shortHelpString
;
61 wxString m_longHelpString
;
64 class WXDLLEXPORT wxToolBarBase
: public wxControl
66 DECLARE_ABSTRACT_CLASS(wxToolBarBase
)
72 // Handle wxToolBar events
74 // Only allow toggle if returns TRUE. Call when left button up.
75 virtual bool OnLeftClick(int toolIndex
, bool toggleDown
);
77 // Call when right button down.
78 virtual void OnRightClick(int toolIndex
, long x
, long y
);
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
);
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);
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
; }
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
; }
104 virtual wxSize
GetMaxSize ( void ) const;
106 virtual bool GetToolState(int toolIndex
) const;
107 virtual bool GetToolEnabled(int toolIndex
) const;
108 virtual wxToolBarTool
*FindToolForPosition(long x
, long y
) const;
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;
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
);
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
; }
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
); }
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
); } ;
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(); }
144 virtual void Layout(void);
146 // Add all the buttons: required for Win95.
147 virtual bool CreateTools(void) { return TRUE
; }
149 // Calls the appropriate function after tools have been created.
150 // E.g. Layout, or CreateTools.
151 virtual bool Realize() = 0;
153 void Command(wxCommandEvent
& event
);
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.
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);
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);
171 // Prepare the DC by translating it according to the current scroll position
172 virtual void PrepareDC(wxDC
& dc
);
174 int GetScrollPageSize(int orient
) const ;
175 void SetScrollPageSize(int orient
, int pageSize
);
177 // Get the view start
178 virtual void ViewStart(int *x
, int *y
) const;
180 // Actual size in pixels when scrolling is taken into account
181 virtual void GetVirtualSize(int *x
, int *y
) const;
183 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
184 virtual void DoToolbarUpdates(void);
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
; }
190 void OnScroll(wxScrollEvent
& event
);
191 void OnSize(wxSizeEvent
& event
);
192 void OnIdle(wxIdleEvent
& event
);
194 // Required to force normal cursor-setting behaviour in Windows
196 virtual void MSWOnMouseMove(int x
, int y
, WXUINT flags
);
201 // int m_tilingDirection;
202 // int m_rowsOrColumns;
205 long m_maxWidth
, m_maxHeight
;
206 int m_currentTool
; // Tool where mouse currently is
207 int m_pressedTool
; // Tool where mouse pressed
211 int m_toolSeparation
;
213 long m_defaultHeight
;
216 ////////////////////////////////////////////////////////////////////////
219 // Calculate scroll increment
220 virtual int CalcScrollInc(wxScrollEvent
& event
);
222 ////////////////////////////////////////////////////////////////////////
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
234 int m_xScrollLinesPerPage
;
235 int m_yScrollLinesPerPage
;
238 DECLARE_EVENT_TABLE()