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
; }
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple
, wxToolBarBase
)
90 #if !wxUSE_TOOLBAR_NATIVE && !defined(__WXUNIVERSAL__)
91 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarSimple
)
94 BEGIN_EVENT_TABLE(wxToolBarSimple
, wxToolBarBase
)
95 EVT_SIZE(wxToolBarSimple::OnSize
)
96 EVT_SCROLL(wxToolBarSimple::OnScroll
)
97 EVT_PAINT(wxToolBarSimple::OnPaint
)
98 EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus
)
99 EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent
)
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
107 // tool bar tools creation
108 // ----------------------------------------------------------------------------
110 wxToolBarToolBase
*wxToolBarSimple::CreateTool(int id
,
111 const wxString
& label
,
112 const wxBitmap
& bmpNormal
,
113 const wxBitmap
& bmpDisabled
,
115 wxObject
*clientData
,
116 const wxString
& shortHelp
,
117 const wxString
& longHelp
)
119 return new wxToolBarToolSimple(this, id
, label
, bmpNormal
, bmpDisabled
,
120 kind
, clientData
, shortHelp
, longHelp
);
123 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
125 return new wxToolBarToolSimple(this, control
);
128 // ----------------------------------------------------------------------------
129 // wxToolBarSimple creation
130 // ----------------------------------------------------------------------------
132 void wxToolBarSimple::Init()
134 m_currentRowsOrColumns
= 0;
149 m_toolSeparation
= 5;
152 m_defaultHeight
= 15;
154 m_xScrollPixelsPerLine
= 1;
155 m_yScrollPixelsPerLine
= 1;
156 m_xScrollingEnabled
= FALSE
;
157 m_yScrollingEnabled
= FALSE
;
158 m_xScrollPosition
= 0;
159 m_yScrollPosition
= 0;
162 m_xScrollLinesPerPage
= 0;
163 m_yScrollLinesPerPage
= 0;
166 wxToolBarToolBase
*wxToolBarSimple::DoAddTool(int id
,
167 const wxString
& label
,
168 const wxBitmap
& bitmap
,
169 const wxBitmap
& bmpDisabled
,
171 const wxString
& shortHelp
,
172 const wxString
& longHelp
,
173 wxObject
*clientData
,
177 // rememeber the position for DoInsertTool()
181 return wxToolBarBase::DoAddTool(id
, label
, bitmap
, bmpDisabled
, kind
,
183 clientData
, xPos
, yPos
);
186 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
187 wxToolBarToolBase
*toolBase
)
189 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
191 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
192 _T("generic wxToolBarSimple doesn't support controls") );
195 if ( tool
->m_x
== -1 )
196 tool
->m_x
= m_xMargin
;
199 if ( tool
->m_y
== -1 )
200 tool
->m_y
= m_yMargin
;
202 tool
->SetSize(GetToolSize());
204 if ( tool
->IsButton() )
206 // Calculate reasonable max size in case Layout() not called
207 if ((tool
->m_x
+ tool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_maxWidth
)
208 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
210 if ((tool
->m_y
+ tool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_maxHeight
)
211 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
217 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
218 wxToolBarToolBase
*tool
)
220 // VZ: didn't test whether it works, but why not...
228 bool wxToolBarSimple::Create(wxWindow
*parent
,
233 const wxString
& name
)
235 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
238 // Set it to grey (or other 3D face colour)
239 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
241 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
246 m_maxRows
= 32000; // a lot
255 m_maxCols
= 32000; // a lot
258 SetCursor(*wxSTANDARD_CURSOR
);
263 wxToolBarSimple::~wxToolBarSimple()
267 bool wxToolBarSimple::Realize()
269 m_currentRowsOrColumns
= 0;
275 int maxToolWidth
= 0;
276 int maxToolHeight
= 0;
278 // Find the maximum tool width and height
279 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
282 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
283 if ( tool
->GetWidth() > maxToolWidth
)
284 maxToolWidth
= tool
->GetWidth();
285 if (tool
->GetHeight() > maxToolHeight
)
286 maxToolHeight
= tool
->GetHeight();
288 node
= node
->GetNext();
291 int separatorSize
= m_toolSeparation
;
293 node
= m_tools
.GetFirst();
296 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
297 if ( tool
->IsSeparator() )
299 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
301 if (m_currentRowsOrColumns
>= m_maxCols
)
302 m_lastY
+= separatorSize
;
304 m_lastX
+= separatorSize
;
308 if (m_currentRowsOrColumns
>= m_maxRows
)
309 m_lastX
+= separatorSize
;
311 m_lastY
+= separatorSize
;
314 else if ( tool
->IsButton() )
316 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
318 if (m_currentRowsOrColumns
>= m_maxCols
)
320 m_currentRowsOrColumns
= 0;
322 m_lastY
+= maxToolHeight
+ m_toolPacking
;
324 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
325 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
327 m_lastX
+= maxToolWidth
+ m_toolPacking
;
331 if (m_currentRowsOrColumns
>= m_maxRows
)
333 m_currentRowsOrColumns
= 0;
334 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
337 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
338 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
340 m_lastY
+= maxToolHeight
+ m_toolPacking
;
342 m_currentRowsOrColumns
++;
346 // TODO: support the controls
349 if (m_lastX
> m_maxWidth
)
350 m_maxWidth
= m_lastX
;
351 if (m_lastY
> m_maxHeight
)
352 m_maxHeight
= m_lastY
;
354 node
= node
->GetNext();
357 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
358 m_maxHeight
+= maxToolHeight
;
360 m_maxWidth
+= maxToolWidth
;
362 m_maxWidth
+= m_xMargin
;
363 m_maxHeight
+= m_yMargin
;
365 SetSize(m_maxWidth
, m_maxHeight
);
370 // ----------------------------------------------------------------------------
372 // ----------------------------------------------------------------------------
374 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
379 static int count
= 0;
380 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
385 for ( wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
387 node
= node
->GetNext() )
389 wxToolBarToolBase
*tool
= node
->GetData();
390 if ( tool
->IsButton() )
397 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
399 #if wxUSE_CONSTRAINTS
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