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$
|
2003-03-17 10:34:04 +00:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
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
|
|
|
|
2003-08-09 12:38:21 +00:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
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"
|
|
|
|
|
2003-10-08 22:13:14 +00:00
|
|
|
WX_DEFINE_EXPORTED_ARRAY_PTR(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
|
|
|
|
2003-07-18 14:12:53 +00:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
|
|
|
class WXDLLEXPORT wxToolBar;
|
|
|
|
#endif
|
|
|
|
|
2004-06-12 22:58:28 +00:00
|
|
|
|
|
|
|
// Not using a combined wxToolBar/wxMenuBar? then use
|
|
|
|
// a commandbar in WinCE .NET to implement the
|
|
|
|
// menubar, since there is no ::SetMenu function.
|
|
|
|
#if defined(__WXWINCE__)
|
|
|
|
# if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
|
|
|
|
defined(__HANDHELDPC__)
|
|
|
|
# define WINCE_WITH_COMMANDBAR
|
|
|
|
# else
|
|
|
|
# define WINCE_WITHOUT_COMMANDBAR
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-07-21 19:55:46 +00:00
|
|
|
#include "wx/arrstr.h"
|
|
|
|
|
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
|
2004-01-23 18:46:05 +00:00
|
|
|
virtual wxMenuItem* DoAppend(wxMenuItem *item);
|
|
|
|
virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
|
|
|
|
virtual wxMenuItem* DoRemove(wxMenuItem *item);
|
1999-11-02 01:25:43 +00:00
|
|
|
|
|
|
|
virtual void Break();
|
|
|
|
|
|
|
|
virtual void SetTitle(const wxString& title);
|
1999-03-24 19:05:19 +00:00
|
|
|
|
2003-07-02 13:45:49 +00:00
|
|
|
// deprecated functions
|
|
|
|
#if wxUSE_MENU_CALLBACK
|
|
|
|
wxMenu(const wxString& title, const wxFunction func)
|
|
|
|
: wxMenuBase(title)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
Callback(func);
|
|
|
|
}
|
|
|
|
#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();
|
|
|
|
|
2004-08-30 10:18:55 +00:00
|
|
|
// if true, insert a breal before appending the next item
|
1999-11-02 01:25:43 +00:00
|
|
|
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
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu Bar (a la Windows)
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-24 19:05:19 +00:00
|
|
|
|
2003-08-25 23:26:49 +00:00
|
|
|
class WXDLLEXPORT wxMenuInfo : public wxObject
|
|
|
|
{
|
|
|
|
public :
|
2005-02-06 16:17:18 +00:00
|
|
|
wxMenuInfo() { m_menu = NULL; }
|
2003-08-25 23:26:49 +00:00
|
|
|
virtual ~wxMenuInfo() { }
|
|
|
|
|
2004-08-30 10:18:55 +00:00
|
|
|
void Create( wxMenu *menu , const wxString &title )
|
2005-02-06 16:17:18 +00:00
|
|
|
{ m_menu = menu; m_title = title; }
|
|
|
|
wxMenu* GetMenu() const { return m_menu; }
|
|
|
|
wxString GetTitle() const { return m_title; }
|
2003-08-25 23:26:49 +00:00
|
|
|
private :
|
2005-02-06 16:17:18 +00:00
|
|
|
wxMenu *m_menu;
|
|
|
|
wxString m_title;
|
2003-08-25 23:26:49 +00:00
|
|
|
|
2005-02-06 16:17:18 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenuInfo)
|
|
|
|
};
|
2003-08-25 23:26:49 +00:00
|
|
|
|
|
|
|
WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
|
|
|
|
|
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:
|
2004-08-30 10:18:55 +00:00
|
|
|
// 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
|
2005-03-17 23:45:24 +00:00
|
|
|
wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
|
1999-03-24 19:05:19 +00:00
|
|
|
virtual ~wxMenuBar();
|
|
|
|
|
|
|
|
// menubar construction
|
2005-02-06 16:17:18 +00:00
|
|
|
bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); }
|
|
|
|
const wxMenuInfoList& GetMenuInfos() const;
|
2003-08-25 23:26:49 +00:00
|
|
|
|
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
|
|
|
// 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
|
|
|
|
2004-06-12 22:58:28 +00:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
2003-07-18 14:12:53 +00:00
|
|
|
// Under WinCE, a menubar is owned by the frame's toolbar
|
|
|
|
void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; }
|
|
|
|
wxToolBar* GetToolBar() const { return m_toolBar; }
|
|
|
|
#endif
|
|
|
|
|
2004-06-12 22:58:28 +00:00
|
|
|
#ifdef WINCE_WITH_COMMANDBAR
|
2004-05-27 09:09:19 +00:00
|
|
|
WXHWND GetCommandBar() const { return m_commandBar; }
|
2004-05-27 11:31:12 +00:00
|
|
|
bool AddAdornments(long style);
|
2004-05-27 09:09:19 +00:00
|
|
|
#endif
|
|
|
|
|
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();
|
|
|
|
|
2003-07-02 11:44:24 +00:00
|
|
|
// To avoid compile warning
|
2003-07-02 13:45:49 +00:00
|
|
|
void Refresh( bool eraseBackground,
|
2003-07-02 11:44:24 +00:00
|
|
|
const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
|
|
|
|
|
1999-09-06 12:53:09 +00:00
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
2005-02-06 16:17:18 +00:00
|
|
|
wxArrayString m_titles;
|
2003-08-25 23:26:49 +00:00
|
|
|
wxMenuInfoList m_menuInfos;
|
1999-10-26 19:35:25 +00:00
|
|
|
|
1999-04-03 22:25:12 +00:00
|
|
|
WXHMENU m_hMenu;
|
1999-05-19 00:53:27 +00:00
|
|
|
|
2004-01-14 05:57:09 +00:00
|
|
|
// Return the MSW position for a wxMenu which is sometimes different from
|
2004-05-23 14:56:36 +00:00
|
|
|
// the wxWidgets position.
|
2004-01-14 05:57:09 +00:00
|
|
|
int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
|
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
|
|
|
|
2003-07-18 14:12:53 +00:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
|
|
|
wxToolBar* m_toolBar;
|
|
|
|
#endif
|
2004-06-12 22:58:28 +00:00
|
|
|
|
|
|
|
#ifdef WINCE_WITH_COMMANDBAR
|
2003-12-28 01:07:31 +00:00
|
|
|
WXHWND m_commandBar;
|
2004-05-27 11:31:12 +00:00
|
|
|
bool m_adornmentsAdded;
|
2003-12-28 01:07:31 +00:00
|
|
|
#endif
|
2003-07-18 14:12:53 +00:00
|
|
|
|
1999-10-26 19:35:25 +00:00
|
|
|
private:
|
2003-07-22 00:24:07 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
1998-08-07 23:52:45 +00:00
|
|
|
#endif // _WX_MENU_H_
|