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