1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/src/deprecated//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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/deprecated/tbarsmpl.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 class WXDLLIMPEXP_DEPRECATED 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
))
407 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
409 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
412 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
415 event
.GetPosition(&x
, &y
);
416 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
418 if (event
.LeftDown())
429 if (m_currentTool
> -1)
431 if (event
.LeftIsDown())
432 SpringUpButton(m_currentTool
);
439 if (!event
.IsButton())
441 if ( tool
->GetId() != m_currentTool
)
443 // If the left button is kept down and moved over buttons,
444 // press those buttons.
445 if ( event
.LeftIsDown() && tool
->IsEnabled() )
447 SpringUpButton(m_currentTool
);
449 if ( tool
->CanBeToggled() )
457 m_currentTool
= tool
->GetId();
458 OnMouseEnter(m_currentTool
);
463 // Left button pressed.
464 if ( event
.LeftDown() && tool
->IsEnabled() )
466 if ( tool
->CanBeToggled() )
473 else if (event
.RightDown())
475 OnRightClick(tool
->GetId(), x
, y
);
478 // Left Button Released. Only this action confirms selection.
479 // If the button is enabled and it is not a toggle tool and it is
480 // in the pressed state, then raise the button and call OnLeftClick.
482 if ( event
.LeftUp() && tool
->IsEnabled() )
484 // Pass the OnLeftClick event to tool
485 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
486 tool
->CanBeToggled() )
488 // If it was a toggle, and OnLeftClick says No Toggle allowed,
489 // then change it back
497 // ----------------------------------------------------------------------------
499 // ----------------------------------------------------------------------------
501 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
507 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
509 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
514 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
515 wxPen
white_pen(wxT("WHITE"), 1, wxSOLID
);
516 wxPen
black_pen(wxT("BLACK"), 1, wxSOLID
);
518 wxBitmap bitmap
= tool
->GetNormalBitmap();
522 if ( !tool
->IsToggled() )
526 if (bitmap
.GetPalette())
527 memDC
.SetPalette(*bitmap
.GetPalette());
529 #endif // wxUSE_PALETTE
531 int ax
= (int)tool
->m_x
,
533 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
534 by
= (int)(tool
->m_y
+tool
->GetHeight());
536 memDC
.SelectObject(bitmap
);
537 if (m_windowStyle
& wxTB_3DBUTTONS
)
539 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
540 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
541 wxPen
* old_pen
= & dc
.GetPen();
542 dc
.SetPen( white_pen
);
543 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
544 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
545 dc
.SetPen( dark_grey_pen
);
546 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
547 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
548 dc
.SetPen( black_pen
);
549 dc
.DrawLine(bx
,ay
,bx
,by
);
550 dc
.DrawLine(bx
,by
,ax
,by
);
551 dc
.SetPen( *old_pen
);
552 dc
.DestroyClippingRegion();
553 // Select bitmap out of the DC
557 dc
.Blit(tool
->m_x
, tool
->m_y
,
558 bitmap
.GetWidth(), bitmap
.GetHeight(),
561 memDC
.SelectObject(wxNullBitmap
);
565 if (bitmap
.GetPalette())
566 memDC
.SetPalette(wxNullPalette
);
568 #endif // wxUSE_PALETTE
570 // No second bitmap, so draw a thick line around bitmap, or invert if mono
571 else if ( tool
->IsToggled() )
573 bool drawBorder
= FALSE
;
574 #ifdef __X__ // X doesn't invert properly on colour
575 drawBorder
= wxColourDisplay();
576 #else // Inversion works fine under Windows
582 memDC
.SelectObject(tool
->GetNormalBitmap());
583 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
584 &memDC
, 0, 0, wxSRC_INVERT
);
585 memDC
.SelectObject(wxNullBitmap
);
589 bitmap
= tool
->GetNormalBitmap();
591 if (m_windowStyle
& wxTB_3DBUTTONS
)
593 int ax
= (int)tool
->m_x
,
595 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
596 by
= (int)(tool
->m_y
+tool
->GetHeight());
598 memDC
.SelectObject(bitmap
);
599 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
600 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
601 wxPen
* old_pen
= & dc
.GetPen();
602 dc
.SetPen( black_pen
);
603 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
604 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
605 dc
.SetPen( dark_grey_pen
);
606 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
607 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
608 dc
.SetPen( white_pen
);
609 dc
.DrawLine(bx
,ay
,bx
,by
);
610 dc
.DrawLine(bx
,by
,ax
,by
);
611 dc
.SetPen( *old_pen
);
612 dc
.DestroyClippingRegion();
613 memDC
.SelectObject(wxNullBitmap
);
617 wxCoord x
= tool
->m_x
;
618 wxCoord y
= tool
->m_y
;
619 wxCoord w
= bitmap
.GetWidth();
620 wxCoord h
= bitmap
.GetHeight();
621 wxPen
thick_black_pen(wxT("BLACK"), 3, wxSOLID
);
623 memDC
.SelectObject(bitmap
);
624 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
625 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
627 dc
.SetPen(thick_black_pen
);
628 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
629 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
630 dc
.DestroyClippingRegion();
631 memDC
.SelectObject(wxNullBitmap
);
637 // ----------------------------------------------------------------------------
639 // ----------------------------------------------------------------------------
641 void wxToolBarSimple::SetRows(int nRows
)
643 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
645 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
651 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
654 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
657 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
658 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
659 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
660 (y
<= (tool
->m_y
+ tool
->GetHeight())))
665 node
= node
->GetNext();
668 return (wxToolBarToolBase
*)NULL
;
671 // ----------------------------------------------------------------------------
672 // tool state change handlers
673 // ----------------------------------------------------------------------------
675 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
676 bool WXUNUSED(enable
))
681 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
682 bool WXUNUSED(toggle
))
687 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
688 bool WXUNUSED(toggle
))
693 // Okay, so we've left the tool we're in ... we must check if the tool we're
694 // leaving was a 'sprung push button' and if so, spring it back to the up
696 void wxToolBarSimple::SpringUpButton(int id
)
698 wxToolBarToolBase
*tool
= FindById(id
);
700 if ( tool
&& tool
->CanBeToggled() )
702 if (tool
->IsToggled())
709 // ----------------------------------------------------------------------------
710 // scrolling implementation
711 // ----------------------------------------------------------------------------
714 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
715 * noUnitsX/noUnitsY: : no. units per scrollbar
717 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
718 int noUnitsX
, int noUnitsY
,
721 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
722 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
723 m_xScrollLines
= noUnitsX
;
724 m_yScrollLines
= noUnitsY
;
729 // Recalculate scroll bar range and position
730 if (m_xScrollLines
> 0)
732 m_xScrollPosition
= xPos
;
733 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
737 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
738 m_xScrollPosition
= 0;
741 if (m_yScrollLines
> 0)
743 m_yScrollPosition
= yPos
;
744 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
748 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
749 m_yScrollPosition
= 0;
754 #if 0 //def __WXMSW__
755 ::UpdateWindow ((HWND
) GetHWND());
759 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
761 int orient
= event
.GetOrientation();
763 int nScrollInc
= CalcScrollInc(event
);
767 if (orient
== wxHORIZONTAL
)
769 int newPos
= m_xScrollPosition
+ nScrollInc
;
770 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
774 int newPos
= m_yScrollPosition
+ nScrollInc
;
775 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
778 if (orient
== wxHORIZONTAL
)
780 if (m_xScrollingEnabled
)
781 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
787 if (m_yScrollingEnabled
)
788 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
793 if (orient
== wxHORIZONTAL
)
795 m_xScrollPosition
+= nScrollInc
;
799 m_yScrollPosition
+= nScrollInc
;
804 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
806 int pos
= event
.GetPosition();
807 int orient
= event
.GetOrientation();
810 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
812 if (orient
== wxHORIZONTAL
)
813 nScrollInc
= - m_xScrollPosition
;
815 nScrollInc
= - m_yScrollPosition
;
817 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
819 if (orient
== wxHORIZONTAL
)
820 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
822 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
824 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
828 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
832 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
834 if (orient
== wxHORIZONTAL
)
835 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
837 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
839 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
841 if (orient
== wxHORIZONTAL
)
842 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
844 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
846 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
847 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
849 if (orient
== wxHORIZONTAL
)
850 nScrollInc
= pos
- m_xScrollPosition
;
852 nScrollInc
= pos
- m_yScrollPosition
;
855 if (orient
== wxHORIZONTAL
)
858 GetClientSize(&w
, &h
);
860 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
861 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
865 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
866 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
867 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
868 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
875 GetClientSize(&w
, &h
);
877 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
878 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
882 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
883 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
884 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
885 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
891 // Adjust the scrollbars - new version.
892 void wxToolBarSimple::AdjustScrollbars()
895 GetClientSize(&w
, &h
);
897 // Recalculate scroll bar range and position
898 if (m_xScrollLines
> 0)
900 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
901 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
905 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
907 // Calculate page size i.e. number of scroll units you get on the
908 // current client window
909 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
910 if (noPagePositions
< 1)
913 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
914 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
916 if (m_yScrollLines
> 0)
918 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
919 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
923 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
925 // Calculate page size i.e. number of scroll units you get on the
926 // current client window
927 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
928 if (noPagePositions
< 1)
931 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
932 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
936 // Prepare the DC by translating it according to the current scroll position
937 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
939 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
942 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
944 *x_unit
= m_xScrollPixelsPerLine
;
945 *y_unit
= m_yScrollPixelsPerLine
;
948 int wxToolBarSimple::GetScrollPageSize(int orient
) const
950 if ( orient
== wxHORIZONTAL
)
951 return m_xScrollLinesPerPage
;
953 return m_yScrollLinesPerPage
;
956 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
958 if ( orient
== wxHORIZONTAL
)
959 m_xScrollLinesPerPage
= pageSize
;
961 m_yScrollLinesPerPage
= pageSize
;
965 * Scroll to given position (scroll position, not pixel position)
967 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
970 ViewStart (&old_x
, &old_y
);
971 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
976 m_xScrollPosition
= x_pos
;
977 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
981 m_yScrollPosition
= y_pos
;
982 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
986 #if 0 //def __WXMSW__
987 UpdateWindow ((HWND
) GetHWND());
991 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
993 m_xScrollingEnabled
= x_scroll
;
994 m_yScrollingEnabled
= y_scroll
;
997 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
999 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
1000 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
1003 // Where the current view starts from
1004 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
1006 *x
= m_xScrollPosition
;
1007 *y
= m_yScrollPosition
;
1010 #endif // wxUSE_TOOLBAR_SIMPLE