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