home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classes.lha / Classes / Layouter / Layouter.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  9.7 KB  |  333 lines

  1. #ifndef CPP_LAYOUTER_LAYOUTER_H
  2. #define CPP_LAYOUTER_LAYOUTER_H
  3.  
  4. // Layouter für Gadgets und andere rechteckige Oberflächenelemente
  5. //
  6. // Autor: Jochen Becher
  7. //
  8. // Historie:
  9. // Version 1.0 am 8. März 94
  10.  
  11. #ifndef EXEC_TYPES_H
  12. #include <exec/types.h>
  13. #endif
  14.  
  15. #ifndef CPP_EXEC_LISTS_H
  16. #include <classes/exec/lists.h>
  17. #endif
  18.  
  19. #ifndef CPP_UTILITY_HOOKS_H
  20. #include <classes/utility/hooks.h>
  21. #endif
  22.  
  23. #ifndef CPP_EXCEPTIONS_EXCEPTIONS_H
  24. #include <classes/exceptions/exceptions.h>
  25. #endif
  26.  
  27. #define LAYOUT_NOSIZE    0
  28. #define LAYOUT_AUTOSIZE -1
  29.  
  30. class LayoutC {
  31. public:
  32.     virtual BOOL layoutWidth() { return TRUE; };
  33.     virtual BOOL layoutHeight() { return TRUE; };
  34.     virtual VOID setTop(WORD t) = 0;
  35.     virtual VOID setLeft(WORD l) = 0;
  36.     virtual VOID setWidth(WORD w) = 0;
  37.     virtual VOID setHeight(WORD h) = 0;
  38.     virtual WORD top() const = 0;
  39.     virtual WORD left() const = 0;
  40.     virtual WORD width() const = 0;
  41.     virtual WORD height() const = 0;
  42.     virtual BOOL autoWidth() const = 0;
  43.     virtual BOOL autoHeight() const = 0;
  44.     virtual WORD topBorder() const = 0;
  45.     virtual WORD bottomBorder() const = 0;
  46.     virtual WORD leftBorder() const = 0;
  47.     virtual WORD rightBorder() const = 0;
  48.     virtual WORD minWidth() { return width(); };
  49.     virtual WORD minHeight() { return height(); };
  50. };
  51.  
  52. class TransparentLayoutC : public LayoutC {
  53. public:
  54.     TransparentLayoutC(
  55.         WORD width = LAYOUT_AUTOSIZE, WORD height = LAYOUT_AUTOSIZE);
  56.     BOOL layoutWidth();
  57.     BOOL layoutHeight();
  58.     VOID setTop(WORD t) { Top = t; };
  59.     VOID setLeft(WORD l) { Left = l; };
  60.     VOID setWidth(WORD w);
  61.     VOID setHeight(WORD h);
  62.     WORD top() const { return Top; };
  63.     WORD left() const { return Left; };
  64.     WORD width() const { return Width; };
  65.     WORD height() const { return Height; };
  66.     BOOL autoWidth() const { return aWidth; };
  67.     BOOL autoHeight() const { return aHeight; };
  68.     WORD topBorder() const { return 0; };
  69.     WORD bottomBorder() const { return 0; };
  70.     WORD leftBorder() const { return 0; };
  71.     WORD rightBorder() const { return 0; };
  72. private:
  73.     WORD Left;
  74.     WORD Top;
  75.     WORD Height;
  76.     WORD Width;
  77.     BOOL aWidth;
  78.     BOOL aHeight;
  79. };
  80.  
  81. class GroupLayoutC : public LayoutC {
  82. public:
  83.     GroupLayoutC() : LayoutC(), minimumWidth(0), minimumHeight(0) { };
  84.     virtual WORD innerTopBorder() const = 0;
  85.     virtual WORD innerBottomBorder() const = 0;
  86.     virtual WORD innerLeftBorder() const = 0;
  87.     virtual WORD innerRightBorder() const = 0;
  88.     WORD minWidth() { return minimumWidth; };
  89.     WORD minHeight() { return minimumHeight; };
  90.     virtual VOID setMinWidth(WORD w) { minimumWidth = w; };
  91.     virtual VOID setMinHeight(WORD h) { minimumHeight = h; };
  92. private:
  93.     WORD minimumWidth;
  94.     WORD minimumHeight;
  95. };
  96.  
  97. class TransparentGroupLayoutC : public GroupLayoutC {
  98. public:
  99.     TransparentGroupLayoutC(
  100.         WORD width = LAYOUT_AUTOSIZE, WORD height = LAYOUT_AUTOSIZE);
  101.     BOOL layoutWidth();
  102.     BOOL layoutHeight();
  103.     VOID setTop(WORD t) { Top = t; };
  104.     VOID setLeft(WORD l) { Left = l; };
  105.     VOID setWidth(WORD w);
  106.     VOID setHeight(WORD h);
  107.     WORD top() const { return Top; };
  108.     WORD left() const { return Left; };
  109.     WORD width() const { return Width; };
  110.     WORD height() const { return Height; };
  111.     BOOL autoWidth() const { return aWidth; };
  112.     BOOL autoHeight() const { return aHeight; };
  113.     WORD topBorder() const { return 0; };
  114.     WORD bottomBorder() const { return 0; };
  115.     WORD leftBorder() const { return 0; };
  116.     WORD rightBorder() const { return 0; };
  117.     WORD minWidth() { return GroupLayoutC::minWidth(); };
  118.     WORD minHeight() { return GroupLayoutC::minHeight(); };
  119.     WORD innerTopBorder() const { return 0; };
  120.     WORD innerBottomBorder() const { return 0; };
  121.     WORD innerLeftBorder() const { return 0; };
  122.     WORD innerRightBorder() const { return 0; };
  123. private:
  124.     WORD Left;
  125.     WORD Top;
  126.     WORD Height;
  127.     WORD Width;
  128.     BOOL aWidth;
  129.     BOOL aHeight;
  130. };
  131.  
  132. class GeometryC;
  133. class GeometryGroupC;
  134. class GeometryBaseC { };
  135.  
  136. // alle möglichen Relationsarten
  137. #define LAYOUT_SIZE              0
  138. #define LAYOUT_SAME              1
  139. #define LAYOUT_SAMEBORDER        2
  140. #define LAYOUT_GROUP             3
  141. #define LAYOUT_OPP               4
  142. #define LAYOUT_OPPBORDER         5
  143. #define LAYOUT_OPPGROUP          6
  144. #define LAYOUT_MAXSIZE           7
  145. #define LAYOUT_SAMESIZE          8
  146. #define LAYOUT_PROCENT           9
  147. #define LAYOUT_PROCENTCENTER    10
  148. #define LAYOUT_MAXSAMEBORDER    11
  149. #define LAYOUT_MAXOPPBORDER     12
  150. #define LAYOUT_HOOK             13
  151. #define LAYOUT_BORDERGROUP      14
  152.  
  153. class LayoutParamPkt {
  154. public:
  155.     UWORD command;
  156.     UWORD flags;
  157.     GeometryGroupC *parent;
  158.     WORD parentPosition;
  159.     WORD parentSize;
  160.     ULONG count;
  161.     WORD offset;
  162.     WORD other_coor;
  163.     WORD coor_result;
  164. };
  165.  
  166. // Commands
  167. #define LAYOUTC_PREWIDTH         1
  168. #define LAYOUTC_PREHEIGHT        2
  169. #define LAYOUTC_PRELEFT          3
  170. #define LAYOUTC_PRERIGHT         4
  171. #define LAYOUTC_PRETOP           5
  172. #define LAYOUTC_PREBOTTOM        6
  173. #define LAYOUTC_LEFT             7
  174. #define LAYOUTC_RIGHT            8
  175. #define LAYOUTC_TOP              9
  176. #define LAYOUTC_BOTTOM          10
  177.  
  178. // Flags
  179. #define LAYOUTB_VALID_OTHER      0
  180. #define LAYOUTF_VALID_OTHER      1
  181. #define LAYOUTB_LAST_CHANCE      1
  182. #define LAYOUTF_LAST_CHANCE      2
  183.  
  184. // Return codes
  185. #define LAYOUTR_UNKNOWN          0
  186. #define LAYOUTR_OK               1
  187. #define LAYOUTR_ERROR            2
  188. #define LAYOUTR_NOTYET           3
  189.  
  190. class GeometryHookC : public GeometryBaseC, public HookC {
  191. public:
  192.     GeometryHookC(APTR data = NULL);
  193.     virtual ULONG layout(GeometryC *, struct LayoutParamPkt *);
  194.     ULONG hook(APTR, APTR);
  195.     ULONG call(GeometryC *, struct LayoutParamPkt *);
  196. };
  197.  
  198. class GeometryC : public GeometryBaseC, public NodeC {
  199. friend class GeometryGroupC;
  200. public:
  201.     GeometryC(LayoutC &g,
  202.         ULONG topRelation, GeometryBaseC *topObject, WORD topOffset,
  203.         ULONG bottomRelation, GeometryBaseC *bottomObject, WORD bottomOffset,
  204.         ULONG leftRelation, GeometryBaseC *leftObject, WORD leftOffset,
  205.         ULONG rightRelation, GeometryBaseC *rightObject, WORD rightOffset);
  206.     virtual ~GeometryC();
  207.     virtual BOOL layoutX(WORD parentLeft, WORD parentWidth, ULONG countX);
  208.     virtual BOOL layoutY(WORD parentTop, WORD parentHeight, ULONG countY);
  209.     virtual BOOL preLayoutX(ULONG countX);
  210.     virtual BOOL preLayoutY(ULONG countY);
  211.     virtual VOID move(WORD dx, WORD dy);
  212.     virtual BOOL layoutGadWidth();
  213.     virtual BOOL layoutGadHeight();
  214.     WORD layoutedTop() { return top; };
  215.     WORD layoutedLeft() { return left; };
  216.     WORD layoutedRight() { return right; };
  217.     WORD layoutedBottom() { return bottom; };
  218.     WORD layoutedWidth() { return right-left; };
  219.     WORD layoutedHeight() { return bottom-top; };
  220.     virtual WORD topBorder() { return gadget->topBorder(); };
  221.     virtual WORD bottomBorder() { return gadget->bottomBorder(); };
  222.     virtual WORD leftBorder() { return gadget->leftBorder(); };
  223.     virtual WORD rightBorder() { return gadget->rightBorder(); };
  224.     LayoutC *layoutObject() { return gadget; };
  225.     VOID setTopRule(ULONG relation, GeometryBaseC *object, WORD offset);
  226.     VOID setBottomRule(ULONG relation, GeometryBaseC *object, WORD offset);
  227.     VOID setLeftRule(ULONG relation, GeometryBaseC *object, WORD offset);
  228.     VOID setRightRule(ULONG relation, GeometryBaseC *object, WORD offset);
  229.     ULONG topRule(GeometryBaseC *&object, WORD &offset);
  230.     ULONG bottomRule(GeometryBaseC *&object, WORD &offset);
  231.     ULONG leftRule(GeometryBaseC *&object, WORD &offset);
  232.     ULONG rightRule(GeometryBaseC *&object, WORD &offset);
  233.     WORD pWidth() { return preWidth; };
  234.     WORD pHeight() { return preHeight; };
  235. private:
  236.     virtual VOID setCounters(ULONG cX, ULONG cY, ULONG pX, ULONG pY);
  237.     BOOL xLayouting;
  238.     BOOL yLayouting;
  239.     ULONG counterX;
  240.     WORD left;
  241.     WORD right;
  242.     ULONG counterY;
  243.     WORD top;
  244.     WORD bottom;
  245.     ULONG preCounterX;
  246.     WORD preLeft;
  247.     WORD preRight;
  248.     WORD preWidth;
  249.     ULONG preCounterY;
  250.     WORD preTop;
  251.     WORD preBottom;
  252.     WORD preHeight;
  253. protected:
  254.     LayoutC *gadget;
  255.     GeometryGroupC *parent;
  256.     ULONG tRel;
  257.     GeometryC *tObj;
  258.     WORD tOffset;
  259.     ULONG bRel;
  260.     GeometryC *bObj;
  261.     WORD bOffset;
  262.     ULONG lRel;
  263.     GeometryC *lObj;
  264.     WORD lOffset;
  265.     ULONG rRel;
  266.     GeometryC *rObj;
  267.     WORD rOffset;
  268. };
  269.  
  270. class GeometryGroupC : public GeometryC, protected ListC {
  271. public:
  272.     GeometryGroupC(GroupLayoutC &g,
  273.         ULONG topRelation, GeometryBaseC *topObject, WORD topOffset,
  274.         ULONG bottomRelation, GeometryBaseC *bottomObject, WORD bottomOffset,
  275.         ULONG leftRelation, GeometryBaseC *leftObject, WORD leftOffset,
  276.         ULONG rightRelation, GeometryBaseC *rightObject, WORD rightOffset);
  277.     virtual ~GeometryGroupC();
  278.     VOID add(GeometryC &g);
  279.     BOOL layoutX(WORD parentLeft, WORD parentWidth, ULONG countX);
  280.     BOOL layoutY(WORD parentTop, WORD parentHeight, ULONG countY);
  281.     BOOL preLayoutX(ULONG countX);
  282.     BOOL preLayoutY(ULONG countY);
  283.     VOID move(WORD dx, WORD dy);
  284.     BOOL layoutGadWidth();
  285.     BOOL layoutGadHeight();
  286.     WORD topBorder() { return maxTBorder; };
  287.     WORD bottomBorder() { return maxBBorder; };
  288.     WORD leftBorder() { return maxLBorder; };
  289.     WORD rightBorder() { return maxRBorder; };
  290.     WORD maxWidth() { return maximumWidth; };
  291.     WORD maxHeight() { return maximumHeight; };
  292.     WORD maxLeftBorder() { return maximumLeftB; };
  293.     WORD maxRightBorder() { return maximumRightB; };
  294.     WORD maxTopBorder() { return maximumTopB; };
  295.     WORD maxBottomBorder() { return maximumBottomB; };
  296. private:
  297.     VOID setCounters(ULONG cX, ULONG cY, ULONG pX, ULONG pY);
  298.     GroupLayoutC *border;
  299.     WORD maximumWidth;
  300.     WORD maximumHeight;
  301.     WORD maximumLeftB;
  302.     WORD maximumRightB;
  303.     WORD maximumTopB;
  304.     WORD maximumBottomB;
  305.     WORD maxLBorder;
  306.     WORD maxRBorder;
  307.     WORD maxTBorder;
  308.     WORD maxBBorder;
  309. };
  310.  
  311. class RootGeometryC {
  312. public:
  313.     RootGeometryC();
  314.     RootGeometryC(GroupLayoutC &);
  315.     VOID add(GeometryC &g);
  316.     VOID layout(WORD parentTop, WORD parentLeft,
  317.         WORD parentWidth, WORD parentHeight);
  318.     WORD top() { return group.layoutedTop(); };
  319.     WORD left() { return group.layoutedLeft(); };
  320.     WORD width() { return group.layoutedWidth(); };
  321.     WORD height() { return group.layoutedHeight(); };
  322.     VOID move(WORD dx, WORD dy) { group.move(dx,dy); };
  323. private:
  324.     TransparentGroupLayoutC transparent;
  325.     GroupLayoutC &gadget;
  326.     GeometryGroupC group;
  327.     ULONG counterX;
  328.     ULONG counterY;
  329. };
  330.  
  331. #endif
  332.  
  333.