]> git.saurik.com Git - wxWidgets.git/blob - include/wx/tbarbase.h
Removed the WXUNUSED() from size parameters in wxIcon(filename,width,height)
[wxWidgets.git] / include / wx / tbarbase.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbarbase.h
3 // Purpose: Base class for toolbar classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __TBARBASEH__
13 #define __TBARBASEH__
14
15 #ifdef __GNUG__
16 #pragma interface "tbarbase.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if USE_TOOLBAR
22
23 #include "wx/bitmap.h"
24 #include "wx/list.h"
25 #include "wx/control.h"
26
27 WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
28 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
29 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
30
31 #define wxTOOL_STYLE_BUTTON 1
32 #define wxTOOL_STYLE_SEPARATOR 2
33
34 class WXDLLEXPORT wxToolBarTool: public wxObject
35 {
36 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
37 public:
38 wxToolBarTool(const int theIndex = 0, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap,
39 const bool toggle = FALSE, const long xPos = -1, const long yPos = -1,
40 const wxString& shortHelpString = "", const wxString& longHelpString = "");
41 ~wxToolBarTool ();
42 inline void SetSize( const long w, const long h ) { m_width = w; m_height = h; }
43 inline long GetWidth () const { return m_width; }
44 inline long GetHeight () const { return m_height; }
45
46 public:
47 int m_toolStyle;
48 wxObject * m_clientData;
49 int m_index;
50 long m_x;
51 long m_y;
52 long m_width;
53 long m_height;
54 bool m_toggleState;
55 bool m_isToggle;
56 bool m_deleteSecondBitmap;
57 bool m_enabled;
58 wxBitmap m_bitmap1;
59 wxBitmap m_bitmap2;
60 bool m_isMenuCommand;
61 wxString m_shortHelpString;
62 wxString m_longHelpString;
63 };
64
65 class WXDLLEXPORT wxToolBarBase : public wxControl
66 {
67 DECLARE_DYNAMIC_CLASS(wxToolBarBase)
68 public:
69
70 wxToolBarBase(void);
71 ~wxToolBarBase(void);
72
73 // Handle wxToolBar events
74
75 // Only allow toggle if returns TRUE. Call when left button up.
76 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
77
78 // Call when right button down.
79 virtual void OnRightClick(int toolIndex, long x, long y);
80
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);
84
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(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
89 const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL,
90 const wxString& helpString1 = "", const wxString& helpString2 = "");
91 virtual void AddSeparator(void);
92 virtual void ClearTools(void);
93
94 virtual void EnableTool(const int toolIndex, const bool enable);
95 virtual void ToggleTool(const int toolIndex, const bool toggle); // toggle is TRUE if toggled on
96 virtual void SetToggle(const int toolIndex, const bool toggle); // Set this to be togglable (or not)
97 virtual wxObject *GetToolClientData(const int index) const;
98 inline wxList& GetTools(void) const { return (wxList&) m_tools; }
99
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; }
104 #endif
105 virtual wxSize GetMaxSize ( void ) const;
106
107 virtual bool GetToolState(const int toolIndex) const;
108 virtual bool GetToolEnabled(const int toolIndex) const;
109 virtual wxToolBarTool *FindToolForPosition(const long x, const long y) const;
110
111 virtual void SetToolShortHelp(const int toolIndex, const wxString& helpString);
112 virtual wxString GetToolShortHelp(const int toolIndex) const;
113 virtual void SetToolLongHelp(const int toolIndex, const wxString& helpString);
114 virtual wxString GetToolLongHelp(const int toolIndex) const;
115
116 virtual void SetMargins(const int x, const int y);
117 inline void SetMargins(const wxSize& size) { SetMargins(size.x, size.y); }
118 virtual void SetToolPacking(const int packing);
119 virtual void SetToolSeparation(const int separation);
120
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; }
124
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); }
127
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); } ;
131
132 // Compatibility
133 #if WXWIN_COMPATIBILITY
134 inline void SetDefaultSize(const int w, const 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; };
139 #endif
140
141 // Lay the tools out
142 virtual void Layout(void);
143
144 // Add all the buttons: required for Win95.
145 // TODO: unify API so there's no ambiguity
146 virtual bool CreateTools(void) { return TRUE; }
147
148 void Command(wxCommandEvent& event);
149
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.
153
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(const int horizontal, const int vertical,
157 const int x_length, const int y_length,
158 const int x_pos = 0, const int y_pos = 0);
159
160 // Physically scroll the window
161 virtual void Scroll(const int x_pos, const int y_pos);
162 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
163 virtual void EnableScrolling(const bool x_scrolling, const bool y_scrolling);
164 virtual void AdjustScrollbars(void);
165
166 // Prepare the DC by translating it according to the current scroll position
167 virtual void PrepareDC(wxDC& dc);
168
169 int GetScrollPageSize(int orient) const ;
170 void SetScrollPageSize(int orient, int pageSize);
171
172 // Get the view start
173 virtual void ViewStart(int *x, int *y) const;
174
175 // Actual size in pixels when scrolling is taken into account
176 virtual void GetVirtualSize(int *x, int *y) const;
177
178 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
179 virtual void DoToolbarUpdates(void);
180
181 /*
182 virtual void CalcScrolledPosition(const int x, const int y, int *xx, int *yy) const ;
183 virtual void CalcUnscrolledPosition(const int x, const int y, long *xx, long *yy) const ;
184 */
185
186 void OnScroll(wxScrollEvent& event);
187 void OnSize(wxSizeEvent& event);
188 void OnIdle(wxIdleEvent& event);
189
190 // Required to force normal cursor-setting behaviour in Windows
191 #ifdef __WINDOWS__
192 virtual void MSWOnMouseMove(const int x, const int y, const WXUINT flags);
193 #endif
194
195 protected:
196 wxList m_tools;
197 int m_tilingDirection;
198 int m_rowsOrColumns;
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
204 int m_xMargin;
205 int m_yMargin;
206 int m_toolPacking;
207 int m_toolSeparation;
208 long m_defaultWidth;
209 long m_defaultHeight;
210
211 public:
212 ////////////////////////////////////////////////////////////////////////
213 //// IMPLEMENTATION
214
215 // Calculate scroll increment
216 virtual int CalcScrollInc(wxScrollEvent& event);
217
218 ////////////////////////////////////////////////////////////////////////
219 //// PROTECTED DATA
220 protected:
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
228 int m_xScrollLines;
229 int m_yScrollLines;
230 int m_xScrollLinesPerPage;
231 int m_yScrollLinesPerPage;
232
233 public:
234 DECLARE_EVENT_TABLE()
235 };
236
237 #endif // USE_TOOLBAR
238 #endif
239 // __TBARBASEH__
240