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