1998-05-20 14:12:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-03-21 02:35:08 +00:00
|
|
|
// Name: wx/msw/menu.h
|
1998-05-20 14:12:05 +00:00
|
|
|
// Purpose: wxMenu, wxMenuBar classes
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
|
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1998-08-07 15:09:04 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-20 14:12:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-07 23:52:45 +00:00
|
|
|
#ifndef _WX_MENU_H_
|
|
|
|
#define _WX_MENU_H_
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-03-24 19:05:19 +00:00
|
|
|
#pragma interface "menu.h"
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-23 15:23:29 +00:00
|
|
|
#if wxUSE_ACCEL
|
1999-10-25 15:51:37 +00:00
|
|
|
#include "wx/accel.h"
|
1999-11-02 01:25:43 +00:00
|
|
|
#include "wx/dynarray.h"
|
|
|
|
|
|
|
|
WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
|
1999-08-23 15:23:29 +00:00
|
|
|
#endif // wxUSE_ACCEL
|
1998-05-20 14:12:05 +00:00
|
|
|
|
1999-03-24 19:05:19 +00:00
|
|
|
class WXDLLEXPORT wxFrame;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-24 19:05:19 +00:00
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
class WXDLLEXPORT wxMenu : public wxMenuBase
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-07-19 22:17:40 +00:00
|
|
|
// ctors & dtor
|
1999-11-02 01:25:43 +00:00
|
|
|
wxMenu(const wxString& title, long style = 0)
|
|
|
|
: wxMenuBase(title, style) { Init(); }
|
1999-08-04 13:01:20 +00:00
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
|
1999-07-19 22:17:40 +00:00
|
|
|
|
1999-03-24 19:05:19 +00:00
|
|
|
virtual ~wxMenu();
|
|
|
|
|
1999-11-02 01:25:43 +00: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-03-24 19:05:19 +00:00
|
|
|
|
1999-11-19 16:19:33 +00:00
|
|
|
// deprecated functions
|
|
|
|
#if wxUSE_MENU_CALLBACK
|
1999-11-02 01:25:43 +00:00
|
|
|
wxMenu(const wxString& title, const wxFunction func)
|
|
|
|
: wxMenuBase(title)
|
|
|
|
{
|
2000-01-25 15:35:55 +00:00
|
|
|
Init();
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
Callback(func);
|
|
|
|
}
|
1999-11-19 16:19:33 +00:00
|
|
|
#endif // wxUSE_MENU_CALLBACK
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// implementation only from now on
|
|
|
|
// -------------------------------
|
1999-03-24 19:05:19 +00:00
|
|
|
|
2002-03-21 02:35:08 +00:00
|
|
|
virtual void Attach(wxMenuBarBase *menubar);
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
bool MSWCommand(WXUINT param, WXWORD id);
|
1999-03-24 19:05:19 +00:00
|
|
|
|
|
|
|
// semi-private accessors
|
|
|
|
// get the window which contains this menu
|
|
|
|
wxWindow *GetWindow() const;
|
|
|
|
// get the menu handle
|
1999-11-02 01:25:43 +00:00
|
|
|
WXHMENU GetHMenu() const { return m_hMenu; }
|
1998-05-20 14:12:05 +00:00
|
|
|
|
1999-06-13 22:54:04 +00:00
|
|
|
#if wxUSE_ACCEL
|
1999-11-02 01:25:43 +00:00
|
|
|
// called by wxMenuBar to build its accel table from the accels of all menus
|
|
|
|
bool HasAccels() const { return !m_accels.IsEmpty(); }
|
1999-10-25 15:51:37 +00:00
|
|
|
size_t GetAccelCount() const { return m_accels.GetCount(); }
|
1999-05-19 00:53:27 +00:00
|
|
|
size_t CopyAccels(wxAcceleratorEntry *accels) const;
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// called by wxMenuItem when its accels changes
|
|
|
|
void UpdateAccel(wxMenuItem *item);
|
1999-05-19 00:53:27 +00:00
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// helper used by wxMenu itself (returns the index in m_accels)
|
|
|
|
int FindAccel(int id) const;
|
|
|
|
#endif // wxUSE_ACCEL
|
1999-05-19 00:53:27 +00:00
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
private:
|
1999-07-19 22:17:40 +00:00
|
|
|
// common part of all ctors
|
1999-11-02 01:25:43 +00: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);
|
|
|
|
|
2002-03-21 02:35:08 +00:00
|
|
|
// terminate the current radio group, if any
|
|
|
|
void EndRadioGroup();
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// if TRUE, insert a breal before appending the next item
|
|
|
|
bool m_doBreak;
|
|
|
|
|
2002-03-21 02:35:08 +00:00
|
|
|
// the position of the first item in the current radio group or -1
|
|
|
|
int m_startRadioGroup;
|
|
|
|
|
1999-11-02 01:25:43 +00:00
|
|
|
// the menu handle of this menu
|
|
|
|
WXHMENU m_hMenu;
|
1999-05-19 00:53:27 +00:00
|
|
|
|
1999-06-13 22:54:04 +00:00
|
|
|
#if wxUSE_ACCEL
|
1999-10-25 15:51:37 +00:00
|
|
|
// the accelerators for our menu items
|
|
|
|
wxAcceleratorArray m_accels;
|
1999-06-13 22:54:04 +00:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-11-02 01:25:43 +00:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenu)
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu Bar (a la Windows)
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-24 19:05:19 +00:00
|
|
|
|
1999-10-26 19:35:25 +00:00
|
|
|
class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
1999-03-24 19:05:19 +00:00
|
|
|
public:
|
|
|
|
// ctors & dtor
|
1999-04-03 22:25:12 +00:00
|
|
|
// default constructor
|
1999-03-24 19:05:19 +00:00
|
|
|
wxMenuBar();
|
1999-04-03 22:25:12 +00:00
|
|
|
// unused under MSW
|
1999-03-24 19:05:19 +00:00
|
|
|
wxMenuBar(long style);
|
1999-04-03 22:25:12 +00:00
|
|
|
// menubar takes ownership of the menus arrays but copies the titles
|
1999-03-24 19:05:19 +00:00
|
|
|
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
|
|
|
|
virtual ~wxMenuBar();
|
|
|
|
|
|
|
|
// menubar construction
|
1999-10-26 19:35:25 +00: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-03-24 19:05:19 +00:00
|
|
|
|
1999-10-26 19:35:25 +00: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-03-24 19:05:19 +00:00
|
|
|
|
1999-10-26 19:35:25 +00:00
|
|
|
// compatibility: these functions are deprecated
|
1999-11-02 01:27:42 +00:00
|
|
|
#if WXWIN_COMPATIBILITY
|
1999-03-24 19:05:19 +00:00
|
|
|
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); }
|
|
|
|
#endif // WXWIN_COMPATIBILITY
|
1998-05-20 14:12:05 +00:00
|
|
|
|
1999-10-26 19:35:25 +00:00
|
|
|
// implementation from now on
|
|
|
|
WXHMENU Create();
|
2001-06-26 20:59:19 +00:00
|
|
|
virtual void Detach();
|
|
|
|
virtual void Attach(wxFrame *frame);
|
1999-04-03 22:25:12 +00:00
|
|
|
|
1999-06-13 22:54:04 +00:00
|
|
|
#if wxUSE_ACCEL
|
1999-11-02 01:25:43 +00:00
|
|
|
// get the accel table for all the menus
|
1999-05-19 00:53:27 +00:00
|
|
|
const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
|
1999-11-02 01:25:43 +00:00
|
|
|
|
|
|
|
// update the accel table (must be called after adding/deletign a menu)
|
|
|
|
void RebuildAccelTable();
|
1999-06-13 22:54:04 +00:00
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
1999-04-03 22:25:12 +00:00
|
|
|
// get the menu handle
|
|
|
|
WXHMENU GetHMenu() const { return m_hMenu; }
|
|
|
|
|
|
|
|
// if the menubar is modified, the display is not updated automatically,
|
|
|
|
// call this function to update it (m_menuBarFrame should be !NULL)
|
|
|
|
void Refresh();
|
|
|
|
|
1999-09-06 12:53:09 +00:00
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
1999-11-02 01:27:42 +00:00
|
|
|
#if WXWIN_COMPATIBILITY
|
1999-04-03 22:25:12 +00:00
|
|
|
wxEvtHandler *m_eventHandler;
|
1999-10-26 19:35:25 +00:00
|
|
|
#endif // WXWIN_COMPATIBILITY
|
|
|
|
|
|
|
|
wxArrayString m_titles;
|
|
|
|
|
1999-04-03 22:25:12 +00:00
|
|
|
WXHMENU m_hMenu;
|
1999-05-19 00:53:27 +00:00
|
|
|
|
1999-06-13 22:54:04 +00:00
|
|
|
#if wxUSE_ACCEL
|
1999-05-19 00:53:27 +00:00
|
|
|
// the accelerator table for all accelerators in all our menus
|
|
|
|
wxAcceleratorTable m_accelTable;
|
1999-06-13 22:54:04 +00:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-10-26 19:35:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenuBar)
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
1998-08-07 23:52:45 +00:00
|
|
|
#endif // _WX_MENU_H_
|