menu.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 750 行 · 第 1/2 页
CPP
750 行
/////////////////////////////////////////////////////////////////////////////
// Name: src/palmos/menu.cpp
// Purpose: wxMenu, wxMenuBar, wxMenuItem
// Author: William Osborne - minimal working wxPalmOS port
// Modified by:
// Created: 10/12/04
// RCS-ID: $Id: menu.cpp,v 1.6 2005/07/01 19:36:56 ABX Exp $
// Copyright: (c) William Osborne
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// declarations
// ===========================================================================
// ---------------------------------------------------------------------------
// headers
// ---------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "menu.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_MENUS
#ifndef WX_PRECOMP
#include "wx/frame.h"
#include "wx/menu.h"
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/log.h"
#endif
#if wxUSE_OWNER_DRAWN
#include "wx/ownerdrw.h"
#endif
#include <Loader.h>
#include <Form.h>
#include <Menu.h>
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
extern wxMenu *wxCurrentPopupMenu;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// the (popup) menu title has this special id
static const int idMenuTitle = -3;
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
// ============================================================================
// implementation
// ============================================================================
#include <wx/listimpl.cpp>
WX_DEFINE_LIST( wxMenuInfoList ) ;
#if wxUSE_EXTENDED_RTTI
WX_DEFINE_FLAGS( wxMenuStyle )
wxBEGIN_FLAGS( wxMenuStyle )
wxFLAGS_MEMBER(wxMENU_TEAROFF)
wxEND_FLAGS( wxMenuStyle )
IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenu, wxEvtHandler,"wx/menu.h")
wxCOLLECTION_TYPE_INFO( wxMenuItem * , wxMenuItemList ) ;
template<> void wxCollectionToVariantArray( wxMenuItemList const &theList, wxxVariantArray &value)
{
wxListCollectionToVariantArray<wxMenuItemList::compatibility_iterator>( theList , value ) ;
}
wxBEGIN_PROPERTIES_TABLE(wxMenu)
wxEVENT_PROPERTY( Select , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
wxPROPERTY( Title, wxString , SetTitle, GetTitle, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
wxREADONLY_PROPERTY_FLAGS( MenuStyle , wxMenuStyle , long , GetStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
wxPROPERTY_COLLECTION( MenuItems , wxMenuItemList , wxMenuItem* , Append , GetMenuItems , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxMenu)
wxEND_HANDLERS_TABLE()
wxDIRECT_CONSTRUCTOR_2( wxMenu , wxString , Title , long , MenuStyle )
WX_DEFINE_FLAGS( wxMenuBarStyle )
wxBEGIN_FLAGS( wxMenuBarStyle )
wxFLAGS_MEMBER(wxMB_DOCKABLE)
wxEND_FLAGS( wxMenuBarStyle )
// the negative id would lead the window (its superclass !) to vetoe streaming out otherwise
bool wxMenuBarStreamingCallback( const wxObject *WXUNUSED(object), wxWriter * , wxPersister * , wxxVariantArray & )
{
return true ;
}
IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuBar, wxWindow ,"wx/menu.h",wxMenuBarStreamingCallback)
IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenuInfo, wxObject , "wx/menu.h" )
wxBEGIN_PROPERTIES_TABLE(wxMenuInfo)
wxREADONLY_PROPERTY( Menu , wxMenu* , GetMenu , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxREADONLY_PROPERTY( Title , wxString , GetTitle , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxMenuInfo)
wxEND_HANDLERS_TABLE()
wxCONSTRUCTOR_2( wxMenuInfo , wxMenu* , Menu , wxString , Title )
wxCOLLECTION_TYPE_INFO( wxMenuInfo * , wxMenuInfoList ) ;
template<> void wxCollectionToVariantArray( wxMenuInfoList const &theList, wxxVariantArray &value)
{
wxListCollectionToVariantArray<wxMenuInfoList::compatibility_iterator>( theList , value ) ;
}
wxBEGIN_PROPERTIES_TABLE(wxMenuBar)
wxPROPERTY_COLLECTION( MenuInfos , wxMenuInfoList , wxMenuInfo* , Append , GetMenuInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxMenuBar)
wxEND_HANDLERS_TABLE()
wxCONSTRUCTOR_DUMMY( wxMenuBar )
#else
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow)
IMPLEMENT_DYNAMIC_CLASS(wxMenuInfo, wxObject)
#endif
const wxMenuInfoList& wxMenuBar::GetMenuInfos() const
{
wxMenuInfoList* list = const_cast< wxMenuInfoList* >( &m_menuInfos ) ;
WX_CLEAR_LIST( wxMenuInfoList , *list ) ;
for( size_t i = 0 ; i < GetMenuCount() ; ++i )
{
wxMenuInfo* info = new wxMenuInfo() ;
info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetLabelTop(i) ) ;
list->Append( info ) ;
}
return m_menuInfos ;
}
// ---------------------------------------------------------------------------
// wxMenu construction, adding and removing menu items
// ---------------------------------------------------------------------------
// Construct a menu with optional title (then use append)
void wxMenu::Init()
{
}
// The wxWindow destructor will take care of deleting the submenus.
wxMenu::~wxMenu()
{
}
void wxMenu::Break()
{
}
void wxMenu::Attach(wxMenuBarBase *menubar)
{
wxMenuBase::Attach(menubar);
}
#if wxUSE_ACCEL
int wxMenu::FindAccel(int id) const
{
return wxNOT_FOUND;
}
void wxMenu::UpdateAccel(wxMenuItem *item)
{
}
#endif // wxUSE_ACCEL
// append a new item or submenu to the menu
bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
{
if ( IsAttached() && GetMenuBar()->IsAttached() )
{
// Regenerate the menu resource
GetMenuBar()->Refresh();
}
return true;
}
void wxMenu::EndRadioGroup()
{
}
wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") );
if(!wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item))
{
return NULL;
}
else if(IsAttached() && GetMenuBar()->IsAttached())
{
// Regenerate the menu resource
GetMenuBar()->Refresh();
}
return item;
}
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos))
return item;
else
return NULL;
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
{
// we need to find the items position in the child list
size_t pos;
wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
for ( pos = 0; node; pos++ )
{
if ( node->GetData() == item )
break;
node = node->GetNext();
}
// DoRemove() (unlike Remove) can only be called for existing item!
wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") );
// remove the item from the menu
wxMenuItem *ret=wxMenuBase::DoRemove(item);
if ( IsAttached() && GetMenuBar()->IsAttached() )
{
// Regenerate the menu resource
GetMenuBar()->Refresh();
}
return ret;
}
// ---------------------------------------------------------------------------
// accelerator helpers
// ---------------------------------------------------------------------------
#if wxUSE_ACCEL
// create the wxAcceleratorEntries for our accels and put them into provided
// array - return the number of accels we have
size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const
{
size_t count = GetAccelCount();
for ( size_t n = 0; n < count; n++ )
{
*accels++ = *m_accels[n];
}
return count;
}
#endif // wxUSE_ACCEL
// ---------------------------------------------------------------------------
// set wxMenu title
// ---------------------------------------------------------------------------
void wxMenu::SetTitle(const wxString& label)
{
m_title = label;
if ( IsAttached() && GetMenuBar()->IsAttached() )
{
// Regenerate the menu resource
GetMenuBar()->Refresh();
}
}
// ---------------------------------------------------------------------------
// event processing
// ---------------------------------------------------------------------------
bool wxMenu::PalmCommand(WXUINT WXUNUSED(param), WXWORD id)
{
return false;
}
// ---------------------------------------------------------------------------
// other
// ---------------------------------------------------------------------------
wxWindow *wxMenu::GetWindow() const
{
return NULL;
}
// ---------------------------------------------------------------------------
// Menu Bar
// ---------------------------------------------------------------------------
void wxMenuBar::Init()
{
}
wxMenuBar::wxMenuBar()
{
}
wxMenuBar::wxMenuBar( long WXUNUSED(style) )
{
}
wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
{
}
wxMenuBar::~wxMenuBar()
{
}
// ---------------------------------------------------------------------------
// wxMenuBar helpers
// ---------------------------------------------------------------------------
void wxMenuBar::Refresh()
{
wxCHECK_RET( IsAttached(), wxT("can't refresh unattached menubar") );
// Regenerate the menu resource
LoadMenu();
}
WXHMENU wxMenuBar::Create()
{
return NULL;
}
int wxMenuBar::PalmPositionForWxMenu(wxMenu *menu, int wxpos)
{
return -1;
}
// ---------------------------------------------------------------------------
// wxMenuBar functions to work with the top level submenus
// ---------------------------------------------------------------------------
void wxMenuBar::EnableTop(size_t pos, bool enable)
{
// Palm OS does not have support for grayed or disabled items
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?