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