]>
Commit | Line | Data |
---|---|---|
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(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 = ""); | |
41 | ~wxToolBarTool (); | |
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; } | |
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_ABSTRACT_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(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); | |
93 | ||
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; } | |
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(int toolIndex) const; | |
108 | virtual bool GetToolEnabled(int toolIndex) const; | |
109 | virtual wxToolBarTool *FindToolForPosition(long x, long y) const; | |
110 | ||
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; | |
115 | ||
116 | virtual void SetMargins(int x, int y); | |
117 | inline void SetMargins(const wxSize& size) { SetMargins((int) size.x, (int) size.y); } | |
118 | virtual void SetToolPacking(int packing); | |
119 | virtual void SetToolSeparation(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 SetToolBitmapSize(const wxSize& size) { m_defaultWidth = size.x; m_defaultHeight = size.y; }; | |
126 | virtual wxSize GetToolBitmapSize(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 GetToolSize(void) const { return wxSize(m_defaultWidth, m_defaultHeight); } ; | |
131 | ||
132 | // Compatibility | |
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 (int) GetDefaultButtonSize().x; }; | |
138 | inline int GetDefaultButtonHeight(void) const { return (int) GetDefaultButtonSize().y; }; | |
139 | virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); } | |
140 | virtual wxSize GetDefaultSize(void) const { return GetToolBitmapSize(); } | |
141 | virtual wxSize GetDefaultButtonSize(void) const { return GetToolSize(); } | |
142 | #endif | |
143 | ||
144 | // Lay the tools out | |
145 | virtual void Layout(void); | |
146 | ||
147 | // Add all the buttons: required for Win95. | |
148 | virtual bool CreateTools(void) { return TRUE; } | |
149 | ||
150 | // Calls the appropriate function after tools have been created. | |
151 | // E.g. Layout, or CreateTools. | |
152 | virtual bool Realize() = 0; | |
153 | ||
154 | void Command(wxCommandEvent& event); | |
155 | ||
156 | // SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase | |
157 | // inherits from wxControl. This could have been put into wxToolBarSimple, | |
158 | // but we might want any derived toolbar class to be scrollable. | |
159 | ||
160 | // Number of pixels per user unit (0 or -1 for no scrollbar) | |
161 | // Length of virtual canvas in user units | |
162 | virtual void SetScrollbars(int horizontal, int vertical, | |
163 | int x_length, int y_length, | |
164 | int x_pos = 0, int y_pos = 0); | |
165 | ||
166 | // Physically scroll the window | |
167 | virtual void Scroll(int x_pos, int y_pos); | |
168 | virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const; | |
169 | virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); | |
170 | virtual void AdjustScrollbars(void); | |
171 | ||
172 | // Prepare the DC by translating it according to the current scroll position | |
173 | virtual void PrepareDC(wxDC& dc); | |
174 | ||
175 | int GetScrollPageSize(int orient) const ; | |
176 | void SetScrollPageSize(int orient, int pageSize); | |
177 | ||
178 | // Get the view start | |
179 | virtual void ViewStart(int *x, int *y) const; | |
180 | ||
181 | // Actual size in pixels when scrolling is taken into account | |
182 | virtual void GetVirtualSize(int *x, int *y) const; | |
183 | ||
184 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
185 | virtual void DoToolbarUpdates(void); | |
186 | ||
187 | inline void SetMaxRowsCols(int rows, int cols) { m_maxRows = rows; m_maxCols = cols; } | |
188 | inline int GetMaxRows() const { return m_maxRows; } | |
189 | inline int GetMaxCols() const { return m_maxCols; } | |
190 | ||
191 | void OnScroll(wxScrollEvent& event); | |
192 | void OnSize(wxSizeEvent& event); | |
193 | void OnIdle(wxIdleEvent& event); | |
194 | ||
195 | // Required to force normal cursor-setting behaviour in Windows | |
196 | #ifdef __WXMSW__ | |
197 | virtual void MSWOnMouseMove(int x, int y, WXUINT flags); | |
198 | #endif | |
199 | ||
200 | protected: | |
201 | wxList m_tools; | |
202 | // int m_tilingDirection; | |
203 | // int m_rowsOrColumns; | |
204 | int m_maxRows; | |
205 | int m_maxCols; | |
206 | long m_maxWidth, m_maxHeight; | |
207 | int m_currentTool; // Tool where mouse currently is | |
208 | int m_pressedTool; // Tool where mouse pressed | |
209 | int m_xMargin; | |
210 | int m_yMargin; | |
211 | int m_toolPacking; | |
212 | int m_toolSeparation; | |
213 | long m_defaultWidth; | |
214 | long m_defaultHeight; | |
215 | ||
216 | public: | |
217 | //////////////////////////////////////////////////////////////////////// | |
218 | //// IMPLEMENTATION | |
219 | ||
220 | // Calculate scroll increment | |
221 | virtual int CalcScrollInc(wxScrollEvent& event); | |
222 | ||
223 | //////////////////////////////////////////////////////////////////////// | |
224 | //// PROTECTED DATA | |
225 | protected: | |
226 | int m_xScrollPixelsPerLine; | |
227 | int m_yScrollPixelsPerLine; | |
228 | bool m_xScrollingEnabled; | |
229 | bool m_yScrollingEnabled; | |
230 | int m_xScrollPosition; | |
231 | int m_yScrollPosition; | |
232 | bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets | |
233 | int m_xScrollLines; | |
234 | int m_yScrollLines; | |
235 | int m_xScrollLinesPerPage; | |
236 | int m_yScrollLinesPerPage; | |
237 | ||
238 | public: | |
239 | DECLARE_EVENT_TABLE() | |
240 | }; | |
241 | ||
242 | #endif // USE_TOOLBAR | |
243 | #endif | |
244 | // __TBARBASEH__ | |
245 |