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() )
685 if (tool
->IsToggled())
692 // ----------------------------------------------------------------------------
693 // scrolling implementation
694 // ----------------------------------------------------------------------------
697 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
698 * noUnitsX/noUnitsY: : no. units per scrollbar
700 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
701 int noUnitsX
, int noUnitsY
,
704 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
705 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
706 m_xScrollLines
= noUnitsX
;
707 m_yScrollLines
= noUnitsY
;
712 // Recalculate scroll bar range and position
713 if (m_xScrollLines
> 0)
715 m_xScrollPosition
= xPos
;
716 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
720 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
721 m_xScrollPosition
= 0;
724 if (m_yScrollLines
> 0)
726 m_yScrollPosition
= yPos
;
727 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
731 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
732 m_yScrollPosition
= 0;
737 #if 0 //def __WXMSW__
738 ::UpdateWindow ((HWND
) GetHWND());
742 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
744 int orient
= event
.GetOrientation();
746 int nScrollInc
= CalcScrollInc(event
);
750 if (orient
== wxHORIZONTAL
)
752 int newPos
= m_xScrollPosition
+ nScrollInc
;
753 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
757 int newPos
= m_yScrollPosition
+ nScrollInc
;
758 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
761 if (orient
== wxHORIZONTAL
)
763 if (m_xScrollingEnabled
)
764 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
770 if (m_yScrollingEnabled
)
771 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
776 if (orient
== wxHORIZONTAL
)
778 m_xScrollPosition
+= nScrollInc
;
782 m_yScrollPosition
+= nScrollInc
;
787 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
789 int pos
= event
.GetPosition();
790 int orient
= event
.GetOrientation();
793 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
795 if (orient
== wxHORIZONTAL
)
796 nScrollInc
= - m_xScrollPosition
;
798 nScrollInc
= - m_yScrollPosition
;
800 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
802 if (orient
== wxHORIZONTAL
)
803 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
805 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
807 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
811 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
815 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
817 if (orient
== wxHORIZONTAL
)
818 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
820 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
822 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
824 if (orient
== wxHORIZONTAL
)
825 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
827 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
829 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
830 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
832 if (orient
== wxHORIZONTAL
)
833 nScrollInc
= pos
- m_xScrollPosition
;
835 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