X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a71d815bbe669ebb9bdb9409926a272c37a5a9aa..ee6c519a4b1c8e919c1353b977e6396a160bc4b3:/src/msw/wince/tbarwce.cpp diff --git a/src/msw/wince/tbarwce.cpp b/src/msw/wince/tbarwce.cpp index 4d5f0e3f49..a2e2847ea2 100644 --- a/src/msw/wince/tbarwce.cpp +++ b/src/msw/wince/tbarwce.cpp @@ -24,24 +24,25 @@ #pragma hdrstop #endif +// Use the WinCE-specific toolbar only if we're either compiling +// with a WinCE earlier than 4, or we wish to emulate a PocketPC-style UI +#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__)) + +#include "wx/toolbar.h" + #ifndef WX_PRECOMP + #include "wx/msw/wrapcctl.h" // include "properly" + #include "wx/dynarray.h" #include "wx/frame.h" #include "wx/log.h" #include "wx/intl.h" - #include "wx/dynarray.h" #include "wx/settings.h" #include "wx/bitmap.h" #include "wx/dcmemory.h" #include "wx/control.h" #endif -// Use the WinCE-specific toolbar only if we're either compiling -// with a WinCE earlier than 4, or we wish to emulate a PocketPC-style UI -#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_NATIVE && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__)) - -#include "wx/toolbar.h" - -#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) +#if !defined(__GNUWIN32__) #include "malloc.h" #endif @@ -51,9 +52,9 @@ #include #include #include -#include #if defined(WINCE_WITHOUT_COMMANDBAR) #include + #include "wx/msw/wince/resources.h" #endif #include "wx/msw/wince/missing.h" @@ -96,8 +97,8 @@ public: m_bitmapIndex = -1; } - wxToolMenuBarTool(wxToolBar *tbar, wxControl *control) - : wxToolBarToolBase(tbar, control) + wxToolMenuBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) + : wxToolBarToolBase(tbar, control, label) { m_nSepCount = 1; m_bitmapIndex = -1; @@ -151,9 +152,10 @@ wxToolBarToolBase *wxToolMenuBar::CreateTool(int id, clientData, shortHelp, longHelp); } -wxToolBarToolBase *wxToolMenuBar::CreateTool(wxControl *control) +wxToolBarToolBase * +wxToolMenuBar::CreateTool(wxControl *control, const wxString& label) { - return new wxToolMenuBarTool(this, control); + return new wxToolMenuBarTool(this, control, label); } // ---------------------------------------------------------------------------- @@ -191,38 +193,34 @@ bool wxToolMenuBar::Create(wxWindow *parent, return true; } -bool wxToolMenuBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), const wxSize& WXUNUSED(size), wxMenuBar* menuBar) +bool wxToolMenuBar::MSWCreateToolbar(const wxPoint& WXUNUSED(pos), + const wxSize& WXUNUSED(size), + wxMenuBar *menuBar) { SetMenuBar(menuBar); if (m_menuBar) m_menuBar->SetToolBar(this); + HWND hwndParent = GetHwndOf(GetParent()); + wxCHECK_MSG( hwndParent, false, wxT("should have valid parent HWND") ); + #if defined(WINCE_WITHOUT_COMMANDBAR) - // Create the menubar. - SHMENUBARINFO mbi; - - memset (&mbi, 0, sizeof (SHMENUBARINFO)); - mbi.cbSize = sizeof (SHMENUBARINFO); - mbi.hwndParent = (HWND) GetParent()->GetHWND(); -#ifdef __SMARTPHONE__ - mbi.nToolBarId = 5002; -#else - mbi.nToolBarId = 5000; -#endif - mbi.nBmpId = 0; - mbi.cBmpImages = 0; - mbi.dwFlags = 0 ; // SHCMBF_EMPTYBAR; + // create the menubar. + WinStruct mbi; + + mbi.hwndParent = hwndParent; + mbi.nToolBarId = wxIDM_SHMENU; mbi.hInstRes = wxGetInstance(); - if (!SHCreateMenuBar(&mbi)) + if ( !SHCreateMenuBar(&mbi) ) { - wxFAIL_MSG( _T("SHCreateMenuBar failed") ); + wxFAIL_MSG( wxT("SHCreateMenuBar failed") ); return false; } SetHWND((WXHWND) mbi.hwndMB); #else - HWND hWnd = CommandBar_Create(wxGetInstance(), (HWND) GetParent()->GetHWND(), GetId()); + HWND hWnd = CommandBar_Create(wxGetInstance(), hwndParent, GetId()); SetHWND((WXHWND) hWnd); #endif @@ -249,16 +247,14 @@ wxToolMenuBar::~wxToolMenuBar() // Return HMENU for the menu associated with the commandbar WXHMENU wxToolMenuBar::GetHMenu() { -#if defined(__HANDHELDPC__) - return 0; -#else +#if !defined(__HANDHELDPC__) if (GetHWND()) { - return (WXHMENU) (HMENU)::SendMessage((HWND) GetHWND(), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0); + return (WXHMENU)::SendMessage(GetHwnd(), SHCMBM_GETMENU, 0, 0); } - else - return 0; #endif + + return NULL; } // ---------------------------------------------------------------------------- @@ -276,6 +272,10 @@ bool wxToolMenuBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) bool wxToolMenuBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) { + // Skip over the menus + if (GetMenuBar()) + pos += GetMenuBar()->GetMenuCount(); + // the main difficulty we have here is with the controls in the toolbars: // as we (sometimes) use several separators to cover up the space used by // them, the indices are not the same for us and the toolbar @@ -308,7 +308,7 @@ bool wxToolMenuBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) RECT r; if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) ) { - wxLogLastError(_T("TB_GETITEMRECT")); + wxLogLastError(wxT("TB_GETITEMRECT")); } int width = r.right - r.left; @@ -372,7 +372,7 @@ bool wxToolMenuBar::Realize() #endif // 0 bool lastWasRadio = false; - wxToolBarToolsList::Node* node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolMenuBarTool *tool = (wxToolMenuBarTool*) node->GetData(); @@ -403,7 +403,7 @@ bool wxToolMenuBar::Realize() const wxString& label = tool->GetLabel(); if ( !label.empty() ) { - button.iString = (int)label.c_str(); + button.iString = (int) wxMSW_CONV_LPCTSTR(label); } } @@ -429,7 +429,7 @@ bool wxToolMenuBar::Realize() } int n = 0; - if ( bmpToUse.Ok() ) + if ( bmpToUse.IsOk() ) { n = ::CommandBar_AddBitmap( (HWND) GetHWND(), NULL, (int) (HBITMAP) bmpToUse.GetHBITMAP(), 1, 16, 16 ); @@ -466,7 +466,7 @@ bool wxToolMenuBar::Realize() break; default: - wxFAIL_MSG( _T("unexpected toolbar button kind") ); + wxFAIL_MSG( wxT("unexpected toolbar button kind") ); // fall through case wxITEM_NORMAL: @@ -486,15 +486,28 @@ bool wxToolMenuBar::Realize() return true; } -bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) +bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) { - wxToolBarToolBase *tool = FindById((int)id); + const int id = (signed short)id_; + + wxToolBarToolBase *tool = FindById(id); if ( !tool ) { + bool checked = false; + if ( m_menuBar ) + { + wxMenuItem *item = m_menuBar->FindItem(id); + if ( item && item->IsCheckable() ) + { + item->Toggle(); + checked = item->IsChecked(); + } + } + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); event.SetEventObject(this); event.SetId(id); - event.SetInt(id); + event.SetInt(checked); return GetEventHandler()->ProcessEvent(event); } @@ -512,7 +525,7 @@ bool wxToolMenuBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled ) { // OnLeftClick() can veto the button state change - for buttons which - // may be toggled only, of couse + // may be toggled only, of course. if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) { // revert back @@ -543,7 +556,7 @@ WXLRESULT wxToolMenuBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lP break; } - return wxControl::MSWWindowProc(nMsg, wParam, lParam); + return MSWDefWindowProc(nMsg, wParam, lParam); } @@ -631,7 +644,7 @@ void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(to void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) { - wxFAIL_MSG( _T("not implemented") ); + wxFAIL_MSG( wxT("not implemented") ); } #endif