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
38 #include "wx/tbarmsw.h"
41 #include "wx/bitmap.h"
42 #include "wx/msw/private.h"
43 #include "wx/msw/dib.h"
45 #define DEFAULTBITMAPX 16
46 #define DEFAULTBITMAPY 15
47 #define DEFAULTBUTTONX 24
48 #define DEFAULTBUTTONY 22
49 #define DEFAULTBARHEIGHT 27
51 /////// Non-Windows 95 implementation
53 #if !wxUSE_IMAGE_LOADING_IN_MSW
54 #error If wxUSE_IMAGE_LOADING_IN_MSW is set to 0, then wxUSE_BUTTONBAR must be set to 0 too.
57 #if !USE_SHARED_LIBRARY
58 IMPLEMENT_DYNAMIC_CLASS(wxToolBarMSW
, wxToolBarBase
)
60 BEGIN_EVENT_TABLE(wxToolBarMSW
, wxToolBarBase
)
61 EVT_SIZE(wxToolBarMSW::OnSize
)
62 EVT_PAINT(wxToolBarMSW::OnPaint
)
63 EVT_MOUSE_EVENTS(wxToolBarMSW::OnMouseEvent
)
67 wxToolBarMSW::wxToolBarMSW(void)
77 m_defaultWidth
= DEFAULTBITMAPX
;
78 m_defaultHeight
= DEFAULTBITMAPY
;
81 bool wxToolBarMSW::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
82 long style
, const wxString
& name
)
84 if ( ! wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
87 if ( style
& wxTB_HORIZONTAL
)
88 { m_lastX
= 3; m_lastY
= 7; }
90 { m_lastX
= 7; m_lastY
= 3; }
91 m_maxWidth
= m_maxHeight
= 0;
92 m_pressedTool
= m_currentTool
= -1;
99 SetBackgroundColour(wxColour(192, 192, 192));
109 m_defaultWidth
= DEFAULTBITMAPX
;
110 m_defaultHeight
= DEFAULTBITMAPY
;
117 wxToolBarMSW::~wxToolBarMSW(void)
122 void wxToolBarMSW::SetToolBitmapSize(const wxSize
& size
)
124 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
129 // The button size is bigger than the bitmap size
130 wxSize
wxToolBarMSW::GetToolSize(void) const
132 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
135 void wxToolBarMSW::OnPaint(wxPaintEvent
& event
)
139 static int wxOnPaintCount
= 0;
141 // Prevent reentry of OnPaint which would cause
142 // wxMemoryDC errors.
143 if (wxOnPaintCount
> 0)
147 wxNode
*node
= m_tools
.First();
150 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
151 if (tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
153 int state
= wxTBSTATE_ENABLED
;
154 if (!tool
->m_enabled
)
156 if (tool
->m_isToggle
&& tool
->m_toggleState
)
157 state
|= wxTBSTATE_CHECKED
;
158 DrawTool(dc
, tool
, state
);
165 void wxToolBarMSW::OnSize(wxSizeEvent
& event
)
167 wxToolBarBase::OnSize(event
);
170 // If a Button is disabled, then NO function (besides leaving
171 // or entering) should be carried out. Therefore the additions
172 // of 'enabled' testing (Stefan Hammes).
173 void wxToolBarMSW::OnMouseEvent(wxMouseEvent
& event
)
175 static wxToolBarTool
*eventCurrentTool
= NULL
;
181 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
184 int state
= wxTBSTATE_ENABLED
;
185 if (eventCurrentTool
->m_toggleState
)
186 state
|= wxTBSTATE_CHECKED
;
187 DrawTool(dc
, eventCurrentTool
, state
);
188 eventCurrentTool
= NULL
;
195 event
.Position(&x
, &y
);
196 wxToolBarTool
*tool
= FindToolForPosition(x
, y
);
200 if (eventCurrentTool
&& eventCurrentTool
->m_enabled
)
204 int state
= wxTBSTATE_ENABLED
;
205 if (eventCurrentTool
->m_toggleState
)
206 state
|= wxTBSTATE_CHECKED
;
207 DrawTool(dc
, eventCurrentTool
, state
);
208 eventCurrentTool
= NULL
;
210 if (m_currentTool
> -1)
218 if (!event
.Dragging() && !event
.IsButton())
220 if (tool
->m_index
!= m_currentTool
)
222 OnMouseEnter(tool
->m_index
);
223 m_currentTool
= tool
->m_index
;
227 if (event
.Dragging() && tool
->m_enabled
)
229 if (eventCurrentTool
)
231 // Might have dragged outside tool
232 if (eventCurrentTool
!= tool
)
234 int state
= wxTBSTATE_ENABLED
;
235 if (tool
->m_toggleState
)
236 state
|= wxTBSTATE_CHECKED
;
237 DrawTool(dc
, tool
, state
);
238 eventCurrentTool
= NULL
;
244 if (tool
&& event
.LeftIsDown() && tool
->m_enabled
)
246 eventCurrentTool
= tool
;
247 ::SetCapture((HWND
) GetHWND());
248 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
249 if (tool
->m_toggleState
)
250 state
|= wxTBSTATE_CHECKED
;
251 DrawTool(dc
, tool
, state
);
255 if (event
.LeftDown() && tool
->m_enabled
)
257 eventCurrentTool
= tool
;
258 ::SetCapture((HWND
) GetHWND());
259 int state
= wxTBSTATE_ENABLED
|wxTBSTATE_PRESSED
;
260 if (tool
->m_toggleState
)
261 state
|= wxTBSTATE_CHECKED
;
262 DrawTool(dc
, tool
, state
);
264 else if (event
.LeftUp() && tool
->m_enabled
)
266 if (eventCurrentTool
)
268 if (eventCurrentTool
== tool
)
270 if (tool
->m_isToggle
)
272 tool
->m_toggleState
= !tool
->m_toggleState
;
273 if (!OnLeftClick(tool
->m_index
, tool
->m_toggleState
))
275 tool
->m_toggleState
= !tool
->m_toggleState
;
277 int state
= wxTBSTATE_ENABLED
;
278 if (tool
->m_toggleState
)
279 state
|= wxTBSTATE_CHECKED
;
280 DrawTool(dc
, tool
, state
);
284 int state
= wxTBSTATE_ENABLED
;
285 if (tool
->m_toggleState
)
286 state
|= wxTBSTATE_CHECKED
;
287 DrawTool(dc
, tool
, state
);
288 OnLeftClick(tool
->m_index
, tool
->m_toggleState
);
291 eventCurrentTool
= NULL
;
293 else if (event
.RightDown() && tool
->m_enabled
)
295 OnRightClick(tool
->m_index
, x
, y
);
299 // This function enables/disables a toolbar tool and redraws it.
300 // If that would not be done, the enabling/disabling wouldn't be
301 // visible on the screen.
302 void wxToolBarMSW::EnableTool(int toolIndex
, bool enable
)
304 wxNode
*node
= m_tools
.Find((long)toolIndex
);
309 // at first do the enabling/disabling in the base class
310 wxToolBarBase::EnableTool(toolIndex
,enable
);
311 // then calculate the state of the tool and draw it
312 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
314 if(tool
->m_toggleState
) state
|= wxTBSTATE_CHECKED
;
315 if(tool
->m_enabled
) state
|= wxTBSTATE_ENABLED
;
316 // how can i access the PRESSED state???
317 DrawTool(dc
, tool
,state
);
321 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxToolBarTool
*tool
, int state
)
323 DrawButton(dc
.GetHDC(), (int)tool
->m_x
, (int)tool
->m_y
, (int)tool
->GetWidth(), (int)tool
->GetHeight(), tool
, state
);
326 void wxToolBarMSW::DrawTool(wxDC
& dc
, wxMemoryDC
& , wxToolBarTool
*tool
)
328 int state
= wxTBSTATE_ENABLED
;
329 if (!tool
->m_enabled
)
331 if (tool
->m_toggleState
)
332 state
|= wxTBSTATE_CHECKED
;
333 DrawTool(dc
, tool
, state
);
336 // If pushedBitmap is NULL, a reversed version of bitmap is
337 // created and used as the pushed/toggled image.
338 // If toggle is TRUE, the button toggles between the two states.
339 wxToolBarTool
*wxToolBarMSW::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
340 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
342 // Using bitmap2 can cause problems (don't know why!)
344 // TODO: use the mapping code from wxToolBar95 to get it right in this class
345 #if !defined(__WIN32__) && !defined(__WIN386__)
349 bitmap2
.SetHBITMAP( (WXHBITMAP
) CreateMappedBitmap(wxGetInstance(), (HBITMAP
) ((wxBitmap
& )bitmap
).GetHBITMAP()));
352 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, bitmap2
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
354 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
357 tool
->m_clientData
= clientData
;
362 tool
->m_x
= m_xMargin
;
367 tool
->m_y
= m_yMargin
;
369 tool
->m_deleteSecondBitmap
= TRUE
;
370 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
372 // Calculate reasonable max size in case Layout() not called
373 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
374 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
376 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
377 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
379 m_tools
.Append((long)index
, tool
);
383 void wxToolBarMSW::Layout(void)
385 m_currentRowsOrColumns
= 0;
388 int maxToolWidth
= 0;
389 int maxToolHeight
= 0;
393 // Find the maximum tool width and height
394 wxNode
*node
= m_tools
.First();
397 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
398 if (tool
->GetWidth() > maxToolWidth
)
399 maxToolWidth
= (int)tool
->GetWidth();
400 if (tool
->GetHeight() > maxToolHeight
)
401 maxToolHeight
= (int)tool
->GetHeight();
405 int separatorSize
= m_toolSeparation
;
407 node
= m_tools
.First();
410 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
411 if (tool
->m_toolStyle
== wxTOOL_STYLE_SEPARATOR
)
413 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
415 if (m_currentRowsOrColumns
>= m_maxCols
)
416 m_lastY
+= separatorSize
;
418 m_lastX
+= separatorSize
;
422 if (m_currentRowsOrColumns
>= m_maxRows
)
423 m_lastX
+= separatorSize
;
425 m_lastY
+= separatorSize
;
428 else if (tool
->m_toolStyle
== wxTOOL_STYLE_BUTTON
)
430 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
432 if (m_currentRowsOrColumns
>= m_maxCols
)
434 m_currentRowsOrColumns
= 0;
436 m_lastY
+= maxToolHeight
+ m_toolPacking
;
438 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
439 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
441 m_lastX
+= maxToolWidth
+ m_toolPacking
;
445 if (m_currentRowsOrColumns
>= m_maxRows
)
447 m_currentRowsOrColumns
= 0;
448 m_lastX
+= (maxToolWidth
+ m_toolPacking
);
451 tool
->m_x
= (long) (m_lastX
+ (maxToolWidth
- tool
->GetWidth())/2.0);
452 tool
->m_y
= (long) (m_lastY
+ (maxToolHeight
- tool
->GetHeight())/2.0);
454 m_lastY
+= maxToolHeight
+ m_toolPacking
;
456 m_currentRowsOrColumns
++;
459 if (m_lastX
> m_maxWidth
)
460 m_maxWidth
= m_lastX
;
461 if (m_lastY
> m_maxHeight
)
462 m_maxHeight
= m_lastY
;
466 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
467 m_maxWidth
+= maxToolWidth
;
469 m_maxHeight
+= maxToolHeight
;
471 m_maxWidth
+= m_xMargin
;
472 m_maxHeight
+= m_yMargin
;
476 bool wxToolBarMSW::InitGlobalObjects(void)
479 if (!CreateDitherBrush())
482 m_hdcMono
= (WXHDC
) CreateCompatibleDC(NULL
);
486 m_hbmMono
= (WXHBITMAP
) CreateBitmap((int)GetToolSize().x
, (int)GetToolSize().y
, 1, 1, NULL
);
490 m_hbmDefault
= (WXHBITMAP
) SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmMono
);
494 void wxToolBarMSW::FreeGlobalObjects(void)
501 SelectObject((HDC
) m_hdcMono
, (HBITMAP
) m_hbmDefault
);
504 DeleteDC((HDC
) m_hdcMono
); // toast the DCs
509 DeleteObject((HBITMAP
) m_hbmMono
);
514 void wxToolBarMSW::PatB(WXHDC hdc
,int x
,int y
,int dx
,int dy
, long rgb
)
523 SetBkColor((HDC
) hdc
,rgb
);
524 ExtTextOut((HDC
) hdc
,0,0,ETO_OPAQUE
,&rc
,NULL
,0,NULL
);
528 // create a mono bitmap mask:
529 // 1's where color == COLOR_BTNFACE || COLOR_HILIGHT
530 // 0's everywhere else
532 void wxToolBarMSW::CreateMask(WXHDC hdc
, int xoffset
, int yoffset
, int dx
, int dy
)
534 HDC globalDC
= ::GetDC(NULL
);
535 HDC hdcGlyphs
= CreateCompatibleDC((HDC
) globalDC
);
536 ReleaseDC(NULL
, (HDC
) globalDC
);
538 // krj - create a new bitmap and copy the image from hdc.
539 //HBITMAP bitmapOld = SelectObject(hdcGlyphs, hBitmap);
540 HBITMAP hBitmap
= CreateCompatibleBitmap((HDC
) hdc
, dx
, dy
);
541 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, hBitmap
);
542 BitBlt(hdcGlyphs
, 0,0, dx
, dy
, (HDC
) hdc
, 0, 0, SRCCOPY
);
544 // initalize whole area with 1's
545 PatBlt((HDC
) m_hdcMono
, 0, 0, dx
, dy
, WHITENESS
);
547 // create mask based on color bitmap
548 // convert this to 1's
549 SetBkColor(hdcGlyphs
, m_rgbFace
);
550 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
551 hdcGlyphs
, 0, 0, SRCCOPY
);
552 // convert this to 1's
553 SetBkColor(hdcGlyphs
, m_rgbHilight
);
555 BitBlt((HDC
) m_hdcMono
, xoffset
, yoffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
556 hdcGlyphs
, 0, 0, SRCPAINT
);
558 SelectObject(hdcGlyphs
, bitmapOld
);
559 DeleteObject(hBitmap
);
563 void wxToolBarMSW::DrawBlankButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, int state
)
566 PatB(hdc
, x
, y
, dx
, dy
, m_rgbFace
);
568 if (state
& wxTBSTATE_PRESSED
) {
569 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
570 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
571 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
572 PatB(hdc
, x
+ dx
- 1, y
+1, 1, dy
- 2, m_rgbFrame
);
573 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
-2, m_rgbShadow
);
574 PatB(hdc
, x
+ 1, y
+ 1, dx
-2, 1, m_rgbShadow
);
577 PatB(hdc
, x
+ 1, y
, dx
- 2, 1, m_rgbFrame
);
578 PatB(hdc
, x
+ 1, y
+ dy
- 1, dx
- 2, 1, m_rgbFrame
);
579 PatB(hdc
, x
, y
+ 1, 1, dy
- 2, m_rgbFrame
);
580 PatB(hdc
, x
+ dx
- 1, y
+ 1, 1, dy
- 2, m_rgbFrame
);
583 PatB(hdc
, x
+ 1, y
+ 1, 1, dy
- 1, m_rgbHilight
);
584 PatB(hdc
, x
+ 1, y
+ 1, dx
- 1, 1, m_rgbHilight
);
585 PatB(hdc
, x
+ dx
, y
+ 1, 1, dy
, m_rgbShadow
);
586 PatB(hdc
, x
+ 1, y
+ dy
, dx
, 1, m_rgbShadow
);
587 PatB(hdc
, x
+ dx
- 1, y
+ 2, 1, dy
- 2, m_rgbShadow
);
588 PatB(hdc
, x
+ 2, y
+ dy
- 1, dx
- 2, 1, m_rgbShadow
);
592 void wxToolBarMSW::DrawButton(WXHDC hdc
, int x
, int y
, int dx
, int dy
, wxToolBarTool
*tool
, int state
)
596 BOOL bMaskCreated
= FALSE
;
597 int xButton
= 0; // assume button is down
604 // HBITMAP hBitmap = (HBITMAP) tool->m_bitmap1.GetHBITMAP();
605 HDC globalDC
= ::GetDC(NULL
);
606 HDC hdcGlyphs
= CreateCompatibleDC(globalDC
);
607 ReleaseDC(NULL
, globalDC
);
609 // get the proper button look - up or down.
610 if (!(state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))) {
611 xButton
= dx
; // use 'up' version of button
613 dyFace
-= 2; // extents to ignore button highlight
616 DrawBlankButton(hdc
, x
, y
, dx
, dy
, state
);
619 // move coordinates inside border and away from upper left highlight.
620 // the extents change accordingly.
626 // Using bitmap2 can cause problems (don't know why!)
627 #if !defined(__WIN32__) && !defined(__WIN386__)
629 if (tool
->m_bitmap2
.Ok())
630 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap2
.GetHBITMAP());
632 bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
634 HBITMAP bitmapOld
= (HBITMAP
) SelectObject(hdcGlyphs
, (HBITMAP
) tool
->m_bitmap1
.GetHBITMAP());
637 // calculate offset of face from (x,y). y is always from the top,
638 // so the offset is easy. x needs to be centered in face.
640 xCenterOffset
= (dxFace
- (int)GetToolBitmapSize().x
)/2;
641 if (state
& (wxTBSTATE_PRESSED
| wxTBSTATE_CHECKED
))
643 // pressed state moves down and to the right
644 // (x moves automatically as face size grows)
648 // now put on the face
649 if (state
& wxTBSTATE_ENABLED
) {
651 BitBlt((HDC
) hdc
, x
+xCenterOffset
, y
+ yOffset
, (int)GetToolBitmapSize().x
, (int)GetToolBitmapSize().y
,
652 hdcGlyphs
, 0, 0, SRCCOPY
);
654 // disabled version (or indeterminate)
656 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
657 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
659 SetTextColor((HDC
) hdc
, 0L); // 0's in mono -> 0 (for ROP)
660 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1's in mono -> 1
662 // draw glyph's white understrike
663 if (!(state
& wxTBSTATE_INDETERMINATE
)) {
664 hbr
= CreateSolidBrush(m_rgbHilight
);
666 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
668 // draw hilight color where we have 0's in the mask
669 BitBlt((HDC
) hdc
, x
+ 1, y
+ 1, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
670 SelectObject((HDC
) hdc
, hbrOld
);
677 hbr
= CreateSolidBrush(m_rgbShadow
);
679 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, hbr
);
681 // draw the shadow color where we have 0's in the mask
682 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00B8074A);
683 SelectObject((HDC
) hdc
, hbrOld
);
688 if (state
& wxTBSTATE_CHECKED
) {
689 BitBlt((HDC
) m_hdcMono
, 1, 1, dxFace
- 1, dyFace
- 1, (HDC
) m_hdcMono
, 0, 0, SRCAND
);
693 if (state
& (wxTBSTATE_CHECKED
| wxTBSTATE_INDETERMINATE
)) {
695 hbrOld
= (HBRUSH
) SelectObject((HDC
) hdc
, (HBRUSH
) m_hbrDither
);
699 CreateMask((WXHDC
) hdcGlyphs
, xCenterOffset
, yOffset
, dxFace
, dyFace
);
700 // CreateMask(hBitmap, xCenterOffset, yOffset, dxFace, dyFace);
702 SetTextColor((HDC
) hdc
, 0L); // 0 -> 0
703 SetBkColor((HDC
) hdc
, 0x00FFFFFF); // 1 -> 1
705 // only draw the dither brush where the mask is 1's
706 BitBlt((HDC
) hdc
, x
, y
, dxFace
, dyFace
, (HDC
) m_hdcMono
, 0, 0, 0x00E20746);
708 SelectObject((HDC
) hdc
, hbrOld
);
711 SelectObject(hdcGlyphs
, bitmapOld
);
715 void wxToolBarMSW::GetSysColors(void)
717 static COLORREF rgbSaveFace
= 0xffffffffL
,
718 rgbSaveShadow
= 0xffffffffL
,
719 rgbSaveHilight
= 0xffffffffL
,
720 rgbSaveFrame
= 0xffffffffL
;
722 // For now, override these because the colour replacement isn't working,
723 // and we get inconsistent colours. Assume all buttons are grey for the moment.
725 // m_rgbFace = GetSysColor(COLOR_BTNFACE);
726 m_rgbFace
= RGB(192,192,192);
727 // m_rgbShadow = GetSysColor(COLOR_BTNSHADOW);
728 m_rgbShadow
= RGB(128,128,128);
729 // m_rgbHilight = GetSysColor(COLOR_BTNHIGHLIGHT);
730 m_rgbHilight
= RGB(255, 255, 255);
732 m_rgbFrame
= GetSysColor(COLOR_WINDOWFRAME
);
734 if (rgbSaveFace
!=m_rgbFace
|| rgbSaveShadow
!=m_rgbShadow
735 || rgbSaveHilight
!=m_rgbHilight
|| rgbSaveFrame
!=m_rgbFrame
)
737 rgbSaveFace
= m_rgbFace
;
738 rgbSaveShadow
= m_rgbShadow
;
739 rgbSaveHilight
= m_rgbHilight
;
740 rgbSaveFrame
= m_rgbFrame
;
742 // Update the brush for pushed-in buttons
747 WXHBITMAP
wxToolBarMSW::CreateDitherBitmap()
756 pbmi
= (BITMAPINFO
*)malloc(sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
));
757 memset(pbmi
, 0, (sizeof(BITMAPINFOHEADER
) + 16*sizeof(RGBQUAD
)));
759 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
760 pbmi
->bmiHeader
.biWidth
= 8;
761 pbmi
->bmiHeader
.biHeight
= 8;
762 pbmi
->bmiHeader
.biPlanes
= 1;
763 pbmi
->bmiHeader
.biBitCount
= 1;
764 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
766 // rgb = GetSysColor(COLOR_BTNFACE);
767 rgb
= RGB(192,192,192);
769 pbmi
->bmiColors
[0].rgbBlue
= GetBValue(rgb
);
770 pbmi
->bmiColors
[0].rgbGreen
= GetGValue(rgb
);
771 pbmi
->bmiColors
[0].rgbRed
= GetRValue(rgb
);
772 pbmi
->bmiColors
[0].rgbReserved
= 0;
774 // rgb = GetSysColor(COLOR_BTNHIGHLIGHT);
775 rgb
= RGB(255, 255, 255);
777 pbmi
->bmiColors
[1].rgbBlue
= GetBValue(rgb
);
778 pbmi
->bmiColors
[1].rgbGreen
= GetGValue(rgb
);
779 pbmi
->bmiColors
[1].rgbRed
= GetRValue(rgb
);
780 pbmi
->bmiColors
[1].rgbReserved
= 0;
782 /* initialize the brushes */
784 for (i
= 0; i
< 8; i
++)
786 patGray
[i
] = 0xAAAA5555L
; // 0x11114444L; // lighter gray
788 patGray
[i
] = 0x5555AAAAL
; // 0x11114444L; // lighter gray
792 hbm
= CreateDIBitmap(hdc
, &pbmi
->bmiHeader
, CBM_INIT
, patGray
, pbmi
, DIB_RGB_COLORS
);
794 ReleaseDC(NULL
, hdc
);
797 return (WXHBITMAP
)hbm
;
800 bool wxToolBarMSW::CreateDitherBrush(void)
806 hbmGray
= (HBITMAP
) CreateDitherBitmap();
810 hbrSave
= (HBRUSH
) m_hbrDither
;
811 m_hbrDither
= (WXHBRUSH
) CreatePatternBrush(hbmGray
);
812 DeleteObject(hbmGray
);
817 DeleteObject(hbrSave
);
823 m_hbrDither
= (WXHBRUSH
) hbrSave
;
830 bool wxToolBarMSW::FreeDitherBrush(void)
833 DeleteObject((HBRUSH
) m_hbrDither
);
838 typedef struct tagCOLORMAP2
845 // these are the default colors used to map the dib colors
846 // to the current system colors
848 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
849 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
850 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
851 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
852 #define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
853 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
854 #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
856 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE
WXUNUSED(hInstance
), void *info
)
858 LPBITMAPINFOHEADER lpBitmapInfo
= (LPBITMAPINFOHEADER
)info
;
859 HDC hdc
, hdcMem
= NULL
;
863 HBITMAP hbm
= NULL
, hbmOld
;
866 static COLORMAP2 ColorMap
[] = {
867 {BGR_BUTTONTEXT
, BGR_BUTTONTEXT
, COLOR_BTNTEXT
}, // black
868 {BGR_BUTTONSHADOW
, BGR_BUTTONSHADOW
, COLOR_BTNSHADOW
}, // dark grey
869 {BGR_BUTTONFACE
, BGR_BUTTONFACE
, COLOR_BTNFACE
}, // bright grey
870 {BGR_BUTTONHILIGHT
, BGR_BUTTONHILIGHT
, COLOR_BTNHIGHLIGHT
},// white
871 {BGR_BACKGROUNDSEL
, BGR_BACKGROUNDSEL
, COLOR_HIGHLIGHT
}, // blue
872 {BGR_BACKGROUND
, BGR_BACKGROUND
, COLOR_WINDOW
} // magenta
875 #define NUM_MAPS (sizeof(ColorMap)/sizeof(COLORMAP2))
881 // So what are the new colors anyway ?
883 for (i
=0; i
< (int) NUM_MAPS
; i
++) {
884 ColorMap
[i
].bgrto
= (long unsigned int) FlipColor(GetSysColor((int)ColorMap
[i
].sysColor
));
887 p
= (DWORD FAR
*)(((LPSTR
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
889 /* Replace button-face and button-shadow colors with the current values
893 while (numcolors
-- > 0) {
894 for (i
= 0; i
< (int) NUM_MAPS
; i
++) {
895 if (*p
== ColorMap
[i
].bgrfrom
) {
896 *p
= ColorMap
[i
].bgrto
;
903 /* First skip over the header structure */
904 lpBits
= (LPSTR
)(lpBitmapInfo
+ 1);
906 /* Skip the color table entries, if any */
907 lpBits
+= (1 << (lpBitmapInfo
->biBitCount
)) * sizeof(RGBQUAD
);
909 /* Create a color bitmap compatible with the display device */
910 i
= wid
= (int)lpBitmapInfo
->biWidth
;
911 hgt
= (int)lpBitmapInfo
->biHeight
;
914 hdcMem
= CreateCompatibleDC(hdc
);
916 // hbm = CreateDiscardableBitmap(hdc, i, hgt);
917 hbm
= CreateCompatibleBitmap(hdc
, i
, hgt
);
919 hbmOld
= (HBITMAP
) SelectObject(hdcMem
, hbm
);
921 // set the main image
922 StretchDIBits(hdcMem
, 0, 0, wid
, hgt
, 0, 0, wid
, hgt
, lpBits
,
923 (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
925 SelectObject(hdcMem
, hbmOld
);
928 DeleteObject(hdcMem
);
931 ReleaseDC(NULL
, hdc
);
933 return (WXHBITMAP
) hbm
;
936 WXHBITMAP
wxToolBarMSW::CreateMappedBitmap(WXHINSTANCE hInstance
, WXHBITMAP hBitmap
)
938 HANDLE hDIB
= BitmapToDIB((HBITMAP
) hBitmap
, 0);
941 #ifdef __WINDOWS_386__
942 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)MK_FP32(GlobalLock(hDIB
));
944 LPBITMAPINFOHEADER lpbmInfoHdr
= (LPBITMAPINFOHEADER
)GlobalLock(hDIB
);
946 HBITMAP newBitmap
= (HBITMAP
) CreateMappedBitmap((WXHINSTANCE
) wxGetInstance(), lpbmInfoHdr
);
949 return (WXHBITMAP
) newBitmap
;