Smartphone menus.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27832 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-06-16 06:37:55 +00:00
parent 665b71b17c
commit fb8a56b77c
9 changed files with 393 additions and 136 deletions

View File

@@ -1319,6 +1319,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
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
@@ -1327,6 +1328,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/msw/wince/libraries.h
wx/msw/wince/missing.h
wx/msw/wince/tbarwce.h
wx/msw/wince/resources.h
</set>

View File

@@ -81,6 +81,12 @@ public:
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();
@@ -123,6 +129,41 @@ protected:
// 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)
};

View File

@@ -522,7 +522,11 @@
// 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

View File

@@ -36,7 +36,7 @@
#endif
#if defined(_WIN32_WCE)
#include <commctrl.h>
#include "wx\msw\wince\wince.rc"
#endif
//////////////////////////////////////////////////////////////////////////////
@@ -57,95 +57,6 @@ BEGIN
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

View File

@@ -25,6 +25,7 @@
#include "wx/wx.h"
#endif
#include "wx/datetime.h"
#include "wx/image.h"
#if wxUSE_COLOURDLG
@@ -256,7 +257,7 @@ bool MyApp::OnInit()
file_menu->Append(wxID_ANY,_T("Entry dialogs"),entry_menu);
#endif
#endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
#if wxUSE_FILEDLG
@@ -327,9 +328,13 @@ bool MyApp::OnInit()
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);
@@ -366,7 +371,9 @@ MyFrame::MyFrame(wxWindow *parent,
}
#endif // wxUSE_COLOURDLG
#if wxUSE_STATUSBAR
CreateStatusBar();
#endif // wxUSE_STATUSBAR
}
#if wxUSE_COLOURDLG

View File

@@ -318,7 +318,19 @@ void wxFrame::PositionStatusBar()
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,
@@ -852,6 +864,14 @@ bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
}
#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;

View File

@@ -79,9 +79,11 @@ int wxMessageDialog::ShowModal()
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)

View File

@@ -143,6 +143,10 @@ void wxTopLevelWindowMSW::Init()
m_fsIsShowing = FALSE;
m_winLastFocused = (wxWindow *)NULL;
#ifdef __SMARTPHONE__
m_MenuBarHWND = 0;
#endif
}
WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
@@ -523,6 +527,11 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent,
}
#endif
#ifdef __SMARTPHONE__
SetLeftMenu(wxID_EXIT, _("Done"));
SetRightMenu(); // to nothing for initialization
#endif
return ret;
}

261
src/msw/wince/menuce.cpp Normal file
View File

@@ -0,0 +1,261 @@
///////////////////////////////////////////////////////////////////////////////
// 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__