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 wxString
& label
,
52 const wxBitmap
& bmpNormal
,
53 const wxBitmap
& bmpDisabled
,
56 const wxString
& shortHelp
,
57 const wxString
& longHelp
)
58 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
59 clientData
, shortHelp
, longHelp
)
63 wxToolBarToolSimple(wxToolBarSimple
*tbar
, wxControl
*control
)
64 : wxToolBarToolBase(tbar
, control
)
68 void SetSize(const wxSize
& size
)
74 wxCoord
GetWidth() const { return m_width
; }
75 wxCoord
GetHeight() const { return m_height
; }
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple
, wxToolBarBase
)
89 #if !wxUSE_TOOLBAR_NATIVE
90 #include "wx/toolbar.h"
92 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarSimple
)
95 BEGIN_EVENT_TABLE(wxToolBarSimple
, wxToolBarBase
)
96 EVT_SIZE(wxToolBarSimple::OnSize
)
97 EVT_SCROLL(wxToolBarSimple::OnScroll
)
98 EVT_PAINT(wxToolBarSimple::OnPaint
)
99 EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus
)
100 EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent
)
103 // ============================================================================
105 // ============================================================================
107 // ----------------------------------------------------------------------------
108 // tool bar tools creation
109 // ----------------------------------------------------------------------------
111 wxToolBarToolBase
*wxToolBarSimple::CreateTool(int id
,
112 const wxString
& label
,
113 const wxBitmap
& bmpNormal
,
114 const wxBitmap
& bmpDisabled
,
116 wxObject
*clientData
,
117 const wxString
& shortHelp
,
118 const wxString
& longHelp
)
120 return new wxToolBarToolSimple(this, id
, label
, bmpNormal
, bmpDisabled
,
121 kind
, clientData
, shortHelp
, longHelp
);
124 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
126 return new wxToolBarToolSimple(this, control
);
129 // ----------------------------------------------------------------------------
130 // wxToolBarSimple creation
131 // ----------------------------------------------------------------------------
133 void wxToolBarSimple::Init()
135 m_currentRowsOrColumns
= 0;
150 m_toolSeparation
= 5;
153 m_defaultHeight
= 15;
155 m_xScrollPixelsPerLine
= 1;
156 m_yScrollPixelsPerLine
= 1;
157 m_xScrollingEnabled
= FALSE
;
158 m_yScrollingEnabled
= FALSE
;
159 m_xScrollPosition
= 0;
160 m_yScrollPosition
= 0;
163 m_xScrollLinesPerPage
= 0;
164 m_yScrollLinesPerPage
= 0;
167 wxToolBarToolBase
*wxToolBarSimple::DoAddTool(int id
,
168 const wxString
& label
,
169 const wxBitmap
& bitmap
,
170 const wxBitmap
& bmpDisabled
,
172 const wxString
& shortHelp
,
173 const wxString
& longHelp
,
174 wxObject
*clientData
,
178 // rememeber the position for DoInsertTool()
182 return wxToolBarBase::DoAddTool(id
, label
, bitmap
, bmpDisabled
, kind
,
184 clientData
, xPos
, yPos
);
187 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
188 wxToolBarToolBase
*toolBase
)
190 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
192 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
193 _T("generic wxToolBarSimple doesn't support controls") );
196 if ( tool
->m_x
== -1 )
197 tool
->m_x
= m_xMargin
;
200 if ( tool
->m_y
== -1 )
201 tool
->m_y
= m_yMargin
;
203 tool
->SetSize(GetToolSize());
205 if ( tool
->IsButton() )
207 // Calculate reasonable max size in case Layout() not called
208 if ((tool
->m_x
+ tool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_maxWidth
)
209 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
211 if ((tool
->m_y
+ tool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_maxHeight
)
212 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
218 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
219 wxToolBarToolBase
*tool
)
221 // VZ: didn't test whether it works, but why not...
229 bool wxToolBarSimple::Create(wxWindow
*parent
,
234 const wxString
& name
)
236 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
239 // Set it to grey (or other 3D face colour)
240 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
242 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
247 m_maxRows
= 32000; // a lot
256 m_maxCols
= 32000; // a lot
259 SetCursor(*wxSTANDARD_CURSOR
);
264 wxToolBarSimple::~wxToolBarSimple()
268 bool wxToolBarSimple::Realize()
270 m_currentRowsOrColumns
= 0;
276 int maxToolWidth
= 0;
277 int maxToolHeight
= 0;
279 // Find the maximum tool width and height
280 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
283 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
284 if ( tool
->GetWidth() > maxToolWidth
)
285 maxToolWidth
= tool
->GetWidth();
286 if (tool
->GetHeight() > maxToolHeight
)
287 maxToolHeight
= tool
->GetHeight();
289 node
= node
->GetNext();
292 int separatorSize
= m_toolSeparation
;
294 node
= m_tools
.GetFirst();
297 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
298 if ( tool
->IsSeparator() )
300 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
302 if (m_currentRowsOrColumns
>= m_maxCols
)
303 m_lastY
+= separatorSize
;
305 m_lastX
+= separatorSize
;
309 if (m_currentRowsOrColumns
>= m_maxRows
)
310 m_lastX
+= separatorSize
;
312 m_lastY
+= separatorSize
;
315 else if ( tool
->IsButton() )
317 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
319 if (m_currentRowsOrColumns
>= m_maxCols
)
321 m_currentRowsOrColumns
= 0;
323 m_lastY
+= maxToolHeight
+ m_toolPacking
;
325 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
326 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
328 m_lastX
+= maxToolWidth
+ m_toolPacking
;
332 if (m_currentRowsOrColumns
>= m_maxRows
)
334 m_currentRowsOrColumns
= 0;
335 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
338 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
339 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
341 m_lastY
+= maxToolHeight
+ m_toolPacking
;
343 m_currentRowsOrColumns
++;
347 // TODO: support the controls
350 if (m_lastX
> m_maxWidth
)
351 m_maxWidth
= m_lastX
;
352 if (m_lastY
> m_maxHeight
)
353 m_maxHeight
= m_lastY
;
355 node
= node
->GetNext();
358 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
359 m_maxWidth
+= maxToolWidth
;
361 m_maxHeight
+= maxToolHeight
;
363 m_maxWidth
+= m_xMargin
;
364 m_maxHeight
+= m_yMargin
;
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
373 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
378 static int count
= 0;
379 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
384 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
386 node
= node
->GetNext() )
388 wxToolBarToolBase
*tool
= node
->GetData();
389 if ( tool
->IsButton() )
396 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
398 #if wxUSE_CONSTRAINTS
406 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
408 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
411 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
414 event
.GetPosition(&x
, &y
);
415 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
417 if (event
.LeftDown())
428 if (m_currentTool
> -1)
430 if (event
.LeftIsDown())
431 SpringUpButton(m_currentTool
);
438 if (!event
.IsButton())
440 if ( tool
->GetId() != m_currentTool
)
442 // If the left button is kept down and moved over buttons,
443 // press those buttons.
444 if ( event
.LeftIsDown() && tool
->IsEnabled() )
446 SpringUpButton(m_currentTool
);
448 if ( tool
->CanBeToggled() )
456 m_currentTool
= tool
->GetId();
457 OnMouseEnter(m_currentTool
);
462 // Left button pressed.
463 if ( event
.LeftDown() && tool
->IsEnabled() )
465 if ( tool
->CanBeToggled() )
472 else if (event
.RightDown())
474 OnRightClick(tool
->GetId(), x
, y
);
477 // Left Button Released. Only this action confirms selection.
478 // If the button is enabled and it is not a toggle tool and it is
479 // in the pressed state, then raise the button and call OnLeftClick.
481 if ( event
.LeftUp() && tool
->IsEnabled() )
483 // Pass the OnLeftClick event to tool
484 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
485 tool
->CanBeToggled() )
487 // If it was a toggle, and OnLeftClick says No Toggle allowed,
488 // then change it back
496 // ----------------------------------------------------------------------------
498 // ----------------------------------------------------------------------------
500 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
506 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
508 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
513 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
514 wxPen
white_pen(wxT("WHITE"), 1, wxSOLID
);
515 wxPen
black_pen(wxT("BLACK"), 1, wxSOLID
);
517 wxBitmap bitmap
= tool
->GetBitmap();
523 if (bitmap
.GetPalette())
524 memDC
.SetPalette(*bitmap
.GetPalette());
526 #endif // wxUSE_PALETTE
528 int ax
= (int)tool
->m_x
,
530 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
531 by
= (int)(tool
->m_y
+tool
->GetHeight());
533 memDC
.SelectObject(bitmap
);
534 if (m_windowStyle
& wxTB_3DBUTTONS
)
536 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
537 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
538 wxPen
* old_pen
= & dc
.GetPen();
539 dc
.SetPen( white_pen
);
540 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
541 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
542 dc
.SetPen( dark_grey_pen
);
543 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
544 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
545 dc
.SetPen( black_pen
);
546 dc
.DrawLine(bx
,ay
,bx
,by
);
547 dc
.DrawLine(bx
,by
,ax
,by
);
548 dc
.SetPen( *old_pen
);
549 dc
.DestroyClippingRegion();
550 // Select bitmap out of the DC
554 dc
.Blit(tool
->m_x
, tool
->m_y
,
555 bitmap
.GetWidth(), bitmap
.GetHeight(),
558 memDC
.SelectObject(wxNullBitmap
);
562 if (bitmap
.GetPalette())
563 memDC
.SetPalette(wxNullPalette
);
565 #endif // wxUSE_PALETTE
567 // No second bitmap, so draw a thick line around bitmap, or invert if mono
568 else if ( tool
->IsToggled() )
570 bool drawBorder
= FALSE
;
571 #ifdef __X__ // X doesn't invert properly on colour
572 drawBorder
= wxColourDisplay();
573 #else // Inversion works fine under Windows
579 memDC
.SelectObject(tool
->GetNormalBitmap());
580 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
581 &memDC
, 0, 0, wxSRC_INVERT
);
582 memDC
.SelectObject(wxNullBitmap
);
586 bitmap
= tool
->GetNormalBitmap();
588 if (m_windowStyle
& wxTB_3DBUTTONS
)
590 int ax
= (int)tool
->m_x
,
592 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
593 by
= (int)(tool
->m_y
+tool
->GetHeight());
595 memDC
.SelectObject(bitmap
);
596 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
597 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
598 wxPen
* old_pen
= & dc
.GetPen();
599 dc
.SetPen( black_pen
);
600 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
601 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
602 dc
.SetPen( dark_grey_pen
);
603 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
604 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
605 dc
.SetPen( white_pen
);
606 dc
.DrawLine(bx
,ay
,bx
,by
);
607 dc
.DrawLine(bx
,by
,ax
,by
);
608 dc
.SetPen( *old_pen
);
609 dc
.DestroyClippingRegion();
610 memDC
.SelectObject(wxNullBitmap
);
614 wxCoord x
= tool
->m_x
;
615 wxCoord y
= tool
->m_y
;
616 wxCoord w
= bitmap
.GetWidth();
617 wxCoord h
= bitmap
.GetHeight();
618 wxPen
thick_black_pen(wxT("BLACK"), 3, wxSOLID
);
620 memDC
.SelectObject(bitmap
);
621 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
622 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
624 dc
.SetPen(thick_black_pen
);
625 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
626 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
627 dc
.DestroyClippingRegion();
628 memDC
.SelectObject(wxNullBitmap
);
634 // ----------------------------------------------------------------------------
636 // ----------------------------------------------------------------------------
638 void wxToolBarSimple::SetRows(int nRows
)
640 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
642 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
648 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
651 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
654 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
655 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
656 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
657 (y
<= (tool
->m_y
+ tool
->GetHeight())))
662 node
= node
->GetNext();
665 return (wxToolBarToolBase
*)NULL
;
668 // ----------------------------------------------------------------------------
669 // tool state change handlers
670 // ----------------------------------------------------------------------------
672 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
673 bool WXUNUSED(enable
))
678 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
679 bool WXUNUSED(toggle
))
684 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
685 bool WXUNUSED(toggle
))
690 // Okay, so we've left the tool we're in ... we must check if the tool we're
691 // leaving was a 'sprung push button' and if so, spring it back to the up
693 void wxToolBarSimple::SpringUpButton(int id
)
695 wxToolBarToolBase
*tool
= FindById(id
);
697 if ( tool
&& tool
->CanBeToggled() )
699 if (tool
->IsToggled())
706 // ----------------------------------------------------------------------------
707 // scrolling implementation
708 // ----------------------------------------------------------------------------
711 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
712 * noUnitsX/noUnitsY: : no. units per scrollbar
714 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
715 int noUnitsX
, int noUnitsY
,
718 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
719 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
720 m_xScrollLines
= noUnitsX
;
721 m_yScrollLines
= noUnitsY
;
726 // Recalculate scroll bar range and position
727 if (m_xScrollLines
> 0)
729 m_xScrollPosition
= xPos
;
730 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
734 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
735 m_xScrollPosition
= 0;
738 if (m_yScrollLines
> 0)
740 m_yScrollPosition
= yPos
;
741 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
745 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
746 m_yScrollPosition
= 0;
751 #if 0 //def __WXMSW__
752 ::UpdateWindow ((HWND
) GetHWND());
756 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
758 int orient
= event
.GetOrientation();
760 int nScrollInc
= CalcScrollInc(event
);
764 if (orient
== wxHORIZONTAL
)
766 int newPos
= m_xScrollPosition
+ nScrollInc
;
767 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
771 int newPos
= m_yScrollPosition
+ nScrollInc
;
772 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
775 if (orient
== wxHORIZONTAL
)
777 if (m_xScrollingEnabled
)
778 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
784 if (m_yScrollingEnabled
)
785 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
790 if (orient
== wxHORIZONTAL
)
792 m_xScrollPosition
+= nScrollInc
;
796 m_yScrollPosition
+= nScrollInc
;
801 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
803 int pos
= event
.GetPosition();
804 int orient
= event
.GetOrientation();
807 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
809 if (orient
== wxHORIZONTAL
)
810 nScrollInc
= - m_xScrollPosition
;
812 nScrollInc
= - m_yScrollPosition
;
814 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
816 if (orient
== wxHORIZONTAL
)
817 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
819 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
821 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
825 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
829 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
831 if (orient
== wxHORIZONTAL
)
832 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
834 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
836 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
838 if (orient
== wxHORIZONTAL
)
839 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
841 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
843 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
844 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
846 if (orient
== wxHORIZONTAL
)
847 nScrollInc
= pos
- m_xScrollPosition
;
849 nScrollInc
= pos
- m_yScrollPosition
;
852 if (orient
== wxHORIZONTAL
)
855 GetClientSize(&w
, &h
);
857 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
858 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
862 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
863 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
864 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
865 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
872 GetClientSize(&w
, &h
);
874 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
875 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
879 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
880 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
881 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
882 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
888 // Adjust the scrollbars - new version.
889 void wxToolBarSimple::AdjustScrollbars()
892 GetClientSize(&w
, &h
);
894 // Recalculate scroll bar range and position
895 if (m_xScrollLines
> 0)
897 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
898 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
902 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
904 // Calculate page size i.e. number of scroll units you get on the
905 // current client window
906 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
907 if (noPagePositions
< 1)
910 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
911 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
913 if (m_yScrollLines
> 0)
915 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
916 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
920 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
922 // Calculate page size i.e. number of scroll units you get on the
923 // current client window
924 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
925 if (noPagePositions
< 1)
928 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
929 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
933 // Prepare the DC by translating it according to the current scroll position
934 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
936 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
939 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
941 *x_unit
= m_xScrollPixelsPerLine
;
942 *y_unit
= m_yScrollPixelsPerLine
;
945 int wxToolBarSimple::GetScrollPageSize(int orient
) const
947 if ( orient
== wxHORIZONTAL
)
948 return m_xScrollLinesPerPage
;
950 return m_yScrollLinesPerPage
;
953 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
955 if ( orient
== wxHORIZONTAL
)
956 m_xScrollLinesPerPage
= pageSize
;
958 m_yScrollLinesPerPage
= pageSize
;
962 * Scroll to given position (scroll position, not pixel position)
964 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
967 ViewStart (&old_x
, &old_y
);
968 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
973 m_xScrollPosition
= x_pos
;
974 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
978 m_yScrollPosition
= y_pos
;
979 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
983 #if 0 //def __WXMSW__
984 UpdateWindow ((HWND
) GetHWND());
988 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
990 m_xScrollingEnabled
= x_scroll
;
991 m_yScrollingEnabled
= y_scroll
;
994 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
996 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
997 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
1000 // Where the current view starts from
1001 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
1003 *x
= m_xScrollPosition
;
1004 *y
= m_yScrollPosition
;
1007 #endif // wxUSE_TOOLBAR_SIMPLE