]> git.saurik.com Git - wxWidgets.git/blame - src/os2/toolbar.cpp
added and documented wxProcess::Is{Input|Error}Available() and IsInputOpened
[wxWidgets.git] / src / os2 / toolbar.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: toolbar.cpp
3// Purpose: wxToolBar
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d697657f 6// Created: 06/30/02
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
d697657f
DW
15#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE
16
d90895ac 17#ifndef WX_PRECOMP
d697657f
DW
18 #include "wx/settings.h"
19 #include "wx/window.h"
20 #include "wx/dcclient.h"
21 #include "wx/dcmemory.h"
d90895ac
DW
22#endif
23
05facebb 24#include "wx/tooltip.h"
b7c2b5c5 25#include "wx/toolbar.h"
d90895ac 26
d697657f 27bool wxToolBar::m_bInitialized = FALSE;
d90895ac 28
d697657f
DW
29// ---------------------------------------------------------------------------
30// Helper for taking a regular bitmap and giving it a disabled look
31// ---------------------------------------------------------------------------
32wxBitmap wxDisableBitmap(
33 const wxBitmap& rBmp
34, long lColor
35)
36{
37 wxMask* pMask = rBmp.GetMask();
38
39 if (!pMask)
40 return(wxNullBitmap);
41
42 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
43 SIZEL vSize = {0, 0};
44 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
45 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
46 BITMAPINFOHEADER2 vHeader;
47 BITMAPINFO2 vInfo;
48 ERRORID vError;
49 wxString sError;
50 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
51 HBITMAP hOldBitmap = NULLHANDLE;
52 HBITMAP hOldMask = NULLHANDLE;
53 HBITMAP hMask = (HBITMAP)rBmp.GetMask()->GetMaskBitmap();
54 unsigned char* pucBits; // buffer that will contain the bitmap data
55 unsigned char* pucData; // pointer to use to traverse bitmap data
56 unsigned char* pucBitsMask; // buffer that will contain the mask data
57 unsigned char* pucDataMask; // pointer to use to traverse mask data
58 LONG lScans = 0L;
59 LONG lScansSet = 0L;
60 bool bpp16 = (wxDisplayDepth() == 16);
61
62 memset(&vHeader, '\0', 16);
63 vHeader.cbFix = 16;
64
65 memset(&vInfo, '\0', 16);
66 vInfo.cbFix = 16;
67 vInfo.cx = (ULONG)rBmp.GetWidth();
68 vInfo.cy = (ULONG)rBmp.GetHeight();
69 vInfo.cPlanes = 1;
70 vInfo.cBitCount = 24; // Set to desired count going in
71
72 //
73 // Create the buffers for data....all wxBitmaps are 24 bit internally
74 //
75 int nBytesPerLine = rBmp.GetWidth() * 3;
76 int nSizeDWORD = sizeof(DWORD);
77 int nLineBoundary = nBytesPerLine % nSizeDWORD;
78 int nPadding = 0;
79 int i;
80 int j;
81
82 //
83 // Bitmap must be ina double-word alligned address so we may
84 // have some padding to worry about
85 //
86 if (nLineBoundary > 0)
87 {
88 nPadding = nSizeDWORD - nLineBoundary;
89 nBytesPerLine += nPadding;
90 }
91 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
92 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
93 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
94 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
95
96 //
97 // Extract the bitmap and mask data
98 //
99 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
100 {
101 vError = ::WinGetLastError(vHabmain);
102 sError = wxPMErrorToStr(vError);
103 }
104 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
105 vInfo.cBitCount = 24;
106 if ((lScans = ::GpiQueryBitmapBits( hPS
107 ,0L
108 ,(LONG)rBmp.GetHeight()
109 ,(PBYTE)pucBits
110 ,&vInfo
111 )) == GPI_ALTERROR)
112 {
113 vError = ::WinGetLastError(vHabmain);
114 sError = wxPMErrorToStr(vError);
115 }
116 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
117 {
118 vError = ::WinGetLastError(vHabmain);
119 sError = wxPMErrorToStr(vError);
120 }
121 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
122 vInfo.cBitCount = 24;
123 if ((lScans = ::GpiQueryBitmapBits( hPS
124 ,0L
125 ,(LONG)rBmp.GetHeight()
126 ,(PBYTE)pucBitsMask
127 ,&vInfo
128 )) == GPI_ALTERROR)
129 {
130 vError = ::WinGetLastError(vHabmain);
131 sError = wxPMErrorToStr(vError);
132 }
133 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
134 {
135 vError = ::WinGetLastError(vHabmain);
136 sError = wxPMErrorToStr(vError);
137 }
138 pucData = pucBits;
139 pucDataMask = pucBitsMask;
d90895ac 140
d697657f
DW
141 //
142 // Get the mask value
143 //
144 for (i = 0; i < rBmp.GetHeight(); i++)
145 {
146 for (j = 0; j < rBmp.GetWidth(); j++)
147 {
148 // Byte 1
149 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
150 {
151 *pucData = 0x7F;
152 pucData++;
153 }
154 else if (*pucDataMask == 0xFF) // set to grey
155 {
156 *pucData = 0x7F;
157 pucData++;
158 }
159 else
160 {
161 *pucData = ((unsigned char)(lColor >> 16));
162 pucData++;
163 }
0e320a79 164
d697657f
DW
165 // Byte 2
166 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
167 {
168 *pucData = 0x7F;
169 pucData++;
170 }
171 else if (*(pucDataMask + 1) == 0xFF) // set to grey
172 {
173 *pucData = 0x7F;
174 pucData++;
175 }
176 else
177 {
178 *pucData = ((unsigned char)(lColor >> 8));
179 pucData++;
180 }
b7c2b5c5 181
d697657f
DW
182 // Byte 3
183 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
184 {
185 *pucData = 0x7F;
186 pucData++;
187 }
188 else if (*(pucDataMask + 2) == 0xFF) // set to grey
189 {
190 *pucData = 0x7F;
191 pucData++;
192 }
193 else
194 {
195 *pucData = ((unsigned char)lColor);
196 pucData++;
197 }
198 pucDataMask += 3;
199 }
200 for (j = 0; j < nPadding; j++)
201 {
202 pucData++;
203 pucDataMask++;
204 }
205 }
b7c2b5c5 206
d697657f
DW
207 //
208 // Create a new bitmap and set the modified bits
209 //
210 wxBitmap vNewBmp( rBmp.GetWidth()
211 ,rBmp.GetHeight()
212 ,24
213 );
214 HBITMAP hNewBmp = (HBITMAP)vNewBmp.GetHBITMAP();
b7c2b5c5 215
d697657f
DW
216 if ((hOldBitmap = ::GpiSetBitmap(hPS, hNewBmp)) == HBM_ERROR)
217 {
218 vError = ::WinGetLastError(vHabmain);
219 sError = wxPMErrorToStr(vError);
220 }
221 if ((lScansSet = ::GpiSetBitmapBits( hPS
222 ,0L
223 ,(LONG)rBmp.GetHeight()
224 ,(PBYTE)pucBits
225 ,&vInfo
226 )) == GPI_ALTERROR)
0e320a79 227
d697657f
DW
228 {
229 vError = ::WinGetLastError(vHabmain);
230 sError = wxPMErrorToStr(vError);
231 }
3029781e
DW
232 wxMask* pNewMask;
233
234 pNewMask = new wxMask(pMask->GetMaskBitmap());
235 vNewBmp.SetMask(pNewMask);
d697657f
DW
236 free(pucBits);
237 ::GpiSetBitmap(hPS, NULLHANDLE);
238 ::GpiDestroyPS(hPS);
239 ::DevCloseDC(hDC);
240 if (vNewBmp.Ok())
241 return(vNewBmp);
242 return(wxNullBitmap);
243} // end of wxDisableBitmap
d90895ac 244
b7c2b5c5
DW
245// ----------------------------------------------------------------------------
246// private classes
247// ----------------------------------------------------------------------------
0e320a79 248
b7c2b5c5 249class wxToolBarTool : public wxToolBarToolBase
0e320a79 250{
b7c2b5c5
DW
251public:
252 inline wxToolBarTool( wxToolBar* pTbar
253 ,int vId
3437f881 254 ,const wxString& rsLabel
b7c2b5c5
DW
255 ,const wxBitmap& rBitmap1
256 ,const wxBitmap& rBitmap2
3437f881 257 ,wxItemKind vKind
b7c2b5c5 258 ,wxObject* pClientData
d697657f
DW
259 ,const wxString& rsShortHelpString
260 ,const wxString& rsLongHelpString
b7c2b5c5
DW
261 ) : wxToolBarToolBase( pTbar
262 ,vId
3437f881 263 ,rsLabel
b7c2b5c5
DW
264 ,rBitmap1
265 ,rBitmap2
3437f881 266 ,vKind
b7c2b5c5 267 ,pClientData
d697657f
DW
268 ,rsShortHelpString
269 ,rsLongHelpString
b7c2b5c5
DW
270 )
271 {
b7c2b5c5
DW
272 }
273
274 inline wxToolBarTool( wxToolBar* pTbar
275 ,wxControl* pControl
276 ) : wxToolBarToolBase( pTbar
277 ,pControl
278 )
279 {
b7c2b5c5
DW
280 }
281
d697657f
DW
282 void SetSize(const wxSize& rSize)
283 {
284 m_vWidth = rSize.x;
285 m_vHeight = rSize.y;
286 }
287
288 wxCoord GetWidth(void) const { return m_vWidth; }
289 wxCoord GetHeight(void) const { return m_vHeight; }
b7c2b5c5 290
d697657f
DW
291 wxCoord m_vX;
292 wxCoord m_vY;
293 wxCoord m_vWidth;
294 wxCoord m_vHeight;
295}; // end of CLASS wxToolBarTool
b7c2b5c5 296
d697657f
DW
297// ----------------------------------------------------------------------------
298// wxWin macros
299// ----------------------------------------------------------------------------
300
301IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
302
303BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
304 EVT_SIZE(wxToolBar::OnSize)
305 EVT_PAINT(wxToolBar::OnPaint)
306 EVT_KILL_FOCUS(wxToolBar::OnKillFocus)
307 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
233d6db5 308 EVT_TIMER(-1, wxToolBar::OnTimer)
d697657f 309END_EVENT_TABLE()
b7c2b5c5
DW
310
311// ============================================================================
312// implementation
313// ============================================================================
314
315// ----------------------------------------------------------------------------
d697657f 316// tool bar tools creation
b7c2b5c5
DW
317// ----------------------------------------------------------------------------
318
319wxToolBarToolBase* wxToolBar::CreateTool(
320 int nId
3437f881 321, const wxString& rsLabel
d697657f
DW
322, const wxBitmap& rBmpNormal
323, const wxBitmap& rBmpDisabled
324, wxItemKind eKind
b7c2b5c5 325, wxObject* pClientData
d697657f
DW
326, const wxString& rsShortHelp
327, const wxString& rsLongHelp
b7c2b5c5
DW
328)
329{
d697657f 330 return new wxToolBarTool( this
b7c2b5c5 331 ,nId
3437f881 332 ,rsLabel
d697657f
DW
333 ,rBmpNormal
334 ,rBmpDisabled
335 ,eKind
b7c2b5c5 336 ,pClientData
d697657f
DW
337 ,rsShortHelp
338 ,rsLongHelp
339 );
340} // end of wxToolBarSimple::CreateTool
0e320a79 341
d697657f 342wxToolBarToolBase *wxToolBar::CreateTool(
b7c2b5c5
DW
343 wxControl* pControl
344)
0e320a79 345{
d697657f 346 return new wxToolBarTool( this
b7c2b5c5 347 ,pControl
d697657f
DW
348 );
349} // end of wxToolBarSimple::CreateTool
b7c2b5c5
DW
350
351// ----------------------------------------------------------------------------
d697657f 352// wxToolBarSimple creation
b7c2b5c5
DW
353// ----------------------------------------------------------------------------
354
355void wxToolBar::Init()
356{
d697657f 357 m_nCurrentRowsOrColumns = 0;
b7c2b5c5 358
d697657f
DW
359 m_vLastX = m_vLastY = 0;
360 m_vMaxWidth = m_vMaxHeight = 0;
361 m_nPressedTool = m_nCurrentTool = -1;
362 m_vXPos = m_vYPos = -1;
363 m_vTextX = m_vTextY = 0;
d90895ac 364
d697657f
DW
365 m_toolPacking = 1;
366 m_toolSeparation = 5;
b7c2b5c5 367
d697657f
DW
368 m_defaultWidth = 16;
369 m_defaultHeight = 15;
05facebb
DW
370
371 m_pToolTip = NULL;
d697657f 372} // end of wxToolBar::Init
b7c2b5c5 373
d697657f
DW
374wxToolBarToolBase* wxToolBar::DoAddTool(
375 int vId
376, const wxString& rsLabel
377, const wxBitmap& rBitmap
378, const wxBitmap& rBmpDisabled
379, wxItemKind eKind
380, const wxString& rsShortHelp
381, const wxString& rsLongHelp
382, wxObject* pClientData
383, wxCoord vXPos
384, wxCoord vYPos
385)
386{
387 //
388 // Rememeber the position for DoInsertTool()
389 //
390 m_vXPos = vXPos;
391 m_vYPos = vYPos;
392
393 return wxToolBarBase::DoAddTool( vId
394 ,rsLabel
395 ,rBitmap
396 ,rBmpDisabled
397 ,eKind
398 ,rsShortHelp
399 ,rsLongHelp
400 ,pClientData
401 ,vXPos
402 ,vYPos
403 );
404} // end of wxToolBar::DoAddTool
b7c2b5c5 405
3029781e
DW
406bool wxToolBar::DeleteTool(
407 int nId
408)
409{
410 bool bOk = wxToolBarBase::DeleteTool(nId);
411
412 if (bOk)
413 {
414 Realize();
415 }
416 return bOk;
417} // end of wxToolBar::DeleteTool
418
419bool wxToolBar::DeleteToolByPos(
420 size_t nPos
421)
422{
423 bool bOk = wxToolBarBase::DeleteToolByPos(nPos);
424
425 if (bOk)
426 {
427 Realize();
428 }
429 return bOk;
430} // end of wxToolBar::DeleteTool
431
432wxToolBarToolBase* wxToolBar::InsertControl(
433 size_t nPos
434, wxControl* pControl
435)
436{
437 wxToolBarToolBase* pTool = wxToolBarBase::InsertControl( nPos
438 ,pControl
439 );
440 if (m_bInitialized)
441 {
442 Realize();
443 Refresh();
444 }
445 return pTool;
446} // end of wxToolBar::InsertControl
447
448wxToolBarToolBase* wxToolBar::InsertSeparator(
449 size_t nPos
450)
451{
452 wxToolBarToolBase* pTool = wxToolBarBase::InsertSeparator(nPos);
453
454 if (m_bInitialized)
455 {
456 Realize();
457 Refresh();
458 }
459 return pTool;
460} // end of wxToolBar::InsertSeparator
461
462wxToolBarToolBase* wxToolBar::InsertTool(
463 size_t nPos
464, int nId
465, const wxString& rsLabel
466, const wxBitmap& rBitmap
467, const wxBitmap& rBmpDisabled
468, wxItemKind eKind
469, const wxString& rsShortHelp
470, const wxString& rsLongHelp
471, wxObject* pClientData
472)
473{
474 wxToolBarToolBase* pTool = wxToolBarBase::InsertTool( nPos
475 ,nId
476 ,rsLabel
477 ,rBitmap
478 ,rBmpDisabled
479 ,eKind
480 ,rsShortHelp
481 ,rsLongHelp
482 ,pClientData
483 );
484 if (m_bInitialized)
485 {
486 Realize();
487 Refresh();
488 }
489 return pTool;
490} // end of wxToolBar::InsertTool
491
d697657f
DW
492bool wxToolBar::DoInsertTool(
493 size_t WXUNUSED(nPos)
494, wxToolBarToolBase* pToolBase
495)
496{
497 wxToolBarTool* pTool = (wxToolBarTool *)pToolBase;
b7c2b5c5 498
d697657f
DW
499 pTool->m_vX = m_vXPos;
500 if (pTool->m_vX == -1)
501 pTool->m_vX = m_xMargin;
b7c2b5c5 502
d697657f
DW
503 pTool->m_vY = m_vYPos;
504 if (pTool->m_vY == -1)
505 pTool->m_vX = m_yMargin;
b7c2b5c5 506
d697657f 507 pTool->SetSize(GetToolSize());
0e320a79 508
d697657f 509 if (pTool->IsButton())
b7c2b5c5 510 {
d697657f
DW
511 //
512 // Calculate reasonable max size in case Layout() not called
513 //
514 if ((pTool->m_vX + pTool->GetNormalBitmap().GetWidth() + m_xMargin) > m_vMaxWidth)
515 m_vMaxWidth = (wxCoord)((pTool->m_vX + pTool->GetWidth() + m_xMargin));
516
517 if ((pTool->m_vY + pTool->GetNormalBitmap().GetHeight() + m_yMargin) > m_vMaxHeight)
518 m_vMaxHeight = (wxCoord)((pTool->m_vY + pTool->GetHeight() + m_yMargin));
b7c2b5c5 519 }
d697657f
DW
520 return TRUE;
521} // end of wxToolBar::DoInsertTool
b7c2b5c5 522
d697657f 523bool wxToolBar::DoDeleteTool(
b7c2b5c5
DW
524 size_t WXUNUSED(nPos)
525, wxToolBarToolBase* pTool
526)
527{
d697657f
DW
528 pTool->Detach();
529 Refresh();
530 return TRUE;
531} // end of wxToolBar::DoDeleteTool
0e320a79 532
d697657f
DW
533bool wxToolBar::Create(
534 wxWindow* pParent
535, wxWindowID vId
536, const wxPoint& rPos
537, const wxSize& rSize
538, long lStyle
539, const wxString& rsName
b7c2b5c5 540)
0e320a79 541{
d697657f
DW
542 if ( !wxWindow::Create( pParent
543 ,vId
544 ,rPos
545 ,rSize
546 ,lStyle
547 ,rsName
548 ))
549 return FALSE;
d90895ac 550
d697657f
DW
551 // Set it to grey (or other 3D face colour)
552 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
553 SetFont(*wxSMALL_FONT);
d90895ac 554
d697657f 555 if (GetWindowStyleFlag() & wxTB_VERTICAL)
b7c2b5c5 556 {
d697657f
DW
557 m_vLastX = 7;
558 m_vLastY = 3;
d90895ac 559
d697657f
DW
560 m_maxRows = 32000; // a lot
561 m_maxCols = 1;
562 }
563 else
564 {
565 m_vLastX = 3;
566 m_vLastY = 7;
d90895ac 567
d697657f
DW
568 m_maxRows = 1;
569 m_maxCols = 32000; // a lot
570 }
571 SetCursor(*wxSTANDARD_CURSOR);
572
573 //
574 // The toolbar's tools, if they have labels and the winTB_TEXT
575 // style is set, then we need to take into account the size of
576 // the text when drawing tool bitmaps and the text
577 //
578 if (HasFlag(wxTB_TEXT))
b7c2b5c5 579 {
d697657f 580 wxClientDC vDC(this);
d90895ac 581
d697657f
DW
582 vDC.SetFont(GetFont());
583 vDC.GetTextExtent( "XXXX"
584 ,&m_vTextX
585 ,&m_vTextY
586 );
b7c2b5c5
DW
587 }
588
d697657f
DW
589 //
590 // Position it
591 //
592 int nX = rPos.x;
593 int nY = rPos.y;
594 int nWidth = rSize.x;
595 int nHeight = rSize.y;
596 wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame);
597
598 if (lStyle & wxTB_HORIZONTAL)
d90895ac 599 {
d697657f 600 if (nWidth <= 0)
b7c2b5c5 601 {
d697657f
DW
602 nWidth = pParent->GetClientSize().x;
603 }
604 if (nHeight <= 0)
605 {
606 if (lStyle & wxTB_TEXT)
3029781e 607 nHeight = m_defaultHeight + m_vTextY;
d697657f
DW
608 else
609 nHeight = m_defaultHeight;
b7c2b5c5 610 }
d90895ac 611 }
d697657f 612 else
d90895ac 613 {
d697657f 614 if (nHeight <= 0)
b7c2b5c5 615 {
d697657f
DW
616 nHeight = pParent->GetClientSize().y;
617 }
618 if (nWidth <= 0)
619 {
620 if (lStyle & wxTB_TEXT)
621 nWidth = m_vTextX + (int)(m_vTextX/2); // a little margin
622 else
623 nWidth = m_defaultWidth + (int)(m_defaultWidth/2); // a little margin
b7c2b5c5 624 }
d90895ac 625 }
d697657f
DW
626 if (nX < 0)
627 nX = 0;
628 if (nY < 0)
629 nY = 0;
630
631 SetSize( nX
632 ,nY
633 ,nWidth
634 ,nHeight
635 );
636 return TRUE;
637} // end of wxToolBar::Create
d90895ac 638
d697657f 639wxToolBar::~wxToolBar()
b7c2b5c5 640{
05facebb
DW
641 if (m_pToolTip)
642 {
643 delete m_pToolTip;
644 m_pToolTip = NULL;
645 }
d697657f 646} // end of wxToolBar::~wxToolBar
d90895ac 647
d697657f
DW
648bool wxToolBar::Realize()
649{
650 int nMaxToolWidth = 0;
651 int nMaxToolHeight = 0;
652 int nX;
653 int nY;
b7c2b5c5 654
d697657f
DW
655 m_nCurrentRowsOrColumns = 0;
656 m_vLastX = m_xMargin;
657 m_vLastY = m_yMargin;
658 m_vMaxWidth = 0;
659 m_vMaxHeight = 0;
b7c2b5c5 660
b7c2b5c5 661
d697657f
DW
662 //
663 // Find the maximum tool width and height
664 //
665 wxToolBarToolsList::Node* pNode = m_tools.GetFirst();
b7c2b5c5 666
d697657f 667 while (pNode )
d90895ac 668 {
d697657f 669 wxToolBarTool* pTool = (wxToolBarTool *)pNode->GetData();
b7c2b5c5 670
d697657f
DW
671 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsEmpty())
672 {
673 //
674 // Set the height according to the font and the border size
675 //
3029781e
DW
676 if (pTool->GetWidth() > m_vTextX)
677 nMaxToolWidth = pTool->GetWidth() + 4;
678 else
679 nMaxToolWidth = m_vTextX;
d697657f
DW
680 if (pTool->GetHeight() + m_vTextY > nMaxToolHeight)
681 nMaxToolHeight = pTool->GetHeight() + m_vTextY;
682 }
683 else
684 {
685 if (pTool->GetWidth() > nMaxToolWidth )
3029781e 686 nMaxToolWidth = pTool->GetWidth() + 4;
d697657f
DW
687 if (pTool->GetHeight() > nMaxToolHeight)
688 nMaxToolHeight = pTool->GetHeight();
689 }
690 pNode = pNode->GetNext();
d90895ac 691 }
d90895ac 692
3029781e
DW
693 wxCoord vTbWidth = 0L;
694 wxCoord vTbHeight = 0L;
695
696 GetSize( &vTbWidth
697 ,&vTbHeight
698 );
699 if (vTbHeight < nMaxToolHeight)
700 {
701 SetSize( -1L
702 ,-1L
703 ,vTbWidth
704 ,nMaxToolHeight + 4
705 );
706 if (GetParent()->IsKindOf(CLASSINFO(wxFrame)))
707 {
708 wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame);
709
710 if (pFrame)
711 pFrame->PositionToolBar();
712 }
713 }
714
d697657f 715 int nSeparatorSize = m_toolSeparation;
b7c2b5c5 716
d697657f
DW
717 pNode = m_tools.GetFirst();
718 while (pNode)
d90895ac 719 {
d697657f
DW
720 wxToolBarTool* pTool = (wxToolBarTool *)pNode->GetData();
721
722 if (pTool->IsSeparator())
b7c2b5c5 723 {
d697657f 724 if (GetWindowStyleFlag() & wxTB_HORIZONTAL)
b7c2b5c5 725 {
d697657f
DW
726 pTool->m_vX = m_vLastX + nSeparatorSize;
727 pTool->m_vHeight = m_defaultHeight + m_vTextY;
728 if (m_nCurrentRowsOrColumns >= m_maxCols)
729 m_vLastY += nSeparatorSize;
730 else
3029781e 731 m_vLastX += nSeparatorSize * 4;
b7c2b5c5
DW
732 }
733 else
734 {
d697657f
DW
735 pTool->m_vY = m_vLastY + nSeparatorSize;
736 pTool->m_vHeight = m_defaultHeight + m_vTextY;
737 if (m_nCurrentRowsOrColumns >= m_maxRows)
738 m_vLastX += nSeparatorSize;
739 else
3029781e 740 m_vLastY += nSeparatorSize * 4;
b7c2b5c5 741 }
b7c2b5c5 742 }
d697657f 743 else if (pTool->IsButton())
b7c2b5c5 744 {
d697657f
DW
745 if (GetWindowStyleFlag() & wxTB_HORIZONTAL)
746 {
747 if (m_nCurrentRowsOrColumns >= m_maxCols)
748 {
749 m_nCurrentRowsOrColumns = 0;
750 m_vLastX = m_xMargin;
751 m_vLastY += nMaxToolHeight + m_toolPacking;
752 }
753 pTool->m_vX = m_vLastX + (nMaxToolWidth - ((int)(nMaxToolWidth/2) + (int)(pTool->GetWidth()/2)));
754 if (HasFlag(wxTB_TEXT))
755 pTool->m_vY = m_vLastY + nSeparatorSize - 2; // just bit of adjustment
756 else
757 pTool->m_vY = m_vLastY + (nMaxToolHeight - (int)(pTool->GetHeight()/2));
758 m_vLastX += nMaxToolWidth + m_toolPacking + m_toolSeparation;
759 }
760 else
b7c2b5c5 761 {
d697657f
DW
762 if (m_nCurrentRowsOrColumns >= m_maxRows)
763 {
764 m_nCurrentRowsOrColumns = 0;
765 m_vLastX += (nMaxToolWidth + m_toolPacking);
766 m_vLastY = m_yMargin;
767 }
768 pTool->m_vX = m_vLastX + pTool->GetWidth();
769 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsNull())
770 pTool->m_vY = m_vLastY + (nMaxToolHeight - m_vTextY) + m_toolPacking;
771 else
772 pTool->m_vY = m_vLastY + (nMaxToolHeight - (int)(pTool->GetHeight()/2));
773 m_vLastY += nMaxToolHeight + m_toolPacking + m_toolSeparation;
b7c2b5c5 774 }
d697657f 775 m_nCurrentRowsOrColumns++;
b7c2b5c5 776 }
d697657f 777 else
b7c2b5c5 778 {
d697657f 779 // TODO: support the controls
b7c2b5c5 780 }
d697657f
DW
781
782 if (m_vLastX > m_maxWidth)
783 m_maxWidth = m_vLastX;
784 if (m_vLastY > m_maxHeight)
785 m_maxHeight = m_vLastY;
786
787 pNode = pNode->GetNext();
d90895ac
DW
788 }
789
d697657f
DW
790 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
791 m_maxWidth += nMaxToolWidth;
792 else
793 m_maxHeight += nMaxToolHeight;
d90895ac 794
d697657f
DW
795 m_maxWidth += m_xMargin;
796 m_maxHeight += m_yMargin;
3029781e 797 m_bInitialized = TRUE;
d697657f
DW
798 return TRUE;
799} // end of wxToolBar::Realize
d90895ac 800
d697657f
DW
801// ----------------------------------------------------------------------------
802// event handlers
803// ----------------------------------------------------------------------------
d90895ac 804
d697657f
DW
805void wxToolBar::OnPaint (
806 wxPaintEvent& WXUNUSED(rEvent)
807)
808{
809 wxPaintDC vDc(this);
b7c2b5c5 810
d697657f 811 PrepareDC(vDc);
d90895ac 812
d697657f 813 static int nCount = 0;
b7c2b5c5 814
d697657f
DW
815 //
816 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
817 //
818 if (nCount > 0)
819 return;
820 nCount++;
b7c2b5c5 821
b856b0f5 822 ::WinFillRect(vDc.GetHPS(), &vDc.m_vRclPaint, GetBackgroundColour().GetPixel());
d697657f
DW
823 for ( wxToolBarToolsList::Node* pNode = m_tools.GetFirst();
824 pNode;
825 pNode = pNode->GetNext() )
826 {
827 wxToolBarTool* pTool = (wxToolBarTool*)pNode->GetData();
b7c2b5c5 828
d697657f
DW
829 if (pTool->IsButton() )
830 DrawTool(vDc, pTool);
831 if (pTool->IsSeparator())
b7c2b5c5 832 {
d697657f
DW
833 wxPen vDarkGreyPen( wxColour(85, 85, 85)
834 ,1
835 ,wxSOLID
836 );
837 int nX;
838 int nY;
97d74dd2
DW
839 int nHeight = 0;
840 int nWidth = 0;
d697657f
DW
841
842 vDc.SetPen(vDarkGreyPen);
97d74dd2 843 if (HasFlag(wxTB_TEXT))
d697657f 844 {
97d74dd2
DW
845 if (HasFlag(wxTB_HORIZONTAL))
846 {
847 nX = pTool->m_vX;
848 nY = pTool->m_vY - (m_vTextY - 6);
849 nHeight = (m_vTextY - 2) + pTool->GetHeight();
850 }
851 else
852 {
853 nX = pTool->m_vX + m_xMargin + 10;
854 nY = pTool->m_vY + m_vTextY + m_toolSeparation;
855 nWidth = pTool->GetWidth() > m_vTextX ? pTool->GetWidth() : m_vTextX;
856 }
d697657f
DW
857 }
858 else
859 {
860 nX = pTool->m_vX;
861 nY = pTool->m_vY;
97d74dd2
DW
862 if (HasFlag(wxTB_HORIZONTAL))
863 nHeight = pTool->GetHeight() - 2;
864 else
865 {
866 nX += m_xMargin + 10;
867 nY += m_yMargin + m_toolSeparation;
868 nWidth = pTool->GetWidth();
869 }
d697657f 870 }
97d74dd2 871 vDc.DrawLine(nX, nY, nX + nWidth, nY + nHeight);
d697657f
DW
872 }
873 }
874 nCount--;
875} // end of wxToolBar::OnPaint
b7c2b5c5 876
d697657f
DW
877void wxToolBar::OnSize (
878 wxSizeEvent& WXUNUSED(rEvent)
879)
880{
881#if wxUSE_CONSTRAINTS
882 if (GetAutoLayout())
883 Layout();
884#endif
885} // end of wxToolBar::OnSize
b7c2b5c5 886
d697657f
DW
887void wxToolBar::OnKillFocus(
888 wxFocusEvent& WXUNUSED(rEvent)
889)
890{
891 OnMouseEnter(m_nPressedTool = m_nCurrentTool = -1);
892} // end of wxToolBar::OnKillFocus
b7c2b5c5 893
d697657f
DW
894void wxToolBar::OnMouseEvent(
895 wxMouseEvent& rEvent
896)
897{
05facebb
DW
898 POINTL vPoint;
899 HWND hWnd;
d697657f
DW
900 wxCoord vX;
901 wxCoord vY;
902 HPOINTER hPtr = ::WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
b7c2b5c5 903
d697657f 904 ::WinSetPointer(HWND_DESKTOP, hPtr);
05facebb
DW
905 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
906 hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
907 if (hWnd != (HWND)GetHwnd())
908 {
909 m_vToolTimer.Stop();
910 return;
911 }
912
d697657f 913 rEvent.GetPosition(&vX, &vY);
b7c2b5c5 914
d697657f
DW
915 wxToolBarTool* pTool = (wxToolBarTool *)FindToolForPosition( vX
916 ,vY
917 );
b7c2b5c5 918
d697657f
DW
919 if (rEvent.LeftDown())
920 {
921 CaptureMouse();
b7c2b5c5 922 }
d697657f 923 if (rEvent.LeftUp())
b7c2b5c5 924 {
d697657f 925 ReleaseMouse();
b7c2b5c5
DW
926 }
927
d697657f 928 if (!pTool)
b7c2b5c5 929 {
05facebb 930 m_vToolTimer.Stop();
d697657f 931 if (m_nCurrentTool > -1)
b7c2b5c5 932 {
d697657f
DW
933 if (rEvent.LeftIsDown())
934 SpringUpButton(m_nCurrentTool);
935 pTool = (wxToolBarTool *)FindById(m_nCurrentTool);
3029781e 936 if (pTool && !pTool->IsToggled())
b7c2b5c5 937 {
d697657f
DW
938 RaiseTool( pTool
939 ,FALSE
940 );
b7c2b5c5 941 }
d697657f
DW
942 m_nCurrentTool = -1;
943 OnMouseEnter(-1);
944 }
945 return;
946 }
947 if (!rEvent.IsButton())
948 {
949 if (pTool->GetId() != m_nCurrentTool)
950 {
951 //
952 // If the left button is kept down and moved over buttons,
953 // press those buttons.
954 //
955 if (rEvent.LeftIsDown() && pTool->IsEnabled())
b7c2b5c5 956 {
d697657f
DW
957 SpringUpButton(m_nCurrentTool);
958 if (pTool->CanBeToggled())
b7c2b5c5 959 {
d697657f 960 pTool->Toggle();
b7c2b5c5 961 }
d697657f 962 DrawTool(pTool);
b7c2b5c5 963 }
3029781e
DW
964 wxToolBarTool* pOldTool = (wxToolBarTool*)FindById(m_nCurrentTool);
965
966 if (pOldTool && !pTool->IsToggled())
967 RaiseTool( pOldTool
968 ,FALSE
969 );
d697657f
DW
970 m_nCurrentTool = pTool->GetId();
971 OnMouseEnter(m_nCurrentTool);
05facebb
DW
972 if (!pTool->GetShortHelp().IsEmpty())
973 {
ff5802f3
DW
974 if (m_pToolTip)
975 delete m_pToolTip;
05facebb
DW
976 m_pToolTip = new wxToolTip(pTool->GetShortHelp());
977 m_vXMouse = (wxCoord)vPoint.x;
978 m_vYMouse = (wxCoord)vPoint.y;
0256cfeb 979 m_vToolTimer.Start(1000L, TRUE);
05facebb 980 }
d697657f
DW
981 if (!pTool->IsToggled())
982 RaiseTool(pTool);
b7c2b5c5 983 }
d697657f 984 return;
b7c2b5c5
DW
985 }
986
d697657f
DW
987 // Left button pressed.
988 if (rEvent.LeftDown() && pTool->IsEnabled())
b7c2b5c5 989 {
d697657f 990 if (pTool->CanBeToggled())
b7c2b5c5 991 {
d697657f 992 pTool->Toggle();
b7c2b5c5 993 }
d697657f
DW
994 DrawTool(pTool);
995 }
996 else if (rEvent.RightDown())
997 {
998 OnRightClick( pTool->GetId()
999 ,vX
1000 ,vY
1001 );
b7c2b5c5 1002 }
d697657f
DW
1003
1004 //
1005 // Left Button Released. Only this action confirms selection.
1006 // If the button is enabled and it is not a toggle tool and it is
1007 // in the pressed state, then raise the button and call OnLeftClick.
1008 //
1009 if (rEvent.LeftUp() && pTool->IsEnabled() )
b7c2b5c5 1010 {
d697657f
DW
1011 //
1012 // Pass the OnLeftClick event to tool
1013 //
1014 if (!OnLeftClick( pTool->GetId()
1015 ,pTool->IsToggled()) &&
1016 pTool->CanBeToggled())
b7c2b5c5 1017 {
d697657f
DW
1018 //
1019 // If it was a toggle, and OnLeftClick says No Toggle allowed,
1020 // then change it back
1021 //
1022 pTool->Toggle();
b7c2b5c5 1023 }
d697657f 1024 DrawTool(pTool);
b7c2b5c5 1025 }
d697657f 1026} // end of wxToolBar::OnMouseEvent
d90895ac 1027
b7c2b5c5 1028// ----------------------------------------------------------------------------
d697657f 1029// drawing
b7c2b5c5
DW
1030// ----------------------------------------------------------------------------
1031
d697657f
DW
1032void wxToolBar::DrawTool(
1033 wxToolBarToolBase* pTool
b7c2b5c5 1034)
d90895ac 1035{
d697657f 1036 wxClientDC vDc(this);
b7c2b5c5 1037
d697657f
DW
1038 DrawTool( vDc
1039 ,pTool
1040 );
1041} // end of wxToolBar::DrawTool
b7c2b5c5 1042
d697657f
DW
1043void wxToolBar::DrawTool(
1044 wxDC& rDc
1045, wxToolBarToolBase* pToolBase
b7c2b5c5 1046)
d90895ac 1047{
d697657f
DW
1048 wxToolBarTool* pTool = (wxToolBarTool *)pToolBase;
1049 wxPen vDarkGreyPen( wxColour( 85,85,85 )
1050 ,1
1051 ,wxSOLID
1052 );
1053 wxPen vWhitePen( wxT("WHITE")
1054 ,1
1055 ,wxSOLID
1056 );
1057 wxPen vBlackPen( wxT("BLACK")
1058 ,1
1059 ,wxSOLID
1060 );
1061 wxBitmap vBitmap = pTool->GetNormalBitmap();
1062 bool bUseMask = FALSE;
1063 wxMask* pMask = NULL;
1064 RECTL vRect;
d90895ac 1065
d697657f 1066 PrepareDC(rDc);
d90895ac 1067
d697657f
DW
1068 if (!vBitmap.Ok())
1069 return;
1070 if ((pMask = vBitmap.GetMask()) != NULL)
1071 if (pMask->GetMaskBitmap() != NULLHANDLE)
1072 bUseMask = TRUE;
d90895ac 1073
d697657f 1074 if (!pTool->IsToggled())
d90895ac 1075 {
d697657f
DW
1076 LowerTool(pTool, FALSE);
1077 if (!pTool->IsEnabled())
d90895ac 1078 {
d697657f
DW
1079 wxColour vColor("GREY");
1080
1081 rDc.SetTextForeground(vColor);
1082 if (!pTool->GetDisabledBitmap().Ok())
1083 pTool->SetDisabledBitmap(wxDisableBitmap( vBitmap
1084 ,(long)GetBackgroundColour().GetPixel()
1085 ));
1086 rDc.DrawBitmap( pTool->GetDisabledBitmap()
1087 ,pTool->m_vX
1088 ,pTool->m_vY
1089 ,bUseMask
1090 );
d90895ac 1091 }
d90895ac
DW
1092 else
1093 {
d697657f
DW
1094 wxColour vColor("BLACK");
1095
1096 rDc.SetTextForeground(vColor);
1097 rDc.DrawBitmap( vBitmap
1098 ,pTool->m_vX
1099 ,pTool->m_vY
1100 ,bUseMask
1101 );
1102 }
1103 if (m_windowStyle & wxTB_3DBUTTONS)
1104 {
1105 RaiseTool(pTool);
1106 }
1107 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsNull())
1108 {
1109 wxCoord vX;
1110 wxCoord vY;
1111 wxCoord vLeft = pTool->m_vX - (int)(pTool->GetWidth()/2);
1112
1113 rDc.SetFont(GetFont());
1114 rDc.GetTextExtent( pTool->GetLabel()
1115 ,&vX
1116 ,&vY
1117 );
3029781e
DW
1118 if (pTool->GetWidth() > vX) // large tools
1119 {
1120 vLeft = pTool->m_vX + (pTool->GetWidth() - vX);
1121 GetSize(&vX, &vY);
1122 rDc.DrawText( pTool->GetLabel()
1123 ,vLeft
1124 ,vY - (m_vTextY - 2)
1125 );
1126 }
1127 else // normal tools
1128 {
1129 vLeft += (wxCoord)((m_vTextX - vX)/2);
1130 rDc.DrawText( pTool->GetLabel()
1131 ,vLeft
1132 ,pTool->m_vY + m_vTextY + 4 // a bit of margin
1133 );
1134 }
d90895ac 1135 }
d90895ac 1136 }
d697657f
DW
1137 else
1138 {
1139 wxColour vColor("GREY");
1140
1141 LowerTool(pTool);
1142 rDc.SetTextForeground(vColor);
1143 if (!pTool->GetDisabledBitmap().Ok())
1144 pTool->SetDisabledBitmap(wxDisableBitmap( vBitmap
1145 ,(long)GetBackgroundColour().GetPixel()
1146 ));
1147 rDc.DrawBitmap( pTool->GetDisabledBitmap()
1148 ,pTool->m_vX
1149 ,pTool->m_vY
1150 ,bUseMask
1151 );
1152 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsNull())
1153 {
1154 wxCoord vX;
1155 wxCoord vY;
1156 wxCoord vLeft = pTool->m_vX - (int)(pTool->GetWidth()/2);
1157
1158 rDc.SetFont(GetFont());
1159 rDc.GetTextExtent( pTool->GetLabel()
1160 ,&vX
1161 ,&vY
1162 );
1163 vLeft += (wxCoord)((m_vTextX - vX)/2);
1164 rDc.DrawText( pTool->GetLabel()
1165 ,vLeft
1166 ,pTool->m_vY + m_vTextY + 4 // a bit of margin
1167 );
1168 }
1169 }
1170} // end of wxToolBar::DrawTool
0e320a79 1171
b7c2b5c5
DW
1172// ----------------------------------------------------------------------------
1173// toolbar geometry
1174// ----------------------------------------------------------------------------
d90895ac 1175
b7c2b5c5
DW
1176void wxToolBar::SetRows(
1177 int nRows
1178)
0e320a79 1179{
d697657f 1180 wxCHECK_RET( nRows != 0, _T("max number of rows must be > 0") );
b7c2b5c5 1181
d697657f
DW
1182 m_maxCols = (GetToolsCount() + nRows - 1) / nRows;
1183 Refresh();
1184} // end of wxToolBar::SetRows
0e320a79 1185
d697657f 1186wxToolBarToolBase* wxToolBar::FindToolForPosition(
b7c2b5c5
DW
1187 wxCoord vX
1188, wxCoord vY
1189) const
0e320a79 1190{
d697657f
DW
1191 wxCoord vTextX = 0;
1192 wxCoord vTextY = 0;
1193 wxCoord vTBarHeight = 0;
b7c2b5c5 1194
3029781e
DW
1195 GetSize( NULL
1196 ,&vTBarHeight
1197 );
1198 vY = vTBarHeight - vY;
d697657f
DW
1199 wxToolBarToolsList::Node* pNode = m_tools.GetFirst();
1200 while (pNode)
b7c2b5c5 1201 {
d697657f 1202 wxToolBarTool* pTool = (wxToolBarTool *)pNode->GetData();
b7c2b5c5 1203
d697657f 1204 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsNull())
b7c2b5c5 1205 {
d697657f
DW
1206 if ((vX >= (pTool->m_vX - ((wxCoord)(pTool->GetWidth()/2) - 2))) &&
1207 (vY >= (pTool->m_vY - 2)) &&
1208 (vX <= (pTool->m_vX + pTool->GetWidth())) &&
1209 (vY <= (pTool->m_vY + pTool->GetHeight() + m_vTextY + 2)))
1210 {
1211 return pTool;
1212 }
b7c2b5c5 1213 }
d697657f
DW
1214 else
1215 {
1216 if ((vX >= pTool->m_vX) &&
1217 (vY >= pTool->m_vY) &&
1218 (vX <= (pTool->m_vX + pTool->GetWidth())) &&
1219 (vY <= (pTool->m_vY + pTool->GetHeight())))
1220 {
1221 return pTool;
1222 }
1223 }
1224 pNode = pNode->GetNext();
0e320a79 1225 }
d697657f
DW
1226 return (wxToolBarToolBase *)NULL;
1227} // end of wxToolBar::FindToolForPosition
d90895ac 1228
b7c2b5c5 1229// ----------------------------------------------------------------------------
d697657f 1230// tool state change handlers
b7c2b5c5
DW
1231// ----------------------------------------------------------------------------
1232
1233void wxToolBar::DoEnableTool(
1234 wxToolBarToolBase* pTool
d697657f 1235, bool WXUNUSED(bEnable)
b7c2b5c5 1236)
d90895ac 1237{
d697657f
DW
1238 DrawTool(pTool);
1239} // end of wxToolBar::DoEnableTool
0e320a79 1240
b7c2b5c5
DW
1241void wxToolBar::DoToggleTool(
1242 wxToolBarToolBase* pTool
d697657f 1243, bool WXUNUSED(bToggle)
b7c2b5c5 1244)
0e320a79 1245{
d697657f
DW
1246 DrawTool(pTool);
1247} // end of wxToolBar::DoToggleTool
0e320a79 1248
b7c2b5c5 1249void wxToolBar::DoSetToggle(
d697657f
DW
1250 wxToolBarToolBase* WXUNUSED(pTool)
1251, bool WXUNUSED(bToggle)
1252)
1253{
1254 // nothing to do
1255} // end of wxToolBar::DoSetToggle
1256
1257//
1258// Okay, so we've left the tool we're in ... we must check if the tool we're
1259// leaving was a 'sprung push button' and if so, spring it back to the up
1260// state.
1261//
1262void wxToolBar::SpringUpButton(
1263 int vId
b7c2b5c5 1264)
0e320a79 1265{
d697657f
DW
1266 wxToolBarToolBase* pTool = FindById(vId);
1267
1268 if (pTool && pTool->CanBeToggled())
1269 {
1270 if (pTool->IsToggled())
1271 pTool->Toggle();
1272
1273 DrawTool(pTool);
1274 }
1275} // end of wxToolBar::SpringUpButton
0e320a79 1276
b7c2b5c5 1277// ----------------------------------------------------------------------------
d697657f 1278// private helpers
b7c2b5c5
DW
1279// ----------------------------------------------------------------------------
1280
d697657f
DW
1281void wxToolBar::LowerTool (
1282 wxToolBarToolBase* pToolBase
1283, bool bLower
b7c2b5c5 1284)
d90895ac 1285{
d697657f
DW
1286 wxToolBarTool* pTool = (wxToolBarTool*)pToolBase;
1287 wxCoord vX;
1288 wxCoord vY;
1289 wxCoord vWidth;
1290 wxCoord vHeight;
1291 wxPen vDarkGreyPen( wxColour(85, 85, 85)
1292 ,1
1293 ,wxSOLID
1294 );
1295 wxPen vWhitePen( "WHITE"
1296 ,1
1297 ,wxSOLID
1298 );
1299 wxPen vClearPen( GetBackgroundColour()
1300 ,1
1301 ,wxSOLID
1302 );
1303 wxClientDC vDC(this);
b7c2b5c5 1304
d697657f
DW
1305 if (!pTool)
1306 return;
d90895ac 1307
d697657f
DW
1308 if (pTool->IsSeparator())
1309 return;
d90895ac 1310
d697657f
DW
1311 //
1312 // We only do this for flat toolbars
1313 //
1314 if (!HasFlag(wxTB_FLAT))
1315 return;
d90895ac 1316
d697657f 1317 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsEmpty())
d90895ac 1318 {
3029781e
DW
1319 if (pTool->GetWidth() > m_vTextX)
1320 {
1321 vX = pTool->m_vX - 2;
1322 vWidth = pTool->GetWidth() + 4;
1323 }
1324 else
1325 {
1326 vX = pTool->m_vX - (wxCoord)(pTool->GetWidth()/2);
1327 vWidth = m_vTextX + 4;
1328 }
d697657f 1329 vY = pTool->m_vY - 2;
d697657f 1330 vHeight = pTool->GetHeight() + m_vTextY + 2;
d90895ac
DW
1331 }
1332 else
1333 {
3029781e 1334 vX = pTool->m_vX - 2;
d697657f
DW
1335 vY = pTool->m_vY - 2;
1336 vWidth = pTool->GetWidth() + 4;
1337 vHeight = pTool->GetHeight() + 4;
b7c2b5c5 1338 }
d697657f
DW
1339 if (bLower)
1340 {
1341 vDC.SetPen(vWhitePen);
1342 vDC.DrawLine(vX + vWidth, vY + vHeight, vX, vY + vHeight);
1343 vDC.DrawLine(vX + vWidth, vY, vX + vWidth, vY + vHeight);
1344 vDC.SetPen(vDarkGreyPen);
1345 vDC.DrawLine(vX, vY, vX + vWidth, vY);
1346 vDC.DrawLine(vX, vY + vHeight, vX, vY);
1347 }
1348 else
1349 {
1350 vDC.SetPen(vClearPen);
1351 vDC.DrawLine(vX + vWidth, vY + vHeight, vX, vY + vHeight);
1352 vDC.DrawLine(vX + vWidth, vY, vX + vWidth, vY + vHeight);
1353 vDC.DrawLine(vX, vY, vX + vWidth, vY);
1354 vDC.DrawLine(vX, vY + vHeight, vX, vY);
1355 }
1356} // end of WinGuiBase_CToolBarTool::LowerTool
b7c2b5c5 1357
d697657f
DW
1358void wxToolBar::RaiseTool (
1359 wxToolBarToolBase* pToolBase
1360, bool bRaise
b7c2b5c5
DW
1361)
1362{
d697657f
DW
1363 wxToolBarTool* pTool = (wxToolBarTool*)pToolBase;
1364 wxCoord vX;
1365 wxCoord vY;
1366 wxCoord vWidth;
1367 wxCoord vHeight;
1368 wxPen vDarkGreyPen( wxColour(85, 85, 85)
1369 ,1
1370 ,wxSOLID
1371 );
1372 wxPen vWhitePen( "WHITE"
1373 ,1
1374 ,wxSOLID
1375 );
1376 wxPen vClearPen( GetBackgroundColour()
1377 ,1
1378 ,wxSOLID
1379 );
1380 wxClientDC vDC(this);
b7c2b5c5 1381
d697657f
DW
1382 if (!pTool)
1383 return;
b7c2b5c5 1384
d697657f
DW
1385 if (pTool->IsSeparator())
1386 return;
b7c2b5c5 1387
d697657f
DW
1388 if (!pTool->IsEnabled())
1389 return;
d90895ac 1390
d697657f
DW
1391 //
1392 // We only do this for flat toolbars
1393 //
1394 if (!HasFlag(wxTB_FLAT))
1395 return;
b7c2b5c5 1396
d697657f 1397 if (HasFlag(wxTB_TEXT) && !pTool->GetLabel().IsEmpty())
d90895ac 1398 {
3029781e
DW
1399 if (pTool->GetWidth() > m_vTextX)
1400 {
1401 vX = pTool->m_vX - 2;
1402 vWidth = pTool->GetWidth() + 4;
1403 }
1404 else
1405 {
1406 vX = pTool->m_vX - (wxCoord)(pTool->GetWidth()/2);
1407 vWidth = m_vTextX + 4;
1408 }
d697657f 1409 vY = pTool->m_vY - 2;
d697657f 1410 vHeight = pTool->GetHeight() + m_vTextY + 2;
d90895ac 1411 }
d697657f
DW
1412 else
1413 {
3029781e 1414 vX = pTool->m_vX - 2;
d697657f
DW
1415 vY = pTool->m_vY - 2;
1416 vWidth = pTool->GetWidth() + 4;
1417 vHeight = pTool->GetHeight() + 4;
1418 }
1419 if (bRaise)
1420 {
1421 vDC.SetPen(vDarkGreyPen);
1422 vDC.DrawLine(vX + vWidth, vY + vHeight, vX, vY + vHeight);
1423 vDC.DrawLine(vX + vWidth, vY, vX + vWidth, vY + vHeight);
1424 vDC.SetPen(vWhitePen);
1425 vDC.DrawLine(vX, vY, vX + vWidth, vY);
1426 vDC.DrawLine(vX, vY + vHeight, vX, vY);
1427 }
1428 else
1429 {
1430 vDC.SetPen(vClearPen);
1431 vDC.DrawLine(vX + vWidth, vY + vHeight, vX, vY + vHeight);
1432 vDC.DrawLine(vX + vWidth, vY, vX + vWidth, vY + vHeight);
1433 vDC.DrawLine(vX, vY, vX + vWidth, vY);
1434 vDC.DrawLine(vX, vY + vHeight, vX, vY);
1435 }
1436} // end of wxToolBar::RaiseTool
d90895ac 1437
233d6db5
DW
1438void wxToolBar::OnTimer (
1439 wxTimerEvent& rEvent
1440)
1441{
5d644707 1442 if (rEvent.GetId() == m_vToolTimer.GetTimerId())
233d6db5 1443 {
05facebb
DW
1444 wxPoint vPos( m_vXMouse
1445 ,m_vYMouse
1446 );
1447
1448 m_pToolTip->DisplayToolTipWindow(vPos);
ff5802f3 1449 m_vToolTimer.Stop();
0256cfeb 1450 m_vToolExpTimer.Start(4000L, TRUE);
233d6db5 1451 }
5d644707 1452 else if (rEvent.GetId() == m_vToolExpTimer.GetTimerId())
233d6db5 1453 {
05facebb 1454 m_pToolTip->HideToolTipWindow();
ff5802f3
DW
1455 GetParent()->Refresh();
1456 m_vToolExpTimer.Stop();
233d6db5
DW
1457 }
1458} // end of wxToolBar::OnTimer
1459
d697657f 1460#endif // ndef for wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE