1999-07-29 01:11:30 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: menu.h
|
|
|
|
// Purpose: wxMenu, wxMenuBar classes
|
1999-10-10 22:49:06 -04:00
|
|
|
// Author: David Webster
|
1999-07-29 01:11:30 -04:00
|
|
|
// Modified by:
|
1999-10-10 22:49:06 -04:00
|
|
|
// Created: 10/10/99
|
1999-07-29 01:11:30 -04:00
|
|
|
// RCS-ID: $Id$
|
1999-10-10 22:49:06 -04:00
|
|
|
// Copyright: (c) David Webster
|
|
|
|
// Licence: wxWindows licence
|
1999-07-29 01:11:30 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_MENU_H_
|
|
|
|
#define _WX_MENU_H_
|
|
|
|
|
1999-10-10 22:49:06 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
#include "wx/accel.h"
|
|
|
|
#include "wx/dynarray.h"
|
|
|
|
|
|
|
|
WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
|
1999-10-10 22:49:06 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-07-29 01:11:30 -04:00
|
|
|
|
1999-10-10 22:49:06 -04:00
|
|
|
class WXDLLEXPORT wxFrame;
|
1999-07-29 01:11:30 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
class WXDLLEXPORT wxMenu : public wxMenuBase
|
|
|
|
{
|
1999-07-29 01:11:30 -04:00
|
|
|
public:
|
1999-11-01 23:38:14 -05:00
|
|
|
// ctors & dtor
|
|
|
|
wxMenu(const wxString& title, long style = 0)
|
|
|
|
: wxMenuBase(title, style) { Init(); }
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
virtual ~wxMenu();
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// implement base class virtuals
|
|
|
|
virtual bool DoAppend(wxMenuItem *item);
|
|
|
|
virtual bool DoInsert(size_t pos, wxMenuItem *item);
|
|
|
|
virtual wxMenuItem *DoRemove(wxMenuItem *item);
|
|
|
|
|
|
|
|
virtual void Break();
|
|
|
|
|
|
|
|
virtual void SetTitle(const wxString& title);
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// OS2-specific
|
1999-10-10 22:49:06 -04:00
|
|
|
bool ProcessCommand(wxCommandEvent& event);
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
#if WXWIN_COMPATIBILITY
|
|
|
|
wxMenu(const wxString& title, const wxFunction func)
|
|
|
|
: wxMenuBase(title)
|
|
|
|
{
|
|
|
|
Callback(func);
|
|
|
|
}
|
|
|
|
#endif // WXWIN_COMPATIBILITY
|
|
|
|
|
|
|
|
// implementation only from now on
|
|
|
|
// -------------------------------
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
bool OS2Command(WXUINT param, WXWORD id);
|
|
|
|
|
|
|
|
// semi-private accessors
|
|
|
|
// get the window which contains this menu
|
|
|
|
wxWindow *GetWindow() const;
|
|
|
|
// get the menu handle
|
1999-11-01 23:38:14 -05:00
|
|
|
WXHMENU GetHMenu() const { return m_hMenu; }
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// attach/detach menu to/from wxMenuBar
|
1999-10-10 22:49:06 -04:00
|
|
|
void Attach(wxMenuBar *menubar);
|
|
|
|
void Detach();
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
// called by wxMenuBar to build its accel table from the accels of all menus
|
|
|
|
bool HasAccels() const { return !m_accels.IsEmpty(); }
|
|
|
|
size_t GetAccelCount() const { return m_accels.GetCount(); }
|
1999-10-10 22:49:06 -04:00
|
|
|
size_t CopyAccels(wxAcceleratorEntry *accels) const;
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// called by wxMenuItem when its accels changes
|
|
|
|
void UpdateAccel(wxMenuItem *item);
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// helper used by wxMenu itself (returns the index in m_accels)
|
|
|
|
int FindAccel(int id) const;
|
|
|
|
#endif // wxUSE_ACCEL
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// common part of all ctors
|
1999-11-01 23:38:14 -05:00
|
|
|
void Init();
|
|
|
|
|
|
|
|
// common part of Append/Insert (behaves as Append is pos == (size_t)-1)
|
|
|
|
bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
|
|
|
|
|
|
|
|
// if TRUE, insert a breal before appending the next item
|
|
|
|
bool m_doBreak;
|
|
|
|
|
|
|
|
// the menu handle of this menu
|
|
|
|
WXHMENU m_hMenu;
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
// the accelerators for our menu items
|
|
|
|
wxAcceleratorArray m_accels;
|
1999-10-10 22:49:06 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenu)
|
1999-07-29 01:11:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu Bar (a la Windows)
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
|
1999-07-29 01:11:30 -04:00
|
|
|
{
|
1999-10-10 22:49:06 -04:00
|
|
|
public:
|
|
|
|
// ctors & dtor
|
|
|
|
// default constructor
|
|
|
|
wxMenuBar();
|
1999-11-01 23:38:14 -05:00
|
|
|
// unused under OS2
|
1999-10-10 22:49:06 -04:00
|
|
|
wxMenuBar(long style);
|
|
|
|
// menubar takes ownership of the menus arrays but copies the titles
|
|
|
|
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
|
|
|
|
virtual ~wxMenuBar();
|
|
|
|
|
|
|
|
// menubar construction
|
1999-11-01 23:38:14 -05:00
|
|
|
virtual bool Append( wxMenu *menu, const wxString &title );
|
|
|
|
virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
|
|
|
|
virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
|
|
|
|
virtual wxMenu *Remove(size_t pos);
|
|
|
|
|
1999-10-10 22:49:06 -04:00
|
|
|
virtual int FindMenuItem(const wxString& menuString,
|
|
|
|
const wxString& itemString) const;
|
1999-11-01 23:38:14 -05:00
|
|
|
virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
|
1999-10-10 22:49:06 -04:00
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
virtual void EnableTop( size_t pos, bool flag );
|
|
|
|
virtual void SetLabelTop( size_t pos, const wxString& label );
|
|
|
|
virtual wxString GetLabelTop( size_t pos ) const;
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
// compatibility: these functions are deprecated
|
1999-11-01 23:38:14 -05:00
|
|
|
#if WXWIN_COMPATIBILITY
|
|
|
|
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
|
|
|
|
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
|
|
|
|
|
|
|
|
bool Enabled(int id) const { return IsEnabled(id); }
|
|
|
|
bool Checked(int id) const { return IsChecked(id); }
|
1999-10-10 22:49:06 -04:00
|
|
|
#endif // WXWIN_COMPATIBILITY
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
// implementation from now on
|
|
|
|
WXHMENU Create();
|
|
|
|
int FindMenu(const wxString& title);
|
|
|
|
void Detach();
|
|
|
|
|
1999-10-10 22:49:06 -04:00
|
|
|
// returns TRUE if we're attached to a frame
|
1999-11-01 23:38:14 -05:00
|
|
|
bool IsAttached() const { return m_menuBarFrame != NULL; }
|
1999-10-10 22:49:06 -04:00
|
|
|
// get the frame we live in
|
1999-11-01 23:38:14 -05:00
|
|
|
wxFrame *GetFrame() const { return m_menuBarFrame; }
|
1999-10-10 22:49:06 -04:00
|
|
|
// attach to a frame
|
|
|
|
void Attach(wxFrame *frame);
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
// get the accel table for all the menus
|
|
|
|
const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
|
|
|
|
|
|
|
|
// update the accel table (must be called after adding/deletign a menu)
|
|
|
|
void RebuildAccelTable();
|
1999-10-10 22:49:06 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
// get the menu handle
|
2000-02-18 18:35:39 -05:00
|
|
|
WXHMENU GetHMenu() const { return m_hMenu; }
|
|
|
|
unsigned long GetMenubarId() const { return m_ulMenubarId; }
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
// if the menubar is modified, the display is not updated automatically,
|
|
|
|
// call this function to update it (m_menuBarFrame should be !NULL)
|
1999-11-01 23:38:14 -05:00
|
|
|
void Refresh( bool eraseBackground = TRUE
|
|
|
|
,const wxRect *rect = (const wxRect *) NULL
|
|
|
|
);
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
1999-11-01 23:38:14 -05:00
|
|
|
#if WXWIN_COMPATIBILITY
|
1999-10-10 22:49:06 -04:00
|
|
|
wxEvtHandler *m_eventHandler;
|
1999-11-01 23:38:14 -05:00
|
|
|
#endif // WXWIN_COMPATIBILITY
|
|
|
|
|
|
|
|
wxArrayString m_titles;
|
|
|
|
|
2000-02-18 18:35:39 -05:00
|
|
|
wxFrame* m_menuBarFrame;
|
|
|
|
WXHMENU m_hMenu;
|
|
|
|
unsigned long m_ulMenubarId;
|
1999-10-10 22:49:06 -04:00
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// the accelerator table for all accelerators in all our menus
|
|
|
|
wxAcceleratorTable m_accelTable;
|
|
|
|
#endif // wxUSE_ACCEL
|
1999-11-01 23:38:14 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenuBar)
|
1999-07-29 01:11:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_MENU_H_
|