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
)
309 // ============================================================================
311 // ============================================================================
313 // ----------------------------------------------------------------------------
314 // tool bar tools creation
315 // ----------------------------------------------------------------------------
317 wxToolBarToolBase
* wxToolBar::CreateTool(
319 , const wxString
& rsLabel
320 , const wxBitmap
& rBmpNormal
321 , const wxBitmap
& rBmpDisabled
323 , wxObject
* pClientData
324 , const wxString
& rsShortHelp
325 , const wxString
& rsLongHelp
328 return new wxToolBarTool( this
338 } // end of wxToolBarSimple::CreateTool
340 wxToolBarToolBase
*wxToolBar::CreateTool(
344 return new wxToolBarTool( this
347 } // end of wxToolBarSimple::CreateTool
349 // ----------------------------------------------------------------------------
350 // wxToolBarSimple creation
351 // ----------------------------------------------------------------------------
353 void wxToolBar::Init()
355 m_nCurrentRowsOrColumns
= 0;
357 m_vLastX
= m_vLastY
= 0;
358 m_vMaxWidth
= m_vMaxHeight
= 0;
359 m_nPressedTool
= m_nCurrentTool
= -1;
360 m_vXPos
= m_vYPos
= -1;
361 m_vTextX
= m_vTextY
= 0;
364 m_toolSeparation
= 5;
367 m_defaultHeight
= 15;
368 } // end of wxToolBar::Init
370 wxToolBarToolBase
* wxToolBar::DoAddTool(
372 , const wxString
& rsLabel
373 , const wxBitmap
& rBitmap
374 , const wxBitmap
& rBmpDisabled
376 , const wxString
& rsShortHelp
377 , const wxString
& rsLongHelp
378 , wxObject
* pClientData
384 // Rememeber the position for DoInsertTool()
389 return wxToolBarBase::DoAddTool( vId
400 } // end of wxToolBar::DoAddTool
402 bool wxToolBar::DeleteTool(
406 bool bOk
= wxToolBarBase::DeleteTool(nId
);
413 } // end of wxToolBar::DeleteTool
415 bool wxToolBar::DeleteToolByPos(
419 bool bOk
= wxToolBarBase::DeleteToolByPos(nPos
);
426 } // end of wxToolBar::DeleteTool
428 wxToolBarToolBase
* wxToolBar::InsertControl(
430 , wxControl
* pControl
433 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertControl( nPos
442 } // end of wxToolBar::InsertControl
444 wxToolBarToolBase
* wxToolBar::InsertSeparator(
448 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertSeparator(nPos
);
456 } // end of wxToolBar::InsertSeparator
458 wxToolBarToolBase
* wxToolBar::InsertTool(
461 , const wxString
& rsLabel
462 , const wxBitmap
& rBitmap
463 , const wxBitmap
& rBmpDisabled
465 , const wxString
& rsShortHelp
466 , const wxString
& rsLongHelp
467 , wxObject
* pClientData
470 wxToolBarToolBase
* pTool
= wxToolBarBase::InsertTool( nPos
486 } // end of wxToolBar::InsertTool
488 bool wxToolBar::DoInsertTool(
489 size_t WXUNUSED(nPos
)
490 , wxToolBarToolBase
* pToolBase
493 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
495 pTool
->m_vX
= m_vXPos
;
496 if (pTool
->m_vX
== -1)
497 pTool
->m_vX
= m_xMargin
;
499 pTool
->m_vY
= m_vYPos
;
500 if (pTool
->m_vY
== -1)
501 pTool
->m_vX
= m_yMargin
;
503 pTool
->SetSize(GetToolSize());
505 if (pTool
->IsButton())
508 // Calculate reasonable max size in case Layout() not called
510 if ((pTool
->m_vX
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
)
511 m_vMaxWidth
= (wxCoord
)((pTool
->m_vX
+ pTool
->GetWidth() + m_xMargin
));
513 if ((pTool
->m_vY
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
)
514 m_vMaxHeight
= (wxCoord
)((pTool
->m_vY
+ pTool
->GetHeight() + m_yMargin
));
517 } // end of wxToolBar::DoInsertTool
519 bool wxToolBar::DoDeleteTool(
520 size_t WXUNUSED(nPos
)
521 , wxToolBarToolBase
* pTool
527 } // end of wxToolBar::DoDeleteTool
529 bool wxToolBar::Create(
532 , const wxPoint
& rPos
533 , const wxSize
& rSize
535 , const wxString
& rsName
538 if ( !wxWindow::Create( pParent
547 // Set it to grey (or other 3D face colour)
548 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
549 SetFont(*wxSMALL_FONT
);
551 if (GetWindowStyleFlag() & wxTB_VERTICAL
)
556 m_maxRows
= 32000; // a lot
565 m_maxCols
= 32000; // a lot
567 SetCursor(*wxSTANDARD_CURSOR
);
570 // The toolbar's tools, if they have labels and the winTB_TEXT
571 // style is set, then we need to take into account the size of
572 // the text when drawing tool bitmaps and the text
574 if (HasFlag(wxTB_TEXT
))
576 wxClientDC
vDC(this);
578 vDC
.SetFont(GetFont());
579 vDC
.GetTextExtent( "XXXX"
590 int nWidth
= rSize
.x
;
591 int nHeight
= rSize
.y
;
592 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
594 if (lStyle
& wxTB_HORIZONTAL
)
598 nWidth
= pParent
->GetClientSize().x
;
602 if (lStyle
& wxTB_TEXT
)
603 nHeight
= m_defaultHeight
+ m_vTextY
;
605 nHeight
= m_defaultHeight
;
612 nHeight
= pParent
->GetClientSize().y
;
616 if (lStyle
& wxTB_TEXT
)
617 nWidth
= m_vTextX
+ (int)(m_vTextX
/2); // a little margin
619 nWidth
= m_defaultWidth
+ (int)(m_defaultWidth
/2); // a little margin
633 } // end of wxToolBar::Create
635 wxToolBar::~wxToolBar()
637 } // end of wxToolBar::~wxToolBar
639 bool wxToolBar::Realize()
641 int nMaxToolWidth
= 0;
642 int nMaxToolHeight
= 0;
646 m_nCurrentRowsOrColumns
= 0;
647 m_vLastX
= m_xMargin
;
648 m_vLastY
= m_yMargin
;
654 // Find the maximum tool width and height
656 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
660 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
662 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
665 // Set the height according to the font and the border size
667 if (pTool
->GetWidth() > m_vTextX
)
668 nMaxToolWidth
= pTool
->GetWidth() + 4;
670 nMaxToolWidth
= m_vTextX
;
671 if (pTool
->GetHeight() + m_vTextY
> nMaxToolHeight
)
672 nMaxToolHeight
= pTool
->GetHeight() + m_vTextY
;
676 if (pTool
->GetWidth() > nMaxToolWidth
)
677 nMaxToolWidth
= pTool
->GetWidth() + 4;
678 if (pTool
->GetHeight() > nMaxToolHeight
)
679 nMaxToolHeight
= pTool
->GetHeight();
681 pNode
= pNode
->GetNext();
684 wxCoord vTbWidth
= 0L;
685 wxCoord vTbHeight
= 0L;
690 if (vTbHeight
< nMaxToolHeight
)
697 if (GetParent()->IsKindOf(CLASSINFO(wxFrame
)))
699 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
702 pFrame
->PositionToolBar();
706 int nSeparatorSize
= m_toolSeparation
;
708 pNode
= m_tools
.GetFirst();
711 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
713 if (pTool
->IsSeparator())
715 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
717 pTool
->m_vX
= m_vLastX
+ nSeparatorSize
;
718 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
719 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
720 m_vLastY
+= nSeparatorSize
;
722 m_vLastX
+= nSeparatorSize
* 4;
726 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
;
727 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
728 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
729 m_vLastX
+= nSeparatorSize
;
731 m_vLastY
+= nSeparatorSize
* 4;
734 else if (pTool
->IsButton())
736 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
738 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
740 m_nCurrentRowsOrColumns
= 0;
741 m_vLastX
= m_xMargin
;
742 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
;
744 pTool
->m_vX
= m_vLastX
+ (nMaxToolWidth
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2)));
745 if (HasFlag(wxTB_TEXT
))
746 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
- 2; // just bit of adjustment
748 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
749 m_vLastX
+= nMaxToolWidth
+ m_toolPacking
+ m_toolSeparation
;
753 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
755 m_nCurrentRowsOrColumns
= 0;
756 m_vLastX
+= (nMaxToolWidth
+ m_toolPacking
);
757 m_vLastY
= m_yMargin
;
759 pTool
->m_vX
= m_vLastX
+ pTool
->GetWidth();
760 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
761 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- m_vTextY
) + m_toolPacking
;
763 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
764 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
+ m_toolSeparation
;
766 m_nCurrentRowsOrColumns
++;
770 // TODO: support the controls
773 if (m_vLastX
> m_maxWidth
)
774 m_maxWidth
= m_vLastX
;
775 if (m_vLastY
> m_maxHeight
)
776 m_maxHeight
= m_vLastY
;
778 pNode
= pNode
->GetNext();
781 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
782 m_maxWidth
+= nMaxToolWidth
;
784 m_maxHeight
+= nMaxToolHeight
;
786 m_maxWidth
+= m_xMargin
;
787 m_maxHeight
+= m_yMargin
;
788 m_bInitialized
= TRUE
;
790 } // end of wxToolBar::Realize
792 // ----------------------------------------------------------------------------
794 // ----------------------------------------------------------------------------
796 void wxToolBar::OnPaint (
797 wxPaintEvent
& WXUNUSED(rEvent
)
804 static int nCount
= 0;
807 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
813 ::WinFillRect(vDc
.GetHPS(), &vDc
.m_vRclPaint
, GetBackgroundColour().GetPixel());
814 for ( wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
816 pNode
= pNode
->GetNext() )
818 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
820 if (pTool
->IsButton() )
821 DrawTool(vDc
, pTool
);
822 if (pTool
->IsSeparator())
824 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
832 vDc
.SetPen(vDarkGreyPen
);
833 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
836 nY
= pTool
->m_vY
- (m_vTextY
- 6);
837 nHeight
= (m_vTextY
- 2) + pTool
->GetHeight();
843 nHeight
= pTool
->GetHeight() - 2;
845 vDc
.DrawLine(nX
, nY
, nX
, nY
+ nHeight
);
849 } // end of wxToolBar::OnPaint
851 void wxToolBar::OnSize (
852 wxSizeEvent
& WXUNUSED(rEvent
)
855 #if wxUSE_CONSTRAINTS
859 } // end of wxToolBar::OnSize
861 void wxToolBar::OnKillFocus(
862 wxFocusEvent
& WXUNUSED(rEvent
)
865 OnMouseEnter(m_nPressedTool
= m_nCurrentTool
= -1);
866 } // end of wxToolBar::OnKillFocus
868 void wxToolBar::OnMouseEvent(
874 HPOINTER hPtr
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
);
876 ::WinSetPointer(HWND_DESKTOP
, hPtr
);
877 rEvent
.GetPosition(&vX
, &vY
);
879 wxToolBarTool
* pTool
= (wxToolBarTool
*)FindToolForPosition( vX
883 if (rEvent
.LeftDown())
894 if (m_nCurrentTool
> -1)
896 if (rEvent
.LeftIsDown())
897 SpringUpButton(m_nCurrentTool
);
898 pTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
899 if (pTool
&& !pTool
->IsToggled())
910 if (!rEvent
.IsButton())
912 if (pTool
->GetId() != m_nCurrentTool
)
915 // If the left button is kept down and moved over buttons,
916 // press those buttons.
918 if (rEvent
.LeftIsDown() && pTool
->IsEnabled())
920 SpringUpButton(m_nCurrentTool
);
921 if (pTool
->CanBeToggled())
927 wxToolBarTool
* pOldTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
929 if (pOldTool
&& !pTool
->IsToggled())
933 m_nCurrentTool
= pTool
->GetId();
934 OnMouseEnter(m_nCurrentTool
);
935 if (!pTool
->IsToggled())
941 // Left button pressed.
942 if (rEvent
.LeftDown() && pTool
->IsEnabled())
944 if (pTool
->CanBeToggled())
950 else if (rEvent
.RightDown())
952 OnRightClick( pTool
->GetId()
959 // Left Button Released. Only this action confirms selection.
960 // If the button is enabled and it is not a toggle tool and it is
961 // in the pressed state, then raise the button and call OnLeftClick.
963 if (rEvent
.LeftUp() && pTool
->IsEnabled() )
966 // Pass the OnLeftClick event to tool
968 if (!OnLeftClick( pTool
->GetId()
969 ,pTool
->IsToggled()) &&
970 pTool
->CanBeToggled())
973 // If it was a toggle, and OnLeftClick says No Toggle allowed,
974 // then change it back
980 } // end of wxToolBar::OnMouseEvent
982 // ----------------------------------------------------------------------------
984 // ----------------------------------------------------------------------------
986 void wxToolBar::DrawTool(
987 wxToolBarToolBase
* pTool
990 wxClientDC
vDc(this);
995 } // end of wxToolBar::DrawTool
997 void wxToolBar::DrawTool(
999 , wxToolBarToolBase
* pToolBase
1002 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1003 wxPen
vDarkGreyPen( wxColour( 85,85,85 )
1007 wxPen
vWhitePen( wxT("WHITE")
1011 wxPen
vBlackPen( wxT("BLACK")
1015 wxBitmap vBitmap
= pTool
->GetNormalBitmap();
1016 bool bUseMask
= FALSE
;
1017 wxMask
* pMask
= NULL
;
1024 if ((pMask
= vBitmap
.GetMask()) != NULL
)
1025 if (pMask
->GetMaskBitmap() != NULLHANDLE
)
1028 if (!pTool
->IsToggled())
1030 LowerTool(pTool
, FALSE
);
1031 if (!pTool
->IsEnabled())
1033 wxColour
vColor("GREY");
1035 rDc
.SetTextForeground(vColor
);
1036 if (!pTool
->GetDisabledBitmap().Ok())
1037 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1038 ,(long)GetBackgroundColour().GetPixel()
1040 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1048 wxColour
vColor("BLACK");
1050 rDc
.SetTextForeground(vColor
);
1051 rDc
.DrawBitmap( vBitmap
1057 if (m_windowStyle
& wxTB_3DBUTTONS
)
1061 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1065 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1067 rDc
.SetFont(GetFont());
1068 rDc
.GetTextExtent( pTool
->GetLabel()
1072 if (pTool
->GetWidth() > vX
) // large tools
1074 vLeft
= pTool
->m_vX
+ (pTool
->GetWidth() - vX
);
1076 rDc
.DrawText( pTool
->GetLabel()
1078 ,vY
- (m_vTextY
- 2)
1081 else // normal tools
1083 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1084 rDc
.DrawText( pTool
->GetLabel()
1086 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1093 wxColour
vColor("GREY");
1096 rDc
.SetTextForeground(vColor
);
1097 if (!pTool
->GetDisabledBitmap().Ok())
1098 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
1099 ,(long)GetBackgroundColour().GetPixel()
1101 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
1106 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1110 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
1112 rDc
.SetFont(GetFont());
1113 rDc
.GetTextExtent( pTool
->GetLabel()
1117 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
1118 rDc
.DrawText( pTool
->GetLabel()
1120 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
1124 } // end of wxToolBar::DrawTool
1126 // ----------------------------------------------------------------------------
1128 // ----------------------------------------------------------------------------
1130 void wxToolBar::SetRows(
1134 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
1136 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
1138 } // end of wxToolBar::SetRows
1140 wxToolBarToolBase
* wxToolBar::FindToolForPosition(
1147 wxCoord vTBarHeight
= 0;
1152 vY
= vTBarHeight
- vY
;
1153 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
1156 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
1158 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1160 if ((vX
>= (pTool
->m_vX
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) &&
1161 (vY
>= (pTool
->m_vY
- 2)) &&
1162 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1163 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight() + m_vTextY
+ 2)))
1170 if ((vX
>= pTool
->m_vX
) &&
1171 (vY
>= pTool
->m_vY
) &&
1172 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1173 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight())))
1178 pNode
= pNode
->GetNext();
1180 return (wxToolBarToolBase
*)NULL
;
1181 } // end of wxToolBar::FindToolForPosition
1183 // ----------------------------------------------------------------------------
1184 // tool state change handlers
1185 // ----------------------------------------------------------------------------
1187 void wxToolBar::DoEnableTool(
1188 wxToolBarToolBase
* pTool
1189 , bool WXUNUSED(bEnable
)
1193 } // end of wxToolBar::DoEnableTool
1195 void wxToolBar::DoToggleTool(
1196 wxToolBarToolBase
* pTool
1197 , bool WXUNUSED(bToggle
)
1201 } // end of wxToolBar::DoToggleTool
1203 void wxToolBar::DoSetToggle(
1204 wxToolBarToolBase
* WXUNUSED(pTool
)
1205 , bool WXUNUSED(bToggle
)
1209 } // end of wxToolBar::DoSetToggle
1212 // Okay, so we've left the tool we're in ... we must check if the tool we're
1213 // leaving was a 'sprung push button' and if so, spring it back to the up
1216 void wxToolBar::SpringUpButton(
1220 wxToolBarToolBase
* pTool
= FindById(vId
);
1222 if (pTool
&& pTool
->CanBeToggled())
1224 if (pTool
->IsToggled())
1229 } // end of wxToolBar::SpringUpButton
1231 // ----------------------------------------------------------------------------
1233 // ----------------------------------------------------------------------------
1235 void wxToolBar::LowerTool (
1236 wxToolBarToolBase
* pToolBase
1240 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1245 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1249 wxPen
vWhitePen( "WHITE"
1253 wxPen
vClearPen( GetBackgroundColour()
1257 wxClientDC
vDC(this);
1262 if (pTool
->IsSeparator())
1266 // We only do this for flat toolbars
1268 if (!HasFlag(wxTB_FLAT
))
1271 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1273 if (pTool
->GetWidth() > m_vTextX
)
1275 vX
= pTool
->m_vX
- 2;
1276 vWidth
= pTool
->GetWidth() + 4;
1280 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1281 vWidth
= m_vTextX
+ 4;
1283 vY
= pTool
->m_vY
- 2;
1284 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1288 vX
= pTool
->m_vX
- 2;
1289 vY
= pTool
->m_vY
- 2;
1290 vWidth
= pTool
->GetWidth() + 4;
1291 vHeight
= pTool
->GetHeight() + 4;
1295 vDC
.SetPen(vWhitePen
);
1296 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1297 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1298 vDC
.SetPen(vDarkGreyPen
);
1299 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1300 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1304 vDC
.SetPen(vClearPen
);
1305 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1306 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1307 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1308 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1310 } // end of WinGuiBase_CToolBarTool::LowerTool
1312 void wxToolBar::RaiseTool (
1313 wxToolBarToolBase
* pToolBase
1317 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1322 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1326 wxPen
vWhitePen( "WHITE"
1330 wxPen
vClearPen( GetBackgroundColour()
1334 wxClientDC
vDC(this);
1339 if (pTool
->IsSeparator())
1342 if (!pTool
->IsEnabled())
1346 // We only do this for flat toolbars
1348 if (!HasFlag(wxTB_FLAT
))
1351 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1353 if (pTool
->GetWidth() > m_vTextX
)
1355 vX
= pTool
->m_vX
- 2;
1356 vWidth
= pTool
->GetWidth() + 4;
1360 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1361 vWidth
= m_vTextX
+ 4;
1363 vY
= pTool
->m_vY
- 2;
1364 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1368 vX
= pTool
->m_vX
- 2;
1369 vY
= pTool
->m_vY
- 2;
1370 vWidth
= pTool
->GetWidth() + 4;
1371 vHeight
= pTool
->GetHeight() + 4;
1375 vDC
.SetPen(vDarkGreyPen
);
1376 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1377 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1378 vDC
.SetPen(vWhitePen
);
1379 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1380 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1384 vDC
.SetPen(vClearPen
);
1385 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1386 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1387 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1388 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1390 } // end of wxToolBar::RaiseTool
1392 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE