home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TVTOOL.ZIP / TVDIALOG.INT < prev    next >
Encoding:
Text File  |  1992-10-08  |  14.3 KB  |  419 lines

  1. {*
  2. *   TvDialog.pas
  3. *
  4. *   Enhancements to Turbo Vision dialog boxes.
  5. *
  6. *   Copyright 1992 by Richard W. Hansen
  7. *
  8. *}
  9.  
  10. UNIT TvDialog;
  11. {$X+}
  12. {$V-}
  13.  
  14. {$I TVDEFS.INC}
  15.  
  16. INTERFACE
  17.  
  18.  
  19. USES
  20.   Dos,
  21.   TvColl, TvConst, TvString, TvType, TvViews,
  22.   {$IFDEF TVSCROLL}
  23.   TvScroll,
  24.   {$ENDIF}
  25.   App, Dialogs, Drivers, Memory, MsgBox, Objects, StdDlg, Views;
  26.  
  27.  
  28. CONST
  29.   { 3D Button Palette }
  30.   { 1 = Button normal }
  31.   { 2 = Button shaded }
  32.   { 3 = Button text }
  33.   { 4 = Button disabled text}
  34.   { 5 = Button shortcut text}
  35.   { 6 = Button default text }
  36.   C3DButton     = #37#41#38#39#40#42;
  37.  
  38.   { 3D Dialog Palette - additions to normal dialog palette }
  39.   { 33 = Frame normal }
  40.   { 34 = Frame shaded }
  41.   { 35 = Frame passive }
  42.   { 36 = Frame Icon/Frame dragging }
  43.   { 37 = Button normal }
  44.   { 38 = Button text }
  45.   { 39 = Button disabled text }
  46.   { 40 = Button shortcut text }
  47.   { 41 = Button shaded }
  48.   { 42 = Button default text }
  49.   { 43 = Outline normal }
  50.   { 44 = Outline shaded }
  51.   { 45 = Inputline normal }
  52.   { 46 = Inputline selected text }
  53.   { 47 = Inputline arrow }
  54.   { 48 = ListViewer normal }
  55.   { 49 = ListViewer focused }
  56.   { 50 = ListViewer selected }
  57.   { 51 = ListViewer divider }
  58.   { 52 = Reserved }
  59.   { 53 = Reserved }
  60.   { 54 = Reserved }
  61.   { 55 = Reserved }
  62.   { 56 = Reserved }
  63.   { 57 = Reserved }
  64.   { 58 = Reserved }
  65.   { 59 = Reserved }
  66.   { 60 = Reserved }
  67.   { 61 = Reserved }
  68.   C3DDialog     = CDialog + #72#73#74#75#76#77#78#79#80#81#82#83#84#85#86#87;
  69.  
  70.   { 3D Outline Palette }
  71.   { 1 = Outline normal }
  72.   { 2 = Outline shaded }
  73.   C3DOutline    = #43#44;
  74.  
  75.   { 3D ListViewer Palette }
  76.   { 1 = Active }
  77.   { 2 = Inactive }
  78.   { 3 = Focused }
  79.   { 4 = Selected }
  80.   { 5 = Divider }
  81.   C3DListViewer = #48#48#49#50#51;
  82.  
  83.  
  84.   BarChar       : Char = '▒';
  85.   BarFillChar   : Char = '█';
  86.  
  87.   ButtonSelect  : FrameArray = '╔╗╚╝║║══';
  88.   ButtonNormal1 : FrameArray = '┌┐└┘││──';
  89.   ButtonNormal2 : FrameArray = '┌╖╘╝│║─═';
  90.   ButtonPress   : FrameArray = '┌┐└┘││──';
  91.   BorderNormal  : FrameArray = '╔╗╚╝║║══';
  92.  
  93.  
  94.   Buttons       : Array[0..3] of String[8] =
  95.                     ('~Y~es', '~N~o', 'O~K~', '~C~ancel');
  96.   Commands      : Array[0..3] of Word =
  97.                     (cmYes, cmNo, cmOK, cmCancel);
  98.   Titles        : Array[0..3] of String[11] =
  99.                     ('Warning', 'Error', 'Information', 'Confirm');
  100.  
  101.   {---- These are in defined in MSGBOX.PAS -------------------------
  102.  
  103.   Message box classes
  104.  
  105.   mfWarning      = $0000;        < Display a Warning box >
  106.   mfError        = $0001;        < Dispaly a Error box   >
  107.   mfInformation  = $0002;        < Display an Information Box >
  108.   mfConfirmation = $0003;        < Display a Confirmation Box >
  109.  
  110.   Message box button flags
  111.  
  112.   mfYesButton    = $0100;        < Put a Yes button into the dialog >
  113.   mfNoButton     = $0200;        < Put a No button into the dialog  >
  114.   mfOKButton     = $0400;        < Put an OK button into the dialog >
  115.   mfCancelButton = $0800;        < Put a Cancel button into the dialog >
  116.  
  117.   mfYesNoCancel  = mfYesButton + mfNoButton + mfCancelButton;
  118.                                  < Standard Yes, No, Cancel dialog >
  119.   mfOKCancel     = mfOKButton + mfCancelButton;
  120.                                  < Standard OK, Cancel dialog >
  121.   ------------------------------------------------------------------}
  122.  
  123.   mfMessageLine  = $1000;
  124.   mfPauseButton  = $2000;
  125.   mfPauseCancel  = mfPauseButton + mfCancelButton;
  126.   mfOKPauseCancel= mfOKCancel + mfPauseButton;
  127.  
  128.  
  129. TYPE
  130.   PSearchRec = ^TSearchRec;   {why isn't this public in StdDlg?}
  131.   DriveLetters  = 'A'..'Z';
  132.   DriveSet      = Set of DriveLetters;
  133.  
  134.  
  135. TYPE
  136.   { TRunDialog is the base a object used to create progress display
  137.     dialogs. TRunDialogs do some work, while allowing the user to abort.
  138.     It was used to create the TPercentDialog and TPrintDialogs.
  139.     To use a TRunDialog you must provide a Process method. The Process
  140.     method is where the work will get done. TRunDialog.Execute will
  141.     repeated call your Process method, until there is nothing left to do.
  142.     Your Process needs to do the work in small bits, so that Execute can
  143.     run and check for user input. When all the work is done, set RunState to
  144.     pfJobComplete and Execute will terminate. If RunState is ever set to
  145.     pfJobCancel, that means the user aborted, and your Process must close
  146.     done. When you init a TRunDialog, you can choose several different
  147.     combinations of buttons. If AOptions is mfCancel only a cancel button
  148.     will be added, mfCancel and mfOk get a start and a cancel buttons. If
  149.     mfPause is added to AOptions, the dialog will also have pause
  150.     capabilities. You can display a changeable message to the user by
  151.     including mfMessageLine in AOptions. After the dialog is inited, call
  152.     SetMessage to display or change the message line.
  153.   }
  154.   PRunDialog      = ^TRunDialog;
  155.   TRunDialog      = Object(TDialog)
  156.     Msg     : PStaticText;
  157.     RunState: Word;
  158.     pfFlags : Word;
  159.     BtnRow  : Byte;
  160.     SButton : PButton;
  161.     CButton : PButton;
  162.  
  163.     Constructor Init(var Bounds   : TRect;
  164.                          ATitle   : TTitleStr;
  165.                          AMessage : String;
  166.                          AOptions : Word;
  167.                          ButtonRow: Byte);
  168.     Function    Execute: Word;                          Virtual;
  169.     Procedure   HandleEvent(var Event : TEvent);        Virtual;
  170.     Procedure   Process;                                Virtual;
  171.     Procedure   ChangeMessage(AMessage : String);
  172.   end;
  173.  
  174.  
  175.   { TPercentDialog is a descendant of TRunDialog for displaying percent
  176.     done and a progress bar. In Init AStep and ATotal are the size to
  177.     increase the completion counter by and the max (or finished) size for
  178.     the counter. Each time you want to indicate some progress, call
  179.     Increment to change the completion counter by AStep size. Alternately,
  180.     you can call IncrementBy supplying the amount to increment the count.
  181.   }
  182.   PPercentDialog  = ^TPercentDialog;
  183.   TPercentDialog  = Object(TRunDialog)
  184.     Total   : LongInt;
  185.     Count   : LongInt;
  186.     Step    : Word;
  187.     Pct     : PStaticText;
  188.     Bar     : PStaticText;
  189.  
  190.     Constructor Init(ATitle   : TTitleStr;
  191.                      AMessage : String;
  192.                      ATotal   : LongInt;
  193.                      AOptions : Word
  194.                     );
  195.     Procedure   Increment;
  196.     Procedure   IncrementBy(AStep : Word);
  197.   end;
  198.  
  199.  
  200.   { TPrintDialog is useful for printing. You must declare a Process method
  201.     to handle the actual output.
  202.   }
  203.   PPrintDialog  = ^TPrintDialog;
  204.   TPrintDialog  = Object(TRunDialog)
  205.     Constructor Init(ATitle   : TTitleStr;
  206.                      AMessage : String;
  207.                      AOptions : Word
  208.                     );
  209.  
  210.   end;
  211.  
  212.  
  213.   { PMessageDialog takes the same parameters as the MsgBox function for
  214.     displaying Title and Buttons. It does not handle formatting parameters
  215.     for strings. You can add multiple strings through multiple calls to
  216.     AddMessage. The dialog will size itself based on the text to be
  217.     displayed. There is checking in the X axis, but none in the Y axis. Just
  218.     be careful not to add to many strings.
  219.     Call Process to display the dialog.
  220.   }
  221.   PMessageDialog  = ^TMessageDialog;
  222.   TMessageDialog  = Object(TDialog)
  223.     SList   : TUnsortedStringCollection;
  224.     DOptions: Word;
  225.  
  226.     Constructor Init(AOptions : Word);
  227.     Procedure   AddMessage(St : String);
  228.     Function    Process: Word;
  229.     Destructor  Done;                                   Virtual;
  230.   end;
  231.  
  232.  
  233.   {$IFDEF NEW_FILE_DIALOG}
  234.   PNewFileCollection = ^TNewFileCollection;
  235.   TNewFileCollection = object(TFileCollection)
  236.     Function Compare(Key1, Key2: Pointer): Integer;     Virtual;
  237.   end;
  238.  
  239.  
  240.   PNewFileList = ^TNewFileList;
  241.   TNewFileList = object(TFileList)
  242.     Constructor Init(var Bounds     : TRect;
  243.                          AWildCard  : PathStr;
  244.                          AScrollBar : PScrollBar);
  245.  
  246.     Procedure   HandleEvent(var Event: TEvent);         Virtual;
  247.     Procedure   FocusItem(Item: Integer);               Virtual;
  248.  
  249.     { **************************************************
  250.       NOTE: The following method must be made virtual in
  251.       the TFileList object in the file STDDLG.PAS unit.
  252.       At line # 102 add a "virtual" declaration.
  253.       ************************************************** }
  254.     Procedure   ReadDirectory(AWildCard : PathStr);     Virtual;
  255.   end;
  256.  
  257.  
  258.   PDriveList = ^TDriveList;
  259.   TDriveList = object(TNewFileList)
  260.     Constructor Init(var Bounds     : TRect;
  261.                          AScrollBar : PScrollBar);
  262.     Procedure   GetDrives(var Drives : DriveSet);
  263.     Procedure   ReadDirectory(AWildCard : PathStr);     Virtual;
  264.     Function    GetKey(var S : String): Pointer;        Virtual;
  265.   end;
  266.  
  267.  
  268.   PNewFileInputLine = ^TNewFileInputLine;
  269.   TNewFileInputLine = object(TFileInputLine)
  270.     Procedure HandleEvent(var Event : TEvent);          Virtual;
  271.   end;
  272.  
  273.  
  274.   PNewFileInfoPane = ^TNewFileInfoPane;
  275.   TNewFileInfoPane = object(TFileInfoPane)
  276.     Procedure   Draw;                                   Virtual;
  277.   end;
  278.  
  279.  
  280.   PDirectoryInfoPane = ^TDirectoryInfoPane;
  281.   TDirectoryInfoPane = object(TView)
  282.     Constructor Init(var Bounds: TRect);
  283.     Function    GetPalette: PPalette;                   Virtual;
  284.     Procedure   HandleEvent(var Event: TEvent);         Virtual;
  285.     Procedure   Draw;                                   Virtual;
  286.   end;
  287.  
  288.  
  289.   { TNewFileDialog is a new file list dialog that implements a look that
  290.     is much closer to the "Windows" file dialog. It displays directories
  291.     and drives in a separate window from the files list. TNewFileDialog
  292.     has a display line that shows the statistics for the current file. Any
  293.     file that is opened with a double click in the file list will also be
  294.     added to the file history box, unlike the normal TV file dialog.
  295.   }
  296.   PNewFileDialog = ^TNewFileDialog;
  297.   TNewFileDialog = object(TFileDialog)
  298.     DriveList : PDriveList;
  299.  
  300.     Constructor Init(AWildCard  : TWildStr;
  301.                      ATitle     : String;
  302.                      InputName  : String;
  303.                      AOptions   : Word;
  304.                      HistoryId  : Byte);
  305.  
  306.     { **************************************************
  307.       NOTE: In TFileDialog in the unit STDDLG.PAS the
  308.       method ReadDirectory must be made PUBLIC.
  309.       At line # 153 remove the "private" declaration.
  310.       ************************************************** }
  311.   end;
  312.   {$ENDIF}
  313.  
  314.  
  315.   { TLinkedInputLine is for linking an input lines to a ListBox, like the
  316.     file name input in the file dialog box. It is just like an ordinary
  317.     input line, except that it works in conjunction with a TLinkedListBox
  318.     to update its contents whenever the focus of the list box changes.
  319.     You assign a unique command to link the input and ListBox as a parameter
  320.     to the Init constructors of each object. Each ListBox and input line must
  321.     be assigned a unique command. The default HandleEvent expects the event
  322.     InfoPtr field to be a PString, this is the default for standard list
  323.     boxes.
  324.   }
  325.   PLinkedInputLine = ^TLinkedInputLine;
  326.   TLinkedInputLine = Object(TInputLine)
  327.     LinkEvent : Word;
  328.  
  329.     Constructor Init(var Bounds   : TRect;
  330.                          AMaxLen  : Integer;
  331.                          EventCode: Word);
  332.     Procedure   HandleEvent(var Event : TEvent);              Virtual;
  333.   end;
  334.  
  335.  
  336.   { TLinkedListBox is for linking a ListBox to an input line. TLinkedListBox
  337.     works together with the TLinkedInputLine. Each time the focus in the list
  338.     changes, the ListBox will generate an event using the unique link command
  339.     assigned with Init. The event will include a pointer to the focused item
  340.     in the InfoPtr field. The TLinkedInputLine will handle the event and
  341.     extract the data it needs from the focused item and update its display.
  342.     You assign a unique command to link the input and ListBox as a parameter
  343.     to the Init constructors of each object. Each ListBox and input line must
  344.     be assigned a unique command.
  345.   }
  346.   PLinkedListBox = ^TLinkedListBox;
  347.   TLinkedListBox = object(TListBox)
  348.     LinkEvent : Word;
  349.  
  350.     Constructor Init(var Bounds     : TRect;
  351.                          ANumCols   : Word;
  352.                          AScrollBar : PScrollBar;
  353.                          EventCode  : Word);
  354.     Procedure   FocusItem(Item: Integer); virtual;
  355.   end;
  356.  
  357.  
  358.   P3DButton = ^T3DButton;
  359.   T3DButton = Object(TButton)
  360.     Down    : Boolean;
  361.  
  362.     Constructor Init(var Bounds   : TRect;
  363.                          ATitle   : TTitleStr;
  364.                          ACommand : Word;
  365.                          AFlags   : Word);
  366.     Procedure   Draw;                                     Virtual;
  367.     Procedure   HandleEvent(var Event : TEvent);          Virtual;
  368.     Procedure   DrawTitle(ATitle: TTitleStr;
  369.                           Color : Word;
  370.                           Row   : Word);
  371.     Function    GetPalette: PPalette;                     Virtual;
  372.     Procedure   GetFrame(var F : FrameArray);             Virtual;
  373.   end;
  374.  
  375.  
  376.   PToolButton = ^TToolButton;
  377.   TToolButton = Object(T3DButton)
  378.     Procedure   GetFrame(var F : FrameArray);             Virtual;
  379.   end;
  380.  
  381.  
  382.   P3DDialog = ^T3DDialog;
  383.   T3DDialog = Object(TDialog)
  384.     Procedure   InitFrame;                                Virtual;
  385.     Function    GetPalette: PPalette;                     Virtual;
  386.   end;
  387.  
  388.  
  389.   P3DOutline  = ^T3DOutline;
  390.   T3DOutline  = Object(TView)
  391.     Constructor Init(var Bounds : TRect);
  392.     Procedure   Draw;                                     Virtual;
  393.     Function    GetPalette: PPalette;                     Virtual;
  394.     Procedure   GetFrame(var F : FrameArray);             Virtual;
  395.   end;
  396.  
  397.  
  398.   PToolBar  = ^TToolBar;
  399.   TToolBar  = Object(T3DDialog)
  400.     IsVertical  : Boolean;
  401.     LastX       : Word;
  402.     LastY       : Word;
  403.  
  404.     Constructor Init(var Bounds  : TRect;
  405.                          Vertical: Boolean);
  406.     Procedure   AddTool(ATitle   : TTitleStr;
  407.                         ACommand : Word);
  408.     Procedure   SizeLimits(var Min, Max : TPoint);        Virtual;
  409.     Procedure   InitFrame;                                Virtual;
  410.   end;
  411.  
  412.  
  413.   P3DListViewer = ^T3DListViewer;
  414.   T3DListViewer = Object(TView)
  415.     Function GetPalette: PPalette;                        Virtual;
  416.   end;
  417.  
  418.  
  419.