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 USE_BUTTONBAR && USE_TOOLBAR
36 #include "wx/tbarmsw.h"
38 #include "wx/msw/private.h"
39 #include "wx/msw/dib.h"
41 #define DEFAULTBITMAPX 16
42 #define DEFAULTBITMAPY 15
43 #define DEFAULTBUTTONX 24
44 #define DEFAULTBUTTONY 22
45 #define DEFAULTBARHEIGHT 27
47 /////// Non-Windows 95 implementation
49 #if !USE_IMAGE_LOADING_IN_MSW
50 #error If USE_IMAGE_LOADING_IN_MSW is set to 0, then USE_BUTTONBAR must be set to 0 too.
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxToolBarMSW
, wxToolBarBase
)
56 BEGIN_EVENT_TABLE(wxToolBarMSW
, wxToolBarBase
)
57 EVT_SIZE(wxToolBarMSW::OnSize
)
58 EVT_PAINT(wxToolBarMSW::OnPaint
)
59 EVT_MOUSE_EVENTS(wxToolBarMSW::OnMouseEvent
)
63 wxToolBarMSW::wxToolBarMSW(void)
73 m_defaultWidth
= DEFAULTBITMAPX
;
74 m_defaultHeight
= DEFAULTBITMAPY
;
77 bool wxToolBarMSW::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
78 long style
, const wxString
& name
)
80 if ( ! wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
83 if ( style
& wxTB_HORIZONTAL
)
84 { m_lastX
= 3; m_lastY
= 7; }
86 { m_lastX
= 7; m_lastY
= 3; }
87 m_maxWidth
= m_maxHeight
= 0;
88 m_pressedTool
= m_currentTool
= -1;
95 SetBackgroundColour(wxColour(192, 192, 192));
105 m_defaultWidth
= DEFAULTBITMAPX
;
106 m_defaultHeight
= DEFAULTBITMAPY
;
113 wxToolBarMSW::~wxToolBarMSW(void)
118 void wxToolBarMSW::SetToolBitmapSize(const wxSize
& size
)
120 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
125 // The button size is bigger than the bitmap size
126 wxSize
wxToolBarMSW::GetToolSize(void) const
128 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
131 void wxToolBarMSW::OnPaint(wxPaintEvent
& event
)
135 static int wxOnPaintCount
= 0;
137 // Prevent reentry of OnPaint which would cause
138 // wxMemoryDC errors.
139 if (wxOnPaintCount
> 0)
143 wxNode
*node
= m_tools
.First();
146 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
147 if (tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
149 int state
= wxTBSTATE_ENABLED
;
150 if (!tool
->m_enabled
)
152 if (tool
->m_isToggle
&& tool
->m_toggleState
)
153 state
|= wxTBSTATE_CHECKED
;
154 DrawTool(dc
, tool
, state
);
161 void wxToolBarMSW::OnSize(wxSizeEvent
& event
)
163 wxToolBarBase::OnSize(event
);
166 // If a Button is disabled, then NO function (besides leaving
167 // or entering) should be carried out. Therefore the additions
168 // of 'enabled' testing (Stefan Hammes).
169 void wxToolBarMSW::OnMouseEvent(wxMouseEvent
& event
)
171 static wxToolBarTool
*eventCurrentTool
= NULL
;
177 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
180 int state
= wxTBSTATE_ENABLED
;
181 if (eventCurrentTool
->m_toggleState
)
182 state
|= wxTBSTATE_CHECKED
;
183 DrawTool(dc
, eventCurrentTool
, state
);
184 eventCurrentTool
= NULL
;
191 event
.Position(&x
, &y
);
192 wxToolBarTool
*tool
= FindToolForPosition(x
, y
);
196 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
200 int state
= wxTBSTATE_ENABLED
;
201 if (eventCurrentTool
->m_toggleState
)
202 state
|= wxTBSTATE_CHECKED
;
203 DrawTool(dc
, eventCurrentTool
, state
);
204 eventCurrentTool
= NULL
;
206 if (m_currentTool
> -1)
214 if (!event
.Dragging() && !event
.IsButton())
216 if (tool
->m_index
!= m_currentTool
)
218 OnMouseEnter(tool
->m_index
);
219 m_currentTool
= tool
->m_index
;
223 if (event
.Dragging() && tool
->m_enabled
)
225 if (eventCurrentTool
)
227 // Might have dragged outside tool
228 if (eventCurrentTool
!= tool
)
230 int state
= wxTBSTATE_ENABLED
;
231 if (tool
->m_toggleState
)
232 state
|= wxTBSTATE_CHECKED
;
233 DrawTool(dc
, tool
, state
);
234 eventCurrentTool
= NULL
;
240 if (tool
&& event
.LeftIsDown() && tool
->m_enabled
)
242 eventCurrentTool
= tool
;
243 ::SetCapture((HWND
) GetHWND());
244 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
245 if (tool
->m_toggleState
)
246 state
|= wxTBSTATE_CHECKED
;
247 DrawTool(dc
, tool
, state
);
251 if (event
.LeftDown() && tool
->m_enabled
)
253 eventCurrentTool
= tool
;
254 ::SetCapture((HWND
) GetHWND());
255 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
256 if (tool
->m_toggleState
)
257 state
|= wxTBSTATE_CHECKED
;
258 DrawTool(dc
, tool
, state
);
260 else if (event
.LeftUp() && tool
->m_enabled
)
262 if (eventCurrentTool
)
264 if (eventCurrentTool
== tool
)
266 if (tool
->m_isToggle
)
268 tool
->m_toggleState
= !tool
->m_toggleState
;
269 if (!OnLeftClick(tool
->m_index
, tool
->m_toggleState
))
271 tool
->m_toggleState
= !tool
->m_toggleState
;
273 int state
= wxTBSTATE_ENABLED
;
274 if (tool
->m_toggleState
)
275 state
|= wxTBSTATE_CHECKED
;
276 DrawTool(dc
, tool
, state
);
280 int state
= wxTBSTATE_ENABLED
;
281 if (tool
->m_toggleState
)
282 state
|= wxTBSTATE_CHECKED
;
283 DrawTool(dc
, tool
, state
);
284 OnLeftClick(tool
->m_index
, tool
->m_toggleState
);
287 eventCurrentTool
= NULL
;
289 else if (event
.RightDown() && tool
->m_enabled
)
291 OnRightClick(tool
->m_index
, x
, y
);
295 // This function enables/disables a toolbar tool and redraws it.
296 // If that would not be done, the enabling/disabling wouldn't be
297 // visible on the screen.
298 void wxToolBarMSW::EnableTool(int toolIndex
, bool enable
)
300 wxNode
*node
= m_tools
.Find((long)toolIndex
);
305 // at first do the enabling/disabling in the base class
306 wxToolBarBase::EnableTool(toolIndex
,enable
);
307 // then calculate the state of the tool and draw it
308 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
310 if(tool
->m_toggleState
) state
|= wxTBSTATE_CHECKED
;
311 if(tool
->m_enabled
) state
|= wxTBSTATE_ENABLED
;
312 // how can i access the PRESSED state???
313 DrawTool(dc
, tool
,state
);
317 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxToolBarTool
*tool
, int state
)
319 DrawButton(dc
.GetHDC(), (int)tool
->m_x
, (int)tool
->m_y
, (int)tool
->GetWidth(), (int)tool
->GetHeight(), tool
, state
);
322 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxMemoryDC
& , wxToolBarTool
*tool
)
324 int state
= wxTBSTATE_ENABLED
;
325 if (!tool
->m_enabled
)
327 if (tool
->m_toggleState
)
328 state
|= wxTBSTATE_CHECKED
;
329 DrawTool(dc
, tool
, state
);
332 // If pushedBitmap is NULL, a reversed version of bitmap is
333 // created and used as the pushed/toggled image.
334 // If toggle is TRUE, the button toggles between the two states.
335 wxToolBarTool
*wxToolBarMSW::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
336 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
338 // Using bitmap2 can cause problems (don't know why!)
340 // TODO: use the mapping code from wxToolBar95 to get it right in this class
341 #if !defined(__WIN32__) && !defined(__WIN386__)
342 wxBitmap
*bitmap2
= NULL
;
345 bitmap2
= new wxBitmap
;
346 bitmap2
->SetHBITMAP( (WXHBITMAP
) CreateMappedBitmap(wxGetInstance(), (HBITMAP
) ((wxBitmap
& )bitmap
).GetHBITMAP()));
349 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, *bitmap2
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
351 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, (wxBitmap
*)NULL
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
354 tool
->m_clientData
= clientData
;
359 tool
->m_x
= m_xMargin
;
364 tool
->m_y
= m_yMargin
;
366 tool
->m_deleteSecondBitmap
= TRUE
;
367 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
369 // Calculate reasonable max size in case Layout() not called
370 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
371 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
373 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
374 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
376 m_tools
.Append((long)index
, tool
);
380 void wxToolBarMSW::Layout(void)
382 m_currentRowsOrColumns
= 0;
385 int maxToolWidth
= 0;
386 int maxToolHeight
= 0;
390 // Find the maximum tool width and height
391 wxNode
*node
= m_tools
.First();
394 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
395 if (tool
->GetWidth() > maxToolWidth
)
396 maxToolWidth
= (int)tool
->GetWidth();
397 if (tool
->GetHeight() > maxToolHeight
)
398 maxToolHeight
= (int)tool
->GetHeight();
402 int separatorSize
= m_toolSeparation
;
404 node
= m_tools
.First();
407 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
408 if (tool
->m_toolStyle
== wxTOOL_STYLE_SEPARATOR
)
410 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
412 if (m_currentRowsOrColumns
>= m_maxCols
)
413 m_lastY
+= separatorSize
;
415 m_lastX
+= separatorSize
;
419 if (m_currentRowsOrColumns
>= m_maxRows
)
420 m_lastX
+= separatorSize
;
422 m_lastY
+= separatorSize
;
425 else if (tool
->m_toolStyle
== wxTOOL_STYLE_BUTTON
)
427 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
429 if (m_currentRowsOrColumns
>= m_maxCols
)
431 m_currentRowsOrColumns
= 0;
433 m_lastY
+= maxToolHeight
+ m_toolPacking
;
435 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
436 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
438 m_lastX
+= maxToolWidth
+ m_toolPacking
;
442 if (m_currentRowsOrColumns
>= m_maxRows
)
444 m_currentRowsOrColumns
= 0;
445 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
448 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
449 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
451 m_lastY
+= maxToolHeight
+ m_toolPacking
;
453 m_currentRowsOrColumns
++;
456 if (m_lastX
> m_maxWidth
)
457 m_maxWidth
= m_lastX
;
458 if (m_lastY
> m_maxHeight
)
459 m_maxHeight
= m_lastY
;
463 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
464 m_maxWidth
+= maxToolWidth
;
466 m_maxHeight
+= maxToolHeight
;
468 m_maxWidth
+= m_xMargin
;
469 m_maxHeight
+= m_yMargin
;
473 bool wxToolBarMSW::InitGlobalObjects(void)
476 if (!CreateDitherBrush())
479 m_hdcMono
= (WXHDC
) CreateCompatibleDC(NULL
);
483 m_hbmMono
= (WXHBITMAP
) CreateBitmap((int)GetToolSize().x
, (int)GetToolSize().y
, 1, 1, NULL
);
487 m_hbmDefault
= (WXHBITMAP
) SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmMono
);
491 void wxToolBarMSW::FreeGlobalObjects(void)
498 SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmDefault
);
501 DeleteDC((HDC
) m_hdcMono
); // toast the DCs
506 DeleteObject((HBITMAP
) m_hbmMono
);
511 void wxToolBarMSW::PatB(WXHDC hdc
,int x
,int y
,int dx
,int dy
, long rgb
)
520 SetBkColor((HDC
) hdc
,rgb
);
521 ExtTextOut((HDC
) hdc
,0,0,ETO_OPAQUE
,&rc
,NULL
,0,NULL
);
525 // create a mono bitmap mask:
526 // 1's where color == COLOR_BTNFACE || COLOR_HILIGHT
527 // 0's everywhere else
529 void wxToolBarMSW::CreateMask(WXHDC hdc
, int xoffset
, int yoffset
, int dx
, int dy
)
531 HDC globalDC
= ::GetDC(NULL
);
532 HDC hdcGlyphs
= CreateCompatibleDC((HDC
) globalDC
);
533 ReleaseDC(NULL
, (HDC
) globalDC
);
535 // krj - create a new bitmap and copy the image from hdc.
536 //HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap);
537 HBITMAP hBitmap
= CreateCompatibleBitmap((HDC
) hdc
, dx
, dy
);
538 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, hBitmap
);
539 BitBlt(hdcGlyphs
, 0,0, dx
, dy
, (HDC
) hdc
, 0, 0, SRCCOPY
);
541 // initalize whole area with 1's
542 PatBlt((HDC
) m_hdcMono
, 0, 0, dx
, dy
, WHITENESS
);
544 // create mask based on color bitmap
545 // convert this to 1's
546 SetBkColor(hdcGlyphs
, m_rgbFace
);
547 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
548 hdcGlyphs
, 0, 0, SRCCOPY
);
549 // convert this to 1's
550 SetBkColor(hdcGlyphs
, m_rgbHilight
);
552 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
553 hdcGlyphs
, 0, 0, SRCPAINT
);
555 SelectObject(hdcGlyphs
, bitmapOld
);
556 DeleteObject(hBitmap
);
560 void wxToolBarMSW::DrawBlankButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, int state
)
563 PatB(hdc
, x
, y
, dx
, dy
, m_rgbFace
);
565 if (state
& wxTBSTATE_PRESSED
) {
566 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
567 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
568 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
569 PatB(hdc
, x
+ dx
- 1, y
+1, 1, dy
- 2, m_rgbFrame
);
570 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
-2, m_rgbShadow
);
571 PatB(hdc
, x
+ 1, y
+ 1, dx
-2, 1, m_rgbShadow
);
574 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
575 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
576 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
577 PatB(hdc
, x
+ dx
- 1, y
+ 1, 1, dy
- 2, m_rgbFrame
);
580 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
- 1, m_rgbHilight
);
581 PatB(hdc
, x
+ 1, y
+ 1, dx
- 1, 1, m_rgbHilight
);
582 PatB(hdc
, x
+ dx
, y
+ 1, 1, dy
, m_rgbShadow
);
583 PatB(hdc
, x
+ 1, y
+ dy
, dx
, 1, m_rgbShadow
);
584 PatB(hdc
, x
+ dx
- 1, y
+ 2, 1, dy
- 2, m_rgbShadow
);
585 PatB(hdc
, x
+ 2, y
+ dy
- 1, dx
- 2, 1, m_rgbShadow
);
589 void wxToolBarMSW::DrawButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, wxToolBarTool
*tool
, int state
)
593 BOOL bMaskCreated
= FALSE
;
594 int xButton
= 0; // assume button is down
601 // HBITMAP hBitmap = (HBITMAP) tool->m_bitmap1.GetHBITMAP();
602 HDC globalDC
= ::GetDC(NULL
);
603 HDC hdcGlyphs
= CreateCompatibleDC(globalDC
);
604 ReleaseDC(NULL
, globalDC
);
606 // get the proper button look - up or down.
607 if (!(state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))) {
608 xButton
= dx
; // use 'up' version of button
610 dyFace
-= 2; // extents to ignore button highlight
613 DrawBlankButton(hdc
, x
, y
, dx
, dy
, state
);
616 // move coordinates inside border and away from upper left highlight.
617 // the extents change accordingly.
623 // Using bitmap2 can cause problems (don't know why!)
624 #if !defined(__WIN32__) && !defined(__WIN386__)
626 if (tool
->m_bitmap2
.Ok())
627 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap2
.GetHBITMAP());
629 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
631 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
634 // calculate offset of face from (x,y). y is always from the top,
635 // so the offset is easy. x needs to be centered in face.
637 xCenterOffset
= (dxFace
- (int)GetToolBitmapSize().x
)/2;
638 if (state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))
640 // pressed state moves down and to the right
641 // (x moves automatically as face size grows)
645 // now put on the face
646 if (state
& wxTBSTATE_ENABLED
) {
648 BitBlt((HDC
) hdc
, x
+xCenterOffset
, y
+ yOffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
649 hdcGlyphs
, 0, 0, SRCCOPY
);
651 // disabled version (or indeterminate)
653 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
654 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
656 SetTextColor((HDC
) hdc
, 0L); // 0's in mono -> 0 (for ROP)
657 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1's in mono -> 1
659 // draw glyph's white understrike
660 if (!(state
& wxTBSTATE_INDETERMINATE
)) {
661 hbr
= CreateSolidBrush(m_rgbHilight
);
663 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
665 // draw hilight color where we have 0's in the mask
666 BitBlt((HDC
) hdc
, x
+ 1, y
+ 1, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
667 SelectObject((HDC
) hdc
, hbrOld
);
674 hbr
= CreateSolidBrush(m_rgbShadow
);
676 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
678 // draw the shadow color where we have 0's in the mask
679 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
680 SelectObject((HDC
) hdc
, hbrOld
);
685 if (state
& wxTBSTATE_CHECKED
) {
686 BitBlt((HDC
) m_hdcMono
, 1, 1, dxFace
- 1, dyFace
- 1, (HDC
) m_hdcMono
, 0, 0, SRCAND
);
690 if (state
& (wxTBSTATE_CHECKED
| wxTBSTATE_INDETERMINATE
)) {
692 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, (HBRUSH
) m_hbrDither
);
696 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
697 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
699 SetTextColor((HDC
) hdc
, 0L); // 0 -> 0
700 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1 -> 1
702 // only draw the dither brush where the mask is 1's
703 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00E20746);
705 SelectObject((HDC
) hdc
, hbrOld
);
708 SelectObject(hdcGlyphs
, bitmapOld
);
712 void wxToolBarMSW::GetSysColors(void)
714 static COLORREF rgbSaveFace
= 0xffffffffL
,
715 rgbSaveShadow
= 0xffffffffL
,
716 rgbSaveHilight
= 0xffffffffL
,
717 rgbSaveFrame
= 0xffffffffL
;
719 // For now, override these because the colour replacement isn't working,
720 // and we get inconsistent colours. Assume all buttons are grey for the moment.
722 // m_rgbFace = GetSysColor(COLOR_BTNFACE);
723 m_rgbFace
= RGB(192,192,192);
724 // m_rgbShadow = GetSysColor(COLOR_BTNSHADOW);
725 m_rgbShadow
= RGB(128,128,128);
726 // m_rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT);
727 m_rgbHilight
= RGB(255, 255, 255);
729 m_rgbFrame
= GetSysColor(COLOR_WINDOWFRAME
);
731 if (rgbSaveFace
!=m_rgbFace
|| rgbSaveShadow
!=m_rgbShadow
732 || rgbSaveHilight
!=m_rgbHilight
|| rgbSaveFrame
!=m_rgbFrame
)
734 rgbSaveFace
= m_rgbFace
;
735 rgbSaveShadow
= m_rgbShadow
;
736 rgbSaveHilight
= m_rgbHilight
;
737 rgbSaveFrame
= m_rgbFrame
;
739 // Update the brush for pushed-in buttons
744 WXHBITMAP
wxToolBarMSW::CreateDitherBitmap()
753 pbmi
= (BITMAPINFO
*)malloc(sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
));
754 memset(pbmi
, 0, (sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
)));
756 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
757 pbmi
->bmiHeader
.biWidth
= 8;
758 pbmi
->bmiHeader
.biHeight
= 8;
759 pbmi
->bmiHeader
.biPlanes
= 1;
760 pbmi
->bmiHeader
.biBitCount
= 1;
761 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
763 // rgb = GetSysColor(COLOR_BTNFACE);
764 rgb
= RGB(192,192,192);
766 pbmi
->bmiColors
[0].rgbBlue
= GetBValue(rgb
);
767 pbmi
->bmiColors
[0].rgbGreen
= GetGValue(rgb
);
768 pbmi
->bmiColors
[0].rgbRed
= GetRValue(rgb
);
769 pbmi
->bmiColors
[0].rgbReserved
= 0;
771 // rgb = GetSysColor(COLOR_BTNHIGHLIGHT);
772 rgb
= RGB(255, 255, 255);
774 pbmi
->bmiColors
[1].rgbBlue
= GetBValue(rgb
);
775 pbmi
->bmiColors
[1].rgbGreen
= GetGValue(rgb
);
776 pbmi
->bmiColors
[1].rgbRed
= GetRValue(rgb
);
777 pbmi
->bmiColors
[1].rgbReserved
= 0;
779 /* initialize the brushes */
781 for (i
= 0; i
< 8; i
++)
783 patGray
[i
] = 0xAAAA5555L
; // 0x11114444L; // lighter gray
785 patGray
[i
] = 0x5555AAAAL
; // 0x11114444L; // lighter gray
789 hbm
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
, patGray
, pbmi
, DIB_RGB_COLORS
);
791 ReleaseDC(NULL
, hdc
);
794 return (WXHBITMAP
)hbm
;
797 bool wxToolBarMSW::CreateDitherBrush(void)
803 hbmGray
= (HBITMAP
) CreateDitherBitmap();
807 hbrSave
= (HBRUSH
) m_hbrDither
;
808 m_hbrDither
= (WXHBRUSH
) CreatePatternBrush(hbmGray
);
809 DeleteObject(hbmGray
);
814 DeleteObject(hbrSave
);
820 m_hbrDither
= (WXHBRUSH
) hbrSave
;
827 bool wxToolBarMSW::FreeDitherBrush(void)
830 DeleteObject((HBRUSH
) m_hbrDither
);
835 typedef struct tagCOLORMAP2
842 // these are the default colors used to map the dib colors
843 // to the current system colors
845 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
846 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
847 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
848 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
849 #define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
850 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
851 #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
853 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE
WXUNUSED(hInstance
), void *info
)
855 LPBITMAPINFOHEADER lpBitmapInfo
= (LPBITMAPINFOHEADER
)info
;
856 HDC hdc
, hdcMem
= NULL
;
860 HBITMAP hbm
= NULL
, hbmOld
;
863 static COLORMAP2 ColorMap
[] = {
864 {BGR_BUTTONTEXT
, BGR_BUTTONTEXT
, COLOR_BTNTEXT
}, // black
865 {BGR_BUTTONSHADOW
, BGR_BUTTONSHADOW
, COLOR_BTNSHADOW
}, // dark grey
866 {BGR_BUTTONFACE
, BGR_BUTTONFACE
, COLOR_BTNFACE
}, // bright grey
867 {BGR_BUTTONHILIGHT
, BGR_BUTTONHILIGHT
, COLOR_BTNHIGHLIGHT
},// white
868 {BGR_BACKGROUNDSEL
, BGR_BACKGROUNDSEL
, COLOR_HIGHLIGHT
}, // blue
869 {BGR_BACKGROUND
, BGR_BACKGROUND
, COLOR_WINDOW
} // magenta
872 #define NUM_MAPS (sizeof(ColorMap)/sizeof(COLORMAP2))
878 // So what are the new colors anyway ?
880 for (i
=0; i
< (int) NUM_MAPS
; i
++) {
881 ColorMap
[i
].bgrto
= (long unsigned int) FlipColor(GetSysColor((int)ColorMap
[i
].sysColor
));
884 p
= (DWORD FAR
*)(((LPSTR
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
886 /* Replace button-face and button-shadow colors with the current values
890 while (numcolors
-- > 0) {
891 for (i
= 0; i
< (int) NUM_MAPS
; i
++) {
892 if (*p
== ColorMap
[i
].bgrfrom
) {
893 *p
= ColorMap
[i
].bgrto
;
900 /* First skip over the header structure */
901 lpBits
= (LPSTR
)(lpBitmapInfo
+ 1);
903 /* Skip the color table entries, if any */
904 lpBits
+= (1 << (lpBitmapInfo
->biBitCount
)) * sizeof(RGBQUAD
);
906 /* Create a color bitmap compatible with the display device */
907 i
= wid
= (int)lpBitmapInfo
->biWidth
;
908 hgt
= (int)lpBitmapInfo
->biHeight
;
911 hdcMem
= CreateCompatibleDC(hdc
);
913 // hbm = CreateDiscardableBitmap(hdc, i, hgt);
914 hbm
= CreateCompatibleBitmap(hdc
, i
, hgt
);
916 hbmOld
= (HBITMAP
) SelectObject(hdcMem
, hbm
);
918 // set the main image
919 StretchDIBits(hdcMem
, 0, 0, wid
, hgt
, 0, 0, wid
, hgt
, lpBits
,
920 (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
922 SelectObject(hdcMem
, hbmOld
);
925 DeleteObject(hdcMem
);
928 ReleaseDC(NULL
, hdc
);
930 return (WXHBITMAP
) hbm
;
933 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE hInstance
, WXHBITMAP hBitmap
)
935 HANDLE hDIB
= BitmapToDIB((HBITMAP
) hBitmap
, 0);
938 #ifdef __WINDOWS_386__
939 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)MK_FP32(GlobalLock(hDIB
));
941 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)GlobalLock(hDIB
);
943 HBITMAP newBitmap
= (HBITMAP
) CreateMappedBitmap((WXHINSTANCE
) wxGetInstance(), lpbmInfoHdr
);
946 return (WXHBITMAP
) newBitmap
;