home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / IDRAW / LISTCHAN.H < prev    next >
C/C++ Source or Header  |  1980-01-05  |  10KB  |  476 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: listchange.h,v 1.9 89/10/09 14:48:41 linton Exp $
  24. // declares subclasses of ChangeNode and class ChangeList.
  25.  
  26. #ifndef listchange_h
  27. #define listchange_h
  28.  
  29. #include "list.h"
  30.  
  31. // Declare imported types.
  32.  
  33. class CenterList;
  34. class Drawing;
  35. class DrawingView;
  36. class GroupList;
  37. class IBrush;
  38. class IBrushList;
  39. class IColor;
  40. class IColorList;
  41. class IFont;
  42. class IFontList;
  43. class IPattern;
  44. class IPatternList;
  45. class Selection;
  46. class SelectionList;
  47. class State;
  48.  
  49. // ChangeNode stores a change to the Drawing in reversible form and
  50. // can carry out or remove the change.
  51.  
  52. class ChangeNode : public BaseNode {
  53. public:
  54.  
  55.     ChangeNode();
  56.     ChangeNode(Drawing*, DrawingView*, boolean = false);
  57.     ~ChangeNode();
  58.  
  59.     virtual void Do();
  60.     virtual void Undo();
  61.  
  62. protected:
  63.  
  64.     Drawing* drawing;        // performs operations on drawing
  65.     DrawingView* drawingview;    // displays drawing
  66.     SelectionList* oldsl;    // lists the old Selections
  67.  
  68. };
  69.  
  70. // MoveChange translates the Selections.
  71.  
  72. class MoveChange : public ChangeNode {
  73. public:
  74.  
  75.     MoveChange(Drawing*, DrawingView*, float, float);
  76.  
  77.     void Do();
  78.     void Undo();
  79.  
  80. protected:
  81.  
  82.     float dx, dy;        // carries out translation
  83.     float undodx, undody;    // removes translation
  84.  
  85. };
  86.  
  87. // ScaleChange scales the Selections.
  88.  
  89. class ScaleChange : public ChangeNode {
  90. public:
  91.  
  92.     ScaleChange(Drawing*, DrawingView*, float, float);
  93.  
  94.     void Do();
  95.     void Undo();
  96.  
  97. protected:
  98.  
  99.     float sx, sy;        // carries out scaling
  100.     float undosx, undosy;    // removes scaling
  101.  
  102. };
  103.  
  104. // StretchChange stretches the Selections.
  105.  
  106. class StretchChange : public ChangeNode {
  107. public:
  108.  
  109.     StretchChange(Drawing*, DrawingView*, float, Alignment);
  110.  
  111.     void Do();
  112.     void Undo();
  113.  
  114. protected:
  115.  
  116.     Alignment OppositeSide(Alignment);
  117.  
  118.     float stretch;        // carries out stretching
  119.     float undostretch;        // removes stretching
  120.     Alignment side;        // indicates fixed side for do
  121.     Alignment undoside;        // indicates fixed side for undo
  122.  
  123. };
  124.  
  125. // RotateChange rotates the Selections.
  126.  
  127. class RotateChange : public ChangeNode {
  128. public:
  129.  
  130.     RotateChange(Drawing*, DrawingView*, float);
  131.  
  132.     void Do();
  133.     void Undo();
  134.  
  135. protected:
  136.  
  137.     float angle;        // carries out rotation
  138.     float undoangle;        // removes rotation
  139.  
  140. };
  141.  
  142. // ReplaceChange replaces a Selection with another Selection.
  143.  
  144. class ReplaceChange : public ChangeNode {
  145. public:
  146.  
  147.     ReplaceChange(Drawing*, DrawingView*, Selection*, Selection*);
  148.     ~ReplaceChange();
  149.  
  150.     void Do();
  151.     void Undo();
  152.  
  153. protected:
  154.  
  155.     Selection* replacee;    // stores to-be-replaced Selection's address
  156.     Selection* replacer;    // stores replacing Selection's address
  157.  
  158. };
  159.  
  160. // SetBrushChange sets the Selections' brush.
  161.  
  162. class SetBrushChange : public ChangeNode {
  163. public:
  164.  
  165.     SetBrushChange(Drawing*, DrawingView*, IBrush*);
  166.     ~SetBrushChange();
  167.  
  168.     void Do();
  169.     void Undo();
  170.  
  171. protected:
  172.  
  173.     IBrush* brush;        // brush value to set
  174.     IBrushList* undobrushlist;    // brush values to restore
  175.  
  176. };
  177.  
  178. // SetFgColorChange sets the Selections' foreground color.
  179.  
  180. class SetFgColorChange : public ChangeNode {
  181. public:
  182.  
  183.     SetFgColorChange(Drawing*, DrawingView*, IColor*);
  184.     ~SetFgColorChange();
  185.  
  186.     void Do();
  187.     void Undo();
  188.  
  189. protected:
  190.  
  191.     IColor* fgcolor;        // color value to set
  192.     IColorList* undofglist;    // color values to restore
  193.  
  194. };
  195.  
  196. // SetBgColorChange sets the Selections' background color.
  197.  
  198. class SetBgColorChange : public ChangeNode {
  199. public:
  200.  
  201.     SetBgColorChange(Drawing*, DrawingView*, IColor*);
  202.     ~SetBgColorChange();
  203.  
  204.     void Do();
  205.     void Undo();
  206.  
  207. protected:
  208.  
  209.     IColor* bgcolor;        // color value to set
  210.     IColorList* undobglist;    // color values to restore
  211.  
  212. };
  213.  
  214. // SetFontChange sets the Selections' font.
  215.  
  216. class SetFontChange : public ChangeNode {
  217. public:
  218.  
  219.     SetFontChange(Drawing*, DrawingView*, IFont*);
  220.     ~SetFontChange();
  221.  
  222.     void Do();
  223.     void Undo();
  224.  
  225. protected:
  226.  
  227.     IFont* font;        // font value to set
  228.     IFontList* undofontlist;    // font values to restore
  229.  
  230. };
  231.  
  232. // SetPatternChange sets the Selections' pattern.
  233.  
  234. class SetPatternChange : public ChangeNode {
  235. public:
  236.  
  237.     SetPatternChange(Drawing*, DrawingView*, IPattern*);
  238.     ~SetPatternChange();
  239.  
  240.     void Do();
  241.     void Undo();
  242.  
  243. protected:
  244.  
  245.     IPattern* pattern;           // pattern value to set
  246.     IPatternList* undopatternlist; // pattern values to restore
  247.  
  248. };
  249.  
  250. // AddChange adds the Selections to the Drawing.
  251.  
  252. class AddChange : public ChangeNode {
  253. public:
  254.  
  255.     AddChange(Drawing*, DrawingView*);
  256.     ~AddChange();
  257.  
  258.     void Do();
  259.     void Undo();
  260.  
  261. protected:
  262.  
  263.     boolean done;        // remembers if change was done
  264.  
  265. };
  266.  
  267. // DeleteChange deletes the Selections from the Drawing.
  268.  
  269. class DeleteChange : public ChangeNode {
  270. public:
  271.  
  272.     DeleteChange(Drawing*, DrawingView*);
  273.     ~DeleteChange();
  274.  
  275.     void Do();
  276.     void Undo();
  277.  
  278. protected:
  279.  
  280.     SelectionList* prevlist;    // lists the selections' predecessors
  281.     boolean done;        // remembers if change was done
  282.  
  283. };
  284.  
  285. // CutChange removes the Selections from the Drawing and copies them
  286. // to the Clipboard, deleting the Clipboard's previous contents.
  287.  
  288. class CutChange : public DeleteChange {
  289. public:
  290.  
  291.     CutChange(Drawing*, DrawingView*);
  292.  
  293.     void Do();
  294.  
  295. };
  296.  
  297. // CopyChange copies the Selections to the Clipboard, deleting the
  298. // Clipboard's previous contents.
  299.  
  300. class CopyChange : public ChangeNode {
  301. public:
  302.  
  303.     CopyChange(Drawing*, DrawingView*);
  304.  
  305.     void Do();
  306.  
  307. };
  308.  
  309. // PasteChange copies the Selections in the Clipboard and appends the
  310. // new Selections to the Drawing.
  311.  
  312. class PasteChange : public AddChange {
  313. public:
  314.  
  315.     PasteChange(Drawing*, DrawingView*, State*);
  316.  
  317. };
  318.  
  319. // DuplicateChange copies the Selections and appends the new
  320. // Selections to the Drawing.
  321.  
  322. class DuplicateChange : public AddChange {
  323. public:
  324.  
  325.     DuplicateChange(Drawing*, DrawingView*);
  326.  
  327. };
  328.  
  329. // GroupChange groups the Selections into a single PictSelection.
  330.  
  331. class GroupChange : public ChangeNode {
  332. public:
  333.  
  334.     GroupChange(Drawing*, DrawingView*);
  335.     ~GroupChange();
  336.  
  337.     void Do();
  338.     void Undo();
  339.  
  340. protected:
  341.  
  342.     SelectionList* prevlist;    // lists the selections' predecessors
  343.     GroupList* grouplist;    // lists the selections and their new parent
  344.     boolean done;        // remembers whether change was done
  345.  
  346. };
  347.  
  348. // UngroupChange ungroups each PictSelection into its children.
  349.  
  350. class UngroupChange : public ChangeNode {
  351. public:
  352.  
  353.     UngroupChange(Drawing*, DrawingView*);
  354.     ~UngroupChange();
  355.  
  356.     void Do();
  357.     void Undo();
  358.  
  359. protected:
  360.  
  361.     GroupList* undogrouplist;    // lists the selections and their children
  362.     boolean done;        // remembers whether change was done
  363.  
  364. };
  365.  
  366. // BringToFrontChange brings the Selections to the front of the
  367. // Drawing.
  368.  
  369. class BringToFrontChange : public ChangeNode {
  370. public:
  371.  
  372.     BringToFrontChange(Drawing*, DrawingView*);
  373.     ~BringToFrontChange();
  374.  
  375.     void Do();
  376.     void Undo();
  377.  
  378. protected:
  379.  
  380.     SelectionList* prevlist;    // lists the selections' predecessors
  381.  
  382. };
  383.  
  384. // SendToBackChange sends the Selections to the back of the Drawing.
  385.  
  386. class SendToBackChange : public ChangeNode {
  387. public:
  388.  
  389.     SendToBackChange(Drawing*, DrawingView*);
  390.     ~SendToBackChange();
  391.  
  392.     void Do();
  393.     void Undo();
  394.  
  395. protected:
  396.  
  397.     SelectionList* prevlist;    // lists the selections' predecessors
  398.  
  399. };
  400.  
  401. // AlignChange aligns the Selections.
  402.  
  403. class AlignChange : public ChangeNode {
  404. public:
  405.  
  406.     AlignChange(Drawing*, DrawingView*, Alignment, Alignment);
  407.     ~AlignChange();
  408.  
  409.     void Do();
  410.     void Undo();
  411.  
  412. protected:
  413.  
  414.     Alignment falign;        // part of fixed Selection to align up with
  415.     Alignment malign;        // part of moving Selection to align up with
  416.     CenterList* centerlist;    // stores Selections' original positions
  417.  
  418. };
  419.  
  420. // AlignToGridChange aligns the Selections to the grid.
  421.  
  422. class AlignToGridChange : public ChangeNode {
  423. public:
  424.  
  425.     AlignToGridChange(Drawing*, DrawingView*);
  426.     ~AlignToGridChange();
  427.  
  428.     void Do();
  429.     void Undo();
  430.  
  431. protected:
  432.  
  433.     CenterList* centerlist;    // stores Selections' original positions
  434.  
  435. };
  436.  
  437. // A ChangeList manages a list of ChangeNodes.
  438.  
  439. class ChangeList : public BaseList {
  440. public:
  441.  
  442.     ChangeNode* First();
  443.     ChangeNode* Last();
  444.     ChangeNode* Prev();
  445.     ChangeNode* Next();
  446.     ChangeNode* GetCur();
  447.     ChangeNode* Index(int);
  448.  
  449. };
  450.  
  451. inline ChangeNode* ChangeList::First () {
  452.     return (ChangeNode*) BaseList::First();
  453. }
  454.  
  455. inline ChangeNode* ChangeList::Last () {
  456.     return (ChangeNode*) BaseList::Last();
  457. }
  458.  
  459. inline ChangeNode* ChangeList::Prev () {
  460.     return (ChangeNode*) BaseList::Prev();
  461. }
  462.  
  463. inline ChangeNode* ChangeList::Next () {
  464.     return (ChangeNode*) BaseList::Next();
  465. }
  466.  
  467. inline ChangeNode* ChangeList::GetCur () {
  468.     return (ChangeNode*) BaseList::GetCur();
  469. }
  470.  
  471. inline ChangeNode* ChangeList::Index (int index) {
  472.     return (ChangeNode*) BaseList::Index(index);
  473. }
  474.  
  475. #endif
  476.