]>
Commit | Line | Data |
---|---|---|
39d2f9a7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
a71d815b | 2 | // Name: src/msw/wince/tbarwce.cpp |
39d2f9a7 JS |
3 | // Purpose: wxToolBar for Windows CE |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2003-07-12 | |
39d2f9a7 | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
39d2f9a7 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
39d2f9a7 JS |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
ad9835c9 WS |
26 | // Use the WinCE-specific toolbar only if we're either compiling |
27 | // with a WinCE earlier than 4, or we wish to emulate a PocketPC-style UI | |
28 | #if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__)) | |
29 | ||
4e3e485b WS |
30 | #include "wx/toolbar.h" |
31 | ||
39d2f9a7 | 32 | #ifndef WX_PRECOMP |
57bd4c60 | 33 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
ad9835c9 | 34 | #include "wx/dynarray.h" |
39d2f9a7 JS |
35 | #include "wx/frame.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
39d2f9a7 JS |
38 | #include "wx/settings.h" |
39 | #include "wx/bitmap.h" | |
40 | #include "wx/dcmemory.h" | |
41 | #include "wx/control.h" | |
42 | #endif | |
43 | ||
f172cb82 | 44 | #if !defined(__GNUWIN32__) |
39d2f9a7 JS |
45 | #include "malloc.h" |
46 | #endif | |
47 | ||
48 | #include "wx/msw/private.h" | |
49 | #include <windows.h> | |
50 | #include <windowsx.h> | |
51 | #include <tchar.h> | |
52 | #include <ole2.h> | |
eae4425d | 53 | #include <shellapi.h> |
3d487566 | 54 | #if defined(WINCE_WITHOUT_COMMANDBAR) |
2d36b3d8 | 55 | #include <aygshell.h> |
77c1fa98 | 56 | #include "wx/msw/wince/resources.h" |
2d36b3d8 JS |
57 | #endif |
58 | #include "wx/msw/wince/missing.h" | |
39d2f9a7 JS |
59 | |
60 | #include "wx/msw/winundef.h" | |
61 | ||
a9102b36 | 62 | #if !defined(__SMARTPHONE__) |
39d2f9a7 | 63 | |
a9102b36 JS |
64 | ///////////// This implementation is for PocketPC. |
65 | ///////////// See later for the Smartphone dummy toolbar class. | |
39d2f9a7 JS |
66 | |
67 | // ---------------------------------------------------------------------------- | |
a9102b36 | 68 | // Event table |
39d2f9a7 JS |
69 | // ---------------------------------------------------------------------------- |
70 | ||
a9102b36 | 71 | IMPLEMENT_DYNAMIC_CLASS(wxToolMenuBar, wxToolBar) |
39d2f9a7 | 72 | |
a9102b36 | 73 | BEGIN_EVENT_TABLE(wxToolMenuBar, wxToolBar) |
39d2f9a7 JS |
74 | END_EVENT_TABLE() |
75 | ||
76 | // ---------------------------------------------------------------------------- | |
77 | // private classes | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
a9102b36 | 80 | class wxToolMenuBarTool : public wxToolBarToolBase |
39d2f9a7 JS |
81 | { |
82 | public: | |
a9102b36 | 83 | wxToolMenuBarTool(wxToolBar *tbar, |
39d2f9a7 JS |
84 | int id, |
85 | const wxString& label, | |
86 | const wxBitmap& bmpNormal, | |
87 | const wxBitmap& bmpDisabled, | |
88 | wxItemKind kind, | |
89 | wxObject *clientData, | |
90 | const wxString& shortHelp, | |
91 | const wxString& longHelp) | |
92 | : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind, | |
93 | clientData, shortHelp, longHelp) | |
94 | { | |
95 | m_nSepCount = 0; | |
ac1f013c | 96 | m_bitmapIndex = -1; |
39d2f9a7 JS |
97 | } |
98 | ||
96360917 VZ |
99 | wxToolMenuBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) |
100 | : wxToolBarToolBase(tbar, control, label) | |
39d2f9a7 JS |
101 | { |
102 | m_nSepCount = 1; | |
ac1f013c | 103 | m_bitmapIndex = -1; |
39d2f9a7 JS |
104 | } |
105 | ||
106 | virtual void SetLabel(const wxString& label) | |
107 | { | |
108 | if ( label == m_label ) | |
109 | return; | |
110 | ||
111 | wxToolBarToolBase::SetLabel(label); | |
112 | ||
113 | // we need to update the label shown in the toolbar because it has a | |
114 | // pointer to the internal buffer of the old label | |
115 | // | |
116 | // TODO: use TB_SETBUTTONINFO | |
117 | } | |
118 | ||
119 | // set/get the number of separators which we use to cover the space used by | |
120 | // a control in the toolbar | |
121 | void SetSeparatorsCount(size_t count) { m_nSepCount = count; } | |
122 | size_t GetSeparatorsCount() const { return m_nSepCount; } | |
a71d815b | 123 | |
ac1f013c JS |
124 | void SetBitmapIndex(int idx) { m_bitmapIndex = idx; } |
125 | int GetBitmapIndex() const { return m_bitmapIndex; } | |
39d2f9a7 JS |
126 | |
127 | private: | |
128 | size_t m_nSepCount; | |
ac1f013c | 129 | int m_bitmapIndex; |
39d2f9a7 JS |
130 | }; |
131 | ||
132 | ||
133 | // ============================================================================ | |
134 | // implementation | |
135 | // ============================================================================ | |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // wxToolBarTool | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
a9102b36 | 141 | wxToolBarToolBase *wxToolMenuBar::CreateTool(int id, |
39d2f9a7 JS |
142 | const wxString& label, |
143 | const wxBitmap& bmpNormal, | |
144 | const wxBitmap& bmpDisabled, | |
145 | wxItemKind kind, | |
146 | wxObject *clientData, | |
147 | const wxString& shortHelp, | |
148 | const wxString& longHelp) | |
149 | { | |
a9102b36 | 150 | return new wxToolMenuBarTool(this, id, label, bmpNormal, bmpDisabled, kind, |
39d2f9a7 JS |
151 | clientData, shortHelp, longHelp); |
152 | } | |
153 | ||
96360917 VZ |
154 | wxToolBarToolBase * |
155 | wxToolMenuBar::CreateTool(wxControl *control, const wxString& label) | |
39d2f9a7 | 156 | { |
96360917 | 157 | return new wxToolMenuBarTool(this, control, label); |
39d2f9a7 JS |
158 | } |
159 | ||
160 | // ---------------------------------------------------------------------------- | |
161 | // wxToolBar construction | |
162 | // ---------------------------------------------------------------------------- | |
163 | ||
a9102b36 | 164 | void wxToolMenuBar::Init() |
39d2f9a7 | 165 | { |
a9102b36 | 166 | wxToolBar::Init(); |
a71d815b WS |
167 | |
168 | m_nButtons = 0; | |
39d2f9a7 JS |
169 | m_menuBar = NULL; |
170 | } | |
171 | ||
a9102b36 | 172 | bool wxToolMenuBar::Create(wxWindow *parent, |
39d2f9a7 JS |
173 | wxWindowID id, |
174 | const wxPoint& pos, | |
175 | const wxSize& size, | |
176 | long style, | |
177 | const wxString& name, | |
178 | wxMenuBar* menuBar) | |
179 | { | |
180 | // common initialisation | |
181 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
16640ba2 | 182 | return false; |
39d2f9a7 JS |
183 | |
184 | // MSW-specific initialisation | |
185 | if ( !MSWCreateToolbar(pos, size, menuBar) ) | |
16640ba2 | 186 | return false; |
39d2f9a7 JS |
187 | |
188 | // set up the colors and fonts | |
189 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); | |
190 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
191 | ||
39fc096d | 192 | return true; |
39d2f9a7 JS |
193 | } |
194 | ||
272be120 VZ |
195 | bool wxToolMenuBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), |
196 | const wxSize& WXUNUSED(size), | |
197 | wxMenuBar *menuBar) | |
39d2f9a7 JS |
198 | { |
199 | SetMenuBar(menuBar); | |
200 | if (m_menuBar) | |
201 | m_menuBar->SetToolBar(this); | |
202 | ||
272be120 | 203 | HWND hwndParent = GetHwndOf(GetParent()); |
9a83f860 | 204 | wxCHECK_MSG( hwndParent, false, wxT("should have valid parent HWND") ); |
272be120 | 205 | |
3d487566 | 206 | #if defined(WINCE_WITHOUT_COMMANDBAR) |
77c1fa98 | 207 | // create the menubar. |
272be120 | 208 | WinStruct<SHMENUBARINFO> mbi; |
39fc096d | 209 | |
272be120 | 210 | mbi.hwndParent = hwndParent; |
77c1fa98 | 211 | mbi.nToolBarId = wxIDM_SHMENU; |
39d2f9a7 | 212 | mbi.hInstRes = wxGetInstance(); |
39fc096d | 213 | |
77c1fa98 | 214 | if ( !SHCreateMenuBar(&mbi) ) |
39d2f9a7 | 215 | { |
9a83f860 | 216 | wxFAIL_MSG( wxT("SHCreateMenuBar failed") ); |
16640ba2 | 217 | return false; |
39d2f9a7 | 218 | } |
39fc096d | 219 | |
39d2f9a7 | 220 | SetHWND((WXHWND) mbi.hwndMB); |
960b193e | 221 | #else |
272be120 | 222 | HWND hWnd = CommandBar_Create(wxGetInstance(), hwndParent, GetId()); |
960b193e | 223 | SetHWND((WXHWND) hWnd); |
2d36b3d8 JS |
224 | #endif |
225 | ||
77ffb593 | 226 | // install wxWidgets window proc for this window |
39d2f9a7 JS |
227 | SubclassWin(m_hWnd); |
228 | ||
229 | if (menuBar) | |
230 | menuBar->Create(); | |
39fc096d WS |
231 | |
232 | return true; | |
39d2f9a7 JS |
233 | } |
234 | ||
a9102b36 | 235 | void wxToolMenuBar::Recreate() |
39d2f9a7 | 236 | { |
a9102b36 | 237 | // TODO |
39d2f9a7 JS |
238 | } |
239 | ||
a9102b36 | 240 | wxToolMenuBar::~wxToolMenuBar() |
39d2f9a7 | 241 | { |
bf95a04f JS |
242 | if (GetMenuBar()) |
243 | GetMenuBar()->SetToolBar(NULL); | |
39d2f9a7 JS |
244 | } |
245 | ||
246 | // Return HMENU for the menu associated with the commandbar | |
a9102b36 | 247 | WXHMENU wxToolMenuBar::GetHMenu() |
39d2f9a7 | 248 | { |
77c1fa98 | 249 | #if !defined(__HANDHELDPC__) |
39d2f9a7 JS |
250 | if (GetHWND()) |
251 | { | |
77c1fa98 | 252 | return (WXHMENU)::SendMessage(GetHwnd(), SHCMBM_GETMENU, 0, 0); |
39d2f9a7 | 253 | } |
781a24e8 | 254 | #endif |
77c1fa98 VZ |
255 | |
256 | return NULL; | |
39d2f9a7 JS |
257 | } |
258 | ||
39d2f9a7 JS |
259 | // ---------------------------------------------------------------------------- |
260 | // adding/removing tools | |
261 | // ---------------------------------------------------------------------------- | |
262 | ||
a9102b36 | 263 | bool wxToolMenuBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
39d2f9a7 JS |
264 | { |
265 | // nothing special to do here - we really create the toolbar buttons in | |
266 | // Realize() later | |
267 | tool->Attach(this); | |
268 | ||
39fc096d | 269 | return true; |
39d2f9a7 JS |
270 | } |
271 | ||
a9102b36 | 272 | bool wxToolMenuBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) |
39d2f9a7 | 273 | { |
aa838aed JS |
274 | // Skip over the menus |
275 | if (GetMenuBar()) | |
276 | pos += GetMenuBar()->GetMenuCount(); | |
03647350 | 277 | |
39d2f9a7 JS |
278 | // the main difficulty we have here is with the controls in the toolbars: |
279 | // as we (sometimes) use several separators to cover up the space used by | |
280 | // them, the indices are not the same for us and the toolbar | |
281 | ||
282 | // first determine the position of the first button to delete: it may be | |
283 | // different from pos if we use several separators to cover the space used | |
284 | // by a control | |
285 | wxToolBarToolsList::compatibility_iterator node; | |
286 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
287 | { | |
288 | wxToolBarToolBase *tool2 = node->GetData(); | |
289 | if ( tool2 == tool ) | |
290 | { | |
291 | // let node point to the next node in the list | |
292 | node = node->GetNext(); | |
293 | ||
294 | break; | |
295 | } | |
296 | ||
297 | if ( tool2->IsControl() ) | |
298 | { | |
a9102b36 | 299 | pos += ((wxToolMenuBarTool *)tool2)->GetSeparatorsCount() - 1; |
39d2f9a7 JS |
300 | } |
301 | } | |
302 | ||
303 | // now determine the number of buttons to delete and the area taken by them | |
304 | size_t nButtonsToDelete = 1; | |
305 | ||
306 | // get the size of the button we're going to delete | |
307 | RECT r; | |
308 | if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) ) | |
309 | { | |
9a83f860 | 310 | wxLogLastError(wxT("TB_GETITEMRECT")); |
39d2f9a7 JS |
311 | } |
312 | ||
313 | int width = r.right - r.left; | |
314 | ||
315 | if ( tool->IsControl() ) | |
316 | { | |
a9102b36 | 317 | nButtonsToDelete = ((wxToolMenuBarTool *)tool)->GetSeparatorsCount(); |
39d2f9a7 JS |
318 | |
319 | width *= nButtonsToDelete; | |
320 | } | |
321 | ||
322 | // do delete all buttons | |
323 | m_nButtons -= nButtonsToDelete; | |
324 | while ( nButtonsToDelete-- > 0 ) | |
325 | { | |
326 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) ) | |
327 | { | |
328 | wxLogLastError(wxT("TB_DELETEBUTTON")); | |
329 | ||
16640ba2 | 330 | return false; |
39d2f9a7 JS |
331 | } |
332 | } | |
333 | ||
334 | tool->Detach(); | |
335 | ||
336 | // and finally reposition all the controls after this button (the toolbar | |
337 | // takes care of all normal items) | |
338 | for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) | |
339 | { | |
340 | wxToolBarToolBase *tool2 = node->GetData(); | |
341 | if ( tool2->IsControl() ) | |
342 | { | |
343 | int x; | |
344 | wxControl *control = tool2->GetControl(); | |
345 | control->GetPosition(&x, NULL); | |
39fc096d | 346 | control->Move(x - width, wxDefaultCoord); |
39d2f9a7 JS |
347 | } |
348 | } | |
349 | ||
39fc096d | 350 | return true; |
39d2f9a7 JS |
351 | } |
352 | ||
4012b958 | 353 | bool wxToolMenuBar::Realize() |
39d2f9a7 JS |
354 | { |
355 | const size_t nTools = GetToolsCount(); | |
356 | if ( nTools == 0 ) | |
357 | { | |
358 | // nothing to do | |
39fc096d | 359 | return true; |
39d2f9a7 JS |
360 | } |
361 | ||
39d2f9a7 JS |
362 | #if 0 |
363 | // delete all old buttons, if any | |
364 | for ( size_t pos = 0; pos < m_nButtons; pos++ ) | |
365 | { | |
366 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) | |
367 | { | |
368 | wxLogDebug(wxT("TB_DELETEBUTTON failed")); | |
369 | } | |
370 | } | |
7010702f | 371 | #endif // 0 |
39d2f9a7 | 372 | |
16640ba2 | 373 | bool lastWasRadio = false; |
3d2846fc | 374 | wxToolBarToolsList::compatibility_iterator node; |
39d2f9a7 JS |
375 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) |
376 | { | |
a9102b36 | 377 | wxToolMenuBarTool *tool = (wxToolMenuBarTool*) node->GetData(); |
39d2f9a7 | 378 | |
ac1f013c | 379 | TBBUTTON buttons[1] ; |
bf95a04f | 380 | |
ac1f013c | 381 | TBBUTTON& button = buttons[0]; |
39d2f9a7 JS |
382 | |
383 | wxZeroMemory(button); | |
384 | ||
16640ba2 | 385 | bool isRadio = false; |
39d2f9a7 JS |
386 | switch ( tool->GetStyle() ) |
387 | { | |
388 | case wxTOOL_STYLE_CONTROL: | |
389 | button.idCommand = tool->GetId(); | |
390 | // fall through: create just a separator too | |
4012b958 | 391 | // TODO: controls are not yet supported on wxToolMenuBar. |
39d2f9a7 JS |
392 | |
393 | case wxTOOL_STYLE_SEPARATOR: | |
394 | button.fsState = TBSTATE_ENABLED; | |
395 | button.fsStyle = TBSTYLE_SEP; | |
396 | break; | |
397 | ||
398 | case wxTOOL_STYLE_BUTTON: | |
a71d815b | 399 | |
39d2f9a7 JS |
400 | if ( HasFlag(wxTB_TEXT) ) |
401 | { | |
402 | const wxString& label = tool->GetLabel(); | |
403 | if ( !label.empty() ) | |
404 | { | |
017dc06b | 405 | button.iString = (int) wxMSW_CONV_LPCTSTR(label); |
39d2f9a7 JS |
406 | } |
407 | } | |
408 | ||
ac1f013c JS |
409 | const wxBitmap& bmp = tool->GetNormalBitmap(); |
410 | ||
411 | wxBitmap bmpToUse = bmp; | |
412 | ||
ec5f0c24 | 413 | if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16 || bmp.GetMask() != NULL) |
ac1f013c JS |
414 | { |
415 | wxMemoryDC memDC; | |
416 | wxBitmap b(16,16); | |
417 | memDC.SelectObject(b); | |
4012b958 JS |
418 | wxColour col = wxColour(192,192,192); |
419 | memDC.SetBackground(wxBrush(col)); | |
ac1f013c JS |
420 | memDC.Clear(); |
421 | int x = (16 - bmp.GetWidth())/2; | |
422 | int y = (16 - bmp.GetHeight())/2; | |
423 | memDC.DrawBitmap(bmp, x, y, true); | |
424 | memDC.SelectObject(wxNullBitmap); | |
425 | ||
426 | bmpToUse = b; | |
427 | tool->SetNormalBitmap(b); | |
428 | } | |
429 | ||
430 | int n = 0; | |
a1b806b9 | 431 | if ( bmpToUse.IsOk() ) |
bf95a04f | 432 | { |
ac1f013c JS |
433 | n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(), |
434 | 1, 16, 16 ); | |
bf95a04f | 435 | } |
ac1f013c JS |
436 | |
437 | button.idCommand = tool->GetId(); | |
438 | button.iBitmap = n; | |
39d2f9a7 JS |
439 | |
440 | if ( tool->IsEnabled() ) | |
441 | button.fsState |= TBSTATE_ENABLED; | |
442 | if ( tool->IsToggled() ) | |
443 | button.fsState |= TBSTATE_CHECKED; | |
444 | ||
445 | switch ( tool->GetKind() ) | |
446 | { | |
447 | case wxITEM_RADIO: | |
448 | button.fsStyle = TBSTYLE_CHECKGROUP; | |
449 | ||
450 | if ( !lastWasRadio ) | |
451 | { | |
452 | // the first item in the radio group is checked by | |
453 | // default to be consistent with wxGTK and the menu | |
454 | // radio items | |
455 | button.fsState |= TBSTATE_CHECKED; | |
456 | ||
39fc096d | 457 | tool->Toggle(true); |
39d2f9a7 JS |
458 | } |
459 | ||
39fc096d | 460 | isRadio = true; |
39d2f9a7 JS |
461 | break; |
462 | ||
463 | case wxITEM_CHECK: | |
464 | button.fsStyle = TBSTYLE_CHECK; | |
465 | break; | |
466 | ||
467 | default: | |
9a83f860 | 468 | wxFAIL_MSG( wxT("unexpected toolbar button kind") ); |
39d2f9a7 JS |
469 | // fall through |
470 | ||
471 | case wxITEM_NORMAL: | |
472 | button.fsStyle = TBSTYLE_BUTTON; | |
473 | } | |
39d2f9a7 JS |
474 | break; |
475 | } | |
476 | ||
30b9db02 VZ |
477 | if ( !::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons ) ) |
478 | { | |
479 | wxFAIL_MSG( wxT("Could not add toolbar button.")); | |
480 | } | |
7010702f | 481 | |
ac1f013c | 482 | lastWasRadio = isRadio; |
39d2f9a7 | 483 | } |
39d2f9a7 | 484 | |
7010702f | 485 | return true; |
39d2f9a7 JS |
486 | } |
487 | ||
0edeeb6d | 488 | bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) |
39d2f9a7 | 489 | { |
0edeeb6d VZ |
490 | const int id = (signed short)id_; |
491 | ||
492 | wxToolBarToolBase *tool = FindById(id); | |
39d2f9a7 JS |
493 | if ( !tool ) |
494 | { | |
869c9290 VZ |
495 | bool checked = false; |
496 | if ( m_menuBar ) | |
c616c2e8 WS |
497 | { |
498 | wxMenuItem *item = m_menuBar->FindItem(id); | |
869c9290 | 499 | if ( item && item->IsCheckable() ) |
c616c2e8 WS |
500 | { |
501 | item->Toggle(); | |
869c9290 | 502 | checked = item->IsChecked(); |
c616c2e8 WS |
503 | } |
504 | } | |
505 | ||
ce7fe42e | 506 | wxCommandEvent event(wxEVT_MENU); |
39d2f9a7 JS |
507 | event.SetEventObject(this); |
508 | event.SetId(id); | |
869c9290 | 509 | event.SetInt(checked); |
39d2f9a7 JS |
510 | |
511 | return GetEventHandler()->ProcessEvent(event); | |
512 | } | |
513 | ||
514 | if ( tool->CanBeToggled() ) | |
515 | { | |
516 | LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0); | |
517 | tool->Toggle((state & TBSTATE_CHECKED) != 0); | |
518 | } | |
519 | ||
520 | bool toggled = tool->IsToggled(); | |
521 | ||
522 | // avoid sending the event when a radio button is released, this is not | |
523 | // interesting | |
524 | if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled ) | |
525 | { | |
526 | // OnLeftClick() can veto the button state change - for buttons which | |
4c51a665 | 527 | // may be toggled only, of course. |
39d2f9a7 JS |
528 | if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) |
529 | { | |
530 | // revert back | |
531 | toggled = !toggled; | |
532 | tool->SetToggle(toggled); | |
533 | ||
534 | ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); | |
535 | } | |
536 | } | |
537 | ||
39fc096d | 538 | return true; |
39d2f9a7 JS |
539 | } |
540 | ||
ea9aa80e JS |
541 | WXLRESULT wxToolMenuBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
542 | { | |
543 | switch ( nMsg ) | |
544 | { | |
545 | case WM_SIZE: | |
546 | break; | |
547 | ||
548 | case WM_MOUSEMOVE: | |
549 | // we don't handle mouse moves, so always pass the message to | |
550 | // wxControl::MSWWindowProc | |
551 | HandleMouseMove(wParam, lParam); | |
552 | break; | |
553 | ||
554 | case WM_PAINT: | |
555 | break; | |
556 | } | |
557 | ||
625b3cf1 | 558 | return MSWDefWindowProc(nMsg, wParam, lParam); |
ea9aa80e JS |
559 | } |
560 | ||
561 | ||
39d2f9a7 | 562 | #else |
a9102b36 JS |
563 | |
564 | ////////////// For Smartphone | |
39d2f9a7 JS |
565 | |
566 | // ---------------------------------------------------------------------------- | |
a9102b36 | 567 | // Event table |
39d2f9a7 JS |
568 | // ---------------------------------------------------------------------------- |
569 | ||
a9102b36 | 570 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) |
39d2f9a7 | 571 | |
a9102b36 JS |
572 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) |
573 | END_EVENT_TABLE() | |
39d2f9a7 | 574 | |
a9102b36 JS |
575 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
576 | const wxString& label, | |
577 | const wxBitmap& bmpNormal, | |
578 | const wxBitmap& bmpDisabled, | |
579 | wxItemKind kind, | |
580 | wxObject *clientData, | |
581 | const wxString& shortHelp, | |
582 | const wxString& longHelp) | |
39d2f9a7 | 583 | { |
a9102b36 JS |
584 | return new wxToolBarToolBase(this, id, label, bmpNormal, bmpDisabled, kind, |
585 | clientData, shortHelp, longHelp); | |
39d2f9a7 JS |
586 | } |
587 | ||
a9102b36 | 588 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) |
39d2f9a7 | 589 | { |
a9102b36 | 590 | return new wxToolBarToolBase(this, control); |
39d2f9a7 JS |
591 | } |
592 | ||
a9102b36 JS |
593 | bool wxToolBar::Create(wxWindow *parent, |
594 | wxWindowID WXUNUSED(id), | |
595 | const wxPoint& WXUNUSED(pos), | |
596 | const wxSize& WXUNUSED(size), | |
597 | long style, | |
598 | const wxString& name) | |
39d2f9a7 | 599 | { |
a9102b36 JS |
600 | // TODO: we may need to make this a dummy hidden window to |
601 | // satisfy other parts of wxWidgets. | |
39d2f9a7 | 602 | |
a9102b36 | 603 | parent->AddChild(this); |
a71d815b | 604 | |
a9102b36 JS |
605 | SetWindowStyle(style); |
606 | SetName(name); | |
a71d815b | 607 | |
a9102b36 | 608 | return true; |
39d2f9a7 JS |
609 | } |
610 | ||
a9102b36 JS |
611 | // ---------------------------------------------------------------------------- |
612 | // adding/removing tools | |
613 | // ---------------------------------------------------------------------------- | |
39d2f9a7 | 614 | |
a9102b36 JS |
615 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
616 | { | |
617 | tool->Attach(this); | |
618 | return true; | |
39d2f9a7 JS |
619 | } |
620 | ||
a9102b36 | 621 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
39d2f9a7 | 622 | { |
a9102b36 JS |
623 | tool->Detach(); |
624 | return true; | |
39d2f9a7 JS |
625 | } |
626 | ||
a9102b36 | 627 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) const |
39d2f9a7 | 628 | { |
a9102b36 | 629 | return NULL; |
39d2f9a7 JS |
630 | } |
631 | ||
632 | // ---------------------------------------------------------------------------- | |
633 | // tool state | |
634 | // ---------------------------------------------------------------------------- | |
635 | ||
a9102b36 | 636 | void wxToolBar::DoEnableTool(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(enable)) |
39d2f9a7 | 637 | { |
39d2f9a7 JS |
638 | } |
639 | ||
a9102b36 | 640 | void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) |
39d2f9a7 | 641 | { |
39d2f9a7 JS |
642 | } |
643 | ||
644 | void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) | |
645 | { | |
9a83f860 | 646 | wxFAIL_MSG( wxT("not implemented") ); |
39d2f9a7 JS |
647 | } |
648 | ||
a9102b36 JS |
649 | #endif |
650 | // !__SMARTPHONE__ | |
39d2f9a7 | 651 | |
a71d815b | 652 | #endif // wxUSE_TOOLBAR |