src/msw/wince/filedlgwce.cpp
src/msw/wince/helpwce.cpp
src/msw/wince/tbarwce.cpp
+ src/msw/wince/menuce.cpp
</set>
<set var="WINCE_HDR" hints="files">
wx/generic/fdrepdlg.h
wx/msw/wince/libraries.h
wx/msw/wince/missing.h
wx/msw/wince/tbarwce.h
+ wx/msw/wince/resources.h
</set>
void SetLastFocus(wxWindow *win) { m_winLastFocused = win; }
wxWindow *GetLastFocus() const { return m_winLastFocused; }
+#ifdef __SMARTPHONE__
+ void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL);
+ void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL);
+ bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
+#endif // __SMARTPHONE__
+
protected:
// common part of all ctors
void Init();
// the last focused child: we restore focus to it on activation
wxWindow *m_winLastFocused;
+#ifdef __SMARTPHONE__
+ class ButtonMenu
+ {
+ public:
+ ButtonMenu();
+ ~ButtonMenu();
+
+ void SetButton(int id = wxID_ANY,
+ const wxString& label = wxEmptyString,
+ wxMenu *subMenu = NULL);
+
+ bool IsAssigned() const {return m_assigned;}
+ bool IsMenu() const {return m_menu!=NULL;}
+
+ int GetId() const {return m_id;}
+ wxMenu* GetMenu() const {return m_menu;}
+ wxString GetLabel() {return m_label;}
+
+ static wxMenu *DuplicateMenu(wxMenu *menu);
+
+ protected:
+ int m_id;
+ wxString m_label;
+ wxMenu *m_menu;
+ bool m_assigned;
+ };
+
+ ButtonMenu m_LeftButton;
+ ButtonMenu m_RightButton;
+ HWND m_MenuBarHWND;
+
+ void ReloadButton(ButtonMenu& button, UINT menuID);
+ void ReloadAllButtons();
+#endif // __SMARTPHONE__
+
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxTopLevelWindowMSW)
};
// Default is 1
//
// Recommended setting: 1
+#ifdef __SMARTPHONE__
+#define wxUSE_STATUSBAR 0
+#else
#define wxUSE_STATUSBAR 1
+#endif
// Two status bar implementations are available under Win32: the generic one
// or the wrapper around native control. For native look and feel the native
/////////////////////////////////////////////////////////////////////////////
#if (defined( __GNUWIN32__ ) && !defined(__TWIN32__)) || defined(__MWERKS__)
- #include <wx/msw/gnuwin32/winresrc.h>
+ #include <wx/msw/gnuwin32/winresrc.h>
#else
- #include <windows.h>
+ #include <windows.h>
#endif
#if defined(_WIN32_WCE)
- #include <commctrl.h>
+ #include "wx\msw\wince\wince.rc"
#endif
//////////////////////////////////////////////////////////////////////////////
END
END
-#ifdef _WIN32_WCE
-
-// Dummy menubar/toolbar for WinCE
-
-5000 RCDATA DISCARDABLE
-BEGIN
- // Popup menu name
- 5000,
- // Count of items to put on the menu
- 0
-END
-
-5000 MENU DISCARDABLE
-BEGIN
- POPUP "Dummy"
- BEGIN
- MENUITEM "Dummy" 99
- END
-END
-
-// A menubar for Smartphone, which can only have 1 or 2 menu buttons.
-
-#define IDR_SMARTPHONE_MENUBAR 5002
-#define ID_FIRST_BUTTON 40001
-#define ID_SECOND_BUTTON 40002
-#define IDS_CAP_MENU 40003
-#define ID_MENU_TEST 40004
-#define IDS_DONE 40006
-
-STRINGTABLE DISCARDABLE
-BEGIN
- 5001 "Dummy menu"
- IDS_DONE "Done"
- IDS_CAP_MENU "Menu"
-END
-
-#ifndef I_IMAGENONE
- #define I_IMAGENONE (-2)
-#endif
-#ifndef NOMENU
- #define NOMENU 0xFFFF
-#endif
-
-#ifndef wxID_EXIT
-#define wxID_EXIT 5006
-#endif
-
-// A resource for a one-button menubar
-/*
-IDR_SMARTPHONE_MENUBAR MENU DISCARDABLE
-BEGIN
- MENUITEM "Done", wxID_EXIT
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_DONE "Done"
- IDS_CAP_MENU "Menu"
-END
-
-IDR_SMARTPHONE_MENUBAR RCDATA DISCARDABLE
-BEGIN
- IDR_SMARTPHONE_MENUBAR, 1,
- I_IMAGENONE, wxID_EXIT, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE, IDS_DONE, 0, NOMENU,
-END
-*/
-
-// A resource for a two-button menubar
-
-IDR_SMARTPHONE_MENUBAR MENU DISCARDABLE
-BEGIN
- MENUITEM "Done", wxID_EXIT
- POPUP "Menu"
- BEGIN
- MENUITEM "OK", wxID_EXIT
- END
-END
-
-IDR_SMARTPHONE_MENUBAR RCDATA DISCARDABLE
-BEGIN
- IDR_SMARTPHONE_MENUBAR, 2,
- I_IMAGENONE, wxID_EXIT, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE, IDS_DONE, 0, NOMENU,
- I_IMAGENONE, ID_SECOND_BUTTON, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE, IDS_CAP_MENU, 0, 1,
-END
-
-
-#endif
-
-
//////////////////////////////////////////////////////////////////////////////
//
// Standard wxWindows Cursors
#include "wx/wx.h"
#endif
+#include "wx/datetime.h"
#include "wx/image.h"
#if wxUSE_COLOURDLG
file_menu->Append(wxID_ANY,_T("Entry dialogs"),entry_menu);
- #endif
+ #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
#if wxUSE_FILEDLG
file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
+#if !defined( __SMARTPHONE__ )
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File"));
frame->SetMenuBar(menu_bar);
+#else
+ frame->SetRightMenu(wxID_ANY, _T("Menu"), file_menu);
+#endif // __SMARTPHONE__
myCanvas = new MyCanvas(frame);
myCanvas->SetBackgroundColour(*wxWHITE);
}
#endif // wxUSE_COLOURDLG
+#if wxUSE_STATUSBAR
CreateStatusBar();
+#endif // wxUSE_STATUSBAR
}
#if wxUSE_COLOURDLG
IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h")
wxBEGIN_PROPERTIES_TABLE(wxFrame)
- wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
+ wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
void wxFrame::AttachMenuBar(wxMenuBar *menubar)
{
-#if defined(WINCE_WITHOUT_COMMANDBAR)
+#if defined(__SMARTPHONE__)
+ wxMenu *autoMenu = new wxMenu;
+
+ for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
+ {
+ wxMenu *item = menubar->GetMenu(n);
+ wxString label = menubar->GetLabelTop(n);
+ wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
+ autoMenu->Append(wxID_ANY, label, new_item);
+ }
+
+ SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
+#elif defined(WINCE_WITHOUT_COMMANDBAR)
if (!GetToolBar())
{
wxToolBar* toolBar = new wxToolBar(this, -1,
SetToolBar(toolBar);
menubar->SetToolBar(toolBar);
}
- // Now adjust size for menu bar
- int menuHeight = 26;
-
- //When the main window is created using CW_USEDEFAULT the height of the
- // is created is not taken into account). So we resize the window after
- // if a menubar is present
- {
- RECT rc;
- ::GetWindowRect((HWND) GetHWND(), &rc);
- // adjust for menu / titlebar height
- rc.bottom -= (2*menuHeight-1);
-
- MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
- }
+ // Now adjust size for menu bar
+ int menuHeight = 26;
+
+ //When the main window is created using CW_USEDEFAULT the height of the
+ // is created is not taken into account). So we resize the window after
+ // if a menubar is present
+ {
+ RECT rc;
+ ::GetWindowRect((HWND) GetHWND(), &rc);
+ // adjust for menu / titlebar height
+ rc.bottom -= (2*menuHeight-1);
+
+ MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
+ }
#endif
wxFrameBase::AttachMenuBar(menubar);
}
#endif // wxUSE_STATUSBAR
- int x = 0;
- int y = 0;
+ int x = 0;
+ int y = 0;
#if defined(WINCE_WITH_COMMANDBAR)
- // We're using a commandbar - so we have to allow for it.
- if (GetMenuBar() && GetMenuBar()->GetCommandBar())
- {
- RECT rect;
- ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
- y = rect.bottom - rect.top;
- }
+ // We're using a commandbar - so we have to allow for it.
+ if (GetMenuBar() && GetMenuBar()->GetCommandBar())
+ {
+ RECT rect;
+ ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
+ y = rect.bottom - rect.top;
+ }
#endif
int tx, ty;
#endif // wxUSE_TOOLBAR
#if defined(WINCE_WITH_COMMANDBAR)
- // Position the menu command bar
- if (GetMenuBar() && GetMenuBar()->GetCommandBar())
- {
- RECT rect;
- ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
- wxSize clientSz = GetClientSize();
-
- if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
- {
- wxLogLastError(wxT("MoveWindow"));
- }
-
- }
+ // Position the menu command bar
+ if (GetMenuBar() && GetMenuBar()->GetCommandBar())
+ {
+ RECT rect;
+ ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
+ wxSize clientSz = GetClientSize();
+
+ if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
+ {
+ wxLogLastError(wxT("MoveWindow"));
+ }
+
+ }
#endif
}
#endif // wxUSE_MENUS_NATIVE
+#ifdef __SMARTPHONE__
+ // handle here commands from Smartphone menu bar
+ if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) )
+ {
+ return true;
+ }
+#endif // __SMARTPHONE__
+
if ( ProcessCommand(id) )
{
return TRUE;
#endif // wxUSE_TOOLBAR
#if defined(WINCE_WITH_COMMANDBAR)
- if (GetMenuBar() && GetMenuBar()->GetCommandBar())
- {
- RECT rect;
- ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
- pt.y += (rect.bottom - rect.top);
- }
+ if (GetMenuBar() && GetMenuBar()->GetCommandBar())
+ {
+ RECT rect;
+ ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
+ pt.y += (rect.bottom - rect.top);
+ }
#endif
return pt;
unsigned int msStyle = MB_OK;
if (m_dialogStyle & wxYES_NO)
{
+#if !defined(__SMARTPHONE__)
if (m_dialogStyle & wxCANCEL)
msStyle = MB_YESNOCANCEL;
else
+#endif // __SMARTPHONE__
msStyle = MB_YESNO;
if (m_dialogStyle & wxNO_DEFAULT)
m_fsIsShowing = FALSE;
m_winLastFocused = (wxWindow *)NULL;
+
+#ifdef __SMARTPHONE__
+ m_MenuBarHWND = 0;
+#endif
}
WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
}
#endif
+#ifdef __SMARTPHONE__
+ SetLeftMenu(wxID_EXIT, _("Done"));
+ SetRightMenu(); // to nothing for initialization
+#endif
+
return ret;
}
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: src/msw/wince/menuce.cpp
+// Purpose: Smartphone menus implementation
+// Author: Wlodzimierz ABX Skiba
+// Modified by:
+// Created: 28.05.2004
+// RCS-ID: $Id$
+// Copyright: (c) Wlodzimierz Skiba
+// License: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
+ #pragma implementation "menuce"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/wx.h"
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/app.h"
+ #include "wx/toplevel.h"
+ #include "wx/menu.h"
+#endif //WX_PRECOMP
+
+#ifdef __SMARTPHONE__
+
+#include <windows.h>
+#include <ole2.h>
+#include <shellapi.h>
+#include <aygshell.h>
+#include "wx/msw/wince/missing.h"
+
+#include "wx/msw/wince/resources.h"
+
+wxTopLevelWindowMSW::ButtonMenu::ButtonMenu()
+{
+ m_id = wxID_ANY;
+ m_label = wxEmptyString;
+ m_menu = NULL;
+ m_assigned = false;
+}
+
+wxTopLevelWindowMSW::ButtonMenu::~ButtonMenu()
+{
+ if(m_menu)
+ {
+ delete m_menu;
+ m_menu = NULL;
+ };
+}
+
+void wxTopLevelWindowMSW::SetLeftMenu(int id, const wxString& label, wxMenu *subMenu)
+{
+ m_LeftButton.SetButton(id, label, subMenu);
+ ReloadAllButtons();
+}
+
+void wxTopLevelWindowMSW::SetRightMenu(int id, const wxString& label, wxMenu *subMenu)
+{
+ m_RightButton.SetButton(id, label, subMenu);
+ ReloadAllButtons();
+}
+
+void wxTopLevelWindowMSW::ButtonMenu::SetButton(int id, const wxString& label, wxMenu *subMenu)
+{
+ m_assigned = true;
+ m_id = id;
+ m_label = label;
+ m_menu = subMenu;
+}
+
+wxMenu *wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(wxMenu *menu)
+{
+ // This is required in case of converting wxMenuBar to wxMenu in wxFrame::SetMenuBar.
+ // All submenus has to be recreated because of new owner.
+
+ wxMenu *duplication = new wxMenu;
+
+ if (menu)
+ {
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *item = node->GetData();
+ if (item)
+ {
+ wxMenu *submenu = NULL;
+
+ if(item->IsSubMenu())
+ submenu = DuplicateMenu( item->GetSubMenu() );
+ else
+ submenu = NULL;
+
+ wxMenuItem *new_item = wxMenuItem::New(duplication, item->GetId(), item->GetLabel(), item->GetHelp(), item->GetKind(), submenu);
+
+ if( item->IsCheckable() )
+ new_item->Check(item->IsChecked());
+
+ new_item->Enable( item->IsEnabled() );
+
+ duplication->Append(new_item);
+ }
+ node = node->GetNext();
+ }
+
+ }
+
+ return duplication;
+}
+
+void wxMenuToHMenu(wxMenu* in, HMENU hMenu)
+{
+ if(!in) return;
+
+ wxChar buf[256];
+
+ wxMenuItemList::compatibility_iterator node = in->GetMenuItems().GetFirst();
+ while ( node )
+ {
+ wxMenuItem *item = node->GetData();
+
+ UINT uFlags = 0;
+ UINT uIDNewItem;
+ LPCTSTR lpNewItem;
+
+ if( item->IsSeparator() )
+ {
+ uFlags |= MF_SEPARATOR;
+ uIDNewItem = (unsigned)wxID_ANY;
+ lpNewItem = NULL;
+ }
+ else
+ {
+ // label
+ uFlags |= MF_STRING;
+ wxStrcpy(buf, item->GetLabel().c_str());
+ lpNewItem = buf;
+
+ // state
+ uFlags |= ( item->IsEnabled() ? MF_ENABLED : MF_GRAYED );
+
+ // checked
+ uFlags |= ( item->IsChecked() ? MF_CHECKED : MF_UNCHECKED );
+
+ if( item->IsSubMenu() )
+ {
+ uFlags |= MF_POPUP;
+ HMENU hSubMenu = CreatePopupMenu();
+ wxMenuToHMenu(item->GetSubMenu(), hSubMenu);
+ uIDNewItem = (UINT) hSubMenu;
+ }
+ else
+ {
+ uIDNewItem = item->GetId();
+ }
+ }
+
+ AppendMenu(hMenu, uFlags, uIDNewItem, lpNewItem);
+
+ node = node->GetNext();
+ }
+}
+
+void wxTopLevelWindowMSW::ReloadButton(ButtonMenu& button, UINT menuID)
+{
+ TBBUTTONINFO button_info;
+ wxChar buf[256];
+
+ // set button name
+ memset (&button_info, 0, sizeof (TBBUTTONINFO));
+ button_info.cbSize = sizeof(TBBUTTONINFO);
+ button_info.dwMask = TBIF_TEXT | TBIF_STATE;
+ button_info.fsState = TBSTATE_ENABLED;
+ wxStrcpy(buf, button.GetLabel().c_str());
+ button_info.pszText = buf;
+ SendMessage(m_MenuBarHWND, TB_SETBUTTONINFO, menuID, (LPARAM) &button_info);
+
+ if(button.IsMenu())
+ {
+ HMENU hPopupMenu = (HMENU) SendMessage(m_MenuBarHWND, SHCMBM_GETSUBMENU, 0, menuID);
+ RemoveMenu(hPopupMenu, 0, MF_BYPOSITION);
+ wxMenuToHMenu(button.GetMenu(), hPopupMenu);
+ }
+}
+
+void wxTopLevelWindowMSW::ReloadAllButtons()
+{
+ // first reaload only after initialization of both buttons
+ // it should is done at the end of Create() of wxTLW
+ if(!m_LeftButton.IsAssigned() || !m_RightButton.IsAssigned())
+ return;
+
+ SHMENUBARINFO menu_bar;
+ wxString label;
+
+ memset (&menu_bar, 0, sizeof (SHMENUBARINFO));
+ menu_bar.cbSize = sizeof (SHMENUBARINFO);
+ menu_bar.hwndParent = (HWND) GetHWND();
+
+ if(m_LeftButton.IsMenu() && m_RightButton.IsMenu())
+ menu_bar.nToolBarId = IDR_MENUBAR_BOTH_MENUS;
+ else if(m_LeftButton.IsMenu())
+ menu_bar.nToolBarId = IDR_MENUBAR_LEFT_MENU;
+ else if(m_RightButton.IsMenu())
+ menu_bar.nToolBarId = IDR_MENUBAR_RIGHT_MENU;
+ else
+ menu_bar.nToolBarId = IDR_MENUBAR_ONE_BUTTON;
+
+ menu_bar.hInstRes = wxGetInstance();
+
+ if (!SHCreateMenuBar(&menu_bar))
+ {
+ wxFAIL_MSG( _T("SHCreateMenuBar failed") );
+ return;
+ }
+
+ HWND prev_MenuBar = m_MenuBarHWND;
+ m_MenuBarHWND = menu_bar.hwndMB;
+
+ ReloadButton(m_LeftButton, IDM_LEFT);
+ ReloadButton(m_RightButton, IDM_RIGHT);
+
+ // hide previous and show new menubar
+ if ( prev_MenuBar )
+ ::ShowWindow( prev_MenuBar, SW_HIDE );
+ ::ShowWindow( m_MenuBarHWND, SW_SHOW );
+
+}
+
+bool wxTopLevelWindowMSW::HandleCommand(WXWORD id, WXWORD WXUNUSED(cmd), WXHWND WXUNUSED(control))
+{
+ // handle here commands from Smartphone menu bar
+ if ( id == IDM_LEFT || id == IDM_RIGHT )
+ {
+ int menuId = id == IDM_LEFT ? m_LeftButton.GetId() : m_RightButton.GetId() ;
+ wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, menuId);
+ commandEvent.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(commandEvent);
+ return true;
+ }
+ return false;
+}
+
+#endif // __SMARTPHONE__
+