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