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_DYNAMIC_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(size
.x
, 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 SetDefaultSize(const wxSize
& size
) { m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
; };
126 virtual wxSize
GetDefaultSize(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
GetDefaultButtonSize(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 GetDefaultButtonSize().x
; };
138 inline int GetDefaultButtonHeight(void) const { return GetDefaultButtonSize().y
; };
142 virtual void Layout(void);
144 // Add all the buttons: required for Win95.
145 // TODO: unify API so there's no ambiguity
146 virtual bool CreateTools(void) { return TRUE
; }
148 void Command(wxCommandEvent
& event
);
150 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
151 // inherits from wxControl. This could have been put into wxToolBarSimple,
152 // but we might want any derived toolbar class to be scrollable.
154 // Number of pixels per user unit (0 or -1 for no scrollbar)
155 // Length of virtual canvas in user units
156 virtual void SetScrollbars(int horizontal
, int vertical
,
157 int x_length
, int y_length
,
158 int x_pos
= 0, int y_pos
= 0);
160 // Physically scroll the window
161 virtual void Scroll(int x_pos
, int y_pos
);
162 virtual void GetScrollPixelsPerUnit(int *x_unit
, int *y_unit
) const;
163 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
164 virtual void AdjustScrollbars(void);
166 // Prepare the DC by translating it according to the current scroll position
167 virtual void PrepareDC(wxDC
& dc
);
169 int GetScrollPageSize(int orient
) const ;
170 void SetScrollPageSize(int orient
, int pageSize
);
172 // Get the view start
173 virtual void ViewStart(int *x
, int *y
) const;
175 // Actual size in pixels when scrolling is taken into account
176 virtual void GetVirtualSize(int *x
, int *y
) const;
178 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
179 virtual void DoToolbarUpdates(void);
182 virtual void CalcScrolledPosition(int x, int y, int *xx, int *yy) const ;
183 virtual void CalcUnscrolledPosition(int x, int y, long *xx, long *yy) const ;
186 void OnScroll(wxScrollEvent
& event
);
187 void OnSize(wxSizeEvent
& event
);
188 void OnIdle(wxIdleEvent
& event
);
190 // Required to force normal cursor-setting behaviour in Windows
192 virtual void MSWOnMouseMove(int x
, int y
, const WXUINT flags
);
197 int m_tilingDirection
;
199 int m_currentRowsOrColumns
;
200 long m_lastX
, m_lastY
;
201 long m_maxWidth
, m_maxHeight
;
202 int m_currentTool
; // Tool where mouse currently is
203 int m_pressedTool
; // Tool where mouse pressed
207 int m_toolSeparation
;
209 long m_defaultHeight
;
212 ////////////////////////////////////////////////////////////////////////
215 // Calculate scroll increment
216 virtual int CalcScrollInc(wxScrollEvent
& event
);
218 ////////////////////////////////////////////////////////////////////////
221 int m_xScrollPixelsPerLine
;
222 int m_yScrollPixelsPerLine
;
223 bool m_xScrollingEnabled
;
224 bool m_yScrollingEnabled
;
225 int m_xScrollPosition
;
226 int m_yScrollPosition
;
227 bool m_calcScrolledOffset
; // If TRUE, wxCanvasDC uses scrolled offsets
230 int m_xScrollLinesPerPage
;
231 int m_yScrollLinesPerPage
;
234 DECLARE_EVENT_TABLE()
237 #endif // USE_TOOLBAR