home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / TP.7_1 / TP / EXAMPLES / TVDEMO / GENRDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-05  |  8.5 KB  |  316 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision Demo                            }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. { Resource generator for TVRDEMO.EXE. }
  9.  
  10. program GenRDemo;
  11.  
  12. {$M 16384,8192,655360}
  13.  
  14. uses Drivers, Objects, Views, Dialogs, Menus, App, ColorSel,
  15.   StdDlg, Editors, DemoHelp, DemoCmds, DemoStrs;
  16.  
  17. type
  18.   PProtectedStream = ^TProtectedStream;
  19.   TProtectedStream = object(TBufStream)
  20.     procedure Error(Code, Info: Integer); virtual;
  21.   end;
  22.  
  23. var
  24.   RezFile: TResourceFile;
  25.   RezStream: PStream;
  26.  
  27. { TProtectedStream }
  28.  
  29. procedure TProtectedStream.Error(Code, Info: Integer);
  30. begin
  31.   Writeln('Error in stream: Code = ', Code, ' Info = ', Info);
  32.   Halt(1);
  33. end;
  34.  
  35. { Resource procedures }
  36.  
  37. procedure CreateStrings;
  38. var
  39.   S: PStrListMaker;
  40. begin
  41.   S := New(PStrListMaker, Init(10000, 100));
  42.  
  43.   S^.Put(sNoMem, 'Not enough memory available to compilete operation.');
  44.   S^.Put(sErrorReading, 'Error reading file %s.');
  45.   S^.Put(sErrorWriting, 'Error writing file %s.');
  46.   S^.Put(sErrorCreating, 'Error creating file %s.');
  47.   S^.Put(sModified, '%s has been modified. Save?');
  48.   S^.Put(sSaveUntitled, 'Save untitled file?');
  49.   S^.Put(sStrNotFound, 'Search string not found.');
  50.   S^.Put(sReplace, 'Replace this occurence?');
  51.   S^.Put(sErrorHelp, 'Could not open help file.');
  52.   S^.Put(sErrorOpenDesk, 'Could not open desktop file');
  53.   S^.Put(sErrorReadingDesk, 'Error reading desktop file');
  54.   S^.Put(sDeskInvalid, 'Error: Invalid Desktop file.');
  55.   S^.Put(sErrorDeskCreate, 'Could not create TVDEMO.DSK.');
  56.  
  57.   RezFile.Put(S, 'Strings');
  58.   Dispose(S, Done);
  59. end;
  60.  
  61. procedure CreateMenu;
  62. var
  63.   R: TRect;
  64.   P: PView;
  65. begin
  66.   R.Assign(0, 0, 80, 1);
  67.   P := New(PMenuBar, Init(R, NewMenu(
  68.     NewSubMenu('~'#240'~', hcSystem, NewMenu(
  69.       NewItem('~A~bout', '', kbNoKey, cmAbout, hcSAbout,
  70.       NewLine(
  71.       NewItem('~P~uzzle', '', kbNoKey, cmPuzzle, hcSPuzzle,
  72.       NewItem('Ca~l~endar', '', kbNoKey, cmCalendar, hcSCalendar,
  73.       NewItem('Ascii ~t~able', '', kbNoKey, cmAsciiTab, hcSAsciiTable,
  74.       NewItem('~C~alculator', '', kbNoKey, cmCalculator, hcCalculator, nil))))))),
  75.     NewSubMenu('~F~ile', hcFile, NewMenu(
  76.       StdFileMenuItems(nil)),
  77.     NewSubMenu('~E~dit', hcNoContext, NewMenu(
  78.       StdEditMenuItems(
  79.       NewLine(
  80.       NewItem('~S~how clipboard', '', kbNoKey, cmShowClip, hcShowClip,
  81.       nil)))),
  82.     NewSubMenu('~S~earch', hcNoContext, NewMenu(
  83.       NewItem('~F~ind...', '', kbNoKey, cmFind, hcNoContext,
  84.       NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcNoContext,
  85.       NewItem('~S~earch again', '', kbNoKey, cmSearchAgain, hcNoContext,
  86.       nil)))),
  87.     NewSubMenu('~W~indows', hcWindows, NewMenu(
  88.       StdWindowMenuItems(nil)),
  89.     NewSubMenu('~O~ptions', hcOptions, NewMenu(
  90.       NewItem('~M~ouse...', '', kbNoKey, cmMouse, hcOMouse,
  91.       NewItem('~C~olors...', '', kbNoKey, cmColors, hcOColors,
  92.       NewLine(
  93.       NewItem('~S~ave desktop', '', kbNoKey, cmSaveDesktop, hcOSaveDesktop,
  94.       NewItem('~R~etrieve desktop', '', kbNoKey, cmRetrieveDesktop, hcORestoreDesktop, nil)))))),
  95.       nil)))))))));
  96.  
  97.   RezFile.Put(P, 'MenuBar');
  98.   Dispose(P, Done);
  99. end;
  100.  
  101. procedure CreateStatusLine;
  102. var
  103.   R: TRect;
  104.   P: PView;
  105. begin
  106.   R.Assign(0, 24, 80, 25);
  107.   P := New(PStatusLine, Init(R,
  108.     NewStatusDef(0, $FFFF,
  109.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  110.       NewStatusKey('~F1~ Help', kbF1, cmHelp,
  111.       NewStatusKey('~F3~ Open', kbF3, cmOpen,
  112.       NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  113.       NewStatusKey('~F5~ Zoom', kbF5, cmZoom,
  114.       NewStatusKey('', kbF10, cmMenu,
  115.       NewStatusKey('', kbCtrlF5, cmResize,
  116.       nil))))))),
  117.     nil)));
  118.  
  119.   RezFile.Put(P, 'StatusLine');
  120.   Dispose(P, Done);
  121. end;
  122.  
  123. procedure CreateFileOpenDialog;
  124. var
  125.   P: PView;
  126. begin
  127.   P := New(PFileDialog, Init('*.*', 'Open a File',
  128.     '~N~ame', fdOpenButton + fdHelpButton + fdNoLoadDir, 100));
  129.   P^.HelpCtx := hcFOFileOpenDBox;
  130.  
  131.   RezFile.Put(P, 'FileOpenDialog');
  132.   Dispose(P, Done);
  133. end;
  134.  
  135. procedure CreateAboutDialog;
  136. var
  137.   R: TRect;
  138.   D: PDialog;
  139. begin
  140.   R.Assign(0, 0, 40, 11);
  141.   D := New(PDialog, Init(R, 'About'));
  142.   with D^ do
  143.   begin
  144.     Options := Options or ofCentered;
  145.  
  146.     R.Grow(-1, -1);
  147.     Dec(R.B.Y, 3);
  148.     Insert(New(PStaticText, Init(R,
  149.       #13 +
  150.       ^C'Turbo Vision Demo'#13 +
  151.       #13 +
  152.       ^C'Copyright (c) 1992'#13 +
  153.       #13 +
  154.       ^C'Borland International')));
  155.  
  156.     R.Assign(15, 8, 25, 10);
  157.     Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
  158.   end;
  159.  
  160.   RezFile.Put(D, 'AboutDialog');
  161.   Dispose(D, Done);
  162. end;
  163.  
  164. procedure CreateColorSelDialog;
  165. var
  166.   R: TRect;
  167.   D: PDialog;
  168. begin
  169.   D := New(PColorDialog, Init('',
  170.     ColorGroup('Desktop',       DesktopColorItems(nil),
  171.     ColorGroup('Menus',         MenuColorItems(nil),
  172.     ColorGroup('Dialogs/Calc',  DialogColorItems(dpGrayDialog, nil),
  173.     ColorGroup('Editor/Puzzle', WindowColorItems(wpBlueWindow, nil),
  174.     ColorGroup('Ascii table',   WindowColorItems(wpGrayWindow, nil),
  175.     ColorGroup('Calendar',
  176.       WindowColorItems(wpCyanWindow,
  177.       ColorItem('Current day',       22, nil)),
  178.       nil))))))));
  179.   D^.HelpCtx := hcOCColorsDBox;
  180.  
  181.   RezFile.Put(D, 'ColorSelectDialog');
  182.   Dispose(D, Done);
  183. end;
  184.  
  185. procedure CreateChDirDialog;
  186. var
  187.   R: TRect;
  188.   D: PDialog;
  189. begin
  190.   D := New(PChDirDialog, Init(cdNormal + cdHelpButton + cdNoLoadDir, 101));
  191.   D^.HelpCtx := hcFCChDirDBox;
  192.  
  193.   RezFile.Put(D, 'ChDirDialog');
  194.   Dispose(D, Done);
  195. end;
  196.  
  197. procedure CreateFindDialog;
  198. var
  199.   D: PDialog;
  200.   Control: PView;
  201.   R: TRect;
  202. begin
  203.   R.Assign(0, 0, 38, 12);
  204.   D := New(PDialog, Init(R, 'Find'));
  205.   with D^ do
  206.   begin
  207.     Options := Options or ofCentered;
  208.  
  209.     R.Assign(3, 3, 32, 4);
  210.     Control := New(PInputLine, Init(R, 80));
  211.     Insert(Control);
  212.     R.Assign(2, 2, 15, 3);
  213.     Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
  214.     R.Assign(32, 3, 35, 4);
  215.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  216.  
  217.     R.Assign(3, 5, 35, 7);
  218.     Insert(New(PCheckBoxes, Init(R,
  219.       NewSItem('~C~ase sensitive',
  220.       NewSItem('~W~hole words only', nil)))));
  221.  
  222.     R.Assign(14, 9, 24, 11);
  223.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  224.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  225.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  226.  
  227.     SelectNext(False);
  228.   end;
  229.  
  230.   RezFile.Put(D, 'FindDialog');
  231.   Dispose(D, Done);
  232. end;
  233.  
  234. procedure CreateReplaceDialog;
  235. var
  236.   D: PDialog;
  237.   Control: PView;
  238.   R: TRect;
  239. begin
  240.   R.Assign(0, 0, 40, 16);
  241.   D := New(PDialog, Init(R, 'Replace'));
  242.   with D^ do
  243.   begin
  244.     Options := Options or ofCentered;
  245.  
  246.     R.Assign(3, 3, 34, 4);
  247.     Control := New(PInputLine, Init(R, 80));
  248.     Insert(Control);
  249.     R.Assign(2, 2, 15, 3);
  250.     Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
  251.     R.Assign(34, 3, 37, 4);
  252.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  253.  
  254.     R.Assign(3, 6, 34, 7);
  255.     Control := New(PInputLine, Init(R, 80));
  256.     Insert(Control);
  257.     R.Assign(2, 5, 12, 6);
  258.     Insert(New(PLabel, Init(R, '~N~ew text', Control)));
  259.     R.Assign(34, 6, 37, 7);
  260.     Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
  261.  
  262.     R.Assign(3, 8, 37, 12);
  263.     Insert(New(PCheckBoxes, Init(R,
  264.       NewSItem('~C~ase sensitive',
  265.       NewSItem('~W~hole words only',
  266.       NewSItem('~P~rompt on replace',
  267.       NewSItem('~R~eplace all', nil)))))));
  268.  
  269.     R.Assign(17, 13, 27, 15);
  270.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  271.     R.Assign(28, 13, 38, 15);
  272.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  273.  
  274.     SelectNext(False);
  275.   end;
  276.  
  277.   RezFile.Put(D, 'ReplaceDialog');
  278.   Dispose(D, Done);
  279. end;
  280.  
  281. procedure CreateSaveAsDialog;
  282. var
  283.   D: PDialog;
  284. begin
  285.   D := New(PFileDialog, Init('*.*', 'Save file as', '~N~ame',
  286.     fdOkButton + fdHelpButton + fdNoLoadDir, 101));
  287.   RezFile.Put(D, 'SaveAsDialog');
  288.   Dispose(D, Done);
  289. end;
  290.  
  291. begin
  292.   RezStream := New(PProtectedStream, Init('TVRDEMO.TVR', stCreate, 4096));
  293.   RezFile.Init(RezStream);
  294.  
  295.   RegisterObjects;
  296.   RegisterType(RStrListMaker);
  297.   RegisterViews;
  298.   RegisterMenus;
  299.   RegisterDialogs;
  300.   RegisterStdDlg;
  301.   RegisterColorSel;
  302.  
  303.   CreateStrings;
  304.   CreateMenu;
  305.   CreateStatusLine;
  306.   CreateFileOpenDialog;
  307.   CreateAboutDialog;
  308.   CreateColorSelDialog;
  309.   CreateChDirDialog;
  310.   CreateFindDialog;
  311.   CreateReplaceDialog;
  312.   CreateSaveAsDialog;
  313.  
  314.   RezFile.Done;
  315. end.
  316.