]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
Restored wxSizeEvent code form last week -> wxGLCanvas
[wxWidgets.git] / include / wx / tbarbase.h
CommitLineData
10b959e3
JS
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
34138703
JS
12#ifndef _WX_TBARBASE_H_
13#define _WX_TBARBASE_H_
10b959e3
JS
14
15#ifdef __GNUG__
16#pragma interface "tbarbase.h"
17#endif
18
34138703 19#include "wx/setup.h"
10b959e3
JS
20#include "wx/defs.h"
21
10b959e3
JS
22#include "wx/bitmap.h"
23#include "wx/list.h"
24#include "wx/control.h"
25
f39f9220 26WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
10b959e3
JS
27WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
28WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
29
30#define wxTOOL_STYLE_BUTTON 1
31#define wxTOOL_STYLE_SEPARATOR 2
32
4fcd73bd
RR
33#ifdef __WXGTK__
34class WXDLLEXPORT wxToolBar;
35#endif
36
10b959e3
JS
37class WXDLLEXPORT wxToolBarTool: public wxObject
38{
39 DECLARE_DYNAMIC_CLASS(wxToolBarTool)
40 public:
4fcd73bd
RR
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 = "",
85eb36c2 47 GtkWidget *pixmap = (GtkWidget *) NULL );
4fcd73bd 48#else
dbdb39b2 49 wxToolBarTool(int theIndex, const wxBitmap& bitmap1 = wxNullBitmap, const wxBitmap& bitmap2 = wxNullBitmap,
debe6624 50 bool toggle = FALSE, long xPos = -1, long yPos = -1,
62448488 51 const wxString& shortHelpString = wxEmptyString, const wxString& longHelpString = wxEmptyString);
4fcd73bd 52#endif
10b959e3 53 ~wxToolBarTool ();
debe6624 54 inline void SetSize( long w, long h ) { m_width = w; m_height = h; }
10b959e3
JS
55 inline long GetWidth () const { return m_width; }
56 inline long GetHeight () const { return m_height; }
57
58public:
59 int m_toolStyle;
60 wxObject * m_clientData;
61 int m_index;
81d66cf3
JS
62 long m_x;
63 long m_y;
64 long m_width;
65 long m_height;
10b959e3
JS
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;
4fcd73bd
RR
75#ifdef __WXGTK__
76 wxToolBar *m_owner;
77 GtkWidget *m_item;
85eb36c2 78 GtkWidget *m_pixmap;
4fcd73bd 79#endif
10b959e3
JS
80};
81
82class WXDLLEXPORT wxToolBarBase : public wxControl
83{
81d66cf3 84 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
10b959e3
JS
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.
debe6624
JS
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,
62448488 107 const wxString& helpString1 = wxEmptyString, const wxString& helpString2 = wxEmptyString);
10b959e3
JS
108 virtual void AddSeparator(void);
109 virtual void ClearTools(void);
110
debe6624
JS
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;
10b959e3
JS
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
debe6624
JS
124 virtual bool GetToolState(int toolIndex) const;
125 virtual bool GetToolEnabled(int toolIndex) const;
126 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
10b959e3 127
debe6624
JS
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;
10b959e3 132
debe6624 133 virtual void SetMargins(int x, int y);
81d66cf3 134 inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); }
debe6624
JS
135 virtual void SetToolPacking(int packing);
136 virtual void SetToolSeparation(int separation);
10b959e3
JS
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
81d66cf3
JS
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); }
10b959e3
JS
144
145 // The button size (in some implementations) is bigger than the bitmap size: this returns
146 // the total button size.
81d66cf3 147 virtual wxSize GetToolSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ;
10b959e3
JS
148
149 // Compatibility
150#if WXWIN_COMPATIBILITY
debe6624 151 inline void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
10b959e3
JS
152 inline long GetDefaultWidth(void) const { return m_defaultWidth; }
153 inline long GetDefaultHeight(void) const { return m_defaultHeight; }
81d66cf3
JS
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(); }
10b959e3
JS
159#endif
160
161 // Lay the tools out
f03fc89f 162 virtual void LayoutTools();
10b959e3
JS
163
164 // Add all the buttons: required for Win95.
10b959e3
JS
165 virtual bool CreateTools(void) { return TRUE; }
166
81d66cf3
JS
167 // Calls the appropriate function after tools have been created.
168 // E.g. Layout, or CreateTools.
169 virtual bool Realize() = 0;
170
10b959e3
JS
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
debe6624
JS
179 virtual void SetScrollbars(int horizontal, int vertical,
180 int x_length, int y_length,
181 int x_pos = 0, int y_pos = 0);
10b959e3
JS
182
183 // Physically scroll the window
debe6624 184 virtual void Scroll(int x_pos, int y_pos);
10b959e3 185 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
debe6624 186 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
10b959e3
JS
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
81d66cf3
JS
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; }
10b959e3
JS
207
208 void OnScroll(wxScrollEvent& event);
209 void OnSize(wxSizeEvent& event);
210 void OnIdle(wxIdleEvent& event);
211
10b959e3
JS
212 protected:
213 wxList m_tools;
81d66cf3
JS
214// int m_tilingDirection;
215// int m_rowsOrColumns;
216 int m_maxRows;
217 int m_maxCols;
10b959e3
JS
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
228public:
229 ////////////////////////////////////////////////////////////////////////
230 //// IMPLEMENTATION
231
232 // Calculate scroll increment
233 virtual int CalcScrollInc(wxScrollEvent& event);
234
235 ////////////////////////////////////////////////////////////////////////
236 //// PROTECTED DATA
237protected:
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
250public:
251 DECLARE_EVENT_TABLE()
252};
253
10b959e3 254#endif
34138703 255 // _WX_TBARBASE_H_
10b959e3 256