]>
Commit | Line | Data |
---|---|---|
10b959e3 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbarbase.cpp | |
3 | // Purpose: Toolbar base classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
1c383dba | 9 | // Licence: wxWindows license |
10b959e3 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tbarbase.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
e702ff0f JS |
27 | #include "wx/frame.h" |
28 | ||
10b959e3 | 29 | // For ::UpdateWindow |
2049ba38 | 30 | #ifdef __WXMSW__ |
10b959e3 JS |
31 | #include <windows.h> |
32 | #endif | |
33 | ||
47d67540 | 34 | #if wxUSE_TOOLBAR |
10b959e3 JS |
35 | |
36 | #include "wx/tbarbase.h" | |
37 | ||
38 | #if !USE_SHARED_LIBRARY | |
81d66cf3 | 39 | IMPLEMENT_ABSTRACT_CLASS(wxToolBarBase, wxControl) |
10b959e3 JS |
40 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool, wxObject) |
41 | ||
42 | BEGIN_EVENT_TABLE(wxToolBarBase, wxControl) | |
43 | EVT_SCROLL(wxToolBarBase::OnScroll) | |
44 | EVT_SIZE(wxToolBarBase::OnSize) | |
45 | EVT_IDLE(wxToolBarBase::OnIdle) | |
46 | END_EVENT_TABLE() | |
47 | #endif | |
48 | ||
49 | // Keep a list of all toolbars created, so you can tell whether a toolbar | |
50 | // is still valid: a tool may have quit the toolbar. | |
51 | static wxList gs_ToolBars; | |
52 | ||
4fcd73bd RR |
53 | #ifdef __WXGTK__ |
54 | wxToolBarTool::wxToolBarTool(wxToolBar *owner, int theIndex, | |
ac91b9d2 VZ |
55 | const wxBitmap& theBitmap1, const wxBitmap& theBitmap2, |
56 | bool toggle, wxObject *clientData, | |
57 | const wxString& helpS1, const wxString& helpS2, | |
85eb36c2 | 58 | GtkWidget *pixmap ) |
4fcd73bd | 59 | #else |
debe6624 JS |
60 | wxToolBarTool::wxToolBarTool(int theIndex, |
61 | const wxBitmap& theBitmap1, const wxBitmap& theBitmap2, bool toggle, | |
62 | long xPos, long yPos, const wxString& helpS1, const wxString& helpS2) | |
4fcd73bd | 63 | #endif |
10b959e3 JS |
64 | { |
65 | m_toolStyle = wxTOOL_STYLE_BUTTON; | |
4fcd73bd RR |
66 | #ifdef __WXGTK__ |
67 | m_owner = owner; | |
85eb36c2 RR |
68 | m_pixmap = pixmap; |
69 | m_item = (GtkWidget*) NULL; | |
4fcd73bd RR |
70 | m_clientData = clientData; |
71 | m_x = 0; | |
72 | m_y = 0; | |
73 | #else | |
10b959e3 | 74 | m_clientData = NULL; |
4fcd73bd RR |
75 | m_x = xPos; |
76 | m_y = yPos; | |
77 | #endif | |
10b959e3 JS |
78 | m_index = theIndex; |
79 | m_isToggle = toggle; | |
80 | m_toggleState = FALSE; | |
81 | m_enabled = TRUE; | |
82 | m_bitmap1 = theBitmap1; | |
83 | m_bitmap2 = theBitmap2; | |
10b959e3 JS |
84 | m_width = m_height = 0; |
85 | m_deleteSecondBitmap = FALSE; | |
86 | if (m_bitmap1.Ok()) | |
87 | { | |
88 | m_width = m_bitmap1.GetWidth()+2; | |
89 | m_height = m_bitmap1.GetHeight()+2; | |
90 | } | |
91 | m_shortHelpString = helpS1; | |
92 | m_longHelpString = helpS2; | |
97d7bfb8 | 93 | m_control = (wxControl*) NULL; |
10b959e3 JS |
94 | } |
95 | ||
2ccf68ce | 96 | wxToolBarTool::wxToolBarTool(wxControl *control) |
1c383dba VZ |
97 | { |
98 | m_toolStyle = wxTOOL_STYLE_CONTROL; | |
99 | m_control = control; | |
c8f1f088 | 100 | m_index = control->GetId(); |
1c383dba VZ |
101 | } |
102 | ||
ac91b9d2 | 103 | wxToolBarTool::~wxToolBarTool() |
10b959e3 JS |
104 | { |
105 | /* | |
106 | if (m_deleteSecondBitmap && m_bitmap2) | |
107 | delete m_bitmap2; | |
108 | */ | |
109 | } | |
110 | ||
111 | ||
112 | // class wxToolBar | |
113 | ||
114 | wxToolBarBase::wxToolBarBase(void) : m_tools(wxKEY_INTEGER) | |
115 | { | |
116 | gs_ToolBars.Append(this); | |
117 | ||
81d66cf3 JS |
118 | m_maxRows = 1; |
119 | m_maxCols = 32000; | |
10b959e3 JS |
120 | m_maxWidth = 0; |
121 | m_maxHeight = 0; | |
122 | m_defaultWidth = 16; | |
123 | m_defaultHeight = 15; | |
124 | m_xMargin = 0; | |
125 | m_yMargin = 0; | |
126 | m_toolPacking = 1; | |
127 | m_toolSeparation = 5; | |
128 | m_currentTool = -1; | |
129 | ||
130 | m_xScrollPixelsPerLine = 0; | |
131 | m_yScrollPixelsPerLine = 0; | |
132 | m_xScrollingEnabled = TRUE; | |
133 | m_yScrollingEnabled = TRUE; | |
134 | m_xScrollPosition = 0; | |
135 | m_yScrollPosition = 0; | |
136 | m_calcScrolledOffset = TRUE; | |
137 | m_xScrollLines = 0; | |
138 | m_yScrollLines = 0; | |
139 | m_xScrollLinesPerPage = 0; | |
140 | m_yScrollLinesPerPage = 0; | |
141 | } | |
142 | ||
143 | wxToolBarBase::~wxToolBarBase () | |
144 | { | |
145 | gs_ToolBars.DeleteObject(this); | |
146 | ||
147 | for ( wxNode *node = m_tools.First(); node; node = node->Next() ) | |
148 | { | |
149 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
150 | delete tool; | |
151 | } | |
152 | } | |
153 | ||
154 | // Only allow toggle if returns TRUE | |
155 | bool wxToolBarBase::OnLeftClick(int toolIndex, bool toggleDown) | |
156 | { | |
157 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, toolIndex); | |
158 | event.SetEventObject(this); | |
159 | event.SetExtraLong((long) toggleDown); | |
160 | ||
e702ff0f | 161 | // Send events to this toolbar instead (and thence up the window hierarchy) |
10b959e3 JS |
162 | GetEventHandler()->ProcessEvent(event); |
163 | ||
164 | return TRUE; | |
165 | } | |
166 | ||
167 | // Call when right button down. | |
ac91b9d2 VZ |
168 | void wxToolBarBase::OnRightClick(int toolIndex, |
169 | long WXUNUSED(x), | |
170 | long WXUNUSED(y)) | |
10b959e3 JS |
171 | { |
172 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, toolIndex); | |
173 | event.SetEventObject(this); | |
0f217db3 | 174 | event.SetInt(toolIndex); |
10b959e3 JS |
175 | |
176 | GetEventHandler()->ProcessEvent(event); | |
177 | } | |
178 | ||
179 | // Called when the mouse cursor enters a tool bitmap (no button pressed). | |
180 | // Argument is -1 if mouse is exiting the toolbar. | |
81d66cf3 JS |
181 | // Note that for this event, the id of the window is used, |
182 | // and the integer parameter of wxCommandEvent is used to retrieve | |
183 | // the tool id. | |
10b959e3 JS |
184 | void wxToolBarBase::OnMouseEnter ( int toolIndex ) |
185 | { | |
81d66cf3 | 186 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); |
10b959e3 | 187 | event.SetEventObject(this); |
0f217db3 | 188 | event.SetInt(toolIndex); |
10b959e3 JS |
189 | |
190 | GetEventHandler()->ProcessEvent(event); | |
191 | } | |
192 | ||
193 | // If pushedBitmap is NULL, a reversed version of bitmap is | |
194 | // created and used as the pushed/toggled image. | |
195 | // If toggle is TRUE, the button toggles between the two states. | |
debe6624 | 196 | wxToolBarTool *wxToolBarBase::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap, |
1c383dba | 197 | bool toggle, wxCoord xPos, wxCoord yPos, wxObject *clientData, |
10b959e3 JS |
198 | const wxString& helpString1, const wxString& helpString2) |
199 | { | |
4fcd73bd | 200 | #ifdef __WXGTK__ |
ac91b9d2 | 201 | wxToolBarTool *tool = new wxToolBarTool( (wxToolBar*)this, index, bitmap, pushedBitmap, toggle, |
4fcd73bd RR |
202 | (wxObject*) NULL, helpString1, helpString2); |
203 | #else | |
10b959e3 | 204 | wxToolBarTool *tool = new wxToolBarTool(index, bitmap, pushedBitmap, toggle, xPos, yPos, helpString1, helpString2); |
4fcd73bd | 205 | #endif |
10b959e3 JS |
206 | tool->m_clientData = clientData; |
207 | ||
208 | if (xPos > -1) | |
209 | tool->m_x = xPos; | |
210 | else | |
211 | tool->m_x = m_xMargin; | |
212 | ||
213 | if (yPos > -1) | |
214 | tool->m_y = yPos; | |
215 | else | |
216 | tool->m_y = m_yMargin; | |
ac91b9d2 | 217 | |
10b959e3 JS |
218 | // Calculate reasonable max size in case Layout() not called |
219 | if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) | |
220 | m_maxWidth = (tool->m_x + bitmap.GetWidth() + m_xMargin); | |
221 | ||
222 | if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) | |
223 | m_maxHeight = (tool->m_y + bitmap.GetHeight() + m_yMargin); | |
224 | ||
225 | m_tools.Append((long)index, tool); | |
226 | return tool; | |
227 | } | |
228 | ||
229 | void wxToolBarBase::AddSeparator () | |
230 | { | |
231 | wxToolBarTool *tool = new wxToolBarTool; | |
35719632 | 232 | tool->m_index = -1; |
10b959e3 | 233 | tool->m_toolStyle = wxTOOL_STYLE_SEPARATOR; |
fd3f686c | 234 | m_tools.Append(-1, tool); |
10b959e3 JS |
235 | } |
236 | ||
ac91b9d2 | 237 | void wxToolBarBase::ClearTools() |
10b959e3 JS |
238 | { |
239 | m_pressedTool = m_currentTool = -1; | |
240 | wxNode *node = m_tools.First(); | |
241 | while (node) | |
242 | { | |
243 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
244 | wxNode *nextNode = node->Next(); | |
245 | delete tool; | |
246 | delete node; | |
247 | node = nextNode; | |
248 | } | |
249 | } | |
250 | ||
debe6624 | 251 | void wxToolBarBase::EnableTool(int index, bool enable) |
10b959e3 JS |
252 | { |
253 | wxNode *node = m_tools.Find((long)index); | |
254 | if (node) | |
255 | { | |
256 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
257 | if (tool) | |
258 | tool->m_enabled = enable; | |
259 | } | |
260 | } | |
261 | ||
ac91b9d2 VZ |
262 | void wxToolBarBase::ToggleTool(int WXUNUSED(index), |
263 | bool WXUNUSED(toggle)) | |
10b959e3 JS |
264 | { |
265 | } | |
266 | ||
debe6624 | 267 | void wxToolBarBase::SetToggle(int index, bool value) |
10b959e3 JS |
268 | { |
269 | wxNode *node=m_tools.Find((long)index); | |
270 | if (node){ | |
271 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
272 | tool->m_isToggle = value; | |
273 | } | |
274 | } | |
275 | ||
debe6624 | 276 | bool wxToolBarBase::GetToolState(int index) const |
10b959e3 JS |
277 | { |
278 | wxNode *node = m_tools.Find((long)index); | |
279 | if (node) | |
280 | { | |
281 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
282 | if (tool) | |
283 | { | |
284 | return tool->m_toggleState; | |
285 | } | |
286 | else return FALSE; | |
287 | } | |
288 | else return FALSE; | |
289 | } | |
290 | ||
debe6624 | 291 | bool wxToolBarBase::GetToolEnabled(int index) const |
10b959e3 JS |
292 | { |
293 | wxNode *node = m_tools.Find((long)index); | |
294 | if (node) | |
295 | { | |
296 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
297 | if (tool) | |
298 | { | |
299 | return tool->m_enabled; | |
300 | } | |
301 | else return FALSE; | |
302 | } | |
303 | else return FALSE; | |
304 | } | |
305 | ||
debe6624 | 306 | wxObject *wxToolBarBase::GetToolClientData(int index) const |
10b959e3 JS |
307 | { |
308 | wxNode *node = m_tools.Find((long)index); | |
309 | if (node) | |
310 | { | |
311 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
312 | if (tool) | |
313 | { | |
314 | return tool->m_clientData; | |
315 | } | |
316 | else return NULL; | |
317 | } | |
318 | else return NULL; | |
319 | } | |
320 | ||
debe6624 | 321 | void wxToolBarBase::SetToolShortHelp(int index, const wxString& helpString) |
10b959e3 JS |
322 | { |
323 | wxNode *node=m_tools.Find((long)index); | |
324 | if (node) | |
325 | { | |
326 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
327 | tool->m_shortHelpString = helpString; | |
328 | } | |
329 | } | |
330 | ||
debe6624 | 331 | wxString wxToolBarBase::GetToolShortHelp(int index) const |
10b959e3 JS |
332 | { |
333 | wxNode *node=m_tools.Find((long)index); | |
334 | if (node) | |
335 | { | |
336 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
337 | return tool->m_shortHelpString; | |
338 | } | |
339 | else | |
340 | return wxString(""); | |
341 | } | |
342 | ||
debe6624 | 343 | void wxToolBarBase::SetToolLongHelp(int index, const wxString& helpString) |
10b959e3 JS |
344 | { |
345 | wxNode *node=m_tools.Find((long)index); | |
346 | if (node) | |
347 | { | |
348 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
349 | tool->m_longHelpString = helpString; | |
350 | } | |
351 | } | |
352 | ||
debe6624 | 353 | wxString wxToolBarBase::GetToolLongHelp(int index) const |
10b959e3 JS |
354 | { |
355 | wxNode *node=m_tools.Find((long)index); | |
356 | if (node) | |
357 | { | |
358 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
359 | return tool->m_longHelpString; | |
360 | } | |
361 | else | |
362 | return wxString(""); | |
363 | } | |
364 | ||
debe6624 | 365 | wxToolBarTool *wxToolBarBase::FindToolForPosition(long x, long y) const |
10b959e3 JS |
366 | { |
367 | wxNode *node = m_tools.First(); | |
368 | while (node) | |
369 | { | |
370 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
371 | if ((x >= tool->m_x) && (y >= tool->m_y) && | |
372 | (x <= (tool->m_x + tool->GetWidth())) && | |
373 | (y <= (tool->m_y + tool->GetHeight()))) | |
374 | return tool; | |
375 | ||
376 | node = node->Next(); | |
377 | } | |
378 | return NULL; | |
379 | } | |
380 | ||
381 | wxSize wxToolBarBase::GetMaxSize ( void ) const | |
382 | { | |
383 | return wxSize(m_maxWidth, m_maxHeight); | |
384 | } | |
385 | ||
386 | // Okay, so we've left the tool we're in ... we must check if | |
387 | // the tool we're leaving was a 'sprung push button' and if so, | |
388 | // spring it back to the up state. | |
389 | // | |
debe6624 | 390 | void wxToolBarBase::SetMargins(int x, int y) |
10b959e3 JS |
391 | { |
392 | m_xMargin = x; | |
393 | m_yMargin = y; | |
394 | } | |
395 | ||
debe6624 | 396 | void wxToolBarBase::SetToolPacking(int packing) |
10b959e3 JS |
397 | { |
398 | m_toolPacking = packing; | |
399 | } | |
400 | ||
debe6624 | 401 | void wxToolBarBase::SetToolSeparation(int separation) |
10b959e3 JS |
402 | { |
403 | m_toolSeparation = separation; | |
404 | } | |
405 | ||
ac91b9d2 | 406 | void wxToolBarBase::Command(wxCommandEvent& WXUNUSED(event)) |
10b959e3 JS |
407 | { |
408 | } | |
409 | ||
f03fc89f | 410 | void wxToolBarBase::LayoutTools() |
10b959e3 | 411 | { |
10b959e3 JS |
412 | } |
413 | ||
414 | ||
415 | // SCROLLING IMPLEMENTATION | |
416 | ||
417 | /* | |
418 | * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line) | |
419 | * noUnitsX/noUnitsY: : no. units per scrollbar | |
420 | */ | |
debe6624 | 421 | void wxToolBarBase::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, |
ac91b9d2 VZ |
422 | int noUnitsX, int noUnitsY, |
423 | int xPos, int yPos) | |
10b959e3 JS |
424 | { |
425 | m_xScrollPixelsPerLine = pixelsPerUnitX; | |
426 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
427 | m_xScrollLines = noUnitsX; | |
428 | m_yScrollLines = noUnitsY; | |
429 | ||
430 | int w, h; | |
431 | GetSize(&w, &h); | |
432 | ||
433 | // Recalculate scroll bar range and position | |
434 | if (m_xScrollLines > 0) | |
ac91b9d2 VZ |
435 | { |
436 | m_xScrollPosition = xPos; | |
437 | SetScrollPos (wxHORIZONTAL, m_xScrollPosition, TRUE); | |
438 | } | |
10b959e3 JS |
439 | else |
440 | { | |
ac91b9d2 | 441 | SetScrollbar(wxHORIZONTAL, 0, 0, 0, FALSE); |
10b959e3 JS |
442 | m_xScrollPosition = 0; |
443 | } | |
444 | ||
445 | if (m_yScrollLines > 0) | |
ac91b9d2 VZ |
446 | { |
447 | m_yScrollPosition = yPos; | |
448 | SetScrollPos (wxVERTICAL, m_yScrollPosition, TRUE); | |
449 | } | |
10b959e3 JS |
450 | else |
451 | { | |
ac91b9d2 | 452 | SetScrollbar(wxVERTICAL, 0, 0, 0, FALSE); |
10b959e3 JS |
453 | m_yScrollPosition = 0; |
454 | } | |
ac91b9d2 | 455 | AdjustScrollbars(); |
10b959e3 | 456 | Refresh(); |
2049ba38 | 457 | #ifdef __WXMSW__ |
10b959e3 JS |
458 | ::UpdateWindow ((HWND) GetHWND()); |
459 | #endif | |
460 | } | |
461 | ||
462 | ||
463 | void wxToolBarBase::OnScroll(wxScrollEvent& event) | |
464 | { | |
465 | int orient = event.GetOrientation(); | |
466 | ||
467 | int nScrollInc = CalcScrollInc(event); | |
468 | if (nScrollInc == 0) | |
469 | return; | |
470 | ||
471 | if (orient == wxHORIZONTAL) | |
472 | { | |
473 | int newPos = m_xScrollPosition + nScrollInc; | |
474 | SetScrollPos(wxHORIZONTAL, newPos, TRUE ); | |
475 | } | |
476 | else | |
477 | { | |
478 | int newPos = m_yScrollPosition + nScrollInc; | |
479 | SetScrollPos(wxVERTICAL, newPos, TRUE ); | |
480 | } | |
481 | ||
482 | if (orient == wxHORIZONTAL) | |
483 | { | |
484 | if (m_xScrollingEnabled) | |
485 | ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL); | |
486 | else | |
487 | Refresh(); | |
488 | } | |
489 | else | |
490 | { | |
491 | if (m_yScrollingEnabled) | |
492 | ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL); | |
493 | else | |
494 | Refresh(); | |
495 | } | |
496 | ||
497 | if (orient == wxHORIZONTAL) | |
498 | { | |
499 | m_xScrollPosition += nScrollInc; | |
500 | } | |
501 | else | |
502 | { | |
503 | m_yScrollPosition += nScrollInc; | |
504 | } | |
505 | ||
506 | } | |
507 | ||
508 | int wxToolBarBase::CalcScrollInc(wxScrollEvent& event) | |
509 | { | |
510 | int pos = event.GetPosition(); | |
511 | int orient = event.GetOrientation(); | |
512 | ||
513 | int nScrollInc = 0; | |
514 | switch (event.GetEventType()) | |
515 | { | |
0757d27c | 516 | case wxEVT_SCROLL_TOP: |
10b959e3 JS |
517 | { |
518 | if (orient == wxHORIZONTAL) | |
519 | nScrollInc = - m_xScrollPosition; | |
520 | else | |
521 | nScrollInc = - m_yScrollPosition; | |
522 | break; | |
523 | } | |
0757d27c | 524 | case wxEVT_SCROLL_BOTTOM: |
10b959e3 JS |
525 | { |
526 | if (orient == wxHORIZONTAL) | |
527 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
528 | else | |
529 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
530 | break; | |
531 | } | |
0757d27c | 532 | case wxEVT_SCROLL_LINEUP: |
10b959e3 JS |
533 | { |
534 | nScrollInc = -1; | |
535 | break; | |
536 | } | |
0757d27c | 537 | case wxEVT_SCROLL_LINEDOWN: |
10b959e3 JS |
538 | { |
539 | nScrollInc = 1; | |
540 | break; | |
541 | } | |
0757d27c | 542 | case wxEVT_SCROLL_PAGEUP: |
10b959e3 JS |
543 | { |
544 | if (orient == wxHORIZONTAL) | |
545 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
546 | else | |
547 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
548 | break; | |
549 | } | |
0757d27c | 550 | case wxEVT_SCROLL_PAGEDOWN: |
10b959e3 JS |
551 | { |
552 | if (orient == wxHORIZONTAL) | |
553 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
554 | else | |
555 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
556 | break; | |
557 | } | |
0757d27c | 558 | case wxEVT_SCROLL_THUMBTRACK: |
10b959e3 JS |
559 | { |
560 | if (orient == wxHORIZONTAL) | |
561 | nScrollInc = pos - m_xScrollPosition; | |
562 | else | |
563 | nScrollInc = pos - m_yScrollPosition; | |
564 | break; | |
565 | } | |
566 | default: | |
567 | { | |
568 | break; | |
569 | } | |
570 | } | |
571 | if (orient == wxHORIZONTAL) | |
572 | { | |
573 | int w, h; | |
ac91b9d2 | 574 | GetClientSize(&w, &h); |
10b959e3 | 575 | |
ac91b9d2 VZ |
576 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; |
577 | int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 ); | |
578 | if (noPositions < 0) | |
579 | noPositions = 0; | |
10b959e3 | 580 | |
ac91b9d2 VZ |
581 | if ( (m_xScrollPosition + nScrollInc) < 0 ) |
582 | nScrollInc = -m_xScrollPosition; // As -ve as we can go | |
583 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) | |
584 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go | |
10b959e3 JS |
585 | |
586 | return nScrollInc; | |
587 | } | |
588 | else | |
589 | { | |
590 | int w, h; | |
ac91b9d2 | 591 | GetClientSize(&w, &h); |
10b959e3 | 592 | |
ac91b9d2 VZ |
593 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; |
594 | int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 ); | |
595 | if (noPositions < 0) | |
596 | noPositions = 0; | |
10b959e3 | 597 | |
ac91b9d2 VZ |
598 | if ( (m_yScrollPosition + nScrollInc) < 0 ) |
599 | nScrollInc = -m_yScrollPosition; // As -ve as we can go | |
600 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) | |
601 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go | |
10b959e3 JS |
602 | |
603 | return nScrollInc; | |
604 | } | |
605 | } | |
606 | ||
607 | // Adjust the scrollbars - new version. | |
ac91b9d2 | 608 | void wxToolBarBase::AdjustScrollbars() |
10b959e3 JS |
609 | { |
610 | int w, h; | |
611 | GetClientSize(&w, &h); | |
612 | ||
613 | // Recalculate scroll bar range and position | |
614 | if (m_xScrollLines > 0) | |
615 | { | |
616 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
617 | int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 ); | |
618 | if (newRange < 0) | |
619 | newRange = 0; | |
620 | ||
621 | m_xScrollPosition = wxMin(newRange, m_xScrollPosition); | |
622 | ||
ac91b9d2 VZ |
623 | // Calculate page size i.e. number of scroll units you get on the |
624 | // current client window | |
10b959e3 JS |
625 | int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 ); |
626 | if (noPagePositions < 1) | |
627 | noPagePositions = 1; | |
628 | ||
629 | SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange); | |
630 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
631 | } | |
632 | if (m_yScrollLines > 0) | |
633 | { | |
634 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; | |
635 | int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 ); | |
636 | if (newRange < 0) | |
637 | newRange = 0; | |
638 | ||
639 | m_yScrollPosition = wxMin(newRange, m_yScrollPosition); | |
640 | ||
ac91b9d2 VZ |
641 | // Calculate page size i.e. number of scroll units you get on the |
642 | // current client window | |
10b959e3 JS |
643 | int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 ); |
644 | if (noPagePositions < 1) | |
645 | noPagePositions = 1; | |
646 | ||
647 | SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange); | |
648 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
649 | } | |
650 | } | |
651 | ||
652 | // Default OnSize resets scrollbars, if any | |
ac91b9d2 | 653 | void wxToolBarBase::OnSize(wxSizeEvent& WXUNUSED(event)) |
10b959e3 | 654 | { |
47d67540 | 655 | #if wxUSE_CONSTRAINTS |
10b959e3 JS |
656 | if (GetAutoLayout()) |
657 | Layout(); | |
658 | #endif | |
659 | ||
660 | AdjustScrollbars(); | |
661 | } | |
662 | ||
663 | // Prepare the DC by translating it according to the current scroll position | |
664 | void wxToolBarBase::PrepareDC(wxDC& dc) | |
665 | { | |
ac91b9d2 | 666 | dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine); |
10b959e3 JS |
667 | } |
668 | ||
669 | void wxToolBarBase::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const | |
670 | { | |
671 | *x_unit = m_xScrollPixelsPerLine; | |
672 | *y_unit = m_yScrollPixelsPerLine; | |
673 | } | |
674 | ||
675 | int wxToolBarBase::GetScrollPageSize(int orient) const | |
676 | { | |
677 | if ( orient == wxHORIZONTAL ) | |
678 | return m_xScrollLinesPerPage; | |
679 | else | |
680 | return m_yScrollLinesPerPage; | |
681 | } | |
682 | ||
683 | void wxToolBarBase::SetScrollPageSize(int orient, int pageSize) | |
684 | { | |
685 | if ( orient == wxHORIZONTAL ) | |
686 | m_xScrollLinesPerPage = pageSize; | |
687 | else | |
688 | m_yScrollLinesPerPage = pageSize; | |
689 | } | |
690 | ||
691 | /* | |
692 | * Scroll to given position (scroll position, not pixel position) | |
693 | */ | |
debe6624 | 694 | void wxToolBarBase::Scroll (int x_pos, int y_pos) |
10b959e3 JS |
695 | { |
696 | int old_x, old_y; | |
697 | ViewStart (&old_x, &old_y); | |
698 | if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y))) | |
699 | return; | |
700 | ||
701 | if (x_pos > -1) | |
702 | { | |
703 | m_xScrollPosition = x_pos; | |
704 | SetScrollPos (wxHORIZONTAL, x_pos, TRUE); | |
705 | } | |
706 | if (y_pos > -1) | |
707 | { | |
708 | m_yScrollPosition = y_pos; | |
709 | SetScrollPos (wxVERTICAL, y_pos, TRUE); | |
710 | } | |
711 | Refresh(); | |
2049ba38 | 712 | #ifdef __WXMSW__ |
10b959e3 JS |
713 | UpdateWindow ((HWND) GetHWND()); |
714 | #endif | |
715 | } | |
716 | ||
debe6624 | 717 | void wxToolBarBase::EnableScrolling (bool x_scroll, bool y_scroll) |
10b959e3 JS |
718 | { |
719 | m_xScrollingEnabled = x_scroll; | |
720 | m_yScrollingEnabled = y_scroll; | |
721 | } | |
722 | ||
723 | void wxToolBarBase::GetVirtualSize (int *x, int *y) const | |
724 | { | |
725 | *x = m_xScrollPixelsPerLine * m_xScrollLines; | |
726 | *y = m_yScrollPixelsPerLine * m_yScrollLines; | |
727 | } | |
728 | ||
729 | // Where the current view starts from | |
730 | void wxToolBarBase::ViewStart (int *x, int *y) const | |
731 | { | |
732 | *x = m_xScrollPosition; | |
733 | *y = m_yScrollPosition; | |
734 | } | |
735 | ||
74e3313b VZ |
736 | void wxToolBarBase::OnIdle(wxIdleEvent& |
737 | #ifdef __WXGTK__ | |
738 | WXUNUSED(event) | |
739 | #else | |
740 | event | |
741 | #endif | |
742 | ) | |
10b959e3 | 743 | { |
4fcd73bd | 744 | #ifndef __WXGTK__ |
43d811ea | 745 | wxWindow::OnIdle(event); |
4fcd73bd | 746 | #endif |
43d811ea | 747 | |
ac91b9d2 | 748 | DoToolbarUpdates(); |
10b959e3 JS |
749 | } |
750 | ||
751 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
ac91b9d2 VZ |
752 | void wxToolBarBase::DoToolbarUpdates() |
753 | { | |
6c41a418 | 754 | wxEvtHandler* evtHandler = GetEventHandler() ; |
e702ff0f | 755 | |
ac91b9d2 VZ |
756 | wxNode* node = GetTools().First(); |
757 | while (node) | |
758 | { | |
759 | wxToolBarTool* tool = (wxToolBarTool* ) node->Data(); | |
760 | ||
761 | wxUpdateUIEvent event(tool->m_index); | |
762 | event.SetEventObject(this); | |
763 | ||
e702ff0f | 764 | if (evtHandler->ProcessEvent(event)) |
ac91b9d2 VZ |
765 | { |
766 | if (event.GetSetEnabled()) | |
767 | EnableTool(tool->m_index, event.GetEnabled()); | |
768 | if (event.GetSetChecked()) | |
769 | ToggleTool(tool->m_index, event.GetChecked()); | |
10b959e3 | 770 | /* |
ac91b9d2 VZ |
771 | if (event.GetSetText()) |
772 | // Set tooltip? | |
10b959e3 | 773 | */ |
ac91b9d2 | 774 | } |
10b959e3 | 775 | |
ac91b9d2 VZ |
776 | node = node->Next(); |
777 | } | |
10b959e3 JS |
778 | } |
779 | ||
10b959e3 | 780 | #endif |