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
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 !wxUSE_IMAGE_LOADING_IN_MSW
50 #error If wxUSE_IMAGE_LOADING_IN_MSW is set to 0, then wxUSE_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__)
345 bitmap2
.SetHBITMAP( (WXHBITMAP
) CreateMappedBitmap(wxGetInstance(), (HBITMAP
) ((wxBitmap
& )bitmap
).GetHBITMAP()));
348 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, bitmap2
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
350 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
353 tool
->m_clientData
= clientData
;
358 tool
->m_x
= m_xMargin
;
363 tool
->m_y
= m_yMargin
;
365 tool
->m_deleteSecondBitmap
= TRUE
;
366 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
368 // Calculate reasonable max size in case Layout() not called
369 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
370 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
372 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
373 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
375 m_tools
.Append((long)index
, tool
);
379 void wxToolBarMSW::Layout(void)
381 m_currentRowsOrColumns
= 0;
384 int maxToolWidth
= 0;
385 int maxToolHeight
= 0;
389 // Find the maximum tool width and height
390 wxNode
*node
= m_tools
.First();
393 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
394 if (tool
->GetWidth() > maxToolWidth
)
395 maxToolWidth
= (int)tool
->GetWidth();
396 if (tool
->GetHeight() > maxToolHeight
)
397 maxToolHeight
= (int)tool
->GetHeight();
401 int separatorSize
= m_toolSeparation
;
403 node
= m_tools
.First();
406 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
407 if (tool
->m_toolStyle
== wxTOOL_STYLE_SEPARATOR
)
409 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
411 if (m_currentRowsOrColumns
>= m_maxCols
)
412 m_lastY
+= separatorSize
;
414 m_lastX
+= separatorSize
;
418 if (m_currentRowsOrColumns
>= m_maxRows
)
419 m_lastX
+= separatorSize
;
421 m_lastY
+= separatorSize
;
424 else if (tool
->m_toolStyle
== wxTOOL_STYLE_BUTTON
)
426 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
428 if (m_currentRowsOrColumns
>= m_maxCols
)
430 m_currentRowsOrColumns
= 0;
432 m_lastY
+= maxToolHeight
+ m_toolPacking
;
434 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
435 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
437 m_lastX
+= maxToolWidth
+ m_toolPacking
;
441 if (m_currentRowsOrColumns
>= m_maxRows
)
443 m_currentRowsOrColumns
= 0;
444 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
447 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
448 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
450 m_lastY
+= maxToolHeight
+ m_toolPacking
;
452 m_currentRowsOrColumns
++;
455 if (m_lastX
> m_maxWidth
)
456 m_maxWidth
= m_lastX
;
457 if (m_lastY
> m_maxHeight
)
458 m_maxHeight
= m_lastY
;
462 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
463 m_maxWidth
+= maxToolWidth
;
465 m_maxHeight
+= maxToolHeight
;
467 m_maxWidth
+= m_xMargin
;
468 m_maxHeight
+= m_yMargin
;
472 bool wxToolBarMSW::InitGlobalObjects(void)
475 if (!CreateDitherBrush())
478 m_hdcMono
= (WXHDC
) CreateCompatibleDC(NULL
);
482 m_hbmMono
= (WXHBITMAP
) CreateBitmap((int)GetToolSize().x
, (int)GetToolSize().y
, 1, 1, NULL
);
486 m_hbmDefault
= (WXHBITMAP
) SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmMono
);
490 void wxToolBarMSW::FreeGlobalObjects(void)
497 SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmDefault
);
500 DeleteDC((HDC
) m_hdcMono
); // toast the DCs
505 DeleteObject((HBITMAP
) m_hbmMono
);
510 void wxToolBarMSW::PatB(WXHDC hdc
,int x
,int y
,int dx
,int dy
, long rgb
)
519 SetBkColor((HDC
) hdc
,rgb
);
520 ExtTextOut((HDC
) hdc
,0,0,ETO_OPAQUE
,&rc
,NULL
,0,NULL
);
524 // create a mono bitmap mask:
525 // 1's where color == COLOR_BTNFACE || COLOR_HILIGHT
526 // 0's everywhere else
528 void wxToolBarMSW::CreateMask(WXHDC hdc
, int xoffset
, int yoffset
, int dx
, int dy
)
530 HDC globalDC
= ::GetDC(NULL
);
531 HDC hdcGlyphs
= CreateCompatibleDC((HDC
) globalDC
);
532 ReleaseDC(NULL
, (HDC
) globalDC
);
534 // krj - create a new bitmap and copy the image from hdc.
535 //HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap);
536 HBITMAP hBitmap
= CreateCompatibleBitmap((HDC
) hdc
, dx
, dy
);
537 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, hBitmap
);
538 BitBlt(hdcGlyphs
, 0,0, dx
, dy
, (HDC
) hdc
, 0, 0, SRCCOPY
);
540 // initalize whole area with 1's
541 PatBlt((HDC
) m_hdcMono
, 0, 0, dx
, dy
, WHITENESS
);
543 // create mask based on color bitmap
544 // convert this to 1's
545 SetBkColor(hdcGlyphs
, m_rgbFace
);
546 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
547 hdcGlyphs
, 0, 0, SRCCOPY
);
548 // convert this to 1's
549 SetBkColor(hdcGlyphs
, m_rgbHilight
);
551 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
552 hdcGlyphs
, 0, 0, SRCPAINT
);
554 SelectObject(hdcGlyphs
, bitmapOld
);
555 DeleteObject(hBitmap
);
559 void wxToolBarMSW::DrawBlankButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, int state
)
562 PatB(hdc
, x
, y
, dx
, dy
, m_rgbFace
);
564 if (state
& wxTBSTATE_PRESSED
) {
565 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
566 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
567 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
568 PatB(hdc
, x
+ dx
- 1, y
+1, 1, dy
- 2, m_rgbFrame
);
569 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
-2, m_rgbShadow
);
570 PatB(hdc
, x
+ 1, y
+ 1, dx
-2, 1, m_rgbShadow
);
573 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
574 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
575 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
576 PatB(hdc
, x
+ dx
- 1, y
+ 1, 1, dy
- 2, m_rgbFrame
);
579 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
- 1, m_rgbHilight
);
580 PatB(hdc
, x
+ 1, y
+ 1, dx
- 1, 1, m_rgbHilight
);
581 PatB(hdc
, x
+ dx
, y
+ 1, 1, dy
, m_rgbShadow
);
582 PatB(hdc
, x
+ 1, y
+ dy
, dx
, 1, m_rgbShadow
);
583 PatB(hdc
, x
+ dx
- 1, y
+ 2, 1, dy
- 2, m_rgbShadow
);
584 PatB(hdc
, x
+ 2, y
+ dy
- 1, dx
- 2, 1, m_rgbShadow
);
588 void wxToolBarMSW::DrawButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, wxToolBarTool
*tool
, int state
)
592 BOOL bMaskCreated
= FALSE
;
593 int xButton
= 0; // assume button is down
600 // HBITMAP hBitmap = (HBITMAP) tool->m_bitmap1.GetHBITMAP();
601 HDC globalDC
= ::GetDC(NULL
);
602 HDC hdcGlyphs
= CreateCompatibleDC(globalDC
);
603 ReleaseDC(NULL
, globalDC
);
605 // get the proper button look - up or down.
606 if (!(state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))) {
607 xButton
= dx
; // use 'up' version of button
609 dyFace
-= 2; // extents to ignore button highlight
612 DrawBlankButton(hdc
, x
, y
, dx
, dy
, state
);
615 // move coordinates inside border and away from upper left highlight.
616 // the extents change accordingly.
622 // Using bitmap2 can cause problems (don't know why!)
623 #if !defined(__WIN32__) && !defined(__WIN386__)
625 if (tool
->m_bitmap2
.Ok())
626 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap2
.GetHBITMAP());
628 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
630 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
633 // calculate offset of face from (x,y). y is always from the top,
634 // so the offset is easy. x needs to be centered in face.
636 xCenterOffset
= (dxFace
- (int)GetToolBitmapSize().x
)/2;
637 if (state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))
639 // pressed state moves down and to the right
640 // (x moves automatically as face size grows)
644 // now put on the face
645 if (state
& wxTBSTATE_ENABLED
) {
647 BitBlt((HDC
) hdc
, x
+xCenterOffset
, y
+ yOffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
648 hdcGlyphs
, 0, 0, SRCCOPY
);
650 // disabled version (or indeterminate)
652 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
653 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
655 SetTextColor((HDC
) hdc
, 0L); // 0's in mono -> 0 (for ROP)
656 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1's in mono -> 1
658 // draw glyph's white understrike
659 if (!(state
& wxTBSTATE_INDETERMINATE
)) {
660 hbr
= CreateSolidBrush(m_rgbHilight
);
662 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
664 // draw hilight color where we have 0's in the mask
665 BitBlt((HDC
) hdc
, x
+ 1, y
+ 1, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
666 SelectObject((HDC
) hdc
, hbrOld
);
673 hbr
= CreateSolidBrush(m_rgbShadow
);
675 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
677 // draw the shadow color where we have 0's in the mask
678 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
679 SelectObject((HDC
) hdc
, hbrOld
);
684 if (state
& wxTBSTATE_CHECKED
) {
685 BitBlt((HDC
) m_hdcMono
, 1, 1, dxFace
- 1, dyFace
- 1, (HDC
) m_hdcMono
, 0, 0, SRCAND
);
689 if (state
& (wxTBSTATE_CHECKED
| wxTBSTATE_INDETERMINATE
)) {
691 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, (HBRUSH
) m_hbrDither
);
695 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
696 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
698 SetTextColor((HDC
) hdc
, 0L); // 0 -> 0
699 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1 -> 1
701 // only draw the dither brush where the mask is 1's
702 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00E20746);
704 SelectObject((HDC
) hdc
, hbrOld
);
707 SelectObject(hdcGlyphs
, bitmapOld
);
711 void wxToolBarMSW::GetSysColors(void)
713 static COLORREF rgbSaveFace
= 0xffffffffL
,
714 rgbSaveShadow
= 0xffffffffL
,
715 rgbSaveHilight
= 0xffffffffL
,
716 rgbSaveFrame
= 0xffffffffL
;
718 // For now, override these because the colour replacement isn't working,
719 // and we get inconsistent colours. Assume all buttons are grey for the moment.
721 // m_rgbFace = GetSysColor(COLOR_BTNFACE);
722 m_rgbFace
= RGB(192,192,192);
723 // m_rgbShadow = GetSysColor(COLOR_BTNSHADOW);
724 m_rgbShadow
= RGB(128,128,128);
725 // m_rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT);
726 m_rgbHilight
= RGB(255, 255, 255);
728 m_rgbFrame
= GetSysColor(COLOR_WINDOWFRAME
);
730 if (rgbSaveFace
!=m_rgbFace
|| rgbSaveShadow
!=m_rgbShadow
731 || rgbSaveHilight
!=m_rgbHilight
|| rgbSaveFrame
!=m_rgbFrame
)
733 rgbSaveFace
= m_rgbFace
;
734 rgbSaveShadow
= m_rgbShadow
;
735 rgbSaveHilight
= m_rgbHilight
;
736 rgbSaveFrame
= m_rgbFrame
;
738 // Update the brush for pushed-in buttons
743 WXHBITMAP
wxToolBarMSW::CreateDitherBitmap()
752 pbmi
= (BITMAPINFO
*)malloc(sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
));
753 memset(pbmi
, 0, (sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
)));
755 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
756 pbmi
->bmiHeader
.biWidth
= 8;
757 pbmi
->bmiHeader
.biHeight
= 8;
758 pbmi
->bmiHeader
.biPlanes
= 1;
759 pbmi
->bmiHeader
.biBitCount
= 1;
760 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
762 // rgb = GetSysColor(COLOR_BTNFACE);
763 rgb
= RGB(192,192,192);
765 pbmi
->bmiColors
[0].rgbBlue
= GetBValue(rgb
);
766 pbmi
->bmiColors
[0].rgbGreen
= GetGValue(rgb
);
767 pbmi
->bmiColors
[0].rgbRed
= GetRValue(rgb
);
768 pbmi
->bmiColors
[0].rgbReserved
= 0;
770 // rgb = GetSysColor(COLOR_BTNHIGHLIGHT);
771 rgb
= RGB(255, 255, 255);
773 pbmi
->bmiColors
[1].rgbBlue
= GetBValue(rgb
);
774 pbmi
->bmiColors
[1].rgbGreen
= GetGValue(rgb
);
775 pbmi
->bmiColors
[1].rgbRed
= GetRValue(rgb
);
776 pbmi
->bmiColors
[1].rgbReserved
= 0;
778 /* initialize the brushes */
780 for (i
= 0; i
< 8; i
++)
782 patGray
[i
] = 0xAAAA5555L
; // 0x11114444L; // lighter gray
784 patGray
[i
] = 0x5555AAAAL
; // 0x11114444L; // lighter gray
788 hbm
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
, patGray
, pbmi
, DIB_RGB_COLORS
);
790 ReleaseDC(NULL
, hdc
);
793 return (WXHBITMAP
)hbm
;
796 bool wxToolBarMSW::CreateDitherBrush(void)
802 hbmGray
= (HBITMAP
) CreateDitherBitmap();
806 hbrSave
= (HBRUSH
) m_hbrDither
;
807 m_hbrDither
= (WXHBRUSH
) CreatePatternBrush(hbmGray
);
808 DeleteObject(hbmGray
);
813 DeleteObject(hbrSave
);
819 m_hbrDither
= (WXHBRUSH
) hbrSave
;
826 bool wxToolBarMSW::FreeDitherBrush(void)
829 DeleteObject((HBRUSH
) m_hbrDither
);
834 typedef struct tagCOLORMAP2
841 // these are the default colors used to map the dib colors
842 // to the current system colors
844 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
845 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
846 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
847 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
848 #define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
849 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
850 #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
852 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE
WXUNUSED(hInstance
), void *info
)
854 LPBITMAPINFOHEADER lpBitmapInfo
= (LPBITMAPINFOHEADER
)info
;
855 HDC hdc
, hdcMem
= NULL
;
859 HBITMAP hbm
= NULL
, hbmOld
;
862 static COLORMAP2 ColorMap
[] = {
863 {BGR_BUTTONTEXT
, BGR_BUTTONTEXT
, COLOR_BTNTEXT
}, // black
864 {BGR_BUTTONSHADOW
, BGR_BUTTONSHADOW
, COLOR_BTNSHADOW
}, // dark grey
865 {BGR_BUTTONFACE
, BGR_BUTTONFACE
, COLOR_BTNFACE
}, // bright grey
866 {BGR_BUTTONHILIGHT
, BGR_BUTTONHILIGHT
, COLOR_BTNHIGHLIGHT
},// white
867 {BGR_BACKGROUNDSEL
, BGR_BACKGROUNDSEL
, COLOR_HIGHLIGHT
}, // blue
868 {BGR_BACKGROUND
, BGR_BACKGROUND
, COLOR_WINDOW
} // magenta
871 #define NUM_MAPS (sizeof(ColorMap)/sizeof(COLORMAP2))
877 // So what are the new colors anyway ?
879 for (i
=0; i
< (int) NUM_MAPS
; i
++) {
880 ColorMap
[i
].bgrto
= (long unsigned int) FlipColor(GetSysColor((int)ColorMap
[i
].sysColor
));
883 p
= (DWORD FAR
*)(((LPSTR
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
885 /* Replace button-face and button-shadow colors with the current values
889 while (numcolors
-- > 0) {
890 for (i
= 0; i
< (int) NUM_MAPS
; i
++) {
891 if (*p
== ColorMap
[i
].bgrfrom
) {
892 *p
= ColorMap
[i
].bgrto
;
899 /* First skip over the header structure */
900 lpBits
= (LPSTR
)(lpBitmapInfo
+ 1);
902 /* Skip the color table entries, if any */
903 lpBits
+= (1 << (lpBitmapInfo
->biBitCount
)) * sizeof(RGBQUAD
);
905 /* Create a color bitmap compatible with the display device */
906 i
= wid
= (int)lpBitmapInfo
->biWidth
;
907 hgt
= (int)lpBitmapInfo
->biHeight
;
910 hdcMem
= CreateCompatibleDC(hdc
);
912 // hbm = CreateDiscardableBitmap(hdc, i, hgt);
913 hbm
= CreateCompatibleBitmap(hdc
, i
, hgt
);
915 hbmOld
= (HBITMAP
) SelectObject(hdcMem
, hbm
);
917 // set the main image
918 StretchDIBits(hdcMem
, 0, 0, wid
, hgt
, 0, 0, wid
, hgt
, lpBits
,
919 (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
921 SelectObject(hdcMem
, hbmOld
);
924 DeleteObject(hdcMem
);
927 ReleaseDC(NULL
, hdc
);
929 return (WXHBITMAP
) hbm
;
932 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE hInstance
, WXHBITMAP hBitmap
)
934 HANDLE hDIB
= BitmapToDIB((HBITMAP
) hBitmap
, 0);
937 #ifdef __WINDOWS_386__
938 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)MK_FP32(GlobalLock(hDIB
));
940 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)GlobalLock(hDIB
);
942 HBITMAP newBitmap
= (HBITMAP
) CreateMappedBitmap((WXHINSTANCE
) wxGetInstance(), lpbmInfoHdr
);
945 return (WXHBITMAP
) newBitmap
;