1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/tbar95.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "tbar95.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/dynarray.h"
36 #include "wx/settings.h"
37 #include "wx/bitmap.h"
40 #if wxUSE_TOOLBAR && defined(__WIN95__) && wxUSE_TOOLBAR_NATIVE
42 #include "wx/toolbar.h"
44 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
48 #include "wx/msw/private.h"
52 #ifdef __GNUWIN32_OLD__
53 #include "wx/msw/gnuwin32/extra.h"
60 #include "wx/msw/dib.h"
61 #include "wx/app.h" // for GetComCtl32Version
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // these standard constants are not always defined in compilers headers
71 #define TBSTYLE_LIST 0x1000
72 #define TBSTYLE_FLAT 0x0800
73 #define TBSTYLE_TRANSPARENT 0x8000
75 // use TBSTYLE_TRANSPARENT if you use TBSTYLE_FLAT
79 #define TB_SETSTYLE (WM_USER + 56)
80 #define TB_GETSTYLE (WM_USER + 57)
84 #define TB_HITTEST (WM_USER + 69)
87 // these values correspond to those used by comctl32.dll
88 #define DEFAULTBITMAPX 16
89 #define DEFAULTBITMAPY 15
90 #define DEFAULTBUTTONX 24
91 #define DEFAULTBUTTONY 24
92 #define DEFAULTBARHEIGHT 27
94 // ----------------------------------------------------------------------------
95 // private function prototypes
96 // ----------------------------------------------------------------------------
98 static void wxMapBitmap(HBITMAP hBitmap
, int width
, int height
);
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxControl
)
106 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
107 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent
)
108 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged
)
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 class wxToolBarTool
: public wxToolBarToolBase
118 wxToolBarTool(wxToolBar
*tbar
,
120 const wxBitmap
& bitmap1
,
121 const wxBitmap
& bitmap2
,
123 wxObject
*clientData
,
124 const wxString
& shortHelpString
,
125 const wxString
& longHelpString
)
126 : wxToolBarToolBase(tbar
, id
, bitmap1
, bitmap2
, toggle
,
127 clientData
, shortHelpString
, longHelpString
)
132 wxToolBarTool(wxToolBar
*tbar
, wxControl
*control
)
133 : wxToolBarToolBase(tbar
, control
)
138 // set/get the number of separators which we use to cover the space used by
139 // a control in the toolbar
140 void SetSeparatorsCount(size_t count
) { m_nSepCount
= count
; }
141 size_t GetSeparatorsCount() const { return m_nSepCount
; }
148 // ============================================================================
150 // ============================================================================
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
157 const wxBitmap
& bitmap1
,
158 const wxBitmap
& bitmap2
,
160 wxObject
*clientData
,
161 const wxString
& shortHelpString
,
162 const wxString
& longHelpString
)
164 return new wxToolBarTool(this, id
, bitmap1
, bitmap2
, toggle
,
165 clientData
, shortHelpString
, longHelpString
);
168 wxToolBarToolBase
*wxToolBar::CreateTool(wxControl
*control
)
170 return new wxToolBarTool(this, control
);
173 // ----------------------------------------------------------------------------
174 // wxToolBar construction
175 // ----------------------------------------------------------------------------
177 void wxToolBar::Init()
183 m_defaultWidth
= DEFAULTBITMAPX
;
184 m_defaultHeight
= DEFAULTBITMAPY
;
187 bool wxToolBar::Create(wxWindow
*parent
,
192 const wxString
& name
)
194 // common initialisation
195 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
199 DWORD msflags
= 0; // WS_VISIBLE | WS_CHILD always included
200 if (style
& wxBORDER
)
201 msflags
|= WS_BORDER
;
203 #ifdef TBSTYLE_TOOLTIPS
204 msflags
|= TBSTYLE_TOOLTIPS
;
207 if (style
& wxTB_FLAT
)
209 if (wxTheApp
->GetComCtl32Version() > 400)
210 msflags
|= TBSTYLE_FLAT
;
213 // MSW-specific initialisation
214 if ( !wxControl::MSWCreateControl(TOOLBARCLASSNAME
, msflags
) )
217 // toolbar-specific post initialisation
218 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
220 // set up the colors and fonts
221 wxRGBToColour(m_backgroundColour
, GetSysColor(COLOR_BTNFACE
));
222 m_foregroundColour
= *wxBLACK
;
224 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
235 height
= m_defaultHeight
;
241 SetSize(x
, y
, width
, height
);
246 wxToolBar::~wxToolBar()
250 ::DeleteObject((HBITMAP
) m_hBitmap
);
254 // ----------------------------------------------------------------------------
255 // adding/removing tools
256 // ----------------------------------------------------------------------------
258 bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos
),
259 wxToolBarToolBase
*tool
)
261 // nothing special to do here - we really create the toolbar buttons in
268 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
270 // normally, we only delete one button, but we use several separators to
271 // cover the space used by one control sometimes (with old comctl32.dll)
272 size_t nButtonsToDelete
= 1;
274 // get the size of the button we're going to delete
276 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT
, pos
, (LPARAM
)&r
) )
278 wxLogLastError(_T("TB_GETITEMRECT"));
281 int width
= r
.right
- r
.left
;
283 if ( tool
->IsControl() )
285 nButtonsToDelete
= ((wxToolBarTool
*)tool
)->GetSeparatorsCount();
287 width
*= nButtonsToDelete
;
290 while ( nButtonsToDelete
-- > 0 )
292 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, pos
, 0) )
294 wxLogLastError("TB_DELETEBUTTON");
302 m_nButtons
-= nButtonsToDelete
;
304 // reposition all the controls after this button
305 wxToolBarToolsList::Node
*node
= m_tools
.Item(pos
);
306 for ( node
= node
->GetNext(); node
; node
= node
->GetNext() )
308 wxToolBarToolBase
*tool2
= node
->GetData();
309 if ( tool2
->IsControl() )
312 wxControl
*control
= tool2
->GetControl();
313 control
->GetPosition(&x
, NULL
);
314 control
->Move(x
- width
, -1);
321 bool wxToolBar::Realize()
323 size_t nTools
= GetToolsCount();
330 bool isVertical
= (GetWindowStyle() & wxTB_VERTICAL
) != 0;
332 // First, add the bitmap: we use one bitmap for all toolbar buttons
333 // ----------------------------------------------------------------
335 // if we already have a bitmap, we'll replace the existing one - otherwise
336 // we'll install a new one
337 HBITMAP oldToolBarBitmap
= (HBITMAP
)m_hBitmap
;
339 int totalBitmapWidth
= (int)(m_defaultWidth
* nTools
);
340 int totalBitmapHeight
= (int)m_defaultHeight
;
342 // Create a bitmap for all the tool bitmaps
343 HBITMAP hBitmap
= ::CreateCompatibleBitmap(ScreenHDC(),
348 wxLogLastError(_T("CreateCompatibleBitmap"));
353 m_hBitmap
= (WXHBITMAP
)hBitmap
;
355 // Now blit all the tools onto this bitmap
356 HDC memoryDC
= ::CreateCompatibleDC(NULL
);
357 HBITMAP oldBitmap
= (HBITMAP
) ::SelectObject(memoryDC
, hBitmap
);
359 HDC memoryDC2
= ::CreateCompatibleDC(NULL
);
361 // the button position
364 // the number of buttons (not separators)
367 wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
370 wxToolBarToolBase
*tool
= node
->GetData();
371 if ( tool
->IsButton() )
373 HBITMAP hbmp
= GetHbitmapOf(tool
->GetBitmap1());
376 HBITMAP oldBitmap2
= (HBITMAP
)::SelectObject(memoryDC2
, hbmp
);
377 if ( !BitBlt(memoryDC
, x
, 0, m_defaultWidth
, m_defaultHeight
,
378 memoryDC2
, 0, 0, SRCCOPY
) )
380 wxLogLastError("BitBlt");
383 ::SelectObject(memoryDC2
, oldBitmap2
);
387 wxFAIL_MSG( _T("invalid tool button bitmap") );
390 // still inc width and number of buttons because otherwise the
391 // subsequent buttons will all be shifted which is rather confusing
392 // (and like this you'd see immediately which bitmap was bad)
397 node
= node
->GetNext();
400 ::SelectObject(memoryDC
, oldBitmap
);
401 ::DeleteDC(memoryDC
);
402 ::DeleteDC(memoryDC2
);
404 // Map to system colours
405 wxMapBitmap(hBitmap
, totalBitmapWidth
, totalBitmapHeight
);
409 bool addBitmap
= TRUE
;
411 if ( oldToolBarBitmap
)
413 #ifdef TB_REPLACEBITMAP
414 if ( wxTheApp
->GetComCtl32Version() >= 400 )
416 TBREPLACEBITMAP replaceBitmap
;
417 replaceBitmap
.hInstOld
= NULL
;
418 replaceBitmap
.hInstNew
= NULL
;
419 replaceBitmap
.nIDOld
= (UINT
) oldToolBarBitmap
;
420 replaceBitmap
.nIDNew
= (UINT
) hBitmap
;
421 replaceBitmap
.nButtons
= nButtons
;
422 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP
,
423 0, (LPARAM
) &replaceBitmap
) )
425 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
428 ::DeleteObject(oldToolBarBitmap
);
434 #endif // TB_REPLACEBITMAP
436 // we can't replace the old bitmap, so we will add another one
437 // (awfully inefficient, but what else to do?) and shift the bitmap
438 // indices accordingly
441 bitmapId
= m_nButtons
;
444 // Now delete all the buttons
445 for ( size_t pos
= 0; pos
< m_nButtons
; pos
++ )
447 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON
, 0, 0) )
449 wxLogLastError("TB_DELETEBUTTON");
455 if ( addBitmap
) // no old bitmap or we can't replace it
457 TBADDBITMAP addBitmap
;
459 addBitmap
.nID
= (UINT
) hBitmap
;
460 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP
,
461 (WPARAM
) nButtons
, (LPARAM
)&addBitmap
) == -1 )
463 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
467 // Next add the buttons and separators
468 // -----------------------------------
470 TBBUTTON
*buttons
= new TBBUTTON
[nTools
];
472 // this array will hold the indices of all controls in the toolbar
473 wxArrayInt controlIds
;
476 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext() )
478 wxToolBarToolBase
*tool
= node
->GetData();
480 // don't add separators to the vertical toolbar - looks ugly
481 if ( isVertical
&& tool
->IsSeparator() )
484 TBBUTTON
& button
= buttons
[i
];
486 wxZeroMemory(button
);
488 switch ( tool
->GetStyle() )
490 case wxTOOL_STYLE_CONTROL
:
491 button
.idCommand
= tool
->GetId();
492 // fall through: create just a separator too
494 case wxTOOL_STYLE_SEPARATOR
:
495 button
.fsState
= TBSTATE_ENABLED
;
496 button
.fsStyle
= TBSTYLE_SEP
;
499 case wxTOOL_STYLE_BUTTON
:
500 button
.iBitmap
= bitmapId
;
501 button
.idCommand
= tool
->GetId();
503 if ( tool
->IsEnabled() )
504 button
.fsState
|= TBSTATE_ENABLED
;
505 if ( tool
->IsToggled() )
506 button
.fsState
|= TBSTATE_CHECKED
;
508 button
.fsStyle
= tool
->CanBeToggled() ? TBSTYLE_CHECK
518 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS
,
519 (WPARAM
)i
, (LPARAM
)buttons
) )
521 wxLogLastError("TB_ADDBUTTONS");
526 // Deal with the controls finally
527 // ------------------------------
529 // adjust the controls size to fit nicely in the toolbar
531 for ( node
= m_tools
.GetFirst(); node
; node
= node
->GetNext(), index
++ )
533 wxToolBarToolBase
*tool
= node
->GetData();
534 if ( !tool
->IsControl() )
537 wxControl
*control
= tool
->GetControl();
539 wxSize size
= control
->GetSize();
541 // the position of the leftmost controls corner
544 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
545 // latter only appeared in v4.70 of comctl32.dll
547 if ( !SendMessage(GetHwnd(), TB_GETITEMRECT
,
548 index
, (LPARAM
)(LPRECT
)&r
) )
550 wxLogLastError("TB_GETITEMRECT");
553 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
554 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
555 // available in headers, now check whether it is available now
557 if ( wxTheApp
->GetComCtl32Version() >= 471 )
559 // set the (underlying) separators width to be that of the
562 tbbi
.cbSize
= sizeof(tbbi
);
563 tbbi
.dwMask
= TBIF_SIZE
;
565 if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO
,
566 tool
->GetId(), (LPARAM
)&tbbi
) )
568 // the id is probably invalid?
569 wxLogLastError("TB_SETBUTTONINFO");
573 #endif // comctl32.dll 4.71
574 // TB_SETBUTTONINFO unavailable
576 // try adding several separators to fit the controls width
577 int widthSep
= r
.right
- r
.left
;
583 tbb
.fsState
= TBSTATE_ENABLED
| TBSTATE_HIDDEN
;
584 tbb
.fsStyle
= TBSTYLE_SEP
;
586 size_t nSeparators
= size
.x
/ widthSep
;
587 for ( size_t nSep
= 0; nSep
< nSeparators
; nSep
++ )
589 if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON
,
590 index
, (LPARAM
)&tbb
) )
592 wxLogLastError("TB_INSERTBUTTON");
598 // remember the number of separators we used - we'd have to
599 // delete all of them later
600 ((wxToolBarTool
*)tool
)->SetSeparatorsCount(nSeparators
);
602 // adjust the controls width to exactly cover the separators
603 control
->SetSize((nSeparators
+ 1)*widthSep
, -1);
606 // and position the control itself correctly vertically
607 int height
= r
.bottom
- r
.top
;
608 int diff
= height
- size
.y
;
611 // the control is too high, resize to fit
612 control
->SetSize(-1, height
- 2);
617 control
->Move(left
== -1 ? r
.left
: left
, r
.top
+ (diff
+ 1) / 2);
620 // the max index is the "real" number of buttons - i.e. counting even the
621 // separators which we added just for aligning the controls
626 if ( m_maxRows
== 0 )
628 // if not set yet, only one row
632 else if ( m_nButtons
> 0 ) // vertical non empty toolbar
634 if ( m_maxRows
== 0 )
636 // if not set yet, have one column
644 // ----------------------------------------------------------------------------
646 // ----------------------------------------------------------------------------
648 bool wxToolBar::MSWCommand(WXUINT cmd
, WXWORD id
)
650 wxToolBarToolBase
*tool
= FindById((int)id
);
654 if ( tool
->CanBeToggled() )
656 LRESULT state
= ::SendMessage(GetHwnd(), TB_GETSTATE
, id
, 0);
657 tool
->Toggle((state
& TBSTATE_CHECKED
) != 0);
660 bool toggled
= tool
->IsToggled();
662 // OnLeftClick() can veto the button state change - for buttons which may
663 // be toggled only, of couse
664 if ( !OnLeftClick((int)id
, toggled
) && tool
->CanBeToggled() )
668 tool
->SetToggle(toggled
);
670 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
, id
, MAKELONG(toggled
, 0));
676 bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl
),
680 // First check if this applies to us
681 NMHDR
*hdr
= (NMHDR
*)lParam
;
683 // the tooltips control created by the toolbar is sometimes Unicode, even
684 // in an ANSI application - this seems to be a bug in comctl32.dll v5
685 int code
= (int)hdr
->code
;
686 if ( (code
!= TTN_NEEDTEXTA
) && (code
!= TTN_NEEDTEXTW
) )
689 HWND toolTipWnd
= (HWND
)::SendMessage((HWND
)GetHWND(), TB_GETTOOLTIPS
, 0, 0);
690 if ( toolTipWnd
!= hdr
->hwndFrom
)
693 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
694 int id
= (int)ttText
->hdr
.idFrom
;
696 wxToolBarToolBase
*tool
= FindById(id
);
700 const wxString
& help
= tool
->GetShortHelp();
702 if ( !help
.IsEmpty() )
704 if ( code
== TTN_NEEDTEXTA
)
706 ttText
->lpszText
= (wxChar
*)help
.c_str();
710 // VZ: I don't know why it happens, but the versions of
711 // comctl32.dll starting from 4.70 sometimes send TTN_NEEDTEXTW
712 // even to ANSI programs (normally, this message is supposed
713 // to be sent to Unicode programs only) - hence we need to
714 // handle it as well, otherwise no tooltips will be shown in
717 size_t lenAnsi
= help
.Len();
719 // MetroWerks doesn't like calling mbstowcs with NULL argument
720 size_t lenUnicode
= 2*lenAnsi
;
722 size_t lenUnicode
= mbstowcs(NULL
, help
, lenAnsi
);
725 // using the pointer of right type avoids us doing all sorts of
726 // pointer arithmetics ourselves
727 wchar_t *dst
= (wchar_t *)ttText
->szText
,
728 *pwz
= new wchar_t[lenUnicode
+ 1];
729 mbstowcs(pwz
, help
, lenAnsi
+ 1);
730 memcpy(dst
, pwz
, lenUnicode
*sizeof(wchar_t));
732 // put the terminating _wide_ NUL
739 // For backward compatibility...
740 OnMouseEnter(tool
->GetId());
745 // ----------------------------------------------------------------------------
747 // ----------------------------------------------------------------------------
749 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
751 wxToolBarBase::SetToolBitmapSize(size
);
753 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE
, 0, MAKELONG(size
.x
, size
.y
));
756 void wxToolBar::SetRows(int nRows
)
758 if ( nRows
== m_maxRows
)
760 // avoid resizing the frame uselessly
764 // TRUE in wParam means to create at least as many rows, FALSE -
767 ::SendMessage(GetHwnd(), TB_SETROWS
,
768 MAKEWPARAM(nRows
, !(GetWindowStyle() & wxTB_VERTICAL
)),
776 // The button size is bigger than the bitmap size
777 wxSize
wxToolBar::GetToolSize() const
779 // TB_GETBUTTONSIZE is supported from version 4.70
780 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 )
781 if ( wxTheApp
->GetComCtl32Version() >= 470 )
783 DWORD dw
= ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE
, 0, 0);
785 return wxSize(LOWORD(dw
), HIWORD(dw
));
788 #endif // comctl32.dll 4.70+
791 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
795 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
800 int index
= (int)::SendMessage(GetHwnd(), TB_HITTEST
, 0, (LPARAM
)&pt
);
803 // it's a separator or there is no tool at all there
804 return (wxToolBarToolBase
*)NULL
;
807 return m_tools
.Item((size_t)index
)->GetData();
810 void wxToolBar::UpdateSize()
812 // the toolbar size changed
813 SendMessage(GetHwnd(), TB_AUTOSIZE
, 0, 0);
815 // we must also refresh the frame after the toolbar size (possibly) changed
816 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
819 // don't change the size, we just need to generate a WM_SIZE
821 if ( !GetWindowRect(GetHwndOf(frame
), &r
) )
823 wxLogLastError(_T("GetWindowRect"));
826 (void)::SendMessage(GetHwndOf(frame
), WM_SIZE
, SIZE_RESTORED
,
827 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
831 // ----------------------------------------------------------------------------
833 // ----------------------------------------------------------------------------
835 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
837 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON
,
838 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(enable
, 0));
841 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
843 ::SendMessage(GetHwnd(), TB_CHECKBUTTON
,
844 (WPARAM
)tool
->GetId(), (LPARAM
)MAKELONG(toggle
, 0));
847 void wxToolBar::DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
)
849 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
850 // without, so we really need to delete the button and recreate it here
851 wxFAIL_MSG( _T("not implemented") );
854 // ----------------------------------------------------------------------------
856 // ----------------------------------------------------------------------------
858 // Responds to colour changes, and passes event on to children.
859 void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent
& event
)
861 m_backgroundColour
= wxColour(GetRValue(GetSysColor(COLOR_BTNFACE
)),
862 GetGValue(GetSysColor(COLOR_BTNFACE
)), GetBValue(GetSysColor(COLOR_BTNFACE
)));
869 // Propagate the event to the non-top-level children
870 wxWindow::OnSysColourChanged(event
);
873 void wxToolBar::OnMouseEvent(wxMouseEvent
& event
)
875 if (event
.RightDown())
877 // For now, we don't have an id. Later we could
878 // try finding the tool.
879 OnRightClick((int)-1, event
.GetX(), event
.GetY());
887 long wxToolBar::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
889 if ( nMsg
== WM_SIZE
)
891 // calculate our minor dimenstion ourselves - we're confusing the
892 // standard logic (TB_AUTOSIZE) with our horizontal toolbars and other
895 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT
, 0, (LPARAM
)&r
) )
899 if ( GetWindowStyle() & wxTB_VERTICAL
)
901 w
= r
.right
- r
.left
;
904 w
*= (m_nButtons
+ m_maxRows
- 1)/m_maxRows
;
911 h
= r
.bottom
- r
.top
;
914 h
+= 6; // FIXME: this is the separator line height...
919 if ( MAKELPARAM(w
, h
) != lParam
)
921 // size really changed
930 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
933 // ----------------------------------------------------------------------------
935 // ----------------------------------------------------------------------------
937 // These are the default colors used to map the bitmap colors to the current
938 // system colors. Note that they are in BGR format because this is what Windows
939 // wants (and not RGB)
941 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
942 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
943 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
944 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
945 #define BGR_BACKGROUNDSEL (RGB(000,000,255)) // blue
946 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
948 void wxMapBitmap(HBITMAP hBitmap
, int width
, int height
)
950 COLORMAP ColorMap
[] =
952 {BGR_BUTTONTEXT
, COLOR_BTNTEXT
}, // black
953 {BGR_BUTTONSHADOW
, COLOR_BTNSHADOW
}, // dark grey
954 {BGR_BUTTONFACE
, COLOR_BTNFACE
}, // bright grey
955 {BGR_BUTTONHILIGHT
, COLOR_BTNHIGHLIGHT
},// white
956 /* {BGR_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue */
957 {BGR_BACKGROUND
, COLOR_WINDOW
} // magenta
960 int NUM_MAPS
= (sizeof(ColorMap
)/sizeof(COLORMAP
));
962 for ( n
= 0; n
< NUM_MAPS
; n
++)
964 ColorMap
[n
].to
= ::GetSysColor(ColorMap
[n
].to
);
968 HDC hdcMem
= CreateCompatibleDC(NULL
);
972 hbmOld
= (HBITMAP
) SelectObject(hdcMem
, hBitmap
);
975 for ( i
= 0; i
< width
; i
++)
977 for ( j
= 0; j
< height
; j
++)
979 COLORREF pixel
= ::GetPixel(hdcMem
, i
, j
);
981 BYTE red = GetRValue(pixel);
982 BYTE green = GetGValue(pixel);
983 BYTE blue = GetBValue(pixel);
986 for ( k
= 0; k
< NUM_MAPS
; k
++)
988 if ( ColorMap
[k
].from
== pixel
)
990 /* COLORREF actualPixel = */ ::SetPixel(hdcMem
, i
, j
, ColorMap
[k
].to
);
998 SelectObject(hdcMem
, hbmOld
);
999 DeleteObject(hdcMem
);
1004 // Some experiments...
1006 // What we want to do is create another bitmap which has a depth of 4,
1007 // and set the bits. So probably we want to convert this HBITMAP into a
1008 // DIB, then call SetDIBits.
1009 // AAAGH. The stupid thing is that if newBitmap has a depth of 4 (less than that of
1010 // the screen), then SetDIBits fails.
1011 HBITMAP newBitmap
= ::CreateBitmap(totalBitmapWidth
, totalBitmapHeight
, 1, 4, NULL
);
1012 HANDLE newDIB
= ::BitmapToDIB((HBITMAP
) m_hBitmap
, NULL
);
1013 LPBITMAPINFOHEADER lpbmi
= (LPBITMAPINFOHEADER
) GlobalLock(newDIB
);
1016 // LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) newDIB;
1018 int result
= ::SetDIBits(dc
, newBitmap
, 0, lpbmi
->biHeight
, FindDIBBits((LPSTR
)lpbmi
), (LPBITMAPINFO
)lpbmi
,
1020 DWORD err
= GetLastError();
1022 ::ReleaseDC(NULL
, dc
);
1025 GlobalUnlock (newDIB
);
1026 GlobalFree (newDIB
);
1028 // WXHBITMAP hBitmap2 = wxCreateMappedBitmap((WXHINSTANCE) wxGetInstance(), (WXHBITMAP) m_hBitmap);
1029 // Substitute our new bitmap for the old one
1030 ::DeleteObject((HBITMAP
) m_hBitmap
);
1031 m_hBitmap
= (WXHBITMAP
) newBitmap
;
1035 #endif // wxUSE_TOOLBAR && Win95