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