1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolBarMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "tbarmsw.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #if wxUSE_BUTTONBAR && wxUSE_TOOLBAR
29 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
33 #if !defined(__MWERKS__) && !defined(__SALFORDC__)
39 #include "wx/tbarmsw.h"
42 #include "wx/bitmap.h"
43 #include "wx/msw/private.h"
44 #include "wx/msw/dib.h"
46 #define DEFAULTBITMAPX 16
47 #define DEFAULTBITMAPY 15
48 #define DEFAULTBUTTONX 24
49 #define DEFAULTBUTTONY 22
50 #define DEFAULTBARHEIGHT 27
52 /////// Non-Windows 95 implementation
54 #if !wxUSE_IMAGE_LOADING_IN_MSW
55 #error If wxUSE_IMAGE_LOADING_IN_MSW is set to 0, then wxUSE_BUTTONBAR must be set to 0 too.
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_DYNAMIC_CLASS(wxToolBarMSW
, wxToolBarBase
)
61 BEGIN_EVENT_TABLE(wxToolBarMSW
, wxToolBarBase
)
62 EVT_SIZE(wxToolBarMSW::OnSize
)
63 EVT_PAINT(wxToolBarMSW::OnPaint
)
64 EVT_MOUSE_EVENTS(wxToolBarMSW::OnMouseEvent
)
68 wxToolBarMSW::wxToolBarMSW(void)
78 m_defaultWidth
= DEFAULTBITMAPX
;
79 m_defaultHeight
= DEFAULTBITMAPY
;
82 bool wxToolBarMSW::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
83 long style
, const wxString
& name
)
85 if ( ! wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
88 if ( style
& wxTB_HORIZONTAL
)
89 { m_lastX
= 3; m_lastY
= 7; }
91 { m_lastX
= 7; m_lastY
= 3; }
92 m_maxWidth
= m_maxHeight
= 0;
93 m_pressedTool
= m_currentTool
= -1;
100 SetBackgroundColour(wxColour(192, 192, 192));
110 m_defaultWidth
= DEFAULTBITMAPX
;
111 m_defaultHeight
= DEFAULTBITMAPY
;
118 wxToolBarMSW::~wxToolBarMSW(void)
123 void wxToolBarMSW::SetToolBitmapSize(const wxSize
& size
)
125 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
130 // The button size is bigger than the bitmap size
131 wxSize
wxToolBarMSW::GetToolSize(void) const
133 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
136 void wxToolBarMSW::OnPaint(wxPaintEvent
& event
)
140 static int wxOnPaintCount
= 0;
142 // Prevent reentry of OnPaint which would cause
143 // wxMemoryDC errors.
144 if (wxOnPaintCount
> 0)
148 wxNode
*node
= m_tools
.First();
151 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
152 if (tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
154 int state
= wxTBSTATE_ENABLED
;
155 if (!tool
->m_enabled
)
157 if (tool
->m_isToggle
&& tool
->m_toggleState
)
158 state
|= wxTBSTATE_CHECKED
;
159 DrawTool(dc
, tool
, state
);
166 void wxToolBarMSW::OnSize(wxSizeEvent
& event
)
168 wxToolBarBase::OnSize(event
);
171 // If a Button is disabled, then NO function (besides leaving
172 // or entering) should be carried out. Therefore the additions
173 // of 'enabled' testing (Stefan Hammes).
174 void wxToolBarMSW::OnMouseEvent(wxMouseEvent
& event
)
176 static wxToolBarTool
*eventCurrentTool
= NULL
;
182 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
185 int state
= wxTBSTATE_ENABLED
;
186 if (eventCurrentTool
->m_toggleState
)
187 state
|= wxTBSTATE_CHECKED
;
188 DrawTool(dc
, eventCurrentTool
, state
);
189 eventCurrentTool
= NULL
;
196 event
.Position(&x
, &y
);
197 wxToolBarTool
*tool
= FindToolForPosition(x
, y
);
201 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
205 int state
= wxTBSTATE_ENABLED
;
206 if (eventCurrentTool
->m_toggleState
)
207 state
|= wxTBSTATE_CHECKED
;
208 DrawTool(dc
, eventCurrentTool
, state
);
209 eventCurrentTool
= NULL
;
211 if (m_currentTool
> -1)
219 if (!event
.Dragging() && !event
.IsButton())
221 if (tool
->m_index
!= m_currentTool
)
223 OnMouseEnter(tool
->m_index
);
224 m_currentTool
= tool
->m_index
;
228 if (event
.Dragging() && tool
->m_enabled
)
230 if (eventCurrentTool
)
232 // Might have dragged outside tool
233 if (eventCurrentTool
!= tool
)
235 int state
= wxTBSTATE_ENABLED
;
236 if (tool
->m_toggleState
)
237 state
|= wxTBSTATE_CHECKED
;
238 DrawTool(dc
, tool
, state
);
239 eventCurrentTool
= NULL
;
245 if (tool
&& event
.LeftIsDown() && tool
->m_enabled
)
247 eventCurrentTool
= tool
;
248 ::SetCapture((HWND
) GetHWND());
249 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
250 if (tool
->m_toggleState
)
251 state
|= wxTBSTATE_CHECKED
;
252 DrawTool(dc
, tool
, state
);
256 if (event
.LeftDown() && tool
->m_enabled
)
258 eventCurrentTool
= tool
;
259 ::SetCapture((HWND
) GetHWND());
260 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
261 if (tool
->m_toggleState
)
262 state
|= wxTBSTATE_CHECKED
;
263 DrawTool(dc
, tool
, state
);
265 else if (event
.LeftUp() && tool
->m_enabled
)
267 if (eventCurrentTool
)
269 if (eventCurrentTool
== tool
)
271 if (tool
->m_isToggle
)
273 tool
->m_toggleState
= !tool
->m_toggleState
;
274 if (!OnLeftClick(tool
->m_index
, tool
->m_toggleState
))
276 tool
->m_toggleState
= !tool
->m_toggleState
;
278 int state
= wxTBSTATE_ENABLED
;
279 if (tool
->m_toggleState
)
280 state
|= wxTBSTATE_CHECKED
;
281 DrawTool(dc
, tool
, state
);
285 int state
= wxTBSTATE_ENABLED
;
286 if (tool
->m_toggleState
)
287 state
|= wxTBSTATE_CHECKED
;
288 DrawTool(dc
, tool
, state
);
289 OnLeftClick(tool
->m_index
, tool
->m_toggleState
);
292 eventCurrentTool
= NULL
;
294 else if (event
.RightDown() && tool
->m_enabled
)
296 OnRightClick(tool
->m_index
, x
, y
);
300 // This function enables/disables a toolbar tool and redraws it.
301 // If that would not be done, the enabling/disabling wouldn't be
302 // visible on the screen.
303 void wxToolBarMSW::EnableTool(int toolIndex
, bool enable
)
305 wxNode
*node
= m_tools
.Find((long)toolIndex
);
310 // at first do the enabling/disabling in the base class
311 wxToolBarBase::EnableTool(toolIndex
,enable
);
312 // then calculate the state of the tool and draw it
313 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
315 if(tool
->m_toggleState
) state
|= wxTBSTATE_CHECKED
;
316 if(tool
->m_enabled
) state
|= wxTBSTATE_ENABLED
;
317 // how can i access the PRESSED state???
318 DrawTool(dc
, tool
,state
);
322 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxToolBarTool
*tool
, int state
)
324 DrawButton(dc
.GetHDC(), (int)tool
->m_x
, (int)tool
->m_y
, (int)tool
->GetWidth(), (int)tool
->GetHeight(), tool
, state
);
327 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxMemoryDC
& , wxToolBarTool
*tool
)
329 int state
= wxTBSTATE_ENABLED
;
330 if (!tool
->m_enabled
)
332 if (tool
->m_toggleState
)
333 state
|= wxTBSTATE_CHECKED
;
334 DrawTool(dc
, tool
, state
);
337 // If pushedBitmap is NULL, a reversed version of bitmap is
338 // created and used as the pushed/toggled image.
339 // If toggle is TRUE, the button toggles between the two states.
340 wxToolBarTool
*wxToolBarMSW::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
341 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
343 // Using bitmap2 can cause problems (don't know why!)
345 // TODO: use the mapping code from wxToolBar95 to get it right in this class
346 #if !defined(__WIN32__) && !defined(__WIN386__)
350 bitmap2
.SetHBITMAP( (WXHBITMAP
) CreateMappedBitmap(wxGetInstance(), (HBITMAP
) ((wxBitmap
& )bitmap
).GetHBITMAP()));
353 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, bitmap2
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
355 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
358 tool
->m_clientData
= clientData
;
363 tool
->m_x
= m_xMargin
;
368 tool
->m_y
= m_yMargin
;
370 tool
->m_deleteSecondBitmap
= TRUE
;
371 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
373 // Calculate reasonable max size in case Layout() not called
374 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
375 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
377 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
378 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
380 m_tools
.Append((long)index
, tool
);
384 void wxToolBarMSW::Layout(void)
386 m_currentRowsOrColumns
= 0;
389 int maxToolWidth
= 0;
390 int maxToolHeight
= 0;
394 // Find the maximum tool width and height
395 wxNode
*node
= m_tools
.First();
398 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
399 if (tool
->GetWidth() > maxToolWidth
)
400 maxToolWidth
= (int)tool
->GetWidth();
401 if (tool
->GetHeight() > maxToolHeight
)
402 maxToolHeight
= (int)tool
->GetHeight();
406 int separatorSize
= m_toolSeparation
;
408 node
= m_tools
.First();
411 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
412 if (tool
->m_toolStyle
== wxTOOL_STYLE_SEPARATOR
)
414 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
416 if (m_currentRowsOrColumns
>= m_maxCols
)
417 m_lastY
+= separatorSize
;
419 m_lastX
+= separatorSize
;
423 if (m_currentRowsOrColumns
>= m_maxRows
)
424 m_lastX
+= separatorSize
;
426 m_lastY
+= separatorSize
;
429 else if (tool
->m_toolStyle
== wxTOOL_STYLE_BUTTON
)
431 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
433 if (m_currentRowsOrColumns
>= m_maxCols
)
435 m_currentRowsOrColumns
= 0;
437 m_lastY
+= maxToolHeight
+ m_toolPacking
;
439 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
440 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
442 m_lastX
+= maxToolWidth
+ m_toolPacking
;
446 if (m_currentRowsOrColumns
>= m_maxRows
)
448 m_currentRowsOrColumns
= 0;
449 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
452 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
453 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
455 m_lastY
+= maxToolHeight
+ m_toolPacking
;
457 m_currentRowsOrColumns
++;
460 if (m_lastX
> m_maxWidth
)
461 m_maxWidth
= m_lastX
;
462 if (m_lastY
> m_maxHeight
)
463 m_maxHeight
= m_lastY
;
467 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
468 m_maxWidth
+= maxToolWidth
;
470 m_maxHeight
+= maxToolHeight
;
472 m_maxWidth
+= m_xMargin
;
473 m_maxHeight
+= m_yMargin
;
477 bool wxToolBarMSW::InitGlobalObjects(void)
480 if (!CreateDitherBrush())
483 m_hdcMono
= (WXHDC
) CreateCompatibleDC(NULL
);
487 m_hbmMono
= (WXHBITMAP
) CreateBitmap((int)GetToolSize().x
, (int)GetToolSize().y
, 1, 1, NULL
);
491 m_hbmDefault
= (WXHBITMAP
) SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmMono
);
495 void wxToolBarMSW::FreeGlobalObjects(void)
502 SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmDefault
);
505 DeleteDC((HDC
) m_hdcMono
); // toast the DCs
510 DeleteObject((HBITMAP
) m_hbmMono
);
515 void wxToolBarMSW::PatB(WXHDC hdc
,int x
,int y
,int dx
,int dy
, long rgb
)
524 SetBkColor((HDC
) hdc
,rgb
);
525 ExtTextOut((HDC
) hdc
,0,0,ETO_OPAQUE
,&rc
,NULL
,0,NULL
);
529 // create a mono bitmap mask:
530 // 1's where color == COLOR_BTNFACE || COLOR_HILIGHT
531 // 0's everywhere else
533 void wxToolBarMSW::CreateMask(WXHDC hdc
, int xoffset
, int yoffset
, int dx
, int dy
)
535 HDC globalDC
= ::GetDC(NULL
);
536 HDC hdcGlyphs
= CreateCompatibleDC((HDC
) globalDC
);
537 ReleaseDC(NULL
, (HDC
) globalDC
);
539 // krj - create a new bitmap and copy the image from hdc.
540 //HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap);
541 HBITMAP hBitmap
= CreateCompatibleBitmap((HDC
) hdc
, dx
, dy
);
542 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, hBitmap
);
543 BitBlt(hdcGlyphs
, 0,0, dx
, dy
, (HDC
) hdc
, 0, 0, SRCCOPY
);
545 // initalize whole area with 1's
546 PatBlt((HDC
) m_hdcMono
, 0, 0, dx
, dy
, WHITENESS
);
548 // create mask based on color bitmap
549 // convert this to 1's
550 SetBkColor(hdcGlyphs
, m_rgbFace
);
551 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
552 hdcGlyphs
, 0, 0, SRCCOPY
);
553 // convert this to 1's
554 SetBkColor(hdcGlyphs
, m_rgbHilight
);
556 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
557 hdcGlyphs
, 0, 0, SRCPAINT
);
559 SelectObject(hdcGlyphs
, bitmapOld
);
560 DeleteObject(hBitmap
);
564 void wxToolBarMSW::DrawBlankButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, int state
)
567 PatB(hdc
, x
, y
, dx
, dy
, m_rgbFace
);
569 if (state
& wxTBSTATE_PRESSED
) {
570 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
571 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
572 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
573 PatB(hdc
, x
+ dx
- 1, y
+1, 1, dy
- 2, m_rgbFrame
);
574 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
-2, m_rgbShadow
);
575 PatB(hdc
, x
+ 1, y
+ 1, dx
-2, 1, m_rgbShadow
);
578 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
579 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
580 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
581 PatB(hdc
, x
+ dx
- 1, y
+ 1, 1, dy
- 2, m_rgbFrame
);
584 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
- 1, m_rgbHilight
);
585 PatB(hdc
, x
+ 1, y
+ 1, dx
- 1, 1, m_rgbHilight
);
586 PatB(hdc
, x
+ dx
, y
+ 1, 1, dy
, m_rgbShadow
);
587 PatB(hdc
, x
+ 1, y
+ dy
, dx
, 1, m_rgbShadow
);
588 PatB(hdc
, x
+ dx
- 1, y
+ 2, 1, dy
- 2, m_rgbShadow
);
589 PatB(hdc
, x
+ 2, y
+ dy
- 1, dx
- 2, 1, m_rgbShadow
);
593 void wxToolBarMSW::DrawButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, wxToolBarTool
*tool
, int state
)
597 BOOL bMaskCreated
= FALSE
;
598 int xButton
= 0; // assume button is down
605 // HBITMAP hBitmap = (HBITMAP) tool->m_bitmap1.GetHBITMAP();
606 HDC globalDC
= ::GetDC(NULL
);
607 HDC hdcGlyphs
= CreateCompatibleDC(globalDC
);
608 ReleaseDC(NULL
, globalDC
);
610 // get the proper button look - up or down.
611 if (!(state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))) {
612 xButton
= dx
; // use 'up' version of button
614 dyFace
-= 2; // extents to ignore button highlight
617 DrawBlankButton(hdc
, x
, y
, dx
, dy
, state
);
620 // move coordinates inside border and away from upper left highlight.
621 // the extents change accordingly.
627 // Using bitmap2 can cause problems (don't know why!)
628 #if !defined(__WIN32__) && !defined(__WIN386__)
630 if (tool
->m_bitmap2
.Ok())
631 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap2
.GetHBITMAP());
633 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
635 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
638 // calculate offset of face from (x,y). y is always from the top,
639 // so the offset is easy. x needs to be centered in face.
641 xCenterOffset
= (dxFace
- (int)GetToolBitmapSize().x
)/2;
642 if (state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))
644 // pressed state moves down and to the right
645 // (x moves automatically as face size grows)
649 // now put on the face
650 if (state
& wxTBSTATE_ENABLED
) {
652 BitBlt((HDC
) hdc
, x
+xCenterOffset
, y
+ yOffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
653 hdcGlyphs
, 0, 0, SRCCOPY
);
655 // disabled version (or indeterminate)
657 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
658 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
660 SetTextColor((HDC
) hdc
, 0L); // 0's in mono -> 0 (for ROP)
661 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1's in mono -> 1
663 // draw glyph's white understrike
664 if (!(state
& wxTBSTATE_INDETERMINATE
)) {
665 hbr
= CreateSolidBrush(m_rgbHilight
);
667 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
669 // draw hilight color where we have 0's in the mask
670 BitBlt((HDC
) hdc
, x
+ 1, y
+ 1, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
671 SelectObject((HDC
) hdc
, hbrOld
);
678 hbr
= CreateSolidBrush(m_rgbShadow
);
680 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
682 // draw the shadow color where we have 0's in the mask
683 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
684 SelectObject((HDC
) hdc
, hbrOld
);
689 if (state
& wxTBSTATE_CHECKED
) {
690 BitBlt((HDC
) m_hdcMono
, 1, 1, dxFace
- 1, dyFace
- 1, (HDC
) m_hdcMono
, 0, 0, SRCAND
);
694 if (state
& (wxTBSTATE_CHECKED
| wxTBSTATE_INDETERMINATE
)) {
696 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, (HBRUSH
) m_hbrDither
);
700 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
701 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
703 SetTextColor((HDC
) hdc
, 0L); // 0 -> 0
704 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1 -> 1
706 // only draw the dither brush where the mask is 1's
707 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00E20746);
709 SelectObject((HDC
) hdc
, hbrOld
);
712 SelectObject(hdcGlyphs
, bitmapOld
);
716 void wxToolBarMSW::GetSysColors(void)
718 static COLORREF rgbSaveFace
= 0xffffffffL
,
719 rgbSaveShadow
= 0xffffffffL
,
720 rgbSaveHilight
= 0xffffffffL
,
721 rgbSaveFrame
= 0xffffffffL
;
723 // For now, override these because the colour replacement isn't working,
724 // and we get inconsistent colours. Assume all buttons are grey for the moment.
726 // m_rgbFace = GetSysColor(COLOR_BTNFACE);
727 m_rgbFace
= RGB(192,192,192);
728 // m_rgbShadow = GetSysColor(COLOR_BTNSHADOW);
729 m_rgbShadow
= RGB(128,128,128);
730 // m_rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT);
731 m_rgbHilight
= RGB(255, 255, 255);
733 m_rgbFrame
= GetSysColor(COLOR_WINDOWFRAME
);
735 if (rgbSaveFace
!=m_rgbFace
|| rgbSaveShadow
!=m_rgbShadow
736 || rgbSaveHilight
!=m_rgbHilight
|| rgbSaveFrame
!=m_rgbFrame
)
738 rgbSaveFace
= m_rgbFace
;
739 rgbSaveShadow
= m_rgbShadow
;
740 rgbSaveHilight
= m_rgbHilight
;
741 rgbSaveFrame
= m_rgbFrame
;
743 // Update the brush for pushed-in buttons
748 WXHBITMAP
wxToolBarMSW::CreateDitherBitmap()
757 pbmi
= (BITMAPINFO
*)malloc(sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
));
758 memset(pbmi
, 0, (sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
)));
760 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
761 pbmi
->bmiHeader
.biWidth
= 8;
762 pbmi
->bmiHeader
.biHeight
= 8;
763 pbmi
->bmiHeader
.biPlanes
= 1;
764 pbmi
->bmiHeader
.biBitCount
= 1;
765 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
767 // rgb = GetSysColor(COLOR_BTNFACE);
768 rgb
= RGB(192,192,192);
770 pbmi
->bmiColors
[0].rgbBlue
= GetBValue(rgb
);
771 pbmi
->bmiColors
[0].rgbGreen
= GetGValue(rgb
);
772 pbmi
->bmiColors
[0].rgbRed
= GetRValue(rgb
);
773 pbmi
->bmiColors
[0].rgbReserved
= 0;
775 // rgb = GetSysColor(COLOR_BTNHIGHLIGHT);
776 rgb
= RGB(255, 255, 255);
778 pbmi
->bmiColors
[1].rgbBlue
= GetBValue(rgb
);
779 pbmi
->bmiColors
[1].rgbGreen
= GetGValue(rgb
);
780 pbmi
->bmiColors
[1].rgbRed
= GetRValue(rgb
);
781 pbmi
->bmiColors
[1].rgbReserved
= 0;
783 /* initialize the brushes */
785 for (i
= 0; i
< 8; i
++)
787 patGray
[i
] = 0xAAAA5555L
; // 0x11114444L; // lighter gray
789 patGray
[i
] = 0x5555AAAAL
; // 0x11114444L; // lighter gray
793 hbm
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
, patGray
, pbmi
, DIB_RGB_COLORS
);
795 ReleaseDC(NULL
, hdc
);
798 return (WXHBITMAP
)hbm
;
801 bool wxToolBarMSW::CreateDitherBrush(void)
807 hbmGray
= (HBITMAP
) CreateDitherBitmap();
811 hbrSave
= (HBRUSH
) m_hbrDither
;
812 m_hbrDither
= (WXHBRUSH
) CreatePatternBrush(hbmGray
);
813 DeleteObject(hbmGray
);
818 DeleteObject(hbrSave
);
824 m_hbrDither
= (WXHBRUSH
) hbrSave
;
831 bool wxToolBarMSW::FreeDitherBrush(void)
834 DeleteObject((HBRUSH
) m_hbrDither
);
839 typedef struct tagCOLORMAP2
846 // these are the default colors used to map the dib colors
847 // to the current system colors
849 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
850 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
851 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
852 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
853 #define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
854 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
855 #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
857 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE
WXUNUSED(hInstance
), void *info
)
859 LPBITMAPINFOHEADER lpBitmapInfo
= (LPBITMAPINFOHEADER
)info
;
860 HDC hdc
, hdcMem
= NULL
;
864 HBITMAP hbm
= NULL
, hbmOld
;
867 static COLORMAP2 ColorMap
[] = {
868 {BGR_BUTTONTEXT
, BGR_BUTTONTEXT
, COLOR_BTNTEXT
}, // black
869 {BGR_BUTTONSHADOW
, BGR_BUTTONSHADOW
, COLOR_BTNSHADOW
}, // dark grey
870 {BGR_BUTTONFACE
, BGR_BUTTONFACE
, COLOR_BTNFACE
}, // bright grey
871 {BGR_BUTTONHILIGHT
, BGR_BUTTONHILIGHT
, COLOR_BTNHIGHLIGHT
},// white
872 {BGR_BACKGROUNDSEL
, BGR_BACKGROUNDSEL
, COLOR_HIGHLIGHT
}, // blue
873 {BGR_BACKGROUND
, BGR_BACKGROUND
, COLOR_WINDOW
} // magenta
876 #define NUM_MAPS (sizeof(ColorMap)/sizeof(COLORMAP2))
882 // So what are the new colors anyway ?
884 for (i
=0; i
< (int) NUM_MAPS
; i
++) {
885 ColorMap
[i
].bgrto
= (long unsigned int) FlipColor(GetSysColor((int)ColorMap
[i
].sysColor
));
888 p
= (DWORD FAR
*)(((LPSTR
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
890 /* Replace button-face and button-shadow colors with the current values
894 while (numcolors
-- > 0) {
895 for (i
= 0; i
< (int) NUM_MAPS
; i
++) {
896 if (*p
== ColorMap
[i
].bgrfrom
) {
897 *p
= ColorMap
[i
].bgrto
;
904 /* First skip over the header structure */
905 lpBits
= (LPSTR
)(lpBitmapInfo
+ 1);
907 /* Skip the color table entries, if any */
908 lpBits
+= (1 << (lpBitmapInfo
->biBitCount
)) * sizeof(RGBQUAD
);
910 /* Create a color bitmap compatible with the display device */
911 i
= wid
= (int)lpBitmapInfo
->biWidth
;
912 hgt
= (int)lpBitmapInfo
->biHeight
;
915 hdcMem
= CreateCompatibleDC(hdc
);
917 // hbm = CreateDiscardableBitmap(hdc, i, hgt);
918 hbm
= CreateCompatibleBitmap(hdc
, i
, hgt
);
920 hbmOld
= (HBITMAP
) SelectObject(hdcMem
, hbm
);
922 // set the main image
923 StretchDIBits(hdcMem
, 0, 0, wid
, hgt
, 0, 0, wid
, hgt
, lpBits
,
924 (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
926 SelectObject(hdcMem
, hbmOld
);
929 DeleteObject(hdcMem
);
932 ReleaseDC(NULL
, hdc
);
934 return (WXHBITMAP
) hbm
;
937 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE hInstance
, WXHBITMAP hBitmap
)
939 HANDLE hDIB
= BitmapToDIB((HBITMAP
) hBitmap
, 0);
942 #ifdef __WINDOWS_386__
943 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)MK_FP32(GlobalLock(hDIB
));
945 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)GlobalLock(hDIB
);
947 HBITMAP newBitmap
= (HBITMAP
) CreateMappedBitmap((WXHINSTANCE
) wxGetInstance(), lpbmInfoHdr
);
950 return (WXHBITMAP
) newBitmap
;