home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / controlr.h < prev    next >
C/C++ Source or Header  |  1995-11-08  |  16KB  |  494 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c) 1994   & 1995                      *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. /*
  17.     this class is the class that handles global sheet functions for
  18.     Mesa.  It handles:
  19.  
  20.     Keeping a list of open worksheets
  21.         this is used for sheet linking
  22.         Also used for opening files
  23.  
  24.     Keeps the real time feed table - String / Value
  25.         Can be accessed by open sheets
  26.         Updates sheets that subscribe to given feeds
  27.         Allows multi-threaded changing of the feed table
  28.  
  29.     Keeps the list of AddIn functions
  30.  
  31.     Keeps the list of database queries
  32.         All queries routed through this object
  33.  
  34.     Performs licensing functions
  35.  
  36.     routes messages to delegates
  37.         - sheets opening and closing, etc.
  38.  
  39.     handles error panels
  40.         - opens error panels
  41.  
  42.     There is only one object of this class instantiated for the
  43.     application,  A pointer to the single object is passed to each
  44.     model when the model is instantiated so that the model can access
  45.     the functions of the object.
  46.  
  47.     1-17-94 dpp
  48.  
  49.     94-09-04 added getCharRes()
  50.     94-09-19 dpp added makeBackup()
  51.     94-12-11 dpp added support for a ping function that does not require forking a thread
  52.     95-01-18 dpp added support for OS/2's atom table
  53. */
  54.  
  55. #ifndef _MH_mesa
  56.  
  57. #define _MH_mesa
  58.  
  59. #include "address.h"
  60. #include "color.h"
  61. #include "font.h"
  62. #include "format.h"
  63.  
  64. #include "os2h.h"
  65.  
  66. #include "rect.h"
  67. #include "object.h"
  68.  
  69.  
  70. #if defined(M2Z) || defined(M2NT)
  71. extern HAB TheMesaHAB;
  72. // ifdef M2Z
  73. #endif
  74.  
  75.  
  76. class MException;
  77. class MMesaModel;
  78. class MValue;
  79. class MRange;
  80. class MEditView;
  81. class MView;
  82. class MPing;
  83. class MMutex;
  84. class MAddIn;
  85. class MStack;
  86. class MFunctionAddIn;
  87. class MEditString;
  88. class MCapture;
  89. class MNull;
  90.  
  91. const int MAXPING = 32;
  92. const int MAXCACHEDFONTS = 253;
  93.  
  94.  
  95. #ifdef M2Z
  96. typedef LHANDLE  HATOMTBL;
  97. #endif
  98.  
  99. class MGController : public MObject
  100. {
  101.     public:
  102.     // start a controller and pass the license string, and return the value of the enablement
  103.     //  pass the handle to the application block, if we are in RGB mode
  104.     // 94-09-17 dpp
  105.  
  106.     MGController(const char *,int &,
  107. #if defined(M2Z) || defined(M2NT)
  108.     HAB,
  109. // ifdef M2Z
  110. #endif
  111.     int useRGB);
  112.  
  113.     virtual ~MGController();
  114.  
  115.     // all the methods listed below are thread-safe and may be
  116.     // called from any thread in the application
  117.  
  118.  
  119.     // these methods keep track of the worksheets that are currently open
  120.  
  121.     virtual void setUp();
  122.     virtual void setupAddIns(); // this must be called after the application
  123.                                 // has been started because many addins may need
  124.                                 // application state information (like the menu bar)
  125.     virtual void cleanUp();
  126.  
  127.     // all the methods listed below are thread-safe and may be
  128.     // called from any thread in the application
  129.  
  130.  
  131.     // these methods keep track of the worksheets that are currently open
  132.  
  133.     virtual int addModel(MMesaModel *);
  134.         // adds a model if it is unique and has a unique pathName
  135.         // returns 1 if successful or 0 if unsuccessful
  136.     virtual void removeModel(MMesaModel *);
  137.         // removes the model from the list
  138.  
  139.     // returns true if there is an unsaved model in the list
  140.     virtual int unsavedModel();
  141.  
  142.     virtual void setAllModelsToSaved();
  143.  
  144.  
  145.     // These methods return values for other worksheets
  146.     // they manage value passing for inter-sheet recalculation
  147.  
  148.     // these methods are for the real time feeds
  149.     // they are thread-safe
  150.     // real time feeds are organized by feed service and by item name
  151.     // for example feed service "Reuters" and item "IBM bid"
  152.     virtual void setRealTimeValue(const char *,const char *,double);
  153.     virtual int getRealTimeValue(const char *,const char *,double &);
  154.     // polls the real time value and updates the subscribies
  155.     // every second if the values change
  156.     virtual void waitForData();
  157.  
  158.  
  159.     virtual void recalcNeedFeeds();  // recalculate the sheets that need feeds
  160.  
  161.     // get the error string
  162.     virtual int getMaxErrorNumber();
  163.  
  164.     virtual void displayException(const MException *) {};
  165.     virtual void seriousError(const char *);
  166.     virtual void postMsg(HWND,int,int,int);
  167.     virtual int sendMsg( HWND, int, int, int );
  168.  
  169. #if defined(M2Z) || defined(M2NT)
  170.     virtual void addToDestroyList(HWND) {}; // = 0;
  171. #endif
  172.  
  173.     virtual void ping(int,HWND,int = 0,int = 0);
  174.  
  175.     // every 10 milliseconds, come up for air and ping the application
  176.     virtual int beAlive() {return 1;}; // = 0;
  177.     virtual int getInBeAlive() {return 0;}; // = 0;
  178.  
  179.  
  180.     // send a message to the controller that a long operation is a
  181.     // certain percent complete
  182.     // this is thread-safe
  183.     virtual void percentComplete(int) {};
  184.     virtual void boundedPercentComplete( int, int, int ) {};
  185. #if defined(M2Z) || defined(M2NT)
  186.     virtual HWND getApplicationFrameWindow() {return NULL;}; // = 0;
  187.     virtual HWND getApplicationClientWindow() {return NULL;}; // = 0;
  188. #endif
  189.  
  190.     virtual void setStatusMessage(const char *) {};
  191.  
  192.     virtual int getUseRGB() {return useRGB;};
  193.     virtual int getBufferRedraw() {return 1;};
  194.  
  195. /*
  196.     virtual MPoint getHitPoint() = 0;
  197.     virtual int isEditingFormula() = 0;
  198.     virtual int isEditing() = 0;
  199.     virtual int handleKey(int,int) = 0;
  200.     virtual void updateFormulaView() = 0;
  201.      virtual void setFormulaView( const char * ) {};
  202.     virtual void resizeFormulaView() = 0;
  203.     virtual void removeEdit() = 0;
  204.     virtual MEditView *getEditView() = 0;
  205.     virtual MMesaModel *findModel(const char *,int needsPath = 1);
  206. */
  207.  
  208.     virtual MPoint getHitPoint() {MPoint po; po.set(0,0); return po;}; // = 0;
  209.     virtual int isEditingFormula() {return 0;}; // = 0;
  210.     virtual int isEditing() {return 0;}; // = 0;
  211.     virtual int handleKey(int,int) {return 0;}; // = 0;
  212.     virtual void updateFormulaView() {}; // = 0;
  213.     virtual void updateStatusView() {};
  214.      virtual void setFormulaView( const char * ) {};
  215.     virtual void resizeFormulaView() {}; // = 0;
  216.     virtual void removeEdit() {}; // = 0;
  217.     virtual MEditView *getEditView() {return NULL;};  // = 0;
  218.     virtual MMesaModel *findModelChar(const char *,int needsPath = 1);
  219.     virtual void invokeEdit( MEditString * ) {};
  220.     
  221.     // get info about wether we're in demo mode and what our capabilities are
  222.     virtual int getInDemoMode();
  223.  
  224.     static void setupFuncs();
  225.  
  226.     // get a string from the resource file based on in integer key
  227.     // 94-09-04 dpp
  228.     virtual char *getCharRes(int);
  229.     virtual int loadResString(int,char *);
  230.     virtual void getErrorString(int,char *);
  231.     virtual void getShortErrorString(int,char *);
  232.  
  233.     // get the license string for display
  234.     // 94-09-17 dpp
  235.     virtual const char *getLicense(int);
  236.  
  237.     // should we make a backup file?
  238.     virtual int makeBackup() {return 0;};
  239.  
  240.  
  241.    // controll the keyboard state flags
  242.    virtual void setEndFlag (int on); // set the END flag to on(on=1) or off(on=0)
  243.    virtual int checkKBDState(); //call whenever there is a possibility that the
  244.                         // keyboard state has changed
  245.    // override this method to process when a state has changed
  246.    virtual void KBDStateHasChanged(int) {};
  247.  
  248.     virtual const char *getCurrencyChars(int page,int chr);
  249.  
  250.     virtual void getDefaultUndoAndLayers(int &un,int &lay) {un = 32; lay = 1;};
  251.     virtual void getDefaultRowsAndCols(int &r,int &c) {r = c = 32;};
  252.     virtual void getDefaultFont(MFont &aFont) {aFont.init("12.Helvetica");};
  253.     virtual void getDefaultScale(float &aScale) {aScale=1.0;};
  254.     virtual int getInCellEditing() {return 1;};
  255.  
  256.     virtual int getEnterBehavior() {return 0;};
  257.     virtual void cycleCalcIndicator() {};
  258.  
  259.  
  260.     // fint the number of a model or return -1 if not found
  261.     virtual int findModel(MMesaModel *);
  262.  
  263.     virtual MMesaModel *_findModel(const char *,int needsPath = 1);
  264.         // finds a model with a specific path, returns NULL
  265.         // if the path is not found
  266.     virtual void lockModel();
  267.     virtual void unlockModel();
  268.  
  269.     // script related stuff
  270.     virtual void runScript(const char *,MException *) {}; // = 0;
  271.  
  272.     virtual void addScriptToQueue(const char *) {};
  273.     virtual int canExecute(int,int &flags) {flags = 0; return 0;};
  274.  
  275. #if defined(M2Z) || defined(M2NT)
  276.     // monitor the ping QUEUE and send messages at the right time
  277.     // 94-12-11 dpp
  278.     virtual void watchPing();
  279. #endif
  280.     
  281.     virtual char *getAtom(int);
  282.     virtual int findAtom(const char *);
  283.     
  284.     virtual int getAtomForMesa();
  285.         
  286.     virtual int isRunning() {return running;};
  287.     virtual const char *getTimeSep() { return timeSep; }
  288.     virtual const char *getTimeAM() { return am; }
  289.     virtual const char *getTimePM() { return pm; }
  290.     virtual const int getDateOrder() { return dateOrder; }
  291.     virtual const char *getDateSep() { return dateSep; }
  292.     virtual const unsigned int getDateFormat() { return dateFormat; }
  293.     virtual const unsigned int getTimeFormat() { return timeFormat; }
  294.     virtual const char *getDecSep() { return decimalSep; }
  295.     virtual const char *getThousandsSep() { return thousandsSep; }
  296.     virtual const int getCurrencyPrefix() { return currencyPrefix; }
  297.     virtual const char *getCurrency() { return currencyString; }
  298.  
  299. #if defined(M2Z) || defined(M2NT)
  300.     // returns the "HWND" for the main menu
  301.     // used by addins
  302.     virtual int getMenuWindow() {return 0;} // = 0;
  303.     virtual int addInPMMessage(int,int,int,int);
  304.     virtual HWND getApplicationWindow() {return 0;};
  305.     virtual HWND getActiveWindow() {return 0;};
  306. #endif
  307.     
  308.     virtual void registerAddIn(void *,void *,int);
  309.     // menu command, function (0 execute, 1 can execute, 2 help)
  310.     virtual int doAddInMenuFunction(int,int);
  311.     
  312.     virtual MMesaModel *getActiveModel() {return 0;};
  313.     virtual MMesaModel *openFile(const char *) {return 0;};
  314.     virtual void selectRange(const char *) {return;};
  315.     virtual int getCurrentAddress(MAddress *) {return 0;};
  316.     virtual int getCurrentRange(MRange *) {return 0;};
  317.     virtual MMesaModel *newModel() {return 0;};
  318.     virtual void addInDoubleClick(MMesaModel *,const MAddress *);
  319.     virtual int addInAboutToSave(MMesaModel *);
  320.     virtual void addInOpened(MMesaModel *);
  321.     virtual int addInDataAboutToBeEntered(MMesaModel *,const MAddress *,const char *);
  322.     virtual int addInAboutToClose(MMesaModel *);
  323.     virtual int performAddInFunction(const char *,int numberOfParams,int cache,
  324.         MStack *stack,MMesaModel *model);
  325.     virtual void registerFunctionAddIn(const char *name,const char *fbName,
  326.         const char *fbProto,const char *fbDesc,const char *fbExample,int *fbMembers,
  327.         void *callBack);
  328.     virtual int findFuncAddIns(const char *,int = -1);
  329.     virtual int getNumFuncAddIns() {return numFuncAddIns;};
  330.     virtual const char *getFuncAddInName(int);
  331.     virtual const char *getFuncAddInFBName(int);
  332.     virtual const char *getFuncAddInFBPrototype(int);
  333.     virtual const char *getFuncAddInFBDescription(int);
  334.     virtual const char *getFuncAddInFBExample(int);
  335.     virtual const int *getFuncAddInFBMembers(int);
  336.     
  337.     
  338.     // script history
  339.     virtual void addStringToHistoryBuffer(const char *) {return;};
  340.     
  341.     
  342.     // are we the currently active application?
  343.     virtual int isApplicationActive() {return 1;};
  344.     
  345.     // get the thread ID that was executing when this instance was created (i.e., the UI Thread)
  346.     virtual int getThreadNum() {return myThreadNum;};
  347.     virtual void insertOperator( const char * ) {};
  348.     virtual void insertTextAndSelectArgs( const char * ) {};
  349.     
  350.     virtual MGraphPtr getBufferHPS();
  351.     virtual void releaseBufferHPS();
  352.  
  353.     virtual unsigned int getTime() { return curTime; };
  354.     virtual void setTime(unsigned int now) { curTime = now;};
  355.  
  356.     virtual void checkFontCache(const MFont *);
  357.  
  358. #ifdef M2MAC
  359.     virtual void idleEvent();
  360.     virtual void setCapture(MView *);
  361. #endif
  362.  
  363.     private:
  364.     // load any controller-wide defaults from ini files...
  365.     void loadDefaults();
  366.     void loadLicenseString( char *&license, char *&encrypted, HAB hab );
  367.     void  processLicenseResults( int gotTheLicence, int enable, const char *lic, HAB hab );
  368.     // the double-buffering facilities
  369. #ifdef M2Z
  370.     HDC dbHdc;
  371.     HPS dbHps;
  372.     HBITMAP dbHbm;
  373.     MMutex *dbMutex;
  374.  
  375.     DATETIME lastFeedTime;
  376.     HATOMTBL atoms;
  377. #endif
  378.  
  379. #ifdef M2MAC
  380.     MCapture *capture; // the instance of the view that we are using to capture mouse movement events
  381.     MNull *myNull;
  382.     MMutex *msgMut;
  383.     int msgSendCnt;
  384.     HWND msgWin[100];
  385.     int msgNum[100];
  386.     int msgParam1[100];
  387.     int msgParam2[100];
  388. #endif
  389.  
  390.     // font caching information
  391.     MFont fonts[MAXCACHEDFONTS + 1];  // the fonts;
  392.     int numFonts;      // the number of fonts in the array
  393.     MMutex *fntMut;    // mutex for writing dealing with the fonts
  394.  
  395.     unsigned int curTime;
  396.  
  397.     int numModel,maxModel;
  398.     MMesaModel **models;
  399.     MMutex *pmodelMut;
  400.  
  401.  
  402.     // int feedChanged;
  403.     int waitForFeedNum;
  404.  
  405.     int useRGB;
  406.     int inDemoMode;
  407.     char *theLicense;
  408.  
  409.     // list of pingHolders
  410.     MPing *thePings[MAXPING];
  411.     MMutex *pingMut;
  412.     int pingThreadNum;
  413.     int running;
  414.  
  415.     // internationalization entries...
  416.     char *timeSep;        // between hours, minutes and seconds
  417.     char *dateSep;
  418.     char *am, *pm;    // string used for AM/PM...
  419.     int dateOrder, timeOrder;        // values stored in INI file...
  420.     unsigned int dateFormat;        // mdy, dmy, or ymd
  421.     unsigned int timeFormat;        // 12 hours vs 24 hours
  422.     char *decimalSep;                    // currency decimal separator
  423.     char *thousandsSep;                // thousands separator
  424.     int    fixedDec;                    // number of digits to show for fixed decimal
  425.     int    measurement;    // english, metric, picas, points.
  426.     char currency[ 4 ][ 4 ];        // a 4x4 grid of currency characters...
  427.     int    currencyPrefix;            // 1 if a prefix, 0 if a suffix
  428.     char *currencyString;        // currency string
  429.     
  430.     int numAddIns,maxAddIns;
  431.     MAddIn **addIns;
  432.     
  433.     int maxFuncAddIns,numFuncAddIns;
  434.     MFunctionAddIn **funcAddIn;
  435.     void sortFuncAddIns();
  436.  
  437.     MMutex *errorMut;
  438.  
  439.     char **errors;
  440.     char **shortErrors;
  441.     int numError;
  442.     
  443.     int myThreadNum;
  444.  
  445.    // Keyboard state flags
  446.    int keystateflags;
  447. };
  448.  
  449. // if this bit it set, we have a full size mesa worksheet
  450. const int FULLSIZELIC = 0x8000;
  451. const int NOTVALID_LICENSE = 2; // the license string was not valid
  452. const int EXPIRED_LICENSE = 1; // the license has expired
  453.  
  454.  
  455. //flag values for the keyboard state methods
  456. const int KEYMASK_END         = 0x0001;
  457. const int KEYMASK_CAPSLOCK    = 0x0002;
  458. const int KEYMASK_NUMLOCK     = 0x0004;
  459. const int KEYMASK_INSERTMODE  = 0x0008;
  460. const int KEYMASK_SCROLLLOCK  = 0x0010;
  461.  
  462.  
  463. #ifdef M2Z
  464. // this is support for the entry point for background printing from WPS
  465. #ifdef __cplusplus
  466. extern "C"
  467. {
  468. #endif
  469.  
  470. void doBkgPrint(void *,char *);
  471. #ifdef __cplusplus
  472. }
  473. #endif
  474.  
  475. // ifdef M2Z
  476. #endif
  477.  
  478. #ifdef IN_DLL
  479. extern MGController *TheMesa;
  480. #endif
  481.  
  482. // IBMCHANGE
  483. // the name of the application for defaults lookup
  484. #if defined(M2Z)
  485. #define ApplicationName "Mesa2"
  486. #else
  487. #define ApplicationName "Mesa"
  488. #endif
  489.  
  490. // #ifndef _MH_mesa
  491.  
  492. #endif
  493.  
  494.