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