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