]> git.saurik.com Git - wxWidgets.git/blob - include/wx/tbarbase.h
Header file for MSW GSocket
[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 _WX_TBARBASE_H_
13 #define _WX_TBARBASE_H_
14
15 #ifdef __GNUG__
16 #pragma interface "tbarbase.h"
17 #endif
18
19 #include "wx/setup.h"
20 #include "wx/defs.h"
21
22 #include "wx/bitmap.h"
23 #include "wx/list.h"
24 #include "wx/control.h"
25
26 WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
27 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
28 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
29
30 #define wxTOOL_STYLE_BUTTON 1
31 #define wxTOOL_STYLE_SEPARATOR 2
32
33 #ifdef __WXGTK__
34 class WXDLLEXPORT wxToolBar;
35 #endif
36
37 class WXDLLEXPORT wxToolBarTool: public wxObject
38 {
39 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
40 public:
41 wxToolBarTool() {}
42 #ifdef __WXGTK__
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 *pixmap = (GtkWidget *) NULL );
48 #else
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);
52 #endif
53 ~wxToolBarTool ();
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; }
57
58 public:
59 int m_toolStyle;
60 wxObject * m_clientData;
61 int m_index;
62 long m_x;
63 long m_y;
64 long m_width;
65 long m_height;
66 bool m_toggleState;
67 bool m_isToggle;
68 bool m_deleteSecondBitmap;
69 bool m_enabled;
70 wxBitmap m_bitmap1;
71 wxBitmap m_bitmap2;
72 bool m_isMenuCommand;
73 wxString m_shortHelpString;
74 wxString m_longHelpString;
75 #ifdef __WXGTK__
76 wxToolBar *m_owner;
77 GtkWidget *m_item;
78 GtkWidget *m_pixmap;
79 #endif
80 };
81
82 class WXDLLEXPORT wxToolBarBase : public wxControl
83 {
84 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
85 public:
86
87 wxToolBarBase(void);
88 ~wxToolBarBase(void);
89
90 // Handle wxToolBar events
91
92 // Only allow toggle if returns TRUE. Call when left button up.
93 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
94
95 // Call when right button down.
96 virtual void OnRightClick(int toolIndex, long x, long y);
97
98 // Called when the mouse cursor enters a tool bitmap.
99 // Argument is -1 if mouse is exiting the toolbar.
100 virtual void OnMouseEnter(int toolIndex);
101
102 // If pushedBitmap is NULL, a reversed version of bitmap is
103 // created and used as the pushed/toggled image.
104 // If toggle is TRUE, the button toggles between the two states.
105 virtual wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
106 bool toggle = FALSE, long xPos = -1, long yPos = -1, wxObject *clientData = NULL,
107 const wxString& helpString1 = wxEmptyString, const wxString& helpString2 = wxEmptyString);
108 virtual void AddSeparator(void);
109 virtual void ClearTools(void);
110
111 virtual void EnableTool(int toolIndex, bool enable);
112 virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
113 virtual void SetToggle(int toolIndex, bool toggle); // Set this to be togglable (or not)
114 virtual wxObject *GetToolClientData(int index) const;
115 inline wxList& GetTools(void) const { return (wxList&) m_tools; }
116
117 // After the toolbar has initialized, this is the size the tools take up
118 #if WXWXIN_COMPATIBILITY
119 inline void GetMaxSize ( long * width, long * height ) const
120 { wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
121 #endif
122 virtual wxSize GetMaxSize ( void ) const;
123
124 virtual bool GetToolState(int toolIndex) const;
125 virtual bool GetToolEnabled(int toolIndex) const;
126 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
127
128 virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
129 virtual wxString GetToolShortHelp(int toolIndex) const;
130 virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
131 virtual wxString GetToolLongHelp(int toolIndex) const;
132
133 virtual void SetMargins(int x, int y);
134 inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); }
135 virtual void SetToolPacking(int packing);
136 virtual void SetToolSeparation(int separation);
137
138 inline virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
139 inline virtual int GetToolPacking(void) { return m_toolPacking; }
140 inline virtual int GetToolSeparation(void) { return m_toolSeparation; }
141
142 virtual void SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; };
143 virtual wxSize GetToolBitmapSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); }
144
145 // The button size (in some implementations) is bigger than the bitmap size: this returns
146 // the total button size.
147 virtual wxSize GetToolSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ;
148
149 // Compatibility
150 #if WXWIN_COMPATIBILITY
151 inline void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
152 inline long GetDefaultWidth(void) const { return m_defaultWidth; }
153 inline long GetDefaultHeight(void) const { return m_defaultHeight; }
154 inline int GetDefaultButtonWidth(void) const { return (int) GetDefaultButtonSize().x; };
155 inline int GetDefaultButtonHeight(void) const { return (int) GetDefaultButtonSize().y; };
156 virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
157 virtual wxSize GetDefaultSize(void) const { return GetToolBitmapSize(); }
158 virtual wxSize GetDefaultButtonSize(void) const { return GetToolSize(); }
159 #endif
160
161 // Lay the tools out
162 virtual void LayoutTools();
163
164 // Add all the buttons: required for Win95.
165 virtual bool CreateTools(void) { return TRUE; }
166
167 // Calls the appropriate function after tools have been created.
168 // E.g. Layout, or CreateTools.
169 virtual bool Realize() = 0;
170
171 void Command(wxCommandEvent& event);
172
173 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
174 // inherits from wxControl. This could have been put into wxToolBarSimple,
175 // but we might want any derived toolbar class to be scrollable.
176
177 // Number of pixels per user unit (0 or -1 for no scrollbar)
178 // Length of virtual canvas in user units
179 virtual void SetScrollbars(int horizontal, int vertical,
180 int x_length, int y_length,
181 int x_pos = 0, int y_pos = 0);
182
183 // Physically scroll the window
184 virtual void Scroll(int x_pos, int y_pos);
185 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
186 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
187 virtual void AdjustScrollbars(void);
188
189 // Prepare the DC by translating it according to the current scroll position
190 virtual void PrepareDC(wxDC& dc);
191
192 int GetScrollPageSize(int orient) const ;
193 void SetScrollPageSize(int orient, int pageSize);
194
195 // Get the view start
196 virtual void ViewStart(int *x, int *y) const;
197
198 // Actual size in pixels when scrolling is taken into account
199 virtual void GetVirtualSize(int *x, int *y) const;
200
201 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
202 virtual void DoToolbarUpdates(void);
203
204 inline void SetMaxRowsCols(int rows, int cols) { m_maxRows = rows; m_maxCols = cols; }
205 inline int GetMaxRows() const { return m_maxRows; }
206 inline int GetMaxCols() const { return m_maxCols; }
207
208 void OnScroll(wxScrollEvent& event);
209 void OnSize(wxSizeEvent& event);
210 void OnIdle(wxIdleEvent& event);
211
212 protected:
213 wxList m_tools;
214 // int m_tilingDirection;
215 // int m_rowsOrColumns;
216 int m_maxRows;
217 int m_maxCols;
218 long m_maxWidth, m_maxHeight;
219 int m_currentTool; // Tool where mouse currently is
220 int m_pressedTool; // Tool where mouse pressed
221 int m_xMargin;
222 int m_yMargin;
223 int m_toolPacking;
224 int m_toolSeparation;
225 long m_defaultWidth;
226 long m_defaultHeight;
227
228 public:
229 ////////////////////////////////////////////////////////////////////////
230 //// IMPLEMENTATION
231
232 // Calculate scroll increment
233 virtual int CalcScrollInc(wxScrollEvent& event);
234
235 ////////////////////////////////////////////////////////////////////////
236 //// PROTECTED DATA
237 protected:
238 int m_xScrollPixelsPerLine;
239 int m_yScrollPixelsPerLine;
240 bool m_xScrollingEnabled;
241 bool m_yScrollingEnabled;
242 int m_xScrollPosition;
243 int m_yScrollPosition;
244 bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
245 int m_xScrollLines;
246 int m_yScrollLines;
247 int m_xScrollLinesPerPage;
248 int m_yScrollLinesPerPage;
249
250 public:
251 DECLARE_EVENT_TABLE()
252 };
253
254 #endif
255 // _WX_TBARBASE_H_
256