home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesaaiok.zip / source / model.h < prev    next >
C/C++ Source or Header  |  1995-10-25  |  7KB  |  161 lines

  1.  
  2. // This is the class that abbstracts all of the functions for interacting with the
  3. // model (worksheet)  You can use it to create new sheets, play with current sheets,
  4. // etc...
  5.  
  6. #ifndef __MODEL__
  7. #define __MODEL__
  8.  
  9. #include "extaddin.h"
  10. #include "range.h"
  11.  
  12. class Model {
  13.    public:
  14.     // The constructors
  15.     // The default constructor creates a NEW model and displays it.
  16.     Model();
  17.     // -1 to get current model, 0 for new model, else the model handle
  18.     Model(int m);
  19.     // simple copy constructor
  20.     Model(const Model &md) { _model = md._model; _redisplay = md._redisplay;};
  21.     // loads a model from a file
  22.     Model(char *name);
  23.  
  24.     // for interacting with certain functions that need a model handle
  25.     int getModelPtr() { return _model;};
  26.     void setModelPtr(int m) { _model = m;};
  27.  
  28.     // Functions for accessing/changing the name of the model.
  29.     Model & getName(char * buf,int max);
  30.     Model & setName(char *);
  31.  
  32.     // Functions to force a save of the model
  33.     Model & save();
  34.     Model & saveAs(char * name);
  35.  
  36.     // Loads a model
  37.     int load(char * name);   // returns true if successfull
  38.  
  39.     // Many actions (such as setCellToValue) can be set to recalc and then
  40.     // redisplay or not do anything.  Use these functions to
  41.     // set that.  (0 = recalc/redisplay, -1 = do nothing)
  42.     // (*) Note that there are other flags too.(used internally)  the general
  43.     //     format is what flags NOT to do.  Example -1 is 0xFFFFFFFF or don't
  44.     //     do any of these flags.  0 means do all of the defaults.
  45.     //     Experiment with knowledge at your own risk.
  46.     Model & setToRedisplayOnAction(int t = 0) { _redisplay = t; return *this;};
  47.     Model & setToNotRedisplayOnAction() { _redisplay = -1; return *this;};
  48.  
  49.     // Takes an address object and converts it to a string.
  50.     Model & addressToString(Address &a,char * buf,int max);
  51.     // Takes a string and converts it to an Address
  52.     Address stringToAddress(char * buf);
  53.  
  54.     // Does the same thing with ranges.
  55.     Model & rangeToString(Range &r,char * buf, int max);
  56.     Range stringToRange(char * buf);
  57.  
  58.     // Selects a named range.
  59.     // (*) This only works if the model is the current active window
  60.     Model & selectNamedRange(char *buf);
  61.  
  62.     // These methods are for accessing/setting the
  63.     // values of a cell directly.  Setting the cells to a value
  64.     // will return 0 if it is successful or non-zero if not.
  65.     // The getCell* will return 0 if successful or non-zero if
  66.     // it wasn't successfull or if the value type is different
  67.     // than what was asked for. (Example: doing a getCellError
  68.     // on a cell with a proper value in it)
  69.     // (*) Empty cells are cells with Error type 0
  70.     // (*) There are other error types, (Last I checked, there were
  71.     //     over 40) experiment at your own risk.
  72.     int setCellValue(const Address &ad,double db);
  73.     int setCellValue(const Address &ad,char * str);
  74.     int setCellError(const Address &ad,int error);
  75.  
  76.     int getCellValue(const Address &ad,double &db);
  77.     int getCellValue(const Address &ad,char * &str, int max);
  78.     int getCellError(const Address &ad,int &error);
  79.  
  80.     // The cell string is the string that a user would type
  81.     // into the cell, wither that be a number, like "3.14159"
  82.     // or a formula, like "=if(0>1,A1,A2)".  The cell output
  83.     // is what is displayed in the cell.  You can use the
  84.     // setCellString to set the formula in the string.
  85.     int setCellString(const Address &ad,char * str);
  86.     Model & getCellString(const Address &ad,char * &str, int max);
  87.     Model & getCellOutput(const Address &ad,char * &str, int max);
  88.  
  89.     // These are used for dealing with the size of the layer
  90.     // (*) Note that these are the VISIBLE extents of the sheet.
  91.     //     Mesa allows cells to exist off of the visible region.
  92.     int setExtentsForLayer(int layer,int rows,int columns);
  93.     int getExtentsForLayer(int layer,int &rows,int &columns);
  94.  
  95.     // Methods for playing with the layers.  Add layer always
  96.     // add's it as the last layer.
  97.     int getNumberOfLayers();
  98.     Model & addLayer();
  99.  
  100.     // These methods are for manipulating the size of columns
  101.     // and rows.
  102.     int setRowSize(int layer,int row, int size);
  103.     int getRowSize(int layer,int row);
  104.     int setColSize(int layer,int col, int size);
  105.     int getColSize(int layer,int col);
  106.  
  107.     // Forces a recalc of the model
  108.     Model & recalc();
  109.  
  110.     // forces a redisplay of the model.
  111.     Model & redisplay();
  112.  
  113.     // These methods allow you to save data (BLOBS) (Binare Lengths of Bytes)
  114.     // in the model to be recalled later.
  115.     // (*) These were EXTREMELY broken in 101 (they caused a crash) so make sure
  116.     //     you check the version number if you have any intentions of using them.
  117.     Model & setBlob(char * name, int len, void * data);
  118.     int getBlob(char * name,int max, void * data); // returns number of bytes put in data
  119.  
  120.     // These functions are used inside of functions that are regstered
  121.     // by the addin.  They work like the CellValue() methods except they
  122.     // operate on the evaluation stack.
  123.     // (*) Stacks are FILO so if the funtion is FOO(1,2,3,4), the first
  124.     //     number poped from the stack is 4 and the last number is 1.
  125.     // (*) If you ask for a certain type(like the double) and the result
  126.     //     is not a double, The value is pushed back onto the stack so
  127.     //     you can query it properly.
  128.     // (*) These were also broken in 101.  Be careful.
  129.     int pushValue(void * stack,double db);
  130.     int pushValue(void * stack,char * str);
  131.     int pushError(void * stack,int error);
  132.  
  133.     int popValue(void * stack,double &db);
  134.     int popValue(void * stack,char * &str, int max);
  135.     int popError(void * stack,int &error);
  136.  
  137.  
  138.     // stuff for dealing directly with the MesaAddInValue structure. Use
  139.     // these for dealing with arrays.  If someone has a briliant way to deal
  140.     // with the array issue so that methods like popValue(stack,array) can
  141.     // be done, let me know.
  142.     void initAddInValue(MesaAddInValue &aiv);
  143.     void freeAddInValue(MesaAddInValue &aiv);
  144.  
  145.     void pushValue( void * stack, MesaAddInValue &aiv);
  146.     void popValue( void * stack, MesaAddInValue &aiv);
  147.  
  148.     void getCellValue( Address & ad, MesaAddInValue &aiv);
  149.     void setCellValue( Address & ad, MesaAddInValue &aiv);
  150.  
  151.  
  152.  
  153.     int operator == (const Model &mo) { return (_model == mo._model);};
  154.  
  155.    private:
  156.     int _model;
  157.     int _redisplay;
  158. };
  159.  
  160. #endif
  161.