1 /////////////////////////////////////////////////////////////////////////////
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
18 #include "wx/settings.h"
19 #include "wx/window.h"
22 #include "wx/dcclient.h"
23 #include "wx/dcmemory.h"
26 #include "wx/tooltip.h"
27 #include "wx/toolbar.h"
29 bool wxToolBar::m_bInitialized
= FALSE
;
31 // ---------------------------------------------------------------------------
32 // Helper for taking a regular bitmap and giving it a disabled look
33 // ---------------------------------------------------------------------------
34 wxBitmap
wxDisableBitmap(
39 wxMask
* pMask
= rBmp
.GetMask();
44 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
46 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
47 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
48 BITMAPINFOHEADER2 vHeader
;
52 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
53 HBITMAP hOldBitmap
= NULLHANDLE
;
54 HBITMAP hOldMask
= NULLHANDLE
;
55 HBITMAP hMask
= (HBITMAP
)rBmp
.GetMask()->GetMaskBitmap();
56 unsigned char* pucBits
; // buffer that will contain the bitmap data
57 unsigned char* pucData
; // pointer to use to traverse bitmap data
58 unsigned char* pucBitsMask
; // buffer that will contain the mask data
59 unsigned char* pucDataMask
; // pointer to use to traverse mask data
62 bool bpp16
= (wxDisplayDepth() == 16);
64 memset(&vHeader
, '\0', 16);
67 memset(&vInfo
, '\0', 16);
69 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
70 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
72 vInfo
.cBitCount
= 24; // Set to desired count going in
75 // Create the buffers for data....all wxBitmaps are 24 bit internally
77 int nBytesPerLine
= rBmp
.GetWidth() * 3;
78 int nSizeDWORD
= sizeof(DWORD
);
79 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
85 // Bitmap must be ina double-word alligned address so we may
86 // have some padding to worry about
88 if (nLineBoundary
> 0)
90 nPadding
= nSizeDWORD
- nLineBoundary
;
91 nBytesPerLine
+= nPadding
;
93 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
94 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
95 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
96 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
99 // Extract the bitmap and mask data
101 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
103 vError
= ::WinGetLastError(vHabmain
);
104 sError
= wxPMErrorToStr(vError
);
106 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
107 vInfo
.cBitCount
= 24;
108 if ((lScans
= ::GpiQueryBitmapBits( hPS
110 ,(LONG
)rBmp
.GetHeight()
115 vError
= ::WinGetLastError(vHabmain
);
116 sError
= wxPMErrorToStr(vError
);
118 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
120 vError
= ::WinGetLastError(vHabmain
);
121 sError
= wxPMErrorToStr(vError
);
123 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
124 vInfo
.cBitCount
= 24;
125 if ((lScans
= ::GpiQueryBitmapBits( hPS
127 ,(LONG
)rBmp
.GetHeight()
132 vError
= ::WinGetLastError(vHabmain
);
133 sError
= wxPMErrorToStr(vError
);
135 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
137 vError
= ::WinGetLastError(vHabmain
);
138 sError
= wxPMErrorToStr(vError
);
141 pucDataMask
= pucBitsMask
;
144 // Get the mask value
146 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
148 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
151 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
156 else if (*pucDataMask
== 0xFF) // set to grey
163 *pucData
= ((unsigned char)(lColor
>> 16));
168 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
173 else if (*(pucDataMask
+ 1) == 0xFF) // set to grey
180 *pucData
= ((unsigned char)(lColor
>> 8));
185 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
190 else if (*(pucDataMask
+ 2) == 0xFF) // set to grey
197 *pucData
= ((unsigned char)lColor
);
202 for (j
= 0; j
< nPadding
; j
++)
210 // Create a new bitmap and set the modified bits
212 wxBitmap
vNewBmp( rBmp
.GetWidth()
216 HBITMAP hNewBmp
= (HBITMAP
)vNewBmp
.GetHBITMAP();
218 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hNewBmp
)) == HBM_ERROR
)
220 vError
= ::WinGetLastError(vHabmain
);
221 sError
= wxPMErrorToStr(vError
);
223 if ((lScansSet
= ::GpiSetBitmapBits( hPS
225 ,(LONG
)rBmp
.GetHeight()
231 vError
= ::WinGetLastError(vHabmain
);
232 sError
= wxPMErrorToStr(vError
);
236 pNewMask
= new wxMask(pMask
->GetMaskBitmap());
237 vNewBmp
.SetMask(pNewMask
);
239 ::GpiSetBitmap(hPS
, NULLHANDLE
);
244 return(wxNullBitmap
);
245 } // end of wxDisableBitmap
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 class wxToolBarTool
: public wxToolBarToolBase
254 inline wxToolBarTool( wxToolBar
* pTbar
256 ,const wxString
& rsLabel
257 ,const wxBitmap
& rBitmap1
258 ,const wxBitmap
& rBitmap2
260 ,wxObject
* pClientData
261 ,const wxString
& rsShortHelpString
262 ,const wxString
& rsLongHelpString
263 ) : wxToolBarToolBase( pTbar
276 inline wxToolBarTool( wxToolBar
* pTbar
278 ) : wxToolBarToolBase( pTbar
284 void SetSize(const wxSize
& rSize
)
290 wxCoord
GetWidth(void) const { return m_vWidth
; }
291 wxCoord
GetHeight(void) const { return m_vHeight
; }
297 }; // end of CLASS wxToolBarTool
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
303 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarBase
)
305 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
306 EVT_SIZE(wxToolBar::OnSize
)
307 EVT_PAINT(wxToolBar::OnPaint
)
308 EVT_KILL_FOCUS(wxToolBar::OnKillFocus
)
309 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
310 EVT_TIMER(-1, wxToolBar::OnTimer
)
313 // ============================================================================
315 // ============================================================================
317 // ----------------------------------------------------------------------------
318 // tool bar tools creation
319 // ----------------------------------------------------------------------------
321 wxToolBarToolBase
* wxToolBar::CreateTool(
323 , const wxString
& rsLabel
324 , const wxBitmap
& rBmpNormal
325 , const wxBitmap
& rBmpDisabled
327 , wxObject
* pClientData
328 , const wxString
& rsShortHelp
329 , const wxString
& rsLongHelp
332 return new wxToolBarTool( this
342 } // end of wxToolBarSimple::CreateTool
344 wxToolBarToolBase
*wxToolBar::CreateTool(
348 return new wxToolBarTool( this
351 } // end of wxToolBarSimple::CreateTool
353 // ----------------------------------------------------------------------------
354 // wxToolBarSimple creation
355 // ----------------------------------------------------------------------------
357 void wxToolBar::Init()
359 m_nCurrentRowsOrColumns
= 0;
361 m_vLastX
= m_vLastY
= 0;
362 m_vMaxWidth
= m_vMaxHeight
= 0;
363 m_nPressedTool
= m_nCurrentTool
= -1;
364 m_vXPos
= m_vYPos
= -1;
365 m_vTextX
= m_vTextY
= 0;
368 m_toolSeparation
= 5;
371 m_defaultHeight
= 15;
374 } // end of wxToolBar::Init
376 wxToolBarToolBase
* wxToolBar::DoAddTool(
378 , const wxString
& rsLabel
379 , const wxBitmap
& rBitmap
380 , const wxBitmap
& rBmpDisabled
382 , const wxString
& rsShortHelp
383 , const wxString
& rsLongHelp
384 , wxObject
* pClientData
390 // Rememeber the position for DoInsertTool()
395 return wxToolBarBase::DoAddTool( vId
406 } // end of wxToolBar::DoAddTool
408 bool wxToolBar::DeleteTool(
412 bool bOk
= wxToolBarBase::DeleteTool(nId
);
419 } // end of wxToolBar::DeleteTool
421 bool wxToolBar::DeleteToolByPos(
425 bool bOk
= wxToolBarBase::DeleteToolByPos(nPos
);
432 } // end of wxToolBar::DeleteTool
434 wxToolBarToolBase
* wxToolBar::InsertControl(
436 , wxControl
* pControl
439 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertControl( nPos
448 } // end of wxToolBar::InsertControl
450 wxToolBarToolBase
* wxToolBar::InsertSeparator(
454 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertSeparator(nPos
);
462 } // end of wxToolBar::InsertSeparator
464 wxToolBarToolBase
* wxToolBar::InsertTool(
467 , const wxString
& rsLabel
468 , const wxBitmap
& rBitmap
469 , const wxBitmap
& rBmpDisabled
471 , const wxString
& rsShortHelp
472 , const wxString
& rsLongHelp
473 , wxObject
* pClientData
476 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertTool( nPos
492 } // end of wxToolBar::InsertTool
494 bool wxToolBar::DoInsertTool(
495 size_t WXUNUSED(nPos
)
496 , wxToolBarToolBase
* pToolBase
499 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
501 pTool
->m_vX
= m_vXPos
;
502 if (pTool
->m_vX
== -1)
503 pTool
->m_vX
= m_xMargin
;
505 pTool
->m_vY
= m_vYPos
;
506 if (pTool
->m_vY
== -1)
507 pTool
->m_vX
= m_yMargin
;
509 pTool
->SetSize(GetToolSize());
511 if (pTool
->IsButton())
514 // Calculate reasonable max size in case Layout() not called
516 if ((pTool
->m_vX
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
)
517 m_vMaxWidth
= (wxCoord
)((pTool
->m_vX
+ pTool
->GetWidth() + m_xMargin
));
519 if ((pTool
->m_vY
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
)
520 m_vMaxHeight
= (wxCoord
)((pTool
->m_vY
+ pTool
->GetHeight() + m_yMargin
));
523 } // end of wxToolBar::DoInsertTool
525 bool wxToolBar::DoDeleteTool(
526 size_t WXUNUSED(nPos
)
527 , wxToolBarToolBase
* pTool
533 } // end of wxToolBar::DoDeleteTool
535 bool wxToolBar::Create(
538 , const wxPoint
& rPos
539 , const wxSize
& rSize
541 , const wxString
& rsName
544 if ( !wxWindow::Create( pParent
553 // Set it to grey (or other 3D face colour)
554 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
555 SetFont(*wxSMALL_FONT
);
557 if (GetWindowStyleFlag() & wxTB_VERTICAL
)
562 m_maxRows
= 32000; // a lot
571 m_maxCols
= 32000; // a lot
573 SetCursor(*wxSTANDARD_CURSOR
);
576 // The toolbar's tools, if they have labels and the winTB_TEXT
577 // style is set, then we need to take into account the size of
578 // the text when drawing tool bitmaps and the text
580 if (HasFlag(wxTB_TEXT
))
582 wxClientDC
vDC(this);
584 vDC
.SetFont(GetFont());
585 vDC
.GetTextExtent( "XXXX"
596 int nWidth
= rSize
.x
;
597 int nHeight
= rSize
.y
;
598 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
600 if (lStyle
& wxTB_HORIZONTAL
)
604 nWidth
= pParent
->GetClientSize().x
;
608 if (lStyle
& wxTB_TEXT
)
609 nHeight
= m_defaultHeight
+ m_vTextY
;
611 nHeight
= m_defaultHeight
;
618 nHeight
= pParent
->GetClientSize().y
;
622 if (lStyle
& wxTB_TEXT
)
623 nWidth
= m_vTextX
+ (int)(m_vTextX
/2); // a little margin
625 nWidth
= m_defaultWidth
+ (int)(m_defaultWidth
/2); // a little margin
639 } // end of wxToolBar::Create
641 wxToolBar::~wxToolBar()
648 } // end of wxToolBar::~wxToolBar
650 bool wxToolBar::Realize()
652 int nMaxToolWidth
= 0;
653 int nMaxToolHeight
= 0;
657 m_nCurrentRowsOrColumns
= 0;
658 m_vLastX
= m_xMargin
;
659 m_vLastY
= m_yMargin
;
665 // Find the maximum tool width and height
667 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
671 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
673 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
676 // Set the height according to the font and the border size
678 if (pTool
->GetWidth() > m_vTextX
)
679 nMaxToolWidth
= pTool
->GetWidth() + 4;
681 nMaxToolWidth
= m_vTextX
;
682 if (pTool
->GetHeight() + m_vTextY
> nMaxToolHeight
)
683 nMaxToolHeight
= pTool
->GetHeight() + m_vTextY
;
687 if (pTool
->GetWidth() > nMaxToolWidth
)
688 nMaxToolWidth
= pTool
->GetWidth() + 4;
689 if (pTool
->GetHeight() > nMaxToolHeight
)
690 nMaxToolHeight
= pTool
->GetHeight();
692 pNode
= pNode
->GetNext();
695 wxCoord vTbWidth
= 0L;
696 wxCoord vTbHeight
= 0L;
701 if (vTbHeight
< nMaxToolHeight
)
708 if (GetParent()->IsKindOf(CLASSINFO(wxFrame
)))
710 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
713 pFrame
->PositionToolBar();
717 int nSeparatorSize
= m_toolSeparation
;
719 pNode
= m_tools
.GetFirst();
722 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
724 if (pTool
->IsSeparator())
726 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
728 pTool
->m_vX
= m_vLastX
+ nSeparatorSize
;
729 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
730 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
731 m_vLastY
+= nSeparatorSize
;
733 m_vLastX
+= nSeparatorSize
* 4;
737 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
;
738 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
739 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
740 m_vLastX
+= nSeparatorSize
;
742 m_vLastY
+= nSeparatorSize
* 4;
745 else if (pTool
->IsButton())
747 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
749 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
751 m_nCurrentRowsOrColumns
= 0;
752 m_vLastX
= m_xMargin
;
753 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
;
755 pTool
->m_vX
= m_vLastX
+ (nMaxToolWidth
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2)));
756 if (HasFlag(wxTB_TEXT
))
757 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
- 2; // just bit of adjustment
759 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
760 m_vLastX
+= nMaxToolWidth
+ m_toolPacking
+ m_toolSeparation
;
764 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
766 m_nCurrentRowsOrColumns
= 0;
767 m_vLastX
+= (nMaxToolWidth
+ m_toolPacking
);
768 m_vLastY
= m_yMargin
;
770 pTool
->m_vX
= m_vLastX
+ pTool
->GetWidth();
771 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
772 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- m_vTextY
) + m_toolPacking
;
774 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
775 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
+ m_toolSeparation
;
777 m_nCurrentRowsOrColumns
++;
781 // TODO: support the controls
784 if (m_vLastX
> m_maxWidth
)
785 m_maxWidth
= m_vLastX
;
786 if (m_vLastY
> m_maxHeight
)
787 m_maxHeight
= m_vLastY
;
789 pNode
= pNode
->GetNext();
792 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
793 m_maxWidth
+= nMaxToolWidth
;
795 m_maxHeight
+= nMaxToolHeight
;
797 m_maxWidth
+= m_xMargin
;
798 m_maxHeight
+= m_yMargin
;
799 m_bInitialized
= TRUE
;
801 } // end of wxToolBar::Realize
803 // ----------------------------------------------------------------------------
805 // ----------------------------------------------------------------------------
807 void wxToolBar::OnPaint (
808 wxPaintEvent
& WXUNUSED(rEvent
)
815 static int nCount
= 0;
818 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
824 ::WinFillRect(vDc
.GetHPS(), &vDc
.m_vRclPaint
, GetBackgroundColour().GetPixel());
825 for ( wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
827 pNode
= pNode
->GetNext() )
829 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
831 if (pTool
->IsButton() )
832 DrawTool(vDc
, pTool
);
833 if (pTool
->IsSeparator())
835 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
844 vDc
.SetPen(vDarkGreyPen
);
845 if (HasFlag(wxTB_TEXT
))
847 if (HasFlag(wxTB_HORIZONTAL
))
850 nY
= pTool
->m_vY
- (m_vTextY
- 6);
851 nHeight
= (m_vTextY
- 2) + pTool
->GetHeight();
855 nX
= pTool
->m_vX
+ m_xMargin
+ 10;
856 nY
= pTool
->m_vY
+ m_vTextY
+ m_toolSeparation
;
857 nWidth
= pTool
->GetWidth() > m_vTextX
? pTool
->GetWidth() : m_vTextX
;
864 if (HasFlag(wxTB_HORIZONTAL
))
865 nHeight
= pTool
->GetHeight() - 2;
868 nX
+= m_xMargin
+ 10;
869 nY
+= m_yMargin
+ m_toolSeparation
;
870 nWidth
= pTool
->GetWidth();
873 vDc
.DrawLine(nX
, nY
, nX
+ nWidth
, nY
+ nHeight
);
877 } // end of wxToolBar::OnPaint
879 void wxToolBar::OnSize (
880 wxSizeEvent
& WXUNUSED(rEvent
)
883 #if wxUSE_CONSTRAINTS
887 } // end of wxToolBar::OnSize
889 void wxToolBar::OnKillFocus(
890 wxFocusEvent
& WXUNUSED(rEvent
)
893 OnMouseEnter(m_nPressedTool
= m_nCurrentTool
= -1);
894 } // end of wxToolBar::OnKillFocus
896 void wxToolBar::OnMouseEvent(
904 HPOINTER hPtr
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
);
906 ::WinSetPointer(HWND_DESKTOP
, hPtr
);
907 ::WinQueryPointerPos(HWND_DESKTOP
, &vPoint
);
908 hWnd
= ::WinWindowFromPoint(HWND_DESKTOP
, &vPoint
, TRUE
);
909 if (hWnd
!= (HWND
)GetHwnd())
915 rEvent
.GetPosition(&vX
, &vY
);
917 wxToolBarTool
* pTool
= (wxToolBarTool
*)FindToolForPosition( vX
921 if (rEvent
.LeftDown())
933 if (m_nCurrentTool
> -1)
935 if (rEvent
.LeftIsDown())
936 SpringUpButton(m_nCurrentTool
);
937 pTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
938 if (pTool
&& !pTool
->IsToggled())
949 if (!rEvent
.IsButton())
951 if (pTool
->GetId() != m_nCurrentTool
)
954 // If the left button is kept down and moved over buttons,
955 // press those buttons.
957 if (rEvent
.LeftIsDown() && pTool
->IsEnabled())
959 SpringUpButton(m_nCurrentTool
);
960 if (pTool
->CanBeToggled())
966 wxToolBarTool
* pOldTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
968 if (pOldTool
&& !pTool
->IsToggled())
972 m_nCurrentTool
= pTool
->GetId();
973 OnMouseEnter(m_nCurrentTool
);
974 if (!pTool
->GetShortHelp().IsEmpty())
978 m_pToolTip
= new wxToolTip(pTool
->GetShortHelp());
979 m_vXMouse
= (wxCoord
)vPoint
.x
;
980 m_vYMouse
= (wxCoord
)vPoint
.y
;
981 m_vToolTimer
.Start(1000L, TRUE
);
983 if (!pTool
->IsToggled())
989 // Left button pressed.
990 if (rEvent
.LeftDown() && pTool
->IsEnabled())
992 if (pTool
->CanBeToggled())
998 else if (rEvent
.RightDown())
1000 OnRightClick( pTool
->GetId()
1007 // Left Button Released. Only this action confirms selection.
1008 // If the button is enabled and it is not a toggle tool and it is
1009 // in the pressed state, then raise the button and call OnLeftClick.
1011 if (rEvent
.LeftUp() && pTool
->IsEnabled() )
1014 // Pass the OnLeftClick event to tool
1016 if (!OnLeftClick( pTool
->GetId()
1017 ,pTool
->IsToggled()) &&
1018 pTool
->CanBeToggled())
1021 // If it was a toggle, and OnLeftClick says No Toggle allowed,
1022 // then change it back
1028 } // end of wxToolBar::OnMouseEvent
1030 // ----------------------------------------------------------------------------
1032 // ----------------------------------------------------------------------------
1034 void wxToolBar::DrawTool(
1035 wxToolBarToolBase
* pTool
1038 wxClientDC
vDc(this);
1043 } // end of wxToolBar::DrawTool
1045 void wxToolBar::DrawTool(
1047 , wxToolBarToolBase
* pToolBase
1050 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1051 wxPen
vDarkGreyPen( wxColour( 85,85,85 )
1055 wxPen
vWhitePen( wxT("WHITE")
1059 wxPen
vBlackPen( wxT("BLACK")
1063 wxBitmap vBitmap
= pTool
->GetNormalBitmap();
1064 bool bUseMask
= FALSE
;
1065 wxMask
* pMask
= NULL
;
1072 if ((pMask
= vBitmap
.GetMask()) != NULL
)
1073 if (pMask
->GetMaskBitmap() != NULLHANDLE
)
1076 if (!pTool
->IsToggled())
1078 LowerTool(pTool
, FALSE
);
1079 if (!pTool
->IsEnabled())
1081 wxColour
vColor("GREY");
1083 rDc
.SetTextForeground(vColor
);
1084 if (!pTool
->GetDisabledBitmap().Ok())
1085 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1086 ,(long)GetBackgroundColour().GetPixel()
1088 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1096 wxColour
vColor("BLACK");
1098 rDc
.SetTextForeground(vColor
);
1099 rDc
.DrawBitmap( vBitmap
1105 if (m_windowStyle
& wxTB_3DBUTTONS
)
1109 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1113 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1115 rDc
.SetFont(GetFont());
1116 rDc
.GetTextExtent( pTool
->GetLabel()
1120 if (pTool
->GetWidth() > vX
) // large tools
1122 vLeft
= pTool
->m_vX
+ (pTool
->GetWidth() - vX
);
1124 rDc
.DrawText( pTool
->GetLabel()
1126 ,vY
- (m_vTextY
- 2)
1129 else // normal tools
1131 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1132 rDc
.DrawText( pTool
->GetLabel()
1134 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1141 wxColour
vColor("GREY");
1144 rDc
.SetTextForeground(vColor
);
1145 if (!pTool
->GetDisabledBitmap().Ok())
1146 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1147 ,(long)GetBackgroundColour().GetPixel()
1149 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1154 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1158 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1160 rDc
.SetFont(GetFont());
1161 rDc
.GetTextExtent( pTool
->GetLabel()
1165 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1166 rDc
.DrawText( pTool
->GetLabel()
1168 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1172 } // end of wxToolBar::DrawTool
1174 // ----------------------------------------------------------------------------
1176 // ----------------------------------------------------------------------------
1178 void wxToolBar::SetRows(
1182 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
1184 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
1186 } // end of wxToolBar::SetRows
1188 wxToolBarToolBase
* wxToolBar::FindToolForPosition(
1195 wxCoord vTBarHeight
= 0;
1200 vY
= vTBarHeight
- vY
;
1201 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
1204 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
1206 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1208 if ((vX
>= (pTool
->m_vX
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) &&
1209 (vY
>= (pTool
->m_vY
- 2)) &&
1210 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1211 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight() + m_vTextY
+ 2)))
1218 if ((vX
>= pTool
->m_vX
) &&
1219 (vY
>= pTool
->m_vY
) &&
1220 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1221 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight())))
1226 pNode
= pNode
->GetNext();
1228 return (wxToolBarToolBase
*)NULL
;
1229 } // end of wxToolBar::FindToolForPosition
1231 // ----------------------------------------------------------------------------
1232 // tool state change handlers
1233 // ----------------------------------------------------------------------------
1235 void wxToolBar::DoEnableTool(
1236 wxToolBarToolBase
* pTool
1237 , bool WXUNUSED(bEnable
)
1241 } // end of wxToolBar::DoEnableTool
1243 void wxToolBar::DoToggleTool(
1244 wxToolBarToolBase
* pTool
1245 , bool WXUNUSED(bToggle
)
1249 } // end of wxToolBar::DoToggleTool
1251 void wxToolBar::DoSetToggle(
1252 wxToolBarToolBase
* WXUNUSED(pTool
)
1253 , bool WXUNUSED(bToggle
)
1257 } // end of wxToolBar::DoSetToggle
1260 // Okay, so we've left the tool we're in ... we must check if the tool we're
1261 // leaving was a 'sprung push button' and if so, spring it back to the up
1264 void wxToolBar::SpringUpButton(
1268 wxToolBarToolBase
* pTool
= FindById(vId
);
1270 if (pTool
&& pTool
->CanBeToggled())
1272 if (pTool
->IsToggled())
1277 } // end of wxToolBar::SpringUpButton
1279 // ----------------------------------------------------------------------------
1281 // ----------------------------------------------------------------------------
1283 void wxToolBar::LowerTool (
1284 wxToolBarToolBase
* pToolBase
1288 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1293 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1297 wxPen
vWhitePen( "WHITE"
1301 wxPen
vClearPen( GetBackgroundColour()
1305 wxClientDC
vDC(this);
1310 if (pTool
->IsSeparator())
1314 // We only do this for flat toolbars
1316 if (!HasFlag(wxTB_FLAT
))
1319 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1321 if (pTool
->GetWidth() > m_vTextX
)
1323 vX
= pTool
->m_vX
- 2;
1324 vWidth
= pTool
->GetWidth() + 4;
1328 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1329 vWidth
= m_vTextX
+ 4;
1331 vY
= pTool
->m_vY
- 2;
1332 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1336 vX
= pTool
->m_vX
- 2;
1337 vY
= pTool
->m_vY
- 2;
1338 vWidth
= pTool
->GetWidth() + 4;
1339 vHeight
= pTool
->GetHeight() + 4;
1343 vDC
.SetPen(vWhitePen
);
1344 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1345 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1346 vDC
.SetPen(vDarkGreyPen
);
1347 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1348 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1352 vDC
.SetPen(vClearPen
);
1353 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1354 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1355 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1356 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1358 } // end of WinGuiBase_CToolBarTool::LowerTool
1360 void wxToolBar::RaiseTool (
1361 wxToolBarToolBase
* pToolBase
1365 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1370 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1374 wxPen
vWhitePen( "WHITE"
1378 wxPen
vClearPen( GetBackgroundColour()
1382 wxClientDC
vDC(this);
1387 if (pTool
->IsSeparator())
1390 if (!pTool
->IsEnabled())
1394 // We only do this for flat toolbars
1396 if (!HasFlag(wxTB_FLAT
))
1399 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1401 if (pTool
->GetWidth() > m_vTextX
)
1403 vX
= pTool
->m_vX
- 2;
1404 vWidth
= pTool
->GetWidth() + 4;
1408 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1409 vWidth
= m_vTextX
+ 4;
1411 vY
= pTool
->m_vY
- 2;
1412 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1416 vX
= pTool
->m_vX
- 2;
1417 vY
= pTool
->m_vY
- 2;
1418 vWidth
= pTool
->GetWidth() + 4;
1419 vHeight
= pTool
->GetHeight() + 4;
1423 vDC
.SetPen(vDarkGreyPen
);
1424 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1425 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1426 vDC
.SetPen(vWhitePen
);
1427 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1428 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1432 vDC
.SetPen(vClearPen
);
1433 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1434 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1435 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1436 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1438 } // end of wxToolBar::RaiseTool
1440 void wxToolBar::OnTimer (
1441 wxTimerEvent
& rEvent
1444 if (rEvent
.GetId() == m_vToolTimer
.GetTimerId())
1446 wxPoint
vPos( m_vXMouse
1450 m_pToolTip
->DisplayToolTipWindow(vPos
);
1451 m_vToolTimer
.Stop();
1452 m_vToolExpTimer
.Start(4000L, TRUE
);
1454 else if (rEvent
.GetId() == m_vToolExpTimer
.GetTimerId())
1456 m_pToolTip
->HideToolTipWindow();
1457 GetParent()->Refresh();
1458 m_vToolExpTimer
.Stop();
1460 } // end of wxToolBar::OnTimer
1462 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE