1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/tbarsmpl.cpp
3 // Purpose: wxToolBarSimple
4 // Author: Julian Smart
5 // Modified by: VZ on 14.12.99 during wxToolBarSimple reorganization
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "tbarsmpl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_TOOLBAR_SIMPLE
34 #include "wx/settings.h"
35 #include "wx/window.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/tbarsmpl.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxToolBarToolSimple
: public wxToolBarToolBase
49 wxToolBarToolSimple(wxToolBarSimple
*tbar
,
51 const wxBitmap
& bitmap1
,
52 const wxBitmap
& bitmap2
,
55 const wxString
& shortHelpString
,
56 const wxString
& longHelpString
)
57 : wxToolBarToolBase(tbar
, id
, bitmap1
, bitmap2
, toggle
,
58 clientData
, shortHelpString
, longHelpString
)
62 wxToolBarToolSimple(wxToolBarSimple
*tbar
, wxControl
*control
)
63 : wxToolBarToolBase(tbar
, control
)
67 void SetSize(const wxSize
& size
)
73 wxCoord
GetWidth() const { return m_width
; }
74 wxCoord
GetHeight() const { return m_height
; }
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple
, wxControl
)
88 BEGIN_EVENT_TABLE(wxToolBarSimple
, wxToolBarBase
)
89 EVT_SIZE(wxToolBarSimple::OnSize
)
90 EVT_SCROLL(wxToolBarSimple::OnScroll
)
91 EVT_PAINT(wxToolBarSimple::OnPaint
)
92 EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus
)
93 EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent
)
96 // ============================================================================
98 // ============================================================================
100 // ----------------------------------------------------------------------------
101 // tool bar tools creation
102 // ----------------------------------------------------------------------------
104 wxToolBarToolBase
*wxToolBarSimple::CreateTool(int id
,
105 const wxBitmap
& bitmap1
,
106 const wxBitmap
& bitmap2
,
108 wxObject
*clientData
,
109 const wxString
& shortHelpString
,
110 const wxString
& longHelpString
)
112 return new wxToolBarToolSimple(this, id
, bitmap1
, bitmap2
, toggle
,
113 clientData
, shortHelpString
, longHelpString
);
116 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
118 return new wxToolBarToolSimple(this, control
);
121 // ----------------------------------------------------------------------------
122 // wxToolBarSimple creation
123 // ----------------------------------------------------------------------------
125 void wxToolBarSimple::Init()
127 m_currentRowsOrColumns
= 0;
142 m_toolSeparation
= 5;
145 m_defaultHeight
= 15;
148 wxToolBarToolBase
*wxToolBarSimple::AddTool(int id
,
149 const wxBitmap
& bitmap
,
150 const wxBitmap
& pushedBitmap
,
154 wxObject
*clientData
,
155 const wxString
& helpString1
,
156 const wxString
& helpString2
)
158 // rememeber the position for DoInsertTool()
162 return wxToolBarBase::AddTool(id
, bitmap
, pushedBitmap
, toggle
,
163 xPos
, yPos
, clientData
,
164 helpString1
, helpString2
);
167 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
168 wxToolBarToolBase
*toolBase
)
170 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
172 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
173 _T("generic wxToolBarSimple doesn't support controls") );
176 if ( tool
->m_x
== -1 )
177 tool
->m_x
= m_xMargin
;
180 if ( tool
->m_y
== -1 )
181 tool
->m_y
= m_yMargin
;
183 tool
->SetSize(GetToolSize());
185 if ( tool
->IsButton() )
187 // Calculate reasonable max size in case Layout() not called
188 if ((tool
->m_x
+ tool
->GetBitmap1().GetWidth() + m_xMargin
) > m_maxWidth
)
189 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
191 if ((tool
->m_y
+ tool
->GetBitmap1().GetHeight() + m_yMargin
) > m_maxHeight
)
192 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
198 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
199 wxToolBarToolBase
*tool
)
201 // VZ: didn't test whether it works, but why not...
209 bool wxToolBarSimple::Create(wxWindow
*parent
,
214 const wxString
& name
)
216 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
219 // Set it to grey (or other 3D face colour)
220 wxSystemSettings settings
;
221 SetBackgroundColour(settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
));
223 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
228 m_maxRows
= 32000; // a lot
237 m_maxCols
= 32000; // a lot
240 SetCursor(*wxSTANDARD_CURSOR
);
245 wxToolBarSimple::~wxToolBarSimple()
249 bool wxToolBarSimple::Realize()
251 m_currentRowsOrColumns
= 0;
257 int maxToolWidth
= 0;
258 int maxToolHeight
= 0;
260 // Find the maximum tool width and height
261 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
264 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
265 if ( tool
->GetWidth() > maxToolWidth
)
266 maxToolWidth
= tool
->GetWidth();
267 if (tool
->GetHeight() > maxToolHeight
)
268 maxToolHeight
= tool
->GetHeight();
270 node
= node
->GetNext();
273 int separatorSize
= m_toolSeparation
;
275 node
= m_tools
.GetFirst();
278 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
279 if ( tool
->IsSeparator() )
281 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
283 if (m_currentRowsOrColumns
>= m_maxCols
)
284 m_lastY
+= separatorSize
;
286 m_lastX
+= separatorSize
;
290 if (m_currentRowsOrColumns
>= m_maxRows
)
291 m_lastX
+= separatorSize
;
293 m_lastY
+= separatorSize
;
296 else if ( tool
->IsButton() )
298 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
300 if (m_currentRowsOrColumns
>= m_maxCols
)
302 m_currentRowsOrColumns
= 0;
304 m_lastY
+= maxToolHeight
+ m_toolPacking
;
306 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
307 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
309 m_lastX
+= maxToolWidth
+ m_toolPacking
;
313 if (m_currentRowsOrColumns
>= m_maxRows
)
315 m_currentRowsOrColumns
= 0;
316 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
319 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
320 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
322 m_lastY
+= maxToolHeight
+ m_toolPacking
;
324 m_currentRowsOrColumns
++;
328 // TODO: support the controls
331 if (m_lastX
> m_maxWidth
)
332 m_maxWidth
= m_lastX
;
333 if (m_lastY
> m_maxHeight
)
334 m_maxHeight
= m_lastY
;
336 node
= node
->GetNext();
339 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
340 m_maxWidth
+= maxToolWidth
;
342 m_maxHeight
+= maxToolHeight
;
344 m_maxWidth
+= m_xMargin
;
345 m_maxHeight
+= m_yMargin
;
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
359 static int count
= 0;
360 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
365 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
367 node
= node
->GetNext() )
369 wxToolBarToolBase
*tool
= node
->GetData();
370 if ( tool
->IsButton() )
377 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
379 #if wxUSE_CONSTRAINTS
387 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
389 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
392 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
395 event
.GetPosition(&x
, &y
);
396 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
398 if (event
.LeftDown())
409 if (m_currentTool
> -1)
411 if (event
.LeftIsDown())
412 SpringUpButton(m_currentTool
);
419 if (!event
.IsButton())
421 if ( tool
->GetId() != m_currentTool
)
423 // If the left button is kept down and moved over buttons,
424 // press those buttons.
425 if ( event
.LeftIsDown() && tool
->IsEnabled() )
427 SpringUpButton(m_currentTool
);
429 if ( tool
->CanBeToggled() )
437 m_currentTool
= tool
->GetId();
438 OnMouseEnter(m_currentTool
);
443 // Left button pressed.
444 if ( event
.LeftDown() && tool
->IsEnabled() )
446 if ( tool
->CanBeToggled() )
453 else if (event
.RightDown())
455 OnRightClick(tool
->GetId(), x
, y
);
458 // Left Button Released. Only this action confirms selection.
459 // If the button is enabled and it is not a toggle tool and it is
460 // in the pressed state, then raise the button and call OnLeftClick.
462 if ( event
.LeftUp() && tool
->IsEnabled() )
464 // Pass the OnLeftClick event to tool
465 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
466 tool
->CanBeToggled() )
468 // If it was a toggle, and OnLeftClick says No Toggle allowed,
469 // then change it back
477 // ----------------------------------------------------------------------------
479 // ----------------------------------------------------------------------------
481 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
487 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
489 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
494 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
495 wxPen
white_pen("WHITE", 1, wxSOLID
);
496 wxPen
black_pen("BLACK", 1, wxSOLID
);
498 wxBitmap bitmap
= tool
->GetBitmap();
503 if (bitmap
.GetPalette())
504 memDC
.SetPalette(*bitmap
.GetPalette());
507 int ax
= (int)tool
->m_x
,
509 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
510 by
= (int)(tool
->m_y
+tool
->GetHeight());
512 memDC
.SelectObject(bitmap
);
513 if (m_windowStyle
& wxTB_3DBUTTONS
)
515 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
516 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
517 wxPen
* old_pen
= & dc
.GetPen();
518 dc
.SetPen( white_pen
);
519 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
520 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
521 dc
.SetPen( dark_grey_pen
);
522 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
523 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
524 dc
.SetPen( black_pen
);
525 dc
.DrawLine(bx
,ay
,bx
,by
);
526 dc
.DrawLine(bx
,by
,ax
,by
);
527 dc
.SetPen( *old_pen
);
528 dc
.DestroyClippingRegion();
529 // Select bitmap out of the DC
533 dc
.Blit(tool
->m_x
, tool
->m_y
,
534 bitmap
.GetWidth(), bitmap
.GetHeight(),
537 memDC
.SelectObject(wxNullBitmap
);
539 memDC
.SetPalette(wxNullPalette
);
542 // No second bitmap, so draw a thick line around bitmap, or invert if mono
543 else if ( tool
->IsToggled() )
545 bool drawBorder
= FALSE
;
546 #ifdef __X__ // X doesn't invert properly on colour
547 drawBorder
= wxColourDisplay();
548 #else // Inversion works fine under Windows
554 memDC
.SelectObject(tool
->GetBitmap1());
555 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
556 &memDC
, 0, 0, wxSRC_INVERT
);
557 memDC
.SelectObject(wxNullBitmap
);
561 bitmap
= tool
->GetBitmap1();
563 if (m_windowStyle
& wxTB_3DBUTTONS
)
565 int ax
= (int)tool
->m_x
,
567 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
568 by
= (int)(tool
->m_y
+tool
->GetHeight());
570 memDC
.SelectObject(bitmap
);
571 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
572 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
573 wxPen
* old_pen
= & dc
.GetPen();
574 dc
.SetPen( black_pen
);
575 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
576 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
577 dc
.SetPen( dark_grey_pen
);
578 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
579 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
580 dc
.SetPen( white_pen
);
581 dc
.DrawLine(bx
,ay
,bx
,by
);
582 dc
.DrawLine(bx
,by
,ax
,by
);
583 dc
.SetPen( *old_pen
);
584 dc
.DestroyClippingRegion();
585 memDC
.SelectObject(wxNullBitmap
);
589 wxCoord x
= tool
->m_x
;
590 wxCoord y
= tool
->m_y
;
591 wxCoord w
= bitmap
.GetWidth();
592 wxCoord h
= bitmap
.GetHeight();
593 wxPen
thick_black_pen("BLACK", 3, wxSOLID
);
595 memDC
.SelectObject(bitmap
);
596 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
597 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
599 dc
.SetPen(thick_black_pen
);
600 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
601 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
602 dc
.DestroyClippingRegion();
603 memDC
.SelectObject(wxNullBitmap
);
609 // ----------------------------------------------------------------------------
611 // ----------------------------------------------------------------------------
613 void wxToolBarSimple::SetRows(int nRows
)
615 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
617 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
623 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
626 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
629 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
630 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
631 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
632 (y
<= (tool
->m_y
+ tool
->GetHeight())))
637 node
= node
->GetNext();
640 return (wxToolBarToolBase
*)NULL
;
643 // ----------------------------------------------------------------------------
644 // tool state change handlers
645 // ----------------------------------------------------------------------------
647 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
648 bool WXUNUSED(enable
))
653 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
654 bool WXUNUSED(toggle
))
659 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
660 bool WXUNUSED(toggle
))
665 // Okay, so we've left the tool we're in ... we must check if the tool we're
666 // leaving was a 'sprung push button' and if so, spring it back to the up
668 void wxToolBarSimple::SpringUpButton(int id
)
670 wxToolBarToolBase
*tool
= FindById(id
);
672 if ( tool
&& tool
->CanBeToggled() )
680 // ----------------------------------------------------------------------------
681 // scrolling implementation
682 // ----------------------------------------------------------------------------
685 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
686 * noUnitsX/noUnitsY: : no. units per scrollbar
688 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
689 int noUnitsX
, int noUnitsY
,
692 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
693 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
694 m_xScrollLines
= noUnitsX
;
695 m_yScrollLines
= noUnitsY
;
700 // Recalculate scroll bar range and position
701 if (m_xScrollLines
> 0)
703 m_xScrollPosition
= xPos
;
704 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
708 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
709 m_xScrollPosition
= 0;
712 if (m_yScrollLines
> 0)
714 m_yScrollPosition
= yPos
;
715 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
719 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
720 m_yScrollPosition
= 0;
725 #if 0 //def __WXMSW__
726 ::UpdateWindow ((HWND
) GetHWND());
730 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
732 int orient
= event
.GetOrientation();
734 int nScrollInc
= CalcScrollInc(event
);
738 if (orient
== wxHORIZONTAL
)
740 int newPos
= m_xScrollPosition
+ nScrollInc
;
741 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
745 int newPos
= m_yScrollPosition
+ nScrollInc
;
746 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
749 if (orient
== wxHORIZONTAL
)
751 if (m_xScrollingEnabled
)
752 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
758 if (m_yScrollingEnabled
)
759 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
764 if (orient
== wxHORIZONTAL
)
766 m_xScrollPosition
+= nScrollInc
;
770 m_yScrollPosition
+= nScrollInc
;
775 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
777 int pos
= event
.GetPosition();
778 int orient
= event
.GetOrientation();
781 switch (event
.GetEventType())
783 case wxEVT_SCROLL_TOP
:
785 if (orient
== wxHORIZONTAL
)
786 nScrollInc
= - m_xScrollPosition
;
788 nScrollInc
= - m_yScrollPosition
;
791 case wxEVT_SCROLL_BOTTOM
:
793 if (orient
== wxHORIZONTAL
)
794 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
796 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
799 case wxEVT_SCROLL_LINEUP
:
804 case wxEVT_SCROLL_LINEDOWN
:
809 case wxEVT_SCROLL_PAGEUP
:
811 if (orient
== wxHORIZONTAL
)
812 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
814 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
817 case wxEVT_SCROLL_PAGEDOWN
:
819 if (orient
== wxHORIZONTAL
)
820 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
822 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
825 case wxEVT_SCROLL_THUMBTRACK
:
827 if (orient
== wxHORIZONTAL
)
828 nScrollInc
= pos
- m_xScrollPosition
;
830 nScrollInc
= pos
- m_yScrollPosition
;
838 if (orient
== wxHORIZONTAL
)
841 GetClientSize(&w
, &h
);
843 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
844 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
848 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
849 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
850 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
851 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
858 GetClientSize(&w
, &h
);
860 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
861 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
865 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
866 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
867 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
868 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
874 // Adjust the scrollbars - new version.
875 void wxToolBarSimple::AdjustScrollbars()
878 GetClientSize(&w
, &h
);
880 // Recalculate scroll bar range and position
881 if (m_xScrollLines
> 0)
883 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
884 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
888 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
890 // Calculate page size i.e. number of scroll units you get on the
891 // current client window
892 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
893 if (noPagePositions
< 1)
896 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
897 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
899 if (m_yScrollLines
> 0)
901 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
902 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
906 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
908 // Calculate page size i.e. number of scroll units you get on the
909 // current client window
910 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
911 if (noPagePositions
< 1)
914 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
915 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
919 // Prepare the DC by translating it according to the current scroll position
920 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
922 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
925 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
927 *x_unit
= m_xScrollPixelsPerLine
;
928 *y_unit
= m_yScrollPixelsPerLine
;
931 int wxToolBarSimple::GetScrollPageSize(int orient
) const
933 if ( orient
== wxHORIZONTAL
)
934 return m_xScrollLinesPerPage
;
936 return m_yScrollLinesPerPage
;
939 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
941 if ( orient
== wxHORIZONTAL
)
942 m_xScrollLinesPerPage
= pageSize
;
944 m_yScrollLinesPerPage
= pageSize
;
948 * Scroll to given position (scroll position, not pixel position)
950 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
953 ViewStart (&old_x
, &old_y
);
954 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
959 m_xScrollPosition
= x_pos
;
960 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
964 m_yScrollPosition
= y_pos
;
965 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
969 #if 0 //def __WXMSW__
970 UpdateWindow ((HWND
) GetHWND());
974 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
976 m_xScrollingEnabled
= x_scroll
;
977 m_yScrollingEnabled
= y_scroll
;
980 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
982 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
983 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
986 // Where the current view starts from
987 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
989 *x
= m_xScrollPosition
;
990 *y
= m_yScrollPosition
;
993 #endif // wxUSE_TOOLBAR_SIMPLE