home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / select.h < prev    next >
C/C++ Source or Header  |  1995-09-15  |  8KB  |  208 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c) 1994                               *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. // 94-09-11 dpp
  17. // this class handles the "current selection" of the worksheet.  This allows
  18. // the expansion of ranges and cells to graphics to anything else
  19. // 94-09-17 dpp added isFrameSelected()
  20.  
  21. #ifndef _MH_selection
  22.  
  23. #define _MH_selection
  24.  
  25. class MStream;
  26. class MMesaModel;
  27. class MFont;
  28. class MFormat;
  29.  
  30. #include "address.h"
  31. #include "range.h"
  32.  
  33. // masks for some layer types
  34.  
  35. const int ASHEETLAYER = 0;
  36. const int ASCRIPTLAYER = 0x10000;
  37. const int ADISPLAYLAYER = 0x20000;
  38. const int AQUERYLAYER = 0x40000;
  39. const int ALAYERMASK = 0xffff;
  40.  
  41. class MSelection
  42. {
  43.  
  44.     public:    
  45.     
  46.     void init();                                // initialize
  47.     void init(MStream *);                        // initialize from a stream
  48.     void init(const MSelection *,int = 1);        // initialize from a copy
  49.     void initToA1() {init();};                    // initialize to cell [A]A1
  50.     void free();                                // release storage
  51.     void zap() {free(); init(); ad.zap();};        // reset to a known state
  52.     void zapToLayer();                            // reset to a known state on the current layer
  53.     void zapRange() {range.zap();};                // zap the range
  54.     void write(MStream *) const;                // archive
  55.  
  56.     MSelection &operator=(const MSelection &);
  57.     MSelection &operator=(const MSelection *);
  58.     MSelection &operator=(const MAddress &);
  59.     MSelection &operator=(const MRange &);
  60.  
  61.     // setting the selection
  62.     void setAddressAndRange(const MAddress *,const MRange *);
  63.  
  64.  
  65.     // setting the layer
  66.     void setLayer(int, MMesaModel *);
  67.  
  68.     // sets the default range for the given layer number
  69.     void setDefaultForLayer(int,const MSelection *);
  70.     void setDefaultForLayer(int,const MAddress *,const MRange *);
  71.  
  72.     // prime a series of selections for the correct stuff
  73.     void prime(int layer,const MAddress *);
  74.     void prime(int layer,const MAddress *,const MRange *);
  75.     void prime(int layer,const MSelection *);
  76.  
  77.  
  78.     // deal if we are selecting a script layer
  79.     int isAScript() const;        // dpr - this doesn't exist?
  80.     // const char *getScriptLayerName() const;
  81.  
  82.     // deal if we are selecting something on a spreadsheet layer
  83.     int isASpreadsheet() const;
  84.     const MAddress *getAdPtr() const {return &ad;};
  85.     const MRange *getRangePtr() const {return ⦥};
  86.     
  87.     const MAddress *getUpperLeftPtr() const {return &upperLeft;};
  88.     MRange *getUnconstRangePtr() {return ⦥};
  89.     int getUpperLeftRow() const {return upperLeft.getRow();};
  90.     int getUpperLeftColumn() const {return upperLeft.getCol();};
  91.     int getUpperLeftLayer() const {return upperLeft.getLayer();};
  92.     int getLayer() const {return layer;};
  93.     void setUpperLeft(const MAddress *ap) {upperLeft = *ap;};
  94.     void setUpperLeftRow(int i) {upperLeft.setRow(i);};
  95.     void setUpperLeftColumn(int i) {upperLeft.setCol(i);};
  96.     void setFrameSelection(const char *);
  97.  
  98.     // get the nth item in the range
  99.     void getItem(int n,MAddress &a1,MAddress &a2) const {range.getItem(n,a1,a2);};
  100.  
  101.     // is a cell in the range?
  102.     int inRange(const MAddress *ad) const {return range.inRange(ad);};
  103.  
  104.     // and what range is it in?
  105.     int inWhichRange(const MAddress *ad,
  106.         MAddress &a1,MAddress &a2) const {return range.inWhichRange(ad,a1,a2);};
  107.  
  108.     // some more range mechanics
  109.     int isRowInRange(int i1,int i2) const {return range.isRowInRange(i1,i2);};
  110.     int isColInRange(int i1,int i2) const {return range.isColInRange(i1,i2);};
  111.  
  112.     // how many elements in the range?
  113.     int getRangeCount() const {return range.getCount();};
  114.  
  115.     // some things that a selection can do
  116.     // return the contents of the current selection
  117.     // and remember to free the returned string
  118.     char *getSelectionContents(MMesaModel *) const;
  119.     char *getSelectionName(MMesaModel *) const;
  120.     void getSelectionFont(MMesaModel *,MFont *) const;
  121.     void getSelectionFormat(MMesaModel *,MFormat *) const;
  122.     const char *getFrameName(int n) const
  123.         {if (graphs && n < numGraphs) return graphs[n]; return 0;};
  124.  
  125.      // return a string representation of the range, if one is selected, or
  126.      // the address if not
  127.      char *getSelectionRange( MMesaModel *, int &);
  128.  
  129. //     void setSelectionContents( MMesaModel *, char * );
  130.     // set the address, but don't disturb the range
  131.     void setAdButNotRange(const MAddress *);
  132.  
  133.     // set a range and sort the range items
  134.     void setAndSort(const MAddress *,const MAddress *);
  135.      void setAndSortItem( int item, const MAddress *, const MAddress * );
  136.     void set(const MAddress *);
  137.  
  138.     // does the selection have any contents?
  139.     int hasSelection() const;
  140.  
  141.     // is the selection zapped?
  142.     int isZapped() const;
  143.  
  144.     // set the selection type
  145.     void makeARange();     // force the selection to be an address or a range
  146.     void makeNoGraph();    // make sure that no graphs are selected
  147.     void makeGraphs();     // force the selection to be graphs plus the underlying range selection
  148.     void makeScript();     // make the current selection a script
  149.  
  150.     // get the selection type
  151.     int isScriptLayer() const; // is the layer a script
  152.     int isSheetLayer() const; // is a worksheet layer selected?
  153.  
  154.     // is the difference between the two selections only the range
  155.     // or is there more
  156.     int deltaOnlyRange(const MSelection *) const;
  157.  
  158.     // get the name of the script if it's a script layer, otherwise, return a blank string
  159.     // 94-09-14 dpp
  160.     const char *getLayerName(MMesaModel *);
  161.  
  162.     // can we edit the contents of the current selection (i.e., does it have a
  163.     // text representation?
  164.     int canEditContents(MMesaModel *) const;
  165.  
  166.     // returns a pointer to a layer if that layer exists so that we
  167.     // can retrieve the former position on a layer
  168.     const MSelection *findSelection(int) const;
  169.  
  170.     // is a named frame one of the selected items?
  171.     int isFrameSelected(const char *) const;
  172.     int isFrameSelected() const;
  173.  
  174.  
  175.     // from the layer number, figure out the type of selections it is
  176.     static int testForSheetLayer(int i)
  177.         {if ((i & ~ALAYERMASK) == 0) return 1; return 0;};
  178.     static int testForScriptLayer(int i)
  179.         {if ((i & ASCRIPTLAYER) == ASCRIPTLAYER) return 1; return 0;};
  180.  
  181.     // put the current cell or range into the given range
  182.     // 94-09-24 dpp
  183.     void fillRange(MRange *) const;
  184.     // returns 0 if the two selections are identical in content, 1 otherwise
  185.     int areDifferent( const MSelection * ) const;
  186.     int getNumGraphs() const { return numGraphs; };
  187.     
  188.     private:
  189.     // int type;                // the type of selection
  190.     int layer;                // the number of the currently displaying layer
  191.     MAddress ad;            // the current address
  192.     MAddress upperLeft;        // the upperleft of the display area
  193.     MRange range;            // the current range
  194.     int numGraphs;            // the number of graphs
  195.     char **graphs;            // a list of the graphs
  196.     char *scriptName;        // the name of the current script
  197.     int numSelections;        // get the number of selections that we have chained
  198.     MSelection *selections;    // selections for each layer
  199.     
  200.  
  201.     // copy the selections except don't mess with the other selections
  202.     void copyExceptOtherSelections(const MSelection *);
  203. };
  204.  
  205.  
  206. // ifndef _MH_selection
  207. #endif
  208.