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