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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_SIMPLE
30 #include "wx/settings.h"
31 #include "wx/window.h"
32 #include "wx/dcclient.h"
33 #include "wx/dcmemory.h"
36 #include "wx/toolbar.h"
37 #include "wx/deprecated/tbarsmpl.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_DEPRECATED wxToolBarToolSimple
: public wxToolBarToolBase
46 wxToolBarToolSimple(wxToolBarSimple
*tbar
,
48 const wxString
& label
,
49 const wxBitmap
& bmpNormal
,
50 const wxBitmap
& bmpDisabled
,
53 const wxString
& shortHelp
,
54 const wxString
& longHelp
)
55 : wxToolBarToolBase(tbar
, id
, label
, bmpNormal
, bmpDisabled
, kind
,
56 clientData
, shortHelp
, longHelp
)
60 wxToolBarToolSimple(wxToolBarSimple
*tbar
, wxControl
*control
)
61 : wxToolBarToolBase(tbar
, control
)
65 void SetSize(const wxSize
& size
)
71 wxCoord
GetWidth() const { return m_width
; }
72 wxCoord
GetHeight() const { return m_height
; }
79 DECLARE_NO_COPY_CLASS(wxToolBarToolSimple
)
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple
, wxControl
)
88 #if !wxUSE_TOOLBAR_NATIVE && !defined(__WXUNIVERSAL__)
89 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarSimple
)
92 BEGIN_EVENT_TABLE(wxToolBarSimple
, wxToolBarBase
)
93 EVT_SIZE(wxToolBarSimple::OnSize
)
94 EVT_SCROLL(wxToolBarSimple::OnScroll
)
95 EVT_PAINT(wxToolBarSimple::OnPaint
)
96 EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus
)
97 EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent
)
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
105 // tool bar tools creation
106 // ----------------------------------------------------------------------------
108 wxToolBarToolBase
*wxToolBarSimple::CreateTool(int id
,
109 const wxString
& label
,
110 const wxBitmap
& bmpNormal
,
111 const wxBitmap
& bmpDisabled
,
113 wxObject
*clientData
,
114 const wxString
& shortHelp
,
115 const wxString
& longHelp
)
117 return new wxToolBarToolSimple(this, id
, label
, bmpNormal
, bmpDisabled
,
118 kind
, clientData
, shortHelp
, longHelp
);
121 wxToolBarToolBase
*wxToolBarSimple::CreateTool(wxControl
*control
)
123 return new wxToolBarToolSimple(this, control
);
126 // ----------------------------------------------------------------------------
127 // wxToolBarSimple creation
128 // ----------------------------------------------------------------------------
130 void wxToolBarSimple::Init()
132 m_currentRowsOrColumns
= 0;
144 m_yPos
= wxDefaultCoord
;
147 m_toolSeparation
= 5;
150 m_defaultHeight
= 15;
152 m_xScrollPixelsPerLine
= 1;
153 m_yScrollPixelsPerLine
= 1;
154 m_xScrollingEnabled
= false;
155 m_yScrollingEnabled
= false;
156 m_xScrollPosition
= 0;
157 m_yScrollPosition
= 0;
160 m_xScrollLinesPerPage
= 0;
161 m_yScrollLinesPerPage
= 0;
164 wxToolBarToolBase
*wxToolBarSimple::DoAddTool(int id
,
165 const wxString
& label
,
166 const wxBitmap
& bitmap
,
167 const wxBitmap
& bmpDisabled
,
169 const wxString
& shortHelp
,
170 const wxString
& longHelp
,
171 wxObject
*clientData
,
175 // rememeber the position for DoInsertTool()
179 return wxToolBarBase::DoAddTool(id
, label
, bitmap
, bmpDisabled
, kind
,
181 clientData
, xPos
, yPos
);
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
== wxDefaultCoord
)
194 tool
->m_x
= m_xMargin
;
197 if ( tool
->m_y
== wxDefaultCoord
)
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
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_maxWidth
)
206 m_maxWidth
= (wxCoord
)((tool
->m_x
+ tool
->GetWidth() + m_xMargin
));
208 if ((tool
->m_y
+ tool
->GetNormalBitmap().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 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
239 if ( GetWindowStyleFlag() & wxTB_VERTICAL
)
244 m_maxRows
= 32000; // a lot
253 m_maxCols
= 32000; // a lot
256 SetCursor(*wxSTANDARD_CURSOR
);
261 wxToolBarSimple::~wxToolBarSimple()
265 bool wxToolBarSimple::Realize()
267 m_currentRowsOrColumns
= 0;
273 int maxToolWidth
= 0;
274 int maxToolHeight
= 0;
276 // Find the maximum tool width and height
277 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
280 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
281 if ( tool
->GetWidth() > maxToolWidth
)
282 maxToolWidth
= tool
->GetWidth();
283 if (tool
->GetHeight() > maxToolHeight
)
284 maxToolHeight
= tool
->GetHeight();
286 node
= node
->GetNext();
289 int separatorSize
= m_toolSeparation
;
291 node
= m_tools
.GetFirst();
294 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
295 if ( tool
->IsSeparator() )
297 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
299 if (m_currentRowsOrColumns
>= m_maxCols
)
300 m_lastY
+= separatorSize
;
302 m_lastX
+= separatorSize
;
306 if (m_currentRowsOrColumns
>= m_maxRows
)
307 m_lastX
+= separatorSize
;
309 m_lastY
+= separatorSize
;
312 else if ( tool
->IsButton() )
314 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
316 if (m_currentRowsOrColumns
>= m_maxCols
)
318 m_currentRowsOrColumns
= 0;
320 m_lastY
+= maxToolHeight
+ m_toolPacking
;
322 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
323 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
325 m_lastX
+= maxToolWidth
+ m_toolPacking
;
329 if (m_currentRowsOrColumns
>= m_maxRows
)
331 m_currentRowsOrColumns
= 0;
332 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
335 tool
->m_x
= (wxCoord
)(m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
336 tool
->m_y
= (wxCoord
)(m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
338 m_lastY
+= maxToolHeight
+ m_toolPacking
;
340 m_currentRowsOrColumns
++;
344 // TODO: support the controls
347 if (m_lastX
> m_maxWidth
)
348 m_maxWidth
= m_lastX
;
349 if (m_lastY
> m_maxHeight
)
350 m_maxHeight
= m_lastY
;
352 node
= node
->GetNext();
355 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
356 m_maxHeight
+= maxToolHeight
;
358 m_maxWidth
+= maxToolWidth
;
360 m_maxWidth
+= m_xMargin
;
361 m_maxHeight
+= m_yMargin
;
363 SetSize(m_maxWidth
, m_maxHeight
);
368 // ----------------------------------------------------------------------------
370 // ----------------------------------------------------------------------------
372 void wxToolBarSimple::OnPaint (wxPaintEvent
& WXUNUSED(event
))
377 static int count
= 0;
378 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
383 for ( wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
385 node
= node
->GetNext() )
387 wxToolBarToolBase
*tool
= node
->GetData();
388 if ( tool
->IsButton() )
395 void wxToolBarSimple::OnSize (wxSizeEvent
& WXUNUSED(event
))
403 void wxToolBarSimple::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
405 OnMouseEnter(m_pressedTool
= m_currentTool
= -1);
408 void wxToolBarSimple::OnMouseEvent(wxMouseEvent
& event
)
411 event
.GetPosition(&x
, &y
);
412 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)FindToolForPosition(x
, y
);
414 if (event
.LeftDown())
425 if (m_currentTool
> -1)
427 if (event
.LeftIsDown())
428 SpringUpButton(m_currentTool
);
435 if (!event
.IsButton())
437 if ( tool
->GetId() != m_currentTool
)
439 // If the left button is kept down and moved over buttons,
440 // press those buttons.
441 if ( event
.LeftIsDown() && tool
->IsEnabled() )
443 SpringUpButton(m_currentTool
);
445 if ( tool
->CanBeToggled() )
453 m_currentTool
= tool
->GetId();
454 OnMouseEnter(m_currentTool
);
459 // Left button pressed.
460 if ( event
.LeftDown() && tool
->IsEnabled() )
462 if ( tool
->CanBeToggled() )
469 else if (event
.RightDown())
471 OnRightClick(tool
->GetId(), x
, y
);
474 // Left Button Released. Only this action confirms selection.
475 // If the button is enabled and it is not a toggle tool and it is
476 // in the pressed state, then raise the button and call OnLeftClick.
478 if ( event
.LeftUp() && tool
->IsEnabled() )
480 // Pass the OnLeftClick event to tool
481 if ( !OnLeftClick(tool
->GetId(), tool
->IsToggled()) &&
482 tool
->CanBeToggled() )
484 // If it was a toggle, and OnLeftClick says No Toggle allowed,
485 // then change it back
493 // ----------------------------------------------------------------------------
495 // ----------------------------------------------------------------------------
497 void wxToolBarSimple::DrawTool(wxToolBarToolBase
*tool
)
503 void wxToolBarSimple::DrawTool(wxDC
& dc
, wxToolBarToolBase
*toolBase
)
505 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)toolBase
;
510 wxPen
dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID
);
511 wxPen
white_pen(wxT("WHITE"), 1, wxSOLID
);
512 wxPen
black_pen(wxT("BLACK"), 1, wxSOLID
);
514 wxBitmap bitmap
= tool
->GetNormalBitmap();
518 if ( !tool
->IsToggled() )
522 if (bitmap
.GetPalette())
523 memDC
.SetPalette(*bitmap
.GetPalette());
525 #endif // wxUSE_PALETTE
527 int ax
= (int)tool
->m_x
,
529 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
530 by
= (int)(tool
->m_y
+tool
->GetHeight());
532 memDC
.SelectObject(bitmap
);
533 if (m_windowStyle
& wxTB_3DBUTTONS
)
535 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
536 dc
.Blit((ax
+1), (ay
+1), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
537 wxPen
* old_pen
= & dc
.GetPen();
538 dc
.SetPen( white_pen
);
539 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
540 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
541 dc
.SetPen( dark_grey_pen
);
542 dc
.DrawLine((bx
-1),(ay
+1),(bx
-1),(by
-1));
543 dc
.DrawLine((bx
-1),(by
-1),(ax
+1),(by
-1));
544 dc
.SetPen( black_pen
);
545 dc
.DrawLine(bx
,ay
,bx
,by
);
546 dc
.DrawLine(bx
,by
,ax
,by
);
547 dc
.SetPen( *old_pen
);
548 dc
.DestroyClippingRegion();
549 // Select bitmap out of the DC
553 dc
.Blit(tool
->m_x
, tool
->m_y
,
554 bitmap
.GetWidth(), bitmap
.GetHeight(),
557 memDC
.SelectObject(wxNullBitmap
);
561 if (bitmap
.GetPalette())
562 memDC
.SetPalette(wxNullPalette
);
564 #endif // wxUSE_PALETTE
566 // No second bitmap, so draw a thick line around bitmap, or invert if mono
567 else if ( tool
->IsToggled() )
569 bool drawBorder
= false;
570 #ifdef __X__ // X doesn't invert properly on colour
571 drawBorder
= wxColourDisplay();
572 #else // Inversion works fine under Windows
578 memDC
.SelectObject(tool
->GetNormalBitmap());
579 dc
.Blit(tool
->m_x
, tool
->m_y
, tool
->GetWidth(), tool
->GetHeight(),
580 &memDC
, 0, 0, wxSRC_INVERT
);
581 memDC
.SelectObject(wxNullBitmap
);
585 bitmap
= tool
->GetNormalBitmap();
587 if (m_windowStyle
& wxTB_3DBUTTONS
)
589 int ax
= (int)tool
->m_x
,
591 bx
= (int)(tool
->m_x
+tool
->GetWidth()),
592 by
= (int)(tool
->m_y
+tool
->GetHeight());
594 memDC
.SelectObject(bitmap
);
595 dc
.SetClippingRegion(ax
, ay
, (bx
-ax
+1), (by
-ay
+1));
596 dc
.Blit((ax
+2), (ay
+2), (bx
-ax
-2), (by
-ay
-2), &memDC
, 0, 0);
597 wxPen
* old_pen
= & dc
.GetPen();
598 dc
.SetPen( black_pen
);
599 dc
.DrawLine(ax
,(by
-1),ax
,ay
);
600 dc
.DrawLine(ax
,ay
,(bx
-1),ay
);
601 dc
.SetPen( dark_grey_pen
);
602 dc
.DrawLine((ax
+1),(by
-2),(ax
+1),(ay
+1));
603 dc
.DrawLine((ax
+1),(ay
+1),(bx
-2),(ay
+1));
604 dc
.SetPen( white_pen
);
605 dc
.DrawLine(bx
,ay
,bx
,by
);
606 dc
.DrawLine(bx
,by
,ax
,by
);
607 dc
.SetPen( *old_pen
);
608 dc
.DestroyClippingRegion();
609 memDC
.SelectObject(wxNullBitmap
);
613 wxCoord x
= tool
->m_x
;
614 wxCoord y
= tool
->m_y
;
615 wxCoord w
= bitmap
.GetWidth();
616 wxCoord h
= bitmap
.GetHeight();
617 wxPen
thick_black_pen(wxT("BLACK"), 3, wxSOLID
);
619 memDC
.SelectObject(bitmap
);
620 dc
.SetClippingRegion(tool
->m_x
, tool
->m_y
, w
, h
);
621 dc
.Blit(tool
->m_x
, tool
->m_y
, w
, h
,
623 dc
.SetPen(thick_black_pen
);
624 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
625 dc
.DrawRectangle(x
, y
, w
-1, h
-1);
626 dc
.DestroyClippingRegion();
627 memDC
.SelectObject(wxNullBitmap
);
633 // ----------------------------------------------------------------------------
635 // ----------------------------------------------------------------------------
637 void wxToolBarSimple::SetRows(int nRows
)
639 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
641 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
647 wxToolBarToolBase
*wxToolBarSimple::FindToolForPosition(wxCoord x
,
650 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
653 wxToolBarToolSimple
*tool
= (wxToolBarToolSimple
*)node
->GetData();
654 if ((x
>= tool
->m_x
) && (y
>= tool
->m_y
) &&
655 (x
<= (tool
->m_x
+ tool
->GetWidth())) &&
656 (y
<= (tool
->m_y
+ tool
->GetHeight())))
661 node
= node
->GetNext();
664 return (wxToolBarToolBase
*)NULL
;
667 // ----------------------------------------------------------------------------
668 // tool state change handlers
669 // ----------------------------------------------------------------------------
671 void wxToolBarSimple::DoEnableTool(wxToolBarToolBase
*tool
,
672 bool WXUNUSED(enable
))
677 void wxToolBarSimple::DoToggleTool(wxToolBarToolBase
*tool
,
678 bool WXUNUSED(toggle
))
683 void wxToolBarSimple::DoSetToggle(wxToolBarToolBase
* WXUNUSED(tool
),
684 bool WXUNUSED(toggle
))
689 // Okay, so we've left the tool we're in ... we must check if the tool we're
690 // leaving was a 'sprung push button' and if so, spring it back to the up
692 void wxToolBarSimple::SpringUpButton(int id
)
694 wxToolBarToolBase
*tool
= FindById(id
);
696 if ( tool
&& tool
->CanBeToggled() )
698 if (tool
->IsToggled())
705 // ----------------------------------------------------------------------------
706 // scrolling implementation
707 // ----------------------------------------------------------------------------
710 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
711 * noUnitsX/noUnitsY: : no. units per scrollbar
713 void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
714 int noUnitsX
, int noUnitsY
,
717 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
718 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
719 m_xScrollLines
= noUnitsX
;
720 m_yScrollLines
= noUnitsY
;
725 // Recalculate scroll bar range and position
726 if (m_xScrollLines
> 0)
728 m_xScrollPosition
= xPos
;
729 SetScrollPos (wxHORIZONTAL
, m_xScrollPosition
, true);
733 SetScrollbar(wxHORIZONTAL
, 0, 0, 0, false);
734 m_xScrollPosition
= 0;
737 if (m_yScrollLines
> 0)
739 m_yScrollPosition
= yPos
;
740 SetScrollPos (wxVERTICAL
, m_yScrollPosition
, true);
744 SetScrollbar(wxVERTICAL
, 0, 0, 0, false);
745 m_yScrollPosition
= 0;
750 #if 0 //def __WXMSW__
751 ::UpdateWindow ((HWND
) GetHWND());
755 void wxToolBarSimple::OnScroll(wxScrollEvent
& event
)
757 int orient
= event
.GetOrientation();
759 int nScrollInc
= CalcScrollInc(event
);
763 if (orient
== wxHORIZONTAL
)
765 int newPos
= m_xScrollPosition
+ nScrollInc
;
766 SetScrollPos(wxHORIZONTAL
, newPos
, true );
770 int newPos
= m_yScrollPosition
+ nScrollInc
;
771 SetScrollPos(wxVERTICAL
, newPos
, true );
774 if (orient
== wxHORIZONTAL
)
776 if (m_xScrollingEnabled
)
777 ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, NULL
);
783 if (m_yScrollingEnabled
)
784 ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, NULL
);
789 if (orient
== wxHORIZONTAL
)
791 m_xScrollPosition
+= nScrollInc
;
795 m_yScrollPosition
+= nScrollInc
;
800 int wxToolBarSimple::CalcScrollInc(wxScrollEvent
& event
)
802 int pos
= event
.GetPosition();
803 int orient
= event
.GetOrientation();
806 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
808 if (orient
== wxHORIZONTAL
)
809 nScrollInc
= - m_xScrollPosition
;
811 nScrollInc
= - m_yScrollPosition
;
813 if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
815 if (orient
== wxHORIZONTAL
)
816 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
818 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
820 if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
824 if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
828 if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
830 if (orient
== wxHORIZONTAL
)
831 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
833 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
835 if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
837 if (orient
== wxHORIZONTAL
)
838 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
840 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
842 if ((event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
) ||
843 (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
))
845 if (orient
== wxHORIZONTAL
)
846 nScrollInc
= pos
- m_xScrollPosition
;
848 nScrollInc
= pos
- m_yScrollPosition
;
851 if (orient
== wxHORIZONTAL
)
854 GetClientSize(&w
, &h
);
856 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
857 int noPositions
= (int) ( ((nMaxWidth
- w
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
861 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
862 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
863 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
864 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
871 GetClientSize(&w
, &h
);
873 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
874 int noPositions
= (int) ( ((nMaxHeight
- h
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
878 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
879 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
880 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
881 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
887 // Adjust the scrollbars - new version.
888 void wxToolBarSimple::AdjustScrollbars()
891 GetClientSize(&w
, &h
);
893 // Recalculate scroll bar range and position
894 if (m_xScrollLines
> 0)
896 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
897 int newRange
= (int) ( ((nMaxWidth
)/(float)m_xScrollPixelsPerLine
) + 0.5 );
901 m_xScrollPosition
= wxMin(newRange
, m_xScrollPosition
);
903 // Calculate page size i.e. number of scroll units you get on the
904 // current client window
905 int noPagePositions
= (int) ( (w
/(float)m_xScrollPixelsPerLine
) + 0.5 );
906 if (noPagePositions
< 1)
909 SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, newRange
);
910 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
912 if (m_yScrollLines
> 0)
914 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
915 int newRange
= (int) ( ((nMaxHeight
)/(float)m_yScrollPixelsPerLine
) + 0.5 );
919 m_yScrollPosition
= wxMin(newRange
, m_yScrollPosition
);
921 // Calculate page size i.e. number of scroll units you get on the
922 // current client window
923 int noPagePositions
= (int) ( (h
/(float)m_yScrollPixelsPerLine
) + 0.5 );
924 if (noPagePositions
< 1)
927 SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, newRange
);
928 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
932 // Prepare the DC by translating it according to the current scroll position
933 void wxToolBarSimple::PrepareDC(wxDC
& dc
)
935 dc
.SetDeviceOrigin(- m_xScrollPosition
* m_xScrollPixelsPerLine
, - m_yScrollPosition
* m_yScrollPixelsPerLine
);
938 void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
940 *x_unit
= m_xScrollPixelsPerLine
;
941 *y_unit
= m_yScrollPixelsPerLine
;
944 int wxToolBarSimple::GetScrollPageSize(int orient
) const
946 if ( orient
== wxHORIZONTAL
)
947 return m_xScrollLinesPerPage
;
949 return m_yScrollLinesPerPage
;
952 void wxToolBarSimple::SetScrollPageSize(int orient
, int pageSize
)
954 if ( orient
== wxHORIZONTAL
)
955 m_xScrollLinesPerPage
= pageSize
;
957 m_yScrollLinesPerPage
= pageSize
;
961 * Scroll to given position (scroll position, not pixel position)
963 void wxToolBarSimple::Scroll (int x_pos
, int y_pos
)
966 ViewStart (&old_x
, &old_y
);
967 if (((x_pos
== wxDefaultCoord
) || (x_pos
== old_x
)) && ((y_pos
== wxDefaultCoord
) || (y_pos
== old_y
)))
970 if (x_pos
!= wxDefaultCoord
)
972 m_xScrollPosition
= x_pos
;
973 SetScrollPos (wxHORIZONTAL
, x_pos
, true);
975 if (y_pos
!= wxDefaultCoord
)
977 m_yScrollPosition
= y_pos
;
978 SetScrollPos (wxVERTICAL
, y_pos
, true);
982 #if 0 //def __WXMSW__
983 UpdateWindow ((HWND
) GetHWND());
987 void wxToolBarSimple::EnableScrolling (bool x_scroll
, bool y_scroll
)
989 m_xScrollingEnabled
= x_scroll
;
990 m_yScrollingEnabled
= y_scroll
;
993 void wxToolBarSimple::GetVirtualSize (int *x
, int *y
) const
995 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
996 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
999 // Where the current view starts from
1000 void wxToolBarSimple::ViewStart (int *x
, int *y
) const
1002 *x
= m_xScrollPosition
;
1003 *y
= m_yScrollPosition
;
1006 #endif // wxUSE_TOOLBAR_SIMPLE