home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TVTOOL.ZIP / SCROLL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-09-15  |  10.5 KB  |  405 lines

  1. program TV_SCROLL_TEST;
  2. {$X+}
  3.  
  4. USES
  5.   TvScroll,
  6.   Objects, Drivers, Views, Menus, Dialogs, App;
  7.  
  8.  
  9. CONST
  10.   cmTestW  = 100;
  11.   cmTestD  = 101;
  12.  
  13.             {         1         2         3         4         5         6         7         8         9         0}
  14.             {1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}
  15.   Line1   = '┌─ These () are Dragable and Resizable, farther down are some input lines. ────┬────┬────┬────┬────┐';
  16.   Line2   = '│    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │';
  17.   Line3   = '├────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┤';
  18.  
  19.  
  20. TYPE
  21.   TMyApp = object(TApplication)
  22.     Constructor Init;
  23.     Procedure   HandleEvent(var Event: TEvent); virtual;
  24.     Procedure   InitMenuBar; virtual;
  25.     Procedure   InitStatusLine; virtual;
  26.     Procedure   TestWindow;
  27.     Procedure   TestDialog;
  28.   end;
  29.  
  30.  
  31.   PMyView1 = ^TMyView1;
  32.   TMyView1 = Object(TView)
  33.     Procedure   Draw;                                               Virtual;
  34.   end;
  35.  
  36.  
  37.   PMyView2 = ^TMyView2;
  38.   TMyView2 = Object(TView)
  39.     Procedure   Draw;                                               Virtual;
  40.   end;
  41.  
  42.  
  43.   PMyView3 = ^TMyView3;
  44.   TMyView3 = Object(TScrollView)
  45.     Procedure   Draw;                                               Virtual;
  46.     Procedure   SizeLimits(var Min, Max : TPoint);                  Virtual;
  47.   end;
  48.  
  49.  
  50. { TMyView3 }
  51. { Scrolling, selectable views }
  52. Procedure TMyView3.Draw;
  53.  
  54.   var
  55.     B : TDrawBuffer;
  56.     C : Word;
  57.  
  58.   begin
  59.     { set colors for the various modes. }
  60.     if (State AND sfDragging <> 0) and (State AND sfSelected <> 0) then
  61.       C := 3
  62.     else if (State AND sfFocused <> 0) then
  63.       C := 2
  64.     else
  65.       C := 1;
  66.  
  67.     MoveChar(B, 'X', GetColor(C), Size.X);
  68.     WriteLine(0, 0, Size.X, Size.Y, B);
  69.   end;
  70.  
  71. Procedure TMyView3.SizeLimits(var Min, Max : TPoint);
  72.   begin
  73.     { only grow in X dimension }
  74.     Min.X := 1;
  75.     Min.Y := 1;
  76.     Max.X := Owner^.Size.X;
  77.     Max.Y := 1;
  78.   end;
  79.  
  80.  
  81. { TMyView2 }
  82. { Scrolling background }
  83. Procedure TMyView2.Draw;
  84.  
  85.   var
  86.     C : Word;
  87.     Y : Word;
  88.     X : Word;
  89.     I : Integer;
  90.     T : String[5];
  91.     S : String;
  92.  
  93.   begin
  94.     if State and sfFocused <> 0 then
  95.       C := $0002
  96.     else
  97.       C := $0001;
  98.  
  99.     { Display the currently visible portion of the background }
  100.     Y := PScrollGroup(Owner)^.VScrollBar^.Value;
  101.     X := PScrollGroup(Owner)^.HScrollBar^.Value + 1;
  102.  
  103.     for I := 0 to Size.Y - 1 do
  104.     begin
  105.       if (Y = 0) then
  106.         S := Copy(Line1, X, Size.X)
  107.       else if (Y MOD 3 = 0) then
  108.         S := Copy(Line3, X, Size.X)
  109.       else
  110.         S := Copy(Line2, X, Size.X);
  111.  
  112.       Inc(Y);
  113.       Str(Y:3, T);
  114.       S[Length(S) - 1] := T[3];
  115.       S[Length(S) - 2] := T[2];
  116.       S[Length(S) - 3] := T[1];
  117.  
  118.       WriteStr(0, I, S, C);
  119.     end;
  120.   end;
  121.  
  122.  
  123. { TMyView1 }
  124. { Scrolling non-selectable views }
  125. Procedure TMyView1.Draw;
  126.  
  127.   var
  128.     B : TDrawBuffer;
  129.     C : Word;
  130.  
  131.   begin
  132.     if State and sfFocused <> 0 then
  133.     begin
  134.       C := $0002;
  135.     end
  136.     else
  137.     begin
  138.       C := $0001;
  139.     end;
  140.  
  141.     MoveChar(B, '*', GetColor(C), Size.X);
  142.     WriteLine(0, 0, Size.X, Size.Y, B);
  143.   end;
  144.  
  145.  
  146. { TMyApp }
  147. Procedure TMyApp.HandleEvent(var Event: TEvent);
  148.   begin
  149.     TApplication.HandleEvent(Event);
  150.  
  151.     if Event.What = evCommand then
  152.     begin
  153.       case Event.Command of
  154.         cmTestW : TestWindow;
  155.         cmTestD : TestDialog;
  156.       else
  157.         Exit;
  158.       end;
  159.  
  160.       ClearEvent(Event);
  161.     end;
  162.   end;
  163.  
  164. Procedure TMyApp.InitMenuBar;
  165.  
  166.   var
  167.     R: TRect;
  168.  
  169.   begin
  170.     GetExtent(R);
  171.     R.B.Y := R.A.Y + 1;
  172.     MenuBar := New(PMenuBar, Init(R, NewMenu(
  173.       NewSubMenu('~T~est', hcNoContext, NewMenu(
  174.         NewItem('Test ~W~indow', 'F4', kbF4, cmTestW, hcNoContext,
  175.         NewItem('Test ~D~ialog', 'F5', kbF4, cmTestD, hcNoContext,
  176.         NewLine(
  177.         NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  178.         nil))))),
  179.       nil))
  180.     ));
  181.   end;
  182.  
  183. Procedure TMyApp.InitStatusLine;
  184.  
  185.   var
  186.     R: TRect;
  187.  
  188.   begin
  189.     GetExtent(R);
  190.     R.A.Y := R.B.Y - 1;
  191.     StatusLine := New(PStatusLine, Init(R,
  192.       NewStatusDef(0, $FFFF,
  193.         NewStatusKey('', kbF10, cmMenu,
  194.         NewStatusKey('~Alt-X~ Exit',      kbAltX, cmQuit,
  195.         NewStatusKey('~F2~ Resize Window',kbF2,   cmResize,
  196.         NewStatusKey('~F3~ Resize Field', kbF3,   cmDragView,
  197.         NewStatusKey('~F4~ New Window',   kbF4,   cmTestW,
  198.         NewStatusKey('~F5~ New Dialog',   kbF5,   cmTestD,
  199.         NewStatusKey('~F6~ Next Window',  kbF6,   cmNext,
  200.         nil))))))),
  201.       nil)
  202.     ));
  203.   end;
  204.  
  205. Procedure TMyApp.TestDialog;
  206.  
  207.   var
  208.     Dlg : PScrollDialog;
  209.     R   : TRect;
  210.     P   : PView;
  211.     i   : Integer;
  212.  
  213.   begin
  214.     R.Assign(0,0,44,19);
  215.     New(Dlg, Init(R, 'Test Dialog'));
  216.  
  217.     with Dlg^ do
  218.     begin
  219.       Options := Options OR ofCentered;
  220.       { Make sure to set the size limits so the scrolling can be controlled. }
  221.       SetLimit(60, 30);
  222.  
  223.       { There should always be some view that will in all situations
  224.         cover the entire window interior in the scrolling group. In general
  225.         this will be the first view, and will probably be all blank. Here,
  226.         we add a standard TView.
  227.       }
  228.       Interior^.GetExtent(R);
  229.       P := New(PView, Init(R));
  230.       { This view should be disabled and non-selectable, and should
  231.         grow with the window.
  232.       }
  233.       P^.SetState(sfDisabled, True);
  234.       P^.Options    := P^.Options AND not ofSelectable;
  235.       InsertToScroll(P);
  236.  
  237.       { add a label }
  238.       { any view can be inserted to scroll, just set the scroll flag }
  239.       R.Assign(10,0,30,1);
  240.       P := New(PStaticText, Init(R, 'Scrolling Data Entry'));
  241.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  242.       InsertToScroll(P);
  243.  
  244.       { add some input lines }
  245.       for i := 1 to 12 do
  246.       begin
  247.         R.Assign(5,i + 1, 20, i + 2);
  248.         P := New(PInputLine, Init(R, 12));
  249.         P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  250.         InsertToScroll(P);
  251.       end;
  252.  
  253.       { add check boxes }
  254.       R.Assign(23,2,34,6);
  255.       P := New(PCheckBoxes, Init(R,
  256.         NewSItem('~O~ne',
  257.         NewSItem('~T~wo',
  258.         NewSItem('Th~r~ee',
  259.         NewSItem('~F~our',Nil))))));
  260.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  261.       PCluster(P)^.Value := 0;
  262.       InsertToScroll(P);
  263.  
  264.       { add radio buttons }
  265.       R.Assign(23,8,34,12);
  266.       P := New(PRadioButtons, Init(R,
  267.         NewSItem('~O~ne',
  268.         NewSItem('~T~wo',
  269.         NewSItem('Th~r~ee',
  270.         NewSItem('~F~our',Nil))))));
  271.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  272.       PCluster(P)^.Value := 0;
  273.       InsertToScroll(P);
  274.  
  275.       { add some more input lines }
  276.       for i := 1 to 12 do
  277.       begin
  278.         R.Assign(38,i + 1, 53, i + 2);
  279.         P := New(PInputLine, Init(R, 12));
  280.         P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  281.         InsertToScroll(P);
  282.       end;
  283.  
  284.       { add more radio buttons }
  285.       R.Assign(23,13,34,17);
  286.       P := New(PRadioButtons, Init(R,
  287.         NewSItem('~O~ne',
  288.         NewSItem('~T~wo',
  289.         NewSItem('Th~r~ee',
  290.         NewSItem('~F~our',Nil))))));
  291.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  292.       PCluster(P)^.Value := 0;
  293.       InsertToScroll(P);
  294.  
  295.       { Add some buttons, these can scroll too, as you see fit.
  296.         It kind of depends on how your dialog box is layed out.
  297.         But make sure to insert them into the scrolling group, not
  298.         directly into the dialog box. If buttons are inserted into
  299.         the dialog and not the scrolling group, the tab order gets
  300.         messed up.
  301.       }
  302.       R.Assign(6,20,14,22);
  303.       P := New(PButton, Init(R, 'O~K~', cmOK, bfDefault));
  304.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  305.       InsertToScroll(P);
  306.  
  307.       R.Assign(26,20,38,22);
  308.       P := New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal));
  309.       P^.GrowMode := P^.GrowMode OR gfGrowXYRel;
  310.       InsertToScroll(P);
  311.  
  312.       Interior^.SelectNext(False);
  313.     end;
  314.  
  315.     Desktop^.ExecView(Dlg);
  316.     Dispose(Dlg, Done);
  317.   end;
  318.  
  319. Procedure TMyApp.TestWindow;
  320.  
  321.  
  322.   var
  323.     Win : PScrollWindow;
  324.     i   : Integer;
  325.     P   : PView;
  326.     R   : TRect;
  327.     S   : PScroller;
  328.  
  329.   begin
  330.     R.Assign(0, 0, 40, 15);
  331.     Win := New(PScrollWindow, Init(R, 'Demo Window', wnNoNumber));
  332.     { Make sure to set the size limits so the scrolling can be controlled. }
  333.     Win^.SetLimit(100,30);
  334.  
  335.     { There should always be some view that will in all situations
  336.       cover the entire window interior in the scrolling group. In general
  337.       this will be the first view, and will probably be all blank. Here,
  338.       we add a special view that will display a background that scrolls
  339.       with the other views. This view could just as well be a standard TView,
  340.       that would by default be empty.
  341.     }
  342.     Win^.Interior^.GetExtent(R);
  343.     P := New(PMyView2, Init(R));
  344.     { This view should be disabled and non-selectable, and should
  345.       grow with the window.
  346.     }
  347.     P^.SetState(sfDisabled, True);
  348.     P^.Options    := P^.Options AND not ofSelectable;
  349.     P^.GrowMode   := P^.GrowMode OR gfGrowHiX OR gfGrowHiY;
  350.     Win^.InsertToScroll(P);
  351.  
  352.  
  353.     { Add some views that scroll, and can be resized and dragged. }
  354.     for i := 1 to 7 do
  355.     begin
  356.       R.Assign(i,i, i + i * 2, i + 1);
  357.       P := New(PMyView3, Init(R));
  358.       Win^.InsertToScroll(P);
  359.     end;
  360.  
  361.     { Add some views that scroll, but cannot be resized or dragged.
  362.       You could also add views that do not scroll at all, just by
  363.       cleared the gfGrowXYRel bit in the GrowMode.
  364.     }
  365.     for i := 1 to 7 do
  366.     begin
  367.       R.Assign(1,i + 9, i * i + 1, i + 10);
  368.       P := New(PMyView1, Init(R));
  369.       P^.GrowMode  := P^.GrowMode OR gfGrowXYRel;
  370.       Win^.InsertToScroll(P);
  371.     end;
  372.  
  373.     { add some scrolling input lines }
  374.     for i := 1 to 2 do
  375.     begin
  376.       R.Assign(1,i + 18, 9, i + 19);
  377.       P := New(PScrollInputLine, Init(R, 6));
  378.       Win^.InsertToScroll(P);
  379.     end;
  380.  
  381.     R.Assign(1,i + 20, 9, i + 21);
  382.     P := New(PScrollInputLine, Init(R, 15));
  383.     Win^.InsertToScroll(P);
  384.  
  385.     { Always insert the window after it is setup, (after first view
  386.       has been inserted) this will avoid some unsightly screen displays on
  387.       slower machines.
  388.     }
  389.     DeskTop^.Insert(Win);
  390.   end;
  391.  
  392. Constructor TMyApp.Init;
  393.   begin
  394.     TApplication.Init;
  395.   end;
  396.  
  397.  
  398. VAR
  399.   MyApp : TMyApp;
  400.  
  401. BEGIN
  402.   MyApp.Init;
  403.   MyApp.Run;
  404.   MyApp.Done;
  405. END.