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 / SQUARES / METAVIEW.C < prev    next >
C/C++ Source or Header  |  1992-02-05  |  10KB  |  364 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. /*
  24.  * Implementation of squares metaview.
  25.  */
  26.  
  27. #include "metaview.h"
  28. #include <InterViews/border.h>
  29. #include <InterViews/box.h>
  30. #include <InterViews/button.h>
  31. #include <InterViews/deck.h>
  32. #include <InterViews/event.h>
  33. #include <InterViews/frame.h>
  34. #include <InterViews/glue.h>
  35. #include <InterViews/message.h>
  36. #include <InterViews/paint.h>
  37. #include <InterViews/painter.h>
  38. #include <InterViews/tray.h>
  39. #include <InterViews/world.h>
  40.  
  41. class Builder {
  42. public:
  43.     Builder(SquaresMetaView*);
  44. private:
  45.     friend class SquaresMetaView;
  46.  
  47.     SquaresMetaView* meta;
  48.     Button* accept, * cancel;
  49.     Button* scrollers, * panner;
  50.     Button* small, * medium, * large;
  51.     Button* below, * above;
  52.     Button* right, * left;
  53.     Button* bottomright;
  54.     Button* bottomleft;
  55.     Button* topright;
  56.     Button* topleft;
  57.     Button* horizontal;
  58.     Button* vertical;
  59.  
  60.     Interactor* Body();
  61.     Interactor* Title();
  62.     Interactor* TypeLabel();
  63.     Interactor* Types();
  64.     Interactor* SizeLabel();
  65.     Interactor* Sizes();
  66.  
  67.     Interactor* Controls();
  68.     Interactor* TypeSizeControls();
  69.     Interactor* ScrollerPositionControls();
  70.     Interactor* PannerPositionControls();
  71.  
  72.     Interactor* ScrollerLabel();
  73.     Interactor* PannerLabel();
  74.     Interactor* HScrollerPositions();
  75.     Interactor* VScrollerPositions();
  76. };
  77.  
  78. SquaresMetaView::SquaresMetaView () {
  79.     type = AdjustByScrollers;
  80.     size = Medium;
  81.     right = true;
  82.     below = true;
  83.     align = BottomRight;
  84.     hscroll = true;
  85.     vscroll = true;
  86.     Init();
  87. }
  88.  
  89. SquaresMetaView::SquaresMetaView (SquaresMetaView* m) {
  90.     type = m->type;
  91.     size = m->size;
  92.     right = m->right;
  93.     below = m->below;
  94.     align = m->align;
  95.     hscroll = m->hscroll;
  96.     vscroll = m->vscroll;
  97.     Init();
  98. }
  99.  
  100. void SquaresMetaView::Init () {
  101.     deck = new Deck;
  102.     typeButton = new ButtonState;
  103.     sizeButton = new ButtonState;
  104.     rightButton = new ButtonState;
  105.     belowButton = new ButtonState;
  106.     alignButton = new ButtonState;
  107.     hscrollButton = new ButtonState;
  108.     vscrollButton = new ButtonState;
  109.     accept = new ButtonState;
  110.     Make();
  111. }
  112.  
  113. SquaresMetaView::~SquaresMetaView () {
  114.     Unref(typeButton);
  115.     Unref(sizeButton);
  116.     Unref(rightButton);
  117.     Unref(belowButton);
  118.     Unref(alignButton);
  119.     Unref(hscrollButton);
  120.     Unref(vscrollButton);
  121.     Unref(accept);
  122. }
  123.  
  124. boolean SquaresMetaView::Popup (Event& e) {
  125.     World* w;
  126.     Coord wx, wy;
  127.     int status;
  128.  
  129.     typeButton->SetValue(type);
  130.     sizeButton->SetValue(size);
  131.     rightButton->SetValue(right);
  132.     belowButton->SetValue(below);
  133.     alignButton->SetValue(align);
  134.     hscrollButton->SetValue(hscroll);
  135.     vscrollButton->SetValue(vscroll);
  136.     accept->SetValue(0);
  137.  
  138.     e.GetAbsolute(w, wx, wy);
  139.     w->InsertToplevel(this, e.target);
  140.     do {
  141.         Read(e);
  142.         if (e.eventType == KeyEvent || e.eventType == DownEvent) {
  143.             Root()->Raise(this);
  144.         }
  145.         e.target->Handle(e);
  146.         typeButton->GetValue(status);
  147.         deck->FlipTo((status == AdjustByScrollers) ? 1 : 2);
  148.         accept->GetValue(status);
  149.     } while (status == 0 && e.target != nil);
  150.     w->Remove(this);
  151.  
  152.     if (status == 1) {
  153.     int v;
  154.  
  155.         typeButton->GetValue(v); type = v;
  156.         sizeButton->GetValue(v); size = v;
  157.         rightButton->GetValue(v); right = v;
  158.         belowButton->GetValue(v); below = v;
  159.         alignButton->GetValue(v); align = v;
  160.         vscrollButton->GetValue(v); vscroll = v;
  161.         hscrollButton->GetValue(v); hscroll = v;
  162.     return true;
  163.     }
  164.     return false;
  165. }
  166.  
  167. void SquaresMetaView::Make () {
  168.     register Builder* b = new Builder(this);
  169.  
  170.     b->accept = new PushButton("Accept", accept, 1);
  171.     b->cancel = new PushButton("Cancel", accept, -1);
  172.  
  173.     b->scrollers = new RadioButton("scrollers", typeButton, AdjustByScrollers);
  174.     b->panner = new RadioButton("panner", typeButton, AdjustByPanner);
  175.  
  176.     b->small = new RadioButton("small", sizeButton, Small);
  177.     b->medium = new RadioButton("medium", sizeButton, Medium);
  178.     b->large = new RadioButton("large", sizeButton, Large);
  179.  
  180.     b->below = new RadioButton("below", belowButton, true);
  181.     b->above = new RadioButton("above", belowButton, (int)false);
  182.     b->right = new RadioButton("right", rightButton, true);
  183.     b->left = new RadioButton("left", rightButton, (int)false);
  184.  
  185.     b->bottomright = new RadioButton("bottom right", alignButton, BottomRight);
  186.     b->bottomleft = new RadioButton("bottom left", alignButton, BottomLeft);
  187.     b->topright = new RadioButton("top right", alignButton, TopRight);
  188.     b->topleft = new RadioButton("top left", alignButton, (int)TopLeft);
  189.  
  190.     b->horizontal = new CheckBox("Horizontal", hscrollButton, true, false);
  191.     b->vertical = new CheckBox("Vertical", vscrollButton, true, false);
  192.  
  193.     b->horizontal->Attach(b->below);
  194.     b->horizontal->Attach(b->above);
  195.     b->vertical->Attach(b->left);
  196.     b->vertical->Attach(b->right);
  197.  
  198.     Insert(new Frame("dialog", b->Body()));
  199.     delete b;
  200. }
  201.  
  202. Builder::Builder (SquaresMetaView* m) {
  203.     meta = m;
  204. }
  205.  
  206. inline int spc (int n = 1) { return n * round(.25*cm); }
  207. inline HGlue* hspc (int n = 1) { return new HGlue(spc(n), spc(n), spc(2*n)); }
  208. inline VGlue* vspc (int n = 1) { return new VGlue(spc(n), spc(n), spc(2*n)); }
  209.  
  210. inline int gap (int n = 1) { return n * round(1*cm); }
  211. inline HGlue* hgap (int n = 1) { return new HGlue(gap(n), gap(n), gap(2*n)); }
  212. inline VGlue* vgap (int n = 1) { return new VGlue(gap(n), gap(n), gap(2*n)); }
  213.  
  214. Interactor* Builder::Body () {
  215.     return new HBox(
  216.     new HGlue(gap(), gap(), hfil),
  217.     new VBox(
  218.         new VGlue(gap(), gap(), vfil),
  219.         Title(),
  220.         new VGlue(spc(2), spc(2), 0),
  221.         Controls(),
  222.         new VGlue(gap(), gap(), vfil)
  223.     ),
  224.     new HGlue(gap(), gap(), hfil)
  225.     );
  226. }
  227.  
  228. Interactor* Builder::Controls () {
  229.     meta->deck->Insert(ScrollerPositionControls());
  230.     meta->deck->Insert(PannerPositionControls());
  231.  
  232.     return new VBox(
  233.     TypeSizeControls(),
  234.     new VGlue(spc(), spc(), 0),
  235.     meta->deck
  236.     );
  237. }
  238.  
  239. Interactor* Builder::TypeSizeControls () {
  240.     Tray* t = new Tray;
  241.     Interactor* typeLabel = TypeLabel();
  242.     Interactor* types = Types();
  243.     Interactor* sizeLabel = SizeLabel();
  244.     Interactor* sizes = Sizes();
  245.     
  246.     t->HBox(t, typeLabel, hgap(), types, new HGlue, t);
  247.     t->HBox(t, sizeLabel, hgap(), sizes, new HGlue, t);
  248.     t->Align(Left, types, sizes);
  249.  
  250.     t->VBox(t, typeLabel, vspc(), sizeLabel, t);
  251.     t->Align(VertCenter, typeLabel, types);
  252.     t->Align(VertCenter, sizeLabel, sizes);
  253.  
  254.     return t;
  255. }
  256.  
  257. Interactor* Builder::ScrollerPositionControls () {
  258.     Tray* t = new Tray;
  259.     Interactor* scrollerLabel = ScrollerLabel();
  260.     Interactor* hscrollerPositions = HScrollerPositions();
  261.     Interactor* vscrollerPositions = VScrollerPositions();
  262.     
  263.     t->HBox(t, scrollerLabel);
  264.     t->HBox(t, hspc(2), horizontal, hspc(2), hscrollerPositions, new HGlue, t);
  265.     t->HBox(t, hspc(2), vertical, hspc(2), vscrollerPositions, new HGlue, t);
  266.     t->Align(Left, horizontal, vertical);
  267.     t->Align(Left, hscrollerPositions, vscrollerPositions);
  268.  
  269.     t->VBox(t, scrollerLabel, vspc(), horizontal, vspc(), vertical, t);
  270.     t->Align(VertCenter, horizontal, hscrollerPositions);
  271.     t->Align(VertCenter, vertical, vscrollerPositions);
  272.     
  273.     return t;
  274. }
  275.  
  276. Interactor* Builder::PannerPositionControls () {
  277.     Tray* t = new Tray;
  278.     Interactor* pannerLabel = PannerLabel();
  279.  
  280.     t->HBox(t, pannerLabel);
  281.     t->HBox(t, hspc(2), topleft, hspc(), topright, new HGlue, t);
  282.     t->HBox(t, hspc(2), bottomleft, hspc(), bottomright, new HGlue, t);
  283.     t->Align(Left, topleft, bottomleft);
  284.     t->Align(Left, topright, bottomright);
  285.  
  286.     t->VBox(t, pannerLabel, vspc(), topleft, vspc(), bottomleft, t);
  287.     t->Align(VertCenter, topleft, topright);
  288.     t->Align(VertCenter, bottomleft, bottomright);
  289.     
  290.     return t;
  291. }
  292.  
  293. Interactor* Builder::Title () {
  294.     return new HBox(
  295.      new VBox(
  296.         new VGlue,
  297.         new HBox(
  298.         new Message("MetaViewTitle", "Squares Frame Setup"),
  299.         new HGlue
  300.         ),
  301.         new VGlue,
  302.         new HBorder,
  303.         new VGlue(2, 0),
  304.         new HBorder
  305.     ),
  306.     new HGlue(spc(), 0),
  307.     new VBox(
  308.         accept,
  309.         new VGlue(spc(), spc(), 0),
  310.         cancel
  311.     )
  312.     );
  313. }
  314.  
  315. Interactor* Builder::TypeLabel () {
  316.     return new Message("Adjuster type:");
  317. }
  318.  
  319. Interactor* Builder::Types () {
  320.     return new HBox(
  321.     scrollers,
  322.     new HGlue(spc(), spc(), 0),
  323.     panner
  324.     );
  325. }
  326.  
  327. Interactor* Builder::SizeLabel () {
  328.     return new Message("Adjuster size:");
  329. }
  330.  
  331. Interactor* Builder::Sizes () {
  332.     return new HBox(
  333.     small,
  334.     new HGlue(spc(), spc(), 0),
  335.     medium,
  336.     new HGlue(spc(), spc(), 0),
  337.     large
  338.     );
  339. }
  340.  
  341. Interactor* Builder::ScrollerLabel () {
  342.     return new Message("Scroller positions:");
  343. }
  344.  
  345. Interactor* Builder::PannerLabel () {
  346.     return new Message("Panner position:");
  347. }
  348.  
  349. Interactor* Builder::HScrollerPositions () {
  350.     return new HBox(
  351.     above,
  352.     new HGlue(spc(), spc(), 0),
  353.     below
  354.     );
  355. }
  356.  
  357. Interactor* Builder::VScrollerPositions () {
  358.     return new HBox(
  359.     left,
  360.     new HGlue(spc(), spc(), 0),
  361.     right
  362.     );
  363. }
  364.