1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/msw/wince/menuce.cpp 
   3 // Purpose:     Smartphone menus implementation 
   4 // Author:      Wlodzimierz ABX Skiba 
   8 // Copyright:   (c) Wlodzimierz Skiba 
   9 // License:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  21     #pragma implementation "menuce" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  37     #include "wx/toplevel.h" 
  41 #if defined(__SMARTPHONE__) && defined(__WXWINCE__) 
  47 #include "wx/msw/wince/missing.h" 
  49 #include "wx/msw/wince/resources.h" 
  51 #include "wx/stockitem.h" 
  53 wxTopLevelWindowMSW::ButtonMenu::ButtonMenu() 
  56     m_label 
= wxEmptyString
; 
  61 wxTopLevelWindowMSW::ButtonMenu::~ButtonMenu() 
  70 void wxTopLevelWindowMSW::SetLeftMenu(int id
, const wxString
& label
, wxMenu 
*subMenu
) 
  72     m_LeftButton
.SetButton(id
, label
, subMenu
); 
  76 void wxTopLevelWindowMSW::SetRightMenu(int id
, const wxString
& label
, wxMenu 
*subMenu
) 
  78     m_RightButton
.SetButton(id
, label
, subMenu
); 
  82 void wxTopLevelWindowMSW::ButtonMenu::SetButton(int id
, const wxString
& label
, wxMenu 
*subMenu
) 
  86     if(label
.empty() && wxIsStockID(id
)) 
  87         m_label 
= wxGetStockLabel(id
, false); 
  93 wxMenu 
*wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(wxMenu 
*menu
) 
  95     // This is required in case of converting wxMenuBar to wxMenu in wxFrame::SetMenuBar. 
  96     // All submenus has to be recreated because of new owner. 
  98     wxMenu 
*duplication 
= new wxMenu
; 
 102         wxMenuItemList::compatibility_iterator node 
= menu
->GetMenuItems().GetFirst(); 
 105             wxMenuItem 
*item 
= node
->GetData(); 
 108                 wxMenu 
*submenu 
= NULL
; 
 110                 if(item
->IsSubMenu()) 
 111                     submenu 
= DuplicateMenu( item
->GetSubMenu() ); 
 115                 wxMenuItem 
*new_item 
= wxMenuItem::New(duplication
, item
->GetId(), item
->GetLabel(), item
->GetHelp(), item
->GetKind(), submenu
); 
 117                 if( item
->IsCheckable() ) 
 118                     new_item
->Check(item
->IsChecked()); 
 120                 new_item
->Enable( item
->IsEnabled() ); 
 122                 duplication
->Append(new_item
); 
 124             node 
= node
->GetNext(); 
 132 void wxMenuToHMenu(wxMenu
* in
, HMENU hMenu
) 
 138     wxMenuItemList::compatibility_iterator node 
= in
->GetMenuItems().GetFirst(); 
 141         wxMenuItem 
*item 
= node
->GetData(); 
 147         if( item
->IsSeparator() ) 
 149             uFlags 
|= MF_SEPARATOR
; 
 150             uIDNewItem 
= (unsigned)wxID_ANY
; 
 157             wxStrcpy(buf
, item
->GetLabel().c_str()); 
 161             uFlags 
|= ( item
->IsEnabled() ? MF_ENABLED 
: MF_GRAYED 
); 
 164             uFlags 
|= ( item
->IsChecked() ? MF_CHECKED 
: MF_UNCHECKED 
); 
 166             if( item
->IsSubMenu() ) 
 169                 HMENU hSubMenu 
= CreatePopupMenu(); 
 170                 wxMenuToHMenu(item
->GetSubMenu(), hSubMenu
); 
 171                 uIDNewItem 
= (UINT
) hSubMenu
; 
 175                 uIDNewItem 
= item
->GetId(); 
 179         AppendMenu(hMenu
, uFlags
, uIDNewItem
, lpNewItem
); 
 181         node 
