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 #if !wxUSE_TOOLBAR_NATIVE || defined(__WXUNIVERSAL__)
89 #include "wx/toolbar.h"
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 wxBitmap
& bitmap1
,
112 const wxBitmap
& bitmap2
,
114 wxObject
*clientData
,
115 const wxString
& shortHelpString
,
116 const wxString
& longHelpString
)
118 return new wxToolBarToolSimple(this, id
, bitmap1
, bitmap2
, toggle
,
119 clientData
, shortHelpString
, longHelpString
);
122 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
124 return new wxToolBarToolSimple(this, control
);
127 // ----------------------------------------------------------------------------
128 // wxToolBarSimple creation
129 // ----------------------------------------------------------------------------
131 void wxToolBarSimple::Init()
133 m_currentRowsOrColumns
= 0;
148 m_toolSeparation
= 5;
151 m_defaultHeight
= 15;
153 m_xScrollPixelsPerLine
= 1;
154 m_yScrollPixelsPerLine
= 1;
155 m_xScrollingEnabled
= FALSE
;
156 m_yScrollingEnabled
= FALSE
;
157 m_xScrollPosition
= 0;
158 m_yScrollPosition
= 0;
161 m_xScrollLinesPerPage
= 0;
162 m_yScrollLinesPerPage
= 0;
165 wxToolBarToolBase
*wxToolBarSimple::AddTool(int id
,
166 const wxBitmap
& bitmap
,
167 const wxBitmap
& pushedBitmap
,
171 wxObject
*clientData
,
172 const wxString
& helpString1
,
173 const wxString
& helpString2
)
175 // rememeber the position for DoInsertTool()
179 return wxToolBarBase::AddTool(id
, bitmap
, pushedBitmap
, toggle
,
180 xPos
, yPos
, clientData
,
181 helpString1
, helpString2
);
184 bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos
),
185 wxToolBarToolBase
*toolBase
)
187 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
189 wxCHECK_MSG( !tool
->IsControl(), FALSE
,
190 _T("generic wxToolBarSimple doesn't support controls") );
193 if ( tool
->m_x
== -1 )
194 tool
->m_x
= m_xMargin
;
197 if ( tool
->m_y
== -1 )
198 tool
->m_y
= m_yMargin
;
200 tool
->SetSize(GetToolSize());
202 if ( tool
->IsButton() )
204 // Calculate reasonable max size in case Layout() not called
205 if ((tool
->m_x
+ tool
->GetBitmap1().GetWidth() + m_xMargin
) > m_maxWidth
)
206 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
208 if ((tool
->m_y
+ tool
->GetBitmap1().GetHeight() + m_yMargin
) > m_maxHeight
)
209 m_maxHeight
= (wxCoord
)((tool
->m_y
+ tool
->GetHeight() + m_yMargin
));
215 bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos
),
216 wxToolBarToolBase
*tool
)
218 // VZ: didn't test whether it works, but why not...
226 bool wxToolBarSimple::Create(wxWindow
*parent
,
231 const wxString
& name
)
233 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
236 // Set it to grey (or other 3D face colour)
237 wxSystemSettings settings
;
238 SetBackgroundColour(settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
));
240 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
245 m_maxRows
= 32000; // a lot
254 m_maxCols
= 32000; // a lot
257 SetCursor(*wxSTANDARD_CURSOR
);
262 wxToolBarSimple::~wxToolBarSimple()
266 bool wxToolBarSimple::Realize()
268 m_currentRowsOrColumns
= 0;
274 int maxToolWidth
= 0;
275 int maxToolHeight
= 0;
277 // Find the maximum tool width and height
278 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
281 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
282 if ( tool
->GetWidth() > maxToolWidth
)
283 maxToolWidth
= tool
->GetWidth();
284 if (tool
->GetHeight() > maxToolHeight
)
285 maxToolHeight
= tool
->GetHeight();
287 node
= node
->GetNext();
290 int separatorSize
= m_toolSeparation
;
292 node
= m_tools
.GetFirst();
295 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
296 if ( tool
->IsSeparator() )
298 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
300 if (m_currentRowsOrColumns
>= m_maxCols
)
301 m_lastY
+= separatorSize
;
303 m_lastX
+= separatorSize
;
307 if (m_currentRowsOrColumns
>= m_maxRows
)
308 m_lastX
+= separatorSize
;
310 m_lastY
+= separatorSize
;
313 else if ( tool
->IsButton() )
315 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
317 if (m_currentRowsOrColumns
>= m_maxCols
)
319 m_currentRowsOrColumns
= 0;
321 m_lastY
+= maxToolHeight
+ m_toolPacking
;
323 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
324 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
326 m_lastX
+= maxToolWidth
+ m_toolPacking
;
330 if (m_currentRowsOrColumns
>= m_maxRows
)
332 m_currentRowsOrColumns
= 0;
333 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
336 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
337 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
339 m_lastY
+= maxToolHeight
+ m_toolPacking
;
341 m_currentRowsOrColumns
++;
345 // TODO: support the controls
348 if (m_lastX
> m_maxWidth
)
349 m_maxWidth
= m_lastX
;
350 if (m_lastY
> m_maxHeight
)
351 m_maxHeight
= m_lastY
;
353 node
= node
->GetNext();
356 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
357 m_maxWidth
+= maxToolWidth
;
359 m_maxHeight
+= maxToolHeight
;
361 m_maxWidth
+= m_xMargin
;
362 m_maxHeight
+= m_yMargin
;
367 // ----------------------------------------------------------------------------
369 // ----------------------------------------------------------------------------
371 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
376 static int count
= 0;
377 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
382 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
384 node
= node
->GetNext() )
386 wxToolBarToolBase
*tool
= node
->GetData();
387 if ( tool
->IsButton() )
394 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
396 #if wxUSE_CONSTRAINTS
404 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
406 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
409 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
412 event
.GetPosition(&x
, &y
);
413 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
415 if (event
.LeftDown())
426 if (m_currentTool
> -1)
428 if (event
.LeftIsDown())
429 SpringUpButton(m_currentTool
);
436 if (!event
.IsButton())
438 if ( tool
->GetId() != m_currentTool
)
440 // If the left button is kept down and moved over buttons,
441 // press those buttons.
442 if ( event
.LeftIsDown() && tool
->IsEnabled() )
444 SpringUpButton(m_currentTool
);
446 if ( tool
->CanBeToggled() )
454 m_currentTool
= tool
->GetId();
455 OnMouseEnter(m_currentTool
);
460 // Left button pressed.
461 if ( event
.LeftDown() && tool
->IsEnabled() )
463 if ( tool
->CanBeToggled() )
470 else if (event
.RightDown())
472 OnRightClick(tool
->GetId(), x
, y
);
475 // Left Button Released. Only this action confirms selection.
476 // If the button is enabled and it is not a toggle tool and it is
477 // in the pressed state, then raise the button and call OnLeftClick.
479 if ( event
.LeftUp() && tool
->IsEnabled() )
481 // Pass the OnLeftClick event to tool
482 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
483 tool
->CanBeToggled() )
485 // If it was a toggle, and OnLeftClick says No Toggle allowed,
486 // then change it back
494 // ----------------------------------------------------------------------------
496 // ----------------------------------------------------------------------------
498 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
504 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
506 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
511 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
512 wxPen
white_pen(wxT("WHITE"), 1, wxSOLID
);
513 wxPen
black_pen(wxT("BLACK"), 1, wxSOLID
);
515 wxBitmap bitmap
= tool
->GetBitmap();
521 if (bitmap
.GetPalette())
522 memDC
.SetPalette(*bitmap
.GetPalette());
524 #endif // wxUSE_PALETTE
526 int ax
= (int)tool
->m_x
,
528 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
529 by
= (int)(tool
->m_y
+tool
->GetHeight());
531 memDC
.SelectObject(bitmap
);
532 if (m_windowStyle
& wxTB_3DBUTTONS
)
534 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
535 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
536 wxPen
* old_pen
= & dc
.GetPen();
537 dc
.SetPen( white_pen
);
538 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
539 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
540 dc
.SetPen( dark_grey_pen
);
541 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
542 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
543 dc
.SetPen( black_pen
);
544 dc
.DrawLine(bx
,ay
,bx
,by
);
545 dc
.DrawLine(bx
,by
,ax
,by
);
546 dc
.SetPen( *old_pen
);
547 dc
.DestroyClippingRegion();
548 // Select bitmap out of the DC
552 dc
.Blit(tool
->m_x
, tool
->m_y
,
553 bitmap
.GetWidth(), bitmap
.GetHeight(),
556 memDC
.SelectObject(wxNullBitmap
);
560 if (bitmap
.GetPalette())
561 memDC
.SetPalette(wxNullPalette
);
563 #endif // wxUSE_PALETTE
565 // No second bitmap, so draw a thick line around bitmap, or invert if mono
566 else if ( tool
->IsToggled() )
568 bool drawBorder
= FALSE
;
569 #ifdef __X__ // X doesn't invert properly on colour
570 drawBorder
= wxColourDisplay();
571 #else // Inversion works fine under Windows
577 memDC
.SelectObject(tool
->GetBitmap1());
578 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
579 &memDC
, 0, 0, wxSRC_INVERT
);
580 memDC
.SelectObject(wxNullBitmap
);
584 bitmap
= tool
->GetBitmap1();
586 if (m_windowStyle
& wxTB_3DBUTTONS
)
588 int ax
= (int)tool
->m_x
,
590 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
591 by
= (int)(tool
->m_y
+tool
->GetHeight());
593 memDC
.SelectObject(bitmap
);
594 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
595 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
596 wxPen
* old_pen
= & dc
.GetPen();
597 dc
.SetPen( black_pen
);
598 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
599 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
600 dc
.SetPen( dark_grey_pen
);
601 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
602 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
603 dc
.SetPen( white_pen
);
604 dc
.DrawLine(bx
,ay
,bx
,by
);
605 dc
.DrawLine(bx
,by
,ax
,by
);
606 dc
.SetPen( *old_pen
);
607 dc
.DestroyClippingRegion();
608 memDC
.SelectObject(wxNullBitmap
);
612 wxCoord x
= tool
->m_x
;
613 wxCoord y
= tool
->m_y
;
614 wxCoord w
= bitmap
.GetWidth();
615 wxCoord h
= bitmap
.GetHeight();
616 wxPen
thick_black_pen(wxT("BLACK"), 3, wxSOLID
);
618 memDC
.SelectObject(bitmap
);
619 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
620 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
622 dc
.SetPen(thick_black_pen
);
623 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
624 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
625 dc
.DestroyClippingRegion();
626 memDC
.SelectObject(wxNullBitmap
);
632 // ----------------------------------------------------------------------------
634 // ----------------------------------------------------------------------------
636 void wxToolBarSimple::SetRows(int nRows
)
638 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
640 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
646 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
649 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
652 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
653 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
654 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
655 (y
<= (tool
->m_y
+ tool
->GetHeight())))
660 node
= node
->GetNext();
663 return (wxToolBarToolBase
*)NULL
;
666 // ----------------------------------------------------------------------------
667 // tool state change handlers
668 // ----------------------------------------------------------------------------
670 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
671 bool WXUNUSED(enable
))
676 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
677 bool WXUNUSED(toggle
))
682 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
683 bool WXUNUSED(toggle
))
688 // Okay, so we've left the tool we're in ... we must check if the tool we're
689 // leaving was a 'sprung push button' and if so, spring it back to the up
691 void wxToolBarSimple::SpringUpButton(int id
)
693 wxToolBarToolBase
*tool
= FindById(id
);
695 if ( tool
&& tool
->CanBeToggled() )
697 if (tool
->IsToggled())
704 // ----------------------------------------------------------------------------
705 // scrolling implementation
706 // ----------------------------------------------------------------------------
709 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
710 * noUnitsX/noUnitsY: : no. units per scrollbar
712 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
713 int noUnitsX
, int noUnitsY
,
716 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
717 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
718 m_xScrollLines
= noUnitsX
;
719 m_yScrollLines
= noUnitsY
;
724 // Recalculate scroll bar range and position
725 if (m_xScrollLines
> 0)
727 m_xScrollPosition
= xPos
;
728 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, TRUE
);
732 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, FALSE
);
733 m_xScrollPosition
= 0;
736 if (m_yScrollLines
> 0)
738 m_yScrollPosition
= yPos
;
739 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, TRUE
);
743 SetScrollbar(wxVERTICAL
, 0, 0, 0, FALSE
);
744 m_yScrollPosition
= 0;
749 #if 0 //def __WXMSW__
750 ::UpdateWindow ((HWND
) GetHWND());
754 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
756 int orient
= event
.GetOrientation();
758 int nScrollInc
= CalcScrollInc(event
);
762 if (orient
== wxHORIZONTAL
)
764 int newPos
= m_xScrollPosition
+ nScrollInc
;
765 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
769 int newPos
= m_yScrollPosition
+ nScrollInc
;
770 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
773 if (orient
== wxHORIZONTAL
)
775 if (m_xScrollingEnabled
)
776 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
782 if (m_yScrollingEnabled
)
783 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
788 if (orient
== wxHORIZONTAL
)
790 m_xScrollPosition
+= nScrollInc
;
794 m_yScrollPosition
+= nScrollInc
;
799 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
801 int pos
= event
.GetPosition();
802 int orient
= event
.GetOrientation();
805 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
807 if (orient
== wxHORIZONTAL
)
808 nScrollInc
= - m_xScrollPosition
;
810 nScrollInc
= - m_yScrollPosition
;
812 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
814 if (orient
== wxHORIZONTAL
)
815 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
817 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
819 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
823 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
827 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
829 if (orient
== wxHORIZONTAL
)
830 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
832 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
834 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
836 if (orient
== wxHORIZONTAL
)
837 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
839 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
841 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
842 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
844 if (orient
== wxHORIZONTAL
)
845 nScrollInc
= pos
- m_xScrollPosition
;
847 nScrollInc
= pos
- m_yScrollPosition
;
850 if (orient
== wxHORIZONTAL
)
853 GetClientSize(&w
, &h
);
855 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
856 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
860 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
861 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
862 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
863 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
870 GetClientSize(&w
, &h
);
872 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
873 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
877 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
878 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
879 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
880 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
886 // Adjust the scrollbars - new version.
887 void wxToolBarSimple::AdjustScrollbars()
890 GetClientSize(&w
, &h
);
892 // Recalculate scroll bar range and position
893 if (m_xScrollLines
> 0)
895 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
896 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
900 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
902 // Calculate page size i.e. number of scroll units you get on the
903 // current client window
904 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
905 if (noPagePositions
< 1)
908 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
909 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
911 if (m_yScrollLines
> 0)
913 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
914 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
918 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
920 // Calculate page size i.e. number of scroll units you get on the
921 // current client window
922 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
923 if (noPagePositions
< 1)
926 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
927 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
931 // Prepare the DC by translating it according to the current scroll position
932 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
934 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
937 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
939 *x_unit
= m_xScrollPixelsPerLine
;
940 *y_unit
= m_yScrollPixelsPerLine
;
943 int wxToolBarSimple::GetScrollPageSize(int orient
) const
945 if ( orient
== wxHORIZONTAL
)
946 return m_xScrollLinesPerPage
;
948 return m_yScrollLinesPerPage
;
951 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
953 if ( orient
== wxHORIZONTAL
)
954 m_xScrollLinesPerPage
= pageSize
;
956 m_yScrollLinesPerPage
= pageSize
;
960 * Scroll to given position (scroll position, not pixel position)
962 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
965 ViewStart (&old_x
, &old_y
);
966 if (((x_pos
== -1) || (x_pos
== old_x
)) && ((y_pos
== -1) || (y_pos
== old_y
)))
971 m_xScrollPosition
= x_pos
;
972 SetScrollPos (wxHORIZONTAL
, x_pos
, TRUE
);
976 m_yScrollPosition
= y_pos
;
977 SetScrollPos (wxVERTICAL
, y_pos
, TRUE
);
981 #if 0 //def __WXMSW__
982 UpdateWindow ((HWND
) GetHWND());
986 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
988 m_xScrollingEnabled
= x_scroll
;
989 m_yScrollingEnabled
= y_scroll
;
992 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
994 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
995 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
998 // Where the current view starts from
999 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
1001 *x
= m_xScrollPosition
;
1002 *y
= m_yScrollPosition
;
1005 #endif // wxUSE_TOOLBAR_SIMPLE