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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "tbarbase.h"
23 #include "wx/bitmap.h"
25 #include "wx/control.h"
27 WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr
;
28 WXDLLEXPORT_DATA(extern const wxSize
) wxDefaultSize
;
29 WXDLLEXPORT_DATA(extern const wxPoint
) wxDefaultPosition
;
31 #define wxTOOL_STYLE_BUTTON 1
32 #define wxTOOL_STYLE_SEPARATOR 2
34 class WXDLLEXPORT wxToolBarTool
: public wxObject
36 DECLARE_DYNAMIC_CLASS(wxToolBarTool
)
38 wxToolBarTool(int theIndex
= 0, const wxBitmap
& bitmap1
= wxNullBitmap
, const wxBitmap
& bitmap2
= wxNullBitmap
,
39 bool toggle
= FALSE
, long xPos
= -1, long yPos
= -1,
40 const wxString
& shortHelpString
= "", const wxString
& longHelpString
= "");
42 inline void SetSize( long w
, long h
) { m_width
= w
; m_height
= h
; }
43 inline long GetWidth () const { return m_width
; }
44 inline long GetHeight () const { return m_height
; }
48 wxObject
* m_clientData
;
56 bool m_deleteSecondBitmap
;
61 wxString m_shortHelpString
;
62 wxString m_longHelpString
;
65 class WXDLLEXPORT wxToolBarBase
: public wxControl
67 DECLARE_ABSTRACT_CLASS(wxToolBarBase
)
73 // Handle wxToolBar events
75 // Only allow toggle if returns TRUE. Call when left button up.
76 virtual bool OnLeftClick(int toolIndex
, bool toggleDown
);
78 // Call when right button down.
79 virtual void OnRightClick(int toolIndex
, long x
, long y
);
81 // Called when the mouse cursor enters a tool bitmap.
82 // Argument is -1 if mouse is exiting the toolbar.
83 virtual void OnMouseEnter(int toolIndex
);
85 // If pushedBitmap is NULL, a reversed version of bitmap is
86 // created and used as the pushed/toggled image.
87 // If toggle is TRUE, the button toggles between the two states.
88 virtual wxToolBarTool
*AddTool(int toolIndex
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
= wxNullBitmap
,
89 bool toggle
= FALSE
, long xPos
= -1, long yPos
= -1, wxObject
*clientData
= NULL
,
90 const wxString
& helpString1
= "", const wxString
& helpString2
= "");
91 virtual void AddSeparator(void);
92 virtual void ClearTools(void);
94 virtual void EnableTool(int toolIndex
, bool enable
);
95 virtual void ToggleTool(int toolIndex
, bool toggle
); // toggle is TRUE if toggled on
96 virtual void SetToggle(int toolIndex
, bool toggle
); // Set this to be togglable (or not)
97 virtual wxObject
*GetToolClientData(int index
) const;
98 inline wxList
& GetTools(void) const { return (wxList
&) m_tools
; }
100 // After the toolbar has initialized, this is the size the tools take up
101 #if WXWXIN_COMPATIBILITY
102 inline void GetMaxSize ( long * width
, long * height
) const
103 { wxSize
maxSize(GetMaxSize()); *width
= maxSize
.x
; *height
= maxSize
.y
; }
105 virtual wxSize
GetMaxSize ( void ) const;
107 virtual bool GetToolState(int toolIndex
) const;
108 virtual bool GetToolEnabled(int toolIndex
) const;
109 virtual wxToolBarTool
*FindToolForPosition(long x
, long y
) const;
111 virtual void SetToolShortHelp(int toolIndex
, const wxString
& helpString
);
112 virtual wxString
GetToolShortHelp(int toolIndex
) const;
113 virtual void SetToolLongHelp(int toolIndex
, const wxString
& helpString
);
114 virtual wxString
GetToolLongHelp(int toolIndex
) const;
116 virtual void SetMargins(int x
, int y
);
117 inline void SetMargins(const wxSize
& size
) { SetMargins((int) size
.x
, (int) size
.y
); }
118 virtual void SetToolPacking(int packing
);
119 virtual void SetToolSeparation(int separation
);
121 inline virtual wxSize
GetToolMargins(void) { return wxSize(m_xMargin
, m_yMargin
); }
122 inline virtual int GetToolPacking(void) { return m_toolPacking
; }
123 inline virtual int GetToolSeparation(void) { return m_toolSeparation
; }
125 virtual void SetToolBitmapSize(const wxSize
& size
) { m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
; };
126 virtual wxSize
GetToolBitmapSize(void) const { return wxSize(m_defaultWidth
, m_defaultHeight
); }
128 // The button size (in some implementations) is bigger than the bitmap size: this returns
129 // the total button size.
130 virtual wxSize
GetToolSize(void) const { return wxSize(m_defaultWidth
, m_defaultHeight
); } ;
133 #if WXWIN_COMPATIBILITY
134 inline void SetDefaultSize(int w
, int h
) { SetDefaultSize(wxSize(w
, h
)); }
135 inline long GetDefaultWidth(void) const { return m_defaultWidth
; }
136 inline long GetDefaultHeight(void) const { return m_defaultHeight
; }
137 inline int GetDefaultButtonWidth(void) const { return (int) GetDefaultButtonSize().x
; };
138 inline int GetDefaultButtonHeight(void) const { return (int) GetDefaultButtonSize().y
; };
139 virtual void SetDefaultSize(const wxSize
& size
) { SetToolBitmapSize(size
); }
140 virtual wxSize
GetDefaultSize(void) const { return GetToolBitmapSize(); }
141 virtual wxSize
GetDefaultButtonSize(void) const { return GetToolSize(); }
145 virtual void Layout(void);
147 // Add all the buttons: required for Win95.
148 virtual bool CreateTools(void) { return TRUE
; }
150 // Calls the appropriate function after tools have been created.
151 // E.g. Layout, or CreateTools.
152 virtual bool Realize() = 0;
154 void Command(wxCommandEvent
& event
);
156 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
157 // inherits from wxControl. This could have been put into wxToolBarSimple,
158 // but we might want any derived toolbar class to be scrollable.
160 // Number of pixels per user unit (0 or -1 for no scrollbar)
161 // Length of virtual canvas in user units
162 virtual void SetScrollbars(int horizontal
, int vertical
,
163 int x_length
, int y_length
,
164 int x_pos
= 0, int y_pos
= 0);
166 // Physically scroll the window
167 virtual void Scroll(int x_pos
, int y_pos
);
168 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
169 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
170 virtual void AdjustScrollbars(void);
172 // Prepare the DC by translating it according to the current scroll position
173 virtual void PrepareDC(wxDC
& dc
);
175 int GetScrollPageSize(int orient
) const ;
176 void SetScrollPageSize(int orient
, int pageSize
);
178 // Get the view start
179 virtual void ViewStart(int *x
, int *y
) const;
181 // Actual size in pixels when scrolling is taken into account
182 virtual void GetVirtualSize(int *x
, int *y
) const;
184 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
185 virtual void DoToolbarUpdates(void);
187 inline void SetMaxRowsCols(int rows
, int cols
) { m_maxRows
= rows
; m_maxCols
= cols
; }
188 inline int GetMaxRows() const { return m_maxRows
; }
189 inline int GetMaxCols() const { return m_maxCols
; }
191 void OnScroll(wxScrollEvent
& event
);
192 void OnSize(wxSizeEvent
& event
);
193 void OnIdle(wxIdleEvent
& event
);
195 // Required to force normal cursor-setting behaviour in Windows
197 virtual void MSWOnMouseMove(int x
, int y
, const WXUINT flags
);
202 // int m_tilingDirection;
203 // int m_rowsOrColumns;
206 long m_maxWidth
, m_maxHeight
;
207 int m_currentTool
; // Tool where mouse currently is
208 int m_pressedTool
; // Tool where mouse pressed
212 int m_toolSeparation
;
214 long m_defaultHeight
;
217 ////////////////////////////////////////////////////////////////////////
220 // Calculate scroll increment
221 virtual int CalcScrollInc(wxScrollEvent
& event
);
223 ////////////////////////////////////////////////////////////////////////
226 int m_xScrollPixelsPerLine
;
227 int m_yScrollPixelsPerLine
;
228 bool m_xScrollingEnabled
;
229 bool m_yScrollingEnabled
;
230 int m_xScrollPosition
;
231 int m_yScrollPosition
;
232 bool m_calcScrolledOffset
; // If TRUE, wxCanvasDC uses scrolled offsets
235 int m_xScrollLinesPerPage
;
236 int m_yScrollLinesPerPage
;
239 DECLARE_EVENT_TABLE()
242 #endif // USE_TOOLBAR