]>
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 | ||
39d2f9a7 JS |
45 | #if !defined(__GNUWIN32__) && !defined(__SALFORDC__) |
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 JS |
56 | #include <aygshell.h> |
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 | ||
a9102b36 | 195 | bool wxToolMenuBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), const wxSize& WXUNUSED(size), wxMenuBar* menuBar) |
39d2f9a7 JS |
196 | { |
197 | SetMenuBar(menuBar); | |
198 | if (m_menuBar) | |
199 | m_menuBar->SetToolBar(this); | |
200 | ||
3d487566 | 201 | #if defined(WINCE_WITHOUT_COMMANDBAR) |
39d2f9a7 JS |
202 | // Create the menubar. |
203 | SHMENUBARINFO mbi; | |
39fc096d | 204 | |
39d2f9a7 JS |
205 | memset (&mbi, 0, sizeof (SHMENUBARINFO)); |
206 | mbi.cbSize = sizeof (SHMENUBARINFO); | |
207 | mbi.hwndParent = (HWND) GetParent()->GetHWND(); | |
d7da7f13 | 208 | #ifdef __SMARTPHONE__ |
74d0b78c JS |
209 | mbi.nToolBarId = 5002; |
210 | #else | |
39d2f9a7 | 211 | mbi.nToolBarId = 5000; |
74d0b78c | 212 | #endif |
39d2f9a7 JS |
213 | mbi.nBmpId = 0; |
214 | mbi.cBmpImages = 0; | |
215 | mbi.dwFlags = 0 ; // SHCMBF_EMPTYBAR; | |
216 | mbi.hInstRes = wxGetInstance(); | |
39fc096d | 217 | |
39d2f9a7 JS |
218 | if (!SHCreateMenuBar(&mbi)) |
219 | { | |
220 | wxFAIL_MSG( _T("SHCreateMenuBar failed") ); | |
16640ba2 | 221 | return false; |
39d2f9a7 | 222 | } |
39fc096d | 223 | |
39d2f9a7 | 224 | SetHWND((WXHWND) mbi.hwndMB); |
960b193e JS |
225 | #else |
226 | HWND hWnd = CommandBar_Create(wxGetInstance(), (HWND) GetParent()->GetHWND(), GetId()); | |
227 | SetHWND((WXHWND) hWnd); | |
2d36b3d8 JS |
228 | #endif |
229 | ||
77ffb593 | 230 | // install wxWidgets window proc for this window |
39d2f9a7 JS |
231 | SubclassWin(m_hWnd); |
232 | ||
233 | if (menuBar) | |
234 | menuBar->Create(); | |
39fc096d WS |
235 | |
236 | return true; | |
39d2f9a7 JS |
237 | } |
238 | ||
a9102b36 | 239 | void wxToolMenuBar::Recreate() |
39d2f9a7 | 240 | { |
a9102b36 | 241 | // TODO |
39d2f9a7 JS |
242 | } |
243 | ||
a9102b36 | 244 | wxToolMenuBar::~wxToolMenuBar() |
39d2f9a7 | 245 | { |
bf95a04f JS |
246 | if (GetMenuBar()) |
247 | GetMenuBar()->SetToolBar(NULL); | |
39d2f9a7 JS |
248 | } |
249 | ||
250 | // Return HMENU for the menu associated with the commandbar | |
a9102b36 | 251 | WXHMENU wxToolMenuBar::GetHMenu() |
39d2f9a7 | 252 | { |
781a24e8 | 253 | #if defined(__HANDHELDPC__) |
781a24e8 RR |
254 | return 0; |
255 | #else | |
39d2f9a7 JS |
256 | if (GetHWND()) |
257 | { | |
258 | return (WXHMENU) (HMENU)::SendMessage((HWND) GetHWND(), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0); | |
259 | } | |
260 | else | |
261 | return 0; | |
781a24e8 | 262 | #endif |
39d2f9a7 JS |
263 | } |
264 | ||
39d2f9a7 JS |
265 | // ---------------------------------------------------------------------------- |
266 | // adding/removing tools | |
267 | // ---------------------------------------------------------------------------- | |
268 | ||
a9102b36 | 269 | bool wxToolMenuBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
39d2f9a7 JS |
270 | { |
271 | // nothing special to do here - we really create the toolbar buttons in | |
272 | // Realize() later | |
273 | tool->Attach(this); | |
274 | ||
39fc096d | 275 | return true; |
39d2f9a7 JS |
276 | } |
277 | ||
a9102b36 | 278 | bool wxToolMenuBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) |
39d2f9a7 JS |
279 | { |
280 | // the main difficulty we have here is with the controls in the toolbars: | |
281 | // as we (sometimes) use several separators to cover up the space used by | |
282 | // them, the indices are not the same for us and the toolbar | |
283 | ||
284 | // first determine the position of the first button to delete: it may be | |
285 | // different from pos if we use several separators to cover the space used | |
286 | // by a control | |
287 | wxToolBarToolsList::compatibility_iterator node; | |
288 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
289 | { | |
290 | wxToolBarToolBase *tool2 = node->GetData(); | |
291 | if ( tool2 == tool ) | |
292 | { | |
293 | // let node point to the next node in the list | |
294 | node = node->GetNext(); | |
295 | ||
296 | break; | |
297 | } | |
298 | ||
299 | if ( tool2->IsControl() ) | |
300 | { | |
a9102b36 | 301 | pos += ((wxToolMenuBarTool *)tool2)->GetSeparatorsCount() - 1; |
39d2f9a7 JS |
302 | } |
303 | } | |
304 | ||
305 | // now determine the number of buttons to delete and the area taken by them | |
306 | size_t nButtonsToDelete = 1; | |
307 | ||
308 | // get the size of the button we're going to delete | |
309 | RECT r; | |
310 | if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) ) | |
311 | { | |
312 | wxLogLastError(_T("TB_GETITEMRECT")); | |
313 | } | |
314 | ||
315 | int width = r.right - r.left; | |
316 | ||
317 | if ( tool->IsControl() ) | |
318 | { | |
a9102b36 | 319 | nButtonsToDelete = ((wxToolMenuBarTool *)tool)->GetSeparatorsCount(); |
39d2f9a7 JS |
320 | |
321 | width *= nButtonsToDelete; | |
322 | } | |
323 | ||
324 | // do delete all buttons | |
325 | m_nButtons -= nButtonsToDelete; | |
326 | while ( nButtonsToDelete-- > 0 ) | |
327 | { | |
328 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) ) | |
329 | { | |
330 | wxLogLastError(wxT("TB_DELETEBUTTON")); | |
331 | ||
16640ba2 | 332 | return false; |
39d2f9a7 JS |
333 | } |
334 | } | |
335 | ||
336 | tool->Detach(); | |
337 | ||
338 | // and finally reposition all the controls after this button (the toolbar | |
339 | // takes care of all normal items) | |
340 | for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) | |
341 | { | |
342 | wxToolBarToolBase *tool2 = node->GetData(); | |
343 | if ( tool2->IsControl() ) | |
344 | { | |
345 | int x; | |
346 | wxControl *control = tool2->GetControl(); | |
347 | control->GetPosition(&x, NULL); | |
39fc096d | 348 | control->Move(x - width, wxDefaultCoord); |
39d2f9a7 JS |
349 | } |
350 | } | |
351 | ||
39fc096d | 352 | return true; |
39d2f9a7 JS |
353 | } |
354 | ||
4012b958 | 355 | bool wxToolMenuBar::Realize() |
39d2f9a7 JS |
356 | { |
357 | const size_t nTools = GetToolsCount(); | |
358 | if ( nTools == 0 ) | |
359 | { | |
360 | // nothing to do | |
39fc096d | 361 | return true; |
39d2f9a7 JS |
362 | } |
363 | ||
39d2f9a7 JS |
364 | #if 0 |
365 | // delete all old buttons, if any | |
366 | for ( size_t pos = 0; pos < m_nButtons; pos++ ) | |
367 | { | |
368 | if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) | |
369 | { | |
370 | wxLogDebug(wxT("TB_DELETEBUTTON failed")); | |
371 | } | |
372 | } | |
7010702f | 373 | #endif // 0 |
39d2f9a7 | 374 | |
16640ba2 | 375 | bool lastWasRadio = false; |
39d2f9a7 JS |
376 | wxToolBarToolsList::Node* node; |
377 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
378 | { | |
a9102b36 | 379 | wxToolMenuBarTool *tool = (wxToolMenuBarTool*) node->GetData(); |
39d2f9a7 | 380 | |
ac1f013c | 381 | TBBUTTON buttons[1] ; |
bf95a04f | 382 | |
ac1f013c | 383 | TBBUTTON& button = buttons[0]; |
39d2f9a7 JS |
384 | |
385 | wxZeroMemory(button); | |
386 | ||
16640ba2 | 387 | bool isRadio = false; |
39d2f9a7 JS |
388 | switch ( tool->GetStyle() ) |
389 | { | |
390 | case wxTOOL_STYLE_CONTROL: | |
391 | button.idCommand = tool->GetId(); | |
392 | // fall through: create just a separator too | |
4012b958 | 393 | // TODO: controls are not yet supported on wxToolMenuBar. |
39d2f9a7 JS |
394 | |
395 | case wxTOOL_STYLE_SEPARATOR: | |
396 | button.fsState = TBSTATE_ENABLED; | |
397 | button.fsStyle = TBSTYLE_SEP; | |
398 | break; | |
399 | ||
400 | case wxTOOL_STYLE_BUTTON: | |
a71d815b | 401 | |
39d2f9a7 JS |
402 | if ( HasFlag(wxTB_TEXT) ) |
403 | { | |
404 | const wxString& label = tool->GetLabel(); | |
405 | if ( !label.empty() ) | |
406 | { | |
407 | button.iString = (int)label.c_str(); | |
408 | } | |
409 | } | |
410 | ||
ac1f013c JS |
411 | const wxBitmap& bmp = tool->GetNormalBitmap(); |
412 | ||
413 | wxBitmap bmpToUse = bmp; | |
414 | ||
ec5f0c24 | 415 | if (bmp.GetWidth() < 16 || bmp.GetHeight() < 16 || bmp.GetMask() != NULL) |
ac1f013c JS |
416 | { |
417 | wxMemoryDC memDC; | |
418 | wxBitmap b(16,16); | |
419 | memDC.SelectObject(b); | |
4012b958 JS |
420 | wxColour col = wxColour(192,192,192); |
421 | memDC.SetBackground(wxBrush(col)); | |
ac1f013c JS |
422 | memDC.Clear(); |
423 | int x = (16 - bmp.GetWidth())/2; | |
424 | int y = (16 - bmp.GetHeight())/2; | |
425 | memDC.DrawBitmap(bmp, x, y, true); | |
426 | memDC.SelectObject(wxNullBitmap); | |
427 | ||
428 | bmpToUse = b; | |
429 | tool->SetNormalBitmap(b); | |
430 | } | |
431 | ||
432 | int n = 0; | |
433 | if ( bmpToUse.Ok() ) | |
bf95a04f | 434 | { |
ac1f013c JS |
435 | n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(), |
436 | 1, 16, 16 ); | |
bf95a04f | 437 | } |
ac1f013c JS |
438 | |
439 | button.idCommand = tool->GetId(); | |
440 | button.iBitmap = n; | |
39d2f9a7 JS |
441 | |
442 | if ( tool->IsEnabled() ) | |
443 | button.fsState |= TBSTATE_ENABLED; | |
444 | if ( tool->IsToggled() ) | |
445 | button.fsState |= TBSTATE_CHECKED; | |
446 | ||
447 | switch ( tool->GetKind() ) | |
448 | { | |
449 | case wxITEM_RADIO: | |
450 | button.fsStyle = TBSTYLE_CHECKGROUP; | |
451 | ||
452 | if ( !lastWasRadio ) | |
453 | { | |
454 | // the first item in the radio group is checked by | |
455 | // default to be consistent with wxGTK and the menu | |
456 | // radio items | |
457 | button.fsState |= TBSTATE_CHECKED; | |
458 | ||
39fc096d | 459 | tool->Toggle(true); |
39d2f9a7 JS |
460 | } |
461 | ||
39fc096d | 462 | isRadio = true; |
39d2f9a7 JS |
463 | break; |
464 | ||
465 | case wxITEM_CHECK: | |
466 | button.fsStyle = TBSTYLE_CHECK; | |
467 | break; | |
468 | ||
469 | default: | |
470 | wxFAIL_MSG( _T("unexpected toolbar button kind") ); | |
471 | // fall through | |
472 | ||
473 | case wxITEM_NORMAL: | |
474 | button.fsStyle = TBSTYLE_BUTTON; | |
475 | } | |
39d2f9a7 JS |
476 | break; |
477 | } | |
478 | ||
30b9db02 VZ |
479 | if ( !::CommandBar_AddButtons( (HWND) GetHWND(), 1, buttons ) ) |
480 | { | |
481 | wxFAIL_MSG( wxT("Could not add toolbar button.")); | |
482 | } | |
7010702f | 483 | |
ac1f013c | 484 | lastWasRadio = isRadio; |
39d2f9a7 | 485 | } |
39d2f9a7 | 486 | |
7010702f | 487 | return true; |
39d2f9a7 JS |
488 | } |
489 | ||
a9102b36 | 490 | bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) |
39d2f9a7 JS |
491 | { |
492 | wxToolBarToolBase *tool = FindById((int)id); | |
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 | ||
39d2f9a7 JS |
506 | wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); |
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 | |
527 | // may be toggled only, of couse | |
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 | { | |
39d2f9a7 JS |
646 | wxFAIL_MSG( _T("not implemented") ); |
647 | } | |
648 | ||
a9102b36 JS |
649 | #endif |
650 | // !__SMARTPHONE__ | |
39d2f9a7 | 651 | |
a71d815b | 652 | #endif // wxUSE_TOOLBAR |