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