]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
wxCheckListBox fixes: crash/memory leak when items are dynamically
[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
26WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
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 = "",
47 GtkWidget *item = (GtkWidget *) NULL );
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;
78#endif
10b959e3
JS
79};
80
81class WXDLLEXPORT wxToolBarBase : public wxControl
82{
81d66cf3 83 DECLARE_ABSTRACT_CLASS(wxToolBarBase)
10b959e3
JS
84 public:
85
86 wxToolBarBase(void);
87 ~wxToolBarBase(void);
88
89 // Handle wxToolBar events
90
91 // Only allow toggle if returns TRUE. Call when left button up.
92 virtual bool OnLeftClick(int toolIndex, bool toggleDown);
93
94 // Call when right button down.
95 virtual void OnRightClick(int toolIndex, long x, long y);
96
97 // Called when the mouse cursor enters a tool bitmap.
98 // Argument is -1 if mouse is exiting the toolbar.
99 virtual void OnMouseEnter(int toolIndex);
100
101 // If pushedBitmap is NULL, a reversed version of bitmap is
102 // created and used as the pushed/toggled image.
103 // If toggle is TRUE, the button toggles between the two states.
debe6624
JS
104 virtual wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
105 bool toggle = FALSE, long xPos = -1, long yPos = -1, wxObject *clientData = NULL,
62448488 106 const wxString& helpString1 = wxEmptyString, const wxString& helpString2 = wxEmptyString);
10b959e3
JS
107 virtual void AddSeparator(void);
108 virtual void ClearTools(void);
109
debe6624
JS
110 virtual void EnableTool(int toolIndex, bool enable);
111 virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
112 virtual void SetToggle(int toolIndex, bool toggle); // Set this to be togglable (or not)
113 virtual wxObject *GetToolClientData(int index) const;
10b959e3
JS
114 inline wxList& GetTools(void) const { return (wxList&) m_tools; }
115
116 // After the toolbar has initialized, this is the size the tools take up
117#if WXWXIN_COMPATIBILITY
118 inline void GetMaxSize ( long * width, long * height ) const
119 { wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
120#endif
121 virtual wxSize GetMaxSize ( void ) const;
122
debe6624
JS
123 virtual bool GetToolState(int toolIndex) const;
124 virtual bool GetToolEnabled(int toolIndex) const;
125 virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
10b959e3 126
debe6624
JS
127 virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
128 virtual wxString GetToolShortHelp(int toolIndex) const;
129 virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
130 virtual wxString GetToolLongHelp(int toolIndex) const;
10b959e3 131
debe6624 132 virtual void SetMargins(int x, int y);
81d66cf3 133 inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); }
debe6624
JS
134 virtual void SetToolPacking(int packing);
135 virtual void SetToolSeparation(int separation);
10b959e3
JS
136
137 inline virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
138 inline virtual int GetToolPacking(void) { return m_toolPacking; }
139 inline virtual int GetToolSeparation(void) { return m_toolSeparation; }
140
81d66cf3
JS
141 virtual void SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; };
142 virtual wxSize GetToolBitmapSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); }
10b959e3
JS
143
144 // The button size (in some implementations) is bigger than the bitmap size: this returns
145 // the total button size.
81d66cf3 146 virtual wxSize GetToolSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ;
10b959e3
JS
147
148 // Compatibility
149#if WXWIN_COMPATIBILITY
debe6624 150 inline void SetDefaultSize(int w, int h) { SetDefaultSize(wxSize(w, h)); }
10b959e3
JS
151 inline long GetDefaultWidth(void) const { return m_defaultWidth; }
152 inline long GetDefaultHeight(void) const { return m_defaultHeight; }
81d66cf3
JS
153 inline int GetDefaultButtonWidth(void) const { return (int) GetDefaultButtonSize().x; };
154 inline int GetDefaultButtonHeight(void) const { return (int) GetDefaultButtonSize().y; };
155 virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
156 virtual wxSize GetDefaultSize(void) const { return GetToolBitmapSize(); }
157 virtual wxSize GetDefaultButtonSize(void) const { return GetToolSize(); }
10b959e3
JS
158#endif
159
160 // Lay the tools out
161 virtual void Layout(void);
162
163 // Add all the buttons: required for Win95.
10b959e3
JS
164 virtual bool CreateTools(void) { return TRUE; }
165
81d66cf3
JS
166 // Calls the appropriate function after tools have been created.
167 // E.g. Layout, or CreateTools.
168 virtual bool Realize() = 0;
169
10b959e3
JS
170 void Command(wxCommandEvent& event);
171
172 // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
173 // inherits from wxControl. This could have been put into wxToolBarSimple,
174 // but we might want any derived toolbar class to be scrollable.
175
176 // Number of pixels per user unit (0 or -1 for no scrollbar)
177 // Length of virtual canvas in user units
debe6624
JS
178 virtual void SetScrollbars(int horizontal, int vertical,
179 int x_length, int y_length,
180 int x_pos = 0, int y_pos = 0);
10b959e3
JS
181
182 // Physically scroll the window
debe6624 183 virtual void Scroll(int x_pos, int y_pos);
10b959e3 184 virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
debe6624 185 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
10b959e3
JS
186 virtual void AdjustScrollbars(void);
187
188 // Prepare the DC by translating it according to the current scroll position
189 virtual void PrepareDC(wxDC& dc);
190
191 int GetScrollPageSize(int orient) const ;
192 void SetScrollPageSize(int orient, int pageSize);
193
194 // Get the view start
195 virtual void ViewStart(int *x, int *y) const;
196
197 // Actual size in pixels when scrolling is taken into account
198 virtual void GetVirtualSize(int *x, int *y) const;
199
200 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
201 virtual void DoToolbarUpdates(void);
202
81d66cf3
JS
203 inline void SetMaxRowsCols(int rows, int cols) { m_maxRows = rows; m_maxCols = cols; }
204 inline int GetMaxRows() const { return m_maxRows; }
205 inline int GetMaxCols() const { return m_maxCols; }
10b959e3
JS
206
207 void OnScroll(wxScrollEvent& event);
208 void OnSize(wxSizeEvent& event);
209 void OnIdle(wxIdleEvent& event);
210
211 // Required to force normal cursor-setting behaviour in Windows
2049ba38 212#ifdef __WXMSW__
4d0c0756 213 virtual void MSWOnMouseMove(int x, int y, WXUINT flags);
10b959e3
JS
214#endif
215
216 protected:
217 wxList m_tools;
81d66cf3
JS
218// int m_tilingDirection;
219// int m_rowsOrColumns;
220 int m_maxRows;
221 int m_maxCols;
10b959e3
JS
222 long m_maxWidth, m_maxHeight;
223 int m_currentTool; // Tool where mouse currently is
224 int m_pressedTool; // Tool where mouse pressed
225 int m_xMargin;
226 int m_yMargin;
227 int m_toolPacking;
228 int m_toolSeparation;
229 long m_defaultWidth;
230 long m_defaultHeight;
231
232public:
233 ////////////////////////////////////////////////////////////////////////
234 //// IMPLEMENTATION
235
236 // Calculate scroll increment
237 virtual int CalcScrollInc(wxScrollEvent& event);
238
239 ////////////////////////////////////////////////////////////////////////
240 //// PROTECTED DATA
241protected:
242 int m_xScrollPixelsPerLine;
243 int m_yScrollPixelsPerLine;
244 bool m_xScrollingEnabled;
245 bool m_yScrollingEnabled;
246 int m_xScrollPosition;
247 int m_yScrollPosition;
248 bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
249 int m_xScrollLines;
250 int m_yScrollLines;
251 int m_xScrollLinesPerPage;
252 int m_yScrollLinesPerPage;
253
254public:
255 DECLARE_EVENT_TABLE()
256};
257
10b959e3 258#endif
34138703 259 // _WX_TBARBASE_H_
10b959e3 260