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.C < prev    next >
C/C++ Source or Header  |  1980-01-05  |  22KB  |  819 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.c,v 1.12 89/10/09 14:48:39 linton Exp $
  24. // implements subclasses of ChangeNode and class ChangeList.
  25.  
  26. #include "drawing.h"
  27. #include "drawingview.h"
  28. #include "listcenter.h"
  29. #include "listchange.h"
  30. #include "listgroup.h"
  31. #include "listibrush.h"
  32. #include "listicolor.h"
  33. #include "listifont.h"
  34. #include "listipattern.h"
  35. #include "listselectn.h"
  36. #include "selection.h"
  37. #include "slpict.h"
  38.  
  39. // ChangeNode creates a dummy ChangeNode object for the header of the
  40. // ChangeList.
  41.  
  42. ChangeNode::ChangeNode () {
  43.     drawing = nil;
  44.     drawingview = nil;
  45.     oldsl = nil;
  46. }
  47.  
  48. // ChangeNode stores the Drawing and DrawingView.  It copies the
  49. // SelectionList, optionally sorting the SelectionList first.
  50.  
  51. ChangeNode::ChangeNode (Drawing* d, DrawingView* dv, boolean sort) {
  52.     drawing = d;
  53.     drawingview = dv;
  54.     if (sort) {
  55.     drawing->Sort();
  56.     }
  57.     oldsl = drawing->GetSelections();
  58. }
  59.  
  60. // Free storage allocated for the list of old Selections.
  61.  
  62. ChangeNode::~ChangeNode () {
  63.     delete oldsl;
  64. }
  65.  
  66. // Do carries out the change to the Drawing.
  67.  
  68. void ChangeNode::Do () {
  69.     // nop
  70. }
  71.  
  72. // Undo removes the change to the Drawing.
  73.  
  74. void ChangeNode::Undo () {
  75.     // nop
  76. }
  77.  
  78. // MoveChange stores the Selections' translation in reversible form.
  79.  
  80. MoveChange::MoveChange (Drawing* d, DrawingView* dv, float xdisp, float ydisp)
  81. : (d, dv) {
  82.     dx = xdisp;
  83.     dy = ydisp;
  84.     undodx = -xdisp;
  85.     undody = -ydisp;
  86. }
  87.  
  88. // Do moves the Selections.
  89.  
  90. void MoveChange::Do () {
  91.     drawingview->EraseExcessHandles(oldsl);
  92.     drawing->Select(oldsl);
  93.     drawingview->Damaged();
  94.     drawing->Move(dx, dy);
  95.     drawingview->Damaged();
  96.     drawingview->Repair();
  97. }
  98.  
  99. // Undo moves the Selections back to their original places.
  100.  
  101. void MoveChange::Undo () {
  102.     drawingview->EraseExcessHandles(oldsl);
  103.     drawing->Select(oldsl);
  104.     drawingview->Damaged();
  105.     drawing->Move(undodx, undody);
  106.     drawingview->Damaged();
  107.     drawingview->Repair();
  108. }
  109.  
  110. // ScaleChange stores the Selections' scaling in reversible form.
  111.  
  112. ScaleChange::ScaleChange (Drawing* d, DrawingView* dv, float xsc, float ysc)
  113. : (d, dv) {
  114.     sx = xsc;
  115.     sy = ysc;
  116.     undosx = 1.0 / xsc;
  117.     undosy = 1.0 / ysc;
  118. }
  119.  
  120. // Do scales the Selections.
  121.  
  122. void ScaleChange::Do () {
  123.     drawingview->EraseExcessHandles(oldsl);
  124.     drawing->Select(oldsl);
  125.     drawingview->Damaged();
  126.     drawing->Scale(sx, sy);
  127.     drawingview->Damaged();
  128.     drawingview->Repair();
  129. }
  130.  
  131. // Undo scales the Selections back to their former sizes.
  132.  
  133. void ScaleChange::Undo () {
  134.     drawingview->EraseExcessHandles(oldsl);
  135.     drawing->Select(oldsl);
  136.     drawingview->Damaged();
  137.     drawing->Scale(undosx, undosy);
  138.     drawingview->Damaged();
  139.     drawingview->Repair();
  140. }
  141.  
  142. // StretchChange stores the Selections' stretching in reversible form.
  143.  
  144. StretchChange::StretchChange (Drawing* d, DrawingView* dv, float str,
  145. Alignment sd) : (d, dv) {
  146.     stretch = str;
  147.     undostretch = 1/str;
  148.     side = sd;
  149.     undoside = (str < 0) ? OppositeSide(sd) : sd;
  150. }
  151.  
  152. // Do stretches the Selections.
  153.  
  154. void StretchChange::Do () {
  155.     drawingview->EraseExcessHandles(oldsl);
  156.     drawing->Select(oldsl);
  157.     drawingview->Damaged();
  158.     drawing->Stretch(stretch, side);
  159.     drawingview->Damaged();
  160.     drawingview->Repair();
  161. }
  162.  
  163. // Undo stretches the Selections back to their former sizes.
  164.  
  165. void StretchChange::Undo () {
  166.     drawingview->EraseExcessHandles(oldsl);
  167.     drawing->Select(oldsl);
  168.     drawingview->Damaged();
  169.     drawing->Stretch(undostretch, undoside);
  170.     drawingview->Damaged();
  171.     drawingview->Repair();
  172. }
  173.  
  174. // OppositeSide returns the side opposite the given side.
  175.  
  176. Alignment StretchChange::OppositeSide (Alignment original) {
  177.     Alignment opposite;
  178.     switch (original) {
  179.     case Left:
  180.     opposite = Right;
  181.     break;
  182.     case Right:
  183.     opposite = Left;
  184.     break;
  185.     case Bottom:
  186.     opposite = Top;
  187.     break;
  188.     case Top:
  189.     opposite = Bottom;
  190.     break;
  191.     }
  192.     return opposite;
  193. }
  194.  
  195. // RotateChange stores the Selections' rotation in reversible form.
  196.  
  197. RotateChange::RotateChange (Drawing* d, DrawingView* dv, float a) : (d, dv) {
  198.     angle = a;
  199.     undoangle = -a;
  200. }
  201.  
  202. // Do rotates the Selections.
  203.  
  204. void RotateChange::Do () {
  205.     drawingview->EraseExcessHandles(oldsl);
  206.     drawing->Select(oldsl);
  207.     drawingview->Damaged();
  208.     drawing->Rotate(angle);
  209.     drawingview->Damaged();
  210.     drawingview->Repair();
  211. }
  212.  
  213. // Undo rotates the Selections back to their original places.
  214.  
  215. void RotateChange::Undo () {
  216.     drawingview->EraseExcessHandles(oldsl);
  217.     drawing->Select(oldsl);
  218.     drawingview->Damaged();
  219.     drawing->Rotate(undoangle);
  220.     drawingview->Damaged();
  221.     drawingview->Repair();
  222. }
  223.  
  224. // Skew comments/code ratio to work around cpp bug
  225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  226. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  227.  
  228. // ReplaceChange stores the replaced and replacing Selections.
  229.  
  230. ReplaceChange::ReplaceChange (Drawing* d, DrawingView* dv, Selection* ee,
  231. Selection* er) : (d, dv) {
  232.     replacee = ee;
  233.     replacer = er;
  234. }
  235.  
  236. // Free storage allocated for the Selection not in the
  237. // Drawing, which always resides in replacer.
  238.  
  239. ReplaceChange::~ReplaceChange () {
  240.     delete replacer;
  241. }
  242.  
  243. // Do swaps the replaced and replacing Selections.
  244.  
  245. void ReplaceChange::Do () {
  246.     drawingview->EraseHandles();
  247.     drawing->Select(replacee);
  248.     drawingview->Damaged();
  249.     drawing->Replace(replacee, replacer);
  250.     drawing->Select(replacer);
  251.     drawingview->Damaged();
  252.     drawingview->Repair();
  253.     Selection* temp = replacer;
  254.     replacer = replacee;
  255.     replacee = temp;
  256. }
  257.  
  258. // Undo unswaps the replaced and replacing Selections.
  259.  
  260. void ReplaceChange::Undo () {
  261.     Do();
  262. }
  263.  
  264. // SetBrushChange stores the Selections' original brushes and the new
  265. // brush to set.
  266.  
  267. SetBrushChange::SetBrushChange (Drawing* d, DrawingView* dv, IBrush* br)
  268. : (d, dv) {
  269.     brush = br;
  270.     undobrushlist = drawing->GetBrush();
  271. }
  272.  
  273. // Free storage allocated for the list of original brushes.
  274.  
  275. SetBrushChange::~SetBrushChange () {
  276.     delete undobrushlist;
  277. }
  278.  
  279. // Do sets the Selections' new brush.
  280.  
  281. void SetBrushChange::Do () {
  282.     drawingview->EraseExcessHandles(oldsl);
  283.     drawing->Select(oldsl);
  284.     drawingview->Damaged();
  285.     drawing->SetBrush(brush);
  286.     drawingview->Damaged();
  287.     drawingview->Repair();
  288. }
  289.  
  290. // Undo restores the Selections' original brushes.
  291.  
  292. void SetBrushChange::Undo () {
  293.     drawingview->EraseExcessHandles(oldsl);
  294.     drawing->Select(oldsl);
  295.     drawingview->Damaged();
  296.     drawing->SetBrush(undobrushlist);
  297.     drawingview->Damaged();
  298.     drawingview->Repair();
  299. }
  300.  
  301. // SetFgColorChange stores the Selections' original foreground colors
  302. // and the new foreground color to set.
  303.  
  304. SetFgColorChange::SetFgColorChange (Drawing* d, DrawingView* dv, IColor* fg)
  305. : (d, dv) {
  306.     fgcolor = fg;
  307.     undofglist = drawing->GetFgColor();
  308. }
  309.  
  310. // Free storage allocated for the list of original colors.
  311.  
  312. SetFgColorChange::~SetFgColorChange () {
  313.     delete undofglist;
  314. }
  315.  
  316. // Do sets the Selections' new foreground color.
  317.  
  318. void SetFgColorChange::Do () {
  319.     drawingview->EraseExcessHandles(oldsl);
  320.     drawing->Select(oldsl);
  321.     drawingview->Damaged();
  322.     drawing->SetFgColor(fgcolor);
  323.     drawingview->Damaged();
  324.     drawingview->Repair();
  325. }
  326.  
  327. // Undo restores the Selections' original foreground colors.
  328.  
  329. void SetFgColorChange::Undo () {
  330.     drawingview->EraseExcessHandles(oldsl);
  331.     drawing->Select(oldsl);
  332.     drawingview->Damaged();
  333.     drawing->SetFgColor(undofglist);
  334.     drawingview->Damaged();
  335.     drawingview->Repair();
  336. }
  337.  
  338. // Skew comments/code ratio to work around cpp bug
  339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  340.  
  341. // SetBgColorChange stores the Selections' original background colors
  342. // and the new background color to set.
  343.  
  344. SetBgColorChange::SetBgColorChange (Drawing* d, DrawingView* dv, IColor* bg)
  345. : (d, dv) {
  346.     bgcolor = bg;
  347.     undobglist = drawing->GetBgColor();
  348. }
  349.  
  350. // Free storage allocated for the list of original colors.
  351.  
  352. SetBgColorChange::~SetBgColorChange () {
  353.     delete undobglist;
  354. }
  355.  
  356. // Do sets the Selections' new background color.
  357.  
  358. void SetBgColorChange::Do () {
  359.     drawingview->EraseExcessHandles(oldsl);
  360.     drawing->Select(oldsl);
  361.     drawingview->Damaged();
  362.     drawing->SetBgColor(bgcolor);
  363.     drawingview->Damaged();
  364.     drawingview->Repair();
  365. }
  366.  
  367. // Undo restores the Selections' original background colors.
  368.  
  369. void SetBgColorChange::Undo () {
  370.     drawingview->EraseExcessHandles(oldsl);
  371.     drawing->Select(oldsl);
  372.     drawingview->Damaged();
  373.     drawing->SetBgColor(undobglist);
  374.     drawingview->Damaged();
  375.     drawingview->Repair();
  376. }
  377.  
  378. // SetFontChange stores the Selections' original fonts and
  379. // the new font to set.
  380.  
  381. SetFontChange::SetFontChange (Drawing* d, DrawingView* dv, IFont* f)
  382. : (d, dv) {
  383.     font = f;
  384.     undofontlist = drawing->GetFont();
  385. }
  386.  
  387. // Free storage allocated for the list of original fonts.
  388.  
  389. SetFontChange::~SetFontChange () {
  390.     delete undofontlist;
  391. }
  392.  
  393. // Do sets the Selections' new font.
  394.  
  395. void SetFontChange::Do () {
  396.     drawingview->EraseExcessHandles(oldsl);
  397.     drawing->Select(oldsl);
  398.     drawingview->Damaged();
  399.     drawing->SetFont(font);
  400.     drawingview->Damaged();
  401.     drawingview->Repair();
  402. }
  403.  
  404. // Undo restores the Selections' original fonts.
  405.  
  406. void SetFontChange::Undo () {
  407.     drawingview->EraseExcessHandles(oldsl);
  408.     drawing->Select(oldsl);
  409.     drawingview->Damaged();
  410.     drawing->SetFont(undofontlist);
  411.     drawingview->Damaged();
  412.     drawingview->Repair();
  413. }
  414.  
  415. // SetPatternChange stores the Selections' original patterns and the
  416. // new pattern to set.
  417.  
  418. SetPatternChange::SetPatternChange (Drawing* d, DrawingView* dv, IPattern* pat)
  419. : (d, dv) {
  420.     pattern = pat;
  421.     undopatternlist = drawing->GetPattern();
  422. }
  423.  
  424. // Free storage allocated for the list of original patterns.
  425.  
  426. SetPatternChange::~SetPatternChange () {
  427.     delete undopatternlist;
  428. }
  429.  
  430. // Do sets the Selections' new pattern.
  431.  
  432. void SetPatternChange::Do () {
  433.     drawingview->EraseExcessHandles(oldsl);
  434.     drawing->Select(oldsl);
  435.     drawing->SetPattern(pattern);
  436.     drawingview->Damaged();
  437.     drawingview->Repair();
  438. }
  439.  
  440. // Undo restores the Selections' original patterns.
  441.  
  442. void SetPatternChange::Undo () {
  443.     drawingview->EraseExcessHandles(oldsl);
  444.     drawing->Select(oldsl);
  445.     drawing->SetPattern(undopatternlist);
  446.     drawingview->Damaged();
  447.     drawingview->Repair();
  448. }
  449.  
  450. // AddChange knows it hasn't done its change yet.
  451.  
  452. AddChange::AddChange (Drawing* d, DrawingView* dv) : (d, dv) {
  453.     done = false;
  454. }
  455.  
  456. // Free storage allocated for the Selections if AddChange
  457. // never added them to the Drawing.
  458.  
  459. AddChange::~AddChange () {
  460.     if (!done) {
  461.     for (oldsl->First(); !oldsl->AtEnd(); oldsl->Next()) {
  462.         Selection* s = oldsl->GetCur()->GetSelection();
  463.         delete s;
  464.     }
  465.     }
  466. }
  467.  
  468. // Do appends the Selections to the Drawing.
  469.  
  470. void AddChange::Do () {
  471.     drawingview->EraseHandles();
  472.     drawing->Select(oldsl);
  473.     drawing->Append();
  474.     drawingview->Added();
  475.     drawingview->Repair();
  476.     done = true;
  477. }
  478.  
  479. // Undo removes the Selections from the Drawing.
  480.  
  481. void AddChange::Undo () {
  482.     drawingview->EraseExcessHandles(oldsl);
  483.     drawing->Select(oldsl);
  484.     drawingview->Damaged();
  485.     drawing->Remove();
  486.     drawing->Clear();
  487.     drawingview->Repair();
  488.     done = false;
  489. }
  490.  
  491. // DeleteChange stores the Selections' predecessors.
  492.  
  493. DeleteChange::DeleteChange (Drawing* d, DrawingView* dv) : (d, dv, true) {
  494.     prevlist = drawing->GetPrevs();
  495.     done = false;
  496. }
  497.  
  498. // Free storage allocated for the Selections if DeleteChange
  499. // removed them from the Drawing.
  500.  
  501. DeleteChange::~DeleteChange () {
  502.     delete prevlist;
  503.     if (done) {
  504.     for (oldsl->First(); !oldsl->AtEnd(); oldsl->Next()) {
  505.         Selection* s = oldsl->GetCur()->GetSelection();
  506.         delete s;
  507.     }
  508.     }
  509. }
  510.  
  511. // Do removes the Selections from the Drawing.
  512.  
  513. void DeleteChange::Do () {
  514.     drawingview->EraseExcessHandles(oldsl);
  515.     drawing->Select(oldsl);
  516.     drawingview->Damaged();
  517.     drawing->Remove();
  518.     drawing->Clear();
  519.     drawingview->Repair();
  520.     done = true;
  521. }
  522.  
  523. // Undo puts the Selections back where they came from in the Drawing.
  524.  
  525. void DeleteChange::Undo () {
  526.     drawingview->EraseExcessHandles(oldsl);
  527.     drawing->Select(oldsl);
  528.     drawing->InsertAfterPrev(prevlist);
  529.     drawingview->Damaged();
  530.     drawingview->Repair();
  531.     done = false;
  532. }
  533.  
  534. // CutChange passes its arguments to its DeleteChange constructor.
  535.  
  536. CutChange::CutChange (Drawing* d, DrawingView* dv) : (d, dv) {
  537. }
  538.  
  539. // Do removes the Selections from the Drawing and writes them to the
  540. // clipboard file, overwriting the clipboard file's previous contents.
  541.  
  542. void CutChange::Do () {
  543.     drawingview->EraseExcessHandles(oldsl);
  544.     drawing->Select(oldsl);
  545.     drawing->WriteClipboard();
  546.     DeleteChange::Do();
  547. }
  548.  
  549. // CopyChange must sort the Selections.
  550.  
  551. CopyChange::CopyChange (Drawing* d, DrawingView* dv) : (d, dv, true) {
  552. }
  553.  
  554. // Do writes the Selections to the clipboard file, overwriting
  555. // whatever was there previously.
  556.  
  557. void CopyChange::Do () {
  558.     drawingview->EraseExcessHandles(oldsl);
  559.     drawing->Select(oldsl);
  560.     drawing->WriteClipboard();
  561. }
  562.  
  563. // PasteChange reads the clipboard file and stores the clippings for
  564. // pasting into the Drawing later.
  565.  
  566. PasteChange::PasteChange (Drawing* d, DrawingView* dv, State* state)
  567. : (d, dv) {
  568.     delete oldsl;
  569.     oldsl = drawing->ReadClipboard(state);
  570. }
  571.  
  572. // DuplicateChange stores duplicates of the picked Selections for
  573. // pasting into the Drawing later.
  574.  
  575. DuplicateChange::DuplicateChange (Drawing* d, DrawingView* dv) : (d, dv) {
  576.     drawing->Sort();
  577.     delete oldsl;
  578.     oldsl = drawing->GetDuplicates();
  579. }
  580.  
  581. // GroupChange stores the Selections' new parent and their
  582. // predecessors.
  583.  
  584. GroupChange::GroupChange (Drawing* d, DrawingView* dv) : (d, dv, true) {
  585.     grouplist = drawing->GetParent();
  586.     prevlist = drawing->GetPrevs();
  587.     done = false;
  588. }
  589.  
  590. // Delete frees storage allocated for the Selections' new parent if
  591. // they never end up grouped under it and the lists themselves.
  592.  
  593. GroupChange::~GroupChange () {
  594.     if (!done) {
  595.     for (grouplist->First(); !grouplist->AtEnd(); grouplist->Next()) {
  596.         PictSelection* s = grouplist->GetCur()->GetParent();
  597.         delete s;
  598.     }
  599.     }
  600.     delete grouplist;
  601.     delete prevlist;
  602. }
  603.  
  604. // Do groups the Selections under their parent.
  605.  
  606. void GroupChange::Do () {
  607.     drawingview->EraseHandles();
  608.     drawing->Group(grouplist);
  609.     drawingview->Damaged();
  610.     drawingview->Repair();
  611.     done = true;
  612. }
  613.  
  614. // Undo ungroups the Selections and puts them back where they came
  615. // from in the Drawing.
  616.  
  617. void GroupChange::Undo () {
  618.     drawingview->EraseHandles();
  619.     drawing->Ungroup(grouplist);
  620.     drawing->Remove();
  621.     drawing->InsertAfterPrev(prevlist);
  622.     drawingview->Damaged();
  623.     drawingview->Repair();
  624.     done = false;
  625. }
  626.  
  627. // UngroupChange stores the Selections' children.
  628.  
  629. UngroupChange::UngroupChange (Drawing* d, DrawingView* dv) : (d, dv, true) {
  630.     undogrouplist = drawing->GetChildren();
  631.     done = false;
  632. }
  633.  
  634. // Delete frees storage allocated for the Selections if they were
  635. // ungrouped and for the list itself.
  636.  
  637. UngroupChange::~UngroupChange () {
  638.     if (done) {
  639.     for (undogrouplist->First(); !undogrouplist->AtEnd();
  640.          undogrouplist->Next())
  641.     {
  642.         boolean haschildren = undogrouplist->GetCur()->GetHasChildren();
  643.         if (haschildren) {
  644.         PictSelection* s = undogrouplist->GetCur()->GetParent();
  645.         delete s;
  646.         }
  647.     }
  648.     }
  649.     delete undogrouplist;
  650. }
  651.  
  652. // Do replaces all Selections which contain children with their
  653. // children.
  654.  
  655. void UngroupChange::Do () {
  656.     drawingview->EraseHandles();
  657.     drawing->Ungroup(undogrouplist);
  658.     drawingview->RedrawHandles();
  659.     done = true;
  660. }
  661.  
  662. // Undo regroups each set of children under their former parents.
  663.  
  664. void UngroupChange::Undo () {
  665.     drawingview->EraseHandles();
  666.     drawing->Group(undogrouplist);
  667.     drawingview->RedrawHandles();
  668.     done = false;
  669. }
  670.  
  671. // Skew comments/code ratio to work around cpp bug
  672. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  673. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  674.  
  675. // BringToFrontChange stores the Selections' predecessors.
  676.  
  677. BringToFrontChange::BringToFrontChange (Drawing* d, DrawingView* dv)
  678. : (d, dv, true) {
  679.     prevlist = drawing->GetPrevs();
  680. }
  681.  
  682. // Delete frees storage allocated for the Selections' predecessors.
  683.  
  684. BringToFrontChange::~BringToFrontChange () {
  685.     delete prevlist;
  686. }
  687.  
  688. // Do brings the Selections to the front by removing them from and
  689. // appending them to the Drawing.
  690.  
  691. void BringToFrontChange::Do () {
  692.     drawingview->EraseHandles();
  693.     drawing->Select(oldsl);
  694.     drawing->Remove();
  695.     drawing->Append();
  696.     drawingview->Added();
  697.     drawingview->Repair();
  698. }
  699.  
  700. // Undo puts the Selections back where they came from in the Drawing.
  701.  
  702. void BringToFrontChange::Undo () {
  703.     drawingview->EraseExcessHandles(oldsl);
  704.     drawing->Select(oldsl);
  705.     drawing->Remove();
  706.     drawing->InsertAfterPrev(prevlist);
  707.     drawingview->Damaged();
  708.     drawingview->Repair();
  709. }
  710.  
  711. // SendToBackChange stores the Selections' predecessors.
  712.  
  713. SendToBackChange::SendToBackChange (Drawing* d, DrawingView* dv)
  714. : (d, dv, true) {
  715.     prevlist = drawing->GetPrevs();
  716. }
  717.  
  718. // Delete frees storage allocated for the Selections' predecessors.
  719.  
  720. SendToBackChange::~SendToBackChange () {
  721.     delete prevlist;
  722. }
  723.  
  724. // Do sends the Selections to the back by removing them from and
  725. // prepending them to the Drawing.
  726.  
  727. void SendToBackChange::Do () {
  728.     drawingview->EraseExcessHandles(oldsl);
  729.     drawing->Select(oldsl);
  730.     drawing->Remove();
  731.     drawing->Prepend();
  732.     drawingview->Damaged();
  733.     drawingview->Repair();
  734. }
  735.  
  736. // Undo puts the Selections back where they came from in the Drawing.
  737.  
  738. void SendToBackChange::Undo () {
  739.     drawingview->EraseExcessHandles(oldsl);
  740.     drawing->Select(oldsl);
  741.     drawing->Remove();
  742.     drawing->InsertAfterPrev(prevlist);
  743.     drawingview->Damaged();
  744.     drawingview->Repair();
  745. }
  746.  
  747. // AlignChange stores the Selections' original positions and their
  748. // desired alignments.
  749.  
  750. AlignChange::AlignChange (Drawing* d, DrawingView* dv, Alignment fix,
  751. Alignment move) : (d, dv) {
  752.     falign = fix;
  753.     malign = move;
  754.     centerlist = drawing->GetCenter();
  755. }
  756.  
  757. // Delete frees storage allocated for the list of original positions.
  758.  
  759. AlignChange::~AlignChange () {
  760.     delete centerlist;
  761. }
  762.  
  763. // Do aligns the Selections.
  764.  
  765. void AlignChange::Do () {
  766.     drawingview->EraseExcessHandles(oldsl);
  767.     drawing->Select(oldsl);
  768.     drawingview->Damaged();
  769.     drawing->Align(falign, malign);
  770.     drawingview->Damaged();
  771.     drawingview->Repair();
  772. }
  773.  
  774. // Undo moves the Selections to their original positions.
  775.  
  776. void AlignChange::Undo () {
  777.     drawingview->EraseExcessHandles(oldsl);
  778.     drawing->Select(oldsl);
  779.     drawingview->Damaged();
  780.     drawing->SetCenter(centerlist);
  781.     drawingview->Damaged();
  782.     drawingview->Repair();
  783. }
  784.  
  785. // AlignToGridChange stores the Selections' original positions.
  786.  
  787. AlignToGridChange::AlignToGridChange (Drawing* d, DrawingView* dv) : (d, dv) {
  788.     centerlist = drawing->GetCenter();
  789. }
  790.  
  791. // Delete frees storage allocated for the list of original positions.
  792.  
  793. AlignToGridChange::~AlignToGridChange () {
  794.     delete centerlist;
  795. }
  796.  
  797. // Do aligns the Selections' lower left corners to the nearest grid
  798. // point.
  799.  
  800. void AlignToGridChange::Do () {
  801.     drawingview->EraseExcessHandles(oldsl);
  802.     drawing->Select(oldsl);
  803.     drawingview->Damaged();
  804.     drawing->AlignToGrid();
  805.     drawingview->Damaged();
  806.     drawingview->Repair();
  807. }
  808.  
  809. // Undo moves the Selections to their original positions.
  810.  
  811. void AlignToGridChange::Undo () {
  812.     drawingview->EraseExcessHandles(oldsl);
  813.     drawing->Select(oldsl);
  814.     drawingview->Damaged();
  815.     drawing->SetCenter(centerlist);
  816.     drawingview->Damaged();
  817.     drawingview->Repair();
  818. }
  819.