1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/toolbar.cpp
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE
17 #include "wx/toolbar.h"
20 #include "wx/settings.h"
21 #include "wx/window.h"
24 #include "wx/dcclient.h"
25 #include "wx/dcmemory.h"
28 #include "wx/tooltip.h"
29 #include "wx/os2/dcclient.h"
31 bool wxToolBar::m_bInitialized
= false;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class wxToolBarTool
: public wxToolBarToolBase
40 inline wxToolBarTool( wxToolBar
* pTbar
42 ,const wxString
& rsLabel
43 ,const wxBitmap
& rBitmap1
44 ,const wxBitmap
& rBitmap2
46 ,wxObject
* pClientData
47 ,const wxString
& rsShortHelpString
48 ,const wxString
& rsLongHelpString
49 ) : wxToolBarToolBase( pTbar
62 inline wxToolBarTool( wxToolBar
* pTbar
64 ,const wxString
& label
65 ) : wxToolBarToolBase( pTbar
72 void SetSize(const wxSize
& rSize
)
78 wxCoord
GetWidth(void) const { return m_vWidth
; }
79 wxCoord
GetHeight(void) const { return m_vHeight
; }
85 }; // end of CLASS wxToolBarTool
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
93 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
94 EVT_SIZE(wxToolBar::OnSize
)
95 EVT_PAINT(wxToolBar::OnPaint
)
96 EVT_KILL_FOCUS(wxToolBar::OnKillFocus
)
97 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
98 EVT_TIMER(-1, wxToolBar::OnTimer
)
101 // ============================================================================
103 // ============================================================================
105 // ----------------------------------------------------------------------------
106 // tool bar tools creation
107 // ----------------------------------------------------------------------------
109 wxToolBarToolBase
* wxToolBar::CreateTool(
111 , const wxString
& rsLabel
112 , const wxBitmap
& rBmpNormal
113 , const wxBitmap
& rBmpDisabled
115 , wxObject
* pClientData
116 , const wxString
& rsShortHelp
117 , const wxString
& rsLongHelp
120 return new wxToolBarTool( this
130 } // end of wxToolBarSimple::CreateTool
132 wxToolBarToolBase
*wxToolBar::CreateTool(
134 , const wxString
& label
137 return new wxToolBarTool( this
141 } // end of wxToolBarSimple::CreateTool
143 // ----------------------------------------------------------------------------
144 // wxToolBarSimple creation
145 // ----------------------------------------------------------------------------
147 void wxToolBar::Init()
149 m_nCurrentRowsOrColumns
= 0;
151 m_vLastX
= m_vLastY
= 0;
152 m_vMaxWidth
= m_vMaxHeight
= 0;
153 m_nPressedTool
= m_nCurrentTool
= -1;
154 m_vXPos
= m_vYPos
= -1;
155 m_vTextX
= m_vTextY
= 0;
158 m_toolSeparation
= 5;
161 m_defaultHeight
= 15;
164 } // end of wxToolBar::Init
166 wxToolBarToolBase
* wxToolBar::DoAddTool(
168 , const wxString
& rsLabel
169 , const wxBitmap
& rBitmap
170 , const wxBitmap
& rBmpDisabled
172 , const wxString
& rsShortHelp
173 , const wxString
& rsLongHelp
174 , wxObject
* pClientData
180 // Rememeber the position for DoInsertTool()
185 return wxToolBarBase::DoAddTool( vId
196 } // end of wxToolBar::DoAddTool
198 bool wxToolBar::DeleteTool(
202 bool bOk
= wxToolBarBase::DeleteTool(nId
);
209 } // end of wxToolBar::DeleteTool
211 bool wxToolBar::DeleteToolByPos(
215 bool bOk
= wxToolBarBase::DeleteToolByPos(nPos
);
222 } // end of wxToolBar::DeleteTool
224 wxToolBarToolBase
* wxToolBar::InsertControl(
226 , wxControl
* pControl
229 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertControl( nPos
238 } // end of wxToolBar::InsertControl
240 wxToolBarToolBase
* wxToolBar::InsertSeparator(
244 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertSeparator(nPos
);
252 } // end of wxToolBar::InsertSeparator
254 wxToolBarToolBase
* wxToolBar::InsertTool(
257 , const wxString
& rsLabel
258 , const wxBitmap
& rBitmap
259 , const wxBitmap
& rBmpDisabled
261 , const wxString
& rsShortHelp
262 , const wxString
& rsLongHelp
263 , wxObject
* pClientData
266 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertTool( nPos
282 } // end of wxToolBar::InsertTool
284 bool wxToolBar::DoInsertTool( size_t WXUNUSED(nPos
),
285 wxToolBarToolBase
* pToolBase
)
287 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
289 pTool
->m_vX
= m_vXPos
;
290 if (pTool
->m_vX
== -1)
291 pTool
->m_vX
= m_xMargin
;
293 pTool
->m_vY
= m_vYPos
;
294 if (pTool
->m_vY
== -1)
295 pTool
->m_vX
= m_yMargin
;
297 pTool
->SetSize(GetToolSize());
299 if (pTool
->IsButton())
302 // Calculate reasonable max size in case Layout() not called
304 if ((pTool
->m_vX
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
)
305 m_vMaxWidth
= (wxCoord
)((pTool
->m_vX
+ pTool
->GetWidth() + m_xMargin
));
307 if ((pTool
->m_vY
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
)
308 m_vMaxHeight
= (wxCoord
)((pTool
->m_vY
+ pTool
->GetHeight() + m_yMargin
));
311 } // end of wxToolBar::DoInsertTool
313 bool wxToolBar::DoDeleteTool( size_t WXUNUSED(nPos
),
314 wxToolBarToolBase
* pTool
)
319 } // end of wxToolBar::DoDeleteTool
321 bool wxToolBar::Create( wxWindow
* pParent
,
326 const wxString
& rsName
)
328 if ( !wxWindow::Create( pParent
337 // Set it to grey (or other 3D face colour)
338 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
339 SetFont(*wxSMALL_FONT
);
341 if (GetWindowStyleFlag() & (wxTB_LEFT
| wxTB_RIGHT
))
346 m_maxRows
= 32000; // a lot
355 m_maxCols
= 32000; // a lot
357 SetCursor(*wxSTANDARD_CURSOR
);
360 // The toolbar's tools, if they have labels and the winTB_TEXT
361 // style is set, then we need to take into account the size of
362 // the text when drawing tool bitmaps and the text
364 if (HasFlag(wxTB_TEXT
))
366 wxClientDC
vDC(this);
368 vDC
.SetFont(GetFont());
369 vDC
.GetTextExtent( wxT("XXXX")
380 int nWidth
= rSize
.x
;
381 int nHeight
= rSize
.y
;
383 if (lStyle
& (wxTB_TOP
| wxTB_BOTTOM
))
387 nWidth
= pParent
->GetClientSize().x
;
391 if (lStyle
& wxTB_TEXT
)
392 nHeight
= m_defaultHeight
+ m_vTextY
;
394 nHeight
= m_defaultHeight
;
401 nHeight
= pParent
->GetClientSize().y
;
405 if (lStyle
& wxTB_TEXT
)
406 nWidth
= m_vTextX
+ (int)(m_vTextX
/2); // a little margin
408 nWidth
= m_defaultWidth
+ (int)(m_defaultWidth
/2); // a little margin
422 } // end of wxToolBar::Create
424 wxToolBar::~wxToolBar()
426 wxDELETE(m_pToolTip
);
427 } // end of wxToolBar::~wxToolBar
429 bool wxToolBar::Realize()
431 int nMaxToolWidth
= 0;
432 int nMaxToolHeight
= 0;
434 m_nCurrentRowsOrColumns
= 0;
435 m_vLastX
= m_xMargin
;
436 m_vLastY
= m_yMargin
;
442 // Find the maximum tool width and height
444 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
448 wxToolBarTool
* pTool
= (wxToolBarTool
*)node
->GetData();
450 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty())
453 // Set the height according to the font and the border size
455 if (pTool
->GetWidth() > m_vTextX
)
456 nMaxToolWidth
= pTool
->GetWidth() + 4;
458 nMaxToolWidth
= m_vTextX
;
459 if (pTool
->GetHeight() + m_vTextY
> nMaxToolHeight
)
460 nMaxToolHeight
= pTool
->GetHeight() + m_vTextY
;
464 if (pTool
->GetWidth() > nMaxToolWidth
)
465 nMaxToolWidth
= pTool
->GetWidth() + 4;
466 if (pTool
->GetHeight() > nMaxToolHeight
)
467 nMaxToolHeight
= pTool
->GetHeight();
469 node
= node
->GetNext();
472 wxCoord vTbWidth
= 0L;
473 wxCoord vTbHeight
= 0L;
478 if (vTbHeight
< nMaxToolHeight
)
485 if (GetParent()->IsKindOf(CLASSINFO(wxFrame
)))
487 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
490 pFrame
->PositionToolBar();
494 int nSeparatorSize
= m_toolSeparation
;
496 node
= m_tools
.GetFirst();
499 wxToolBarTool
* pTool
= (wxToolBarTool
*)node
->GetData();
501 if (pTool
->IsSeparator())
503 if (GetWindowStyleFlag() & (wxTB_TOP
| wxTB_BOTTOM
))
505 pTool
->m_vX
= m_vLastX
+ nSeparatorSize
;
506 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
507 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
508 m_vLastY
+= nSeparatorSize
;
510 m_vLastX
+= nSeparatorSize
* 4;
514 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
;
515 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
516 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
517 m_vLastX
+= nSeparatorSize
;
519 m_vLastY
+= nSeparatorSize
* 4;
522 else if (pTool
->IsButton())
524 if (GetWindowStyleFlag() & (wxTB_TOP
| wxTB_BOTTOM
))
526 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
528 m_nCurrentRowsOrColumns
= 0;
529 m_vLastX
= m_xMargin
;
530 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
;
532 pTool
->m_vX
= m_vLastX
+ (nMaxToolWidth
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2)));
533 if (HasFlag(wxTB_TEXT
))
534 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
- 2; // just bit of adjustment
536 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
537 m_vLastX
+= nMaxToolWidth
+ m_toolPacking
+ m_toolSeparation
;
541 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
543 m_nCurrentRowsOrColumns
= 0;
544 m_vLastX
+= (nMaxToolWidth
+ m_toolPacking
);
545 m_vLastY
= m_yMargin
;
547 pTool
->m_vX
= m_vLastX
+ pTool
->GetWidth();
548 if ( HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty() )
549 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- m_vTextY
) + m_toolPacking
;
551 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
552 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
+ m_toolSeparation
;
554 m_nCurrentRowsOrColumns
++;
558 // TODO: support the controls
561 if (m_vLastX
> m_maxWidth
)
562 m_maxWidth
= m_vLastX
;
563 if (m_vLastY
> m_maxHeight
)
564 m_maxHeight
= m_vLastY
;
566 node
= node
->GetNext();
569 if (GetWindowStyleFlag() & (wxTB_TOP
| wxTB_BOTTOM
))
570 m_maxWidth
+= nMaxToolWidth
;
572 m_maxHeight
+= nMaxToolHeight
;
574 m_maxWidth
+= m_xMargin
;
575 m_maxHeight
+= m_yMargin
;
576 m_bInitialized
= true;
578 } // end of wxToolBar::Realize
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
584 void wxToolBar::OnPaint (
585 wxPaintEvent
& WXUNUSED(rEvent
)
592 static int nCount
= 0;
595 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
601 wxPMDCImpl
*impl
= (wxPMDCImpl
*) vDc
.GetImpl();
602 ::WinFillRect(impl
->GetHPS(), &impl
->m_vRclPaint
, GetBackgroundColour().GetPixel());
603 for ( wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
605 node
= node
->GetNext() )
607 wxToolBarTool
* pTool
= (wxToolBarTool
*)node
->GetData();
609 if (pTool
->IsButton() )
610 DrawTool(vDc
, pTool
);
611 if (pTool
->IsSeparator())
613 wxColour
gray85(85, 85, 85);
614 wxPen
vDarkGreyPen( gray85
, 1, wxSOLID
);
620 vDc
.SetPen(vDarkGreyPen
);
621 if (HasFlag(wxTB_TEXT
))
623 if (HasFlag(wxTB_TOP
) || HasFlag(wxTB_BOTTOM
))
626 nY
= pTool
->m_vY
- (m_vTextY
- 6);
627 nHeight
= (m_vTextY
- 2) + pTool
->GetHeight();
631 nX
= pTool
->m_vX
+ m_xMargin
+ 10;
632 nY
= pTool
->m_vY
+ m_vTextY
+ m_toolSeparation
;
633 nWidth
= pTool
->GetWidth() > m_vTextX
? pTool
->GetWidth() : m_vTextX
;
640 if (HasFlag(wxTB_TOP
) || HasFlag(wxTB_BOTTOM
))
641 nHeight
= pTool
->GetHeight() - 2;
644 nX
+= m_xMargin
+ 10;
645 nY
+= m_yMargin
+ m_toolSeparation
;
646 nWidth
= pTool
->GetWidth();
649 vDc
.DrawLine(nX
, nY
, nX
+ nWidth
, nY
+ nHeight
);
653 } // end of wxToolBar::OnPaint
655 void wxToolBar::OnSize (
656 wxSizeEvent
& WXUNUSED(rEvent
)
659 #if wxUSE_CONSTRAINTS
663 } // end of wxToolBar::OnSize
665 void wxToolBar::OnKillFocus(
666 wxFocusEvent
& WXUNUSED(rEvent
)
669 OnMouseEnter(m_nPressedTool
= m_nCurrentTool
= -1);
670 } // end of wxToolBar::OnKillFocus
672 void wxToolBar::OnMouseEvent(
680 HPOINTER hPtr
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
);
682 ::WinSetPointer(HWND_DESKTOP
, hPtr
);
683 ::WinQueryPointerPos(HWND_DESKTOP
, &vPoint
);
684 hWnd
= ::WinWindowFromPoint(HWND_DESKTOP
, &vPoint
, TRUE
);
685 if (hWnd
!= (HWND
)GetHwnd())
691 rEvent
.GetPosition(&vX
, &vY
);
693 wxToolBarTool
* pTool
= (wxToolBarTool
*)FindToolForPosition( vX
697 if (rEvent
.LeftDown())
709 if (m_nCurrentTool
> -1)
711 if (rEvent
.LeftIsDown())
712 SpringUpButton(m_nCurrentTool
);
713 pTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
714 if (pTool
&& !pTool
->IsToggled())
716 RaiseTool( pTool
, FALSE
);
723 if (!rEvent
.IsButton())
725 if (pTool
->GetId() != m_nCurrentTool
)
728 // If the left button is kept down and moved over buttons,
729 // press those buttons.
731 if (rEvent
.LeftIsDown() && pTool
->IsEnabled())
733 SpringUpButton(m_nCurrentTool
);
734 if (pTool
->CanBeToggled())
740 wxToolBarTool
* pOldTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
742 if (pOldTool
&& !pTool
->IsToggled())
743 RaiseTool( pOldTool
, FALSE
);
744 m_nCurrentTool
= pTool
->GetId();
745 OnMouseEnter(m_nCurrentTool
);
746 if (!pTool
->GetShortHelp().empty())
750 m_pToolTip
= new wxToolTip(pTool
->GetShortHelp());
751 m_vXMouse
= (wxCoord
)vPoint
.x
;
752 m_vYMouse
= (wxCoord
)vPoint
.y
;
753 m_vToolTimer
.Start(1000L, TRUE
);
755 if (!pTool
->IsToggled())
761 // Left button pressed.
762 if (rEvent
.LeftDown() && pTool
->IsEnabled())
764 if (pTool
->CanBeToggled())
770 else if (rEvent
.RightDown())
772 OnRightClick( pTool
->GetId()
779 // Left Button Released. Only this action confirms selection.
780 // If the button is enabled and it is not a toggle tool and it is
781 // in the pressed state, then raise the button and call OnLeftClick.
783 if (rEvent
.LeftUp() && pTool
->IsEnabled() )
786 // Pass the OnLeftClick event to tool
788 if (!OnLeftClick( pTool
->GetId()
789 ,pTool
->IsToggled()) &&
790 pTool
->CanBeToggled())
793 // If it was a toggle, and OnLeftClick says No Toggle allowed,
794 // then change it back
800 } // end of wxToolBar::OnMouseEvent
802 // ----------------------------------------------------------------------------
804 // ----------------------------------------------------------------------------
806 void wxToolBar::DrawTool( wxToolBarToolBase
* pTool
)
808 wxClientDC
vDc(this);
810 DrawTool( vDc
, pTool
);
811 } // end of wxToolBar::DrawTool
813 void wxToolBar::DrawTool( wxDC
& rDc
, wxToolBarToolBase
* pToolBase
)
815 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
816 wxColour
gray85( 85,85,85 );
817 wxPen
vDarkGreyPen( gray85
, 1, wxSOLID
);
818 wxBitmap vBitmap
= pTool
->GetNormalBitmap();
819 bool bUseMask
= false;
820 wxMask
* pMask
= NULL
;
826 if ((pMask
= vBitmap
.GetMask()) != NULL
)
827 if (pMask
->GetMaskBitmap() != NULLHANDLE
)
830 if (!pTool
->IsToggled())
832 LowerTool(pTool
, FALSE
);
833 if (!pTool
->IsEnabled())
835 wxColour
vColor(wxT("GREY"));
837 rDc
.SetTextForeground(vColor
);
838 if (!pTool
->GetDisabledBitmap().Ok())
839 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
840 ,(long)GetBackgroundColour().GetPixel()
842 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
850 rDc
.SetTextForeground(*wxBLACK
);
851 rDc
.DrawBitmap( vBitmap
857 if (m_windowStyle
& wxTB_3DBUTTONS
)
861 if ( HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty() )
865 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
867 rDc
.SetFont(GetFont());
868 rDc
.GetTextExtent( pTool
->GetLabel()
872 if (pTool
->GetWidth() > vX
) // large tools
874 vLeft
= pTool
->m_vX
+ (pTool
->GetWidth() - vX
);
876 rDc
.DrawText( pTool
->GetLabel()
883 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
884 rDc
.DrawText( pTool
->GetLabel()
886 ,pTool
->m_vY
+ m_vTextY
- 1 // a bit of margin
893 wxColour
vColor(wxT("GREY"));
896 rDc
.SetTextForeground(vColor
);
897 if (!pTool
->GetDisabledBitmap().Ok())
898 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
899 ,(long)GetBackgroundColour().GetPixel()
901 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
906 if ( HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty() )
910 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
912 rDc
.SetFont(GetFont());
913 rDc
.GetTextExtent( pTool
->GetLabel()
917 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
918 rDc
.DrawText( pTool
->GetLabel()
920 ,pTool
->m_vY
+ m_vTextY
- 1 // a bit of margin
924 } // end of wxToolBar::DrawTool
926 // ----------------------------------------------------------------------------
928 // ----------------------------------------------------------------------------
930 void wxToolBar::SetRows(
934 wxCHECK_RET( nRows
!= 0, wxT("max number of rows must be > 0") );
936 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
938 } // end of wxToolBar::SetRows
940 wxToolBarToolBase
* wxToolBar::FindToolForPosition(
945 wxCoord vTBarHeight
= 0;
950 vY
= vTBarHeight
- vY
;
951 wxToolBarToolsList::compatibility_iterator node
= m_tools
.GetFirst();
954 wxToolBarTool
* pTool
= (wxToolBarTool
*)node
->GetData();
956 if ( HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty() )
958 if ((vX
>= (pTool
->m_vX
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) &&
959 (vY
>= (pTool
->m_vY
- 2)) &&
960 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
961 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight() + m_vTextY
+ 2)))
968 if ((vX
>= pTool
->m_vX
) &&
969 (vY
>= pTool
->m_vY
) &&
970 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
971 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight())))
976 node
= node
->GetNext();
979 } // end of wxToolBar::FindToolForPosition
981 // ----------------------------------------------------------------------------
982 // tool state change handlers
983 // ----------------------------------------------------------------------------
985 void wxToolBar::DoEnableTool(
986 wxToolBarToolBase
* pTool
987 , bool WXUNUSED(bEnable
)
991 } // end of wxToolBar::DoEnableTool
993 void wxToolBar::DoToggleTool(
994 wxToolBarToolBase
* pTool
995 , bool WXUNUSED(bToggle
)
999 } // end of wxToolBar::DoToggleTool
1001 void wxToolBar::DoSetToggle(
1002 wxToolBarToolBase
* WXUNUSED(pTool
)
1003 , bool WXUNUSED(bToggle
)
1007 } // end of wxToolBar::DoSetToggle
1010 // Okay, so we've left the tool we're in ... we must check if the tool we're
1011 // leaving was a 'sprung push button' and if so, spring it back to the up
1014 void wxToolBar::SpringUpButton(
1018 wxToolBarToolBase
* pTool
= FindById(vId
);
1020 if (pTool
&& pTool
->CanBeToggled())
1022 if (pTool
->IsToggled())
1027 } // end of wxToolBar::SpringUpButton
1029 // ----------------------------------------------------------------------------
1031 // ----------------------------------------------------------------------------
1033 void wxToolBar::LowerTool ( wxToolBarToolBase
* pToolBase
,
1036 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1041 wxColour
gray85( 85,85,85 );
1042 wxPen
vDarkGreyPen( gray85
, 1, wxSOLID
);
1043 wxPen
vClearPen( GetBackgroundColour(), 1, wxSOLID
);
1044 wxClientDC
vDC(this);
1049 if (pTool
->IsSeparator())
1053 // We only do this for flat toolbars
1055 if (!HasFlag(wxTB_FLAT
))
1058 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty())
1060 if (pTool
->GetWidth() > m_vTextX
)
1062 vX
= pTool
->m_vX
- 2;
1063 vWidth
= pTool
->GetWidth() + 4;
1067 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1068 vWidth
= m_vTextX
+ 4;
1070 vY
= pTool
->m_vY
- 2;
1071 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1075 vX
= pTool
->m_vX
- 2;
1076 vY
= pTool
->m_vY
- 2;
1077 vWidth
= pTool
->GetWidth() + 4;
1078 vHeight
= pTool
->GetHeight() + 4;
1082 vDC
.SetPen(*wxWHITE_PEN
);
1083 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1084 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1085 vDC
.SetPen(vDarkGreyPen
);
1086 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1087 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1091 vDC
.SetPen(vClearPen
);
1092 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1093 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1094 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1095 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1097 } // end of WinGuiBase_CToolBarTool::LowerTool
1099 void wxToolBar::RaiseTool ( wxToolBarToolBase
* pToolBase
,
1102 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1107 wxColour
gray85( 85,85,85 );
1108 wxPen
vDarkGreyPen( gray85
, 1, wxSOLID
);
1109 wxPen
vClearPen( GetBackgroundColour(), 1, wxSOLID
);
1110 wxClientDC
vDC(this);
1115 if (pTool
->IsSeparator())
1118 if (!pTool
->IsEnabled())
1122 // We only do this for flat toolbars
1124 if (!HasFlag(wxTB_FLAT
))
1127 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().empty())
1129 if (pTool
->GetWidth() > m_vTextX
)
1131 vX
= pTool
->m_vX
- 2;
1132 vWidth
= pTool
->GetWidth() + 4;
1136 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1137 vWidth
= m_vTextX
+ 4;
1139 vY
= pTool
->m_vY
- 2;
1140 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1144 vX
= pTool
->m_vX
- 2;
1145 vY
= pTool
->m_vY
- 2;
1146 vWidth
= pTool
->GetWidth() + 4;
1147 vHeight
= pTool
->GetHeight() + 4;
1151 vDC
.SetPen(vDarkGreyPen
);
1152 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1153 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1154 vDC
.SetPen(*wxWHITE_PEN
);
1155 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1156 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1160 vDC
.SetPen(vClearPen
);
1161 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1162 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1163 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1164 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1166 } // end of wxToolBar::RaiseTool
1168 void wxToolBar::OnTimer ( wxTimerEvent
& rEvent
)
1170 if (rEvent
.GetId() == m_vToolTimer
.GetId())
1172 wxPoint
vPos( m_vXMouse
, m_vYMouse
);
1174 m_pToolTip
->DisplayToolTipWindow(vPos
);
1175 m_vToolTimer
.Stop();
1176 m_vToolExpTimer
.Start(4000L, TRUE
);
1178 else if (rEvent
.GetId() == m_vToolExpTimer
.GetId())
1180 m_pToolTip
->HideToolTipWindow();
1181 GetParent()->Refresh();
1182 m_vToolExpTimer
.Stop();
1184 } // end of wxToolBar::OnTimer
1186 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE