]>
Commit | Line | Data |
---|---|---|
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$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1c383dba VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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" |
f538710f | 39 | #include "wx/control.h" |
2bda0e17 KB |
40 | #endif |
41 | ||
a9928e9d | 42 | #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) |
8a0681f9 VZ |
43 | |
44 | #include "wx/toolbar.h" | |
dfa53609 | 45 | #include "wx/sysopt.h" |
2bda0e17 | 46 | |
1c383dba | 47 | #include "wx/msw/private.h" |
2bda0e17 | 48 | |
d679df70 JS |
49 | #if wxUSE_UXTHEME |
50 | #include "wx/msw/uxtheme.h" | |
51 | #endif | |
52 | ||
0d236fd0 VZ |
53 | // include <commctrl.h> "properly" |
54 | #include "wx/msw/wrapcctl.h" | |
e5898961 | 55 | |
1c383dba VZ |
56 | #include "wx/app.h" // for GetComCtl32Version |
57 | ||
58 | // ---------------------------------------------------------------------------- | |
59 | // constants | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | // these standard constants are not always defined in compilers headers | |
2bda0e17 | 63 | |
6a23cbce | 64 | // Styles |
bb6290e3 | 65 | #ifndef TBSTYLE_FLAT |
1c383dba VZ |
66 | #define TBSTYLE_LIST 0x1000 |
67 | #define TBSTYLE_FLAT 0x0800 | |
dd177170 RL |
68 | #endif |
69 | ||
70 | #ifndef TBSTYLE_TRANSPARENT | |
1c383dba | 71 | #define TBSTYLE_TRANSPARENT 0x8000 |
bb6290e3 | 72 | #endif |
bb6290e3 | 73 | |
a3399e6c VZ |
74 | #ifndef TBSTYLE_TOOLTIPS |
75 | #define TBSTYLE_TOOLTIPS 0x0100 | |
76 | #endif | |
77 | ||
6a23cbce JS |
78 | // Messages |
79 | #ifndef TB_GETSTYLE | |
1c383dba | 80 | #define TB_SETSTYLE (WM_USER + 56) |
8a0681f9 VZ |
81 | #define TB_GETSTYLE (WM_USER + 57) |
82 | #endif | |
83 | ||
84 | #ifndef TB_HITTEST | |
85 | #define TB_HITTEST (WM_USER + 69) | |
6a23cbce JS |
86 | #endif |
87 | ||
308bb56f VZ |
88 | #ifndef TB_GETMAXSIZE |
89 | #define TB_GETMAXSIZE (WM_USER + 83) | |
90 | #endif | |
91 | ||
1c383dba | 92 | // these values correspond to those used by comctl32.dll |
81d66cf3 JS |
93 | #define DEFAULTBITMAPX 16 |
94 | #define DEFAULTBITMAPY 15 | |
95 | #define DEFAULTBUTTONX 24 | |
96 | #define DEFAULTBUTTONY 24 | |
97 | #define DEFAULTBARHEIGHT 27 | |
98 | ||
1c383dba VZ |
99 | // ---------------------------------------------------------------------------- |
100 | // wxWin macros | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
2eb10e2a | 103 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
2bda0e17 | 104 | |
066f1b7a | 105 | /* |
bfbb0b4c WS |
106 | TOOLBAR PROPERTIES |
107 | tool | |
108 | bitmap | |
109 | bitmap2 | |
110 | tooltip | |
111 | longhelp | |
112 | radio (bool) | |
113 | toggle (bool) | |
114 | separator | |
115 | style ( wxNO_BORDER | wxTB_HORIZONTAL) | |
116 | bitmapsize | |
117 | margins | |
118 | packing | |
119 | separation | |
120 | ||
121 | dontattachtoframe | |
066f1b7a SC |
122 | */ |
123 | ||
8a0681f9 VZ |
124 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) |
125 | EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent) | |
126 | EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged) | |
0090a153 | 127 | EVT_ERASE_BACKGROUND(wxToolBar::OnEraseBackground) |
2bda0e17 | 128 | END_EVENT_TABLE() |
2bda0e17 | 129 | |
8a0681f9 VZ |
130 | // ---------------------------------------------------------------------------- |
131 | // private classes | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
134 | class wxToolBarTool : public wxToolBarToolBase | |
135 | { | |
136 | public: | |
137 | wxToolBarTool(wxToolBar *tbar, | |
138 | int id, | |
a3399e6c VZ |
139 | const wxString& label, |
140 | const wxBitmap& bmpNormal, | |
141 | const wxBitmap& bmpDisabled, | |
142 | wxItemKind kind, | |
8a0681f9 | 143 | wxObject *clientData, |
a3399e6c VZ |
144 | const wxString& shortHelp, |
145 | const wxString& longHelp) | |
146 | : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind, | |
147 | clientData, shortHelp, longHelp) | |
8a0681f9 VZ |
148 | { |
149 | m_nSepCount = 0; | |
150 | } | |
151 | ||
152 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
153 | : wxToolBarToolBase(tbar, control) | |
154 | { | |
155 | m_nSepCount = 1; | |
156 | } | |
157 | ||
c631abda VZ |
158 | virtual void SetLabel(const wxString& label) |
159 | { | |
160 | if ( label == m_label ) | |
161 | return; | |
162 | ||
163 | wxToolBarToolBase::SetLabel(label); | |
164 | ||
165 | // we need to update the label shown in the toolbar because it has a | |
166 | // pointer to the internal buffer of the old label | |
167 | // | |
168 | // TODO: use TB_SETBUTTONINFO | |
169 | } | |
170 | ||
8a0681f9 VZ |
171 | // set/get the number of separators which we use to cover the space used by |
172 | // a control in the toolbar | |
173 | void SetSeparatorsCount(size_t count) { m_nSepCount = count; } | |
174 | size_t GetSeparatorsCount() const { return m_nSepCount; } | |
175 | ||
176 | private: | |
177 | size_t m_nSepCount; | |
2eb10e2a VZ |
178 | |
179 | DECLARE_NO_COPY_CLASS(wxToolBarTool) | |
8a0681f9 VZ |
180 | }; |
181 | ||
182 | ||
1c383dba VZ |
183 | // ============================================================================ |
184 | // implementation | |
185 | // ============================================================================ | |
2bda0e17 | 186 | |
1c383dba | 187 | // ---------------------------------------------------------------------------- |
8a0681f9 | 188 | // wxToolBarTool |
1c383dba VZ |
189 | // ---------------------------------------------------------------------------- |
190 | ||
8a0681f9 | 191 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
a3399e6c VZ |
192 | const wxString& label, |
193 | const wxBitmap& bmpNormal, | |
194 | const wxBitmap& bmpDisabled, | |
195 | wxItemKind kind, | |
8a0681f9 | 196 | wxObject *clientData, |
a3399e6c VZ |
197 | const wxString& shortHelp, |
198 | const wxString& longHelp) | |
8a0681f9 | 199 | { |
a3399e6c VZ |
200 | return new wxToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind, |
201 | clientData, shortHelp, longHelp); | |
8a0681f9 VZ |
202 | } |
203 | ||
204 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) | |
205 | { | |
206 | return new wxToolBarTool(this, control); | |
207 | } | |
208 | ||
209 | // ---------------------------------------------------------------------------- | |
210 | // wxToolBar construction | |
211 | // ---------------------------------------------------------------------------- | |
212 | ||
213 | void wxToolBar::Init() | |
2bda0e17 | 214 | { |
1c383dba | 215 | m_hBitmap = 0; |
8a0681f9 VZ |
216 | |
217 | m_nButtons = 0; | |
218 | ||
1c383dba VZ |
219 | m_defaultWidth = DEFAULTBITMAPX; |
220 | m_defaultHeight = DEFAULTBITMAPY; | |
37d0bdff MB |
221 | |
222 | m_pInTool = 0; | |
2bda0e17 KB |
223 | } |
224 | ||
8a0681f9 VZ |
225 | bool wxToolBar::Create(wxWindow *parent, |
226 | wxWindowID id, | |
227 | const wxPoint& pos, | |
228 | const wxSize& size, | |
229 | long style, | |
230 | const wxString& name) | |
2bda0e17 | 231 | { |
1c383dba | 232 | // common initialisation |
11b6a93b | 233 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) |
bfbb0b4c | 234 | return false; |
89b892a2 | 235 | |
24998710 | 236 | // MSW-specific initialisation |
278c927d | 237 | if ( !MSWCreateToolbar(pos, size) ) |
bfbb0b4c | 238 | return false; |
b0766406 | 239 | |
9a63feff VZ |
240 | wxSetCCUnicodeFormat(GetHwnd()); |
241 | ||
24998710 | 242 | // set up the colors and fonts |
7474e2cb | 243 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); |
24998710 | 244 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
7d6d3bf3 | 245 | |
6d473712 | 246 | // workaround for flat toolbar on Windows XP classic style |
d679df70 | 247 | #if wxUSE_UXTHEME |
6d473712 JS |
248 | if ( style & wxTB_FLAT ) |
249 | { | |
d679df70 JS |
250 | wxUxThemeEngine *p = wxUxThemeEngine::Get(); |
251 | if ( !p || !p->IsThemeActive() ) | |
252 | { | |
253 | DWORD dwToolbarStyle; | |
6d473712 | 254 | |
d679df70 | 255 | dwToolbarStyle = (DWORD)::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L ); |
bfbb0b4c | 256 | |
d679df70 JS |
257 | if ((dwToolbarStyle & TBSTYLE_FLAT) == 0) |
258 | { | |
259 | dwToolbarStyle |= TBSTYLE_FLAT; | |
260 | ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, (LPARAM)dwToolbarStyle ); | |
261 | } | |
6d473712 JS |
262 | } |
263 | } | |
d679df70 | 264 | #endif |
bfbb0b4c WS |
265 | |
266 | return true; | |
24998710 | 267 | } |
2bda0e17 | 268 | |
278c927d | 269 | bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size) |
24998710 | 270 | { |
fda7962d | 271 | if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, size) ) |
bfbb0b4c | 272 | return false; |
2bda0e17 | 273 | |
c8f1f088 | 274 | // toolbar-specific post initialisation |
1c383dba | 275 | ::SendMessage(GetHwnd(), TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); |
bfbb0b4c WS |
276 | |
277 | return true; | |
24998710 | 278 | } |
c8f1f088 | 279 | |
24998710 VZ |
280 | void wxToolBar::Recreate() |
281 | { | |
282 | const HWND hwndOld = GetHwnd(); | |
283 | if ( !hwndOld ) | |
284 | { | |
285 | // we haven't been created yet, no need to recreate | |
286 | return; | |
287 | } | |
2bda0e17 | 288 | |
24998710 VZ |
289 | // get the position and size before unsubclassing the old toolbar |
290 | const wxPoint pos = GetPosition(); | |
291 | const wxSize size = GetSize(); | |
bb6290e3 | 292 | |
24998710 | 293 | UnsubclassWin(); |
2bda0e17 | 294 | |
278c927d | 295 | if ( !MSWCreateToolbar(pos, size) ) |
24998710 VZ |
296 | { |
297 | // what can we do? | |
298 | wxFAIL_MSG( _T("recreating the toolbar failed") ); | |
299 | ||
300 | return; | |
301 | } | |
302 | ||
303 | // reparent all our children under the new toolbar | |
222ed1d6 | 304 | for ( wxWindowList::compatibility_iterator node = m_children.GetFirst(); |
24998710 VZ |
305 | node; |
306 | node = node->GetNext() ) | |
307 | { | |
308 | wxWindow *win = node->GetData(); | |
309 | if ( !win->IsTopLevel() ) | |
310 | ::SetParent(GetHwndOf(win), GetHwnd()); | |
311 | } | |
312 | ||
313 | // only destroy the old toolbar now -- after all the children had been | |
314 | // reparented | |
315 | ::DestroyWindow(hwndOld); | |
316 | ||
317 | // it is for the old bitmap control and can't be used with the new one | |
318 | if ( m_hBitmap ) | |
319 | { | |
320 | ::DeleteObject((HBITMAP) m_hBitmap); | |
321 | m_hBitmap = 0; | |
322 | } | |
323 | ||
324 | Realize(); | |
325 | UpdateSize(); | |
2bda0e17 KB |
326 | } |
327 | ||
8a0681f9 | 328 | wxToolBar::~wxToolBar() |
2bda0e17 | 329 | { |
f6bcfd97 BP |
330 | // we must refresh the frame size when the toolbar is deleted but the frame |
331 | // is not - otherwise toolbar leaves a hole in the place it used to occupy | |
f6bcfd97 | 332 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
c2fd78b1 | 333 | if ( frame && !frame->IsBeingDeleted() ) |
f6bcfd97 BP |
334 | { |
335 | frame->SendSizeEvent(); | |
336 | } | |
337 | ||
338 | if ( m_hBitmap ) | |
1c383dba VZ |
339 | { |
340 | ::DeleteObject((HBITMAP) m_hBitmap); | |
341 | } | |
342 | } | |
343 | ||
24998710 VZ |
344 | wxSize wxToolBar::DoGetBestSize() const |
345 | { | |
308bb56f VZ |
346 | wxSize sizeBest; |
347 | ||
348 | SIZE size; | |
349 | if ( !::SendMessage(GetHwnd(), TB_GETMAXSIZE, 0, (LPARAM)&size) ) | |
350 | { | |
351 | // maybe an old (< 0x400) Windows version? try to approximate the | |
352 | // toolbar size ourselves | |
353 | sizeBest = GetToolSize(); | |
4f6b4292 | 354 | sizeBest.y += 2 * ::GetSystemMetrics(SM_CYBORDER); // Add borders |
308bb56f VZ |
355 | sizeBest.x *= GetToolsCount(); |
356 | ||
357 | // reverse horz and vertical components if necessary | |
358 | if ( HasFlag(wxTB_VERTICAL) ) | |
359 | { | |
360 | int t = sizeBest.x; | |
361 | sizeBest.x = sizeBest.y; | |
362 | sizeBest.y = t; | |
363 | } | |
364 | } | |
365 | else | |
366 | { | |
367 | sizeBest.x = size.cx; | |
368 | sizeBest.y = size.cy; | |
369 | } | |
24998710 | 370 | |
308bb56f | 371 | return sizeBest; |
24998710 VZ |
372 | } |
373 | ||
374 | WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const | |
375 | { | |
376 | // toolbars never have border, giving one to them results in broken | |
377 | // appearance | |
378 | WXDWORD msStyle = wxControl::MSWGetStyle | |
379 | ( | |
380 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle | |
381 | ); | |
382 | ||
383 | // always include this one, it never hurts and setting it later only if we | |
384 | // do have tooltips wouldn't work | |
385 | msStyle |= TBSTYLE_TOOLTIPS; | |
386 | ||
f9dae779 | 387 | if ( style & (wxTB_FLAT | wxTB_HORZ_LAYOUT) ) |
24998710 VZ |
388 | { |
389 | // static as it doesn't change during the program lifetime | |
390 | static int s_verComCtl = wxTheApp->GetComCtl32Version(); | |
391 | ||
392 | // comctl32.dll 4.00 doesn't support the flat toolbars and using this | |
393 | // style with 6.00 (part of Windows XP) leads to the toolbar with | |
394 | // incorrect background colour - and not using it still results in the | |
395 | // correct (flat) toolbar, so don't use it there | |
396 | if ( s_verComCtl > 400 && s_verComCtl < 600 ) | |
397 | { | |
398 | msStyle |= TBSTYLE_FLAT | TBSTYLE_TRANSPARENT; | |
399 | } | |
f9dae779 VZ |
400 | |
401 | if ( s_verComCtl >= 470 && style & wxTB_HORZ_LAYOUT ) | |
402 | { | |
403 | msStyle |= TBSTYLE_LIST; | |
404 | } | |
24998710 VZ |
405 | } |
406 | ||
407 | if ( style & wxTB_NODIVIDER ) | |
408 | msStyle |= CCS_NODIVIDER; | |
409 | ||
410 | if ( style & wxTB_NOALIGN ) | |
411 | msStyle |= CCS_NOPARENTALIGN; | |
412 | ||
3bb63e5c JS |
413 | if ( style & wxTB_VERTICAL ) |
414 | msStyle |= CCS_VERT; | |
415 | ||
24998710 VZ |
416 | return msStyle; |
417 | } | |
418 | ||
bdc72a22 | 419 | // ---------------------------------------------------------------------------- |
8a0681f9 | 420 | // adding/removing tools |
bdc72a22 VZ |
421 | // ---------------------------------------------------------------------------- |
422 | ||
24998710 | 423 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
1c383dba | 424 | { |
8a0681f9 VZ |
425 | // nothing special to do here - we really create the toolbar buttons in |
426 | // Realize() later | |
427 | tool->Attach(this); | |
428 | ||
9f884528 | 429 | InvalidateBestSize(); |
bfbb0b4c | 430 | return true; |
1c383dba VZ |
431 | } |
432 | ||
8a0681f9 | 433 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) |
bdc72a22 | 434 | { |
f6bcfd97 BP |
435 | // the main difficulty we have here is with the controls in the toolbars: |
436 | // as we (sometimes) use several separators to cover up the space used by | |
437 | // them, the indices are not the same for us and the toolbar | |
438 | ||
439 | // first determine the position of the first button to delete: it may be | |
440 | // different from pos if we use several separators to cover the space used | |
441 | // by a control | |
222ed1d6 | 442 | wxToolBarToolsList::compatibility_iterator node; |
f6bcfd97 BP |
443 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
444 | { | |
445 | wxToolBarToolBase *tool2 = node->GetData(); | |
446 | if ( tool2 == tool ) | |
447 | { | |
448 | // let node point to the next node in the list | |
449 | node = node->GetNext(); | |
450 | ||
451 | break; | |
452 | } | |
453 | ||
454 | if ( tool2->IsControl() ) | |
455 | { | |
56bd6aac | 456 | pos += ((wxToolBarTool *)tool2)->GetSeparatorsCount() - 1; |
f6bcfd97 BP |
457 | } |
458 | } | |
459 | ||
460 | // now determine the number of buttons to delete and the area taken by them | |
8a0681f9 | 461 | size_t nButtonsToDelete = 1; |
bdc72a22 | 462 | |
8a0681f9 VZ |
463 | // get the size of the button we're going to delete |
464 | RECT r; | |
465 | if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) ) | |
bdc72a22 | 466 | { |
8a0681f9 | 467 | wxLogLastError(_T("TB_GETITEMRECT")); |
bdc72a22 VZ |
468 | } |
469 | ||
8a0681f9 | 470 | int width = r.right - r.left; |
bdc72a22 | 471 | |
8a0681f9 VZ |
472 | if ( tool->IsControl() ) |
473 | { | |
474 | nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount(); | |
bdc72a22 | 475 | |
8a0681f9 VZ |
476 | width *= nButtonsToDelete; |
477 | } | |
bdc72a22 | 478 | |
f6bcfd97 BP |
479 | // do delete all buttons |
480 | m_nButtons -= nButtonsToDelete; | |
8a0681f9 VZ |
481 | while ( nButtonsToDelete-- > 0 ) |
482 | { | |
483 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) ) | |
484 | { | |
f6bcfd97 | 485 | wxLogLastError(wxT("TB_DELETEBUTTON")); |
1c383dba | 486 | |
bfbb0b4c | 487 | return false; |
8a0681f9 VZ |
488 | } |
489 | } | |
1c383dba | 490 | |
8a0681f9 | 491 | tool->Detach(); |
1c383dba | 492 | |
f6bcfd97 BP |
493 | // and finally reposition all the controls after this button (the toolbar |
494 | // takes care of all normal items) | |
495 | for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) | |
8a0681f9 VZ |
496 | { |
497 | wxToolBarToolBase *tool2 = node->GetData(); | |
498 | if ( tool2->IsControl() ) | |
499 | { | |
500 | int x; | |
501 | wxControl *control = tool2->GetControl(); | |
502 | control->GetPosition(&x, NULL); | |
bfbb0b4c | 503 | control->Move(x - width, wxDefaultCoord); |
8a0681f9 VZ |
504 | } |
505 | } | |
1c383dba | 506 | |
9f884528 | 507 | InvalidateBestSize(); |
bfbb0b4c | 508 | return true; |
1c383dba VZ |
509 | } |
510 | ||
8a0681f9 | 511 | bool wxToolBar::Realize() |
1c383dba | 512 | { |
24998710 | 513 | const size_t nTools = GetToolsCount(); |
8a0681f9 VZ |
514 | if ( nTools == 0 ) |
515 | { | |
516 | // nothing to do | |
bfbb0b4c | 517 | return true; |
8a0681f9 | 518 | } |
1c383dba | 519 | |
24998710 | 520 | const bool isVertical = HasFlag(wxTB_VERTICAL); |
2bda0e17 | 521 | |
92661f97 VZ |
522 | bool doRemap, doRemapBg, doTransparent; |
523 | if (wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 2) | |
524 | { | |
525 | doRemapBg = doRemap = false; | |
bfbb0b4c | 526 | doTransparent = true; |
92661f97 VZ |
527 | } |
528 | else | |
529 | { doRemap = !wxSystemOptions::HasOption(wxT("msw.remap")) | |
530 | || wxSystemOptions::GetOptionInt(wxT("msw.remap")) == 1; | |
531 | doRemapBg = !doRemap; | |
532 | doTransparent = false; | |
533 | } | |
534 | ||
2b5f62a0 VZ |
535 | // delete all old buttons, if any |
536 | for ( size_t pos = 0; pos < m_nButtons; pos++ ) | |
537 | { | |
538 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) | |
539 | { | |
540 | wxLogDebug(wxT("TB_DELETEBUTTON failed")); | |
541 | } | |
542 | } | |
543 | ||
8a0681f9 VZ |
544 | // First, add the bitmap: we use one bitmap for all toolbar buttons |
545 | // ---------------------------------------------------------------- | |
2bda0e17 | 546 | |
222ed1d6 | 547 | wxToolBarToolsList::compatibility_iterator node; |
24998710 VZ |
548 | int bitmapId = 0; |
549 | ||
550 | wxSize sizeBmp; | |
551 | if ( HasFlag(wxTB_NOICONS) ) | |
552 | { | |
553 | // no icons, don't leave space for them | |
554 | sizeBmp.x = | |
555 | sizeBmp.y = 0; | |
556 | } | |
557 | else // do show icons | |
558 | { | |
559 | // if we already have a bitmap, we'll replace the existing one -- | |
560 | // otherwise we'll install a new one | |
561 | HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap; | |
562 | ||
563 | sizeBmp.x = m_defaultWidth; | |
564 | sizeBmp.y = m_defaultHeight; | |
89b892a2 | 565 | |
24998710 VZ |
566 | const wxCoord totalBitmapWidth = m_defaultWidth * nTools, |
567 | totalBitmapHeight = m_defaultHeight; | |
2bda0e17 | 568 | |
24998710 | 569 | // Create a bitmap and copy all the tool bitmaps to it |
24998710 VZ |
570 | wxMemoryDC dcAllButtons; |
571 | wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight); | |
572 | dcAllButtons.SelectObject(bitmap); | |
92661f97 VZ |
573 | if (doTransparent) |
574 | dcAllButtons.SetBackground(*wxTRANSPARENT_BRUSH); | |
575 | else | |
24998710 VZ |
576 | dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH); |
577 | dcAllButtons.Clear(); | |
578 | ||
579 | m_hBitmap = bitmap.GetHBITMAP(); | |
580 | HBITMAP hBitmap = (HBITMAP)m_hBitmap; | |
2bda0e17 | 581 | |
92661f97 | 582 | if (doRemapBg) |
dfa53609 | 583 | { |
dfa53609 | 584 | dcAllButtons.SelectObject(wxNullBitmap); |
dfa53609 JS |
585 | |
586 | // Even if we're not remapping the bitmap | |
587 | // content, we still have to remap the background. | |
588 | hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap, | |
589 | totalBitmapWidth, totalBitmapHeight); | |
590 | ||
dfa53609 | 591 | dcAllButtons.SelectObject(bitmap); |
dfa53609 JS |
592 | } |
593 | ||
24998710 VZ |
594 | // the button position |
595 | wxCoord x = 0; | |
2bda0e17 | 596 | |
24998710 VZ |
597 | // the number of buttons (not separators) |
598 | int nButtons = 0; | |
1c383dba | 599 | |
4769a562 | 600 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
1c383dba | 601 | { |
24998710 VZ |
602 | wxToolBarToolBase *tool = node->GetData(); |
603 | if ( tool->IsButton() ) | |
1c383dba | 604 | { |
24998710 VZ |
605 | const wxBitmap& bmp = tool->GetNormalBitmap(); |
606 | if ( bmp.Ok() ) | |
607 | { | |
dfa53609 JS |
608 | int xOffset = wxMax(0, (m_defaultWidth - bmp.GetWidth())/2); |
609 | int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2); | |
24998710 | 610 | // notice the last parameter: do use mask |
bfbb0b4c | 611 | dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, true); |
24998710 VZ |
612 | } |
613 | else | |
1c383dba | 614 | { |
24998710 | 615 | wxFAIL_MSG( _T("invalid tool button bitmap") ); |
1c383dba VZ |
616 | } |
617 | ||
24998710 VZ |
618 | // still inc width and number of buttons because otherwise the |
619 | // subsequent buttons will all be shifted which is rather confusing | |
620 | // (and like this you'd see immediately which bitmap was bad) | |
621 | x += m_defaultWidth; | |
622 | nButtons++; | |
1c383dba VZ |
623 | } |
624 | } | |
8a0681f9 | 625 | |
24998710 | 626 | dcAllButtons.SelectObject(wxNullBitmap); |
f6bcfd97 | 627 | |
24998710 VZ |
628 | // don't delete this HBITMAP! |
629 | bitmap.SetHBITMAP(0); | |
2bda0e17 | 630 | |
92661f97 | 631 | if (doRemap) |
dfa53609 JS |
632 | { |
633 | // Map to system colours | |
634 | hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap, | |
635 | totalBitmapWidth, totalBitmapHeight); | |
636 | } | |
1c383dba | 637 | |
bfbb0b4c | 638 | bool addBitmap = true; |
9f83044f | 639 | |
24998710 | 640 | if ( oldToolBarBitmap ) |
1c383dba | 641 | { |
24998710 VZ |
642 | #ifdef TB_REPLACEBITMAP |
643 | if ( wxTheApp->GetComCtl32Version() >= 400 ) | |
9f83044f | 644 | { |
24998710 VZ |
645 | TBREPLACEBITMAP replaceBitmap; |
646 | replaceBitmap.hInstOld = NULL; | |
647 | replaceBitmap.hInstNew = NULL; | |
648 | replaceBitmap.nIDOld = (UINT) oldToolBarBitmap; | |
649 | replaceBitmap.nIDNew = (UINT) hBitmap; | |
650 | replaceBitmap.nButtons = nButtons; | |
651 | if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP, | |
652 | 0, (LPARAM) &replaceBitmap) ) | |
653 | { | |
654 | wxFAIL_MSG(wxT("Could not replace the old bitmap")); | |
655 | } | |
9f83044f | 656 | |
24998710 | 657 | ::DeleteObject(oldToolBarBitmap); |
9f83044f | 658 | |
24998710 | 659 | // already done |
bfbb0b4c | 660 | addBitmap = false; |
24998710 VZ |
661 | } |
662 | else | |
9f83044f | 663 | #endif // TB_REPLACEBITMAP |
24998710 VZ |
664 | { |
665 | // we can't replace the old bitmap, so we will add another one | |
666 | // (awfully inefficient, but what else to do?) and shift the bitmap | |
667 | // indices accordingly | |
bfbb0b4c | 668 | addBitmap = true; |
1c383dba | 669 | |
24998710 VZ |
670 | bitmapId = m_nButtons; |
671 | } | |
9f83044f | 672 | } |
1c383dba | 673 | |
24998710 | 674 | if ( addBitmap ) // no old bitmap or we can't replace it |
1c383dba | 675 | { |
24998710 VZ |
676 | TBADDBITMAP addBitmap; |
677 | addBitmap.hInst = 0; | |
678 | addBitmap.nID = (UINT) hBitmap; | |
679 | if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP, | |
680 | (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 ) | |
8a0681f9 | 681 | { |
24998710 | 682 | wxFAIL_MSG(wxT("Could not add bitmap to toolbar")); |
8a0681f9 | 683 | } |
1c383dba | 684 | } |
2bda0e17 | 685 | } |
9f83044f | 686 | |
24998710 VZ |
687 | // don't call SetToolBitmapSize() as we don't want to change the values of |
688 | // m_defaultWidth/Height | |
689 | if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, | |
690 | MAKELONG(sizeBmp.x, sizeBmp.y)) ) | |
051205e6 | 691 | { |
24998710 | 692 | wxLogLastError(_T("TB_SETBITMAPSIZE")); |
051205e6 | 693 | } |
2bda0e17 | 694 | |
8a0681f9 VZ |
695 | // Next add the buttons and separators |
696 | // ----------------------------------- | |
697 | ||
1c383dba | 698 | TBBUTTON *buttons = new TBBUTTON[nTools]; |
2bda0e17 | 699 | |
8a0681f9 | 700 | // this array will hold the indices of all controls in the toolbar |
1c383dba VZ |
701 | wxArrayInt controlIds; |
702 | ||
bfbb0b4c | 703 | bool lastWasRadio = false; |
1c383dba | 704 | int i = 0; |
4769a562 | 705 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
2bda0e17 | 706 | { |
8a0681f9 VZ |
707 | wxToolBarToolBase *tool = node->GetData(); |
708 | ||
28603488 VZ |
709 | // don't add separators to the vertical toolbar with old comctl32.dll |
710 | // versions as they didn't handle this properly | |
711 | if ( isVertical && tool->IsSeparator() && | |
712 | wxTheApp->GetComCtl32Version() <= 472 ) | |
713 | { | |
714 | continue; | |
715 | } | |
716 | ||
8a0681f9 | 717 | |
1c383dba VZ |
718 | TBBUTTON& button = buttons[i]; |
719 | ||
720 | wxZeroMemory(button); | |
721 | ||
bfbb0b4c | 722 | bool isRadio = false; |
8a0681f9 | 723 | switch ( tool->GetStyle() ) |
1c383dba VZ |
724 | { |
725 | case wxTOOL_STYLE_CONTROL: | |
8a0681f9 | 726 | button.idCommand = tool->GetId(); |
1c383dba VZ |
727 | // fall through: create just a separator too |
728 | ||
729 | case wxTOOL_STYLE_SEPARATOR: | |
730 | button.fsState = TBSTATE_ENABLED; | |
731 | button.fsStyle = TBSTYLE_SEP; | |
732 | break; | |
733 | ||
734 | case wxTOOL_STYLE_BUTTON: | |
24998710 VZ |
735 | if ( !HasFlag(wxTB_NOICONS) ) |
736 | button.iBitmap = bitmapId; | |
c631abda | 737 | |
24998710 | 738 | if ( HasFlag(wxTB_TEXT) ) |
c631abda | 739 | { |
24998710 VZ |
740 | const wxString& label = tool->GetLabel(); |
741 | if ( !label.empty() ) | |
742 | { | |
743 | button.iString = (int)label.c_str(); | |
744 | } | |
c631abda VZ |
745 | } |
746 | ||
8a0681f9 | 747 | button.idCommand = tool->GetId(); |
1c383dba | 748 | |
8a0681f9 | 749 | if ( tool->IsEnabled() ) |
1c383dba | 750 | button.fsState |= TBSTATE_ENABLED; |
8a0681f9 | 751 | if ( tool->IsToggled() ) |
1c383dba | 752 | button.fsState |= TBSTATE_CHECKED; |
8a0681f9 | 753 | |
c631abda VZ |
754 | switch ( tool->GetKind() ) |
755 | { | |
756 | case wxITEM_RADIO: | |
757 | button.fsStyle = TBSTYLE_CHECKGROUP; | |
758 | ||
759 | if ( !lastWasRadio ) | |
760 | { | |
761 | // the first item in the radio group is checked by | |
762 | // default to be consistent with wxGTK and the menu | |
763 | // radio items | |
764 | button.fsState |= TBSTATE_CHECKED; | |
f3ba93c1 | 765 | |
bfbb0b4c | 766 | tool->Toggle(true); |
c631abda VZ |
767 | } |
768 | ||
bfbb0b4c | 769 | isRadio = true; |
c631abda VZ |
770 | break; |
771 | ||
772 | case wxITEM_CHECK: | |
773 | button.fsStyle = TBSTYLE_CHECK; | |
774 | break; | |
775 | ||
776 | default: | |
777 | wxFAIL_MSG( _T("unexpected toolbar button kind") ); | |
778 | // fall through | |
779 | ||
780 | case wxITEM_NORMAL: | |
781 | button.fsStyle = TBSTYLE_BUTTON; | |
782 | } | |
1c383dba VZ |
783 | |
784 | bitmapId++; | |
785 | break; | |
786 | } | |
2bda0e17 | 787 | |
c631abda VZ |
788 | lastWasRadio = isRadio; |
789 | ||
1c383dba | 790 | i++; |
2bda0e17 | 791 | } |
1c383dba | 792 | |
a3399e6c | 793 | if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS, (WPARAM)i, (LPARAM)buttons) ) |
2bda0e17 | 794 | { |
f6bcfd97 | 795 | wxLogLastError(wxT("TB_ADDBUTTONS")); |
2bda0e17 | 796 | } |
89b892a2 | 797 | |
1c383dba | 798 | delete [] buttons; |
2bda0e17 | 799 | |
8a0681f9 VZ |
800 | // Deal with the controls finally |
801 | // ------------------------------ | |
802 | ||
1c383dba | 803 | // adjust the controls size to fit nicely in the toolbar |
34e5028f | 804 | int y = 0; |
8a0681f9 VZ |
805 | size_t index = 0; |
806 | for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ ) | |
1c383dba | 807 | { |
8a0681f9 | 808 | wxToolBarToolBase *tool = node->GetData(); |
1c383dba | 809 | |
34e5028f VZ |
810 | // we calculate the running y coord for vertical toolbars so we need to |
811 | // get the items size for all items but for the horizontal ones we | |
812 | // don't need to deal with the non controls | |
813 | bool isControl = tool->IsControl(); | |
814 | if ( !isControl && !isVertical ) | |
815 | continue; | |
bdc72a22 | 816 | |
8a0681f9 VZ |
817 | // note that we use TB_GETITEMRECT and not TB_GETRECT because the |
818 | // latter only appeared in v4.70 of comctl32.dll | |
819 | RECT r; | |
bfbb0b4c WS |
820 | if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, |
821 | index, (LPARAM)(LPRECT)&r) ) | |
8a0681f9 | 822 | { |
f6bcfd97 | 823 | wxLogLastError(wxT("TB_GETITEMRECT")); |
8a0681f9 VZ |
824 | } |
825 | ||
34e5028f VZ |
826 | if ( !isControl ) |
827 | { | |
828 | // can only be control if isVertical | |
829 | y += r.bottom - r.top; | |
830 | ||
831 | continue; | |
832 | } | |
833 | ||
834 | wxControl *control = tool->GetControl(); | |
835 | ||
836 | wxSize size = control->GetSize(); | |
837 | ||
838 | // the position of the leftmost controls corner | |
bfbb0b4c | 839 | int left = wxDefaultCoord; |
34e5028f | 840 | |
bdc72a22 | 841 | // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+ |
5b59df83 | 842 | #ifdef TB_SETBUTTONINFO |
34e5028f VZ |
843 | // available in headers, now check whether it is available now |
844 | // (during run-time) | |
845 | if ( wxTheApp->GetComCtl32Version() >= 471 ) | |
846 | { | |
847 | // set the (underlying) separators width to be that of the | |
848 | // control | |
849 | TBBUTTONINFO tbbi; | |
850 | tbbi.cbSize = sizeof(tbbi); | |
851 | tbbi.dwMask = TBIF_SIZE; | |
5c519b6c | 852 | tbbi.cx = (WORD)size.x; |
bfbb0b4c WS |
853 | if ( !::SendMessage(GetHwnd(), TB_SETBUTTONINFO, |
854 | tool->GetId(), (LPARAM)&tbbi) ) | |
bdc72a22 | 855 | { |
34e5028f VZ |
856 | // the id is probably invalid? |
857 | wxLogLastError(wxT("TB_SETBUTTONINFO")); | |
bdc72a22 | 858 | } |
34e5028f VZ |
859 | } |
860 | else | |
861 | #endif // comctl32.dll 4.71 | |
862 | // TB_SETBUTTONINFO unavailable | |
863 | { | |
864 | // try adding several separators to fit the controls width | |
865 | int widthSep = r.right - r.left; | |
866 | left = r.left; | |
867 | ||
868 | TBBUTTON tbb; | |
869 | wxZeroMemory(tbb); | |
870 | tbb.idCommand = 0; | |
871 | tbb.fsState = TBSTATE_ENABLED; | |
872 | tbb.fsStyle = TBSTYLE_SEP; | |
873 | ||
874 | size_t nSeparators = size.x / widthSep; | |
875 | for ( size_t nSep = 0; nSep < nSeparators; nSep++ ) | |
bdc72a22 | 876 | { |
bfbb0b4c WS |
877 | if ( !::SendMessage(GetHwnd(), TB_INSERTBUTTON, |
878 | index, (LPARAM)&tbb) ) | |
bdc72a22 | 879 | { |
34e5028f | 880 | wxLogLastError(wxT("TB_INSERTBUTTON")); |
bdc72a22 VZ |
881 | } |
882 | ||
34e5028f | 883 | index++; |
bdc72a22 | 884 | } |
1c383dba | 885 | |
34e5028f VZ |
886 | // remember the number of separators we used - we'd have to |
887 | // delete all of them later | |
888 | ((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators); | |
889 | ||
890 | // adjust the controls width to exactly cover the separators | |
bfbb0b4c | 891 | control->SetSize((nSeparators + 1)*widthSep, wxDefaultCoord); |
34e5028f VZ |
892 | } |
893 | ||
894 | // position the control itself correctly vertically | |
1c383dba VZ |
895 | int height = r.bottom - r.top; |
896 | int diff = height - size.y; | |
897 | if ( diff < 0 ) | |
898 | { | |
899 | // the control is too high, resize to fit | |
bfbb0b4c | 900 | control->SetSize(wxDefaultCoord, height - 2); |
1c383dba VZ |
901 | |
902 | diff = 2; | |
903 | } | |
2bda0e17 | 904 | |
34e5028f VZ |
905 | int top; |
906 | if ( isVertical ) | |
907 | { | |
908 | left = 0; | |
909 | top = y; | |
910 | ||
911 | y += height + 2*GetMargins().y; | |
912 | } | |
913 | else // horizontal toolbar | |
914 | { | |
bfbb0b4c | 915 | if ( left == wxDefaultCoord ) |
34e5028f VZ |
916 | left = r.left; |
917 | ||
918 | top = r.top; | |
919 | } | |
920 | ||
921 | control->Move(left, top + (diff + 1) / 2); | |
1c383dba | 922 | } |
89b892a2 | 923 | |
8a0681f9 VZ |
924 | // the max index is the "real" number of buttons - i.e. counting even the |
925 | // separators which we added just for aligning the controls | |
926 | m_nButtons = index; | |
89b892a2 | 927 | |
8a0681f9 VZ |
928 | if ( !isVertical ) |
929 | { | |
930 | if ( m_maxRows == 0 ) | |
931 | { | |
932 | // if not set yet, only one row | |
933 | SetRows(1); | |
934 | } | |
935 | } | |
936 | else if ( m_nButtons > 0 ) // vertical non empty toolbar | |
937 | { | |
938 | if ( m_maxRows == 0 ) | |
939 | { | |
940 | // if not set yet, have one column | |
941 | SetRows(m_nButtons); | |
942 | } | |
943 | } | |
2bda0e17 | 944 | |
9f884528 | 945 | InvalidateBestSize(); |
bfbb0b4c | 946 | return true; |
2bda0e17 KB |
947 | } |
948 | ||
1c383dba VZ |
949 | // ---------------------------------------------------------------------------- |
950 | // message handlers | |
951 | // ---------------------------------------------------------------------------- | |
952 | ||
33ac7e6f | 953 | bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) |
2bda0e17 | 954 | { |
8a0681f9 VZ |
955 | wxToolBarToolBase *tool = FindById((int)id); |
956 | if ( !tool ) | |
bfbb0b4c | 957 | return false; |
1c383dba | 958 | |
1bba1946 | 959 | bool toggled = false; // just to suppress warnings |
6bb7cee4 | 960 | |
8a0681f9 | 961 | if ( tool->CanBeToggled() ) |
1c383dba VZ |
962 | { |
963 | LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0); | |
6bb7cee4 VZ |
964 | toggled = (state & TBSTATE_CHECKED) != 0; |
965 | ||
966 | // ignore the event when a radio button is released, as this doesn't seem to | |
967 | // happen at all, and is handled otherwise | |
968 | if ( tool->GetKind() == wxITEM_RADIO && !toggled ) | |
bfbb0b4c | 969 | return true; |
1c383dba | 970 | |
6bb7cee4 VZ |
971 | tool->Toggle(toggled); |
972 | UnToggleRadioGroup(tool); | |
973 | } | |
8a0681f9 | 974 | |
6bb7cee4 VZ |
975 | // OnLeftClick() can veto the button state change - for buttons which |
976 | // may be toggled only, of couse | |
977 | if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) | |
f3ba93c1 | 978 | { |
6bb7cee4 VZ |
979 | // revert back |
980 | tool->Toggle(!toggled); | |
8a0681f9 | 981 | |
6bb7cee4 | 982 | ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); |
1c383dba VZ |
983 | } |
984 | ||
bfbb0b4c | 985 | return true; |
2bda0e17 KB |
986 | } |
987 | ||
8a0681f9 | 988 | bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl), |
fd3f686c | 989 | WXLPARAM lParam, |
33ac7e6f | 990 | WXLPARAM *WXUNUSED(result)) |
2bda0e17 | 991 | { |
3bce6687 | 992 | #if wxUSE_TOOLTIPS |
89b892a2 | 993 | // First check if this applies to us |
2bda0e17 | 994 | NMHDR *hdr = (NMHDR *)lParam; |
2bda0e17 | 995 | |
1c383dba VZ |
996 | // the tooltips control created by the toolbar is sometimes Unicode, even |
997 | // in an ANSI application - this seems to be a bug in comctl32.dll v5 | |
bd9cd534 | 998 | UINT code = hdr->code; |
9b601c24 | 999 | if ( (code != (UINT) TTN_NEEDTEXTA) && (code != (UINT) TTN_NEEDTEXTW) ) |
bfbb0b4c | 1000 | return false; |
2bda0e17 | 1001 | |
89b892a2 VZ |
1002 | HWND toolTipWnd = (HWND)::SendMessage((HWND)GetHWND(), TB_GETTOOLTIPS, 0, 0); |
1003 | if ( toolTipWnd != hdr->hwndFrom ) | |
bfbb0b4c | 1004 | return false; |
2bda0e17 | 1005 | |
89b892a2 VZ |
1006 | LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam; |
1007 | int id = (int)ttText->hdr.idFrom; | |
89b892a2 | 1008 | |
8a0681f9 VZ |
1009 | wxToolBarToolBase *tool = FindById(id); |
1010 | if ( !tool ) | |
bfbb0b4c | 1011 | return false; |
2bda0e17 | 1012 | |
bd9cd534 | 1013 | return HandleTooltipNotify(code, lParam, tool->GetShortHelp()); |
3bce6687 | 1014 | #else |
bfbb0b4c | 1015 | return false; |
3bce6687 | 1016 | #endif |
2bda0e17 KB |
1017 | } |
1018 | ||
1c383dba | 1019 | // ---------------------------------------------------------------------------- |
8a0681f9 | 1020 | // toolbar geometry |
1c383dba VZ |
1021 | // ---------------------------------------------------------------------------- |
1022 | ||
8a0681f9 | 1023 | void wxToolBar::SetToolBitmapSize(const wxSize& size) |
2bda0e17 | 1024 | { |
1c383dba VZ |
1025 | wxToolBarBase::SetToolBitmapSize(size); |
1026 | ||
1027 | ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y)); | |
2bda0e17 KB |
1028 | } |
1029 | ||
8a0681f9 | 1030 | void wxToolBar::SetRows(int nRows) |
2bda0e17 | 1031 | { |
8a0681f9 VZ |
1032 | if ( nRows == m_maxRows ) |
1033 | { | |
1034 | // avoid resizing the frame uselessly | |
1035 | return; | |
1036 | } | |
1037 | ||
1038 | // TRUE in wParam means to create at least as many rows, FALSE - | |
1039 | // at most as many | |
1c383dba VZ |
1040 | RECT rect; |
1041 | ::SendMessage(GetHwnd(), TB_SETROWS, | |
8a0681f9 VZ |
1042 | MAKEWPARAM(nRows, !(GetWindowStyle() & wxTB_VERTICAL)), |
1043 | (LPARAM) &rect); | |
1c383dba VZ |
1044 | |
1045 | m_maxRows = nRows; | |
8a0681f9 VZ |
1046 | |
1047 | UpdateSize(); | |
1048 | } | |
1049 | ||
1050 | // The button size is bigger than the bitmap size | |
1051 | wxSize wxToolBar::GetToolSize() const | |
1052 | { | |
1053 | // TB_GETBUTTONSIZE is supported from version 4.70 | |
5438a566 | 1054 | #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \ |
50165591 CE |
1055 | && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \ |
1056 | && !defined (__DIGITALMARS__) | |
8a0681f9 VZ |
1057 | if ( wxTheApp->GetComCtl32Version() >= 470 ) |
1058 | { | |
1059 | DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0); | |
1060 | ||
1061 | return wxSize(LOWORD(dw), HIWORD(dw)); | |
1062 | } | |
1063 | else | |
1064 | #endif // comctl32.dll 4.70+ | |
1065 | { | |
1066 | // defaults | |
1067 | return wxSize(m_defaultWidth + 8, m_defaultHeight + 7); | |
1068 | } | |
2bda0e17 KB |
1069 | } |
1070 | ||
82c9f85c VZ |
1071 | static |
1072 | wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools, | |
1073 | size_t index ) | |
a8945eef | 1074 | { |
222ed1d6 | 1075 | wxToolBarToolsList::compatibility_iterator current = tools.GetFirst(); |
a8945eef | 1076 | |
82c9f85c | 1077 | for ( ; current != 0; current = current->GetNext() ) |
a8945eef | 1078 | { |
82c9f85c | 1079 | if ( index == 0 ) |
a8945eef | 1080 | return current->GetData(); |
82c9f85c VZ |
1081 | |
1082 | wxToolBarTool *tool = (wxToolBarTool *)current->GetData(); | |
1083 | size_t separators = tool->GetSeparatorsCount(); | |
1084 | ||
1085 | // if it is a normal button, sepcount == 0, so skip 1 item (the button) | |
1086 | // otherwise, skip as many items as the separator count, plus the | |
1087 | // control itself | |
1088 | index -= separators ? separators + 1 : 1; | |
a8945eef MB |
1089 | } |
1090 | ||
1091 | return 0; | |
1092 | } | |
1093 | ||
8a0681f9 | 1094 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
2bda0e17 | 1095 | { |
8a0681f9 VZ |
1096 | POINT pt; |
1097 | pt.x = x; | |
1098 | pt.y = y; | |
1099 | int index = (int)::SendMessage(GetHwnd(), TB_HITTEST, 0, (LPARAM)&pt); | |
37d0bdff MB |
1100 | // MBN: when the point ( x, y ) is close to the toolbar border |
1101 | // TB_HITTEST returns m_nButtons ( not -1 ) | |
1102 | if ( index < 0 || (size_t)index >= m_nButtons ) | |
1c383dba | 1103 | { |
8a0681f9 VZ |
1104 | // it's a separator or there is no tool at all there |
1105 | return (wxToolBarToolBase *)NULL; | |
1c383dba VZ |
1106 | } |
1107 | ||
82c9f85c | 1108 | // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers |
a8945eef MB |
1109 | #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 ) |
1110 | if ( wxTheApp->GetComCtl32Version() >= 471 ) | |
1111 | { | |
1112 | return m_tools.Item((size_t)index)->GetData(); | |
1113 | } | |
1114 | else | |
82c9f85c | 1115 | #endif |
a8945eef MB |
1116 | { |
1117 | return GetItemSkippingDummySpacers( m_tools, (size_t) index ); | |
1118 | } | |
2bda0e17 KB |
1119 | } |
1120 | ||
8a0681f9 | 1121 | void wxToolBar::UpdateSize() |
2bda0e17 | 1122 | { |
0d7ea902 | 1123 | // the toolbar size changed |
bfbb0b4c | 1124 | ::SendMessage(GetHwnd(), TB_AUTOSIZE, 0, 0); |
0d7ea902 VZ |
1125 | |
1126 | // we must also refresh the frame after the toolbar size (possibly) changed | |
8a0681f9 VZ |
1127 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
1128 | if ( frame ) | |
1129 | { | |
f6bcfd97 | 1130 | frame->SendSizeEvent(); |
8a0681f9 | 1131 | } |
2bda0e17 KB |
1132 | } |
1133 | ||
c631abda VZ |
1134 | // ---------------------------------------------------------------------------- |
1135 | // toolbar styles | |
1136 | // --------------------------------------------------------------------------- | |
1137 | ||
1138 | void wxToolBar::SetWindowStyleFlag(long style) | |
1139 | { | |
24998710 VZ |
1140 | // the style bits whose changes force us to recreate the toolbar |
1141 | static const long MASK_NEEDS_RECREATE = wxTB_TEXT | wxTB_NOICONS; | |
c631abda | 1142 | |
24998710 | 1143 | const long styleOld = GetWindowStyle(); |
c631abda | 1144 | |
24998710 | 1145 | wxToolBarBase::SetWindowStyleFlag(style); |
c631abda | 1146 | |
24998710 VZ |
1147 | // don't recreate an empty toolbar: not only this is unnecessary, but it is |
1148 | // also fatal as we'd then try to recreate the toolbar when it's just being | |
1149 | // created | |
1150 | if ( GetToolsCount() && | |
1151 | (style & MASK_NEEDS_RECREATE) != (styleOld & MASK_NEEDS_RECREATE) ) | |
1152 | { | |
1153 | // to remove the text labels, simply re-realizing the toolbar is enough | |
1154 | // but I don't know of any way to add the text to an existing toolbar | |
1155 | // other than by recreating it entirely | |
1156 | Recreate(); | |
c631abda | 1157 | } |
c631abda VZ |
1158 | } |
1159 | ||
1c383dba VZ |
1160 | // ---------------------------------------------------------------------------- |
1161 | // tool state | |
1162 | // ---------------------------------------------------------------------------- | |
1163 | ||
8a0681f9 | 1164 | void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable) |
2bda0e17 | 1165 | { |
8a0681f9 VZ |
1166 | ::SendMessage(GetHwnd(), TB_ENABLEBUTTON, |
1167 | (WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0)); | |
2bda0e17 KB |
1168 | } |
1169 | ||
8a0681f9 | 1170 | void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle) |
2bda0e17 | 1171 | { |
8a0681f9 VZ |
1172 | ::SendMessage(GetHwnd(), TB_CHECKBUTTON, |
1173 | (WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0)); | |
2bda0e17 KB |
1174 | } |
1175 | ||
33ac7e6f | 1176 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
088a95f5 | 1177 | { |
8a0681f9 VZ |
1178 | // VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or |
1179 | // without, so we really need to delete the button and recreate it here | |
1180 | wxFAIL_MSG( _T("not implemented") ); | |
2bda0e17 KB |
1181 | } |
1182 | ||
1c383dba VZ |
1183 | // ---------------------------------------------------------------------------- |
1184 | // event handlers | |
1185 | // ---------------------------------------------------------------------------- | |
2bda0e17 KB |
1186 | |
1187 | // Responds to colour changes, and passes event on to children. | |
8a0681f9 | 1188 | void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 | 1189 | { |
84c5b38d | 1190 | wxRGBToColour(m_backgroundColour, ::GetSysColor(COLOR_BTNFACE)); |
2bda0e17 KB |
1191 | |
1192 | // Remap the buttons | |
8a0681f9 | 1193 | Realize(); |
2bda0e17 | 1194 | |
56bd6aac VZ |
1195 | // Relayout the toolbar |
1196 | int nrows = m_maxRows; | |
1197 | m_maxRows = 0; // otherwise SetRows() wouldn't do anything | |
1198 | SetRows(nrows); | |
1199 | ||
2bda0e17 KB |
1200 | Refresh(); |
1201 | ||
56bd6aac VZ |
1202 | // let the event propagate further |
1203 | event.Skip(); | |
2bda0e17 KB |
1204 | } |
1205 | ||
8a0681f9 | 1206 | void wxToolBar::OnMouseEvent(wxMouseEvent& event) |
e6460682 | 1207 | { |
fe87983b MB |
1208 | if (event.Leaving() && m_pInTool) |
1209 | { | |
1210 | OnMouseEnter( -1 ); | |
1211 | event.Skip(); | |
1212 | return; | |
1213 | } | |
1214 | ||
2334fef6 | 1215 | if ( event.RightDown() ) |
e6460682 | 1216 | { |
2334fef6 VZ |
1217 | // find the tool under the mouse |
1218 | wxCoord x,y; | |
1219 | event.GetPosition(&x, &y); | |
1220 | ||
1221 | wxToolBarToolBase *tool = FindToolForPosition(x, y); | |
1222 | OnRightClick(tool ? tool->GetId() : -1, x, y); | |
e6460682 JS |
1223 | } |
1224 | else | |
1225 | { | |
42e69d6b | 1226 | event.Skip(); |
e6460682 JS |
1227 | } |
1228 | } | |
1229 | ||
0090a153 JS |
1230 | // This handler is required to allow the toolbar to be set to a non-default |
1231 | // colour: for example, when it must blend in with a notebook page. | |
1232 | void wxToolBar::OnEraseBackground(wxEraseEvent& event) | |
1233 | { | |
1234 | wxColour bgCol = GetBackgroundColour(); | |
1235 | if (!bgCol.Ok()) | |
1236 | { | |
1237 | event.Skip(); | |
1238 | return; | |
1239 | } | |
1240 | ||
1241 | // notice that this 'dumb' implementation may cause flicker for some of the | |
1242 | // controls in which case they should intercept wxEraseEvent and process it | |
1243 | // themselves somehow | |
1244 | ||
1245 | RECT rect; | |
1246 | ::GetClientRect(GetHwnd(), &rect); | |
1247 | ||
1248 | HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(bgCol)); | |
1249 | ||
1250 | HDC hdc = GetHdcOf((*event.GetDC())); | |
1251 | ||
1252 | #ifndef __WXWINCE__ | |
1253 | int mode = ::SetMapMode(hdc, MM_TEXT); | |
1254 | #endif | |
1255 | ||
1256 | ::FillRect(hdc, &rect, hBrush); | |
1257 | ::DeleteObject(hBrush); | |
1258 | ||
1259 | #ifndef __WXWINCE__ | |
1260 | ::SetMapMode(hdc, mode); | |
1261 | #endif | |
1262 | } | |
1263 | ||
2eb10e2a | 1264 | bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) |
bdc72a22 | 1265 | { |
3bb63e5c | 1266 | // calculate our minor dimension ourselves - we're confusing the standard |
7509fa8c VZ |
1267 | // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks |
1268 | RECT r; | |
1269 | if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) ) | |
bdc72a22 | 1270 | { |
7509fa8c VZ |
1271 | int w, h; |
1272 | ||
1273 | if ( GetWindowStyle() & wxTB_VERTICAL ) | |
1274 | { | |
1275 | w = r.right - r.left; | |
1276 | if ( m_maxRows ) | |
1277 | { | |
1278 | w *= (m_nButtons + m_maxRows - 1)/m_maxRows; | |
1279 | } | |
1280 | h = HIWORD(lParam); | |
1281 | } | |
1282 | else | |
1283 | { | |
1284 | w = LOWORD(lParam); | |
98b96436 RR |
1285 | if (HasFlag( wxTB_FLAT )) |
1286 | h = r.bottom - r.top - 3; | |
1287 | else | |
1288 | h = r.bottom - r.top; | |
7509fa8c VZ |
1289 | if ( m_maxRows ) |
1290 | { | |
28603488 VZ |
1291 | // FIXME: hardcoded separator line height... |
1292 | h += HasFlag(wxTB_NODIVIDER) ? 4 : 6; | |
7509fa8c VZ |
1293 | h *= m_maxRows; |
1294 | } | |
1295 | } | |
1296 | ||
1297 | if ( MAKELPARAM(w, h) != lParam ) | |
8a0681f9 | 1298 | { |
7509fa8c VZ |
1299 | // size really changed |
1300 | SetSize(w, h); | |
1301 | } | |
1302 | ||
1303 | // message processed | |
bfbb0b4c | 1304 | return true; |
7509fa8c VZ |
1305 | } |
1306 | ||
bfbb0b4c | 1307 | return false; |
7509fa8c VZ |
1308 | } |
1309 | ||
1310 | bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) | |
1311 | { | |
1312 | // erase any dummy separators which we used for aligning the controls if | |
1313 | // any here | |
1314 | ||
1315 | // first of all, do we have any controls at all? | |
222ed1d6 | 1316 | wxToolBarToolsList::compatibility_iterator node; |
7509fa8c VZ |
1317 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
1318 | { | |
1319 | if ( node->GetData()->IsControl() ) | |
1320 | break; | |
1321 | } | |
1322 | ||
1323 | if ( !node ) | |
1324 | { | |
1325 | // no controls, nothing to erase | |
bfbb0b4c | 1326 | return false; |
7509fa8c VZ |
1327 | } |
1328 | ||
1329 | // prepare the DC on which we'll be drawing | |
1330 | wxClientDC dc(this); | |
1331 | dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID)); | |
1332 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1333 | ||
1334 | RECT r; | |
bfbb0b4c | 1335 | if ( !::GetUpdateRect(GetHwnd(), &r, FALSE) ) |
7509fa8c VZ |
1336 | { |
1337 | // nothing to redraw anyhow | |
bfbb0b4c | 1338 | return false; |
7509fa8c VZ |
1339 | } |
1340 | ||
1341 | wxRect rectUpdate; | |
1342 | wxCopyRECTToRect(r, rectUpdate); | |
1343 | ||
1344 | dc.SetClippingRegion(rectUpdate); | |
8a0681f9 | 1345 | |
7509fa8c VZ |
1346 | // draw the toolbar tools, separators &c normally |
1347 | wxControl::MSWWindowProc(WM_PAINT, wParam, lParam); | |
1348 | ||
1349 | // for each control in the toolbar find all the separators intersecting it | |
1350 | // and erase them | |
1351 | // | |
1352 | // NB: this is really the only way to do it as we don't know if a separator | |
1353 | // corresponds to a control (i.e. is a dummy one) or a real one | |
1354 | // otherwise | |
1355 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
1356 | { | |
1357 | wxToolBarToolBase *tool = node->GetData(); | |
1358 | if ( tool->IsControl() ) | |
1359 | { | |
1360 | // get the control rect in our client coords | |
1361 | wxControl *control = tool->GetControl(); | |
1362 | wxRect rectCtrl = control->GetRect(); | |
7509fa8c VZ |
1363 | |
1364 | // iterate over all buttons | |
1365 | TBBUTTON tbb; | |
1366 | int count = ::SendMessage(GetHwnd(), TB_BUTTONCOUNT, 0, 0); | |
1367 | for ( int n = 0; n < count; n++ ) | |
8a0681f9 | 1368 | { |
7509fa8c VZ |
1369 | // is it a separator? |
1370 | if ( !::SendMessage(GetHwnd(), TB_GETBUTTON, | |
1371 | n, (LPARAM)&tbb) ) | |
8a0681f9 | 1372 | { |
7509fa8c VZ |
1373 | wxLogDebug(_T("TB_GETBUTTON failed?")); |
1374 | ||
1375 | continue; | |
8a0681f9 | 1376 | } |
7509fa8c VZ |
1377 | |
1378 | if ( tbb.fsStyle != TBSTYLE_SEP ) | |
1379 | continue; | |
1380 | ||
1381 | // get the bounding rect of the separator | |
1382 | RECT r; | |
1383 | if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, | |
1384 | n, (LPARAM)&r) ) | |
8a0681f9 | 1385 | { |
7509fa8c VZ |
1386 | wxLogDebug(_T("TB_GETITEMRECT failed?")); |
1387 | ||
1388 | continue; | |
8a0681f9 | 1389 | } |
8a0681f9 | 1390 | |
7509fa8c VZ |
1391 | // does it intersect the control? |
1392 | wxRect rectItem; | |
1393 | wxCopyRECTToRect(r, rectItem); | |
1394 | if ( rectCtrl.Intersects(rectItem) ) | |
1395 | { | |
1396 | // yes, do erase it! | |
1397 | dc.DrawRectangle(rectItem); | |
bfbb0b4c | 1398 | |
229de929 JS |
1399 | // Necessary in case we use a no-paint-on-size |
1400 | // style in the parent: the controls can disappear | |
bfbb0b4c | 1401 | control->Refresh(false); |
7509fa8c | 1402 | } |
8a0681f9 | 1403 | } |
8a0681f9 | 1404 | } |
bdc72a22 | 1405 | } |
7509fa8c | 1406 | |
bfbb0b4c | 1407 | return true; |
7509fa8c VZ |
1408 | } |
1409 | ||
2eb10e2a | 1410 | void wxToolBar::HandleMouseMove(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) |
7509fa8c VZ |
1411 | { |
1412 | wxCoord x = GET_X_LPARAM(lParam), | |
1413 | y = GET_Y_LPARAM(lParam); | |
1414 | wxToolBarToolBase* tool = FindToolForPosition( x, y ); | |
1415 | ||
1416 | // cursor left current tool | |
1417 | if( tool != m_pInTool && !tool ) | |
a8945eef | 1418 | { |
7509fa8c VZ |
1419 | m_pInTool = 0; |
1420 | OnMouseEnter( -1 ); | |
1421 | } | |
a8945eef | 1422 | |
7509fa8c VZ |
1423 | // cursor entered a tool |
1424 | if( tool != m_pInTool && tool ) | |
1425 | { | |
1426 | m_pInTool = tool; | |
1427 | OnMouseEnter( tool->GetId() ); | |
1428 | } | |
1429 | } | |
a8945eef | 1430 | |
c140b7e7 | 1431 | WXLRESULT wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
7509fa8c VZ |
1432 | { |
1433 | switch ( nMsg ) | |
1434 | { | |
1435 | case WM_SIZE: | |
1436 | if ( HandleSize(wParam, lParam) ) | |
1437 | return 0; | |
1438 | break; | |
1439 | ||
1440 | case WM_MOUSEMOVE: | |
1441 | // we don't handle mouse moves, so always pass the message to | |
1442 | // wxControl::MSWWindowProc | |
1443 | HandleMouseMove(wParam, lParam); | |
1444 | break; | |
a8945eef | 1445 | |
7509fa8c VZ |
1446 | case WM_PAINT: |
1447 | if ( HandlePaint(wParam, lParam) ) | |
1448 | return 0; | |
a8945eef | 1449 | } |
bdc72a22 | 1450 | |
8a0681f9 | 1451 | return wxControl::MSWWindowProc(nMsg, wParam, lParam); |
bdc72a22 VZ |
1452 | } |
1453 | ||
1c383dba VZ |
1454 | // ---------------------------------------------------------------------------- |
1455 | // private functions | |
1456 | // ---------------------------------------------------------------------------- | |
1457 | ||
566fb299 | 1458 | WXHBITMAP wxToolBar::MapBitmap(WXHBITMAP bitmap, int width, int height) |
2bda0e17 | 1459 | { |
566fb299 | 1460 | MemoryHDC hdcMem; |
56bd6aac | 1461 | |
566fb299 | 1462 | if ( !hdcMem ) |
5e68f8f3 | 1463 | { |
566fb299 VZ |
1464 | wxLogLastError(_T("CreateCompatibleDC")); |
1465 | ||
1466 | return bitmap; | |
5e68f8f3 | 1467 | } |
56bd6aac | 1468 | |
566fb299 | 1469 | SelectInHDC bmpInHDC(hdcMem, (HBITMAP)bitmap); |
56bd6aac | 1470 | |
566fb299 | 1471 | if ( !bmpInHDC ) |
5e68f8f3 | 1472 | { |
566fb299 VZ |
1473 | wxLogLastError(_T("SelectObject")); |
1474 | ||
1475 | return bitmap; | |
1476 | } | |
56bd6aac | 1477 | |
90c1530a VZ |
1478 | wxCOLORMAP *cmap = wxGetStdColourMap(); |
1479 | ||
684c68fd VZ |
1480 | for ( int i = 0; i < width; i++ ) |
1481 | { | |
1482 | for ( int j = 0; j < height; j++ ) | |
1483 | { | |
1484 | COLORREF pixel = ::GetPixel(hdcMem, i, j); | |
1485 | ||
90c1530a | 1486 | for ( size_t k = 0; k < wxSTD_COL_MAX; k++ ) |
684c68fd | 1487 | { |
90c1530a | 1488 | COLORREF col = cmap[k].from; |
684c68fd VZ |
1489 | if ( abs(GetRValue(pixel) - GetRValue(col)) < 10 && |
1490 | abs(GetGValue(pixel) - GetGValue(col)) < 10 && | |
1491 | abs(GetBValue(pixel) - GetBValue(col)) < 10 ) | |
1492 | { | |
90c1530a | 1493 | ::SetPixel(hdcMem, i, j, cmap[k].to); |
684c68fd VZ |
1494 | break; |
1495 | } | |
1496 | } | |
1497 | } | |
1498 | } | |
3a3898f8 VZ |
1499 | |
1500 | return bitmap; | |
1501 | ||
566fb299 VZ |
1502 | // VZ: I leave here my attempts to map the bitmap to the system colours |
1503 | // faster by using BitBlt() even though it's broken currently - but | |
1504 | // maybe someone else can finish it? It should be faster than iterating | |
1505 | // over all pixels... | |
3a3898f8 | 1506 | #if 0 |
566fb299 VZ |
1507 | MemoryHDC hdcMask, hdcDst; |
1508 | if ( !hdcMask || !hdcDst ) | |
1509 | { | |
1510 | wxLogLastError(_T("CreateCompatibleDC")); | |
56bd6aac | 1511 | |
566fb299 | 1512 | return bitmap; |
2bda0e17 | 1513 | } |
2bda0e17 | 1514 | |
566fb299 VZ |
1515 | // create the target bitmap |
1516 | HBITMAP hbmpDst = ::CreateCompatibleBitmap(hdcDst, width, height); | |
1517 | if ( !hbmpDst ) | |
1518 | { | |
1519 | wxLogLastError(_T("CreateCompatibleBitmap")); | |
1520 | ||
1521 | return bitmap; | |
1522 | } | |
1523 | ||
1524 | // create the monochrome mask bitmap | |
1525 | HBITMAP hbmpMask = ::CreateBitmap(width, height, 1, 1, 0); | |
1526 | if ( !hbmpMask ) | |
1527 | { | |
1528 | wxLogLastError(_T("CreateBitmap(mono)")); | |
1529 | ||
1530 | ::DeleteObject(hbmpDst); | |
1531 | ||
1532 | return bitmap; | |
1533 | } | |
1534 | ||
1535 | SelectInHDC bmpInDst(hdcDst, hbmpDst), | |
1536 | bmpInMask(hdcMask, hbmpMask); | |
1537 | ||
1538 | // for each colour: | |
1539 | for ( n = 0; n < NUM_OF_MAPPED_COLOURS; n++ ) | |
1540 | { | |
1541 | // create the mask for this colour | |
1542 | ::SetBkColor(hdcMem, ColorMap[n].from); | |
1543 | ::BitBlt(hdcMask, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); | |
1544 | ||
1545 | // replace this colour with the target one in the dst bitmap | |
1546 | HBRUSH hbr = ::CreateSolidBrush(ColorMap[n].to); | |
1547 | HGDIOBJ hbrOld = ::SelectObject(hdcDst, hbr); | |
2bda0e17 | 1548 | |
566fb299 VZ |
1549 | ::MaskBlt(hdcDst, 0, 0, width, height, |
1550 | hdcMem, 0, 0, | |
1551 | hbmpMask, 0, 0, | |
1552 | MAKEROP4(PATCOPY, SRCCOPY)); | |
1553 | ||
1554 | (void)::SelectObject(hdcDst, hbrOld); | |
1555 | ::DeleteObject(hbr); | |
1556 | } | |
1557 | ||
1558 | ::DeleteObject((HBITMAP)bitmap); | |
1559 | ||
1560 | return (WXHBITMAP)hbmpDst; | |
3a3898f8 | 1561 | #endif // 0 |
566fb299 | 1562 | } |
2bda0e17 | 1563 | |
8a0681f9 | 1564 | #endif // wxUSE_TOOLBAR && Win95 |
33ac7e6f | 1565 |