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