menuutils.h

Go to the documentation of this file.
00001 
00002 // Name:        keybinder.h
00003 // Purpose:     Classes for binding keypresses to commands.
00004 // Author:      Francesco Montorsi
00005 // Created:     2004/02/19
00006 // RCS-ID:      $Id: menuutils.h 443 2007-03-01 19:15:57Z frm $
00007 // Copyright:   (c) Aleksandras Gluchovas and (c) Francesco Montorsi
00008 // Licence:     wxWidgets licence
00010 
00011 #ifndef __WX_MENUUTILS_H__
00012 #define __WX_MENUUTILS_H__
00013 
00014 
00015 // includes
00016 #include "wx/keybinderdef.h"
00017 #include "wx/panel.h"
00018 #include "wx/dialog.h"
00019 #include "wx/listbox.h"
00020 #include "wx/treectrl.h"
00021 #include "wx/keybinder.h"
00022 
00023 
00026 int WXDLLIMPEXP_KEYBINDER wxFindMenuItem(wxMenuBar *, const wxString &strMenuItemName);
00027 
00029 #define wxMENUCMD_TYPE                                0x1234
00030 
00031 
00034 class WXDLLIMPEXP_KEYBINDER wxMenuCmd : public wxCmd
00035 {
00037       wxMenuItem *m_pItem;
00038 
00039 public:           // static
00040 
00042       static wxMenuBar *m_pMenuBar;
00043 
00046       static void SetMenuBar(wxMenuBar *p)
00047             { m_pMenuBar = p; }
00048 
00051       static void Register(wxMenuBar *p)
00052             { wxCmd::AddCmdType(wxMENUCMD_TYPE, wxMenuCmd::CreateNew); 
00053                   wxMenuCmd::SetMenuBar(p); }
00054 
00057       static wxCmd *CreateNew(int id);
00058 
00059 public:
00060 
00061       wxMenuCmd(wxMenuItem *p, 
00062             const wxKeyBind &first, 
00063             const wxString &name = wxEmptyString,
00064             const wxString &desc = wxEmptyString) :
00065              wxCmd(first, p->GetId(), name, desc), m_pItem(p) {}
00066 
00067       wxMenuCmd(wxMenuItem *p = NULL, 
00068             const wxString &name = wxEmptyString,
00069             const wxString &desc = wxEmptyString) {
00070             m_pItem = p;
00071             m_strDescription = desc;
00072             m_strName = name;
00073 
00074             if (m_pItem)
00075                   m_nId = m_pItem->GetId();
00076       }
00077 
00078       virtual ~wxMenuCmd() {}
00079 
00080 public:
00081 
00082       virtual void DeepCopy(const wxCmd *p) {
00083             wxMenuCmd *m = (wxMenuCmd *)p;
00084             m_pItem = m->m_pItem;
00085             wxCmd::DeepCopy(p);
00086       }
00087 
00088       virtual wxCmd *Clone() const {
00089             wxCmd *ret = new wxMenuCmd();
00090             ret->DeepCopy(this);
00091             return ret;
00092       }
00093 
00094       virtual int GetType() const {
00095             return wxMENUCMD_TYPE;
00096       }
00097 
00098 
00099 
00100 protected:
00101 
00104       void Exec(wxObject *origin, wxEvtHandler *client);
00105 
00112       void Update();
00113 };
00114 
00115 
00116 
00120 class WXDLLIMPEXP_KEYBINDER wxMenuWalker
00121 {
00122 protected:
00123 
00125       int m_nLevel;
00126 
00127 public:
00128       wxMenuWalker() { m_nLevel=0; }
00129       virtual ~wxMenuWalker() {}
00130 
00131 protected:        // the core functions
00132 
00137       void Walk(wxMenuBar *p, void *data);
00138       
00139       void WalkMenu(wxMenuBar *p, wxMenu *, void *);
00140       void WalkMenuItem(wxMenuBar *p, wxMenuItem *, void *);
00141 
00142 
00155       virtual void *OnMenuWalk(wxMenuBar *p, wxMenu *m, void *data) = 0;
00156 
00163       virtual void *OnMenuItemWalk(wxMenuBar *p, wxMenuItem *m, void *data) = 0;
00164 
00167       virtual void OnMenuExit(wxMenuBar *, wxMenu *, void *) {}
00168 
00174       virtual void DeleteData(void *data) = 0;
00175 };
00176 
00177 
00178 
00188 class WXDLLIMPEXP_KEYBINDER wxExTreeItemData : public wxTreeItemData
00189 {
00190 protected:
00191       int m_nMenuId;
00192 
00193 public:
00194       wxExTreeItemData(int id = wxID_INVALID) : m_nMenuId(id) {}
00195       virtual ~wxExTreeItemData() {}
00196 
00197       void SetMenuItemId(int n) {
00198             m_nMenuId = n;
00199       }
00200 
00201       int GetMenuItemId() {
00202             return m_nMenuId;
00203       }
00204 };
00205 
00206 
00215 class WXDLLIMPEXP_KEYBINDER wxMenuTreeWalker : public wxMenuWalker
00216 {
00217       wxTreeCtrl *m_pTreeCtrl;
00218       wxTreeItemId m_root;
00219 
00220 public:
00221       wxMenuTreeWalker() {}
00222       virtual ~wxMenuTreeWalker() {}
00223 
00224 
00227       void FillTreeBranch(wxMenuBar *p, wxTreeCtrl *ctrl, wxTreeItemId branch);
00228 
00231       void FillTreeCtrl(wxMenuBar *p, wxTreeCtrl *ctrl, 
00232             const wxString &rootname = wxT("root")) {
00233             ctrl->DeleteAllItems();
00234             FillTreeBranch(p, ctrl, ctrl->AddRoot(rootname));
00235       }
00236 
00237 protected:
00238 
00239       void *OnMenuWalk(wxMenuBar *p, wxMenu *, void *);
00240       void *OnMenuItemWalk(wxMenuBar *p, wxMenuItem *, void *);
00241       void DeleteData(void *data);
00242 };
00243 
00244 
00245 
00246 
00247 
00252 class WXDLLIMPEXP_KEYBINDER wxExComboItemData : public wxClientData
00253 {
00254 protected:
00255       wxArrayString m_arrStr;
00256       wxArrayLong m_arrID;
00257 
00258 public:
00259       wxExComboItemData() {}
00260       virtual ~wxExComboItemData() {}
00261       
00262       int GetID(int n) const
00263             { return m_arrID[n]; }
00264       wxArrayString &GetCmdNameArr()
00265             { return m_arrStr; }
00266             
00267       void Append(const wxString &name, int id)
00268             { m_arrStr.Add(name); m_arrID.Add(id); }
00269       void SetID(int n, int id)
00270             { m_arrID[n] = id; }
00271 };
00272 
00273 
00281 class WXDLLIMPEXP_KEYBINDER wxMenuComboListWalker : public wxMenuWalker
00282 {
00283       wxComboBox *m_pCategories;
00284       wxString m_strAcc;
00285 
00286 public:
00287       wxMenuComboListWalker() {}
00288       virtual ~wxMenuComboListWalker() {}
00289       
00291       void FillComboListCtrl(wxMenuBar *p, wxComboBox *combo);
00292 
00293 protected:
00294 
00295       void *OnMenuWalk(wxMenuBar *p, wxMenu *, void *);
00296       void *OnMenuItemWalk(wxMenuBar *p, wxMenuItem *, void *);
00297       void OnMenuExit(wxMenuBar *p, wxMenu *m, void *data);
00298       void DeleteData(void *data);
00299 };
00300 
00301 
00302 
00308 class WXDLLIMPEXP_KEYBINDER wxMenuShortcutWalker : public wxMenuWalker
00309 {
00310       wxCmdArray *m_pArr;
00311 
00312 public:
00313       wxMenuShortcutWalker() {}
00314       virtual ~wxMenuShortcutWalker() {}
00315 
00316 
00317       // Starts the process.
00318       void ImportMenuBarCmd(wxMenuBar *p, wxCmdArray *arr) {
00319             m_pArr = arr;
00320             Walk(p, NULL);
00321       }
00322 
00323 
00324 protected:
00325 
00326       void *OnMenuWalk(wxMenuBar *, wxMenu *, void *) { return NULL; }
00327       void *OnMenuItemWalk(wxMenuBar *p, wxMenuItem *, void *);
00328       void DeleteData(void *data);
00329 };
00330 
00331 
00332 #endif            // __WX_MENUUTILS_H__
00333 
00334 

Generated on Sat Mar 10 18:30:36 2007 for Keybinder by  doxygen 1.4.7