include/ax/ax_menu.h

Go to the documentation of this file.
00001 
00002 // Name:        ax_menu.h
00003 // Purpose:     Menu classes
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2009-03-20
00007 // RCS-ID:
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _AX_MENU_H_
00013 #define _AX_MENU_H_
00014 
00015 /*
00016  * Includes
00017  */
00018 
00019 #include "wx/dynarray.h"
00020 
00021 #include "ax/ax_property.h"
00022 
00023 /*
00024  * Forward declarations
00025  */
00026 
00027 class AxMenu;
00028 class AxMenuItem;
00029 class AxMenuItemData;
00030 class AxViewManager;
00031 class AxSpeechEvent;
00032 class AxActivator;
00033 class AxValidator;
00034 class AxMenuController;
00035 
00036 WX_DEFINE_ARRAY_PTR(AxMenu*, AxMenuArray);
00037 
00041 typedef enum {
00042     AxNavigationHintNone,
00043     AxNavigationHintUp,
00044     AxNavigationHintBack,
00045     AxNavigationHintHome
00046 } AxNavigationHint;
00047 
00052 typedef enum {
00053     AxMenuStyleNormal=0x0000,
00054     AxMenuStyleBold=0x0001,
00055     AxMenuStyleItalic=0x0002
00056 };
00057 
00058 // Standard menu identifiers
00059 #define AxIdentifierOK          wxT("OK")
00060 #define AxIdentifierCancel      wxT("CANCEL")
00061 #define AxIdentifierGoUp        wxT("GO UP")
00062 #define AxIdentifierYes         wxT("YES")
00063 #define AxIdentifierNo          wxT("NO")
00064 #define AxIdentifierExit        wxT("EXIT")
00065 #define AxIdentifierGoHome      wxT("GO HOME")
00066 
00067 // Navigation/speech identifiers for shortcuts
00068 
00069 #define AxIdentifierReadCurrentWord         wxT("READCURRENTWORD")
00070 #define AxIdentifierReadNextWord            wxT("READNEXTWORD")
00071 #define AxIdentifierReadPreviousWord        wxT("READPREVIOUSWORD")
00072 
00073 #define AxIdentifierReadCurrentSentence     wxT("READCURRENTSENTENCE")
00074 #define AxIdentifierReadNextSentence        wxT("READNEXTSENTENCE")
00075 #define AxIdentifierReadPreviousSentence    wxT("READPREVIOUSSENTENCE")
00076 
00077 #define AxIdentifierReadCurrentParagraph    wxT("READCURRENTPARAGRAPH")
00078 #define AxIdentifierReadNextParagraph       wxT("READNEXTPARAGRAPH")
00079 #define AxIdentifierReadPreviousParagraph   wxT("READPREVIOUSPARAGRAPH")
00080 
00081 #define AxIdentifierReadFromHere            wxT("READFROMHERE")
00082 #define AxIdentifierReadAll                 wxT("READALL")
00083 
00084 #define AxIdentifierDescribeContainerWindow wxT("DESCRIBECONTAINERWINDOW")
00085 #define AxIdentifierDescribeContext         wxT("DESCRIBECONTEXT")
00086 #define AxIdentifierDescribeItem            wxT("DESCRIBEITEM")
00087 #define AxIdentifierStopSpeech              wxT("STOPSPEECH")
00088 #define AxIdentifierPauseResumeSpeech       wxT("PAUSERESUMESPEECH")
00089 #define AxIdentifierSkipForward             wxT("SKIPFORWARD")
00090 #define AxIdentifierSkipBack                wxT("SKIPBACK")
00091 
00092 #define AxIdentifierContextHelp             wxT("CONTEXTHELP")
00093 
00095 #define AXID(id) AxGetId(wxT(id))
00096 
00097 int AxGetId(const wxChar* id);
00098 
00135 class AxMenuItem: public wxEvtHandler
00136 {
00137     DECLARE_DYNAMIC_CLASS( AxMenuItem )
00138 
00139 public:
00140 // Constructors
00141 
00142     AxMenuItem(const AxMenuItem& item) { Init(); Copy(item); }
00143     AxMenuItem() { Init(); }
00144 
00147     AxMenuItem(const wxString& label, const wxString& descr,
00148                const wxString& id = wxEmptyString, AxActivator* activator = NULL)
00149     { Init(); m_label = label; m_description = descr; m_activator = activator; m_id = id; }
00150     ~AxMenuItem();
00151 
00152 // Operations
00153 
00155     void Init();
00156 
00157     void Copy(const AxMenuItem& item);
00158     void operator=(const AxMenuItem& item) { Copy(item); }
00159     bool operator==(const AxMenuItem& item) const ;
00160 
00162     virtual AxMenuItem* Clone() const { return new AxMenuItem(*this); }
00163 
00165     void SetSubMenu(AxMenu* menu);
00166 
00168     AxMenu* GetSubMenu() const { return m_subMenu; }
00169 
00171     void SetActivator(AxActivator* activator);
00172 
00174     AxActivator* GetActivator() const { return m_activator; }
00175 
00177     void SetValidator(AxValidator* validator);
00178 
00180     AxValidator* GetValidator() const { return m_validator; }
00181 
00184     void SetData(AxMenuItemData* data) { m_data = data; }
00185 
00188     AxMenuItemData* GetData() const { return m_data; }
00189 
00193     void SetId(const wxString& id) { m_id = id; }
00194 
00196     const wxString& GetId() const { return m_id; }
00197 
00203 
00204     void SetStyle(int style) { m_style = style; }
00205 
00207     int GetStyle() const { return m_style; }
00208 
00211     void Enable(bool enable = true) { m_enabled = enable; }
00212 
00214     bool IsEnabled() const { return m_enabled; }
00215 
00218     void SetDescription(const wxString& description) { m_description = description; }
00219 
00221     const wxString& GetDescription() const { return m_description; }
00222 
00224     void SetLabel(const wxString& label) { m_label = label; }
00225 
00227     const wxString& GetLabel() const { return m_label; }
00228 
00230     void SetParent(AxMenu* menu) { m_parent = menu; }
00231 
00233     AxMenu* GetParent() const { return m_parent; }
00234 
00238 
00239     void SetDynamic(bool dynamic = true) { m_dynamic = dynamic; }
00240 
00242     bool IsDynamic() const { return m_dynamic; }
00243 
00245     bool IsStatic() const { return !IsDynamic(); }
00246 
00248     int GetPosition() const;
00249 
00251     virtual bool ProcessEvent(wxEvent& event);
00252 
00254     virtual bool TransferDataToMenu(bool recurse = false);
00255 
00257     virtual bool TransferDataFromMenu(bool recurse = false);
00258 
00261     void SetLabelSpec(const wxString& spec);
00262 
00264     wxString GetLabelSpec() const;
00265 
00268     void SetDescriptionSpec(const wxString& spec);
00269 
00271     wxString GetDescriptionSpec() const;
00272 
00278     void SetKind(const wxString& kind) { m_kind = kind; }
00279     
00281     const wxString& GetKind() const { return m_kind; }
00282 
00283 protected:
00284 
00285     AxMenu*         m_subMenu;
00286     AxMenuItemData* m_data;
00287     wxString        m_label;
00288     wxString        m_kind;
00289     wxString        m_id;
00290     wxString        m_description;
00291     AxMenu*         m_parent;
00292     AxActivator*    m_activator;
00293     AxValidator*    m_validator;
00294     int             m_style;
00295     bool            m_enabled;
00296     bool            m_dynamic;
00297 };
00298 
00299 WX_DEFINE_ARRAY_PTR(AxMenuItem*, AxMenuItemArray);
00300 
00310 class AxGoUpMenuItem: public AxMenuItem
00311 {
00312     DECLARE_DYNAMIC_CLASS( AxGoUpMenuItem )
00313 
00314 public:
00315 // Constructors
00316 
00317     AxGoUpMenuItem(const AxGoUpMenuItem& item) { Copy(item); }
00318     AxGoUpMenuItem();
00319 };
00320 
00330 class AxMenu: public wxEvtHandler
00331 {
00332     DECLARE_DYNAMIC_CLASS( AxMenu )
00333 
00334 public:
00335 // Constructors
00336 
00337     AxMenu(const AxMenu& menu) { Init(); Copy(menu); }
00338     AxMenu(const wxString& label = wxEmptyString, const wxString& descr = wxEmptyString)
00339     { Init(); m_label = label; m_description = descr; }
00340     ~AxMenu();
00341 
00342 // Operations
00343 
00345     void Init();
00346 
00348     AxMenuItemArray& GetItems() { return m_items; }
00349 
00351     size_t GetCount() const { return m_items.GetCount(); }
00352 
00354     AxMenuItem* GetItem(size_t i) const { return m_items.Item(i); }
00355 
00357     void Copy(const AxMenu& menu);
00358     void operator=(const AxMenu& menu) { Copy(menu); }
00359     bool operator==(const AxMenu& menu) const ;
00360 
00362     void SetId(const wxString& id) { m_id = id; }
00363 
00365     const wxString& GetId() const { return m_id; }
00366 
00368     void SetDescription(const wxString& description) { m_description = description; }
00369 
00371     const wxString& GetDescription() const { return m_description; }
00372 
00374     void SetLabel(const wxString& label) { m_label = label; }
00375 
00377     const wxString& GetLabel() const { return m_label; }
00378 
00380     void SetParent(AxMenuItem* item) { m_parent = item; }
00381 
00383     AxMenuItem* GetParent() const { return m_parent; }
00384 
00386     void AddItem(AxMenuItem* item);
00387 
00389     void RemoveChild(AxMenuItem* item);
00390 
00392     void DeleteChild(AxMenuItem* item);
00393 
00395     void Unlink();
00396 
00398     void ClearChildren();
00399 
00401     AxMenuItem* FindItemById(const wxString& id) const;
00402 
00404     AxMenuItem* FindItemByLabel(const wxString& label) const;
00405 
00407     int GetCurrentSelection() const { return m_currentSelection; }
00408 
00410     void SetCurrentSelection(int sel) { m_currentSelection = sel; }
00411 
00413     AxMenuItem* GetCurrentItem() const;
00414 
00416     bool IsModal() const { return m_isModal; }
00417 
00419     void SetModal(bool isModal) { m_isModal = isModal; }
00420 
00422     static void DoDelayedMenuDeletion();
00423 
00425     static void ScheduleMenuForDeletion(AxMenu* menu);
00426 
00428     virtual bool TransferDataToMenu(bool recurse = false);
00429 
00431     virtual bool TransferDataFromMenu(bool recurse = false);
00432 
00433 protected:
00434 
00435     AxMenuItemArray m_items;
00436 
00437     wxString        m_label;
00438     wxString        m_id;
00439     wxString        m_description;
00440     AxMenuItem*     m_parent;
00441     int             m_currentSelection;
00442     bool            m_isModal;
00443 
00444     static AxMenuArray  sm_menusPendingDeletion;
00445 };
00446 
00457 class AxMenuItemData: public wxObject
00458 {
00459     DECLARE_CLASS( AxMenuItemData )
00460 
00461 public:
00462 // Constructors
00463 
00464     AxMenuItemData() { Init(); }
00465     ~AxMenuItemData() {}
00466 
00467 // Operations
00468 
00470     void Init() {}
00471 
00472     virtual AxMenuItemData* Clone() const = 0;
00473 
00474 protected:
00475 };
00476 
00491 class AxMenuController: public wxEvtHandler
00492 {
00493     DECLARE_CLASS( AxMenuController )
00494 
00495 public:
00496 // Constructors
00497 
00498     AxMenuController() { Init(); }
00499     ~AxMenuController();
00500 
00501 // Operations
00502 
00503     void Init();
00504 
00506     void SetViewManager(AxViewManager* manager) { m_viewManager = manager; }
00507     AxViewManager* GetViewManager() const { return m_viewManager; }
00508 
00510     AxMenu* GetMenu() const { return m_menu; }
00511 
00513     void SetMenu(AxMenu* menu);
00514 
00516     AxMenu* GetCurrentMenu() const { return m_currentMenu; }
00517 
00519     void SetCurrentMenu(AxMenu* menu) { m_currentMenu = menu; }
00520 
00522     virtual bool ShowInitialMenu(AxMenu* menu);
00523 
00525     virtual bool Activate(AxMenuItem* item);
00526     virtual bool Select(AxMenuItem* item);
00527     virtual bool Describe(AxMenuItem* item, int describeAtVerbosity = 5);
00528     virtual bool DescribeCurrentContext(int describeAtVerbosity = 3);
00529     virtual bool DescribeCurrentItem(int describeAtVerbosity = 5);
00530     virtual bool GoUp();
00531     virtual bool GoHome();
00532 
00536     virtual bool ShowMenu(AxMenu* menu, AxMenuItem* parentItem = NULL, AxMenu* childMenu = NULL,
00537         AxNavigationHint hint = AxNavigationHintNone);
00538 
00540     virtual bool UpdateUI(AxMenu* menu);
00541 
00543     virtual bool CanGoUp() const;
00544 
00546     virtual bool CanGoHome() const;
00547 
00549     virtual bool RefreshMenu(AxMenu* menu, AxNavigationHint hint) = 0;
00550 
00552     virtual bool SetMenuSelection(AxMenuItem* menuItem) = 0;
00553 
00555     virtual bool UpdateMenuItem(AxMenuItem* item) = 0;
00556 
00558     virtual AxMenuItem* GetMenuSelection() const = 0;
00559 
00561     virtual bool BeginModal() = 0;
00562 
00564     virtual bool EndModal() = 0;
00565 
00567     virtual bool SetTitle(const wxString& title) = 0;
00568 
00570     virtual bool SetMenuFocus() = 0;
00571 
00574     virtual bool OnChangeMenuPre(AxMenu* currentMenu, AxMenu* newMenu);
00575 
00578     virtual bool OnChangeMenuPost(AxMenu* newMenu);
00579 
00581     virtual bool OnBeforeDisplay(AxMenu* newMenu);
00582 
00584     virtual bool UpdateAppearance(int hints) = 0;
00585 
00587     bool EmitSpeech(AxSpeechEvent& event) { return DoEmitSpeech(event); }
00588 
00590     bool EmitSpeech(const wxString& speechEventType, const wxString& text = wxEmptyString,
00591         AxNavigationHint hint = AxNavigationHintNone, int flags = 0);
00592 
00594     bool EmitSpeech(const wxString& speechEventType, AxNavigationHint hint, int flags = 0);
00595 
00597     virtual bool DoEmitSpeech(AxSpeechEvent& event);
00598 
00600     virtual bool IdleProcessing();
00601 
00602 protected:
00603     AxMenu*             m_menu;
00604     AxMenu*             m_currentMenu;
00605     AxViewManager*      m_viewManager;
00606 };
00607 
00608 #endif
00609     // _AX_MENU_H_

Generated on Wed May 6 19:20:18 2009 for AxTk by  doxygen 1.5.1