= node
->GetNext(); 
 185 void wxTopLevelWindowMSW::ReloadButton(ButtonMenu
& button
, UINT menuID
) 
 187     TBBUTTONINFO  button_info
; 
 191     memset (&button_info
, 0, sizeof (TBBUTTONINFO
)); 
 192     button_info
.cbSize 
= sizeof(TBBUTTONINFO
); 
 193     button_info
.dwMask 
= TBIF_TEXT 
| TBIF_STATE
; 
 194     button_info
.fsState 
= TBSTATE_ENABLED
; 
 195     wxStrcpy(buf
, button
.GetLabel().c_str()); 
 196     button_info
.pszText 
= buf
; 
 197     ::SendMessage(m_MenuBarHWND
, TB_SETBUTTONINFO
, menuID
, (LPARAM
) &button_info
); 
 201         HMENU hPopupMenu 
= (HMENU
) ::SendMessage(m_MenuBarHWND
, SHCMBM_GETSUBMENU
, 0, menuID
); 
 202         RemoveMenu(hPopupMenu
, 0, MF_BYPOSITION
); 
 203         wxMenuToHMenu(button
.GetMenu(), hPopupMenu
); 
 207 void wxTopLevelWindowMSW::ReloadAllButtons() 
 209     // first reaload only after initialization of both buttons 
 210     // it should is done at the end of Create() of wxTLW 
 211     if(!m_LeftButton
.IsAssigned() || !m_RightButton
.IsAssigned()) 
 214     SHMENUBARINFO menu_bar
; 
 217     memset (&menu_bar
,    0, sizeof (SHMENUBARINFO
)); 
 218     menu_bar
.cbSize     
= sizeof (SHMENUBARINFO
); 
 219     menu_bar
.hwndParent 
= (HWND
) GetHWND(); 
 221     if(m_LeftButton
.IsMenu() && m_RightButton
.IsMenu()) 
 222         menu_bar
.nToolBarId 
= IDR_MENUBAR_BOTH_MENUS
; 
 223     else if(m_LeftButton
.IsMenu()) 
 224         menu_bar
.nToolBarId 
= IDR_MENUBAR_LEFT_MENU
; 
 225     else if(m_RightButton
.IsMenu()) 
 226         menu_bar
.nToolBarId 
= IDR_MENUBAR_RIGHT_MENU
; 
 228         menu_bar
.nToolBarId 
= IDR_MENUBAR_ONE_BUTTON
; 
 230     menu_bar
.hInstRes 
= wxGetInstance(); 
 232     if (!SHCreateMenuBar(&menu_bar
)) 
 234         wxFAIL_MSG( _T("SHCreateMenuBar failed") ); 
 238     HWND prev_MenuBar 
= m_MenuBarHWND
; 
 239     m_MenuBarHWND 
= menu_bar
.hwndMB
; 
 241     ReloadButton(m_LeftButton
, IDM_LEFT
); 
 242     ReloadButton(m_RightButton
, IDM_RIGHT
); 
 244     // hide previous and show new menubar 
 246         ::ShowWindow( prev_MenuBar
, SW_HIDE 
); 
 247     ::ShowWindow( m_MenuBarHWND
, SW_SHOW 
); 
 251 bool wxTopLevelWindowMSW::HandleCommand(WXWORD id
, WXWORD 
WXUNUSED(cmd
), WXHWND 
WXUNUSED(control
)) 
 253     // handle here commands from Smartphone menu bar 
 254     if ( id 
== IDM_LEFT 
|| id 
== IDM_RIGHT 
) 
 256         int menuId 
= id 
== IDM_LEFT 
? m_LeftButton
.GetId() : m_RightButton
.GetId() ; 
 257         wxCommandEvent 
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, menuId
); 
 258         commandEvent
.SetEventObject(this); 
 259         GetEventHandler()->ProcessEvent(commandEvent
); 
 265 #endif // __SMARTPHONE__ && __WXWINCE__