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
, wxToolBarBase
)
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;
147 m_xScrollPixelsPerLine
= 1;
148 m_yScrollPixelsPerLine
= 1;
149 m_xScrollingEnabled
= FALSE
;
150 m_yScrollingEnabled
= FALSE
;
151 m_xScrollPosition
= 0;
152 m_yScrollPosition
= 0;
155 m_xScrollLinesPerPage
= 0;
156 m_yScrollLinesPerPage
= 0;
159 wxToolBarToolBase
*wxToolBarSimple::AddTool(int id
,
160 const wxBitmap
& bitmap
,
161 const wxBitmap
& pushedBitmap
,
165 wxObject
*clientData
,
166 const wxString
& helpString1
,
167 const wxString
& helpString2
)
169 // rememeber the position for DoInsertTool()
173 return wxToolBarBase::AddTool(id
, bitmap
, pushedBitmap
, toggle
,
174 xPos
, yPos
, clientData
,
175 helpString1
, helpString2
);
178 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
179 wxToolBarToolBase
*toolBase
)
181 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
183 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
184 _T("generic wxToolBarSimple doesn't support controls") );
187 if ( tool
->m_x
== -1 )
188 tool
->m_x
= m_xMargin
;
191 if ( tool
->m_y
== -1 )
192 tool
->m_y
= m_yMargin
;
194 tool
->SetSize(GetToolSize());
196 if ( tool
->IsButton() )
198 // Calculate reasonable max size in case Layout() not called
199 if ((tool
->m_x
+ tool
->GetBitmap1().GetWidth() + m_xMargin
) > m_maxWidth
)
200 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
202 if ((tool
->m_y
+ tool
->GetBitmap1().GetHeight() + m_yMargin
) > m_maxHeight
)
203 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
209 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
210 wxToolBarToolBase
*tool
)
212 // VZ: didn't test whether it works, but why not...
220 bool wxToolBarSimple::Create(wxWindow
*parent
,
225 const wxString
& name
)
227 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
230 // Set it to grey (or other 3D face colour)
231 wxSystemSettings settings
;
232 SetBackgroundColour(settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
));
234 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
239 m_maxRows
= 32000; // a lot
248 m_maxCols
= 32000; // a lot
251 SetCursor(*wxSTANDARD_CURSOR
);
256 wxToolBarSimple::~wxToolBarSimple()
260 bool wxToolBarSimple::Realize()
262 m_currentRowsOrColumns
= 0;
268 int maxToolWidth
= 0;
269 int maxToolHeight
= 0;
271 // Find the maximum tool width and height
272 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
275 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
276 if ( tool
->GetWidth() > maxToolWidth
)
277 maxToolWidth
= tool
->GetWidth();
278 if (tool
->GetHeight() > maxToolHeight
)
279 maxToolHeight
= tool
->GetHeight();
281 node
= node
->GetNext();
284 int separatorSize
= m_toolSeparation
;
286 node
= m_tools
.GetFirst();
289 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
290 if ( tool
->IsSeparator() )
292 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
294 if (m_currentRowsOrColumns
>= m_maxCols
)
295 m_lastY
+= separatorSize
;
297 m_lastX
+= separatorSize
;
301 if (m_currentRowsOrColumns
>= m_maxRows
)
302 m_lastX
+= separatorSize
;
304 m_lastY
+= separatorSize
;
307 else if ( tool
->IsButton() )
309 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
311 if (m_currentRowsOrColumns
>= m_maxCols
)
313 m_currentRowsOrColumns
= 0;
315 m_lastY
+= maxToolHeight
+ m_toolPacking
;
317 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
318 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
320 m_lastX
+= maxToolWidth
+ m_toolPacking
;
324 if (m_currentRowsOrColumns
>= m_maxRows
)
326 m_currentRowsOrColumns
= 0;
327 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
330 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
331 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
333 m_lastY
+= maxToolHeight
+ m_toolPacking
;
335 m_currentRowsOrColumns
++;
339 // TODO: support the controls
342 if (m_lastX
> m_maxWidth
)
343 m_maxWidth
= m_lastX
;
344 if (m_lastY
> m_maxHeight
)
345 m_maxHeight
= m_lastY
;
347 node
= node
->GetNext();
350 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
351 m_maxWidth
+= maxToolWidth
;
353 m_maxHeight
+= maxToolHeight
;
355 m_maxWidth
+= m_xMargin
;
356 m_maxHeight
+= m_yMargin
;
361 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
370 static int count
= 0;
371 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
376 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
378 node
= node
->GetNext() )
380 wxToolBarToolBase
*tool
= node
->GetData();
381 if ( tool
->IsButton() )
388 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
390 #if wxUSE_CONSTRAINTS
398 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
400 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
403 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
406 event
.GetPosition(&x
, &y
);
407 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
409 if (event
.LeftDown())
420 if (m_currentTool
> -1)
422 if (event
.LeftIsDown())
423 SpringUpButton(m_currentTool
);
430 if (!event
.IsButton())
432 if ( tool
->GetId() != m_currentTool
)
434 // If the left button is kept down and moved over buttons,
435 // press those buttons.
436 if ( event
.LeftIsDown() && tool
->IsEnabled() )
438 SpringUpButton(m_currentTool
);
440 if ( tool
->CanBeToggled() )
448 m_currentTool
= tool
->GetId();
449 OnMouseEnter(m_currentTool
);
454 // Left button pressed.
455 if ( event
.LeftDown() && tool
->IsEnabled() )
457 if ( tool
->CanBeToggled() )
464 else if (event
.RightDown())
466 OnRightClick(tool
->GetId(), x
, y
);
469 // Left Button Released. Only this action confirms selection.
470 // If the button is enabled and it is not a toggle tool and it is
471 // in the pressed state, then raise the button and call OnLeftClick.
473 if ( event
.LeftUp() && tool
->IsEnabled() )
475 // Pass the OnLeftClick event to tool
476 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
477 tool
->CanBeToggled() )
479 // If it was a toggle, and OnLeftClick says No Toggle allowed,
480 // then change it back
488 // ----------------------------------------------------------------------------
490 // ----------------------------------------------------------------------------
492 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
498 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
500 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
505 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
506 wxPen
white_pen("WHITE", 1, wxSOLID
);
507 wxPen
black_pen("BLACK", 1, wxSOLID
);
509 wxBitmap bitmap
= tool
->GetBitmap();
514 if (bitmap
.GetPalette())
515 memDC
.SetPalette(*bitmap
.GetPalette());
518 int ax
= (int)tool
->m_x
,
520 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
521 by
= (int)(tool
->m_y
+tool
->GetHeight());
523 memDC
.SelectObject(bitmap
);
524 if (m_windowStyle
& wxTB_3DBUTTONS
)
526 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
527 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
528 wxPen
* old_pen
= & dc
.GetPen();
529 dc
.SetPen( white_pen
);
530 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
531 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
532 dc
.SetPen( dark_grey_pen
);
533 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
534 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
535 dc
.SetPen( black_pen
);
536 dc
.DrawLine(bx
,ay
,bx
,by
);
537 dc
.DrawLine(bx
,by
,ax
,by
);
538 dc
.SetPen( *old_pen
);
539 dc
.DestroyClippingRegion();
540 // Select bitmap out of the DC
544 dc
.Blit(tool
->m_x
, tool
->m_y
,
545 bitmap
.GetWidth(), bitmap
.GetHeight(),
548 memDC
.SelectObject(wxNullBitmap
);
550 memDC
.SetPalette(wxNullPalette
);
553 // No second bitmap, so draw a thick line around bitmap, or invert if mono
554 else if ( tool
->IsToggled() )
556 bool drawBorder
= FALSE
;
557 #ifdef __X__ // X doesn't invert properly on colour
558 drawBorder
= wxColourDisplay();
559 #else // Inversion works fine under Windows
565 memDC
.SelectObject(tool
->GetBitmap1());
566 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
567 &memDC
, 0, 0, wxSRC_INVERT
);
568 memDC
.SelectObject(wxNullBitmap
);
572 bitmap
= tool
->GetBitmap1();
574 if (m_windowStyle
& wxTB_3DBUTTONS
)
576 int ax
= (int)tool
->m_x
,
578 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
579 by
= (int)(tool
->m_y
+tool
->GetHeight());
581 memDC
.SelectObject(bitmap
);
582 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
583 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
584 wxPen
* old_pen
= & dc
.GetPen();
585 dc
.SetPen( black_pen
);
586 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
587 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
588 dc
.SetPen( dark_grey_pen
);
589 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
590 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
591 dc
.SetPen( white_pen
);
592 dc
.DrawLine(bx
,ay
,bx
,by
);
593 dc
.DrawLine(bx
,by
,ax
,by
);
594 dc
.SetPen( *old_pen
);
595 dc
.DestroyClippingRegion();
596 memDC
.SelectObject(wxNullBitmap
);
600 wxCoord x
= tool
->m_x
;
601 wxCoord y
= tool
->m_y
;
602 wxCoord w
= bitmap
.GetWidth();
603 wxCoord h
= bitmap
.GetHeight();
604 wxPen
thick_black_pen("BLACK", 3, wxSOLID
);
606 memDC
.SelectObject(bitmap
);
607 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
608 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
610 dc
.SetPen(thick_black_pen
);
611 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
612 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
613 dc
.DestroyClippingRegion();
614 memDC
.SelectObject(wxNullBitmap
);
620 // ----------------------------------------------------------------------------
622 // ----------------------------------------------------------------------------
624 void wxToolBarSimple::SetRows(int nRows
)
626 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
628 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
634 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
637 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
640 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
641 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
642 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
643 (y
<= (tool
->m_y
+ tool
->GetHeight())))
648 node
= node
->GetNext();
651 return (wxToolBarToolBase
*)NULL
;
654 // ----------------------------------------------------------------------------
655 // tool state change handlers
656 // ----------------------------------------------------------------------------
658 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
659 bool WXUNUSED(enable
))
664 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
665 bool WXUNUSED(toggle
))
670 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
671 bool WXUNUSED(toggle
))
676 // Okay, so we've left the tool we're in ... we must check if the tool we're
677 // leaving was a 'sprung push button' and if so, spring it back to the up
679 void wxToolBarSimple::SpringUpButton(int id
)
681 wxToolBarToolBase
*tool
= FindById(id
);
683 if ( tool
&& tool
->CanBeToggled() )
691 // ----------------------------------------------------------------------------
692 // scrolling implementation
693 // ----------------------------------------------------------------------------
696 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
697 * noUnitsX/noUnitsY: : no. units per scrollbar
699 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
700 int noUnitsX
, int noUnitsY
,
703 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
704 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
705 m_xScrollLines
= noUnitsX
;
706 m_yScrollLines
= noUnitsY
;
711 // Recalculate scroll bar range and position
712 if (m_xScrollLines
> 0)
714 m_xScrollPosition
= xPos
;
715 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
719 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
720 m_xScrollPosition
= 0;
723 if (m_yScrollLines
> 0)
725 m_yScrollPosition
= yPos
;
726 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
730 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
731 m_yScrollPosition
= 0;
736 #if 0 //def __WXMSW__
737 ::UpdateWindow ((HWND
) GetHWND());
741 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
743 int orient
= event
.GetOrientation();
745 int nScrollInc
= CalcScrollInc(event
);
749 if (orient
== wxHORIZONTAL
)
751 int newPos
= m_xScrollPosition
+ nScrollInc
;
752 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
756 int newPos
= m_yScrollPosition
+ nScrollInc
;
757 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
760 if (orient
== wxHORIZONTAL
)
762 if (m_xScrollingEnabled
)
763 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
769 if (m_yScrollingEnabled
)
770 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
775 if (orient
== wxHORIZONTAL
)
777 m_xScrollPosition
+= nScrollInc
;
781 m_yScrollPosition
+= nScrollInc
;
786 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
788 int pos
= event
.GetPosition();
789 int orient
= event
.GetOrientation();
792 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
794 if (orient
== wxHORIZONTAL
)
795 nScrollInc
= - m_xScrollPosition
;
797 nScrollInc
= - m_yScrollPosition
;
799 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
801 if (orient
== wxHORIZONTAL
)
802 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
804 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
806 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
810 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
814 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
816 if (orient
== wxHORIZONTAL
)
817 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
819 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
821 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
823 if (orient
== wxHORIZONTAL
)
824 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
826 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
828 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
829 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
831 if (orient
== wxHORIZONTAL
)
832 nScrollInc
= pos
- m_xScrollPosition
;
834 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