]> git.saurik.com Git - wxWidgets.git/blob - src/msw/tbar95.cpp
compilation fix
[wxWidgets.git] / src / msw / tbar95.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/tbar95.cpp
3 // Purpose: wxToolBar95
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "tbar95.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/log.h"
33 #include "wx/intl.h"
34 #include "wx/dynarray.h"
35 #endif
36
37 #if wxUSE_BUTTONBAR && wxUSE_TOOLBAR && defined(__WIN95__)
38
39 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
40 #include "malloc.h"
41 #endif
42
43 #include "wx/msw/private.h"
44
45 #ifndef __TWIN32__
46
47 #ifdef __GNUWIN32_OLD__
48 #include "wx/msw/gnuwin32/extra.h"
49 #else
50 #include <commctrl.h>
51 #endif
52
53 #endif // __TWIN32__
54
55 #include "wx/msw/dib.h"
56 #include "wx/tbar95.h"
57 #include "wx/app.h" // for GetComCtl32Version
58
59 // ----------------------------------------------------------------------------
60 // constants
61 // ----------------------------------------------------------------------------
62
63 // these standard constants are not always defined in compilers headers
64
65 // Styles
66 #ifndef TBSTYLE_FLAT
67 #define TBSTYLE_LIST 0x1000
68 #define TBSTYLE_FLAT 0x0800
69 #define TBSTYLE_TRANSPARENT 0x8000
70 #endif
71 // use TBSTYLE_TRANSPARENT if you use TBSTYLE_FLAT
72
73 // Messages
74 #ifndef TB_GETSTYLE
75 #define TB_GETSTYLE (WM_USER + 57)
76 #define TB_SETSTYLE (WM_USER + 56)
77 #endif
78
79 // these values correspond to those used by comctl32.dll
80 #define DEFAULTBITMAPX 16
81 #define DEFAULTBITMAPY 15
82 #define DEFAULTBUTTONX 24
83 #define DEFAULTBUTTONY 24
84 #define DEFAULTBARHEIGHT 27
85
86 // ----------------------------------------------------------------------------
87 // function prototypes
88 // ----------------------------------------------------------------------------
89
90 static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
91
92 // ----------------------------------------------------------------------------
93 // wxWin macros
94 // ----------------------------------------------------------------------------
95
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxToolBar95, wxToolBarBase)
98 #endif
99
100 BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)
101 EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent)
102 EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged)
103 END_EVENT_TABLE()
104
105 // ============================================================================
106 // implementation
107 // ============================================================================
108
109 // ----------------------------------------------------------------------------
110 // wxToolBar95 construction
111 // ----------------------------------------------------------------------------
112
113 void wxToolBar95::Init()
114 {
115 m_maxWidth = -1;
116 m_maxHeight = -1;
117 m_hBitmap = 0;
118 m_defaultWidth = DEFAULTBITMAPX;
119 m_defaultHeight = DEFAULTBITMAPY;
120 }
121
122 bool wxToolBar95::Create(wxWindow *parent,
123 wxWindowID id,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxString& name)
128 {
129 wxASSERT_MSG( (style & wxTB_VERTICAL) == 0,
130 wxT("Sorry, wxToolBar95 under Windows 95 only "
131 "supports horizontal orientation.") );
132
133 // common initialisation
134 if ( !CreateControl(parent, id, pos, size, style, name) )
135 return FALSE;
136
137 // prepare flags
138 DWORD msflags = 0; // WS_VISIBLE | WS_CHILD always included
139 if (style & wxBORDER)
140 msflags |= WS_BORDER;
141 msflags |= TBSTYLE_TOOLTIPS;
142
143 if (style & wxTB_FLAT)
144 {
145 if (wxTheApp->GetComCtl32Version() > 400)
146 msflags |= TBSTYLE_FLAT;
147 }
148
149 // MSW-specific initialisation
150 if ( !wxControl::MSWCreateControl(TOOLBARCLASSNAME, msflags) )
151 return FALSE;
152
153 // toolbar-specific post initialisation
154 ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
155
156 // set up the colors and fonts
157 wxRGBToColour(m_backgroundColour, GetSysColor(COLOR_BTNFACE));
158 m_foregroundColour = *wxBLACK;
159
160 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
161
162 // position it
163 int x = pos.x;
164 int y = pos.y;
165 int width = size.x;
166 int height = size.y;
167
168 if (width <= 0)
169 width = 100;
170 if (height <= 0)
171 height = m_defaultHeight;
172 if (x < 0)
173 x = 0;
174 if (y < 0)
175 y = 0;
176
177 SetSize(x, y, width, height);
178
179 return TRUE;
180 }
181
182 wxToolBar95::~wxToolBar95()
183 {
184 UnsubclassWin();
185
186 if (m_hBitmap)
187 {
188 ::DeleteObject((HBITMAP) m_hBitmap);
189 }
190 }
191
192 void wxToolBar95::ClearTools()
193 {
194 // TODO: Don't know how to reset the toolbar bitmap, as yet.
195 // But adding tools and calling CreateTools should probably
196 // recreate a buttonbar OK.
197 wxToolBarBase::ClearTools();
198 }
199
200 bool wxToolBar95::AddControl(wxControl *control)
201 {
202 wxCHECK_MSG( control, FALSE, _T("toolbar: can't insert NULL control") );
203
204 wxCHECK_MSG( control->GetParent() == this, FALSE,
205 _T("control must have toolbar as parent") );
206
207 wxToolBarTool *tool = new wxToolBarTool(control);
208
209 m_tools.Append(control->GetId(), tool);
210
211 return TRUE;
212 }
213
214 wxToolBarTool *wxToolBar95::AddTool(int index,
215 const wxBitmap& bitmap,
216 const wxBitmap& pushedBitmap,
217 bool toggle,
218 long xPos, long yPos,
219 wxObject *clientData,
220 const wxString& helpString1,
221 const wxString& helpString2)
222 {
223 wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap,
224 toggle, xPos, yPos,
225 helpString1, helpString2);
226 tool->m_clientData = clientData;
227
228 if (xPos > -1)
229 tool->m_x = xPos;
230 else
231 tool->m_x = m_xMargin;
232
233 if (yPos > -1)
234 tool->m_y = yPos;
235 else
236 tool->m_y = m_yMargin;
237
238 tool->SetSize(GetToolSize().x, GetToolSize().y);
239
240 m_tools.Append((long)index, tool);
241
242 return tool;
243 }
244
245 bool wxToolBar95::CreateTools()
246 {
247 size_t nTools = m_tools.GetCount();
248 if ( nTools == 0 )
249 return FALSE;
250
251 HBITMAP oldToolBarBitmap = (HBITMAP) m_hBitmap;
252
253 int totalBitmapWidth = (int)(m_defaultWidth * nTools);
254 int totalBitmapHeight = (int)m_defaultHeight;
255
256 // Create a bitmap for all the tool bitmaps
257 HDC dc = ::GetDC(NULL);
258 m_hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap(dc,
259 totalBitmapWidth,
260 totalBitmapHeight);
261 ::ReleaseDC(NULL, dc);
262
263 // Now blit all the tools onto this bitmap
264 HDC memoryDC = ::CreateCompatibleDC(NULL);
265 HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, (HBITMAP)m_hBitmap);
266
267 HDC memoryDC2 = ::CreateCompatibleDC(NULL);
268
269 // the button position
270 wxCoord x = 0;
271
272 // the number of buttons (not separators)
273 int noButtons = 0;
274
275 wxNode *node = m_tools.First();
276 while (node)
277 {
278 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
279 if ( tool->m_toolStyle == wxTOOL_STYLE_BUTTON && tool->m_bitmap1.Ok() )
280 {
281 HBITMAP hbmp = GetHbitmapOf(tool->m_bitmap1);
282 if ( hbmp )
283 {
284 HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
285 if ( !BitBlt(memoryDC, x, 0, m_defaultWidth, m_defaultHeight,
286 memoryDC2, 0, 0, SRCCOPY) )
287 {
288 wxLogLastError("BitBlt");
289 }
290
291 ::SelectObject(memoryDC2, oldBitmap2);
292
293 x += m_defaultWidth;
294 noButtons++;
295 }
296 }
297 node = node->Next();
298 }
299
300 ::SelectObject(memoryDC, oldBitmap);
301 ::DeleteDC(memoryDC);
302 ::DeleteDC(memoryDC2);
303
304 // Map to system colours
305 wxMapBitmap((HBITMAP) m_hBitmap, totalBitmapWidth, totalBitmapHeight);
306
307 if ( oldToolBarBitmap )
308 {
309 TBREPLACEBITMAP replaceBitmap;
310 replaceBitmap.hInstOld = NULL;
311 replaceBitmap.hInstNew = NULL;
312 replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
313 replaceBitmap.nIDNew = (UINT) (HBITMAP) m_hBitmap;
314 replaceBitmap.nButtons = noButtons;
315 if ( ::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
316 0, (LPARAM) &replaceBitmap) == -1 )
317 {
318 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
319 }
320
321 ::DeleteObject((HBITMAP) oldToolBarBitmap);
322
323 // Now delete all the buttons
324 int i = 0;
325 while ( TRUE )
326 {
327 // TODO: What about separators???? They don't have an id!
328 if ( ! ::SendMessage( GetHwnd(), TB_DELETEBUTTON, i, 0 ) )
329 break;
330 }
331 }
332 else
333 {
334 TBADDBITMAP addBitmap;
335 addBitmap.hInst = 0;
336 addBitmap.nID = (UINT)m_hBitmap;
337 if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
338 (WPARAM) noButtons, (LPARAM)&addBitmap) == -1 )
339 {
340 wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
341 }
342 }
343
344 // Now add the buttons.
345 TBBUTTON *buttons = new TBBUTTON[nTools];
346
347 // this array will holds the indices of all controls in the toolbar
348 wxArrayInt controlIds;
349
350 int i = 0;
351 int bitmapId = 0;
352
353 node = m_tools.First();
354 while (node)
355 {
356 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
357 TBBUTTON& button = buttons[i];
358
359 wxZeroMemory(button);
360
361 switch ( tool->m_toolStyle )
362 {
363 case wxTOOL_STYLE_CONTROL:
364 controlIds.Add(i);
365 button.idCommand = tool->m_index;
366 // fall through: create just a separator too
367
368 case wxTOOL_STYLE_SEPARATOR:
369 button.fsState = TBSTATE_ENABLED;
370 button.fsStyle = TBSTYLE_SEP;
371 break;
372
373 case wxTOOL_STYLE_BUTTON:
374 button.iBitmap = bitmapId;
375 button.idCommand = tool->m_index;
376
377 if (tool->m_enabled)
378 button.fsState |= TBSTATE_ENABLED;
379 if (tool->m_toggleState)
380 button.fsState |= TBSTATE_CHECKED;
381 button.fsStyle = tool->m_isToggle ? TBSTYLE_CHECK
382 : TBSTYLE_BUTTON;
383
384 bitmapId++;
385 break;
386 }
387
388 i++;
389 node = node->Next();
390 }
391
392 if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
393 (WPARAM)i, (LPARAM)buttons) )
394 {
395 wxLogLastError("TB_ADDBUTTONS");
396 }
397
398 delete [] buttons;
399
400 // adjust the controls size to fit nicely in the toolbar
401 size_t nControls = controlIds.GetCount();
402 for ( size_t nCtrl = 0; nCtrl < nControls; nCtrl++ )
403 {
404 wxToolBarTool *tool = (wxToolBarTool *)
405 m_tools.Nth(controlIds[nCtrl])->Data();
406 wxControl *control = tool->GetControl();
407
408 wxSize size = control->GetSize();
409
410 // set the (underlying) separators width to be that of the control
411 TBBUTTONINFO tbbi;
412 tbbi.cbSize = sizeof(tbbi);
413 tbbi.dwMask = TBIF_SIZE;
414 tbbi.cx = size.x;
415 if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
416 tool->m_index, (LPARAM)&tbbi) )
417 {
418 // the index is probably invalid
419 wxLogLastError("TB_SETBUTTONINFO");
420 }
421
422 // and position the control itself correctly vertically
423 RECT r;
424 if ( !SendMessage(GetHwnd(), TB_GETRECT,
425 tool->m_index, (LPARAM)(LPRECT)&r) )
426 {
427 wxLogLastError("TB_GETRECT");
428 }
429
430 int height = r.bottom - r.top;
431 int diff = height - size.y;
432 if ( diff < 0 )
433 {
434 // the control is too high, resize to fit
435 control->SetSize(-1, height - 2);
436
437 diff = 2;
438 }
439
440 control->Move(r.left, r.top + diff / 2);
441 }
442
443 (void)::SendMessage(GetHwnd(), TB_AUTOSIZE, (WPARAM)0, (LPARAM) 0);
444
445 SetRows(m_maxRows);
446
447 return TRUE;
448 }
449
450 // ----------------------------------------------------------------------------
451 // message handlers
452 // ----------------------------------------------------------------------------
453
454 bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id)
455 {
456 wxNode *node = m_tools.Find((long)id);
457 if (!node)
458 return FALSE;
459
460 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
461 if (tool->m_isToggle)
462 {
463 LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
464 tool->m_toggleState = state & TBSTATE_CHECKED;
465 }
466
467 BOOL ret = OnLeftClick((int)id, tool->m_toggleState);
468 if ( ret == FALSE && tool->m_isToggle )
469 {
470 tool->m_toggleState = !tool->m_toggleState;
471 ::SendMessage(GetHwnd(), TB_CHECKBUTTON,
472 (WPARAM)id, (LPARAM)MAKELONG(tool->m_toggleState, 0));
473 }
474
475 return TRUE;
476 }
477
478 bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
479 WXLPARAM lParam,
480 WXLPARAM *result)
481 {
482 // First check if this applies to us
483 NMHDR *hdr = (NMHDR *)lParam;
484
485 // the tooltips control created by the toolbar is sometimes Unicode, even
486 // in an ANSI application - this seems to be a bug in comctl32.dll v5
487 int code = (int)hdr->code;
488 if ( (code != TTN_NEEDTEXTA) && (code != TTN_NEEDTEXTW) )
489 return FALSE;
490
491 HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
492 if ( toolTipWnd != hdr->hwndFrom )
493 return FALSE;
494
495 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
496 int id = (int)ttText->hdr.idFrom;
497 wxNode *node = m_tools.Find((long)id);
498 if (!node)
499 return FALSE;
500
501 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
502
503 const wxString& help = tool->m_shortHelpString;
504
505 if ( !help.IsEmpty() )
506 {
507 if ( code == TTN_NEEDTEXTA )
508 {
509 ttText->lpszText = (wxChar *)help.c_str();
510 }
511 #if (_WIN32_IE >= 0x0300)
512 else
513 {
514 // FIXME this is a temp hack only until I understand better what
515 // must be done in both ANSI and Unicode builds
516
517 size_t lenAnsi = help.Len();
518 #ifdef __MWERKS__
519 // MetroWerks doesn't like calling mbstowcs with NULL argument
520 size_t lenUnicode = 2*lenAnsi;
521 #else
522 size_t lenUnicode = mbstowcs(NULL, help, lenAnsi);
523 #endif
524
525 // using the pointer of right type avoids us doing all sorts of
526 // pointer arithmetics ourselves
527 wchar_t *dst = (wchar_t *)ttText->szText,
528 *pwz = new wchar_t[lenUnicode + 1];
529 mbstowcs(pwz, help, lenAnsi + 1);
530 memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
531
532 // put the terminating _wide_ NUL
533 dst[lenUnicode] = 0;
534
535 delete [] pwz;
536 }
537 #endif // _WIN32_IE >= 0x0300
538 }
539
540 // For backward compatibility...
541 OnMouseEnter(tool->m_index);
542
543 return TRUE;
544 }
545
546 // ----------------------------------------------------------------------------
547 // sizing stuff
548 // ----------------------------------------------------------------------------
549
550 void wxToolBar95::SetToolBitmapSize(const wxSize& size)
551 {
552 wxToolBarBase::SetToolBitmapSize(size);
553
554 ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
555 }
556
557 void wxToolBar95::SetRows(int nRows)
558 {
559 // TRUE in wParam means to create at least as many rows
560 RECT rect;
561 ::SendMessage(GetHwnd(), TB_SETROWS,
562 MAKEWPARAM(nRows, TRUE), (LPARAM) &rect);
563
564 m_maxWidth = (rect.right - rect.left + 2);
565 m_maxHeight = (rect.bottom - rect.top + 2);
566
567 m_maxRows = nRows;
568 }
569
570 wxSize wxToolBar95::GetMaxSize() const
571 {
572 if ( (m_maxWidth == -1) || (m_maxHeight == -1) )
573 {
574 // it has a side effect of filling m_maxWidth/Height variables
575 ((wxToolBar95 *)this)->SetRows(m_maxRows); // const_cast
576 }
577
578 return wxSize(m_maxWidth, m_maxHeight);
579 }
580
581 // The button size is bigger than the bitmap size
582 wxSize wxToolBar95::GetToolSize() const
583 {
584 // FIXME: this is completely bogus (VZ)
585 return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
586 }
587
588 // ----------------------------------------------------------------------------
589 // tool state
590 // ----------------------------------------------------------------------------
591
592 void wxToolBar95::EnableTool(int toolIndex, bool enable)
593 {
594 wxNode *node = m_tools.Find((long)toolIndex);
595 if (node)
596 {
597 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
598 tool->m_enabled = enable;
599 ::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
600 (WPARAM)toolIndex, (LPARAM)MAKELONG(enable, 0));
601 }
602 }
603
604 void wxToolBar95::ToggleTool(int toolIndex, bool toggle)
605 {
606 wxNode *node = m_tools.Find((long)toolIndex);
607 if (node)
608 {
609 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
610 if (tool->m_isToggle)
611 {
612 tool->m_toggleState = toggle;
613 ::SendMessage(GetHwnd(), TB_CHECKBUTTON,
614 (WPARAM)toolIndex, (LPARAM)MAKELONG(toggle, 0));
615 }
616 }
617 }
618
619 bool wxToolBar95::GetToolState(int toolIndex) const
620 {
621 return (::SendMessage(GetHwnd(), TB_ISBUTTONCHECKED, (WPARAM)toolIndex, (LPARAM)0) != 0);
622 }
623
624 // ----------------------------------------------------------------------------
625 // event handlers
626 // ----------------------------------------------------------------------------
627
628 // Responds to colour changes, and passes event on to children.
629 void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event)
630 {
631 m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
632 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
633
634 // Remap the buttons
635 CreateTools();
636
637 Refresh();
638
639 // Propagate the event to the non-top-level children
640 wxWindow::OnSysColourChanged(event);
641 }
642
643 void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
644 {
645 if (event.RightDown())
646 {
647 // For now, we don't have an id. Later we could
648 // try finding the tool.
649 OnRightClick((int)-1, event.GetX(), event.GetY());
650 }
651 else
652 {
653 event.Skip();
654 }
655 }
656
657 // ----------------------------------------------------------------------------
658 // private functions
659 // ----------------------------------------------------------------------------
660
661 // These are the default colors used to map the bitmap colors
662 // to the current system colors
663
664 // VZ: why are they BGR and not RGB? just to confuse the people or is there a
665 // deeper reason?
666 #define BGR_BUTTONTEXT (RGB(000,000,000)) // black
667 #define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
668 #define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
669 #define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
670 #define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
671 #define BGR_BACKGROUND (RGB(255,000,255)) // magenta
672
673 void wxMapBitmap(HBITMAP hBitmap, int width, int height)
674 {
675 COLORMAP ColorMap[] =
676 {
677 {BGR_BUTTONTEXT, COLOR_BTNTEXT}, // black
678 {BGR_BUTTONSHADOW, COLOR_BTNSHADOW}, // dark grey
679 {BGR_BUTTONFACE, COLOR_BTNFACE}, // bright grey
680 {BGR_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT},// white
681 {BGR_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue
682 {BGR_BACKGROUND, COLOR_WINDOW} // magenta
683 };
684
685 int NUM_MAPS = (sizeof(ColorMap)/sizeof(COLORMAP));
686 int n;
687 for ( n = 0; n < NUM_MAPS; n++)
688 {
689 ColorMap[n].to = ::GetSysColor(ColorMap[n].to);
690 }
691
692 HBITMAP hbmOld;
693 HDC hdcMem = CreateCompatibleDC(NULL);
694
695 if (hdcMem)
696 {
697 hbmOld = (HBITMAP) SelectObject(hdcMem, hBitmap);
698
699 int i, j, k;
700 for ( i = 0; i < width; i++)
701 {
702 for ( j = 0; j < height; j++)
703 {
704 COLORREF pixel = ::GetPixel(hdcMem, i, j);
705 /*
706 BYTE red = GetRValue(pixel);
707 BYTE green = GetGValue(pixel);
708 BYTE blue = GetBValue(pixel);
709 */
710
711 for ( k = 0; k < NUM_MAPS; k ++)
712 {
713 if ( ColorMap[k].from == pixel )
714 {
715 /* COLORREF actualPixel = */ ::SetPixel(hdcMem, i, j, ColorMap[k].to);
716 break;
717 }
718 }
719 }
720 }
721
722
723 SelectObject(hdcMem, hbmOld);
724 DeleteObject(hdcMem);
725 }
726
727 }
728
729 // Some experiments...
730 #if 0
731 // What we want to do is create another bitmap which has a depth of 4,
732 // and set the bits. So probably we want to convert this HBITMAP into a
733 // DIB, then call SetDIBits.
734 // AAAGH. The stupid thing is that if newBitmap has a depth of 4 (less than that of
735 // the screen), then SetDIBits fails.
736 HBITMAP newBitmap = ::CreateBitmap(totalBitmapWidth, totalBitmapHeight, 1, 4, NULL);
737 HANDLE newDIB = ::BitmapToDIB((HBITMAP) m_hBitmap, NULL);
738 LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) GlobalLock(newDIB);
739
740 dc = ::GetDC(NULL);
741 // LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) newDIB;
742
743 int result = ::SetDIBits(dc, newBitmap, 0, lpbmi->biHeight, FindDIBBits((LPSTR)lpbmi), (LPBITMAPINFO)lpbmi,
744 DIB_PAL_COLORS);
745 DWORD err = GetLastError();
746
747 ::ReleaseDC(NULL, dc);
748
749 // Delete the DIB
750 GlobalUnlock (newDIB);
751 GlobalFree (newDIB);
752
753 // WXHBITMAP hBitmap2 = wxCreateMappedBitmap((WXHINSTANCE) wxGetInstance(), (WXHBITMAP) m_hBitmap);
754 // Substitute our new bitmap for the old one
755 ::DeleteObject((HBITMAP) m_hBitmap);
756 m_hBitmap = (WXHBITMAP) newBitmap;
757 #endif
758
759
760 #endif // !(wxUSE_TOOLBAR && Win95)