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
9 // Licence: wxWindows licence
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 && 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/toolbar.h"
41 #include "wx/tbarsmpl.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxToolBarToolSimple
: public wxToolBarToolBase
50 wxToolBarToolSimple(wxToolBarSimple
*tbar
,
52 const wxString
& label
,
53 const wxBitmap
& bmpNormal
,
54 const wxBitmap
& bmpDisabled
,
57 const wxString
& shortHelp
,
58 const wxString
& longHelp
)
59 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
60 clientData
, shortHelp
, longHelp
)
64 wxToolBarToolSimple(wxToolBarSimple
*tbar
, wxControl
*control
)
65 : wxToolBarToolBase(tbar
, control
)
69 void SetSize(const wxSize
& size
)
75 wxCoord
GetWidth() const { return m_width
; }
76 wxCoord
GetHeight() const { return m_height
; }
83 DECLARE_NO_COPY_CLASS(wxToolBarToolSimple
)
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple
, wxControl
)
92 #if !wxUSE_TOOLBAR_NATIVE && !defined(__WXUNIVERSAL__)
93 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarSimple
)
96 BEGIN_EVENT_TABLE(wxToolBarSimple
, wxToolBarBase
)
97 EVT_SIZE(wxToolBarSimple::OnSize
)
98 EVT_SCROLL(wxToolBarSimple::OnScroll
)
99 EVT_PAINT(wxToolBarSimple::OnPaint
)
100 EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus
)
101 EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent
)
104 // ============================================================================
106 // ============================================================================
108 // ----------------------------------------------------------------------------
109 // tool bar tools creation
110 // ----------------------------------------------------------------------------
112 wxToolBarToolBase
*wxToolBarSimple::CreateTool(int id
,
113 const wxString
& label
,
114 const wxBitmap
& bmpNormal
,
115 const wxBitmap
& bmpDisabled
,
117 wxObject
*clientData
,
118 const wxString
& shortHelp
,
119 const wxString
& longHelp
)
121 return new wxToolBarToolSimple(this, id
, label
, bmpNormal
, bmpDisabled
,
122 kind
, clientData
, shortHelp
, longHelp
);
125 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
127 return new wxToolBarToolSimple(this, control
);
130 // ----------------------------------------------------------------------------
131 // wxToolBarSimple creation
132 // ----------------------------------------------------------------------------
134 void wxToolBarSimple::Init()
136 m_currentRowsOrColumns
= 0;
151 m_toolSeparation
= 5;
154 m_defaultHeight
= 15;
156 m_xScrollPixelsPerLine
= 1;
157 m_yScrollPixelsPerLine
= 1;
158 m_xScrollingEnabled
= FALSE
;
159 m_yScrollingEnabled
= FALSE
;
160 m_xScrollPosition
= 0;
161 m_yScrollPosition
= 0;
164 m_xScrollLinesPerPage
= 0;
165 m_yScrollLinesPerPage
= 0;
168 wxToolBarToolBase
*wxToolBarSimple::DoAddTool(int id
,
169 const wxString
& label
,
170 const wxBitmap
& bitmap
,
171 const wxBitmap
& bmpDisabled
,
173 const wxString
& shortHelp
,
174 const wxString
& longHelp
,
175 wxObject
*clientData
,
179 // rememeber the position for DoInsertTool()
183 return wxToolBarBase::DoAddTool(id
, label
, bitmap
, bmpDisabled
, kind
,
185 clientData
, xPos
, yPos
);
188 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
189 wxToolBarToolBase
*toolBase
)
191 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
193 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
194 _T("generic wxToolBarSimple doesn't support controls") );
197 if ( tool
->m_x
== -1 )
198 tool
->m_x
= m_xMargin
;
201 if ( tool
->m_y
== -1 )
202 tool
->m_y
= m_yMargin
;
204 tool
->SetSize(GetToolSize());
206 if ( tool
->IsButton() )
208 // Calculate reasonable max size in case Layout() not called
209 if ((tool
->m_x
+ tool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_maxWidth
)
210 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
212 if ((tool
->m_y
+ tool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_maxHeight
)
213 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
219 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
220 wxToolBarToolBase
*tool
)
222 // VZ: didn't test whether it works, but why not...
230 bool wxToolBarSimple::Create(wxWindow
*parent
,
235 const wxString
& name
)
237 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
240 // Set it to grey (or other 3D face colour)
241 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
243 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
248 m_maxRows
= 32000; // a lot
257 m_maxCols
= 32000; // a lot
260 SetCursor(*wxSTANDARD_CURSOR
);
265 wxToolBarSimple::~wxToolBarSimple()
269 bool wxToolBarSimple::Realize()
271 m_currentRowsOrColumns
= 0;
277 int maxToolWidth
= 0;
278 int maxToolHeight
= 0;
280 // Find the maximum tool width and height
281 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
284 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
285 if ( tool
->GetWidth() > maxToolWidth
)
286 maxToolWidth
= tool
->GetWidth();
287 if (tool
->GetHeight() > maxToolHeight
)
288 maxToolHeight
= tool
->GetHeight();
290 node
= node
->GetNext();
293 int separatorSize
= m_toolSeparation
;
295 node
= m_tools
.GetFirst();
298 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
299 if ( tool
->IsSeparator() )
301 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
303 if (m_currentRowsOrColumns
>= m_maxCols
)
304 m_lastY
+= separatorSize
;
306 m_lastX
+= separatorSize
;
310 if (m_currentRowsOrColumns
>= m_maxRows
)
311 m_lastX
+= separatorSize
;
313 m_lastY
+= separatorSize
;
316 else if ( tool
->IsButton() )
318 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
320 if (m_currentRowsOrColumns
>= m_maxCols
)
322 m_currentRowsOrColumns
= 0;
324 m_lastY
+= maxToolHeight
+ m_toolPacking
;
326 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
327 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
329 m_lastX
+= maxToolWidth
+ m_toolPacking
;
333 if (m_currentRowsOrColumns
>= m_maxRows
)
335 m_currentRowsOrColumns
= 0;
336 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
339 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
340 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
342 m_lastY
+= maxToolHeight
+ m_toolPacking
;
344 m_currentRowsOrColumns
++;
348 // TODO: support the controls
351 if (m_lastX
> m_maxWidth
)
352 m_maxWidth
= m_lastX
;
353 if (m_lastY
> m_maxHeight
)
354 m_maxHeight
= m_lastY
;
356 node
= node
->GetNext();
359 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
360 m_maxHeight
+= maxToolHeight
;
362 m_maxWidth
+= maxToolWidth
;
364 m_maxWidth
+= m_xMargin
;
365 m_maxHeight
+= m_yMargin
;
367 SetSize(m_maxWidth
, m_maxHeight
);
372 // ----------------------------------------------------------------------------
374 // ----------------------------------------------------------------------------
376 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
381 static int count
= 0;
382 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
387 for ( wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
389 node
= node
->GetNext() )
391 wxToolBarToolBase
*tool
= node
->GetData();
392 if ( tool
->IsButton() )
399 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
401 #if wxUSE_CONSTRAINTS
409 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
411 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
414 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
417 event
.GetPosition(&x
, &y
);
418 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
420 if (event
.LeftDown())
431 if (m_currentTool
> -1)
433 if (event
.LeftIsDown())
434 SpringUpButton(m_currentTool
);
441 if (!event
.IsButton())
443 if ( tool
->GetId() != m_currentTool
)
445 // If the left button is kept down and moved over buttons,
446 // press those buttons.
447 if ( event
.LeftIsDown() && tool
->IsEnabled() )
449 SpringUpButton(m_currentTool
);
451 if ( tool
->CanBeToggled() )
459 m_currentTool
= tool
->GetId();
460 OnMouseEnter(m_currentTool
);
465 // Left button pressed.
466 if ( event
.LeftDown() && tool
->IsEnabled() )
468 if ( tool
->CanBeToggled() )
475 else if (event
.RightDown())
477 OnRightClick(tool
->GetId(), x
, y
);
480 // Left Button Released. Only this action confirms selection.
481 // If the button is enabled and it is not a toggle tool and it is
482 // in the pressed state, then raise the button and call OnLeftClick.
484 if ( event
.LeftUp() && tool
->IsEnabled() )
486 // Pass the OnLeftClick event to tool
487 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
488 tool
->CanBeToggled() )
490 // If it was a toggle, and OnLeftClick says No Toggle allowed,
491 // then change it back
499 // ----------------------------------------------------------------------------
501 // ----------------------------------------------------------------------------
503 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
509 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
511 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
516 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
517 wxPen
white_pen(wxT("WHITE"), 1, wxSOLID
);
518 wxPen
black_pen(wxT("BLACK"), 1, wxSOLID
);
520 wxBitmap bitmap
= tool
->GetNormalBitmap();
524 if ( !tool
->IsToggled() )
528 if (bitmap
.GetPalette())
529 memDC
.SetPalette(*bitmap
.GetPalette());
531 #endif // wxUSE_PALETTE
533 int ax
= (int)tool
->m_x
,
535 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
536 by
= (int)(tool
->m_y
+tool
->GetHeight());
538 memDC
.SelectObject(bitmap
);
539 if (m_windowStyle
& wxTB_3DBUTTONS
)
541 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
542 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
543 wxPen
* old_pen
= & dc
.GetPen();
544 dc
.SetPen( white_pen
);
545 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
546 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
547 dc
.SetPen( dark_grey_pen
);
548 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
549 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
550 dc
.SetPen( black_pen
);
551 dc
.DrawLine(bx
,ay
,bx
,by
);
552 dc
.DrawLine(bx
,by
,ax
,by
);
553 dc
.SetPen( *old_pen
);
554 dc
.DestroyClippingRegion();
555 // Select bitmap out of the DC
559 dc
.Blit(tool
->m_x
, tool
->m_y
,
560 bitmap
.GetWidth(), bitmap
.GetHeight(),
563 memDC
.SelectObject(wxNullBitmap
);
567 if (bitmap
.GetPalette())
568 memDC
.SetPalette(wxNullPalette
);
570 #endif // wxUSE_PALETTE
572 // No second bitmap, so draw a thick line around bitmap, or invert if mono
573 else if ( tool
->IsToggled() )
575 bool drawBorder
= FALSE
;
576 #ifdef __X__ // X doesn't invert properly on colour
577 drawBorder
= wxColourDisplay();
578 #else // Inversion works fine under Windows
584 memDC
.SelectObject(tool
->GetNormalBitmap());
585 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
586 &memDC
, 0, 0, wxSRC_INVERT
);
587 memDC
.SelectObject(wxNullBitmap
);
591 bitmap
= tool
->GetNormalBitmap();
593 if (m_windowStyle
& wxTB_3DBUTTONS
)
595 int ax
= (int)tool
->m_x
,
597 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
598 by
= (int)(tool
->m_y
+tool
->GetHeight());
600 memDC
.SelectObject(bitmap
);
601 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
602 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
603 wxPen
* old_pen
= & dc
.GetPen();
604 dc
.SetPen( black_pen
);
605 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
606 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
607 dc
.SetPen( dark_grey_pen
);
608 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
609 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
610 dc
.SetPen( white_pen
);
611 dc
.DrawLine(bx
,ay
,bx
,by
);
612 dc
.DrawLine(bx
,by
,ax
,by
);
613 dc
.SetPen( *old_pen
);
614 dc
.DestroyClippingRegion();
615 memDC
.SelectObject(wxNullBitmap
);
619 wxCoord x
= tool
->m_x
;
620 wxCoord y
= tool
->m_y
;
621 wxCoord w
= bitmap
.GetWidth();
622 wxCoord h
= bitmap
.GetHeight();
623 wxPen
thick_black_pen(wxT("BLACK"), 3, wxSOLID
);
625 memDC
.SelectObject(bitmap
);
626 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
627 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
629 dc
.SetPen(thick_black_pen
);
630 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
631 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
632 dc
.DestroyClippingRegion();
633 memDC
.SelectObject(wxNullBitmap
);
639 // ----------------------------------------------------------------------------
641 // ----------------------------------------------------------------------------
643 void wxToolBarSimple::SetRows(int nRows
)
645 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
647 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
653 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
656 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
659 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
660 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
661 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
662 (y
<= (tool
->m_y
+ tool
->GetHeight())))
667 node
= node
->GetNext();
670 return (wxToolBarToolBase
*)NULL
;
673 // ----------------------------------------------------------------------------
674 // tool state change handlers
675 // ----------------------------------------------------------------------------
677 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
678 bool WXUNUSED(enable
))
683 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
684 bool WXUNUSED(toggle
))
689 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
690 bool WXUNUSED(toggle
))
695 // Okay, so we've left the tool we're in ... we must check if the tool we're
696 // leaving was a 'sprung push button' and if so, spring it back to the up
698 void wxToolBarSimple::SpringUpButton(int id
)
700 wxToolBarToolBase
*tool
= FindById(id
);
702 if ( tool
&& tool
->CanBeToggled() )
704 if (tool
->IsToggled())
711 // ----------------------------------------------------------------------------
712 // scrolling implementation
713 // ----------------------------------------------------------------------------
716 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
717 * noUnitsX/noUnitsY: : no. units per scrollbar
719 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
720 int noUnitsX
, int noUnitsY
,
723 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
724 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
725 m_xScrollLines
= noUnitsX
;
726 m_yScrollLines
= noUnitsY
;
731 // Recalculate scroll bar range and position
732 if (m_xScrollLines
> 0)
734 m_xScrollPosition
= xPos
;
735 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
739 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
740 m_xScrollPosition
= 0;
743 if (m_yScrollLines
> 0)
745 m_yScrollPosition
= yPos
;
746 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
750 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
751 m_yScrollPosition
= 0;
756 #if 0 //def __WXMSW__
757 ::UpdateWindow ((HWND
) GetHWND());
761 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
763 int orient
= event
.GetOrientation();
765 int nScrollInc
= CalcScrollInc(event
);
769 if (orient
== wxHORIZONTAL
)
771 int newPos
= m_xScrollPosition
+ nScrollInc
;
772 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
776 int newPos
= m_yScrollPosition
+ nScrollInc
;
777 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
780 if (orient
== wxHORIZONTAL
)
782 if (m_xScrollingEnabled
)
783 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
789 if (m_yScrollingEnabled
)
790 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
795 if (orient
== wxHORIZONTAL
)
797 m_xScrollPosition
+= nScrollInc
;
801 m_yScrollPosition
+= nScrollInc
;
806 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
808 int pos
= event
.GetPosition();
809 int orient
= event
.GetOrientation();
812 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
814 if (orient
== wxHORIZONTAL
)
815 nScrollInc
= - m_xScrollPosition
;
817 nScrollInc
= - m_yScrollPosition
;
819 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
821 if (orient
== wxHORIZONTAL
)
822 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
824 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
826 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
830 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
834 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
836 if (orient
== wxHORIZONTAL
)
837 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
839 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
841 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
843 if (orient
== wxHORIZONTAL
)
844 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
846 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
848 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
849 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
851 if (orient
== wxHORIZONTAL
)
852 nScrollInc
= pos
- m_xScrollPosition
;
854 nScrollInc
= pos
- m_yScrollPosition
;
857 if (orient
== wxHORIZONTAL
)
860 GetClientSize(&w
, &h
);
862 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
863 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
867 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
868 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
869 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
870 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
877 GetClientSize(&w
, &h
);
879 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
880 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
884 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
885 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
886 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
887 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
893 // Adjust the scrollbars - new version.
894 void wxToolBarSimple::AdjustScrollbars()
897 GetClientSize(&w
, &h
);
899 // Recalculate scroll bar range and position
900 if (m_xScrollLines
> 0)
902 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
903 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
907 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
909 // Calculate page size i.e. number of scroll units you get on the
910 // current client window
911 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
912 if (noPagePositions
< 1)
915 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
916 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
918 if (m_yScrollLines
> 0)
920 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
921 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
925 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
927 // Calculate page size i.e. number of scroll units you get on the
928 // current client window
929 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
930 if (noPagePositions
< 1)
933 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
934 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
938 // Prepare the DC by translating it according to the current scroll position
939 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
941 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
944 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
946 *x_unit
= m_xScrollPixelsPerLine
;
947 *y_unit
= m_yScrollPixelsPerLine
;
950 int wxToolBarSimple::GetScrollPageSize(int orient
) const
952 if ( orient
== wxHORIZONTAL
)
953 return m_xScrollLinesPerPage
;
955 return m_yScrollLinesPerPage
;
958 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
960 if ( orient
== wxHORIZONTAL
)
961 m_xScrollLinesPerPage
= pageSize
;
963 m_yScrollLinesPerPage
= pageSize
;
967 * Scroll to given position (scroll position, not pixel position)
969 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
972 ViewStart (&old_x
, &old_y
);
973 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
978 m_xScrollPosition
= x_pos
;
979 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
983 m_yScrollPosition
= y_pos
;
984 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
988 #if 0 //def __WXMSW__
989 UpdateWindow ((HWND
) GetHWND());
993 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
995 m_xScrollingEnabled
= x_scroll
;
996 m_yScrollingEnabled
= y_scroll
;
999 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
1001 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
1002 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
1005 // Where the current view starts from
1006 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
1008 *x
= m_xScrollPosition
;
1009 *y
= m_yScrollPosition
;
1012 #endif // wxUSE_TOOLBAR_SIMPLE