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