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