imacroscript.h

Go to the documentation of this file.
00001 /*  
00002  *      imacroscript.h - Public interface to Macro script manager for the MAX CUI
00003  *
00004  *  Macro scripts (or macros) are scripts that live in buttons and menus in the new 
00005  *  customizable UI.  The macro script manager keeps a directory of all known macros 
00006  *  and provides an API for running and editing macros and for accessing and 
00007  *  updating the directory.
00008  *
00009  *  The directory is used by the CUI to provide a list of available macros in the 
00010  *  toolbar/menu/shelf editor.  The API also provides a way for the CUI
00011  *  to open a macro editor to allow on-the-fly creation of macro scripts. 
00012  *
00013  *  Macros are normally entered into the directory by the MAXScript compiler as a
00014  *  side-effect of compiling a macro () definition.  Anyone using MAXScript can at
00015  *  any time eval a macro definition and thereby add CUI macro scripts.
00016  *  Consequently, macros can be stored in any script file and be loaded just by
00017  *  executing the file.  The macro definition syntax permits any number of macros per
00018  *  file.  
00019  *
00020  *  Most macros will be stored in files in a special CUI macro or config
00021  *  directory so that a user can take all his custom UI stuff with him by copying
00022  *  directories.  (this directory supports recursive scanning of sub-dirs,
00023  *  so users can organize their macros)
00024  *  On-the-fly macro creation in the CUI editor or by text drag-and-
00025  *  drop onto the shelf or by evaling a definition in the listener will generate 
00026  *  a file in this directory to provide permanent storage.
00027  *
00028  *          Copyright (c) Autodesk, Inc, 1998.  John Wainwright.
00029  *
00030  */
00031 
00032 #pragma once
00033 
00034 #include "iFnPub.h"
00035 #include "actiontableTypedefs.h"
00036 #include "maxscript/ScripterExport.h"
00037 // forward declarations
00038 class Value;
00039 class Parser;
00040 
00041 typedef short MacroID;
00042 /* ----------------  macro directory -------------------------- */
00043 
00062 class MacroEntry : public BaseInterfaceServer
00063 {
00064 public:
00065     // access
00067     virtual MacroID     GetID() = 0;
00069     virtual MSTR&       GetName() = 0;
00071     virtual MSTR&       GetCategory() = 0;
00075     virtual MSTR&       GetInternalCategory() = 0;
00077     virtual MSTR&       GetFileName() = 0;
00079 
00082     virtual long        GetOffset() = 0;
00084 
00095     virtual Value*      GetCode() = 0;
00097     virtual MSTR&       GetToolTip() = 0;
00099     virtual MSTR&       GetButtonText() = 0;
00101     virtual MSTR&       GetButtonIconFile() = 0;
00103     virtual int         GetButtonIconIndex() = 0;
00105 
00117     virtual short       GetFlags(short mask) = 0;
00118 
00119     // execution
00121 
00128     virtual Value*      Execute() = 0;
00129 
00130     // R4 extension to support body structured into handlers
00132 
00145     virtual Value*      CallHandler(Value* handler_or_name, Value** arg_list, int count, BOOL hold = TRUE)=0;
00147 
00156     virtual FPStatus    CallHandler(const MCHAR* handler_name, FPParams* params, FPValue& result, BOOL hold = TRUE)=0;
00157 
00159     virtual Value*      GetHandler(Value* handler_name)=0;
00160 
00162     virtual BOOL        HasHandler(const MCHAR* handler_name)=0;
00163 
00165 
00170     virtual BOOL        Compile(Parser* parser = NULL) = 0;
00171 
00173     virtual void        MarkAsUsed() = 0;
00174 
00176 
00182     ScripterExport static void          DisableCompiles();
00183 
00185 
00191     ScripterExport static void          EnableCompiles();
00192 
00194 
00200     ScripterExport static void          CompileUsed();
00201 
00203     virtual void        Reset() = 0;
00204 
00205     // cleanup
00206     virtual void        DeleteThis() = 0;
00207 
00209     virtual MaxIcon*    GetIcon()=0;
00210 };
00211 
00212 #define ME_DROPPED_SCRIPT   0x0001      // macro made from some drag-and-dropped text
00213 #define ME_SILENT_ERRORS    0x0002      // macro won't report any runtime errors
00214 #define ME_HAS_EXECUTE      0x0004      // has execute handler
00215 #define ME_TEMPORARY        0x0008      // temporary dropScript
00216 #define ME_NO_AUTO_UNDO     0x0010      // execution of the macroscript is not automatically wrapped in a thehold begin/accept
00217 #define ME_NEEDS_COMPILE    0x0020      // macro should be compiled when maxscript starts up
00218 
00219 #define BAD_MACRO_ID        -1          // illegal macroID 
00220 
00251 class MacroDir : public InterfaceServer
00252 {
00253 public:
00254 
00255     // access by ID or category & name strings
00261     virtual MacroEntry* GetMacro(MacroID mid) = 0;
00269     virtual MacroEntry* FindMacro(const MCHAR* category, const MCHAR* name) = 0;
00275     virtual BOOL        ValidID(MacroID mid) = 0;
00276 
00277     // iteration 
00280     virtual int         Count() = 0;
00287     virtual MacroEntry* GetMacro(int index) = 0;
00288 
00289     // macro entry management
00290 
00291 // LAM - 10/15/01 - when SDK can change, remove the following and uncomment the versions where internalCategory
00292 // is passed in. Internally, only the verions using internalCategory are used.
00311     virtual MacroEntry* AddMacro(const MCHAR* category, const MCHAR* internalCategory, const MCHAR* name, 
00312                                  const MCHAR* tooltip, const MCHAR* buttonText,
00313                                  const MCHAR* sourceFile, int sourceOffset) = 0;
00335     virtual MacroEntry* AddMacro(const MCHAR* category, const MCHAR* internalCategory, const MCHAR* name, 
00336                                  const MCHAR* tooltip, const MCHAR* buttonText,
00337                                  const MCHAR* sourceText) = 0;
00338 
00352     virtual BOOL        SetMacro(MacroID mid, const MCHAR* tooltip, const MCHAR* btnText, const MCHAR* sourceFile, int sourceOffset) = 0;
00358     virtual MCHAR*      MakeNameValid(MCHAR* s) = 0;
00364     virtual MCHAR*      MakeCategoryValid(MCHAR* s) = 0;
00365     
00366     // editing
00372     virtual BOOL        EditMacro(MacroID mid) = 0;
00373     
00374     // execution
00384     virtual Value*      Execute(MacroID mid) = 0;
00385     // R4 extension to support body structured into handlers
00386     virtual Value*      CallHandler(MacroID mid, Value* handler_or_name, Value** arg_list, int count, BOOL hold = TRUE)=0;
00387     virtual FPStatus    CallHandler(MacroID mid, const MCHAR* handler_name, FPParams* params, FPValue& result, BOOL hold = TRUE)=0;
00388     virtual Value*      GetHandler(MacroID mid, Value* handler_name)=0;
00389 
00390     // macro-script file directory scanning & loading
00401     virtual void        LoadMacroScripts(const MCHAR* path_name = NULL, BOOL recurse = TRUE) = 0;
00402     virtual MacroEntry* LoadMacroScript(const MCHAR* file_name) = 0;
00403 
00404     // set & get default path for storing/searching macro script files
00410     virtual void        SetMacroScriptPath(const MCHAR* path_name) = 0;
00413     virtual const MCHAR*        GetMacroScriptPath() = 0;
00414 };
00415 
00416 #if defined(BLD_CORE)
00417 
00420     extern MacroDir& GetMacroScriptDir();
00421 #else
00422 
00425     extern ScripterExport MacroDir& GetMacroScriptDir();
00430     extern ScripterExport void InitMacroScriptDir();
00431 #endif
00432 
00433 // ActionTableIds
00434 const ActionTableId   kActionMacroScripts = 647394;
00435 const ActionContextId kActionMacroScriptsContext = 647394;
00436