1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-03-20 21:35:08 -05:00
|
|
|
// Name: wx/msw/menu.h
|
1998-05-20 10:12:05 -04: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 05:34:04 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-07 19:52:45 -04:00
|
|
|
#ifndef _WX_MENU_H_
|
|
|
|
#define _WX_MENU_H_
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-08-09 08:38:21 -04:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
1999-03-24 14:05:19 -05:00
|
|
|
#pragma interface "menu.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
#endif
|
|
|
|
|
1999-08-23 11:23:29 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-10-25 11:51:37 -04:00
|
|
|
#include "wx/accel.h"
|
1999-11-01 20:25:43 -05:00
|
|
|
#include "wx/dynarray.h"
|
|
|
|
|
2003-10-08 18:13:14 -04:00
|
|
|
WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
|
1999-08-23 11:23:29 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-03-24 14:05:19 -05:00
|
|
|
class WXDLLEXPORT wxFrame;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-07-18 10:12:53 -04:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
|
|
|
class WXDLLEXPORT wxToolBar;
|
|
|
|
#endif
|
|
|
|
|
2004-06-12 18:58:28 -04: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 15:55:46 -04:00
|
|
|
#include "wx/arrstr.h"
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-24 14:05:19 -05:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
class WXDLLEXPORT wxMenu : public wxMenuBase
|
1998-05-20 10:12:05 -04:00
|
|
|
{
|
|
|
|
public:
|
1999-07-19 18:17:40 -04:00
|
|
|
// ctors & dtor
|
1999-11-01 20:25:43 -05:00
|
|
|
wxMenu(const wxString& title, long style = 0)
|
|
|
|
: wxMenuBase(title, style) { Init(); }
|
1999-08-04 09:01:20 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
|
1999-07-19 18:17:40 -04:00
|
|
|
|
1999-03-24 14:05:19 -05:00
|
|
|
virtual ~wxMenu();
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// implement base class virtuals
|
2004-01-23 13:46:05 -05:00
|
|
|
virtual wxMenuItem* DoAppend(wxMenuItem *item);
|
|
|
|
virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
|
|
|
|
virtual wxMenuItem* DoRemove(wxMenuItem *item);
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
virtual void Break();
|
|
|
|
|
|
|
|
virtual void SetTitle(const wxString& title);
|
1999-03-24 14:05:19 -05:00
|
|
|
|
2003-07-02 09:45:49 -04: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-01 20:25:43 -05:00
|
|
|
// implementation only from now on
|
|
|
|
// -------------------------------
|
1999-03-24 14:05:19 -05:00
|
|
|
|
2002-03-20 21:35:08 -05:00
|
|
|
virtual void Attach(wxMenuBarBase *menubar);
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
bool MSWCommand(WXUINT param, WXWORD id);
|
1999-03-24 14:05:19 -05:00
|
|
|
|
|
|
|
// semi-private accessors
|
|
|
|
// get the window which contains this menu
|
|
|
|
wxWindow *GetWindow() const;
|
|
|
|
// get the menu handle
|
1999-11-01 20:25:43 -05:00
|
|
|
WXHMENU GetHMenu() const { return m_hMenu; }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1999-06-13 18:54:04 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 20:25:43 -05: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 11:51:37 -04:00
|
|
|
size_t GetAccelCount() const { return m_accels.GetCount(); }
|
1999-05-18 20:53:27 -04:00
|
|
|
size_t CopyAccels(wxAcceleratorEntry *accels) const;
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// called by wxMenuItem when its accels changes
|
|
|
|
void UpdateAccel(wxMenuItem *item);
|
1999-05-18 20:53:27 -04:00
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// helper used by wxMenu itself (returns the index in m_accels)
|
|
|
|
int FindAccel(int id) const;
|
|
|
|
#endif // wxUSE_ACCEL
|
1999-05-18 20:53:27 -04:00
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
private:
|
1999-07-19 18:17:40 -04:00
|
|
|
// common part of all ctors
|
1999-11-01 20:25:43 -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);
|
|
|
|
|
2002-03-20 21:35:08 -05:00
|
|
|
// terminate the current radio group, if any
|
|
|
|
void EndRadioGroup();
|
|
|
|
|
2004-08-30 06:18:55 -04:00
|
|
|
// if true, insert a breal before appending the next item
|
1999-11-01 20:25:43 -05:00
|
|
|
bool m_doBreak;
|
|
|
|
|
2002-03-20 21:35:08 -05:00
|
|
|
// the position of the first item in the current radio group or -1
|
|
|
|
int m_startRadioGroup;
|
|
|
|
|
1999-11-01 20:25:43 -05:00
|
|
|
// the menu handle of this menu
|
|
|
|
WXHMENU m_hMenu;
|
1999-05-18 20:53:27 -04:00
|
|
|
|
1999-06-13 18:54:04 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-10-25 11:51:37 -04:00
|
|
|
// the accelerators for our menu items
|
|
|
|
wxAcceleratorArray m_accels;
|
1999-06-13 18:54:04 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-11-01 20:25:43 -05:00
|
|
|
|
2003-07-21 20:24:07 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Menu Bar (a la Windows)
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-03-24 14:05:19 -05:00
|
|
|
|
2003-08-25 19:26:49 -04:00
|
|
|
class WXDLLEXPORT wxMenuInfo : public wxObject
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
wxMenuInfo() { m_menu = NULL ; }
|
|
|
|
virtual ~wxMenuInfo() { }
|
|
|
|
|
2004-08-30 06:18:55 -04:00
|
|
|
void Create( wxMenu *menu , const wxString &title )
|
2003-08-25 19:26:49 -04:00
|
|
|
{ m_menu = menu ; m_title = title ; }
|
|
|
|
wxMenu* GetMenu() const { return m_menu ; }
|
|
|
|
wxString GetTitle() const { return m_title ; }
|
|
|
|
private :
|
|
|
|
wxMenu *m_menu ;
|
|
|
|
wxString m_title ;
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxMenuInfo) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList );
|
|
|
|
|
1999-10-26 15:35:25 -04:00
|
|
|
class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
|
1998-05-20 10:12:05 -04:00
|
|
|
{
|
1999-03-24 14:05:19 -05:00
|
|
|
public:
|
2004-08-30 06:18:55 -04:00
|
|
|
// ctors & dtor
|
1999-04-03 17:25:12 -05:00
|
|
|
// default constructor
|
1999-03-24 14:05:19 -05:00
|
|
|
wxMenuBar();
|
1999-04-03 17:25:12 -05:00
|
|
|
// unused under MSW
|
1999-03-24 14:05:19 -05:00
|
|
|
wxMenuBar(long style);
|
1999-04-03 17:25:12 -05:00
|
|
|
// menubar takes ownership of the menus arrays but copies the titles
|
1999-03-24 14:05:19 -05:00
|
|
|
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
|
|
|
|
virtual ~wxMenuBar();
|
|
|
|
|
|
|
|
// menubar construction
|
2003-08-25 19:26:49 -04:00
|
|
|
bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ) ; }
|
|
|
|
const wxMenuInfoList& GetMenuInfos() const ;
|
|
|
|
|
1999-10-26 15:35:25 -04: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 14:05:19 -05:00
|
|
|
|
1999-10-26 15:35:25 -04: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 14:05:19 -05:00
|
|
|
|
1999-10-26 15:35:25 -04:00
|
|
|
// implementation from now on
|
|
|
|
WXHMENU Create();
|
2001-06-26 16:59:19 -04:00
|
|
|
virtual void Detach();
|
|
|
|
virtual void Attach(wxFrame *frame);
|
1999-04-03 17:25:12 -05:00
|
|
|
|
2004-06-12 18:58:28 -04:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
2003-07-18 10:12:53 -04: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 18:58:28 -04:00
|
|
|
#ifdef WINCE_WITH_COMMANDBAR
|
2004-05-27 05:09:19 -04:00
|
|
|
WXHWND GetCommandBar() const { return m_commandBar; }
|
2004-05-27 07:31:12 -04:00
|
|
|
bool AddAdornments(long style);
|
2004-05-27 05:09:19 -04:00
|
|
|
#endif
|
|
|
|
|
1999-06-13 18:54:04 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-11-01 20:25:43 -05:00
|
|
|
// get the accel table for all the menus
|
1999-05-18 20:53:27 -04:00
|
|
|
const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
|
1999-11-01 20:25:43 -05:00
|
|
|
|
|
|
|
// update the accel table (must be called after adding/deletign a menu)
|
|
|
|
void RebuildAccelTable();
|
1999-06-13 18:54:04 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
1999-04-03 17:25:12 -05: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 07:44:24 -04:00
|
|
|
// To avoid compile warning
|
2003-07-02 09:45:49 -04:00
|
|
|
void Refresh( bool eraseBackground,
|
2003-07-02 07:44:24 -04:00
|
|
|
const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); }
|
|
|
|
|
1999-09-06 08:53:09 -04:00
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
2003-08-25 19:26:49 -04:00
|
|
|
wxArrayString m_titles ;
|
|
|
|
wxMenuInfoList m_menuInfos;
|
1999-10-26 15:35:25 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
WXHMENU m_hMenu;
|
1999-05-18 20:53:27 -04:00
|
|
|
|
2004-01-14 00:57:09 -05:00
|
|
|
// Return the MSW position for a wxMenu which is sometimes different from
|
2004-05-23 10:56:36 -04:00
|
|
|
// the wxWidgets position.
|
2004-01-14 00:57:09 -05:00
|
|
|
int MSWPositionForWxMenu(wxMenu *menu, int wxpos);
|
1999-06-13 18:54:04 -04:00
|
|
|
#if wxUSE_ACCEL
|
1999-05-18 20:53:27 -04:00
|
|
|
// the accelerator table for all accelerators in all our menus
|
|
|
|
wxAcceleratorTable m_accelTable;
|
1999-06-13 18:54:04 -04:00
|
|
|
#endif // wxUSE_ACCEL
|
1999-10-26 15:35:25 -04:00
|
|
|
|
2003-07-18 10:12:53 -04:00
|
|
|
#if defined(__WXWINCE__) && wxUSE_TOOLBAR
|
|
|
|
wxToolBar* m_toolBar;
|
|
|
|
#endif
|
2004-06-12 18:58:28 -04:00
|
|
|
|
|
|
|
#ifdef WINCE_WITH_COMMANDBAR
|
2003-12-27 20:07:31 -05:00
|
|
|
WXHWND m_commandBar;
|
2004-05-27 07:31:12 -04:00
|
|
|
bool m_adornmentsAdded;
|
2003-12-27 20:07:31 -05:00
|
|
|
#endif
|
2003-07-18 10:12:53 -04:00
|
|
|
|
1999-10-26 15:35:25 -04:00
|
|
|
private:
|
2003-07-21 20:24:07 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
1998-08-07 19:52:45 -04:00
|
|
|
#endif // _WX_MENU_H_
|