SetTitle() works even if menu was created without title initially (and setting
title to empty string removes it alltogether) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@802 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
105
src/msw/menu.cpp
105
src/msw/menu.cpp
@@ -11,15 +11,19 @@
|
|||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// headers & declarations
|
// declarations
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// wxWindows headers
|
// wxWindows headers
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "menu.h"
|
#pragma implementation "menu.h"
|
||||||
#pragma implementation "menuitem.h"
|
#pragma implementation "menuitem.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
@@ -36,7 +40,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
#include "wx/ownerdrw.h"
|
#include "wx/ownerdrw.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
@@ -48,9 +52,19 @@
|
|||||||
// ----------------------
|
// ----------------------
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// the (popup) menu title has this special id
|
||||||
|
static const int idMenuTitle = -2;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxWindows macros
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
#if !USE_SHARED_LIBRARY
|
#if !USE_SHARED_LIBRARY
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
|
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
|
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -74,7 +88,7 @@ wxMenu::wxMenu(const wxString& Title, const wxFunction func)
|
|||||||
m_topLevelMenu = this;
|
m_topLevelMenu = this;
|
||||||
if (m_title != "")
|
if (m_title != "")
|
||||||
{
|
{
|
||||||
Append(-2, m_title) ;
|
Append(idMenuTitle, m_title) ;
|
||||||
AppendSeparator() ;
|
AppendSeparator() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +96,7 @@ wxMenu::wxMenu(const wxString& Title, const wxFunction func)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The wxWindow destructor will take care of deleting the submenus.
|
// The wxWindow destructor will take care of deleting the submenus.
|
||||||
wxMenu::~wxMenu(void)
|
wxMenu::~wxMenu()
|
||||||
{
|
{
|
||||||
if (m_hMenu)
|
if (m_hMenu)
|
||||||
DestroyMenu((HMENU) m_hMenu);
|
DestroyMenu((HMENU) m_hMenu);
|
||||||
@@ -132,7 +146,7 @@ wxMenu::~wxMenu(void)
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenu::Break(void)
|
void wxMenu::Break()
|
||||||
{
|
{
|
||||||
m_doBreak = TRUE ;
|
m_doBreak = TRUE ;
|
||||||
}
|
}
|
||||||
@@ -175,7 +189,6 @@ void wxMenu::Append(wxMenuItem *pItem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LPCSTR pData;
|
LPCSTR pData;
|
||||||
wxString name("");
|
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
if ( pItem->IsOwnerDrawn() ) { // want to get {Measure|Draw}Item messages?
|
if ( pItem->IsOwnerDrawn() ) { // want to get {Measure|Draw}Item messages?
|
||||||
@@ -188,27 +201,25 @@ void wxMenu::Append(wxMenuItem *pItem)
|
|||||||
{
|
{
|
||||||
// menu is just a normal string (passed in data parameter)
|
// menu is just a normal string (passed in data parameter)
|
||||||
flags |= MF_STRING;
|
flags |= MF_STRING;
|
||||||
name = pItem->GetName();
|
pData = pItem->GetName();
|
||||||
pData = (const char*) name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VZ: what does this magic -2 mean? I just copied the code but have no idea
|
// visually select the menu title
|
||||||
// about what it does... ###
|
if ( id == idMenuTitle )
|
||||||
if ( pItem->GetId() == -2 ) {
|
{
|
||||||
flags |= MF_DISABLED | MF_GRAYED;
|
// TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face
|
||||||
}
|
}
|
||||||
|
|
||||||
HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
|
HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
|
||||||
|
|
||||||
if ( !AppendMenu(hMenu, flags, id, pData) )
|
if ( !AppendMenu(hMenu, flags, id, pData) )
|
||||||
{
|
{
|
||||||
// wxLogLastError("AppendMenu");
|
wxLogLastError("AppendMenu");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_noItems++;
|
m_noItems++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenu::AppendSeparator(void)
|
void wxMenu::AppendSeparator()
|
||||||
{
|
{
|
||||||
Append(new wxMenuItem(this, ID_SEPARATOR));
|
Append(new wxMenuItem(this, ID_SEPARATOR));
|
||||||
}
|
}
|
||||||
@@ -301,15 +312,47 @@ bool wxMenu::Checked(int Id) const
|
|||||||
|
|
||||||
void wxMenu::SetTitle(const wxString& label)
|
void wxMenu::SetTitle(const wxString& label)
|
||||||
{
|
{
|
||||||
m_title = label ;
|
bool hasNoTitle = m_title.IsEmpty();
|
||||||
if (m_hMenu)
|
m_title = label;
|
||||||
ModifyMenu((HMENU)m_hMenu, 0,
|
|
||||||
MF_BYPOSITION | MF_STRING | MF_DISABLED,
|
HMENU hMenu = (HMENU)((m_hMenu == 0) ? m_savehMenu : m_hMenu);
|
||||||
(UINT)-2, (const char *)m_title);
|
|
||||||
else if (m_savehMenu)
|
if ( hasNoTitle )
|
||||||
ModifyMenu((HMENU)m_savehMenu, 0,
|
{
|
||||||
MF_BYPOSITION | MF_STRING | MF_DISABLED,
|
if ( !label.IsEmpty() )
|
||||||
(UINT)-2, (const char *)m_title);
|
{
|
||||||
|
if ( !InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING,
|
||||||
|
idMenuTitle, m_title) ||
|
||||||
|
!InsertMenu(hMenu, 1, MF_BYPOSITION, -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, 0,
|
||||||
|
MF_BYPOSITION | MF_STRING,
|
||||||
|
idMenuTitle, m_title) )
|
||||||
|
{
|
||||||
|
wxLogLastError("ModifyMenu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxString wxMenu::GetTitle() const
|
const wxString wxMenu::GetTitle() const
|
||||||
@@ -457,7 +500,7 @@ void wxMenu::ProcessCommand(wxCommandEvent & event)
|
|||||||
// Try a callback
|
// Try a callback
|
||||||
if (m_callback)
|
if (m_callback)
|
||||||
{
|
{
|
||||||
(void) (*(m_callback)) (*this, event);
|
(void)(*(m_callback))(*this, event);
|
||||||
processed = TRUE;
|
processed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +538,7 @@ bool wxWindow::PopupMenu(wxMenu *menu, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Menu Bar
|
// Menu Bar
|
||||||
wxMenuBar::wxMenuBar(void)
|
wxMenuBar::wxMenuBar()
|
||||||
{
|
{
|
||||||
m_eventHandler = this;
|
m_eventHandler = this;
|
||||||
|
|
||||||
@@ -522,7 +565,7 @@ wxMenuBar::wxMenuBar(int N, wxMenu *Menus[], const wxString Titles[])
|
|||||||
m_hMenu = 0;
|
m_hMenu = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenuBar::~wxMenuBar(void)
|
wxMenuBar::~wxMenuBar()
|
||||||
{
|
{
|
||||||
// In fact, don't want menu to be destroyed before MDI
|
// In fact, don't want menu to be destroyed before MDI
|
||||||
// shuffling has taken place. Let it be destroyed
|
// shuffling has taken place. Let it be destroyed
|
||||||
|
Reference in New Issue
Block a user