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 long GetWidth() const { return m_width
; }
74 long 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 pos
, wxToolBarToolBase
*toolBase
)
169 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
171 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
172 _T("generic wxToolBarSimple doesn't support controls") );
175 if ( tool
->m_x
== -1 )
176 tool
->m_x
= m_xMargin
;
179 if ( tool
->m_y
== -1 )
180 tool
->m_y
= m_yMargin
;
182 tool
->SetSize(GetToolSize());
184 if ( tool
->IsButton() )
186 // Calculate reasonable max size in case Layout() not called
187 if ((tool
->m_x
+ tool
->GetBitmap1().GetWidth() + m_xMargin
) > m_maxWidth
)
188 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
190 if ((tool
->m_y
+ tool
->GetBitmap1().GetHeight() + m_yMargin
) > m_maxHeight
)
191 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
197 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
198 wxToolBarToolBase
*tool
)
200 // VZ: didn't test whether it works, but why not...
208 bool wxToolBarSimple::Create(wxWindow
*parent
,
213 const wxString
& name
)
215 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
218 // Set it to grey (or other 3D face colour)
219 wxSystemSettings settings
;
220 SetBackgroundColour(settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
));
222 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
227 m_maxRows
= 32000; // a lot
236 m_maxCols
= 32000; // a lot
239 SetCursor(*wxSTANDARD_CURSOR
);
244 wxToolBarSimple::~wxToolBarSimple()
248 bool wxToolBarSimple::Realize()
250 m_currentRowsOrColumns
= 0;
256 int maxToolWidth
= 0;
257 int maxToolHeight
= 0;
259 // Find the maximum tool width and height
260 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
263 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
264 if ( tool
->GetWidth() > maxToolWidth
)
265 maxToolWidth
= tool
->GetWidth();
266 if (tool
->GetHeight() > maxToolHeight
)
267 maxToolHeight
= tool
->GetHeight();
269 node
= node
->GetNext();
272 int separatorSize
= m_toolSeparation
;
274 node
= m_tools
.GetFirst();
277 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
278 if ( tool
->IsSeparator() )
280 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
282 if (m_currentRowsOrColumns
>= m_maxCols
)
283 m_lastY
+= separatorSize
;
285 m_lastX
+= separatorSize
;
289 if (m_currentRowsOrColumns
>= m_maxRows
)
290 m_lastX
+= separatorSize
;
292 m_lastY
+= separatorSize
;
295 else if ( tool
->IsButton() )
297 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
299 if (m_currentRowsOrColumns
>= m_maxCols
)
301 m_currentRowsOrColumns
= 0;
303 m_lastY
+= maxToolHeight
+ m_toolPacking
;
305 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
306 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
308 m_lastX
+= maxToolWidth
+ m_toolPacking
;
312 if (m_currentRowsOrColumns
>= m_maxRows
)
314 m_currentRowsOrColumns
= 0;
315 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
318 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
319 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
321 m_lastY
+= maxToolHeight
+ m_toolPacking
;
323 m_currentRowsOrColumns
++;
327 // TODO: support the controls
330 if (m_lastX
> m_maxWidth
)
331 m_maxWidth
= m_lastX
;
332 if (m_lastY
> m_maxHeight
)
333 m_maxHeight
= m_lastY
;
335 node
= node
->GetNext();
338 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
339 m_maxWidth
+= maxToolWidth
;
341 m_maxHeight
+= maxToolHeight
;
343 m_maxWidth
+= m_xMargin
;
344 m_maxHeight
+= m_yMargin
;
349 // ----------------------------------------------------------------------------
351 // ----------------------------------------------------------------------------
353 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
358 static int count
= 0;
359 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
364 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
366 node
= node
->GetNext() )
368 wxToolBarToolBase
*tool
= node
->GetData();
369 if ( tool
->IsButton() )
376 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
378 #if wxUSE_CONSTRAINTS
386 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
388 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
391 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
394 event
.GetPosition(&x
, &y
);
395 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
397 if (event
.LeftDown())
408 if (m_currentTool
> -1)
410 if (event
.LeftIsDown())
411 SpringUpButton(m_currentTool
);
418 if (!event
.IsButton())
420 if ( tool
->GetId() != m_currentTool
)
422 // If the left button is kept down and moved over buttons,
423 // press those buttons.
424 if ( event
.LeftIsDown() && tool
->IsEnabled() )
426 SpringUpButton(m_currentTool
);
428 if ( tool
->CanBeToggled() )
436 m_currentTool
= tool
->GetId();
437 OnMouseEnter(m_currentTool
);
442 // Left button pressed.
443 if ( event
.LeftDown() && tool
->IsEnabled() )
445 if ( tool
->CanBeToggled() )
452 else if (event
.RightDown())
454 OnRightClick(tool
->GetId(), x
, y
);
457 // Left Button Released. Only this action confirms selection.
458 // If the button is enabled and it is not a toggle tool and it is
459 // in the pressed state, then raise the button and call OnLeftClick.
461 if ( event
.LeftUp() && tool
->IsEnabled() )
463 // Pass the OnLeftClick event to tool
464 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
465 tool
->CanBeToggled() )
467 // If it was a toggle, and OnLeftClick says No Toggle allowed,
468 // then change it back
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
480 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
486 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
488 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
493 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
494 wxPen
white_pen("WHITE", 1, wxSOLID
);
495 wxPen
black_pen("BLACK", 1, wxSOLID
);
497 wxBitmap bitmap
= tool
->GetBitmap();
502 if (bitmap
.GetPalette())
503 memDC
.SetPalette(*bitmap
.GetPalette());
506 int ax
= (int)tool
->m_x
,
508 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
509 by
= (int)(tool
->m_y
+tool
->GetHeight());
511 memDC
.SelectObject(bitmap
);
512 if (m_windowStyle
& wxTB_3DBUTTONS
)
514 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
515 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
516 wxPen
* old_pen
= & dc
.GetPen();
517 dc
.SetPen( white_pen
);
518 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
519 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
520 dc
.SetPen( dark_grey_pen
);
521 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
522 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
523 dc
.SetPen( black_pen
);
524 dc
.DrawLine(bx
,ay
,bx
,by
);
525 dc
.DrawLine(bx
,by
,ax
,by
);
526 dc
.SetPen( *old_pen
);
527 dc
.DestroyClippingRegion();
528 // Select bitmap out of the DC
532 dc
.Blit(tool
->m_x
, tool
->m_y
,
533 bitmap
.GetWidth(), bitmap
.GetHeight(),
536 memDC
.SelectObject(wxNullBitmap
);
538 memDC
.SetPalette(wxNullPalette
);
541 // No second bitmap, so draw a thick line around bitmap, or invert if mono
542 else if ( tool
->IsToggled() )
544 bool drawBorder
= FALSE
;
545 #ifdef __X__ // X doesn't invert properly on colour
546 drawBorder
= wxColourDisplay();
547 #else // Inversion works fine under Windows
553 memDC
.SelectObject(tool
->GetBitmap1());
554 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
555 &memDC
, 0, 0, wxSRC_INVERT
);
556 memDC
.SelectObject(wxNullBitmap
);
560 bitmap
= tool
->GetBitmap1();
562 if (m_windowStyle
& wxTB_3DBUTTONS
)
564 int ax
= (int)tool
->m_x
,
566 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
567 by
= (int)(tool
->m_y
+tool
->GetHeight());
569 memDC
.SelectObject(bitmap
);
570 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
571 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
572 wxPen
* old_pen
= & dc
.GetPen();
573 dc
.SetPen( black_pen
);
574 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
575 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
576 dc
.SetPen( dark_grey_pen
);
577 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
578 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
579 dc
.SetPen( white_pen
);
580 dc
.DrawLine(bx
,ay
,bx
,by
);
581 dc
.DrawLine(bx
,by
,ax
,by
);
582 dc
.SetPen( *old_pen
);
583 dc
.DestroyClippingRegion();
584 memDC
.SelectObject(wxNullBitmap
);
590 long w
= bitmap
.GetWidth();
591 long h
= bitmap
.GetHeight();
592 wxPen
thick_black_pen("BLACK", 3, wxSOLID
);
594 memDC
.SelectObject(bitmap
);
595 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
596 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
598 dc
.SetPen(thick_black_pen
);
599 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
600 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
601 dc
.DestroyClippingRegion();
602 memDC
.SelectObject(wxNullBitmap
);
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
612 void wxToolBarSimple::SetRows(int nRows
)
614 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
616 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
622 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
625 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
628 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
629 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
630 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
631 (y
<= (tool
->m_y
+ tool
->GetHeight())))
636 node
= node
->GetNext();
639 return (wxToolBarToolBase
*)NULL
;
642 // ----------------------------------------------------------------------------
643 // tool state change handlers
644 // ----------------------------------------------------------------------------
646 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
647 bool WXUNUSED(enable
))
652 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
653 bool WXUNUSED(toggle
))
658 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
659 bool WXUNUSED(toggle
))
664 // Okay, so we've left the tool we're in ... we must check if the tool we're
665 // leaving was a 'sprung push button' and if so, spring it back to the up
667 void wxToolBarSimple::SpringUpButton(int id
)
669 wxToolBarToolBase
*tool
= FindById(id
);
671 if ( tool
&& tool
->CanBeToggled() )
679 // ----------------------------------------------------------------------------
680 // scrolling implementation
681 // ----------------------------------------------------------------------------
684 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
685 * noUnitsX/noUnitsY: : no. units per scrollbar
687 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
688 int noUnitsX
, int noUnitsY
,
691 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
692 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
693 m_xScrollLines
= noUnitsX
;
694 m_yScrollLines
= noUnitsY
;
699 // Recalculate scroll bar range and position
700 if (m_xScrollLines
> 0)
702 m_xScrollPosition
= xPos
;
703 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
707 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
708 m_xScrollPosition
= 0;
711 if (m_yScrollLines
> 0)
713 m_yScrollPosition
= yPos
;
714 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
718 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
719 m_yScrollPosition
= 0;
724 #if 0 //def __WXMSW__
725 ::UpdateWindow ((HWND
) GetHWND());
729 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
731 int orient
= event
.GetOrientation();
733 int nScrollInc
= CalcScrollInc(event
);
737 if (orient
== wxHORIZONTAL
)
739 int newPos
= m_xScrollPosition
+ nScrollInc
;
740 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
744 int newPos
= m_yScrollPosition
+ nScrollInc
;
745 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
748 if (orient
== wxHORIZONTAL
)
750 if (m_xScrollingEnabled
)
751 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
757 if (m_yScrollingEnabled
)
758 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
763 if (orient
== wxHORIZONTAL
)
765 m_xScrollPosition
+= nScrollInc
;
769 m_yScrollPosition
+= nScrollInc
;
774 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
776 int pos
= event
.GetPosition();
777 int orient
= event
.GetOrientation();
780 switch (event
.GetEventType())
782 case wxEVT_SCROLL_TOP
:
784 if (orient
== wxHORIZONTAL
)
785 nScrollInc
= - m_xScrollPosition
;
787 nScrollInc
= - m_yScrollPosition
;
790 case wxEVT_SCROLL_BOTTOM
:
792 if (orient
== wxHORIZONTAL
)
793 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
795 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
798 case wxEVT_SCROLL_LINEUP
:
803 case wxEVT_SCROLL_LINEDOWN
:
808 case wxEVT_SCROLL_PAGEUP
:
810 if (orient
== wxHORIZONTAL
)
811 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
813 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
816 case wxEVT_SCROLL_PAGEDOWN
:
818 if (orient
== wxHORIZONTAL
)
819 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
821 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
824 case wxEVT_SCROLL_THUMBTRACK
:
826 if (orient
== wxHORIZONTAL
)
827 nScrollInc
= pos
- m_xScrollPosition
;
829 nScrollInc
= pos
- m_yScrollPosition
;
837 if (orient
== wxHORIZONTAL
)
840 GetClientSize(&w
, &h
);
842 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
843 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
847 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
848 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
849 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
850 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
857 GetClientSize(&w
, &h
);
859 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
860 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
864 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
865 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
866 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
867 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
873 // Adjust the scrollbars - new version.
874 void wxToolBarSimple::AdjustScrollbars()
877 GetClientSize(&w
, &h
);
879 // Recalculate scroll bar range and position
880 if (m_xScrollLines
> 0)
882 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
883 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
887 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
889 // Calculate page size i.e. number of scroll units you get on the
890 // current client window
891 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
892 if (noPagePositions
< 1)
895 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
896 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
898 if (m_yScrollLines
> 0)
900 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
901 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
905 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
907 // Calculate page size i.e. number of scroll units you get on the
908 // current client window
909 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
910 if (noPagePositions
< 1)
913 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
914 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
918 // Prepare the DC by translating it according to the current scroll position
919 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
921 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
924 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
926 *x_unit
= m_xScrollPixelsPerLine
;
927 *y_unit
= m_yScrollPixelsPerLine
;
930 int wxToolBarSimple::GetScrollPageSize(int orient
) const
932 if ( orient
== wxHORIZONTAL
)
933 return m_xScrollLinesPerPage
;
935 return m_yScrollLinesPerPage
;
938 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
940 if ( orient
== wxHORIZONTAL
)
941 m_xScrollLinesPerPage
= pageSize
;
943 m_yScrollLinesPerPage
= pageSize
;
947 * Scroll to given position (scroll position, not pixel position)
949 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
952 ViewStart (&old_x
, &old_y
);
953 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
958 m_xScrollPosition
= x_pos
;
959 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
963 m_yScrollPosition
= y_pos
;
964 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
968 #if 0 //def __WXMSW__
969 UpdateWindow ((HWND
) GetHWND());
973 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
975 m_xScrollingEnabled
= x_scroll
;
976 m_yScrollingEnabled
= y_scroll
;
979 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
981 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
982 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
985 // Where the current view starts from
986 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
988 *x
= m_xScrollPosition
;
989 *y
= m_yScrollPosition
;
992 #endif // wxUSE_TOOLBAR_SIMPLE