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"
20 #include "wx/dcclient.h"
21 #include "wx/dcmemory.h"
24 #include "wx/toolbar.h"
26 bool wxToolBar::m_bInitialized
= FALSE
;
28 // ---------------------------------------------------------------------------
29 // Helper for taking a regular bitmap and giving it a disabled look
30 // ---------------------------------------------------------------------------
31 wxBitmap
wxDisableBitmap(
36 wxMask
* pMask
= rBmp
.GetMask();
41 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
43 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
44 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
45 BITMAPINFOHEADER2 vHeader
;
49 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
50 HBITMAP hOldBitmap
= NULLHANDLE
;
51 HBITMAP hOldMask
= NULLHANDLE
;
52 HBITMAP hMask
= (HBITMAP
)rBmp
.GetMask()->GetMaskBitmap();
53 unsigned char* pucBits
; // buffer that will contain the bitmap data
54 unsigned char* pucData
; // pointer to use to traverse bitmap data
55 unsigned char* pucBitsMask
; // buffer that will contain the mask data
56 unsigned char* pucDataMask
; // pointer to use to traverse mask data
59 bool bpp16
= (wxDisplayDepth() == 16);
61 memset(&vHeader
, '\0', 16);
64 memset(&vInfo
, '\0', 16);
66 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
67 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
69 vInfo
.cBitCount
= 24; // Set to desired count going in
72 // Create the buffers for data....all wxBitmaps are 24 bit internally
74 int nBytesPerLine
= rBmp
.GetWidth() * 3;
75 int nSizeDWORD
= sizeof(DWORD
);
76 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
82 // Bitmap must be ina double-word alligned address so we may
83 // have some padding to worry about
85 if (nLineBoundary
> 0)
87 nPadding
= nSizeDWORD
- nLineBoundary
;
88 nBytesPerLine
+= nPadding
;
90 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
91 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
92 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
93 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
96 // Extract the bitmap and mask data
98 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
100 vError
= ::WinGetLastError(vHabmain
);
101 sError
= wxPMErrorToStr(vError
);
103 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
104 vInfo
.cBitCount
= 24;
105 if ((lScans
= ::GpiQueryBitmapBits( hPS
107 ,(LONG
)rBmp
.GetHeight()
112 vError
= ::WinGetLastError(vHabmain
);
113 sError
= wxPMErrorToStr(vError
);
115 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
117 vError
= ::WinGetLastError(vHabmain
);
118 sError
= wxPMErrorToStr(vError
);
120 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
121 vInfo
.cBitCount
= 24;
122 if ((lScans
= ::GpiQueryBitmapBits( hPS
124 ,(LONG
)rBmp
.GetHeight()
129 vError
= ::WinGetLastError(vHabmain
);
130 sError
= wxPMErrorToStr(vError
);
132 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
134 vError
= ::WinGetLastError(vHabmain
);
135 sError
= wxPMErrorToStr(vError
);
138 pucDataMask
= pucBitsMask
;
141 // Get the mask value
143 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
145 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
148 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
153 else if (*pucDataMask
== 0xFF) // set to grey
160 *pucData
= ((unsigned char)(lColor
>> 16));
165 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
170 else if (*(pucDataMask
+ 1) == 0xFF) // set to grey
177 *pucData
= ((unsigned char)(lColor
>> 8));
182 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
187 else if (*(pucDataMask
+ 2) == 0xFF) // set to grey
194 *pucData
= ((unsigned char)lColor
);
199 for (j
= 0; j
< nPadding
; j
++)
207 // Create a new bitmap and set the modified bits
209 wxBitmap
vNewBmp( rBmp
.GetWidth()
213 HBITMAP hNewBmp
= (HBITMAP
)vNewBmp
.GetHBITMAP();
215 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hNewBmp
)) == HBM_ERROR
)
217 vError
= ::WinGetLastError(vHabmain
);
218 sError
= wxPMErrorToStr(vError
);
220 if ((lScansSet
= ::GpiSetBitmapBits( hPS
222 ,(LONG
)rBmp
.GetHeight()
228 vError
= ::WinGetLastError(vHabmain
);
229 sError
= wxPMErrorToStr(vError
);
233 pNewMask
= new wxMask(pMask
->GetMaskBitmap());
234 vNewBmp
.SetMask(pNewMask
);
236 ::GpiSetBitmap(hPS
, NULLHANDLE
);
241 return(wxNullBitmap
);
242 } // end of wxDisableBitmap
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 class wxToolBarTool
: public wxToolBarToolBase
251 inline wxToolBarTool( wxToolBar
* pTbar
253 ,const wxString
& rsLabel
254 ,const wxBitmap
& rBitmap1
255 ,const wxBitmap
& rBitmap2
257 ,wxObject
* pClientData
258 ,const wxString
& rsShortHelpString
259 ,const wxString
& rsLongHelpString
260 ) : wxToolBarToolBase( pTbar
273 inline wxToolBarTool( wxToolBar
* pTbar
275 ) : wxToolBarToolBase( pTbar
281 void SetSize(const wxSize
& rSize
)
287 wxCoord
GetWidth(void) const { return m_vWidth
; }
288 wxCoord
GetHeight(void) const { return m_vHeight
; }
294 }; // end of CLASS wxToolBarTool
296 // ----------------------------------------------------------------------------
298 // ----------------------------------------------------------------------------
300 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarBase
)
302 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
303 EVT_SIZE(wxToolBar::OnSize
)
304 EVT_PAINT(wxToolBar::OnPaint
)
305 EVT_KILL_FOCUS(wxToolBar::OnKillFocus
)
306 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
307 EVT_TIMER(-1, wxToolBar::OnTimer
)
310 // ============================================================================
312 // ============================================================================
314 // ----------------------------------------------------------------------------
315 // tool bar tools creation
316 // ----------------------------------------------------------------------------
318 wxToolBarToolBase
* wxToolBar::CreateTool(
320 , const wxString
& rsLabel
321 , const wxBitmap
& rBmpNormal
322 , const wxBitmap
& rBmpDisabled
324 , wxObject
* pClientData
325 , const wxString
& rsShortHelp
326 , const wxString
& rsLongHelp
329 return new wxToolBarTool( this
339 } // end of wxToolBarSimple::CreateTool
341 wxToolBarToolBase
*wxToolBar::CreateTool(
345 return new wxToolBarTool( this
348 } // end of wxToolBarSimple::CreateTool
350 // ----------------------------------------------------------------------------
351 // wxToolBarSimple creation
352 // ----------------------------------------------------------------------------
354 void wxToolBar::Init()
356 m_nCurrentRowsOrColumns
= 0;
358 m_vLastX
= m_vLastY
= 0;
359 m_vMaxWidth
= m_vMaxHeight
= 0;
360 m_nPressedTool
= m_nCurrentTool
= -1;
361 m_vXPos
= m_vYPos
= -1;
362 m_vTextX
= m_vTextY
= 0;
365 m_toolSeparation
= 5;
368 m_defaultHeight
= 15;
369 } // end of wxToolBar::Init
371 wxToolBarToolBase
* wxToolBar::DoAddTool(
373 , const wxString
& rsLabel
374 , const wxBitmap
& rBitmap
375 , const wxBitmap
& rBmpDisabled
377 , const wxString
& rsShortHelp
378 , const wxString
& rsLongHelp
379 , wxObject
* pClientData
385 // Rememeber the position for DoInsertTool()
390 return wxToolBarBase::DoAddTool( vId
401 } // end of wxToolBar::DoAddTool
403 bool wxToolBar::DeleteTool(
407 bool bOk
= wxToolBarBase::DeleteTool(nId
);
414 } // end of wxToolBar::DeleteTool
416 bool wxToolBar::DeleteToolByPos(
420 bool bOk
= wxToolBarBase::DeleteToolByPos(nPos
);
427 } // end of wxToolBar::DeleteTool
429 wxToolBarToolBase
* wxToolBar::InsertControl(
431 , wxControl
* pControl
434 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertControl( nPos
443 } // end of wxToolBar::InsertControl
445 wxToolBarToolBase
* wxToolBar::InsertSeparator(
449 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertSeparator(nPos
);
457 } // end of wxToolBar::InsertSeparator
459 wxToolBarToolBase
* wxToolBar::InsertTool(
462 , const wxString
& rsLabel
463 , const wxBitmap
& rBitmap
464 , const wxBitmap
& rBmpDisabled
466 , const wxString
& rsShortHelp
467 , const wxString
& rsLongHelp
468 , wxObject
* pClientData
471 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertTool( nPos
487 } // end of wxToolBar::InsertTool
489 bool wxToolBar::DoInsertTool(
490 size_t WXUNUSED(nPos
)
491 , wxToolBarToolBase
* pToolBase
494 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
496 pTool
->m_vX
= m_vXPos
;
497 if (pTool
->m_vX
== -1)
498 pTool
->m_vX
= m_xMargin
;
500 pTool
->m_vY
= m_vYPos
;
501 if (pTool
->m_vY
== -1)
502 pTool
->m_vX
= m_yMargin
;
504 pTool
->SetSize(GetToolSize());
506 if (pTool
->IsButton())
509 // Calculate reasonable max size in case Layout() not called
511 if ((pTool
->m_vX
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
)
512 m_vMaxWidth
= (wxCoord
)((pTool
->m_vX
+ pTool
->GetWidth() + m_xMargin
));
514 if ((pTool
->m_vY
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
)
515 m_vMaxHeight
= (wxCoord
)((pTool
->m_vY
+ pTool
->GetHeight() + m_yMargin
));
518 } // end of wxToolBar::DoInsertTool
520 bool wxToolBar::DoDeleteTool(
521 size_t WXUNUSED(nPos
)
522 , wxToolBarToolBase
* pTool
528 } // end of wxToolBar::DoDeleteTool
530 bool wxToolBar::Create(
533 , const wxPoint
& rPos
534 , const wxSize
& rSize
536 , const wxString
& rsName
539 if ( !wxWindow::Create( pParent
548 // Set it to grey (or other 3D face colour)
549 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
550 SetFont(*wxSMALL_FONT
);
552 if (GetWindowStyleFlag() & wxTB_VERTICAL
)
557 m_maxRows
= 32000; // a lot
566 m_maxCols
= 32000; // a lot
568 SetCursor(*wxSTANDARD_CURSOR
);
571 // The toolbar's tools, if they have labels and the winTB_TEXT
572 // style is set, then we need to take into account the size of
573 // the text when drawing tool bitmaps and the text
575 if (HasFlag(wxTB_TEXT
))
577 wxClientDC
vDC(this);
579 vDC
.SetFont(GetFont());
580 vDC
.GetTextExtent( "XXXX"
591 int nWidth
= rSize
.x
;
592 int nHeight
= rSize
.y
;
593 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
595 if (lStyle
& wxTB_HORIZONTAL
)
599 nWidth
= pParent
->GetClientSize().x
;
603 if (lStyle
& wxTB_TEXT
)
604 nHeight
= m_defaultHeight
+ m_vTextY
;
606 nHeight
= m_defaultHeight
;
613 nHeight
= pParent
->GetClientSize().y
;
617 if (lStyle
& wxTB_TEXT
)
618 nWidth
= m_vTextX
+ (int)(m_vTextX
/2); // a little margin
620 nWidth
= m_defaultWidth
+ (int)(m_defaultWidth
/2); // a little margin
634 } // end of wxToolBar::Create
636 wxToolBar::~wxToolBar()
638 } // end of wxToolBar::~wxToolBar
640 bool wxToolBar::Realize()
642 int nMaxToolWidth
= 0;
643 int nMaxToolHeight
= 0;
647 m_nCurrentRowsOrColumns
= 0;
648 m_vLastX
= m_xMargin
;
649 m_vLastY
= m_yMargin
;
655 // Find the maximum tool width and height
657 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
661 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
663 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
666 // Set the height according to the font and the border size
668 if (pTool
->GetWidth() > m_vTextX
)
669 nMaxToolWidth
= pTool
->GetWidth() + 4;
671 nMaxToolWidth
= m_vTextX
;
672 if (pTool
->GetHeight() + m_vTextY
> nMaxToolHeight
)
673 nMaxToolHeight
= pTool
->GetHeight() + m_vTextY
;
677 if (pTool
->GetWidth() > nMaxToolWidth
)
678 nMaxToolWidth
= pTool
->GetWidth() + 4;
679 if (pTool
->GetHeight() > nMaxToolHeight
)
680 nMaxToolHeight
= pTool
->GetHeight();
682 pNode
= pNode
->GetNext();
685 wxCoord vTbWidth
= 0L;
686 wxCoord vTbHeight
= 0L;
691 if (vTbHeight
< nMaxToolHeight
)
698 if (GetParent()->IsKindOf(CLASSINFO(wxFrame
)))
700 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
703 pFrame
->PositionToolBar();
707 int nSeparatorSize
= m_toolSeparation
;
709 pNode
= m_tools
.GetFirst();
712 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
714 if (pTool
->IsSeparator())
716 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
718 pTool
->m_vX
= m_vLastX
+ nSeparatorSize
;
719 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
720 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
721 m_vLastY
+= nSeparatorSize
;
723 m_vLastX
+= nSeparatorSize
* 4;
727 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
;
728 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
729 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
730 m_vLastX
+= nSeparatorSize
;
732 m_vLastY
+= nSeparatorSize
* 4;
735 else if (pTool
->IsButton())
737 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
739 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
741 m_nCurrentRowsOrColumns
= 0;
742 m_vLastX
= m_xMargin
;
743 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
;
745 pTool
->m_vX
= m_vLastX
+ (nMaxToolWidth
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2)));
746 if (HasFlag(wxTB_TEXT
))
747 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
- 2; // just bit of adjustment
749 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
750 m_vLastX
+= nMaxToolWidth
+ m_toolPacking
+ m_toolSeparation
;
754 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
756 m_nCurrentRowsOrColumns
= 0;
757 m_vLastX
+= (nMaxToolWidth
+ m_toolPacking
);
758 m_vLastY
= m_yMargin
;
760 pTool
->m_vX
= m_vLastX
+ pTool
->GetWidth();
761 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
762 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- m_vTextY
) + m_toolPacking
;
764 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
765 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
+ m_toolSeparation
;
767 m_nCurrentRowsOrColumns
++;
771 // TODO: support the controls
774 if (m_vLastX
> m_maxWidth
)
775 m_maxWidth
= m_vLastX
;
776 if (m_vLastY
> m_maxHeight
)
777 m_maxHeight
= m_vLastY
;
779 pNode
= pNode
->GetNext();
782 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
783 m_maxWidth
+= nMaxToolWidth
;
785 m_maxHeight
+= nMaxToolHeight
;
787 m_maxWidth
+= m_xMargin
;
788 m_maxHeight
+= m_yMargin
;
789 m_bInitialized
= TRUE
;
791 } // end of wxToolBar::Realize
793 // ----------------------------------------------------------------------------
795 // ----------------------------------------------------------------------------
797 void wxToolBar::OnPaint (
798 wxPaintEvent
& WXUNUSED(rEvent
)
805 static int nCount
= 0;
808 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
814 ::WinFillRect(vDc
.GetHPS(), &vDc
.m_vRclPaint
, GetBackgroundColour().GetPixel());
815 for ( wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
817 pNode
= pNode
->GetNext() )
819 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
821 if (pTool
->IsButton() )
822 DrawTool(vDc
, pTool
);
823 if (pTool
->IsSeparator())
825 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
834 vDc
.SetPen(vDarkGreyPen
);
835 if (HasFlag(wxTB_TEXT
))
837 if (HasFlag(wxTB_HORIZONTAL
))
840 nY
= pTool
->m_vY
- (m_vTextY
- 6);
841 nHeight
= (m_vTextY
- 2) + pTool
->GetHeight();
845 nX
= pTool
->m_vX
+ m_xMargin
+ 10;
846 nY
= pTool
->m_vY
+ m_vTextY
+ m_toolSeparation
;
847 nWidth
= pTool
->GetWidth() > m_vTextX
? pTool
->GetWidth() : m_vTextX
;
854 if (HasFlag(wxTB_HORIZONTAL
))
855 nHeight
= pTool
->GetHeight() - 2;
858 nX
+= m_xMargin
+ 10;
859 nY
+= m_yMargin
+ m_toolSeparation
;
860 nWidth
= pTool
->GetWidth();
863 vDc
.DrawLine(nX
, nY
, nX
+ nWidth
, nY
+ nHeight
);
867 } // end of wxToolBar::OnPaint
869 void wxToolBar::OnSize (
870 wxSizeEvent
& WXUNUSED(rEvent
)
873 #if wxUSE_CONSTRAINTS
877 } // end of wxToolBar::OnSize
879 void wxToolBar::OnKillFocus(
880 wxFocusEvent
& WXUNUSED(rEvent
)
883 OnMouseEnter(m_nPressedTool
= m_nCurrentTool
= -1);
884 } // end of wxToolBar::OnKillFocus
886 void wxToolBar::OnMouseEvent(
892 HPOINTER hPtr
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
);
894 ::WinSetPointer(HWND_DESKTOP
, hPtr
);
895 rEvent
.GetPosition(&vX
, &vY
);
897 wxToolBarTool
* pTool
= (wxToolBarTool
*)FindToolForPosition( vX
901 if (rEvent
.LeftDown())
911 m_vToolTimer
.Start(3000L, FALSE
);
914 if (m_nCurrentTool
> -1)
916 if (rEvent
.LeftIsDown())
917 SpringUpButton(m_nCurrentTool
);
918 pTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
919 if (pTool
&& !pTool
->IsToggled())
930 if (!rEvent
.IsButton())
932 if (pTool
->GetId() != m_nCurrentTool
)
935 // If the left button is kept down and moved over buttons,
936 // press those buttons.
938 if (rEvent
.LeftIsDown() && pTool
->IsEnabled())
940 SpringUpButton(m_nCurrentTool
);
941 if (pTool
->CanBeToggled())
947 wxToolBarTool
* pOldTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
949 if (pOldTool
&& !pTool
->IsToggled())
953 m_nCurrentTool
= pTool
->GetId();
954 OnMouseEnter(m_nCurrentTool
);
955 if (!pTool
->IsToggled())
961 // Left button pressed.
962 if (rEvent
.LeftDown() && pTool
->IsEnabled())
964 if (pTool
->CanBeToggled())
970 else if (rEvent
.RightDown())
972 OnRightClick( pTool
->GetId()
979 // Left Button Released. Only this action confirms selection.
980 // If the button is enabled and it is not a toggle tool and it is
981 // in the pressed state, then raise the button and call OnLeftClick.
983 if (rEvent
.LeftUp() && pTool
->IsEnabled() )
986 // Pass the OnLeftClick event to tool
988 if (!OnLeftClick( pTool
->GetId()
989 ,pTool
->IsToggled()) &&
990 pTool
->CanBeToggled())
993 // If it was a toggle, and OnLeftClick says No Toggle allowed,
994 // then change it back
1000 } // end of wxToolBar::OnMouseEvent
1002 // ----------------------------------------------------------------------------
1004 // ----------------------------------------------------------------------------
1006 void wxToolBar::DrawTool(
1007 wxToolBarToolBase
* pTool
1010 wxClientDC
vDc(this);
1015 } // end of wxToolBar::DrawTool
1017 void wxToolBar::DrawTool(
1019 , wxToolBarToolBase
* pToolBase
1022 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1023 wxPen
vDarkGreyPen( wxColour( 85,85,85 )
1027 wxPen
vWhitePen( wxT("WHITE")
1031 wxPen
vBlackPen( wxT("BLACK")
1035 wxBitmap vBitmap
= pTool
->GetNormalBitmap();
1036 bool bUseMask
= FALSE
;
1037 wxMask
* pMask
= NULL
;
1044 if ((pMask
= vBitmap
.GetMask()) != NULL
)
1045 if (pMask
->GetMaskBitmap() != NULLHANDLE
)
1048 if (!pTool
->IsToggled())
1050 LowerTool(pTool
, FALSE
);
1051 if (!pTool
->IsEnabled())
1053 wxColour
vColor("GREY");
1055 rDc
.SetTextForeground(vColor
);
1056 if (!pTool
->GetDisabledBitmap().Ok())
1057 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1058 ,(long)GetBackgroundColour().GetPixel()
1060 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1068 wxColour
vColor("BLACK");
1070 rDc
.SetTextForeground(vColor
);
1071 rDc
.DrawBitmap( vBitmap
1077 if (m_windowStyle
& wxTB_3DBUTTONS
)
1081 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1085 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1087 rDc
.SetFont(GetFont());
1088 rDc
.GetTextExtent( pTool
->GetLabel()
1092 if (pTool
->GetWidth() > vX
) // large tools
1094 vLeft
= pTool
->m_vX
+ (pTool
->GetWidth() - vX
);
1096 rDc
.DrawText( pTool
->GetLabel()
1098 ,vY
- (m_vTextY
- 2)
1101 else // normal tools
1103 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1104 rDc
.DrawText( pTool
->GetLabel()
1106 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1113 wxColour
vColor("GREY");
1116 rDc
.SetTextForeground(vColor
);
1117 if (!pTool
->GetDisabledBitmap().Ok())
1118 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1119 ,(long)GetBackgroundColour().GetPixel()
1121 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1126 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1130 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1132 rDc
.SetFont(GetFont());
1133 rDc
.GetTextExtent( pTool
->GetLabel()
1137 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1138 rDc
.DrawText( pTool
->GetLabel()
1140 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1144 } // end of wxToolBar::DrawTool
1146 // ----------------------------------------------------------------------------
1148 // ----------------------------------------------------------------------------
1150 void wxToolBar::SetRows(
1154 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
1156 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
1158 } // end of wxToolBar::SetRows
1160 wxToolBarToolBase
* wxToolBar::FindToolForPosition(
1167 wxCoord vTBarHeight
= 0;
1172 vY
= vTBarHeight
- vY
;
1173 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
1176 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
1178 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1180 if ((vX
>= (pTool
->m_vX
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) &&
1181 (vY
>= (pTool
->m_vY
- 2)) &&
1182 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1183 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight() + m_vTextY
+ 2)))
1190 if ((vX
>= pTool
->m_vX
) &&
1191 (vY
>= pTool
->m_vY
) &&
1192 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1193 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight())))
1198 pNode
= pNode
->GetNext();
1200 return (wxToolBarToolBase
*)NULL
;
1201 } // end of wxToolBar::FindToolForPosition
1203 // ----------------------------------------------------------------------------
1204 // tool state change handlers
1205 // ----------------------------------------------------------------------------
1207 void wxToolBar::DoEnableTool(
1208 wxToolBarToolBase
* pTool
1209 , bool WXUNUSED(bEnable
)
1213 } // end of wxToolBar::DoEnableTool
1215 void wxToolBar::DoToggleTool(
1216 wxToolBarToolBase
* pTool
1217 , bool WXUNUSED(bToggle
)
1221 } // end of wxToolBar::DoToggleTool
1223 void wxToolBar::DoSetToggle(
1224 wxToolBarToolBase
* WXUNUSED(pTool
)
1225 , bool WXUNUSED(bToggle
)
1229 } // end of wxToolBar::DoSetToggle
1232 // Okay, so we've left the tool we're in ... we must check if the tool we're
1233 // leaving was a 'sprung push button' and if so, spring it back to the up
1236 void wxToolBar::SpringUpButton(
1240 wxToolBarToolBase
* pTool
= FindById(vId
);
1242 if (pTool
&& pTool
->CanBeToggled())
1244 if (pTool
->IsToggled())
1249 } // end of wxToolBar::SpringUpButton
1251 // ----------------------------------------------------------------------------
1253 // ----------------------------------------------------------------------------
1255 void wxToolBar::LowerTool (
1256 wxToolBarToolBase
* pToolBase
1260 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1265 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1269 wxPen
vWhitePen( "WHITE"
1273 wxPen
vClearPen( GetBackgroundColour()
1277 wxClientDC
vDC(this);
1282 if (pTool
->IsSeparator())
1286 // We only do this for flat toolbars
1288 if (!HasFlag(wxTB_FLAT
))
1291 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1293 if (pTool
->GetWidth() > m_vTextX
)
1295 vX
= pTool
->m_vX
- 2;
1296 vWidth
= pTool
->GetWidth() + 4;
1300 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1301 vWidth
= m_vTextX
+ 4;
1303 vY
= pTool
->m_vY
- 2;
1304 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1308 vX
= pTool
->m_vX
- 2;
1309 vY
= pTool
->m_vY
- 2;
1310 vWidth
= pTool
->GetWidth() + 4;
1311 vHeight
= pTool
->GetHeight() + 4;
1315 vDC
.SetPen(vWhitePen
);
1316 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1317 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1318 vDC
.SetPen(vDarkGreyPen
);
1319 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1320 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1324 vDC
.SetPen(vClearPen
);
1325 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1326 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1327 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1328 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1330 } // end of WinGuiBase_CToolBarTool::LowerTool
1332 void wxToolBar::RaiseTool (
1333 wxToolBarToolBase
* pToolBase
1337 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1342 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1346 wxPen
vWhitePen( "WHITE"
1350 wxPen
vClearPen( GetBackgroundColour()
1354 wxClientDC
vDC(this);
1359 if (pTool
->IsSeparator())
1362 if (!pTool
->IsEnabled())
1366 // We only do this for flat toolbars
1368 if (!HasFlag(wxTB_FLAT
))
1371 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1373 if (pTool
->GetWidth() > m_vTextX
)
1375 vX
= pTool
->m_vX
- 2;
1376 vWidth
= pTool
->GetWidth() + 4;
1380 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1381 vWidth
= m_vTextX
+ 4;
1383 vY
= pTool
->m_vY
- 2;
1384 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1388 vX
= pTool
->m_vX
- 2;
1389 vY
= pTool
->m_vY
- 2;
1390 vWidth
= pTool
->GetWidth() + 4;
1391 vHeight
= pTool
->GetHeight() + 4;
1395 vDC
.SetPen(vDarkGreyPen
);
1396 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1397 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1398 vDC
.SetPen(vWhitePen
);
1399 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1400 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1404 vDC
.SetPen(vClearPen
);
1405 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1406 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1407 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1408 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1410 } // end of wxToolBar::RaiseTool
1412 void wxToolBar::OnTimer (
1413 wxTimerEvent
& rEvent
1416 if (rEvent
.GetId() == (int)m_ulToolTimer
)
1418 (void)wxMessageBox("wxWindows toolbar timer", "ToolTimer");
1420 else if (rEvent
.GetId() == (int)m_ulToolExpTimer
)
1422 (void)wxMessageBox("wxWindows toolbar timer", "ToolExpTimer");
1424 } // end of wxToolBar::OnTimer
1426 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE