2001-06-26 20:59:19 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/univ/menu.h
|
|
|
|
// Purpose: wxMenu and wxMenuBar classes for wxUniversal
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 05.05.01
|
2001-07-02 19:42:27 +00:00
|
|
|
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2001-06-26 20:59:19 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_UNIV_MENU_H_
|
|
|
|
#define _WX_UNIV_MENU_H_
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
#include "wx/accel.h"
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
#include "wx/dynarray.h"
|
|
|
|
|
|
|
|
// fwd declarations
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenuInfo;
|
2003-08-03 20:58:56 +00:00
|
|
|
WX_DECLARE_EXPORTED_OBJARRAY(wxMenuInfo, wxMenuInfoArray);
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxMenuGeometryInfo;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxPopupMenuWindow;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxRenderer;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMenu
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
|
2001-06-26 20:59:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors and dtor
|
|
|
|
wxMenu(const wxString& title, long style = 0)
|
|
|
|
: wxMenuBase(title, style) { Init(); }
|
|
|
|
|
|
|
|
wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
|
|
|
|
|
|
|
|
virtual ~wxMenu();
|
|
|
|
|
|
|
|
// called by wxMenuItem when an item of this menu changes
|
|
|
|
void RefreshItem(wxMenuItem *item);
|
|
|
|
|
|
|
|
// does the menu have any items?
|
|
|
|
bool IsEmpty() const { return !GetMenuItems().GetFirst(); }
|
|
|
|
|
|
|
|
// show this menu at the given position (in screen coords) and optionally
|
|
|
|
// select its first item
|
|
|
|
void Popup(const wxPoint& pos, const wxSize& size,
|
2004-08-10 13:08:43 +00:00
|
|
|
bool selectFirst = true);
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// dismiss the menu
|
|
|
|
void Dismiss();
|
|
|
|
|
|
|
|
// override the base class methods to connect/disconnect event handlers
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void Attach(wxMenuBarBase *menubar) wxOVERRIDE;
|
|
|
|
virtual void Detach() wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// implementation only from here
|
|
|
|
|
2004-08-10 13:08:43 +00:00
|
|
|
// do as if this item were clicked, return true if the resulting event was
|
|
|
|
// processed, false otherwise
|
2001-06-26 20:59:19 +00:00
|
|
|
bool ClickItem(wxMenuItem *item);
|
|
|
|
|
2004-08-10 13:08:43 +00:00
|
|
|
// process the key event, return true if done
|
2001-06-26 20:59:19 +00:00
|
|
|
bool ProcessKeyDown(int key);
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// find the item for the given accel and generate an event if found
|
|
|
|
bool ProcessAccelEvent(const wxKeyEvent& event);
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// implement base class virtuals
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxMenuItem* DoAppend(wxMenuItem *item) wxOVERRIDE;
|
|
|
|
virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item) wxOVERRIDE;
|
|
|
|
virtual wxMenuItem* DoRemove(wxMenuItem *item) wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// common part of DoAppend and DoInsert
|
|
|
|
void OnItemAdded(wxMenuItem *item);
|
|
|
|
|
|
|
|
// called by wxPopupMenuWindow when the window is hidden
|
|
|
|
void OnDismiss(bool dismissParent);
|
|
|
|
|
|
|
|
// return true if the menu is currently shown on screen
|
|
|
|
bool IsShown() const;
|
|
|
|
|
|
|
|
// get the menu geometry info
|
|
|
|
const wxMenuGeometryInfo& GetGeometryInfo() const;
|
|
|
|
|
|
|
|
// forget old menu geometry info
|
|
|
|
void InvalidateGeometryInfo();
|
|
|
|
|
|
|
|
// return either the menubar or the invoking window, normally never NULL
|
|
|
|
wxWindow *GetRootWindow() const;
|
|
|
|
|
|
|
|
// get the renderer we use for drawing: either the one of the menu bar or
|
|
|
|
// the one of the window if we're a popup menu
|
|
|
|
wxRenderer *GetRenderer() const;
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// add/remove accel for the given menu item
|
|
|
|
void AddAccelFor(wxMenuItem *item);
|
|
|
|
void RemoveAccelFor(wxMenuItem *item);
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
private:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
2003-02-02 14:50:05 +00:00
|
|
|
// terminate the current radio group, if any
|
|
|
|
void EndRadioGroup();
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
// the exact menu geometry is defined by a struct derived from this one
|
|
|
|
// which is opaque and defined by the renderer
|
|
|
|
wxMenuGeometryInfo *m_geometry;
|
|
|
|
|
|
|
|
// the menu shown on screen or NULL if not currently shown
|
|
|
|
wxPopupMenuWindow *m_popupMenu;
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// the accel table for this menu
|
|
|
|
wxAcceleratorTable m_accelTable;
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
2003-02-02 14:50:05 +00:00
|
|
|
// the position of the first item in the current radio group or -1
|
|
|
|
int m_startRadioGroup;
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
// it calls out OnDismiss()
|
2001-07-04 20:11:26 +00:00
|
|
|
friend class wxPopupMenuWindow;
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxMenu);
|
2001-06-26 20:59:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxMenuBar
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
|
2001-06-26 20:59:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctors and dtor
|
|
|
|
wxMenuBar(long WXUNUSED(style) = 0) { Init(); }
|
2005-03-18 14:07:22 +00:00
|
|
|
wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
|
2001-06-26 20:59:19 +00:00
|
|
|
virtual ~wxMenuBar();
|
|
|
|
|
|
|
|
// implement base class virtuals
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool Append( wxMenu *menu, const wxString &title ) wxOVERRIDE;
|
|
|
|
virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title) wxOVERRIDE;
|
|
|
|
virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title) wxOVERRIDE;
|
|
|
|
virtual wxMenu *Remove(size_t pos) wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void EnableTop(size_t pos, bool enable) wxOVERRIDE;
|
|
|
|
virtual bool IsEnabledTop(size_t pos) const wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void SetMenuLabel(size_t pos, const wxString& label) wxOVERRIDE;
|
|
|
|
virtual wxString GetMenuLabel(size_t pos) const wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void Attach(wxFrame *frame) wxOVERRIDE;
|
|
|
|
virtual void Detach() wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// get the next item for the givan accel letter (used by wxFrame), return
|
|
|
|
// -1 if none
|
|
|
|
//
|
2004-08-10 13:08:43 +00:00
|
|
|
// if unique is not NULL, filled with true if there is only one item with
|
|
|
|
// this accel, false if two or more
|
2001-06-26 20:59:19 +00:00
|
|
|
int FindNextItemForAccel(int idxStart,
|
|
|
|
int keycode,
|
|
|
|
bool *unique = NULL) const;
|
|
|
|
|
|
|
|
// called by wxFrame to set focus to or open the given menu
|
|
|
|
void SelectMenu(size_t pos);
|
|
|
|
void PopupMenu(size_t pos);
|
|
|
|
|
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// find the item for the given accel and generate an event if found
|
|
|
|
bool ProcessAccelEvent(const wxKeyEvent& event);
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
|
|
|
// called by wxMenu when it is dismissed
|
2004-08-10 13:08:43 +00:00
|
|
|
void OnDismissMenu(bool dismissMenuBar = false);
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void OnLeftDown(wxMouseEvent& event);
|
|
|
|
void OnMouseMove(wxMouseEvent& event);
|
|
|
|
void OnKeyDown(wxKeyEvent& event);
|
|
|
|
void OnKillFocus(wxFocusEvent& event);
|
|
|
|
|
2004-08-10 13:08:43 +00:00
|
|
|
// process the mouse move event, return true if we did, false to continue
|
2001-06-26 20:59:19 +00:00
|
|
|
// processing as usual
|
|
|
|
//
|
|
|
|
// the coordinates are client coordinates of menubar, convert if necessary
|
|
|
|
bool ProcessMouseEvent(const wxPoint& pt);
|
|
|
|
|
|
|
|
// called when the menu bar loses mouse capture - it is not hidden unlike
|
|
|
|
// menus, but it doesn't have modal status any longer
|
|
|
|
void OnDismiss();
|
|
|
|
|
|
|
|
// draw the menubar
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDraw(wxControlRenderer *renderer) wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// menubar geometry
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxSize DoGetBestClientSize() const wxOVERRIDE;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// has the menubar been created already?
|
|
|
|
bool IsCreated() const { return m_frameLast != NULL; }
|
|
|
|
|
|
|
|
// "fast" version of GetMenuCount()
|
|
|
|
size_t GetCount() const { return m_menuInfos.GetCount(); }
|
|
|
|
|
|
|
|
// get the (total) width of the specified menu
|
|
|
|
wxCoord GetItemWidth(size_t pos) const;
|
|
|
|
|
|
|
|
// get the rect of the item
|
|
|
|
wxRect GetItemRect(size_t pos) const;
|
|
|
|
|
|
|
|
// get the menu from the given point or -1 if none
|
|
|
|
int GetMenuFromPoint(const wxPoint& pos) const;
|
|
|
|
|
|
|
|
// refresh the given item
|
|
|
|
void RefreshItem(size_t pos);
|
|
|
|
|
|
|
|
// refresh all items after this one (including it)
|
|
|
|
void RefreshAllItemsAfter(size_t pos);
|
|
|
|
|
|
|
|
// hide the currently shown menu and show this one
|
|
|
|
void DoSelectMenu(size_t pos);
|
|
|
|
|
|
|
|
// popup the currently selected menu
|
2004-08-10 13:08:43 +00:00
|
|
|
void PopupCurrentMenu(bool selectFirst = true);
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// hide the currently selected menu
|
|
|
|
void DismissMenu();
|
|
|
|
|
|
|
|
// do we show a menu currently?
|
|
|
|
bool IsShowingMenu() const { return m_menuShown != 0; }
|
|
|
|
|
|
|
|
// we don't want to have focus except while selecting from menu
|
|
|
|
void GiveAwayFocus();
|
|
|
|
|
2005-05-06 13:42:34 +00:00
|
|
|
// Release the mouse capture if we have it
|
|
|
|
bool ReleaseMouseCapture();
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
// the array containing extra menu info we need
|
|
|
|
wxMenuInfoArray m_menuInfos;
|
|
|
|
|
|
|
|
// the current item (only used when menubar has focus)
|
|
|
|
int m_current;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// the last frame to which we were attached, NULL initially
|
|
|
|
wxFrame *m_frameLast;
|
|
|
|
|
|
|
|
// the currently shown menu or NULL
|
|
|
|
wxMenu *m_menuShown;
|
|
|
|
|
|
|
|
// should be showing the menu? this is subtly different from m_menuShown !=
|
|
|
|
// NULL as the menu which should be shown may be disabled in which case we
|
|
|
|
// don't show it - but will do as soon as the focus shifts to another menu
|
|
|
|
bool m_shouldShowMenu;
|
|
|
|
|
|
|
|
// it calls out ProcessMouseEvent()
|
2001-07-04 20:11:26 +00:00
|
|
|
friend class wxPopupMenuWindow;
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxMenuBar);
|
2001-06-26 20:59:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_UNIV_MENU_H_
|