actiontable.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        ActionTable.h
00012 // DESCRIPTION: Action Table definitions
00013 // AUTHOR:      Scott Morrison
00014 // HISTORY:     Created 8 February, 2000, Based on KbdAction.h.
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "maxheap.h"
00020 #include "stack.h"
00021 #include "iFnPub.h"
00022 #include "strbasic.h"
00023 #include "actiontableTypedefs.h"
00024 #include "Noncopyable.h"
00025 
00026 // forward declarations
00027 class MaxIcon;
00028 class MacroEntry;
00029 class IPoint2;
00030 
00034 const ActionTableId kActionMainUI           = 0;
00035 const ActionTableId kActionTrackView        = 1;
00036 const ActionTableId kActionMaterialEditor   = 2;
00037 const ActionTableId kActionVideoPost        = 3;
00038 const ActionTableId kActionSchematicView    = 5;
00039 const ActionTableId kActionCommonIReshade   = 6;
00040 const ActionTableId kActionScanlineIReshade = 7;
00042 
00043 class ActionTable;
00044 class IMenu;
00045 
00048 
00049 const ActionContextId kActionMainUIContext         = 0;
00050 const ActionContextId kActionTrackViewContext      = 1;
00051 const ActionContextId kActionMaterialEditorContext = 2;
00052 const ActionContextId kActionVideoPostContext      = 3;
00053 const ActionContextId kActionSchematicViewContext  = 5;
00054 const ActionContextId kActionIReshadeContext       = 6;
00056 
00064 struct ActionDescription {
00065 
00069     int mCmdID;
00070 
00072     int mDescriptionResourceID;
00073 
00076         int mShortNameResourceID;
00077 
00080         int mCategoryResourceID;
00081 
00082 };
00083 
00084 
00086 
00087 #define AO_DEFAULT 0x0001 //< Default option command to execute
00088 #define AO_CLOSEDIALOG 0x0002 //< Execute closeDialog option
00089 
00090 
00091 #define ACTION_OPTION_INTERFACE Interface_ID(0x3c0276f5, 0x190964f5) 
00092 #define ACTION_OPTION_INTERFACE_OPT2 Interface_ID(0x0011dcdc, 0x0012dcdc)
00093 
00096 class IActionOptions : public BaseInterface
00097 {
00098 public:
00099     virtual BOOL ExecuteOptions(DWORD options = AO_DEFAULT) = 0;
00100 
00101     // BaseInterface methods
00102     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00103     CoreExport virtual Interface_ID GetID();
00104 };
00105 
00107 #define IID_ACTION_ITEM Interface_ID(0x6fbd5f3c, 0x7c5a32db)
00108 
00120 class ActionItem : public FPMixinInterface
00121 {
00122 public:
00124     CoreExport ActionItem();
00126     CoreExport virtual ~ActionItem();
00127 
00131     virtual int    GetId() = 0;
00132 
00138     virtual BOOL ExecuteAction() = 0;
00139 
00141     CoreExport virtual void EmitMacro();
00142 
00144     CoreExport BOOL Execute(); 
00145 
00149     virtual void GetButtonText(MSTR& buttonText) = 0;
00150 
00157     virtual void GetMenuText(MSTR& menuText) = 0;
00158 
00163     virtual void GetDescriptionText(MSTR& descText) = 0;
00164 
00169     virtual void GetCategoryText(MSTR& catText) = 0;
00170 
00180     virtual BOOL IsChecked() = 0;
00181 
00188     virtual BOOL IsItemVisible() = 0;
00189 
00197     virtual BOOL IsEnabled() = 0;
00198         
00204     virtual MaxIcon* GetIcon() = 0;
00205 
00208     virtual void DeleteThis() = 0;
00209 
00216     CoreExport virtual ActionTable* GetTable();
00217 
00225     CoreExport virtual void SetTable(ActionTable* pTable);
00226 
00231     CoreExport MCHAR* GetShortcutString();
00232 
00240     CoreExport virtual MacroEntry* GetMacroScript();
00241 
00249     CoreExport virtual BOOL IsDynamicMenu();
00250 
00255     CoreExport virtual void SetIsDynamicMenu();
00256 
00270     CoreExport virtual IMenu* GetDynamicMenu(HWND hwnd, IPoint2& m);
00271 
00273     CoreExport virtual BOOL IsDynamicAction();
00274 
00275     // FPMixinInterface methods
00276     CoreExport virtual FPInterfaceDesc* GetDescByID(Interface_ID id);
00277     CoreExport virtual FPInterfaceDesc* GetDesc();
00278 
00279     // BaseInterface methods
00280     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00281     CoreExport virtual Interface_ID GetID();
00282 
00284     enum ActionItemFps
00285     {
00286         kGetId,
00287         kIsVisible,
00288         kIsEnabled,
00289         kIsChecked,
00290         kGetDescription,
00291         kGetCategory,
00292         kGetButtonText,
00293         kGetMenuText,
00294     };
00295 
00296 protected:
00297     #pragma warning(push)
00298     #pragma warning(disable:4100)
00299     BEGIN_FUNCTION_MAP
00300         RO_PROP_FN(kGetId, GetId, TYPE_DWORD);
00301         RO_PROP_FN(kIsVisible, IsItemVisible, TYPE_BOOL);
00302         RO_PROP_FN(kIsEnabled, IsEnabled, TYPE_BOOL);
00303         RO_PROP_FN(kIsChecked, IsChecked, TYPE_BOOL);
00304         VFN_1(kGetDescription, GetDescriptionText, TYPE_TSTR_BR);
00305         VFN_1(kGetCategory, GetCategoryText, TYPE_TSTR_BR);
00306         VFN_1(kGetButtonText, GetButtonText, TYPE_TSTR_BR);
00307         VFN_1(kGetMenuText, GetMenuText, TYPE_TSTR_BR);
00308     END_FUNCTION_MAP
00309     #pragma warning(pop)
00310 
00313     ActionTable* mpTable;
00314 };
00315 
00317 #define ACTIONITEM_STANDIN_INTERFACE Interface_ID(0x108e1314, 0x5aff3138)
00318 
00320 class IActionItemStandin : public BaseInterface
00321 {
00322 public:
00323     virtual void          SetPersistentActionId(MSTR idString) = 0;
00324     virtual MSTR&         GetPersistentActionId() = 0;
00325     virtual void          SetActionTableId( ActionTableId id ) = 0;
00326     virtual ActionTableId GetActionTableId() = 0;
00327     virtual MSTR&         GetPrefixString() = 0;
00328 
00329     // BaseInterface methods
00330     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00331     CoreExport virtual Interface_ID GetID();
00332 };
00333 
00335 inline IActionItemStandin* GetIActionItemStandin(ActionItem* a) { return (IActionItemStandin*)a->GetInterface(ACTIONITEM_STANDIN_INTERFACE); }
00336 
00338 class ActionItemStandin: public ActionItem, public IActionItemStandin
00339 {
00340 public:
00341     CoreExport ActionItemStandin(int cmdId );
00342     CoreExport virtual ~ActionItemStandin();
00343 
00344     CoreExport virtual int  GetId() { return mCmdId; }
00345     CoreExport virtual void SetId(int id) { mCmdId = id; }
00346 
00347     CoreExport virtual MCHAR*  GetDescription() { return mName.data();}
00348     CoreExport virtual void    SetDescription(MCHAR* pDesc) { mName = pDesc; }
00349 
00350     CoreExport virtual MCHAR*  GetShortName() { return mName.data();}
00351     CoreExport virtual void    SetShortName(MCHAR* pShortName) { mName = pShortName; }
00352 
00353     CoreExport virtual MCHAR*  GetCategory() { return mName.data();}
00354     CoreExport virtual void    SetCategory(MCHAR* pCategory) { mName = pCategory; }
00355 
00356     CoreExport virtual MaxIcon* GetIcon() { return NULL; };
00357 
00358     CoreExport virtual BOOL ExecuteAction() { return FALSE; };
00359 
00360     CoreExport virtual void GetButtonText(MSTR& buttonText) { buttonText = mName; };
00361     CoreExport virtual void GetMenuText(MSTR& menuText) { menuText = mName; };
00362     CoreExport virtual void GetDescriptionText(MSTR& descText) { descText = mName; };
00363     CoreExport virtual void GetCategoryText(MSTR& catText) { catText = mName; };
00364 
00365     CoreExport virtual BOOL IsChecked() { return FALSE; };
00366     CoreExport virtual BOOL IsItemVisible() { return TRUE; };
00367     CoreExport virtual BOOL IsEnabled() { return FALSE; };
00368 
00369     CoreExport virtual BOOL IsDynamicMenu() { return FALSE; }
00370     CoreExport virtual void SetIsDynamicMenu() { };
00371     #pragma warning(push)
00372     #pragma warning(disable:4100)
00373     CoreExport virtual IMenu* GetDynamicMenu(HWND hwnd, IPoint2& m) { return NULL; };
00374     #pragma warning(pop)
00375 
00376     CoreExport void DeleteThis();
00377 
00378     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00379 
00380     CoreExport virtual void SetPersistentActionId(MSTR idString);
00381     CoreExport virtual MSTR& GetPersistentActionId() { return mPersistentActionId; };
00382     CoreExport virtual void SetActionTableId( ActionTableId id ) { mId = id; };
00383     CoreExport virtual ActionTableId GetActionTableId() { return mId; };
00384     CoreExport virtual MSTR& GetPrefixString() { return mPrefix; };
00385 
00386 protected:
00387     int   mCmdId;
00388     MSTR  mName;
00389     MSTR  mPersistentActionId;
00390     MSTR  mPrefix;
00391     ActionTableId mId;
00392 };
00393 
00394 class ActionCallback;
00395 
00397 #define IID_ACTION_TABLE Interface_ID(0x27ba191e, 0x4d391886)
00398 
00423 class ActionTable : public FPMixinInterface, public MaxSDK::Util::Noncopyable 
00424 {
00425 public:
00448     CoreExport ActionTable(ActionTableId id,
00449                                                  ActionContextId contextId,
00450                                                  MSTR& name,
00451                                                  HACCEL hDefaults,
00452                                                  int numIds,
00453                                                  ActionDescription* pOps,
00454                                                  HINSTANCE hInst);
00463     CoreExport ActionTable(ActionTableId id,
00464                                                  ActionContextId contextId,
00465                                                  MSTR& name);
00466 
00469     CoreExport virtual ~ActionTable();
00470 
00472 
00473 
00474     CoreExport virtual HACCEL GetHAccel();
00475 
00477     CoreExport virtual void SetHAccel(HACCEL hAccel);
00478 
00481     CoreExport virtual HACCEL GetDefaultHAccel();
00482 
00485     CoreExport virtual void SetDefaultHAccel(HACCEL accel);
00487 
00489     CoreExport virtual MSTR& GetName();
00490 
00492     CoreExport virtual ActionTableId GetId();
00493 
00495     CoreExport virtual ActionContextId GetContextId();
00496 
00499     CoreExport virtual ActionCallback* GetCallback();
00500 
00503     CoreExport virtual void SetCallback(ActionCallback* pCallback);
00504 
00506     CoreExport virtual int Count();
00507 
00510     CoreExport virtual ActionItem* operator[](int i);
00511 
00515     CoreExport virtual ActionItem* GetAction(int cmdId);
00516 
00521     CoreExport virtual ActionItem* GetActionByIndex(int index); 
00522 
00525     CoreExport virtual void AppendOperation(ActionItem* pAction);
00526     
00531     CoreExport virtual BOOL DeleteOperation(ActionItem* pAction);
00532 
00538     CoreExport virtual void DeleteThis(); 
00539 
00545     CoreExport virtual BOOL GetButtonText(int cmdId, MSTR& buttonText);
00546 
00557     CoreExport virtual BOOL GetMenuText(int cmdId, MSTR& menuText);
00558 
00565     CoreExport virtual BOOL GetDescriptionText(int cmdId, MSTR& descText);
00566 
00574     CoreExport virtual BOOL IsChecked(int cmdId);
00575     
00583     CoreExport virtual BOOL IsItemVisible(int cmdId);
00584 
00592     CoreExport virtual BOOL IsEnabled(int cmdId);
00593 
00599     CoreExport virtual void WritePersistentActionId(int cmdId, MSTR& idString);
00600     
00607     CoreExport virtual int ReadPersistentActionId(MSTR& idString);
00608 
00611     CoreExport virtual MaxIcon* GetIcon(int cmdId);
00612 
00619     CoreExport void BuildActionTable(HACCEL hDefaults,
00620                                                             int numIds,
00621                                                             ActionDescription* pOps,
00622                                                             HINSTANCE hInst);
00623 
00626     CoreExport virtual ActionItem* GetCurrentAssignment(ACCEL accel);
00627     
00632     CoreExport virtual void AssignKey(int cmdId, ACCEL accel);
00633 
00636     CoreExport virtual void RemoveShortcutFromTable(ACCEL accel);
00637 
00638     // From FPMixinInterface
00639     CoreExport FPInterfaceDesc* GetDescByID(Interface_ID id);
00640     CoreExport FPInterfaceDesc* GetDesc();
00641 
00642     // BaseInterface methods
00643     CoreExport virtual BaseInterface* GetInterface(Interface_ID id);
00644     CoreExport virtual Interface_ID GetID();
00645 
00646     // Function publishing
00647     enum ActionTableFps
00648     {
00649         kGetId,
00650         kGetName,
00651         kGetContextId,
00652         kGetContextName,
00653         kNumActionItems,
00654         kGetActionItem,
00655     };
00656 
00657 protected:
00658     #pragma warning(push)
00659     #pragma warning(disable:4100)
00660     BEGIN_FUNCTION_MAP
00661         RO_PROP_FN(kGetId, GetId, TYPE_DWORD);
00662         RO_PROP_FN(kGetName, GetName, TYPE_STRING);
00663         RO_PROP_FN(kGetContextId, GetContextId, TYPE_DWORD);
00664         RO_PROP_FN(kGetContextName, fpGetContextName, TYPE_STRING);
00665         RO_PROP_FN(kNumActionItems, Count, TYPE_INT);
00666         FN_1(kGetActionItem, TYPE_INTERFACE, GetActionByIndex, TYPE_INDEX);
00667     END_FUNCTION_MAP
00668     #pragma warning(pop)
00669 
00671     CoreExport const MCHAR* fpGetContextName() const;
00672 
00673 protected:
00674     // Descriptors of all operations that can have Actions
00675     Tab<ActionItem*>  mOps; 
00676 
00677 private:
00678     // These values are set by the plug-in to describe a action table
00679 
00680     // Unique identifier of table (like a class id)
00681     ActionTableId  mId;
00682 
00683     // An identifier to group tables use the same context.  Tables with the
00684     // same context cannot have overlapping keyboard shortcuts.
00685     ActionContextId mContextId;
00686 
00687     // Name to use in preference dlg drop-down
00688     MSTR mName;
00689 
00690     // The windows accelerator table in use when no keyboard shortcuts saved
00691     HACCEL mhDefaultAccel;
00692     // The windows accelerator table in use
00693     HACCEL mhAccel;
00694 
00695     // The currently active callback
00696     ActionCallback* mpCallback;
00697 };
00698 
00699 
00709 class ActionCallback : public BaseInterfaceServer {
00710 public:
00712     CoreExport ActionCallback();
00713 
00715     CoreExport virtual ~ActionCallback();
00716         
00729     CoreExport virtual BOOL ExecuteAction(int id);
00730 
00744     CoreExport virtual IMenu* GetDynamicMenu(int id, HWND hwnd, IPoint2& m);
00745 
00747     CoreExport ActionTable* GetTable();
00748     
00751     CoreExport void SetTable(ActionTable* pTable);
00752 
00753 private:
00755     ActionTable *mpTable;
00756 };
00757 
00766 class ActionContext: public MaxHeapOperators {
00767 public:
00771     ActionContext(ActionContextId contextId, MCHAR *pName)
00772             { mContextId = contextId; mName = pName; mActive = true; }
00773 
00775     MCHAR* GetName() { return mName.data(); }
00776     
00778     ActionContextId GetContextId() { return mContextId; }
00779 
00784     bool IsActive() { return mActive; }
00785     
00788     void SetActive(bool active) { mActive = active; }
00789         
00790 private:
00791     ActionContextId  mContextId;
00792     MSTR             mName;
00793     bool             mActive;
00794 };
00795 
00798 #define ACTION_MGR_INTERFACE  Interface_ID(0x4bb71a79, 0x4e531e4f)
00799 
00808 class IActionManager : public FPStaticInterface  
00809 {
00810 public:
00820     virtual void RegisterActionTable(ActionTable* pTable) = 0;
00821 
00823     virtual int NumActionTables() = 0;
00824     
00827     virtual ActionTable* GetTable(int i) = 0;
00828 
00843     virtual int ActivateActionTable(ActionCallback* pCallback, ActionTableId id) = 0;
00844     
00855     virtual int DeactivateActionTable(ActionCallback* pCallback, ActionTableId id) = 0;
00856 
00859     virtual ActionTable* FindTable(ActionTableId id) = 0;
00860 
00867     virtual BOOL GetShortcutString(ActionTableId tableId, int commandId, MCHAR* buf) = 0;
00868     
00874     virtual BOOL GetActionDescription(ActionTableId tableId, int commandId, MCHAR* buf) = 0;
00875 
00882     virtual BOOL RegisterActionContext(ActionContextId contextId, MCHAR* pName) = 0;
00883     
00885     virtual int NumActionContexts() = 0;
00886     
00889     virtual ActionContext* GetActionContext(int i) = 0;
00890     
00895     virtual ActionContext* FindContext(ActionContextId contextId) = 0;
00896 
00903     virtual BOOL IsContextActive(ActionContextId contextId) = 0;
00904 
00908     virtual MCHAR* GetShortcutFile() = 0;
00910     virtual MCHAR* GetShortcutDir() = 0;
00912     virtual int IdToIndex(ActionTableId id) = 0;
00914     virtual void SaveAllContextsToINI() = 0;
00916     virtual int MakeActionSetCurrent(MCHAR* pDir, MCHAR* pFile) = 0;
00918     virtual int LoadAccelConfig(LPACCEL *accel, int *cts, ActionTableId tableId = -1, BOOL forceDefault = FALSE) = 0;
00920     virtual int SaveAccelConfig(LPACCEL *accel, int *cts) = 0;
00922     virtual int GetCurrentActionSet(MCHAR *buf) = 0;
00924     virtual BOOL SaveKeyboardFile(MCHAR* pFileName) = 0;
00926     virtual BOOL LoadKeyboardFile(MCHAR* pFileName) = 0;
00928     virtual MCHAR* GetKeyboardFile() = 0;
00930 
00932     enum ActionManagerFps
00933     {
00934         executeAction,
00935 #ifndef NO_CUI  // russom - 02/12/02
00936         saveKeyboardFile,
00937         loadKeyboardFile,
00938         getKeyboardFile,
00939 #endif // NO_CUI
00940         numActionTables,
00941         getActionTable,
00942         getActionContext,
00943         };
00944 };
00945 
00960 class IActionManager10 : public BaseInterface, public MaxSDK::Util::Noncopyable {
00961 
00962 public:
00964     CoreExport static const Interface_ID kActionMgr10InterfaceID;
00965 
00975     virtual bool DispatchMessageToApplication(MSG* message) = 0;
00976 
00978     CoreExport virtual Interface_ID GetID(); 
00979 
00980 protected:
00983     CoreExport IActionManager10();
00986     CoreExport virtual ~IActionManager10();
00987 
00988 };
00989 
00990 
00997 class DynamicMenuCallback: public MaxHeapOperators {
00998 public:
01003         virtual void MenuItemSelected(int itemId) = 0;
01004 };
01005 
01014 class DynamicMenu: public MaxHeapOperators {
01015 public:
01016 
01020         CoreExport DynamicMenu(DynamicMenuCallback* pCallback);
01021 
01027         CoreExport IMenu* GetMenu();
01028 
01030         enum DynamicMenuFlags {
01031                 kDisabled   = 1 << 0, //< Item is disabled (can't be selected)
01032                 kChecked    = 1 << 1, //< Item has a check mark beside it or is pressed 
01033                 kSeparator  = 1 << 2, //< Item is a seperator between the previous menu item and the next one.
01034         };
01035 
01040         CoreExport void AddItem(DWORD flags, UINT itemId, MCHAR* pItemTitle);
01041 
01045         CoreExport void BeginSubMenu(MCHAR* pTitle);
01046 
01049         CoreExport void EndSubMenu();
01050 
01051 private:
01052 
01053         Stack<IMenu*> mMenuStack;
01054         DynamicMenuCallback *mpCallback;
01055 };
01056