InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TableTypes.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Joe Shankar
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // Purpose: Base types for tables.
24 //
25 //========================================================================================
26 
27 #ifndef __TableTypes__
28 #define __TableTypes__
29 
30 #include <algorithm>
31 
32 #include "IPMStream.h"
33 #include "K2Vector.h"
34 #include "ParcelKey.h"
35 
36 #ifdef PUBLIC_BUILD
37 #endif
38 
39 template <class T>
40 inline void UNUSED(const volatile T&) {} // Note that this generates no code on Mac or Win (if inlining is on).
41 
42 
43 //-----------------------------------
44 // Forward References
45 //
46 class GridAddress;
47 class GridArea;
48 class GridID;
49 class RowRange;
50 class ColRange;
51 class CellParcelAddr;
52 //-----------------------------------
53 // Types
54 //
55 typedef int32 GridCoord; // Row or column number
56 
57 namespace Tables
58 {
59  enum ECellEdge {eLeft, eRight, eTop, eBottom};
60 
61  enum ERowColumn { eRow, eColumn };
62 
65  enum ERelativePosition { eBefore, eAfter };
66 
71  enum EContinuation {
72  eStructureAllAttrs, // content and table attributes
73  eStructureTableAttrs, // no content attributes
74  eNoStructureAllAttrs // content and table attributes, not not struct
75  };
76 
80  enum ESelectionSides {
81  eNoSides = 0,
82  eLeftSide = 1,
83  eRightSide = 2,
84  eTopSide = 4,
85  eBottomSide = 8,
86  eInteriorRows = 16,
87  eInteriorCols = 32,
88  eAllSides = 63
89  };
90 
91  enum ERowStartAtValue {
92  eStartAnywhere = 0,
93  eStartNextColumn = 2,
94  eStartNextFrame = 3,
95  eStartNextPage = 4,
96  eStartNextOddPage = 5,
97  eStartNextEvenPage = 6
98  };
99 
100  enum EHeaderFootersBreakValues {
101  eStartEachTextColumn = 0,
102  eStartEachTextFrame = 1,
103  eStartEachPage = 2
104  };
105 
106  enum EStrokeDrawingOrder {
107  eBestJoins = 0,
108  eRowOnTop = 1,
109  eColumnOnTop = 2,
110  eInDesign2Compatibility = 3
111  };
112 
113  enum EDirection {eLTR, eRTL};
114 
115  inline ESelectionSides operator|(ESelectionSides first, ESelectionSides second)
116  {
117  ASSERT(first >= eNoSides && first <= eAllSides);
118  ASSERT(second >= eNoSides && second <= eAllSides);
119 
120  ESelectionSides result = (ESelectionSides)((uint32)first | (uint32)second);
121 
122  ASSERT(result >= eNoSides && result <= eAllSides);
123  return result;
124  };
125 }
126 
129 
130 typedef ClassID CellType;
131 
132 //-----------------------------------
133 // Constants
134 //
135  extern const GridID kInvalidGridID;
136  extern const GridAddress kBadGridAddress;
137  extern const GridCoord kBadCoord;
138  extern const GridArea kZeroGridArea;
139  extern const CellParcelAddr kBadParcelAddr;
140  extern const CellType kNoContentType;
141 
142 //===================================================================================
143 // class GridAddress
172 //===================================================================================
173 class GridAddress {
174 
175 public:
179 
183  GridAddress() : row(kBadCoord), col(kBadCoord) {}
188  GridAddress(GridCoord inRow, GridCoord inCol) : row(inRow), col(inCol) {}
189 
194  void Set(GridCoord inRow, GridCoord inCol) {row = inRow; col = inCol;}
195 
201  GridAddress operator+(const GridAddress& rhs) const {return GridAddress(row + rhs.row, col + rhs.col);}
202 
210  GridAddress operator-(const GridAddress& rhs) const {return GridAddress(row - rhs.row, col - rhs.col);}
211 
217  GridAddress& operator+=(const GridAddress& rhs) {row += rhs.row; col += rhs.col; return *this;}
218 
224  GridAddress& operator-=(const GridAddress& rhs) {row -= rhs.row; col -= rhs.col; return *this;}
225 
231  bool16 operator ==(const GridAddress& rhs) const {return row == rhs.row && col == rhs.col;}
232 
237  bool16 operator !=(const GridAddress& rhs) const {return row != rhs.row || col != rhs.col;}
238 
246  bool16 operator < (const GridAddress& rhs) const {return row < rhs.row || (row == rhs.row && col < rhs.col);}
247 
254  bool16 operator <=(const GridAddress& rhs) const {return row < rhs.row || (row == rhs.row && col <= rhs.col);}
255 
262  bool16 operator > (const GridAddress& rhs) const {return row > rhs.row || (row == rhs.row && col > rhs.col);}
263 
272  bool16 operator >=(const GridAddress& rhs) const {return row > rhs.row || (row == rhs.row && col >= rhs.col);}
273 
278  void ReadWrite(IPMStream* stream) {stream->XferInt32(row); stream->XferInt32(col);}
279 
280 public:
284  GridCoord row;
288  GridCoord col;
289 };
290 
291 
292 //===================================================================================
293 // class GridID
304 //===================================================================================
305 class GridID {
306 public:
310  explicit GridID(uint32 id = 0) : fGridID(id) {}
314  operator uint32() const {return fGridID;}
315 private:
316  uint32 fGridID;
317 };
318 
319 
320 //===================================================================================
321 // class GridSpan
327 //===================================================================================
328 class GridSpan {
329 
330 public:
336 
340  GridSpan() : height(1), width(1) {} // $$$ better to initialize to -1?
346  GridSpan(int32 inHeight, int32 inWidth) : height(inHeight), width(inWidth) {}
347 
352  void Set(int32 inHeight, int32 inWidth) {height = inHeight; width = inWidth;}
353 
358  bool16 IsUnitSpan() const {return height == 1 && width == 1;}
359 
363  bool16 IsEmpty() const {return height == 0 || width == 0;}
364 
371  bool16 operator ==(const GridSpan& rhs) const {return height == rhs.height && width == rhs.width;}
378  bool16 operator !=(const GridSpan& rhs) const {return height != rhs.height || width != rhs.width;}
379 
380  void ReadWrite(IPMStream* stream) {stream->XferInt32(height); stream->XferInt32(width);}
381 
382 public:
384  int32 height;
386  int32 width;
387 };
388 
389 
390 //===================================================================================
391 // class GridArea
403 //===================================================================================
404 class GridArea {
405 
406 public:
411 
412  // ----- Constructors -----
414  GridArea();
415 
423  GridArea(GridCoord topRow, GridCoord leftCol, GridCoord bottomRow, GridCoord right);
424 
431  GridArea(const GridAddress& topLeftElement, const GridAddress& bottomRightElement);
432 
438  GridArea(const GridAddress& anchor, const GridSpan& span);
439 
444  GridArea(const RowRange& rows, const ColRange& cols);
445 
446  void Set(GridCoord topRow, GridCoord leftCol, GridCoord bottomRow, GridCoord right);
447 
448  // ----- Corners -----
452 
459 
465  GridAddress GetTopLeftElem() const {return this->GetTopLeft();}
466 
473 
479 
486 
490  void SetTopLeft (const GridAddress& tl) {topRow = tl.row; leftCol = tl.col;}
491 
495  void SetBottomRight(const GridAddress& br) {bottomRow = br.row; rightCol = br.col;}
496 
500  inline RowRange GetRows() const;
501 
505  inline ColRange GetCols() const;
506 
507  // ----- Dimensions -----
511 
514  int32 Width() const {return rightCol - leftCol;}
515 
518  int32 Height() const {return bottomRow - topRow;}
519 
523  bool16 IsEmpty() const {return leftCol >= rightCol || topRow >= bottomRow;}
524 
525  // ----- Operations -----
530  GridArea operator&(const GridArea& rhs) const;
535  GridArea operator|(const GridArea& rhs) const;
536  // Intersect and union operators.
537 
542  GridArea& operator&=(const GridArea& rhs) {*this = *this & rhs; return *this;}
543 
548  GridArea& operator|=(const GridArea& rhs) {*this = *this | rhs; return *this;}
549 
550  // ----- Relational Operators -----
557  bool16 operator ==(const GridArea& rhs) const {return topRow == rhs.topRow && bottomRow == rhs.bottomRow && leftCol == rhs.leftCol && rightCol == rhs.rightCol;}
558 
565  bool16 operator !=(const GridArea& rhs) const {return !this->operator==(rhs);}
566 
567  // ----- Misc -----
573  bool16 Normalize();
574 
580  bool16 IsNormalized() const {return topRow <= bottomRow && leftCol <= rightCol;}
581 
587  bool16 Contains(const GridAddress& element) const {return element.row >= topRow && element.row < bottomRow && element.col >= leftCol && element.col < rightCol;}
588 
589 
594  bool16 Contains(const GridArea& area) const {return area.topRow >= topRow && area.bottomRow <= bottomRow && area.leftCol >= leftCol && area.rightCol <= rightCol;}
595 
600  bool16 Intersects(const GridArea& area) const {return leftCol < area.rightCol && rightCol > area.leftCol && topRow < area.bottomRow && bottomRow > area.topRow;}
601  void ReadWrite(IPMStream* stream) {stream->XferInt32(topRow); stream->XferInt32(leftCol); stream->XferInt32(bottomRow); stream->XferInt32(rightCol);}
606 
607 public:
610  GridCoord topRow;
614  GridCoord leftCol;
617  GridCoord bottomRow;
618 
622  GridCoord rightCol;
623 };
624 
625 //===================================================================================
626 // class RowRange
635 //===================================================================================
636 class RowRange {
637 public:
638 
639  typedef base_type data_type;
640 
643  RowRange() : start(0), count(0) {}
648  RowRange(int32 inStart, int32 inCount) : start(inStart), count(inCount) { ASSERT(count >= 0); }
653  explicit RowRange(const GridArea& area) : start(area.topRow), count(area.Height()) { ASSERT(count >= 0); }
654 
655 
660  void Set(int32 sstart, int32 ccount) { start = sstart; count = ccount; ASSERT(count >= 0); }
661 
664  int32 End() const { return start + count; }
665 
668  bool16 IsEmpty() const { return count == 0; }
669 
675  bool16 Contains (const RowRange& rhs) const { return rhs.start >= start && rhs.End() <= this->End(); }
676 
681  bool16 Contains (int32 row) const { return row >= start && row < start + count; }
682 
686  bool16 Intersects(const RowRange& rhs) const { return start < rhs.End() && this->End() > rhs.start; }
687 
692  bool16 operator ==(const RowRange& rhs) const { return start == rhs.start && count == rhs.count; }
693 
697  bool16 operator !=(const RowRange& rhs) const { return start != rhs.start || count != rhs.count; }
698 
704  RowRange operator&(const RowRange& rhs) const;
708  RowRange operator|(const RowRange& rhs) const;
709 
715  RowRange& operator&=(const RowRange& rhs) { *this = *this & rhs; return *this; }
716 
722  RowRange& operator|=(const RowRange& rhs) { *this = *this | rhs; return *this; }
723 
728  void ReadWrite(IPMStream* stream) { stream->XferInt32(start); stream->XferInt32(count); }
729 
730 public:
733  int32 start;
736  int32 count;
737 };
738 
739 
740 //===================================================================================
741 // class ColRange
750 //===================================================================================
751 class ColRange {
752 
753 public:
754  typedef base_type data_type;
755 
758  ColRange() : start(0), count(0) {}
759 
764  ColRange(int32 sstart, int32 ccount) : start(sstart), count(ccount) { ASSERT(count >= 0);}
765 
770  explicit ColRange(const GridArea& area) : start(area.leftCol), count(area.Width()) { ASSERT(count >= 0);}
771 
776  void Set(int32 sstart, int32 ccount) { start = sstart; count = ccount; ASSERT(count >= 0); }
777 
780  int32 End() const { return start + count; }
781 
785  bool16 IsEmpty() const { return count == 0; }
786 
791  bool16 Contains (const ColRange& rhs) const { return rhs.start >= start && rhs.End() <= this->End(); }
796  bool16 Contains (int32 col) const { return col >= start && col < this->End(); }
801  bool16 Intersects(const ColRange& rhs) const { return start < rhs.End() && this->End() > rhs.start; }
802 
808  bool16 operator ==(const ColRange& rhs) const { return start == rhs.start && count == rhs.count; }
813  bool16 operator !=(const ColRange& rhs) const { return start != rhs.start || count != rhs.count; }
814 
818  ColRange operator&(const ColRange& rhs) const;
822  ColRange operator|(const ColRange& rhs) const;
823 
829  ColRange& operator&=(const ColRange& rhs) { *this = *this & rhs; return *this; }
830 
835  ColRange& operator|=(const ColRange& rhs) { *this = *this | rhs; return *this; }
836 
837 
841  void ReadWrite(IPMStream* stream) { stream->XferInt32(start); stream->XferInt32(count); }
842 
843 public:
846  int32 start;
849  int32 count;
850 };
851 
852 //
853 // An address to a parcel of a cell
854 // This contains the gridID of the cell and the parcel identification for the parcel
855 //
857 public:
858  typedef base_type data_type;
859 
860  GridAddress cellAddr;
861  ParcelKey parcelKey;
862 
863 public:
864  CellParcelAddr() : cellAddr(kBadGridAddress), parcelKey() {}
865  CellParcelAddr(GridAddress addr, ParcelKey key) {cellAddr = addr; parcelKey = key;}
866 
867  bool16 operator ==(const CellParcelAddr& rhs) const { return cellAddr == rhs.cellAddr && parcelKey == rhs.parcelKey; }
868  bool16 operator !=(const CellParcelAddr& rhs) const { return !(*this == rhs); }
869 
870 };
871 
872 
873 //===================================================================================
874 // Inlines
875 //===================================================================================
877  topRow(kBadCoord),
878  leftCol(kBadCoord),
879  bottomRow(kBadCoord),
880  rightCol(kBadCoord)
881 {
882 }
883 
884 inline GridArea::GridArea(GridCoord t, GridCoord l, GridCoord b, GridCoord r) :
885  topRow(t),
886  leftCol(l),
887  bottomRow(b),
888  rightCol(r)
889 {
890 }
891 
892 inline GridArea::GridArea(const GridAddress& tl, const GridAddress& br) :
893  topRow(tl.row),
894  leftCol(tl.col),
895  bottomRow(br.row),
896  rightCol(br.col)
897 {
898 }
899 
900 inline GridArea::GridArea(const GridAddress& tl, const GridSpan& span) :
901  topRow(tl.row),
902  leftCol(tl.col),
903  bottomRow(tl.row + span.height),
904  rightCol(tl.col + span.width)
905 {
906 }
907 
908 inline GridArea::GridArea(const RowRange& rows, const ColRange& cols) :
909  topRow (rows.start),
910  leftCol(cols.start),
911  bottomRow(rows.End()),
912  rightCol(cols.End())
913 {
914 }
915 
916 inline void GridArea::Set(GridCoord t, GridCoord l, GridCoord b, GridCoord r)
917 {
918  topRow = t;
919  leftCol = l;
920  bottomRow = b;
921  rightCol = r;
922 }
923 
925 {
926  return RowRange(topRow, bottomRow - topRow);
927 }
928 
930 {
931  return ColRange(leftCol, rightCol - leftCol);
932 }
933 
934 #ifdef PUBLIC_BUILD
935 #endif
936 
937 #endif // __TableTypes__