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