]> git.saurik.com Git - wxWidgets.git/blame - src/msw/tbar95.cpp
Unicodified wxSplitPath
[wxWidgets.git] / src / msw / tbar95.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
89b892a2 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "tbar95.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
2432b92d 24#include "wx/wx.h"
2bda0e17
KB
25#endif
26
47d67540 27#if wxUSE_BUTTONBAR && wxUSE_TOOLBAR && defined(__WIN95__)
2bda0e17 28
ce3ed50d 29#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
2bda0e17
KB
30#include "malloc.h"
31#endif
32
33#include <windows.h>
34
57c208c5 35#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
2bda0e17
KB
36#include <commctrl.h>
37#endif
38
57c208c5 39#ifndef __TWIN32__
2bda0e17
KB
40#ifdef __GNUWIN32__
41#include "wx/msw/gnuwin32/extra.h"
42#endif
57c208c5 43#endif
2bda0e17
KB
44
45#include "wx/msw/dib.h"
46#include "wx/tbar95.h"
47#include "wx/app.h"
48#include "wx/msw/private.h"
49
6a23cbce 50// Styles
bb6290e3
JS
51#ifndef TBSTYLE_FLAT
52#define TBSTYLE_LIST 0x1000
53#define TBSTYLE_FLAT 0x0800
54#define TBSTYLE_TRANSPARENT 0x8000
55#endif
56 // use TBSTYLE_TRANSPARENT if you use TBSTYLE_FLAT
57
6a23cbce
JS
58// Messages
59#ifndef TB_GETSTYLE
60#define TB_GETSTYLE (WM_USER + 57)
61#define TB_SETSTYLE (WM_USER + 56)
62#endif
63
64/* Hint from a newsgroup for custom flatbar drawing:
65Set the TBSTYLE_CUSTOMERASE style, then handle the
66NM_CUSTOMDRAW message and do your custom drawing.
67*/
68
81d66cf3
JS
69#define DEFAULTBITMAPX 16
70#define DEFAULTBITMAPY 15
71#define DEFAULTBUTTONX 24
72#define DEFAULTBUTTONY 24
73#define DEFAULTBARHEIGHT 27
74
2bda0e17
KB
75#if !USE_SHARED_LIBRARY
76IMPLEMENT_DYNAMIC_CLASS(wxToolBar95, wxToolBarBase)
89b892a2 77#endif
2bda0e17
KB
78
79BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)
601d9e60
JS
80 EVT_SIZE(wxToolBar95::OnSize)
81 EVT_PAINT(wxToolBar95::OnPaint)
89b892a2 82 EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent)
601d9e60 83 EVT_KILL_FOCUS(wxToolBar95::OnKillFocus)
2bda0e17
KB
84 EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged)
85END_EVENT_TABLE()
2bda0e17 86
89b892a2 87static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
2bda0e17 88
89b892a2 89wxToolBar95::wxToolBar95()
2bda0e17 90{
2bda0e17
KB
91 m_maxWidth = -1;
92 m_maxHeight = -1;
93 m_hBitmap = 0;
94 m_defaultWidth = DEFAULTBITMAPX;
95 m_defaultHeight = DEFAULTBITMAPY;
96}
97
89b892a2
VZ
98bool wxToolBar95::Create(wxWindow *parent,
99 wxWindowID id,
100 const wxPoint& pos,
101 const wxSize& size,
102 long style,
103 const wxString& name)
2bda0e17
KB
104{
105 m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
89b892a2
VZ
106 GetGValue(GetSysColor(COLOR_BTNFACE)),
107 GetBValue(GetSysColor(COLOR_BTNFACE)));
2bda0e17
KB
108 m_foregroundColour = *wxBLACK ;
109
89b892a2
VZ
110 wxASSERT_MSG( (style & wxTB_VERTICAL) == 0,
111 "Sorry, wxToolBar95 under Windows 95 only "
112 "supports horizontal orientation." );
113
2bda0e17
KB
114 m_maxWidth = -1;
115 m_maxHeight = -1;
89b892a2 116
2bda0e17
KB
117 m_hBitmap = 0;
118
119 m_defaultWidth = DEFAULTBITMAPX;
120 m_defaultHeight = DEFAULTBITMAPY;
121 SetName(name);
122
2bda0e17
KB
123 m_windowStyle = style;
124
1c089c47 125 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17
KB
126 SetParent(parent);
127
89b892a2
VZ
128 int x = pos.x;
129 int y = pos.y;
130 int width = size.x;
131 int height = size.y;
132
2bda0e17
KB
133 if (width <= 0)
134 width = 100;
135 if (height <= 0)
136 height = 30;
137 if (x < 0)
138 x = 0;
139 if (y < 0)
140 y = 0;
141
142 m_windowId = (id < 0 ? NewControlId() : id);
89b892a2
VZ
143 DWORD msflags = 0;
144 if (style & wxBORDER)
145 msflags |= WS_BORDER;
146 msflags |= WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS;
bb6290e3
JS
147
148 if (style & wxTB_FLAT)
149 {
150 if (wxTheApp->GetComCtl32Version() > 400)
89b892a2 151 msflags |= TBSTYLE_FLAT;
bb6290e3 152 }
2bda0e17 153
2a47d3c1
JS
154 bool want3D;
155 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
156
157 // Even with extended styles, need to combine with WS_BORDER
158 // for them to look right.
159 if ( want3D || wxStyleHasBorder(m_windowStyle) )
160 msflags |= WS_BORDER;
161
2bda0e17 162 // Create the toolbar control.
89b892a2
VZ
163 HWND hWndToolbar = CreateWindowEx
164 (
2a47d3c1 165 exStyle, // Extended styles.
89b892a2
VZ
166 TOOLBARCLASSNAME, // Class name for the toolbar.
167 "", // No default text.
168 msflags, // Styles
169 x, y, width, height, // Standard toolbar size and position.
170 (HWND) parent->GetHWND(), // Parent window of the toolbar.
171 (HMENU)m_windowId, // Toolbar ID.
172 wxGetInstance(), // Current instance.
173 NULL // No class data.
174 );
175
176 wxCHECK_MSG( hWndToolbar, FALSE, "Toolbar creation failed" );
2bda0e17
KB
177
178 // Toolbar-specific initialisation
89b892a2
VZ
179 ::SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE,
180 (WPARAM)sizeof(TBBUTTON), (LPARAM)0);
2bda0e17
KB
181
182 m_hWnd = (WXHWND) hWndToolbar;
89b892a2
VZ
183 if (parent)
184 parent->AddChild(this);
185
186 SubclassWin((WXHWND)hWndToolbar);
2bda0e17
KB
187
188 return TRUE;
189}
190
89b892a2 191wxToolBar95::~wxToolBar95()
2bda0e17
KB
192{
193 UnsubclassWin();
194
195 if (m_hBitmap)
196 {
197 ::DeleteObject((HBITMAP) m_hBitmap);
198 m_hBitmap = 0;
199 }
200}
201
89b892a2 202bool wxToolBar95::CreateTools()
2bda0e17
KB
203{
204 if (m_tools.Number() == 0)
205 return FALSE;
206
207 HBITMAP oldToolBarBitmap = (HBITMAP) m_hBitmap;
89b892a2 208
2bda0e17
KB
209 int totalBitmapWidth = (int)(m_defaultWidth * m_tools.Number());
210 int totalBitmapHeight = (int)m_defaultHeight;
211
212 // Create a bitmap for all the tool bitmaps
213 HDC dc = ::GetDC(NULL);
214 m_hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap(dc, totalBitmapWidth, totalBitmapHeight);
215 ::ReleaseDC(NULL, dc);
89b892a2 216
2bda0e17
KB
217 // Now blit all the tools onto this bitmap
218 HDC memoryDC = ::CreateCompatibleDC(NULL);
c4e7c2aa 219 HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, (HBITMAP) m_hBitmap);
2bda0e17
KB
220
221 HDC memoryDC2 = ::CreateCompatibleDC(NULL);
222 int x = 0;
223 wxNode *node = m_tools.First();
224 int noButtons = 0;
225 while (node)
226 {
227 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
228 if ((tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR) && tool->m_bitmap1.Ok() && tool->m_bitmap1.GetHBITMAP())
229 {
230// wxPalette *palette = tool->m_bitmap1->GetPalette();
231
c4e7c2aa 232 HBITMAP oldBitmap2 = (HBITMAP) ::SelectObject(memoryDC2, (HBITMAP) tool->m_bitmap1.GetHBITMAP());
2bda0e17 233 /* int bltResult = */
89b892a2 234 BitBlt(memoryDC, x, 0, (int) m_defaultWidth, (int) m_defaultHeight, memoryDC2,
2bda0e17
KB
235 0, 0, SRCCOPY);
236 ::SelectObject(memoryDC2, oldBitmap2);
237 x += (int)m_defaultWidth;
238 noButtons ++;
239 }
240 node = node->Next();
241 }
242 ::SelectObject(memoryDC, oldBitmap);
243 ::DeleteDC(memoryDC);
244 ::DeleteDC(memoryDC2);
245
246 // Map to system colours
247 wxMapBitmap((HBITMAP) m_hBitmap, totalBitmapWidth, totalBitmapHeight);
248
249 if ( oldToolBarBitmap )
250 {
251 TBREPLACEBITMAP replaceBitmap;
252 replaceBitmap.hInstOld = NULL;
253 replaceBitmap.hInstNew = NULL;
254 replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
255 replaceBitmap.nIDNew = (UINT) (HBITMAP) m_hBitmap;
256 replaceBitmap.nButtons = noButtons;
257 if (::SendMessage((HWND) GetHWND(), TB_REPLACEBITMAP, (WPARAM) 0, (LPARAM) &replaceBitmap) == -1)
8df13671 258 wxFAIL_MSG("Could not add bitmap to toolbar");
2bda0e17
KB
259
260 ::DeleteObject((HBITMAP) oldToolBarBitmap);
261
262 // Now delete all the buttons
263 int i = 0;
264 while ( TRUE )
265 {
266 // TODO: What about separators???? They don't have an id!
267 if ( ! ::SendMessage( (HWND) GetHWND(), TB_DELETEBUTTON, i, 0 ) )
268 break;
269 }
270 }
271 else
272 {
273 TBADDBITMAP addBitmap;
274 addBitmap.hInst = 0;
275 addBitmap.nID = (UINT)m_hBitmap;
276 if (::SendMessage((HWND) GetHWND(), TB_ADDBITMAP, (WPARAM) noButtons, (LPARAM) &addBitmap) == -1)
8df13671 277 wxFAIL_MSG("Could not add bitmap to toolbar");
2bda0e17
KB
278 }
279
280 // Now add the buttons.
281 TBBUTTON buttons[50];
282
283 node = m_tools.First();
284 int i = 0;
285 int bitmapId = 0;
286 while (node)
287 {
288 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
289 if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR)
290 {
291 buttons[i].iBitmap = 0;
292 buttons[i].idCommand = 0;
293
294 buttons[i].fsState = TBSTATE_ENABLED;
295 buttons[i].fsStyle = TBSTYLE_SEP;
296 buttons[i].dwData = 0L;
297 buttons[i].iString = 0;
298 }
299 else
300 {
301 buttons[i].iBitmap = bitmapId;
302 buttons[i].idCommand = tool->m_index;
303
304 buttons[i].fsState = 0;
305 if (tool->m_enabled)
306 buttons[i].fsState |= TBSTATE_ENABLED;
307 if (tool->m_toggleState)
308 buttons[i].fsState |= TBSTATE_CHECKED;
309 buttons[i].fsStyle = tool->m_isToggle ? TBSTYLE_CHECK : TBSTYLE_BUTTON;
310 buttons[i].dwData = 0L;
311 buttons[i].iString = 0;
312
313 bitmapId ++;
314 }
89b892a2 315
2bda0e17
KB
316 i ++;
317 node = node->Next();
318 }
319
89b892a2 320 long rc = ::SendMessage((HWND) GetHWND(), TB_ADDBUTTONS, (WPARAM)i, (LPARAM)& buttons);
2bda0e17 321
89b892a2
VZ
322 wxCHECK_MSG( rc, FALSE, "failed to add buttons to the toolbar" );
323
324 (void)::SendMessage((HWND) GetHWND(), TB_AUTOSIZE, (WPARAM)0, (LPARAM) 0);
325
326 SetRows(m_maxRows);
2bda0e17
KB
327
328 return TRUE;
329}
330
debe6624 331bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id)
2bda0e17
KB
332{
333 wxNode *node = m_tools.Find((long)id);
334 if (!node)
335 return FALSE;
336 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
337 if (tool->m_isToggle)
338 tool->m_toggleState = (1 == (1 & (int)::SendMessage((HWND) GetHWND(), TB_GETSTATE, (WPARAM) id, (LPARAM) 0)));
339
340 BOOL ret = OnLeftClick((int)id, tool->m_toggleState);
341 if (ret == FALSE && tool->m_isToggle)
342 {
343 tool->m_toggleState = !tool->m_toggleState;
344 ::SendMessage((HWND) GetHWND(), TB_CHECKBUTTON, (WPARAM)id, (LPARAM)MAKELONG(tool->m_toggleState, 0));
345 }
346 return TRUE;
347}
348
fd3f686c
VZ
349bool wxToolBar95::MSWNotify(WXWPARAM WXUNUSED(wParam),
350 WXLPARAM lParam,
351 WXLPARAM *result)
2bda0e17 352{
89b892a2 353 // First check if this applies to us
2bda0e17 354 NMHDR *hdr = (NMHDR *)lParam;
2bda0e17 355
89b892a2
VZ
356 // the tooltips control created by the toolbar is sometimes Unicode, even in
357 // an ANSI application
358 if ( (hdr->code != TTN_NEEDTEXTA) && (hdr->code != TTN_NEEDTEXTW) )
359 return FALSE;
2bda0e17 360
89b892a2
VZ
361 HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0);
362 if ( toolTipWnd != hdr->hwndFrom )
363 return FALSE;
2bda0e17 364
89b892a2
VZ
365 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
366 int id = (int)ttText->hdr.idFrom;
367 wxNode *node = m_tools.Find((long)id);
368 if (!node)
369 return FALSE;
370
371 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
2bda0e17 372
8df13671
VZ
373 const wxString& help = tool->m_shortHelpString;
374
375 if ( !help.IsEmpty() )
89b892a2
VZ
376 {
377 if ( hdr->code == TTN_NEEDTEXTA )
378 {
8df13671 379 ttText->lpszText = (char *)help.c_str();
89b892a2
VZ
380 }
381#if (_WIN32_IE >= 0x0300)
382 else
383 {
384 // FIXME this is a temp hack only until I understand better what
385 // must be done in both ANSI and Unicode builds
8df13671
VZ
386
387 size_t lenAnsi = help.Len();
b2cce0c4 388 #ifdef __MWERKS__
8df13671
VZ
389 // MetroWerks doesn't like calling mbstowcs with NULL argument
390 size_t lenUnicode = 2*lenAnsi;
b2cce0c4 391 #else
8df13671 392 size_t lenUnicode = mbstowcs(NULL, help, lenAnsi);
b2cce0c4 393 #endif
8df13671
VZ
394
395 // using the pointer of right type avoids us doing all sorts of
396 // pointer arithmetics ourselves
397 wchar_t *dst = (wchar_t *)ttText->szText,
398 *pwz = new wchar_t[lenUnicode + 1];
399 mbstowcs(pwz, help, lenAnsi + 1);
400 memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
401
402 // put the terminating _wide_ NUL
403 dst[lenUnicode] = 0;
89b892a2
VZ
404
405 delete [] pwz;
406 }
407#endif // _WIN32_IE >= 0x0300
2bda0e17 408 }
89b892a2
VZ
409
410 // For backward compatibility...
411 OnMouseEnter(tool->m_index);
412
413 return TRUE;
2bda0e17
KB
414}
415
81d66cf3 416void wxToolBar95::SetToolBitmapSize(const wxSize& size)
2bda0e17 417{
89b892a2
VZ
418 m_defaultWidth = size.x;
419 m_defaultHeight = size.y;
2bda0e17
KB
420 ::SendMessage((HWND) GetHWND(), TB_SETBITMAPSIZE, 0, (LPARAM) MAKELONG ((int)size.x, (int)size.y));
421}
422
debe6624 423void wxToolBar95::SetRows(int nRows)
2bda0e17
KB
424{
425 RECT rect;
426 ::SendMessage((HWND) GetHWND(), TB_SETROWS, MAKEWPARAM(nRows, TRUE), (LPARAM) & rect);
427 m_maxWidth = (rect.right - rect.left + 2);
428 m_maxHeight = (rect.bottom - rect.top + 2);
429}
430
89b892a2 431wxSize wxToolBar95::GetMaxSize() const
2bda0e17 432{
dfad0599 433 if ((m_maxWidth == -1) || (m_maxHeight == -1))
2bda0e17
KB
434 {
435 RECT rect;
81d66cf3 436 ::SendMessage((HWND) GetHWND(), TB_SETROWS, MAKEWPARAM(m_maxRows, TRUE), (LPARAM) & rect);
2bda0e17
KB
437 ((wxToolBar95 *)this)->m_maxWidth = (rect.right - rect.left + 2); // ???
438 ((wxToolBar95 *)this)->m_maxHeight = (rect.bottom - rect.top + 2); // ???
439 }
440 return wxSize(m_maxWidth, m_maxHeight);
441}
442
443void wxToolBar95::GetSize(int *w, int *h) const
444{
445 wxWindow::GetSize(w, h);
446 // For some reason, the returned height is several pixels bigger than that
447 // displayed!
2a47d3c1
JS
448 // Taking this fudge factor out now, it seems fine without it.
449// *h -= 2;
2bda0e17
KB
450}
451
452// The button size is bigger than the bitmap size
89b892a2 453wxSize wxToolBar95::GetToolSize() const
2bda0e17
KB
454{
455 return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
456}
457
debe6624 458void wxToolBar95::EnableTool(int toolIndex, bool enable)
2bda0e17
KB
459{
460 wxNode *node = m_tools.Find((long)toolIndex);
461 if (node)
462 {
463 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
464 tool->m_enabled = enable;
465 ::SendMessage((HWND) GetHWND(), TB_ENABLEBUTTON, (WPARAM)toolIndex, (LPARAM)MAKELONG(enable, 0));
466 }
467}
468
debe6624 469void wxToolBar95::ToggleTool(int toolIndex, bool toggle)
2bda0e17
KB
470{
471 wxNode *node = m_tools.Find((long)toolIndex);
472 if (node)
473 {
474 wxToolBarTool *tool = (wxToolBarTool *)node->Data();
475 if (tool->m_isToggle)
476 {
477 tool->m_toggleState = toggle;
478 ::SendMessage((HWND) GetHWND(), TB_CHECKBUTTON, (WPARAM)toolIndex, (LPARAM)MAKELONG(toggle, 0));
479 }
480 }
481}
482
088a95f5
JS
483bool wxToolBar95::GetToolState(int toolIndex) const
484{
485 return (::SendMessage((HWND) GetHWND(), TB_ISBUTTONCHECKED, (WPARAM)toolIndex, (LPARAM)0) != 0);
486}
487
89b892a2 488void wxToolBar95::ClearTools()
2bda0e17
KB
489{
490 // TODO: Don't know how to reset the toolbar bitmap, as yet.
491 // But adding tools and calling CreateTools should probably
492 // recreate a buttonbar OK.
493 wxToolBarBase::ClearTools();
494}
495
496// If pushedBitmap is NULL, a reversed version of bitmap is
497// created and used as the pushed/toggled image.
498// If toggle is TRUE, the button toggles between the two states.
debe6624
JS
499wxToolBarTool *wxToolBar95::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap,
500 bool toggle, long xPos, long yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2)
2bda0e17 501{
dfad0599 502 wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2);
2bda0e17
KB
503 tool->m_clientData = clientData;
504
505 if (xPos > -1)
506 tool->m_x = xPos;
507 else
508 tool->m_x = m_xMargin;
509
510 if (yPos > -1)
511 tool->m_y = yPos;
512 else
513 tool->m_y = m_yMargin;
514
ca5e9f67 515 tool->SetSize(GetToolSize().x, GetToolSize().y);
2bda0e17
KB
516
517 m_tools.Append((long)index, tool);
518 return tool;
519}
520
521// Responds to colour changes, and passes event on to children.
522void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event)
523{
524 m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
89b892a2 525 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
2bda0e17
KB
526
527 // Remap the buttons
528 CreateTools();
529
530 Default();
531
532 Refresh();
533
534 // Propagate the event to the non-top-level children
535 wxWindow::OnSysColourChanged(event);
536}
537
e6460682
JS
538void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
539{
540 if (event.RightDown())
541 {
542 // For now, we don't have an id. Later we could
543 // try finding the tool.
544 OnRightClick((int)-1, event.GetX(), event.GetY());
545 }
546 else
547 {
548 Default();
549 }
550}
551
2bda0e17
KB
552// These are the default colors used to map the bitmap colors
553// to the current system colors
554
555#define BGR_BUTTONTEXT (RGB(000,000,000)) // black
556#define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
557#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
558#define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
559#define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
560#define BGR_BACKGROUND (RGB(255,000,255)) // magenta
561
562void wxMapBitmap(HBITMAP hBitmap, int width, int height)
563{
564 COLORMAP ColorMap[] = {
565 {BGR_BUTTONTEXT, COLOR_BTNTEXT}, // black
566 {BGR_BUTTONSHADOW, COLOR_BTNSHADOW}, // dark grey
567 {BGR_BUTTONFACE, COLOR_BTNFACE}, // bright grey
568 {BGR_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT},// white
569 {BGR_BACKGROUNDSEL, COLOR_HIGHLIGHT}, // blue
570 {BGR_BACKGROUND, COLOR_WINDOW} // magenta
571 };
572
573 int NUM_MAPS = (sizeof(ColorMap)/sizeof(COLORMAP));
574 int n;
575 for ( n = 0; n < NUM_MAPS; n++)
576 {
577 ColorMap[n].to = ::GetSysColor(ColorMap[n].to);
578 }
579
580 HBITMAP hbmOld;
581 HDC hdcMem = CreateCompatibleDC(NULL);
582
583 if (hdcMem)
584 {
c4e7c2aa 585 hbmOld = (HBITMAP) SelectObject(hdcMem, hBitmap);
2bda0e17
KB
586
587 int i, j, k;
588 for ( i = 0; i < width; i++)
589 {
590 for ( j = 0; j < height; j++)
591 {
592 COLORREF pixel = ::GetPixel(hdcMem, i, j);
593/*
594 BYTE red = GetRValue(pixel);
595 BYTE green = GetGValue(pixel);
596 BYTE blue = GetBValue(pixel);
597*/
598
599 for ( k = 0; k < NUM_MAPS; k ++)
600 {
601 if ( ColorMap[k].from == pixel )
602 {
603 /* COLORREF actualPixel = */ ::SetPixel(hdcMem, i, j, ColorMap[k].to);
604 break;
605 }
606 }
607 }
608 }
609
610
611 SelectObject(hdcMem, hbmOld);
612 DeleteObject(hdcMem);
613 }
614
615}
616
617// Some experiments...
618#if 0
619 // What we want to do is create another bitmap which has a depth of 4,
620 // and set the bits. So probably we want to convert this HBITMAP into a
621 // DIB, then call SetDIBits.
622 // AAAGH. The stupid thing is that if newBitmap has a depth of 4 (less than that of
623 // the screen), then SetDIBits fails.
624 HBITMAP newBitmap = ::CreateBitmap(totalBitmapWidth, totalBitmapHeight, 1, 4, NULL);
625 HANDLE newDIB = ::BitmapToDIB((HBITMAP) m_hBitmap, NULL);
626 LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) GlobalLock(newDIB);
627
628 dc = ::GetDC(NULL);
629// LPBITMAPINFOHEADER lpbmi = (LPBITMAPINFOHEADER) newDIB;
630
631 int result = ::SetDIBits(dc, newBitmap, 0, lpbmi->biHeight, FindDIBBits((LPSTR)lpbmi), (LPBITMAPINFO)lpbmi,
632 DIB_PAL_COLORS);
633 DWORD err = GetLastError();
634
635 ::ReleaseDC(NULL, dc);
636
637 // Delete the DIB
638 GlobalUnlock (newDIB);
639 GlobalFree (newDIB);
640
641// WXHBITMAP hBitmap2 = wxCreateMappedBitmap((WXHINSTANCE) wxGetInstance(), (WXHBITMAP) m_hBitmap);
642 // Substitute our new bitmap for the old one
643 ::DeleteObject((HBITMAP) m_hBitmap);
644 m_hBitmap = (WXHBITMAP) newBitmap;
645#endif
646
647
648#endif