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
);
231 vNewBmp
.SetMask(rBmp
.GetMask());
233 ::GpiSetBitmap(hPS
, NULLHANDLE
);
238 return(wxNullBitmap
);
239 } // end of wxDisableBitmap
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
245 class wxToolBarTool
: public wxToolBarToolBase
248 inline wxToolBarTool( wxToolBar
* pTbar
250 ,const wxString
& rsLabel
251 ,const wxBitmap
& rBitmap1
252 ,const wxBitmap
& rBitmap2
254 ,wxObject
* pClientData
255 ,const wxString
& rsShortHelpString
256 ,const wxString
& rsLongHelpString
257 ) : wxToolBarToolBase( pTbar
270 inline wxToolBarTool( wxToolBar
* pTbar
272 ) : wxToolBarToolBase( pTbar
278 void SetSize(const wxSize
& rSize
)
284 wxCoord
GetWidth(void) const { return m_vWidth
; }
285 wxCoord
GetHeight(void) const { return m_vHeight
; }
291 }; // end of CLASS wxToolBarTool
293 // ----------------------------------------------------------------------------
295 // ----------------------------------------------------------------------------
297 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarBase
)
299 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
300 EVT_SIZE(wxToolBar::OnSize
)
301 EVT_PAINT(wxToolBar::OnPaint
)
302 EVT_KILL_FOCUS(wxToolBar::OnKillFocus
)
303 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
306 // ============================================================================
308 // ============================================================================
310 // ----------------------------------------------------------------------------
311 // tool bar tools creation
312 // ----------------------------------------------------------------------------
314 wxToolBarToolBase
* wxToolBar::CreateTool(
316 , const wxString
& rsLabel
317 , const wxBitmap
& rBmpNormal
318 , const wxBitmap
& rBmpDisabled
320 , wxObject
* pClientData
321 , const wxString
& rsShortHelp
322 , const wxString
& rsLongHelp
325 return new wxToolBarTool( this
335 } // end of wxToolBarSimple::CreateTool
337 wxToolBarToolBase
*wxToolBar::CreateTool(
341 return new wxToolBarTool( this
344 } // end of wxToolBarSimple::CreateTool
346 // ----------------------------------------------------------------------------
347 // wxToolBarSimple creation
348 // ----------------------------------------------------------------------------
350 void wxToolBar::Init()
352 m_nCurrentRowsOrColumns
= 0;
354 m_vLastX
= m_vLastY
= 0;
355 m_vMaxWidth
= m_vMaxHeight
= 0;
356 m_nPressedTool
= m_nCurrentTool
= -1;
357 m_vXPos
= m_vYPos
= -1;
358 m_vTextX
= m_vTextY
= 0;
361 m_toolSeparation
= 5;
364 m_defaultHeight
= 15;
365 } // end of wxToolBar::Init
367 wxToolBarToolBase
* wxToolBar::DoAddTool(
369 , const wxString
& rsLabel
370 , const wxBitmap
& rBitmap
371 , const wxBitmap
& rBmpDisabled
373 , const wxString
& rsShortHelp
374 , const wxString
& rsLongHelp
375 , wxObject
* pClientData
381 // Rememeber the position for DoInsertTool()
386 return wxToolBarBase::DoAddTool( vId
397 } // end of wxToolBar::DoAddTool
399 bool wxToolBar::DoInsertTool(
400 size_t WXUNUSED(nPos
)
401 , wxToolBarToolBase
* pToolBase
404 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
406 pTool
->m_vX
= m_vXPos
;
407 if (pTool
->m_vX
== -1)
408 pTool
->m_vX
= m_xMargin
;
410 pTool
->m_vY
= m_vYPos
;
411 if (pTool
->m_vY
== -1)
412 pTool
->m_vX
= m_yMargin
;
414 pTool
->SetSize(GetToolSize());
416 if (pTool
->IsButton())
419 // Calculate reasonable max size in case Layout() not called
421 if ((pTool
->m_vX
+ pTool
->GetNormalBitmap().GetWidth() + m_xMargin
) > m_vMaxWidth
)
422 m_vMaxWidth
= (wxCoord
)((pTool
->m_vX
+ pTool
->GetWidth() + m_xMargin
));
424 if ((pTool
->m_vY
+ pTool
->GetNormalBitmap().GetHeight() + m_yMargin
) > m_vMaxHeight
)
425 m_vMaxHeight
= (wxCoord
)((pTool
->m_vY
+ pTool
->GetHeight() + m_yMargin
));
428 } // end of wxToolBar::DoInsertTool
430 bool wxToolBar::DoDeleteTool(
431 size_t WXUNUSED(nPos
)
432 , wxToolBarToolBase
* pTool
438 } // end of wxToolBar::DoDeleteTool
440 bool wxToolBar::Create(
443 , const wxPoint
& rPos
444 , const wxSize
& rSize
446 , const wxString
& rsName
449 if ( !wxWindow::Create( pParent
458 // Set it to grey (or other 3D face colour)
459 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
460 SetFont(*wxSMALL_FONT
);
462 if (GetWindowStyleFlag() & wxTB_VERTICAL
)
467 m_maxRows
= 32000; // a lot
476 m_maxCols
= 32000; // a lot
478 SetCursor(*wxSTANDARD_CURSOR
);
481 // The toolbar's tools, if they have labels and the winTB_TEXT
482 // style is set, then we need to take into account the size of
483 // the text when drawing tool bitmaps and the text
485 if (HasFlag(wxTB_TEXT
))
487 wxClientDC
vDC(this);
489 vDC
.SetFont(GetFont());
490 vDC
.GetTextExtent( "XXXX"
501 int nWidth
= rSize
.x
;
502 int nHeight
= rSize
.y
;
503 wxFrame
* pFrame
= wxDynamicCast(GetParent(), wxFrame
);
505 if (lStyle
& wxTB_HORIZONTAL
)
509 nWidth
= pParent
->GetClientSize().x
;
513 if (lStyle
& wxTB_TEXT
)
514 nHeight
= m_defaultHeight
+ 18;
516 nHeight
= m_defaultHeight
;
523 nHeight
= pParent
->GetClientSize().y
;
527 if (lStyle
& wxTB_TEXT
)
528 nWidth
= m_vTextX
+ (int)(m_vTextX
/2); // a little margin
530 nWidth
= m_defaultWidth
+ (int)(m_defaultWidth
/2); // a little margin
544 } // end of wxToolBar::Create
546 wxToolBar::~wxToolBar()
548 } // end of wxToolBar::~wxToolBar
550 bool wxToolBar::Realize()
552 int nMaxToolWidth
= 0;
553 int nMaxToolHeight
= 0;
557 m_nCurrentRowsOrColumns
= 0;
558 m_vLastX
= m_xMargin
;
559 m_vLastY
= m_yMargin
;
565 // Find the maximum tool width and height
567 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
571 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
573 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
576 // Set the height according to the font and the border size
578 nMaxToolWidth
= m_vTextX
;
579 if (pTool
->GetHeight() + m_vTextY
> nMaxToolHeight
)
580 nMaxToolHeight
= pTool
->GetHeight() + m_vTextY
;
584 if (pTool
->GetWidth() > nMaxToolWidth
)
585 nMaxToolWidth
= pTool
->GetWidth();
586 if (pTool
->GetHeight() > nMaxToolHeight
)
587 nMaxToolHeight
= pTool
->GetHeight();
589 pNode
= pNode
->GetNext();
592 int nSeparatorSize
= m_toolSeparation
;
594 pNode
= m_tools
.GetFirst();
597 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
599 if (pTool
->IsSeparator())
601 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
603 pTool
->m_vX
= m_vLastX
+ nSeparatorSize
;
604 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
605 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
606 m_vLastY
+= nSeparatorSize
;
608 m_vLastX
+= nSeparatorSize
;
612 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
;
613 pTool
->m_vHeight
= m_defaultHeight
+ m_vTextY
;
614 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
615 m_vLastX
+= nSeparatorSize
;
617 m_vLastY
+= nSeparatorSize
;
620 else if (pTool
->IsButton())
622 if (GetWindowStyleFlag() & wxTB_HORIZONTAL
)
624 if (m_nCurrentRowsOrColumns
>= m_maxCols
)
626 m_nCurrentRowsOrColumns
= 0;
627 m_vLastX
= m_xMargin
;
628 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
;
630 pTool
->m_vX
= m_vLastX
+ (nMaxToolWidth
- ((int)(nMaxToolWidth
/2) + (int)(pTool
->GetWidth()/2)));
631 if (HasFlag(wxTB_TEXT
))
632 pTool
->m_vY
= m_vLastY
+ nSeparatorSize
- 2; // just bit of adjustment
634 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
635 m_vLastX
+= nMaxToolWidth
+ m_toolPacking
+ m_toolSeparation
;
639 if (m_nCurrentRowsOrColumns
>= m_maxRows
)
641 m_nCurrentRowsOrColumns
= 0;
642 m_vLastX
+= (nMaxToolWidth
+ m_toolPacking
);
643 m_vLastY
= m_yMargin
;
645 pTool
->m_vX
= m_vLastX
+ pTool
->GetWidth();
646 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
647 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- m_vTextY
) + m_toolPacking
;
649 pTool
->m_vY
= m_vLastY
+ (nMaxToolHeight
- (int)(pTool
->GetHeight()/2));
650 m_vLastY
+= nMaxToolHeight
+ m_toolPacking
+ m_toolSeparation
;
652 m_nCurrentRowsOrColumns
++;
656 // TODO: support the controls
659 if (m_vLastX
> m_maxWidth
)
660 m_maxWidth
= m_vLastX
;
661 if (m_vLastY
> m_maxHeight
)
662 m_maxHeight
= m_vLastY
;
664 pNode
= pNode
->GetNext();
667 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
668 m_maxWidth
+= nMaxToolWidth
;
670 m_maxHeight
+= nMaxToolHeight
;
672 m_maxWidth
+= m_xMargin
;
673 m_maxHeight
+= m_yMargin
;
675 } // end of wxToolBar::Realize
677 // ----------------------------------------------------------------------------
679 // ----------------------------------------------------------------------------
681 void wxToolBar::OnPaint (
682 wxPaintEvent
& WXUNUSED(rEvent
)
689 static int nCount
= 0;
692 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
698 for ( wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
700 pNode
= pNode
->GetNext() )
702 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
704 if (pTool
->IsButton() )
705 DrawTool(vDc
, pTool
);
706 if (pTool
->IsSeparator())
708 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
716 vDc
.SetPen(vDarkGreyPen
);
717 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
720 nY
= pTool
->m_vY
- (m_vTextY
- 6);
721 nHeight
= (m_vTextY
- 2) + pTool
->GetHeight();
727 nHeight
= pTool
->GetHeight() - 2;
729 vDc
.DrawLine(nX
, nY
, nX
, nY
+ nHeight
);
733 } // end of wxToolBar::OnPaint
735 void wxToolBar::OnSize (
736 wxSizeEvent
& WXUNUSED(rEvent
)
739 #if wxUSE_CONSTRAINTS
743 } // end of wxToolBar::OnSize
745 void wxToolBar::OnKillFocus(
746 wxFocusEvent
& WXUNUSED(rEvent
)
749 OnMouseEnter(m_nPressedTool
= m_nCurrentTool
= -1);
750 } // end of wxToolBar::OnKillFocus
752 void wxToolBar::OnMouseEvent(
758 HPOINTER hPtr
= ::WinQuerySysPointer(HWND_DESKTOP
, SPTR_ARROW
, FALSE
);
760 ::WinSetPointer(HWND_DESKTOP
, hPtr
);
761 rEvent
.GetPosition(&vX
, &vY
);
763 wxToolBarTool
* pTool
= (wxToolBarTool
*)FindToolForPosition( vX
767 if (rEvent
.LeftDown())
778 if (m_nCurrentTool
> -1)
780 if (rEvent
.LeftIsDown())
781 SpringUpButton(m_nCurrentTool
);
782 pTool
= (wxToolBarTool
*)FindById(m_nCurrentTool
);
783 if (pTool
&& pTool
->IsToggled())
794 if (!rEvent
.IsButton())
796 if (pTool
->GetId() != m_nCurrentTool
)
799 // If the left button is kept down and moved over buttons,
800 // press those buttons.
802 if (rEvent
.LeftIsDown() && pTool
->IsEnabled())
804 SpringUpButton(m_nCurrentTool
);
805 if (pTool
->CanBeToggled())
811 m_nCurrentTool
= pTool
->GetId();
812 OnMouseEnter(m_nCurrentTool
);
813 if (!pTool
->IsToggled())
819 // Left button pressed.
820 if (rEvent
.LeftDown() && pTool
->IsEnabled())
822 if (pTool
->CanBeToggled())
828 else if (rEvent
.RightDown())
830 OnRightClick( pTool
->GetId()
837 // Left Button Released. Only this action confirms selection.
838 // If the button is enabled and it is not a toggle tool and it is
839 // in the pressed state, then raise the button and call OnLeftClick.
841 if (rEvent
.LeftUp() && pTool
->IsEnabled() )
844 // Pass the OnLeftClick event to tool
846 if (!OnLeftClick( pTool
->GetId()
847 ,pTool
->IsToggled()) &&
848 pTool
->CanBeToggled())
851 // If it was a toggle, and OnLeftClick says No Toggle allowed,
852 // then change it back
858 } // end of wxToolBar::OnMouseEvent
860 // ----------------------------------------------------------------------------
862 // ----------------------------------------------------------------------------
864 void wxToolBar::DrawTool(
865 wxToolBarToolBase
* pTool
868 wxClientDC
vDc(this);
873 } // end of wxToolBar::DrawTool
875 void wxToolBar::DrawTool(
877 , wxToolBarToolBase
* pToolBase
880 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
881 wxPen
vDarkGreyPen( wxColour( 85,85,85 )
885 wxPen
vWhitePen( wxT("WHITE")
889 wxPen
vBlackPen( wxT("BLACK")
893 wxBitmap vBitmap
= pTool
->GetNormalBitmap();
894 bool bUseMask
= FALSE
;
895 wxMask
* pMask
= NULL
;
902 if ((pMask
= vBitmap
.GetMask()) != NULL
)
903 if (pMask
->GetMaskBitmap() != NULLHANDLE
)
906 if (!pTool
->IsToggled())
908 LowerTool(pTool
, FALSE
);
909 if (!pTool
->IsEnabled())
911 wxColour
vColor("GREY");
913 rDc
.SetTextForeground(vColor
);
914 if (!pTool
->GetDisabledBitmap().Ok())
915 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
916 ,(long)GetBackgroundColour().GetPixel()
918 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
926 wxColour
vColor("BLACK");
928 rDc
.SetTextForeground(vColor
);
929 rDc
.DrawBitmap( vBitmap
935 if (m_windowStyle
& wxTB_3DBUTTONS
)
939 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
943 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
945 rDc
.SetFont(GetFont());
946 rDc
.GetTextExtent( pTool
->GetLabel()
950 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
951 rDc
.DrawText( pTool
->GetLabel()
953 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
959 wxColour
vColor("GREY");
962 rDc
.SetTextForeground(vColor
);
963 if (!pTool
->GetDisabledBitmap().Ok())
964 pTool
->SetDisabledBitmap(wxDisableBitmap( vBitmap
965 ,(long)GetBackgroundColour().GetPixel()
967 rDc
.DrawBitmap( pTool
->GetDisabledBitmap()
972 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
976 wxCoord vLeft
= pTool
->m_vX
- (int)(pTool
->GetWidth()/2);
978 rDc
.SetFont(GetFont());
979 rDc
.GetTextExtent( pTool
->GetLabel()
983 vLeft
+= (wxCoord
)((m_vTextX
- vX
)/2);
984 rDc
.DrawText( pTool
->GetLabel()
986 ,pTool
->m_vY
+ m_vTextY
+ 4 // a bit of margin
990 } // end of wxToolBar::DrawTool
992 // ----------------------------------------------------------------------------
994 // ----------------------------------------------------------------------------
996 void wxToolBar::SetRows(
1000 wxCHECK_RET( nRows
!= 0, _T("max number of rows must be > 0") );
1002 m_maxCols
= (GetToolsCount() + nRows
- 1) / nRows
;
1004 } // end of wxToolBar::SetRows
1006 wxToolBarToolBase
* wxToolBar::FindToolForPosition(
1013 wxCoord vTBarHeight
= 0;
1015 wxToolBarToolsList::Node
* pNode
= m_tools
.GetFirst();
1018 wxToolBarTool
* pTool
= (wxToolBarTool
*)pNode
->GetData();
1020 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsNull())
1022 if ((vX
>= (pTool
->m_vX
- ((wxCoord
)(pTool
->GetWidth()/2) - 2))) &&
1023 (vY
>= (pTool
->m_vY
- 2)) &&
1024 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1025 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight() + m_vTextY
+ 2)))
1032 if ((vX
>= pTool
->m_vX
) &&
1033 (vY
>= pTool
->m_vY
) &&
1034 (vX
<= (pTool
->m_vX
+ pTool
->GetWidth())) &&
1035 (vY
<= (pTool
->m_vY
+ pTool
->GetHeight())))
1040 pNode
= pNode
->GetNext();
1042 return (wxToolBarToolBase
*)NULL
;
1043 } // end of wxToolBar::FindToolForPosition
1045 // ----------------------------------------------------------------------------
1046 // tool state change handlers
1047 // ----------------------------------------------------------------------------
1049 void wxToolBar::DoEnableTool(
1050 wxToolBarToolBase
* pTool
1051 , bool WXUNUSED(bEnable
)
1055 } // end of wxToolBar::DoEnableTool
1057 void wxToolBar::DoToggleTool(
1058 wxToolBarToolBase
* pTool
1059 , bool WXUNUSED(bToggle
)
1063 } // end of wxToolBar::DoToggleTool
1065 void wxToolBar::DoSetToggle(
1066 wxToolBarToolBase
* WXUNUSED(pTool
)
1067 , bool WXUNUSED(bToggle
)
1071 } // end of wxToolBar::DoSetToggle
1074 // Okay, so we've left the tool we're in ... we must check if the tool we're
1075 // leaving was a 'sprung push button' and if so, spring it back to the up
1078 void wxToolBar::SpringUpButton(
1082 wxToolBarToolBase
* pTool
= FindById(vId
);
1084 if (pTool
&& pTool
->CanBeToggled())
1086 if (pTool
->IsToggled())
1091 } // end of wxToolBar::SpringUpButton
1093 // ----------------------------------------------------------------------------
1095 // ----------------------------------------------------------------------------
1097 void wxToolBar::LowerTool (
1098 wxToolBarToolBase
* pToolBase
1102 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1107 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1111 wxPen
vWhitePen( "WHITE"
1115 wxPen
vClearPen( GetBackgroundColour()
1119 wxClientDC
vDC(this);
1124 if (pTool
->IsSeparator())
1128 // We only do this for flat toolbars
1130 if (!HasFlag(wxTB_FLAT
))
1133 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1135 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1136 vY
= pTool
->m_vY
- 2;
1137 vWidth
= m_vTextX
+ 4;
1138 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1143 vY
= pTool
->m_vY
- 2;
1144 vWidth
= pTool
->GetWidth() + 4;
1145 vHeight
= pTool
->GetHeight() + 4;
1149 vDC
.SetPen(vWhitePen
);
1150 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1151 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1152 vDC
.SetPen(vDarkGreyPen
);
1153 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1154 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1158 vDC
.SetPen(vClearPen
);
1159 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1160 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1161 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1162 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1164 } // end of WinGuiBase_CToolBarTool::LowerTool
1166 void wxToolBar::RaiseTool (
1167 wxToolBarToolBase
* pToolBase
1171 wxToolBarTool
* pTool
= (wxToolBarTool
*)pToolBase
;
1176 wxPen
vDarkGreyPen( wxColour(85, 85, 85)
1180 wxPen
vWhitePen( "WHITE"
1184 wxPen
vClearPen( GetBackgroundColour()
1188 wxClientDC
vDC(this);
1193 if (pTool
->IsSeparator())
1196 if (!pTool
->IsEnabled())
1200 // We only do this for flat toolbars
1202 if (!HasFlag(wxTB_FLAT
))
1205 if (HasFlag(wxTB_TEXT
) && !pTool
->GetLabel().IsEmpty())
1207 vX
= pTool
->m_vX
- (wxCoord
)(pTool
->GetWidth()/2);
1208 vY
= pTool
->m_vY
- 2;
1209 vWidth
= m_vTextX
+ 4;
1210 vHeight
= pTool
->GetHeight() + m_vTextY
+ 2;
1215 vY
= pTool
->m_vY
- 2;
1216 vWidth
= pTool
->GetWidth() + 4;
1217 vHeight
= pTool
->GetHeight() + 4;
1221 vDC
.SetPen(vDarkGreyPen
);
1222 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1223 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1224 vDC
.SetPen(vWhitePen
);
1225 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1226 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1230 vDC
.SetPen(vClearPen
);
1231 vDC
.DrawLine(vX
+ vWidth
, vY
+ vHeight
, vX
, vY
+ vHeight
);
1232 vDC
.DrawLine(vX
+ vWidth
, vY
, vX
+ vWidth
, vY
+ vHeight
);
1233 vDC
.DrawLine(vX
, vY
, vX
+ vWidth
, vY
);
1234 vDC
.DrawLine(vX
, vY
+ vHeight
, vX
, vY
);
1236 } // end of wxToolBar::RaiseTool
1238 #endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE