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