home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TVTOOL.ZIP / DEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-07  |  26.5 KB  |  984 lines

  1. {*
  2. *   Demo.pas
  3. *
  4. *   A demo of TV TOOLS.
  5. *
  6. *   Copyright 1992 by Richard W. Hansen
  7. *
  8. *}
  9.  
  10. program TV;
  11. {$F-}
  12. {$X+}
  13. {$V-}
  14. {$S-}
  15. {$R-}
  16.  
  17. {$I TVDEFS.INC}
  18.  
  19. uses
  20.   Crt, Dos,
  21.   Objects, Drivers, Views, Menus, Dialogs, App, MsgBox, StdDlg,
  22.   TvApp, TvConst, TvMenus, TvViews, TvDialog, TvInput;
  23.  
  24. const
  25.   MaxLines          = 600;
  26.  
  27.   cmFileOpen        = 100;
  28.   cmNewText         = 101;
  29.   cmNewWin          = 102;
  30.   cmNewFormatText   = 103;
  31.   cmNewAsciiHex     = 104;
  32.   cmNewDialog       = 105;
  33.   cmNewEditLine     = 106;
  34.   cmAbout           = 107;
  35.   cmSetup           = 108;
  36.   cmTestPct         = 109;
  37.   cmTestPrt         = 110;
  38.   cmTestList        = 111;
  39.   cmTestWrite       = 112;
  40.   cmTestBtn         = 113;
  41.   cmTool1           = 1000;
  42.   cmTool2           = cmTool1 + 1;
  43.   cmTool3           = cmtool2 + 1;
  44.   cmTool4           = cmTool3 + 1;
  45.   cmTool5           = cmTool4 + 1;
  46.   cmTool6           = cmTool5 + 1;
  47.   cmTool7           = cmTool6 + 1;
  48.   cmItem1           = cmMarkStart;
  49.   cmItem2           = cmItem1 + 1;
  50.   cmItem3           = cmItem2 + 1;
  51.   cmItem4           = cmItem3 + 1;
  52.  
  53.   WinCount          : Integer =   0;
  54.  
  55.  
  56. var
  57.   LineCount : Integer;
  58.   Lines     : array[0..MaxLines - 1] of PString;
  59.   Buf       : Array[0..16383] of Char;
  60.   BufSize   : Word;
  61.   BufName   : PathStr;
  62.  
  63.  
  64. type
  65.   TMyApp = object(TNewApplication)
  66.     Constructor Init;
  67.     Procedure   HandleEvent(var Event: TEvent); virtual;
  68.     Procedure   InitMenuBar; virtual;
  69.     Procedure   InitStatusLine; virtual;
  70.     Procedure   NewDialog;
  71.     Procedure   NewWindow;
  72.     Procedure   NewText;
  73.     Procedure   NewFormatText;
  74.     Procedure   NewAsciiHex;
  75.     Procedure   NewEditLine;
  76.     Procedure   OpenFile;
  77.     Procedure   ReadFile(FileToRead : PathStr);
  78.     Procedure   Setup;
  79.     Procedure   About;
  80.     Procedure   PercentTest;
  81.     Procedure   PrintTest;
  82.     Procedure   ListTest;
  83.     Procedure   WritelnText;
  84.     Procedure   Test3D;
  85.     Procedure   InitDeskTop; virtual;
  86.   end;
  87.  
  88.  
  89.   PInterior = ^TInterior;
  90.   TInterior = object(TScroller)
  91.     constructor Init(var Bounds: TRect; AHScrollBar,
  92.       AVScrollBar: PScrollBar);
  93.     procedure Draw; virtual;
  94.   end;
  95.  
  96.  
  97.   PDemoWindow = ^TDemoWindow;
  98.   TDemoWindow = object(TNewWindow)
  99.     Interior: PInterior;
  100.     constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  101.     function MakeInterior(Bounds: TRect): PInterior;
  102.   end;
  103.  
  104.   PPctDialog  = ^TPctDialog;
  105.   TPctDialog  = Object(TPercentDialog)
  106.     Procedure   Process;                                Virtual;
  107.   end;
  108.  
  109.  
  110.   PPrtDialog  = ^TPrtDialog;
  111.   TPrtDialog  = Object(TPrintDialog)
  112.     X : Word;
  113.  
  114.     Procedure   Process;                                Virtual;
  115.   end;
  116.  
  117.  
  118. { TInterior }
  119. constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
  120.                            AVScrollBar: PScrollBar);
  121.   begin
  122.     TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
  123.     Options := Options or ofFramed;
  124.     SetLimit(128, LineCount);
  125.   end;
  126.  
  127. procedure TInterior.Draw;
  128.  
  129.   var
  130.     Color: Byte;
  131.     I, Y: Integer;
  132.     B: TDrawBuffer;
  133.  
  134.   begin
  135.     Color := GetColor(1);
  136.     for Y := 0 to Size.Y - 1 do
  137.     begin
  138.       MoveChar(B, ' ', Color, Size.X);
  139.       i := Delta.Y + Y;
  140.       if (I < LineCount) and (Lines[I] <> nil) then
  141.         MoveStr(B, Copy(Lines[I]^, Delta.X + 1, Size.X), Color);
  142.       WriteLine(0, Y, Size.X, 1, B);
  143.     end;
  144.   end;
  145.  
  146.  
  147. { TDemoWindow }
  148. constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
  149.   begin
  150.     TNewWindow.Init(Bounds, WinTitle, WindowNo{wnNoNumber});
  151.     GetExtent(Bounds);
  152.     Interior := MakeInterior(Bounds);
  153.     Insert(Interior);
  154.   end;
  155.  
  156. function TDemoWindow.MakeInterior(Bounds: TRect): PInterior;
  157.  
  158.   var
  159.     HScrollBar, VScrollBar: PScrollBar;
  160.     R : TRect;
  161.     P : PInterior;
  162.  
  163.   begin
  164.     R.Assign(Bounds.B.X-1, Bounds.A.Y+1, Bounds.B.X, Bounds.B.Y-1);
  165.     VScrollBar := New(PScrollBar, Init(R));
  166.     VScrollBar^.Options := VScrollBar^.Options or ofPostProcess;
  167.     Insert(VScrollBar);
  168.     R.Assign(Bounds.A.X+1, Bounds.B.Y-1, Bounds.B.X-1, Bounds.B.Y);
  169.     HScrollBar := New(PScrollBar, Init(R));
  170.     HScrollBar^.Options := HScrollBar^.Options or ofPostProcess;
  171.     Insert(HScrollBar);
  172.     Bounds.Grow(-1,-1);
  173.     P := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
  174.     P^.GrowMode := gfGrowHiX + gfGrowHiY;
  175.     MakeInterior := P;
  176.   end;
  177.  
  178.  
  179. { TPctDialog }
  180. Procedure TPctDialog.Process;
  181.   begin
  182.     { here is where the works gets done, in this case we just
  183.       delay a bit then bump the counter
  184.     }
  185.     if (RunState > 0) and (RunState < cmCancelJob) then
  186.     begin
  187.       if (RunState <> cmPauseJob) then
  188.       begin
  189.         Delay(5);
  190.         Increment;
  191.  
  192.         if (Count = 500) then
  193.           ChangeMessage('Half way there')
  194.         else if (Count >= Total) then
  195.         begin
  196.           RunState := cmJobComplete;
  197.           Delay(1000);
  198.         end;
  199.       end;
  200.     end;
  201.   end;
  202.  
  203.  
  204. { TPrtDialog }
  205. Procedure TPrtDialog.Process;
  206.  
  207.   var
  208.     N : String[5];
  209.  
  210.   begin
  211.     { Here is where the works gets done. In this case we print a line then
  212.       exit.
  213.     }
  214.     Case RunState of
  215.       cmStartJob : {DO SETUP AND START PRINTING}
  216.         begin
  217.           RunState := cmContinueJob;
  218.         end;
  219.  
  220.       cmContinueJob : {PRINT NEXT LINE}
  221.         begin
  222.           Inc(X);
  223.           Delay(100); {print line here}
  224.           Str(X,N);
  225.           ChangeMessage('Printing Line ' + N);
  226.  
  227.           if (X = 250) then
  228.             RunState := cmJobComplete;
  229.         end;
  230.  
  231.       cmPauseJob : {DO NOTHING}
  232.         ;
  233.  
  234.       cmJobComplete,
  235.       cmCancelJob : {SHUT DOWN}
  236.         ;
  237.     end;
  238.   end;
  239.  
  240.  
  241. { TMyApp }
  242. constructor TMyApp.Init;
  243.  
  244.   var
  245.     Event : TEVent;
  246.     P     : PToolBar;
  247.     R     : TRect;
  248.  
  249.   begin
  250.     TNewApplication.Init;
  251.     ReadFile('READ.ME');
  252.     NewFormatText;
  253.     Event.What := evCommand;
  254.     Event.Command := cmAbout;
  255.     PutEvent(Event);
  256.   end;
  257.  
  258. procedure TMyApp.InitDesktop;
  259.  
  260.   var
  261.     P     : PToolBar;
  262.     R     : TRect;
  263.  
  264.   begin
  265.     DoubleDelay := DoubleDelay DIV 2;
  266.     {!!! TOOL BARS ARE ONLY BETA VERSIONS, SO USE AT YOUR OWN RISK }
  267.     TNewApplication.InitDesktop;
  268.     { TOOL BARS SHOULD ALWAYS BE THE FIRST THING INSERTED INTO THE
  269.       DESKTOP!
  270.     }
  271.     R.Assign(0,0, 8,4);
  272.     P := New(PToolBar, Init(R, True));
  273.     P^.AddTool('  Save  '^M'File', CmTool1);
  274.     P^.AddTool('  Open  '^M'File', CmTool2);
  275.     P^.AddTool('  New   '^M'File', CmTool3);
  276.     P^.AddTool('  Edit  ', CmTool4);
  277.     P^.AddTool('  Cut   ', CmTool5);
  278.     P^.AddTool(' Paste  ', CmTool6);
  279.     Desktop^.Insert(P);
  280.   end;
  281.  
  282. procedure TMyApp.HandleEvent(var Event: TEvent);
  283.  
  284.   var
  285.     R : TRect;
  286.  
  287.   begin
  288.     TApplication.HandleEvent(Event);
  289.  
  290.     if Event.What = evCommand then
  291.     begin
  292.       case Event.Command of
  293.         cmAbout         : About;
  294.         cmNewWin        : NewWindow;
  295.         cmNewDialog     : NewDialog;
  296.         cmNewText       : NewText;
  297.         cmNewFormatText : NewFormatText;
  298.         cmNewAsciiHex   : NewAsciiHex;
  299.         cmNewEditLine   : NewEditLine;
  300.         cmFileOpen      : OpenFile;
  301.         cmSetup         : Setup;
  302.         cmTestPct       : PercentTest;
  303.         cmTestPrt       : PrintTest;
  304.         cmTestList      : ListTest;
  305.         cmTestWrite     : WritelnText;
  306.         cmTestBtn       : Test3D;
  307.         cmTool1         : MessageBox('SAVE TOOL', nil, mfInformation+ mfOkButton);
  308.         cmTool2         : MessageBox('OPEN TOOL', nil, mfInformation+ mfOkButton);
  309.         cmTool3         : MessageBox('NEW TOOL', nil, mfInformation+ mfOkButton);
  310.         cmTool4         : MessageBox('EDIT TOOL', nil, mfInformation+ mfOkButton);
  311.         cmTool5         : MessageBox('CUT TOOL', nil, mfInformation+ mfOkButton);
  312.         cmTool6         : MessageBox('PASTE TOOL', nil, mfInformation+ mfOkButton);
  313.         cmTile          :
  314.           begin
  315.             Desktop^.GetExtent(R);
  316.             Desktop^.Tile(R);
  317.           end;
  318.         cmCascade       :
  319.           begin
  320.             Desktop^.GetExtent(R);
  321.             Desktop^.Cascade(R);
  322.           end;
  323.         cmItem1..cmItem4:
  324.           PNewMenuBar(MenuBar)^.ResetMarkers(cmItem1, cmItem4, Event.Command);
  325.       else
  326.         Exit;
  327.       end;
  328.  
  329.       ClearEvent(Event);
  330.     end;
  331.   end;
  332.  
  333. procedure TMyApp.InitMenuBar;
  334.  
  335.   var
  336.     R : TRect;
  337.     S : String[3];
  338.  
  339.   begin
  340.     S := ' ';
  341.     (* Uncomment this to try check mark menus with a different marker.
  342.     TvMenus.Marker    := 'ON ';
  343.     Tvmenus.NoMarker  := 'OFF';
  344.     TvMenus.MarkerLen := 3;
  345.     S := '   ';
  346.     *)
  347.  
  348.     GetExtent(R);
  349.     R.B.Y := R.A.Y + 1;
  350.     MenuBar := New(PNewMenuBar, Init(R,
  351.     NewMenu(
  352.       NewSubMenu('~≡~', hcNoContext,
  353.       NewMenu(
  354.         NewItem('~A~bout...',               '',     kbNoKey,  cmAbout,          hcNoContext,
  355.         nil)),
  356.       NewSubMenu('~F~ile', hcNoContext,
  357.       NewMenu(
  358.         NewItem('~O~pen...',                'F3',   kbF3,     cmFileOpen,       hcNoContext,
  359.         NewLine(
  360.         NewItem('E~x~it',                   'Alt-X',kbAltX,   cmQuit,           hcNoContext,
  361.         nil)))),
  362.       NewSubMenu('~W~indow', hcNoContext,
  363.       NewMenu(
  364.         NewItem('~N~ext',                   'F6',   kbF6,     cmNext,           hcNoContext,
  365.         NewItem('~Z~oom',                   'F5',   kbF5,     cmZoom,           hcNoContext,
  366.         NewItem('~T~ile',                   '',     kbNoKey,  cmTile,           hcNoContext,
  367.         NewItem('~C~ascade',                '',     kbNoKey,  cmCascade,        hcNoContext,
  368.         nil))))),
  369.       NewSubMenu('~T~est', hcNoContext,
  370.       NewMenu(
  371.         NewItem('~D~ata Entry...',          '',     kbNoKey,  cmNewEditLine,    hcNoContext,
  372.         NewItem('~M~essage Dialog...',      'F2',   kbF2,     cmNewDialog,      hcNoContext,
  373.         NewItem('Standard File ~V~iewer',   'F4',   kbF4,     cmNewWin,         hcNoContext,
  374.         NewItem('~T~ext Window',            'F7',   kbF7,     cmNewText,        hcNoContext,
  375.         NewItem('~F~ormatted File Viewer',  'F8',   kbF8,     cmNewFormatText,  hcNoContext,
  376.         NewItem('~A~scii/Hex Editor',       'F9',   kbF9,     cmNewAsciiHex,    hcNoContext,
  377.         NewItem('~P~rogress Dialog',        '',     kbNoKey,  cmTestPct,        hcNoContext,
  378.         NewItem('P~r~int Dialog',           '',     kbNoKey,  cmTestPrt,        hcNoContext,
  379.         NewItem('~3~D Controls',            '',     kbNoKey,  cmTestBtn,        hcNoContext,
  380.         NewItem('~W~riteln to Window',      '',     kbNoKey,  cmTestWrite,      hcNoContext,
  381.         NewSubMenu('~C~heck Marks', hcNoContext,
  382.         NewMenu(
  383.           NewMarkedItem(S + 'Item 1',       '',     kbNoKey,  cmItem1,          hcNoContext,
  384.           NewMarkedItem(S + 'Item 2',       '',     kbNoKey,  cmItem2,          hcNoContext,
  385.           NewMarkedItem(S + 'Item 3',       '',     kbNoKey,  cmItem3,          hcNoContext,
  386.           NewMarkedItem(S + 'Item 4',       '',     kbNoKey,  cmItem4,          hcNoContext,
  387.           nil))))),
  388.         nil)))))))))))),
  389.       NewSubMenu('~O~ptions', hcNoContext,
  390.       NewMenu(
  391.         NewItem('~S~etup',                  '',     kbNoKey,  cmSetup,          hcNoContext,
  392.         nil)),
  393.       nil)))))
  394.     )));
  395.  
  396.     PNewMenuBar(MenuBar)^.SetMarker(cmItem1);
  397.   end;
  398.  
  399. procedure TMyApp.InitStatusLine;
  400.  
  401.   var
  402.     R : TRect;
  403.  
  404.   begin
  405.     GetExtent(R);
  406.     R.A.Y := R.B.Y - 1;
  407.     StatusLine := New(PStatusLine, Init(R,
  408.       NewStatusDef(0, $FFFF,
  409.         NewStatusKey('', kbF10, cmMenu,
  410.         NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  411.         NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  412.         nil))),
  413.       nil)
  414.     ));
  415.   end;
  416.  
  417. Procedure TMyApp.ListTest;
  418.   begin
  419.   end;
  420.  
  421. Procedure TMyApp.WritelnText;
  422.  
  423.   var
  424.     W : PTextWindow;
  425.     R : TRect;
  426.  
  427.   begin
  428.     R.Assign(0, 0, 60, 13);
  429.     W := New(PTextWindow, Init(R, 'Standard Output', wnNoNumber,
  430.                                ofVScrollBar or ofHScrollBar, 25));
  431.     DeskTop^.Insert(W);
  432.  
  433.     { redirect stnadard writes to a window }
  434.     AssignOutput(Output, W);
  435.     Rewrite(Output);
  436.     Writeln('THIS TEXT IS DISPLAYED THROUGH THE STANDARD WRITE AND');
  437.     Writeln('WRITELN STATEMENTS.');
  438.     Write('THE STANDARD OUTPUT HAS BEEN REDIRECTED TO THIS WINDOW.');
  439.     { restore standard output }
  440.     Close(Output);
  441.     Assign(Output, '');
  442.     Rewrite(Output);
  443.   end;
  444.  
  445. Procedure TMyApp.PercentTest;
  446.  
  447.   var
  448.     Dlg : TPctDialog;
  449.  
  450.   begin
  451.     Dlg.Init('', 'Your Message Here', 1000, mfOKPauseCancel OR mfMessageLine);
  452.     DeskTop^.ExecView(@Dlg);
  453.   end;
  454.  
  455. Procedure TMyApp.PrintTest;
  456.  
  457.   var
  458.     Dlg : TPrtDialog;
  459.  
  460.   begin
  461.     Dlg.Init('PRINT', '', mfOKPauseCancel OR mfMessageLine);
  462.     DeskTop^.ExecView(@Dlg);
  463.   end;
  464.  
  465. Procedure TMyApp.About;
  466.  
  467.   var
  468.     Dialog : TMessageDialog;
  469.  
  470.   begin
  471.     Dialog.Init(mfInformation + mfOKButton);
  472.     Dialog.AddMessage('');
  473.     Dialog.AddMessage('              ╔═════╗    ');
  474.     Dialog.AddMessage('          ┌───╨─────╨───┐');
  475.     Dialog.AddMessage('          ├─────────────┤');
  476.     Dialog.AddMessage('          │ TV TOOL BOX │');
  477.     Dialog.AddMessage('          └─────────────┘');
  478.     Dialog.AddMessage('');
  479.     Dialog.AddMessage(' Tools for Turbo Vision Programmers ');
  480.     Dialog.AddMessage('');
  481.     Dialog.AddMessage('   Copyright 1992, Richard Hansen');
  482.     Dialog.AddMessage('');
  483.     Dialog.Process;
  484.     Dialog.Done;
  485.   end;
  486.  
  487. Procedure TMyApp.Setup;
  488.  
  489.   var
  490.     Dlg     : PDialog;
  491.     R       : TRect;
  492.     Control : PView;
  493.     Command : Word;
  494.     MState  : Word;
  495.  
  496.   begin
  497.     R.Assign(0,0,53,12);
  498.     New(Dlg, Init(R, 'Setup'));
  499.  
  500.     with Dlg^ do
  501.     begin
  502.       Options := Options OR ofCentered;
  503.       R.Assign(2,2,51,3);
  504.       Control := New(PCheckboxes, Init(R,
  505.         NewSItem('Turn mouse cursor off when keyboard is used',Nil)));
  506.       PCluster(Control)^.Value := 0;
  507.       Insert(Control);
  508.  
  509.       R.Assign(10,8,18,10);
  510.       Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
  511.  
  512.       R.Assign(29,8,41,10);
  513.       Insert(New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
  514.  
  515.       SelectNext(False);
  516.  
  517.       if (ValidView(Dlg) <> nil) then
  518.       begin
  519.         if ToggleMouse then
  520.           MState  := 1
  521.         else
  522.           MState := 0;
  523.  
  524.         Dlg^.SetData(MState);
  525.         Command := DeskTop^.ExecView(Dlg);
  526.  
  527.         if (Command <> cmCancel) then
  528.         begin
  529.           Dlg^.GetData(MState);
  530.  
  531.           if (MState = 1) then
  532.             SetMouseToggle(True)
  533.           else
  534.             SetMouseToggle(False);
  535.         end;
  536.       end;
  537.     end;
  538.   end;
  539.  
  540. procedure TMyApp.ReadFile(FileToRead : PathStr);
  541.  
  542.   var
  543.     F : Text;
  544.     S : String;
  545.  
  546.   begin
  547.     ShowBusy;
  548.     LineCount := 0;
  549.     Assign(F, FileToRead);
  550.     {$I-}
  551.     Reset(F);
  552.     {$I+}
  553.  
  554.     if IOResult <> 0 then
  555.     begin
  556.       Writeln('Cannot open ', FileToRead);
  557.       Halt(1);
  558.     end;
  559.  
  560.     BufName := FileToRead;
  561.     BufSize := 0;
  562.     FillChar(Buf, SizeOf(Buf), 0);
  563.  
  564.     while not Eof(F) and (LineCount < MaxLines) do
  565.     begin
  566.       Readln(F, S);
  567.       Lines[LineCount] := NewStr(S);
  568.       Inc(LineCount);
  569.  
  570.       if (BufSize + Length(S) < SizeOf(Buf)) then
  571.       begin
  572.         Inc(Byte(S[0]));
  573.         S[Byte(S[0])] := #13;
  574.         Move(S[1], Buf[BufSize], Byte(S[0]));
  575.         Inc(BufSize, Length(S));
  576.       end;
  577.     end;
  578.  
  579.     Close(F);
  580.     CLearBusy;
  581.   end;
  582.  
  583. procedure TMyApp.OpenFile;
  584.  
  585.   var
  586.     FileName  : PathStr;
  587.     D         : PFileDialog;
  588.  
  589.   begin
  590.     {$IFDEF NEW_FILE_DIALOG}
  591.     D := New(PNewFileDialog, Init('*.*', 'Open a File',
  592.                                   'File~n~ame',
  593.                                   fdOpenButton + fdHelpButton, 100));
  594.     {$ELSE}
  595.     D := New(PFileDialog, Init('*.*', 'Open a File',
  596.                                'File~n~ame',
  597.                                 fdOpenButton + fdHelpButton, 100));
  598.     {$ENDIF}
  599.  
  600.     if ValidView(D) <> nil then
  601.     begin
  602.       if Desktop^.ExecView(D) <> cmCancel then
  603.       begin
  604.         D^.GetFileName(FileName);
  605.         EnableCommands([cmNewWin..cmNewAsciiHex]);
  606.         DisableCommands([cmFileOpen]);
  607.         ReadFile(FileName);
  608.       end;
  609.  
  610.       Dispose(D, Done);
  611.     end;
  612.   end;
  613.  
  614. procedure TMyApp.NewDialog;
  615.  
  616. var
  617.   Dialog : TMessageDialog;
  618.  
  619. begin
  620.   Dialog.Init(mfInformation + mfOKButton);
  621.   Dialog.AddMessage('');
  622.   Dialog.AddMessage(' -------------- TMessageDialog -------------- ');
  623.   Dialog.AddMessage(' It is simple to add text, just make a call');
  624.   Dialog.AddMessage(' to the TMessageDialog.AddMessage method! The');
  625.   Dialog.AddMessage(' message box will size itself to the amount');
  626.   Dialog.AddMessage(' of text that is added.');
  627.   Dialog.AddMessage(' -------------------------------------------- ');
  628.   Dialog.Process;
  629.   Dialog.Done;
  630. end;
  631.  
  632. procedure TMyApp.NewWindow;
  633. var
  634.   Window: PDemoWindow;
  635.   R: TRect;
  636. begin
  637.   Inc(WinCount);
  638.   R.Assign(0, 0, 45, 13);
  639.   R.Move(Random(34), Random(11));
  640.   Window := New(PDemoWindow, Init(R, 'Standard Viewer: ' + BufName, wnNoNumber));
  641.   Window^.Options := Window^.Options OR ofTileable;
  642.   DeskTop^.Insert(Window);
  643. end;
  644.  
  645. procedure TMyApp.NewAsciiHex;
  646.  
  647.   var
  648.     Window: PEditBuffWindow;
  649.     R     : TRect;
  650.  
  651.   begin
  652.     Inc(WinCount);
  653.     R.Assign(1,1, 64,16);
  654.     Window := New(PEditBuffWindow, Init(R, 'Ascii/Hex Editor: ' + BufName,
  655.                                         WinCount, ofPosIndicator,
  656.                                         @Buf, SizeOf(Buf)));
  657.     Window^.Options := Window^.Options OR ofTileable;
  658.     DeskTop^.Insert(Window);
  659.   end;
  660.  
  661. procedure TMyApp.NewText;
  662.  
  663.   var
  664.     R       : TRect;
  665.     i       : Byte;
  666.     S       : String[3];
  667.     TextWin : PTextWindow;
  668.     Event   : TEvent;
  669.  
  670.   begin
  671.     Inc(WinCount);
  672.     R.Assign(0, 0, 60, 13);
  673.     R.Move(Random(19), Random(10));
  674.     TextWin := New(PTextWindow, Init(R, 'Text Window', WinCount,
  675.                                     ofVScrollBar or ofHScrollBar, 25));
  676.     TextWin^.Options := TextWin^.Options OR ofTileable;
  677.     DeskTop^.Insert(TextWin);
  678.  
  679.     TextWin^.Write('');
  680.     TextWin^.Write(' ┌───────────────────────────────────────────────────────┐ ');
  681.     TextWin^.Write(' │ THIS MAY NOT LOOK LIKE MUCH HERE, BUT CHECK OUT THE   │ ');
  682.     TextWin^.Write(' │ EXAMPLE CODE AND YOU WILL SEE THAT THIS IS A TEXT     │ ');
  683.     TextWin^.Write(' │ DISPLAY WINDOW WITHOUT A CUSTOMIZED DRAW METHOD. JUST │ ');
  684.     TextWin^.Write(' │ THE THING FOR A LITTLE QUICK AND EASY TEXT DISPLAY!   │ ');
  685.     TextWin^.Write(' │ OPEN THE DATA ENTRY DIALOG, ENTER SOME DATA, AND HIT  │ ');
  686.     TextWin^.Write(' │ "OK" WHEN THIS WINDOW IS OPEN.                        │ ');
  687.     TextWin^.Write(' └───────────────────────────────────────────────────────┘ ');
  688.     TextWin^.Write('');
  689.   end;
  690.  
  691. procedure TMyApp.NewFormatText;
  692.  
  693.   var
  694.     Window      : PNewWindow;
  695.     R           : TRect;
  696.     AVScrollBar : PScrollBar;
  697.  
  698.   begin
  699.     Inc(WinCount);
  700.     R.Assign(0, 0, Desktop^.Size.X, Desktop^.Size.Y);
  701.     Window := New(PNewWindow, Init(R, 'Formatted Text Scroller: ' + BufName, WinCount));
  702.     Window^.Options := Window^.Options OR ofTileable OR ofCentered;
  703.  
  704.     Window^.GetExtent(R);
  705.     R.Assign(R.B.X-1, R.A.Y+1, R.B.X, R.B.Y-1);
  706.     AVScrollBar := New(PScrollBar, Init(R));
  707.     AVScrollBar^.Options := AVScrollBar^.Options or ofPostProcess;
  708.     Window^.Insert(AVScrollBar);
  709.  
  710.     Window^.GetExtent(R);
  711.     R.Grow(-1, -1);
  712.     Window^.Insert(New(PFormattedTextScroller,
  713.                        Init(R, AVscrollbar, @Buf, BufSize)));
  714.  
  715.     DeskTop^.Insert(Window);
  716.   end;
  717.  
  718. Function Test(P : Pointer; ID : Word): Boolean;   FAR;
  719.   begin
  720.     MessageBox('POST EDIT ROUTINE: '^M'You just entered ' + PEditLine(P)^.Data^, nil, mfError + mfOkButton);
  721.     { Return TRUE to stay, FALSE to leave the field }
  722.     Test := False;
  723.   end;
  724.  
  725. procedure TMyApp.NewEditLine;
  726.  
  727.   type
  728.     DataRec = record
  729.       S1 : String[10];
  730.       S2 : String[21];
  731.       S3 : String[21];
  732.       S4 : String[21];
  733.       S5 : String[21];
  734.       I1 : Word;
  735.       I2 : Integer;
  736.       H1 : LongInt;
  737.       S6 : String[8];
  738.       S7 : String[8];
  739.       S8 : String[10];
  740.       S9 : String[10];
  741.       R1 : Real;
  742.       V1 : Word;
  743.       V2 : Word;
  744.     end;
  745.  
  746.   var
  747.     Dialog : PEntryDialog;
  748.     R      : TRect;
  749.     E      : PEditLine;
  750.     P      : PNewRadioButtons;
  751.     L      : PLabel;
  752.     S      : String[80];
  753.     Data   : DataRec;
  754.  
  755.   begin
  756.     R.Assign(0,0, 75,17);
  757.     Dialog := New(PEntryDialog, Init(R, 'Data Entry'));
  758.  
  759.  
  760.     With Dialog^ do
  761.     begin
  762.       Options := Options or ofCentered;
  763.       R.Assign(2,1, 14,2);
  764.       E := New(PEditLine, Init(R, '99/99/9999'));
  765.       Insert(E);
  766.       {E^.SetEditFlag(efLJustify, True);}
  767.       R.Assign(2,2, 19,3);
  768.       Insert(New(PEditLine, Init(R, '(999) 999-9999 [9999]')));
  769.       R.Assign(2,4, 26,5);
  770.       Insert(New(PEditLine, Init(R, '(999) 999-9999 [9999]')));
  771.  
  772.       R.Assign(2,6, 19,7);
  773.       E := New(PEditLine, Init(R, '(999) 999-9999 [9999]'));
  774.       Insert(E);
  775.       R.Assign(2,5, 19,6);
  776.       L := New(PLabel, Init(R, '~L~ocked Field', E));
  777.       Insert(L);
  778.       E^.AddLabel(L);
  779.       E^.Lock;
  780.  
  781.       R.Assign(2,8, 19,9);
  782.       E := New(PEditLine, Init(R, '(999) 999-9999 [9999]'));
  783.       Insert(E);
  784.       R.Assign(2,7, 19,8);
  785.       L := New(PLabel, Init(R, '~U~nlocked Field', E));
  786.       Insert(L);
  787.       E^.AddLabel(L);
  788.  
  789.       R.Assign(2,10, 10,11);
  790.       E := New(PWordEdit, Init(R, '99999', 0, 10000));
  791.       Insert(E);
  792.       E^.SetEditFlag(efLJustify, True);
  793.       R.Assign(2,9, 19,10);
  794.       L := New(PLabel, Init(R, 'U~n~signed Integer', E));
  795.       Insert(L);
  796.       E^.AddLabel(L);
  797.  
  798.       R.Assign(2,12, 11,13);
  799.       E := New(PIntegerEdit, Init(R, '######', -10000, 10000));
  800.       Insert(E);
  801.       E^.SetEditFlag(efRJustify, True);
  802.       R.Assign(2,11,  19,12);
  803.       L := New(PLabel, Init(R, '~S~igned Integer', E));
  804.       Insert(L);
  805.       E^.AddLabel(L);
  806.  
  807.       R.Assign(30,2, 37,3);
  808.       E := New(PHexEdit, Init(R, '&&&&&', $0000, $FFFF));
  809.       Insert(E);
  810.       R.Assign(30,1,  47,2);
  811.       Insert(New(PLabel, Init(R, '~H~exadecimal', E)));
  812.  
  813.       R.Assign(30,4, 40,5);
  814.       E := New(PEditLine, Init(R, 'XXXXXXXX'));
  815.       E^.SetEditFlag(efHide, True);
  816.       Insert(E);
  817.       R.Assign(30,3, 47,4);
  818.       Insert(New(PLabel, Init(R, '~P~assword', E)));
  819.  
  820.       R.Assign(30,6, 40,7);
  821.       E := New(PEditLine, Init(R, 'XXXXXXXX'));
  822.       E^.PadChar := '_';
  823.       E^.SetEditFlag(efTrim, True);
  824.       Insert(E);
  825.  
  826.       R.Assign(30,8, 42,9);
  827.       E := New(PEditLine, Init(R, 'UUUUUUUUUU'));
  828.       Insert(E);
  829.       E^.SetEditFlag(efRequired, True);
  830.       R.Assign(30,7, 53,8);
  831.       Insert(New(PLabel, Init(R, 'Any Char ~F~orce Upper', E)));
  832.  
  833.       R.Assign(30,10, 42,11);
  834.       E := New(PEditLine, Init(R, 'llllllllll'));
  835.       Insert(E);
  836.       E^.SetEditFlag(efLJustify, True);
  837.       E^.SetPostEdit(@TEST);
  838.       R.Assign(30,9, 53,10);
  839.       Insert(New(PLabel, Init(R, '~A~lpha Only Force Lower', E)));
  840.  
  841.       R.Assign(30,12, 41,13);
  842.       E := New(PRealEdit, Init(R, '#####.###', 0.0, 0.0));
  843.       Insert(E);
  844.       R.Assign(30,11, 53,12);
  845.       Insert(New(PLabel, Init(R, '~F~loating point', E)));
  846.  
  847.       { add radio buttons }
  848.       R.Assign(57,2,68,6);
  849.       P := New(PNewRadioButtons, Init(R,
  850.         NewSItem('~O~ne',
  851.         NewSItem('~T~wo',
  852.         NewSItem('Th~r~ee',
  853.         NewSItem('~F~our',Nil))))));
  854.       PCluster(P)^.Value := 0;
  855.       Insert(P);
  856.       R.Assign(58,1, 71,2);
  857.       L := New(PLabel, Init(R, 'L~o~cked', P));
  858.       Insert(L);
  859.       P^.AddLabel(L);
  860.       P^.Lock;
  861.  
  862.       R.Assign(57,8,68,12);
  863.       P := New(PNewRadioButtons, Init(R,
  864.         NewSItem('~O~ne',
  865.         NewSItem('~T~wo',
  866.         NewSItem('Th~r~ee',
  867.         NewSItem('~F~our',Nil))))));
  868.       PCluster(P)^.Value := 0;
  869.       Insert(P);
  870.       R.Assign(58,7, 71,8);
  871.       L := New(PLabel, Init(R, 'Unlocked', P));
  872.       Insert(L);
  873.       P^.AddLabel(L);
  874.  
  875.       R.Assign(15,14, 23,16);
  876.       Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  877.  
  878.       R.Assign(30,14, 44,16);
  879.       Insert(New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
  880.  
  881.       SelectNext(False);
  882.     end;
  883.  
  884.     if (DeskTop^.ExecView(Dialog) <> cmCancel) then
  885.     begin
  886.       Dialog^.GetData(Data);
  887.  
  888.       with Data do
  889.       begin
  890.         Message(Desktop, evBroadcast, cmDisplayClr, nil);
  891.         S := '<<< HERE IS WHAT YOU JUST ENTERED IN THE DIALOG BOX >>>';
  892.         Message(Desktop, evBroadcast, cmDisplayStr, @S);
  893.         Message(Desktop, evBroadcast, cmDisplayStr, @S1);
  894.         Message(Desktop, evBroadcast, cmDisplayStr, @S2);
  895.         Message(Desktop, evBroadcast, cmDisplayStr, @S3);
  896.         Message(Desktop, evBroadcast, cmDisplayStr, @S4);
  897.         Message(Desktop, evBroadcast, cmDisplayStr, @S5);
  898.         Str(I1, S);
  899.         Message(Desktop, evBroadcast, cmDisplayStr, @S);
  900.         Str(I2, S);
  901.         Message(Desktop, evBroadcast, cmDisplayStr, @S);
  902.         Str(H1, S);
  903.         Message(Desktop, evBroadcast, cmDisplayStr, @S);
  904.         Message(Desktop, evBroadcast, cmDisplayStr, @S6);
  905.         Message(Desktop, evBroadcast, cmDisplayStr, @S7);
  906.         Message(Desktop, evBroadcast, cmDisplayStr, @S8);
  907.         Message(Desktop, evBroadcast, cmDisplayStr, @S9);
  908.         Str(R1:9:3, S);
  909.         Message(Desktop, evBroadcast, cmDisplayStr, @S);
  910.       end;
  911.     end;
  912.  
  913.     Dispose(Dialog);
  914.   end;
  915.  
  916. Procedure TMyApp.Test3D;
  917.  
  918.   var
  919.     Dialog : P3DDialog;
  920.     R      : TRect;
  921.     P      : PView;
  922.  
  923.   begin
  924.     R.Assign(0,0,42,20);
  925.     New(Dialog, Init(R, '3D Controls'));
  926.  
  927.     with Dialog^ do
  928.     begin
  929.       Options := Options or ofCentered;
  930.  
  931.       { these are the inputline bounds, the outline will adjust
  932.        its bounds as needed
  933.       }
  934.       R.Assign(3,3, 14,4);
  935.       P := New(P3DOutline, Init(R));
  936.       Insert(P);
  937.  
  938.       P := New(P3DInputLine, Init(R, 15));
  939.       Insert(P);
  940.  
  941.       R.Assign(3,2, 11,3);
  942.       P := New(PLabel, Init(R, '~T~ext 2', P));
  943.       Insert(P);
  944.  
  945.       R.Assign(3,6, 14,7);
  946.       P := New(P3DOutline, Init(R));
  947.       Insert(P);
  948.  
  949.       P := New(P3DInputLine, Init(R, 15));
  950.       Insert(P);
  951.  
  952.       R.Assign(3,5, 11,6);
  953.       P := New(PLabel, Init(R, '~T~ext 1', P));
  954.       Insert(P);
  955.  
  956.       { 3D Buttons }
  957.       R.Assign(24,2,36,5);
  958.       Insert(New(P3DButton, Init(R, 'OK', cmOK, bfDefault)));
  959.  
  960.       R.Assign(24,5,36,8);
  961.       Insert(New(P3DButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
  962.  
  963.       R.Assign(24,8,36,12);
  964.       Insert(New(P3DButton, Init(R, '~O~pen'^M'File', cmYes, bfNormal)));
  965.  
  966.       R.Assign(24,12,36,16);
  967.       Insert(New(P3DButton, Init(R, '~S~ave'^M'File', cmNo, bfNormal)));
  968.  
  969.       SelectNext(False);
  970.     end;
  971.  
  972.     DeskTop^.ExecView(Dialog);
  973.     Dispose(Dialog);
  974.   end;
  975.  
  976.  
  977. var
  978.   MyApp : TMyApp;
  979.  
  980. begin
  981.   MyApp.Init;
  982.   MyApp.Run;
  983.   MyApp.Done;
  984. end.