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"
47 #include "wx/msw/wince/missing.h"
49 #include "wx/msw/wince/resources.h"
51 wxTopLevelWindowMSW::ButtonMenu::ButtonMenu()
54 m_label
= wxEmptyString
;
59 wxTopLevelWindowMSW::ButtonMenu::~ButtonMenu()
68 void wxTopLevelWindowMSW::SetLeftMenu(int id
, const wxString
& label
, wxMenu
*subMenu
)
70 m_LeftButton
.SetButton(id
, label
, subMenu
);
74 void wxTopLevelWindowMSW::SetRightMenu(int id
, const wxString
& label
, wxMenu
*subMenu
)
76 m_RightButton
.SetButton(id
, label
, subMenu
);
80 void wxTopLevelWindowMSW::ButtonMenu::SetButton(int id
, const wxString
& label
, wxMenu
*subMenu
)
88 wxMenu
*wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(wxMenu
*menu
)
90 // This is required in case of converting wxMenuBar to wxMenu in wxFrame::SetMenuBar.
91 // All submenus has to be recreated because of new owner.
93 wxMenu
*duplication
= new wxMenu
;
97 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
100 wxMenuItem
*item
= node
->GetData();
103 wxMenu
*submenu
= NULL
;
105 if(item
->IsSubMenu())
106 submenu
= DuplicateMenu( item
->GetSubMenu() );
110 wxMenuItem
*new_item
= wxMenuItem::New(duplication
, item
->GetId(), item
->GetLabel(), item
->GetHelp(), item
->GetKind(), submenu
);
112 if( item
->IsCheckable() )
113 new_item
->Check(item
->IsChecked());
115 new_item
->Enable( item
->IsEnabled() );
117 duplication
->Append(new_item
);
119 node
= node
->GetNext();
127 void wxMenuToHMenu(wxMenu
* in
, HMENU hMenu
)
133 wxMenuItemList::compatibility_iterator node
= in
->GetMenuItems().GetFirst();
136 wxMenuItem
*item
= node
->GetData();
142 if( item
->IsSeparator() )
144 uFlags
|= MF_SEPARATOR
;
145 uIDNewItem
= (unsigned)wxID_ANY
;
152 wxStrcpy(buf
, item
->GetLabel().c_str());
156 uFlags
|= ( item
->IsEnabled() ? MF_ENABLED
: MF_GRAYED
);
159 uFlags
|= ( item
->IsChecked() ? MF_CHECKED
: MF_UNCHECKED
);
161 if( item
->IsSubMenu() )
164 HMENU hSubMenu
= CreatePopupMenu();
165 wxMenuToHMenu(item
->GetSubMenu(), hSubMenu
);
166 uIDNewItem
= (UINT
) hSubMenu
;
170 uIDNewItem
= item
->GetId();
174 AppendMenu(hMenu
, uFlags
, uIDNewItem
, lpNewItem
);
176 node
= node
->GetNext();
180 void wxTopLevelWindowMSW::ReloadButton(ButtonMenu
& button
, UINT menuID
)
182 TBBUTTONINFO button_info
;
186 memset (&button_info
, 0, sizeof (TBBUTTONINFO
));
187 button_info
.cbSize
= sizeof(TBBUTTONINFO
);
188 button_info
.dwMask
= TBIF_TEXT
| TBIF_STATE
;
189 button_info
.fsState
= TBSTATE_ENABLED
;
190 wxStrcpy(buf
, button
.GetLabel().c_str());
191 button_info
.pszText
= buf
;
192 SendMessage(m_MenuBarHWND
, TB_SETBUTTONINFO
, menuID
, (LPARAM
) &button_info
);
196 HMENU hPopupMenu
= (HMENU
) SendMessage(m_MenuBarHWND
, SHCMBM_GETSUBMENU
, 0, menuID
);
197 RemoveMenu(hPopupMenu
, 0, MF_BYPOSITION
);
198 wxMenuToHMenu(button
.GetMenu(), hPopupMenu
);
202 void wxTopLevelWindowMSW::ReloadAllButtons()
204 // first reaload only after initialization of both buttons
205 // it should is done at the end of Create() of wxTLW
206 if(!m_LeftButton
.IsAssigned() || !m_RightButton
.IsAssigned())
209 SHMENUBARINFO menu_bar
;
212 memset (&menu_bar
, 0, sizeof (SHMENUBARINFO
));
213 menu_bar
.cbSize
= sizeof (SHMENUBARINFO
);
214 menu_bar
.hwndParent
= (HWND
) GetHWND();
216 if(m_LeftButton
.IsMenu() && m_RightButton
.IsMenu())
217 menu_bar
.nToolBarId
= IDR_MENUBAR_BOTH_MENUS
;
218 else if(m_LeftButton
.IsMenu())
219 menu_bar
.nToolBarId
= IDR_MENUBAR_LEFT_MENU
;
220 else if(m_RightButton
.IsMenu())
221 menu_bar
.nToolBarId
= IDR_MENUBAR_RIGHT_MENU
;
223 menu_bar
.nToolBarId
= IDR_MENUBAR_ONE_BUTTON
;
225 menu_bar
.hInstRes
= wxGetInstance();
227 if (!SHCreateMenuBar(&menu_bar
))
229 wxFAIL_MSG( _T("SHCreateMenuBar failed") );
233 HWND prev_MenuBar
= m_MenuBarHWND
;
234 m_MenuBarHWND
= menu_bar
.hwndMB
;
236 ReloadButton(m_LeftButton
, IDM_LEFT
);
237 ReloadButton(m_RightButton
, IDM_RIGHT
);
239 // hide previous and show new menubar
241 ::ShowWindow( prev_MenuBar
, SW_HIDE
);
242 ::ShowWindow( m_MenuBarHWND
, SW_SHOW
);
246 bool wxTopLevelWindowMSW::HandleCommand(WXWORD id
, WXWORD
WXUNUSED(cmd
), WXHWND
WXUNUSED(control
))
248 // handle here commands from Smartphone menu bar
249 if ( id
== IDM_LEFT
|| id
== IDM_RIGHT
)
251 int menuId
= id
== IDM_LEFT
? m_LeftButton
.GetId() : m_RightButton
.GetId() ;
252 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, menuId
);
253 commandEvent
.SetEventObject(this);
254 GetEventHandler()->ProcessEvent(commandEvent
);
260 #endif // __SMARTPHONE__