// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-
-// ============================================================================
-// headers & declarations
-// ============================================================================
-
-// wxWindows headers
-// -----------------
-
#ifdef __GNUG__
#pragma implementation "menu.h"
-#pragma implementation "menuitem.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#endif
#if wxUSE_OWNER_DRAWN
-#include "wx/ownerdrw.h"
+ #include "wx/ownerdrw.h"
#endif
#include "wx/msw/private.h"
// ----------------------
#include <string.h>
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// the (popup) menu title has this special id
+static const int idMenuTitle = -2;
+
+// ----------------------------------------------------------------------------
+// wxWindows macros
+// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
-IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
+ IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
+ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
#endif
// ============================================================================
m_hMenu = (WXHMENU) CreatePopupMenu();
m_savehMenu = 0 ;
m_topLevelMenu = this;
+ m_clientData = (void*) NULL;
+
if (m_title != "")
{
- Append(-2, m_title) ;
+ Append(idMenuTitle, m_title) ;
AppendSeparator() ;
}
}
// The wxWindow destructor will take care of deleting the submenus.
-wxMenu::~wxMenu(void)
+wxMenu::~wxMenu()
{
if (m_hMenu)
DestroyMenu((HMENU) m_hMenu);
*/
}
-void wxMenu::Break(void)
+void wxMenu::Break()
{
m_doBreak = TRUE ;
}
}
LPCSTR pData;
- wxString name("");
#if wxUSE_OWNER_DRAWN
if ( pItem->IsOwnerDrawn() ) { // want to get {Measure|Draw}Item messages?
{
// menu is just a normal string (passed in data parameter)
flags |= MF_STRING;
- name = pItem->GetName();
- pData = (const char*) name;
+ pData = pItem->GetName();
}
- // VZ: what does this magic -2 mean? I just copied the code but have no idea
- // about what it does... ###
- if ( pItem->GetId() == -2 ) {
- flags |= MF_DISABLED | MF_GRAYED;
+ // visually select the menu title
+ if ( id == idMenuTitle )
+ {
+ // TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face
}
HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
-
if ( !AppendMenu(hMenu, flags, id, pData) )
{
- // wxLogLastError("AppendMenu");
+ wxLogLastError("AppendMenu");
}
m_noItems++;
}
-void wxMenu::AppendSeparator(void)
+void wxMenu::AppendSeparator()
{
Append(new wxMenuItem(this, ID_SEPARATOR));
}
void wxMenu::Delete(int id)
{
wxNode *node;
- wxMenuItem *item;
int pos;
HMENU menu;
+ wxMenuItem *item = NULL;
for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) {
item = (wxMenuItem *)node->Data();
if (item->GetId() == id)
void wxMenu::SetTitle(const wxString& label)
{
- m_title = label ;
- if (m_hMenu)
- ModifyMenu((HMENU)m_hMenu, 0,
- MF_BYPOSITION | MF_STRING | MF_DISABLED,
- (UINT)-2, (const char *)m_title);
- else if (m_savehMenu)
- ModifyMenu((HMENU)m_savehMenu, 0,
- MF_BYPOSITION | MF_STRING | MF_DISABLED,
- (UINT)-2, (const char *)m_title);
+ bool hasNoTitle = m_title.IsEmpty();
+ m_title = label;
+
+ HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
+
+ if ( hasNoTitle )
+ {
+ if ( !label.IsEmpty() )
+ {
+ if ( !InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
+ (unsigned)idMenuTitle, m_title) ||
+ !InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
+ {
+ wxLogLastError("InsertMenu");
+ }
+ }
+ }
+ else
+ {
+ if ( label.IsEmpty() )
+ {
+ // remove the title and the separator after it
+ if ( !RemoveMenu(hMenu, 0, MF_BYPOSITION) ||
+ !RemoveMenu(hMenu, 0, MF_BYPOSITION) )
+ {
+ wxLogLastError("RemoveMenu");
+ }
+ }
+ else
+ {
+ // modify the title
+ if ( !ModifyMenu(hMenu, 0u,
+ MF_BYPOSITION | MF_STRING,
+ (unsigned)idMenuTitle, m_title) )
+ {
+ wxLogLastError("ModifyMenu");
+ }
+ }
+ }
+
+ // TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face
}
const wxString wxMenu::GetTitle() const
item->SetName(label);
}
-wxString wxMenu::GetLabel(int Id) const
+wxString wxMenu::GetLabel(int id) const
{
+/*
static char tmp[128] ;
int len;
if (m_hMenu)
len = 0 ;
tmp[len] = '\0' ;
return wxString(tmp) ;
+
+*/
+ wxMenuItem *pItem = FindItemForId(id) ;
+ if (pItem)
+ return pItem->GetName() ;
+ else
+ return wxEmptyString;
}
bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id)
{
- wxCommandEvent event(wxEVENT_TYPE_MENU_COMMAND);
+ wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
event.SetEventObject( this );
event.SetId( id );
event.SetInt( id );
// Try a callback
if (m_callback)
{
- (void) (*(m_callback)) (*this, event);
+ (void)(*(m_callback))(*this, event);
processed = TRUE;
}
// Try the window the menu was popped up from (and up
// through the hierarchy)
if ( !processed && GetInvokingWindow())
- processed = GetInvokingWindow()->ProcessEvent(event);
+ processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event);
}
extern wxMenu *wxCurrentPopupMenu;
}
// Menu Bar
-wxMenuBar::wxMenuBar(void)
+wxMenuBar::wxMenuBar()
{
m_eventHandler = this;
m_hMenu = 0;
}
-wxMenuBar::~wxMenuBar(void)
+wxMenuBar::~wxMenuBar()
{
// In fact, don't want menu to be destroyed before MDI
// shuffling has taken place. Let it be destroyed
if (!item)
return FALSE;
- int Flag ;
+ int Flag = 0;
if (itemMenu->m_hMenu)
Flag=GetMenuState((HMENU)itemMenu->m_hMenu, Id, MF_BYCOMMAND) ;
wxMenuItem *item = NULL;
int i;
for (i = 0; i < m_menuCount; i++)
- if ((item = m_menus[i]->FindItemForId (Id, itemMenu)))
+ {
+ item = m_menus[i]->FindItemForId (Id, itemMenu);
+ if (item)
return item;
+ }
return NULL;
}