]> git.saurik.com Git - wxWidgets.git/blame - src/msw/tbar95.cpp
fixed spurious assert failure in wxMenuBar::Insert
[wxWidgets.git] / src / msw / tbar95.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1c383dba 2// Name: msw/tbar95.cpp
8a0681f9 3// Purpose: wxToolBar
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
89b892a2 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
1c383dba
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
1c383dba 21 #pragma implementation "tbar95.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
1c383dba 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
8a0681f9 32 #include "wx/frame.h"
1c383dba
VZ
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/dynarray.h"
4e15f6c5 36 #include "wx/settings.h"
381dd4bf 37 #include "wx/bitmap.h"
f6bcfd97 38 #include "wx/dcmemory.h"
2bda0e17
KB
39#endif
40
8a0681f9
VZ
41#if wxUSE_TOOLBAR && defined(__WIN95__) && wxUSE_TOOLBAR_NATIVE
42
43#include "wx/toolbar.h"
2bda0e17 44
ce3ed50d 45#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
1c383dba 46 #include "malloc.h"
2bda0e17
KB
47#endif
48
1c383dba 49#include "wx/msw/private.h"
2bda0e17 50
57c208c5 51#ifndef __TWIN32__
1c383dba 52
ae090fdb 53#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
1c383dba 54 #include <commctrl.h>
ae090fdb
JS
55#else
56 #include "wx/msw/gnuwin32/extra.h"
65fd5cb0 57#endif
2bda0e17 58
1c383dba
VZ
59#endif // __TWIN32__
60
2bda0e17 61#include "wx/msw/dib.h"
1c383dba
VZ
62#include "wx/app.h" // for GetComCtl32Version
63
f6bcfd97
BP
64// ----------------------------------------------------------------------------
65// conditional compilation
66// ----------------------------------------------------------------------------
67
68// wxWindows previously always considered that toolbar buttons have light grey
69// (0xc0c0c0) background and so ignored any bitmap masks - however, this
70// doesn't work with XPMs which then appear to have black background. To make
71// this work, we must respect the bitmap masks - which we do now. This should
72// be ok in any case, but to restore 100% compatible with the old version
73// behaviour, you can set this to 0.
74#define USE_BITMAP_MASKS 1
75
1c383dba
VZ
76// ----------------------------------------------------------------------------
77// constants
78// ----------------------------------------------------------------------------
79
80// these standard constants are not always defined in compilers headers
2bda0e17 81
6a23cbce 82// Styles
bb6290e3 83#ifndef TBSTYLE_FLAT
1c383dba
VZ
84 #define TBSTYLE_LIST 0x1000
85 #define TBSTYLE_FLAT 0x0800
86 #define TBSTYLE_TRANSPARENT 0x8000
bb6290e3
JS
87#endif
88 // use TBSTYLE_TRANSPARENT if you use TBSTYLE_FLAT
89
6a23cbce
JS
90// Messages
91#ifndef TB_GETSTYLE
1c383dba 92 #define TB_SETSTYLE (WM_USER + 56)
8a0681f9
VZ
93 #define TB_GETSTYLE (WM_USER + 57)
94#endif
95
96#ifndef TB_HITTEST
97 #define TB_HITTEST (WM_USER + 69)
6a23cbce
JS
98#endif
99
1c383dba 100// these values correspond to those used by comctl32.dll
81d66cf3
JS
101#define DEFAULTBITMAPX 16
102#define DEFAULTBITMAPY 15
103#define DEFAULTBUTTONX 24
104#define DEFAULTBUTTONY 24
105#define DEFAULTBARHEIGHT 27
106
1c383dba 107// ----------------------------------------------------------------------------
8a0681f9 108// private function prototypes
1c383dba
VZ
109// ----------------------------------------------------------------------------
110
f6bcfd97 111// adjust toolbar bitmap colours
5e68f8f3 112// static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
1c383dba
VZ
113
114// ----------------------------------------------------------------------------
115// wxWin macros
116// ----------------------------------------------------------------------------
117
12ed316d 118IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
2bda0e17 119
8a0681f9
VZ
120BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
121 EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
122 EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged)
2bda0e17 123END_EVENT_TABLE()
2bda0e17 124
8a0681f9
VZ
125// ----------------------------------------------------------------------------
126// private classes
127// ----------------------------------------------------------------------------
128
129class wxToolBarTool : public wxToolBarToolBase
130{
131public:
132 wxToolBarTool(wxToolBar *tbar,
133 int id,
134 const wxBitmap& bitmap1,
135 const wxBitmap& bitmap2,
136 bool toggle,
137 wxObject *clientData,
138 const wxString& shortHelpString,
139 const wxString& longHelpString)
140 : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
141 clientData, shortHelpString, longHelpString)
142 {
143 m_nSepCount = 0;
144 }
145
146 wxToolBarTool(wxToolBar *tbar, wxControl *control)
147 : wxToolBarToolBase(tbar, control)
148 {
149 m_nSepCount = 1;
150 }
151
152 // set/get the number of separators which we use to cover the space used by
153 // a control in the toolbar
154 void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
155 size_t GetSeparatorsCount() const { return m_nSepCount; }
156
157private:
158 size_t m_nSepCount;
159};
160
161
1c383dba
VZ
162// ============================================================================
163// implementation
164// ============================================================================
2bda0e17 165
1c383dba 166// ----------------------------------------------------------------------------
8a0681f9 167// wxToolBarTool
1c383dba
VZ
168// ----------------------------------------------------------------------------
169
8a0681f9
VZ
170wxToolBarToolBase *wxToolBar::CreateTool(int id,
171 const wxBitmap& bitmap1,
172 const wxBitmap& bitmap2,
173 bool toggle,
174 wxObject *clientData,
175 const wxString& shortHelpString,
176 const wxString& longHelpString)
177{
178 return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
179 clientData, shortHelpString, longHelpString);
180}
181
182wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
183{
184 return new wxToolBarTool(this, control);
185}
186
187// ----------------------------------------------------------------------------
188// wxToolBar construction
189// ----------------------------------------------------------------------------
190
191void wxToolBar::Init()
2bda0e17 192{
1c383dba 193 m_hBitmap = 0;
8a0681f9
VZ
194
195 m_nButtons = 0;
196
1c383dba
VZ
197 m_defaultWidth = DEFAULTBITMAPX;
198 m_defaultHeight = DEFAULTBITMAPY;
37d0bdff
MB
199
200 m_pInTool = 0;
2bda0e17
KB
201}
202
8a0681f9
VZ
203bool wxToolBar::Create(wxWindow *parent,
204 wxWindowID id,
205 const wxPoint& pos,
206 const wxSize& size,
207 long style,
208 const wxString& name)
2bda0e17 209{
1c383dba 210 // common initialisation
11b6a93b 211 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
1c383dba 212 return FALSE;
89b892a2 213
1c383dba
VZ
214 // prepare flags
215 DWORD msflags = 0; // WS_VISIBLE | WS_CHILD always included
216 if (style & wxBORDER)
217 msflags |= WS_BORDER;
c25a510b 218
b0766406
JS
219 if ( style & wxCLIP_SIBLINGS )
220 msflags |= WS_CLIPSIBLINGS;
221
c25a510b 222#ifdef TBSTYLE_TOOLTIPS
1c383dba 223 msflags |= TBSTYLE_TOOLTIPS;
c25a510b 224#endif
2bda0e17 225
1c383dba
VZ
226 if (style & wxTB_FLAT)
227 {
228 if (wxTheApp->GetComCtl32Version() > 400)
c8f1f088 229 msflags |= TBSTYLE_FLAT;
1c383dba 230 }
2bda0e17 231
1c383dba
VZ
232 // MSW-specific initialisation
233 if ( !wxControl::MSWCreateControl(TOOLBARCLASSNAME, msflags) )
234 return FALSE;
2bda0e17 235
c8f1f088 236 // toolbar-specific post initialisation
1c383dba 237 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
89b892a2 238
c8f1f088
VZ
239 // set up the colors and fonts
240 wxRGBToColour(m_backgroundColour, GetSysColor(COLOR_BTNFACE));
241 m_foregroundColour = *wxBLACK;
242
243 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
244
1c383dba
VZ
245 // position it
246 int x = pos.x;
247 int y = pos.y;
248 int width = size.x;
249 int height = size.y;
2bda0e17 250
1c383dba
VZ
251 if (width <= 0)
252 width = 100;
253 if (height <= 0)
254 height = m_defaultHeight;
255 if (x < 0)
256 x = 0;
257 if (y < 0)
258 y = 0;
bb6290e3 259
1c383dba 260 SetSize(x, y, width, height);
2bda0e17 261
1c383dba 262 return TRUE;
2bda0e17
KB
263}
264
8a0681f9 265wxToolBar::~wxToolBar()
2bda0e17 266{
f6bcfd97
BP
267 // we must refresh the frame size when the toolbar is deleted but the frame
268 // is not - otherwise toolbar leaves a hole in the place it used to occupy
f6bcfd97 269 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
c2fd78b1 270 if ( frame && !frame->IsBeingDeleted() )
f6bcfd97
BP
271 {
272 frame->SendSizeEvent();
273 }
274
275 if ( m_hBitmap )
1c383dba
VZ
276 {
277 ::DeleteObject((HBITMAP) m_hBitmap);
278 }
279}
280
bdc72a22 281// ----------------------------------------------------------------------------
8a0681f9 282// adding/removing tools
bdc72a22
VZ
283// ----------------------------------------------------------------------------
284
8a0681f9
VZ
285bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
286 wxToolBarToolBase *tool)
1c383dba 287{
8a0681f9
VZ
288 // nothing special to do here - we really create the toolbar buttons in
289 // Realize() later
290 tool->Attach(this);
291
292 return TRUE;
1c383dba
VZ
293}
294
8a0681f9 295bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
bdc72a22 296{
f6bcfd97
BP
297 // the main difficulty we have here is with the controls in the toolbars:
298 // as we (sometimes) use several separators to cover up the space used by
299 // them, the indices are not the same for us and the toolbar
300
301 // first determine the position of the first button to delete: it may be
302 // different from pos if we use several separators to cover the space used
303 // by a control
304 wxToolBarToolsList::Node *node;
305 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
306 {
307 wxToolBarToolBase *tool2 = node->GetData();
308 if ( tool2 == tool )
309 {
310 // let node point to the next node in the list
311 node = node->GetNext();
312
313 break;
314 }
315
316 if ( tool2->IsControl() )
317 {
56bd6aac 318 pos += ((wxToolBarTool *)tool2)->GetSeparatorsCount() - 1;
f6bcfd97
BP
319 }
320 }
321
322 // now determine the number of buttons to delete and the area taken by them
8a0681f9 323 size_t nButtonsToDelete = 1;
bdc72a22 324
8a0681f9
VZ
325 // get the size of the button we're going to delete
326 RECT r;
327 if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) )
bdc72a22 328 {
8a0681f9 329 wxLogLastError(_T("TB_GETITEMRECT"));
bdc72a22
VZ
330 }
331
8a0681f9 332 int width = r.right - r.left;
bdc72a22 333
8a0681f9
VZ
334 if ( tool->IsControl() )
335 {
336 nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount();
bdc72a22 337
8a0681f9
VZ
338 width *= nButtonsToDelete;
339 }
bdc72a22 340
f6bcfd97
BP
341 // do delete all buttons
342 m_nButtons -= nButtonsToDelete;
8a0681f9
VZ
343 while ( nButtonsToDelete-- > 0 )
344 {
345 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) )
346 {
f6bcfd97 347 wxLogLastError(wxT("TB_DELETEBUTTON"));
1c383dba 348
8a0681f9
VZ
349 return FALSE;
350 }
351 }
1c383dba 352
8a0681f9 353 tool->Detach();
1c383dba 354
f6bcfd97
BP
355 // and finally reposition all the controls after this button (the toolbar
356 // takes care of all normal items)
357 for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
8a0681f9
VZ
358 {
359 wxToolBarToolBase *tool2 = node->GetData();
360 if ( tool2->IsControl() )
361 {
362 int x;
363 wxControl *control = tool2->GetControl();
364 control->GetPosition(&x, NULL);
365 control->Move(x - width, -1);
366 }
367 }
1c383dba
VZ
368
369 return TRUE;
370}
371
8a0681f9 372bool wxToolBar::Realize()
1c383dba 373{
8a0681f9
VZ
374 size_t nTools = GetToolsCount();
375 if ( nTools == 0 )
376 {
377 // nothing to do
378 return TRUE;
379 }
1c383dba 380
8a0681f9 381 bool isVertical = (GetWindowStyle() & wxTB_VERTICAL) != 0;
2bda0e17 382
8a0681f9
VZ
383 // First, add the bitmap: we use one bitmap for all toolbar buttons
384 // ----------------------------------------------------------------
2bda0e17 385
8a0681f9
VZ
386 // if we already have a bitmap, we'll replace the existing one - otherwise
387 // we'll install a new one
388 HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap;
89b892a2 389
1c383dba
VZ
390 int totalBitmapWidth = (int)(m_defaultWidth * nTools);
391 int totalBitmapHeight = (int)m_defaultHeight;
2bda0e17 392
f6bcfd97
BP
393 // Create a bitmap and copy all the tool bitmaps to it
394#if USE_BITMAP_MASKS
395 wxMemoryDC dcAllButtons;
396 wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
397 dcAllButtons.SelectObject(bitmap);
398 dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH);
399 dcAllButtons.Clear();
400
401 m_hBitmap = bitmap.GetHBITMAP();
402 HBITMAP hBitmap = (HBITMAP)m_hBitmap;
403#else // !USE_BITMAP_MASKS
8a0681f9
VZ
404 HBITMAP hBitmap = ::CreateCompatibleBitmap(ScreenHDC(),
405 totalBitmapWidth,
406 totalBitmapHeight);
407 if ( !hBitmap )
408 {
409 wxLogLastError(_T("CreateCompatibleBitmap"));
410
411 return FALSE;
412 }
413
414 m_hBitmap = (WXHBITMAP)hBitmap;
89b892a2 415
1c383dba 416 HDC memoryDC = ::CreateCompatibleDC(NULL);
8a0681f9 417 HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, hBitmap);
2bda0e17 418
1c383dba 419 HDC memoryDC2 = ::CreateCompatibleDC(NULL);
f6bcfd97 420#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
2bda0e17 421
1c383dba
VZ
422 // the button position
423 wxCoord x = 0;
2bda0e17 424
1c383dba 425 // the number of buttons (not separators)
8a0681f9 426 int nButtons = 0;
1c383dba 427
8a0681f9
VZ
428 wxToolBarToolsList::Node *node = m_tools.GetFirst();
429 while ( node )
051205e6 430 {
8a0681f9
VZ
431 wxToolBarToolBase *tool = node->GetData();
432 if ( tool->IsButton() )
1c383dba 433 {
f6bcfd97
BP
434 const wxBitmap& bmp = tool->GetBitmap1();
435 if ( bmp.Ok() )
1c383dba 436 {
f6bcfd97
BP
437#if USE_BITMAP_MASKS
438 // notice the last parameter: do use mask
439 dcAllButtons.DrawBitmap(tool->GetBitmap1(), x, 0, TRUE);
440#else // !USE_BITMAP_MASKS
441 HBITMAP hbmp = GetHbitmapOf(bmp);
1c383dba
VZ
442 HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
443 if ( !BitBlt(memoryDC, x, 0, m_defaultWidth, m_defaultHeight,
444 memoryDC2, 0, 0, SRCCOPY) )
445 {
f6bcfd97 446 wxLogLastError(wxT("BitBlt"));
1c383dba
VZ
447 }
448
449 ::SelectObject(memoryDC2, oldBitmap2);
f6bcfd97 450#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
1c383dba 451 }
8a0681f9
VZ
452 else
453 {
454 wxFAIL_MSG( _T("invalid tool button bitmap") );
455 }
456
457 // still inc width and number of buttons because otherwise the
458 // subsequent buttons will all be shifted which is rather confusing
459 // (and like this you'd see immediately which bitmap was bad)
460 x += m_defaultWidth;
461 nButtons++;
1c383dba 462 }
8a0681f9
VZ
463
464 node = node->GetNext();
051205e6 465 }
2bda0e17 466
f6bcfd97
BP
467#if USE_BITMAP_MASKS
468 dcAllButtons.SelectObject(wxNullBitmap);
469
470 // don't delete this HBITMAP!
471 bitmap.SetHBITMAP(0);
472#else // !USE_BITMAP_MASKS
1c383dba
VZ
473 ::SelectObject(memoryDC, oldBitmap);
474 ::DeleteDC(memoryDC);
475 ::DeleteDC(memoryDC2);
f6bcfd97 476#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
2bda0e17 477
1c383dba 478 // Map to system colours
5e68f8f3 479 MapBitmap((WXHBITMAP) hBitmap, totalBitmapWidth, totalBitmapHeight);
1c383dba 480
9f83044f
VZ
481 int bitmapId = 0;
482
483 bool addBitmap = TRUE;
484
1c383dba 485 if ( oldToolBarBitmap )
2bda0e17 486 {
9f83044f
VZ
487#ifdef TB_REPLACEBITMAP
488 if ( wxTheApp->GetComCtl32Version() >= 400 )
1c383dba 489 {
9f83044f
VZ
490 TBREPLACEBITMAP replaceBitmap;
491 replaceBitmap.hInstOld = NULL;
492 replaceBitmap.hInstNew = NULL;
493 replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
494 replaceBitmap.nIDNew = (UINT) hBitmap;
495 replaceBitmap.nButtons = nButtons;
496 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
497 0, (LPARAM) &replaceBitmap) )
498 {
499 wxFAIL_MSG(wxT("Could not replace the old bitmap"));
500 }
501
502 ::DeleteObject(oldToolBarBitmap);
503
504 // already done
505 addBitmap = FALSE;
1c383dba 506 }
9f83044f
VZ
507 else
508#endif // TB_REPLACEBITMAP
509 {
510 // we can't replace the old bitmap, so we will add another one
511 // (awfully inefficient, but what else to do?) and shift the bitmap
512 // indices accordingly
513 addBitmap = TRUE;
1c383dba 514
9f83044f
VZ
515 bitmapId = m_nButtons;
516 }
1c383dba
VZ
517
518 // Now delete all the buttons
8a0681f9 519 for ( size_t pos = 0; pos < m_nButtons; pos++ )
1c383dba 520 {
8a0681f9
VZ
521 if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
522 {
56bd6aac 523 wxLogDebug(wxT("TB_DELETEBUTTON failed"));
8a0681f9 524 }
1c383dba 525 }
9f83044f 526
2bda0e17 527 }
9f83044f
VZ
528
529 if ( addBitmap ) // no old bitmap or we can't replace it
051205e6 530 {
1c383dba
VZ
531 TBADDBITMAP addBitmap;
532 addBitmap.hInst = 0;
8a0681f9 533 addBitmap.nID = (UINT) hBitmap;
1c383dba 534 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
8a0681f9 535 (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
1c383dba
VZ
536 {
537 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
538 }
051205e6 539 }
2bda0e17 540
8a0681f9
VZ
541 // Next add the buttons and separators
542 // -----------------------------------
543
1c383dba 544 TBBUTTON *buttons = new TBBUTTON[nTools];
2bda0e17 545
8a0681f9 546 // this array will hold the indices of all controls in the toolbar
1c383dba
VZ
547 wxArrayInt controlIds;
548
549 int i = 0;
8a0681f9 550 for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
2bda0e17 551 {
8a0681f9
VZ
552 wxToolBarToolBase *tool = node->GetData();
553
554 // don't add separators to the vertical toolbar - looks ugly
555 if ( isVertical && tool->IsSeparator() )
556 continue;
557
1c383dba
VZ
558 TBBUTTON& button = buttons[i];
559
560 wxZeroMemory(button);
561
8a0681f9 562 switch ( tool->GetStyle() )
1c383dba
VZ
563 {
564 case wxTOOL_STYLE_CONTROL:
8a0681f9 565 button.idCommand = tool->GetId();
1c383dba
VZ
566 // fall through: create just a separator too
567
568 case wxTOOL_STYLE_SEPARATOR:
569 button.fsState = TBSTATE_ENABLED;
570 button.fsStyle = TBSTYLE_SEP;
571 break;
572
573 case wxTOOL_STYLE_BUTTON:
574 button.iBitmap = bitmapId;
8a0681f9 575 button.idCommand = tool->GetId();
1c383dba 576
8a0681f9 577 if ( tool->IsEnabled() )
1c383dba 578 button.fsState |= TBSTATE_ENABLED;
8a0681f9 579 if ( tool->IsToggled() )
1c383dba 580 button.fsState |= TBSTATE_CHECKED;
8a0681f9
VZ
581
582 button.fsStyle = tool->CanBeToggled() ? TBSTYLE_CHECK
583 : TBSTYLE_BUTTON;
1c383dba
VZ
584
585 bitmapId++;
586 break;
587 }
2bda0e17 588
1c383dba 589 i++;
2bda0e17 590 }
1c383dba
VZ
591
592 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
593 (WPARAM)i, (LPARAM)buttons) )
2bda0e17 594 {
f6bcfd97 595 wxLogLastError(wxT("TB_ADDBUTTONS"));
2bda0e17 596 }
89b892a2 597
1c383dba 598 delete [] buttons;
2bda0e17 599
8a0681f9
VZ
600 // Deal with the controls finally
601 // ------------------------------
602
1c383dba 603 // adjust the controls size to fit nicely in the toolbar
8a0681f9
VZ
604 size_t index = 0;
605 for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
1c383dba 606 {
8a0681f9
VZ
607 wxToolBarToolBase *tool = node->GetData();
608 if ( !tool->IsControl() )
609 continue;
610
1c383dba
VZ
611 wxControl *control = tool->GetControl();
612
613 wxSize size = control->GetSize();
614
bdc72a22
VZ
615 // the position of the leftmost controls corner
616 int left = -1;
617
8a0681f9
VZ
618 // note that we use TB_GETITEMRECT and not TB_GETRECT because the
619 // latter only appeared in v4.70 of comctl32.dll
620 RECT r;
621 if ( !SendMessage(GetHwnd(), TB_GETITEMRECT,
622 index, (LPARAM)(LPRECT)&r) )
623 {
f6bcfd97 624 wxLogLastError(wxT("TB_GETITEMRECT"));
8a0681f9
VZ
625 }
626
bdc72a22
VZ
627 // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
628 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
629 // available in headers, now check whether it is available now
630 // (during run-time)
631 if ( wxTheApp->GetComCtl32Version() >= 471 )
632 {
633 // set the (underlying) separators width to be that of the
634 // control
635 TBBUTTONINFO tbbi;
636 tbbi.cbSize = sizeof(tbbi);
637 tbbi.dwMask = TBIF_SIZE;
638 tbbi.cx = size.x;
639 if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
8a0681f9 640 tool->GetId(), (LPARAM)&tbbi) )
bdc72a22 641 {
8a0681f9 642 // the id is probably invalid?
f6bcfd97 643 wxLogLastError(wxT("TB_SETBUTTONINFO"));
bdc72a22 644 }
bdc72a22
VZ
645 }
646 else
647 #endif // comctl32.dll 4.71
648 // TB_SETBUTTONINFO unavailable
649 {
bdc72a22 650 // try adding several separators to fit the controls width
bdc72a22
VZ
651 int widthSep = r.right - r.left;
652 left = r.left;
653
654 TBBUTTON tbb;
655 wxZeroMemory(tbb);
656 tbb.idCommand = 0;
f6bcfd97 657 tbb.fsState = TBSTATE_ENABLED;
bdc72a22
VZ
658 tbb.fsStyle = TBSTYLE_SEP;
659
660 size_t nSeparators = size.x / widthSep;
661 for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
662 {
bdc72a22
VZ
663 if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
664 index, (LPARAM)&tbb) )
665 {
f6bcfd97 666 wxLogLastError(wxT("TB_INSERTBUTTON"));
bdc72a22 667 }
8a0681f9
VZ
668
669 index++;
bdc72a22
VZ
670 }
671
8a0681f9
VZ
672 // remember the number of separators we used - we'd have to
673 // delete all of them later
674 ((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
675
bdc72a22
VZ
676 // adjust the controls width to exactly cover the separators
677 control->SetSize((nSeparators + 1)*widthSep, -1);
678 }
1c383dba
VZ
679
680 // and position the control itself correctly vertically
1c383dba
VZ
681 int height = r.bottom - r.top;
682 int diff = height - size.y;
683 if ( diff < 0 )
684 {
685 // the control is too high, resize to fit
686 control->SetSize(-1, height - 2);
687
688 diff = 2;
689 }
2bda0e17 690
8a0681f9 691 control->Move(left == -1 ? r.left : left, r.top + (diff + 1) / 2);
1c383dba 692 }
89b892a2 693
8a0681f9
VZ
694 // the max index is the "real" number of buttons - i.e. counting even the
695 // separators which we added just for aligning the controls
696 m_nButtons = index;
89b892a2 697
8a0681f9
VZ
698 if ( !isVertical )
699 {
700 if ( m_maxRows == 0 )
701 {
702 // if not set yet, only one row
703 SetRows(1);
704 }
705 }
706 else if ( m_nButtons > 0 ) // vertical non empty toolbar
707 {
708 if ( m_maxRows == 0 )
709 {
710 // if not set yet, have one column
711 SetRows(m_nButtons);
712 }
713 }
2bda0e17 714
1c383dba 715 return TRUE;
2bda0e17
KB
716}
717
1c383dba
VZ
718// ----------------------------------------------------------------------------
719// message handlers
720// ----------------------------------------------------------------------------
721
33ac7e6f 722bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id)
2bda0e17 723{
8a0681f9
VZ
724 wxToolBarToolBase *tool = FindById((int)id);
725 if ( !tool )
1c383dba
VZ
726 return FALSE;
727
8a0681f9 728 if ( tool->CanBeToggled() )
1c383dba
VZ
729 {
730 LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
82dd98a7 731 tool->Toggle((state & TBSTATE_CHECKED) != 0);
1c383dba
VZ
732 }
733
8a0681f9
VZ
734 bool toggled = tool->IsToggled();
735
736 // OnLeftClick() can veto the button state change - for buttons which may
737 // be toggled only, of couse
738 if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() )
1c383dba 739 {
8a0681f9
VZ
740 // revert back
741 toggled = !toggled;
742 tool->SetToggle(toggled);
743
744 ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
1c383dba
VZ
745 }
746
747 return TRUE;
2bda0e17
KB
748}
749
8a0681f9 750bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
fd3f686c 751 WXLPARAM lParam,
33ac7e6f 752 WXLPARAM *WXUNUSED(result))
2bda0e17 753{
89b892a2 754 // First check if this applies to us
2bda0e17 755 NMHDR *hdr = (NMHDR *)lParam;
2bda0e17 756
1c383dba
VZ
757 // the tooltips control created by the toolbar is sometimes Unicode, even
758 // in an ANSI application - this seems to be a bug in comctl32.dll v5
a17e237f
VZ
759 int code = (int)hdr->code;
760 if ( (code != TTN_NEEDTEXTA) && (code != TTN_NEEDTEXTW) )
89b892a2 761 return FALSE;
2bda0e17 762
89b892a2
VZ
763 HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
764 if ( toolTipWnd != hdr->hwndFrom )
765 return FALSE;
2bda0e17 766
89b892a2
VZ
767 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
768 int id = (int)ttText->hdr.idFrom;
89b892a2 769
8a0681f9
VZ
770 wxToolBarToolBase *tool = FindById(id);
771 if ( !tool )
772 return FALSE;
2bda0e17 773
8a0681f9 774 const wxString& help = tool->GetShortHelp();
8df13671
VZ
775
776 if ( !help.IsEmpty() )
89b892a2 777 {
a17e237f 778 if ( code == TTN_NEEDTEXTA )
89b892a2 779 {
837e5743 780 ttText->lpszText = (wxChar *)help.c_str();
89b892a2 781 }
89b892a2
VZ
782 else
783 {
f6bcfd97
BP
784#if wxUSE_UNICODE
785 ttText->lpszText = (wxChar *)help.c_str();
786#else
0d910be7 787 // VZ: I don't know why it happens, but the versions of
56bd6aac 788 // comctl32.dll starting from 4.70 sometimes send TTN_NEEDTEXTW
0d910be7
VZ
789 // even to ANSI programs (normally, this message is supposed
790 // to be sent to Unicode programs only) - hence we need to
791 // handle it as well, otherwise no tooltips will be shown in
792 // this case
8df13671
VZ
793
794 size_t lenAnsi = help.Len();
b2cce0c4 795 #ifdef __MWERKS__
8df13671
VZ
796 // MetroWerks doesn't like calling mbstowcs with NULL argument
797 size_t lenUnicode = 2*lenAnsi;
b2cce0c4 798 #else
8df13671 799 size_t lenUnicode = mbstowcs(NULL, help, lenAnsi);
b2cce0c4 800 #endif
8df13671
VZ
801
802 // using the pointer of right type avoids us doing all sorts of
803 // pointer arithmetics ourselves
804 wchar_t *dst = (wchar_t *)ttText->szText,
805 *pwz = new wchar_t[lenUnicode + 1];
806 mbstowcs(pwz, help, lenAnsi + 1);
807 memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
808
809 // put the terminating _wide_ NUL
810 dst[lenUnicode] = 0;
89b892a2
VZ
811
812 delete [] pwz;
f6bcfd97 813#endif
89b892a2 814 }
2bda0e17 815 }
89b892a2 816
89b892a2 817 return TRUE;
2bda0e17
KB
818}
819
1c383dba 820// ----------------------------------------------------------------------------
8a0681f9 821// toolbar geometry
1c383dba
VZ
822// ----------------------------------------------------------------------------
823
8a0681f9 824void wxToolBar::SetToolBitmapSize(const wxSize& size)
2bda0e17 825{
1c383dba
VZ
826 wxToolBarBase::SetToolBitmapSize(size);
827
828 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
2bda0e17
KB
829}
830
8a0681f9 831void wxToolBar::SetRows(int nRows)
2bda0e17 832{
8a0681f9
VZ
833 if ( nRows == m_maxRows )
834 {
835 // avoid resizing the frame uselessly
836 return;
837 }
838
839 // TRUE in wParam means to create at least as many rows, FALSE -
840 // at most as many
1c383dba
VZ
841 RECT rect;
842 ::SendMessage(GetHwnd(), TB_SETROWS,
8a0681f9
VZ
843 MAKEWPARAM(nRows, !(GetWindowStyle() & wxTB_VERTICAL)),
844 (LPARAM) &rect);
1c383dba
VZ
845
846 m_maxRows = nRows;
8a0681f9
VZ
847
848 UpdateSize();
849}
850
851// The button size is bigger than the bitmap size
852wxSize wxToolBar::GetToolSize() const
853{
854 // TB_GETBUTTONSIZE is supported from version 4.70
5438a566
VZ
855#if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \
856 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
8a0681f9
VZ
857 if ( wxTheApp->GetComCtl32Version() >= 470 )
858 {
859 DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0);
860
861 return wxSize(LOWORD(dw), HIWORD(dw));
862 }
863 else
864#endif // comctl32.dll 4.70+
865 {
866 // defaults
867 return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
868 }
2bda0e17
KB
869}
870
82c9f85c
VZ
871static
872wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools,
873 size_t index )
a8945eef
MB
874{
875 wxToolBarToolsList::Node* current = tools.GetFirst();
876
82c9f85c 877 for ( ; current != 0; current = current->GetNext() )
a8945eef 878 {
82c9f85c 879 if ( index == 0 )
a8945eef 880 return current->GetData();
82c9f85c
VZ
881
882 wxToolBarTool *tool = (wxToolBarTool *)current->GetData();
883 size_t separators = tool->GetSeparatorsCount();
884
885 // if it is a normal button, sepcount == 0, so skip 1 item (the button)
886 // otherwise, skip as many items as the separator count, plus the
887 // control itself
888 index -= separators ? separators + 1 : 1;
a8945eef
MB
889 }
890
891 return 0;
892}
893
8a0681f9 894wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
2bda0e17 895{
8a0681f9
VZ
896 POINT pt;
897 pt.x = x;
898 pt.y = y;
899 int index = (int)::SendMessage(GetHwnd(), TB_HITTEST, 0, (LPARAM)&pt);
37d0bdff
MB
900 // MBN: when the point ( x, y ) is close to the toolbar border
901 // TB_HITTEST returns m_nButtons ( not -1 )
902 if ( index < 0 || (size_t)index >= m_nButtons )
1c383dba 903 {
8a0681f9
VZ
904 // it's a separator or there is no tool at all there
905 return (wxToolBarToolBase *)NULL;
1c383dba
VZ
906 }
907
82c9f85c 908 // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
a8945eef
MB
909#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
910 if ( wxTheApp->GetComCtl32Version() >= 471 )
911 {
912 return m_tools.Item((size_t)index)->GetData();
913 }
914 else
82c9f85c 915#endif
a8945eef
MB
916 {
917 return GetItemSkippingDummySpacers( m_tools, (size_t) index );
918 }
2bda0e17
KB
919}
920
8a0681f9 921void wxToolBar::UpdateSize()
2bda0e17 922{
0d7ea902
VZ
923 // the toolbar size changed
924 SendMessage(GetHwnd(), TB_AUTOSIZE, 0, 0);
925
926 // we must also refresh the frame after the toolbar size (possibly) changed
8a0681f9
VZ
927 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
928 if ( frame )
929 {
f6bcfd97 930 frame->SendSizeEvent();
8a0681f9 931 }
2bda0e17
KB
932}
933
1c383dba
VZ
934// ----------------------------------------------------------------------------
935// tool state
936// ----------------------------------------------------------------------------
937
8a0681f9 938void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
2bda0e17 939{
8a0681f9
VZ
940 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
941 (WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0));
2bda0e17
KB
942}
943
8a0681f9 944void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle)
2bda0e17 945{
8a0681f9
VZ
946 ::SendMessage(GetHwnd(), TB_CHECKBUTTON,
947 (WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0));
2bda0e17
KB
948}
949
33ac7e6f 950void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
088a95f5 951{
8a0681f9
VZ
952 // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
953 // without, so we really need to delete the button and recreate it here
954 wxFAIL_MSG( _T("not implemented") );
2bda0e17
KB
955}
956
1c383dba
VZ
957// ----------------------------------------------------------------------------
958// event handlers
959// ----------------------------------------------------------------------------
2bda0e17
KB
960
961// Responds to colour changes, and passes event on to children.
8a0681f9 962void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 963{
84c5b38d 964 wxRGBToColour(m_backgroundColour, ::GetSysColor(COLOR_BTNFACE));
2bda0e17
KB
965
966 // Remap the buttons
8a0681f9 967 Realize();
2bda0e17 968
56bd6aac
VZ
969 // Relayout the toolbar
970 int nrows = m_maxRows;
971 m_maxRows = 0; // otherwise SetRows() wouldn't do anything
972 SetRows(nrows);
973
2bda0e17
KB
974 Refresh();
975
56bd6aac
VZ
976 // let the event propagate further
977 event.Skip();
2bda0e17
KB
978}
979
8a0681f9 980void wxToolBar::OnMouseEvent(wxMouseEvent& event)
e6460682
JS
981{
982 if (event.RightDown())
983 {
984 // For now, we don't have an id. Later we could
985 // try finding the tool.
986 OnRightClick((int)-1, event.GetX(), event.GetY());
987 }
988 else
989 {
42e69d6b 990 event.Skip();
e6460682
JS
991 }
992}
993
8a0681f9 994long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
bdc72a22 995{
8a0681f9 996 if ( nMsg == WM_SIZE )
bdc72a22 997 {
8a0681f9
VZ
998 // calculate our minor dimenstion ourselves - we're confusing the
999 // standard logic (TB_AUTOSIZE) with our horizontal toolbars and other
1000 // hacks
1001 RECT r;
1002 if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) )
1003 {
1004 int w, h;
1005
1006 if ( GetWindowStyle() & wxTB_VERTICAL )
1007 {
1008 w = r.right - r.left;
1009 if ( m_maxRows )
1010 {
1011 w *= (m_nButtons + m_maxRows - 1)/m_maxRows;
1012 }
1013 h = HIWORD(lParam);
1014 }
1015 else
1016 {
1017 w = LOWORD(lParam);
1018 h = r.bottom - r.top;
1019 if ( m_maxRows )
1020 {
1021 h += 6; // FIXME: this is the separator line height...
1022 h *= m_maxRows;
1023 }
1024 }
1025
1026 if ( MAKELPARAM(w, h) != lParam )
1027 {
1028 // size really changed
1029 SetSize(w, h);
1030 }
1031
1032 // message processed
1033 return 0;
1034 }
bdc72a22 1035 }
a8945eef
MB
1036 else if ( nMsg == WM_MOUSEMOVE )
1037 {
1038 wxCoord x = GET_X_LPARAM(lParam), y = GET_Y_LPARAM(lParam);
1039 wxToolBarToolBase* tool = FindToolForPosition( x, y );
1040
1041 // cursor left current tool
1042 if( tool != m_pInTool && !tool )
1043 {
1044 m_pInTool = 0;
1045 OnMouseEnter( -1 );
1046 }
1047
1048 // cursor entered a tool
1049 if( tool != m_pInTool && tool )
1050 {
1051 m_pInTool = tool;
1052 OnMouseEnter( tool->GetId() );
1053 }
1054
1055 // we don't handle mouse moves, so fall through
1056 // to wxControl::MSWWindowProc
1057 }
bdc72a22 1058
8a0681f9 1059 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
bdc72a22
VZ
1060}
1061
1c383dba
VZ
1062// ----------------------------------------------------------------------------
1063// private functions
1064// ----------------------------------------------------------------------------
1065
5e68f8f3
JS
1066bool wxToolBar::sm_coloursInit = FALSE;
1067long wxToolBar::sm_stdColours[6];
2bda0e17 1068
5e68f8f3 1069void wxToolBar::MapBitmap(WXHBITMAP bitmap, int width, int height)
2bda0e17 1070{
5e68f8f3 1071 if (!sm_coloursInit)
2bda0e17 1072 {
5e68f8f3
JS
1073 // When a bitmap is loaded, the RGB values can change. So we need to have a
1074 // reference bitmap which can tell us what the RGB values change to.
1075 wxBitmap stdColourBitmap("wxBITMAP_STD_COLOURS", wxBITMAP_TYPE_RESOURCE);
1076 if (stdColourBitmap.Ok())
2bda0e17 1077 {
5e68f8f3
JS
1078 wxMemoryDC memDC;
1079 memDC.SelectObject(stdColourBitmap);
2bda0e17 1080
5e68f8f3
JS
1081 int i = 0;
1082 wxColour colour;
1083 for (i = 0; i < 6; i++)
1084 {
1085 memDC.GetPixel(i, 0, & colour);
1086 sm_stdColours[i] = RGB(colour.Red(), colour.Green(), colour.Blue());
1087 }
1088 sm_coloursInit = TRUE;
1089 memDC.SelectObject(wxNullBitmap);
1090 }
1091 else
1092 {
1093 sm_stdColours[0] = RGB(000,000,000) ;
1094 sm_stdColours[1] = RGB(128,128,128) ;
1095 sm_stdColours[2] = RGB(192,192,192) ;
1096 sm_stdColours[3] = RGB(255,255,255) ;
1097 sm_stdColours[4] = RGB(000,000,255) ;
1098 sm_stdColours[5] = RGB(255,000,255) ;
1099 sm_coloursInit = TRUE;
1100 }
1101 }
56bd6aac 1102
5e68f8f3 1103 HBITMAP hBitmap = (HBITMAP) bitmap;
56bd6aac 1104
5e68f8f3 1105 COLORMAP ColorMap[5];
56bd6aac 1106
5e68f8f3
JS
1107 ColorMap[0].from = sm_stdColours[0]; ColorMap[0].to = COLOR_BTNTEXT; // black (0, 0 0)
1108 ColorMap[1].from = sm_stdColours[1]; ColorMap[1].to = COLOR_BTNSHADOW; // dark grey (128, 128, 128)
1109 ColorMap[2].from = sm_stdColours[2]; ColorMap[2].to = COLOR_BTNFACE; // bright grey (192, 192, 192)
1110 ColorMap[3].from = sm_stdColours[3]; ColorMap[3].to = COLOR_BTNHIGHLIGHT; // white (255, 255, 255)
1111 // ColorMap[4].from = sm_stdColours[4]; ColorMap[4].to = COLOR_HIGHLIGHT; // blue (0, 0, 255)
1112 ColorMap[4].from = sm_stdColours[5]; ColorMap[4].to = COLOR_WINDOW; // magenta (255, 0, 255)
56bd6aac 1113
bf9b6266 1114 for ( size_t n = 0; n < WXSIZEOF(ColorMap); n++)
5e68f8f3
JS
1115 {
1116 ColorMap[n].to = ::GetSysColor(ColorMap[n].to);
1117 }
56bd6aac 1118
5e68f8f3
JS
1119 HBITMAP hbmOld;
1120 HDC hdcMem = CreateCompatibleDC(NULL);
56bd6aac 1121
5e68f8f3
JS
1122 if (hdcMem)
1123 {
1124 hbmOld = (HBITMAP) SelectObject(hdcMem, hBitmap);
56bd6aac 1125
84c5b38d 1126 for ( int i = 0; i < width; i++ )
5e68f8f3 1127 {
84c5b38d 1128 for ( int j = 0; j < height; j++ )
2bda0e17 1129 {
5e68f8f3 1130 COLORREF pixel = ::GetPixel(hdcMem, i, j);
56bd6aac 1131
bf9b6266 1132 for ( size_t k = 0; k < WXSIZEOF(ColorMap); k++ )
2bda0e17 1133 {
84c5b38d
VZ
1134 int distance = abs( GetRValue( pixel ) - GetRValue( ColorMap[k].from )) ;
1135 distance = max( distance , abs(GetGValue(pixel ) - GetGValue( ColorMap[k].from ))) ;
1136 distance = max( distance , abs(GetBValue(pixel ) - GetBValue( ColorMap[k].from ))) ;
1137 if ( distance < 0x10 )
5e68f8f3 1138 {
84c5b38d 1139 ::SetPixel(hdcMem, i, j, ColorMap[k].to);
5e68f8f3
JS
1140 break;
1141 }
2bda0e17
KB
1142 }
1143 }
1144 }
56bd6aac
VZ
1145
1146
5e68f8f3
JS
1147 SelectObject(hdcMem, hbmOld);
1148 DeleteObject(hdcMem);
2bda0e17 1149 }
2bda0e17
KB
1150}
1151
1152// Some experiments...
1153#if 0
5e68f8f3
JS
1154// What we want to do is create another bitmap which has a depth of 4,
1155// and set the bits. So probably we want to convert this HBITMAP into a
1156// DIB, then call SetDIBits.
1157// AAAGH. The stupid thing is that if newBitmap has a depth of 4 (less than that of
1158// the screen), then SetDIBits fails.
1159HBITMAP newBitmap = ::CreateBitmap(totalBitmapWidth, totalBitmapHeight, 1, 4, NULL);
1160HANDLE newDIB = ::BitmapToDIB((HBITMAP) m_hBitmap, NULL);
1161LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) GlobalLock(newDIB);
1162
1163dc = ::GetDC(NULL);
2bda0e17
KB
1164// LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) newDIB;
1165
5e68f8f3
JS
1166int result = ::SetDIBits(dc, newBitmap, 0, lpbmi->biHeight, FindDIBBits((LPSTR)lpbmi), (LPBITMAPINFO)lpbmi,
1167 DIB_PAL_COLORS);
1168DWORD err = GetLastError();
2bda0e17 1169
5e68f8f3 1170::ReleaseDC(NULL, dc);
2bda0e17 1171
5e68f8f3
JS
1172// Delete the DIB
1173GlobalUnlock (newDIB);
1174GlobalFree (newDIB);
2bda0e17
KB
1175
1176// WXHBITMAP hBitmap2 = wxCreateMappedBitmap((WXHINSTANCE) wxGetInstance(), (WXHBITMAP) m_hBitmap);
5e68f8f3
JS
1177// Substitute our new bitmap for the old one
1178::DeleteObject((HBITMAP) m_hBitmap);
1179m_hBitmap = (WXHBITMAP) newBitmap;
2bda0e17
KB
1180#endif
1181
1182
8a0681f9 1183#endif // wxUSE_TOOLBAR && Win95
33ac7e6f 1184