home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 August / VPR9708A.ISO / D3TRIAL / INSTALL / DATA.Z / DIALOGS.INT < prev    next >
Text File  |  1997-03-21  |  8KB  |  246 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {                                                       }
  6. {       Copyright (c) 1995,97 Borland International     }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit Dialogs;
  11.  
  12. {$R-}
  13.  
  14. interface
  15.  
  16. uses Windows, Messages, SysUtils, CommDlg, Classes, Graphics, Controls,
  17.   Forms, StdCtrls;
  18.  
  19. const
  20.  
  21. { Maximum number of custom colors in color dialog }
  22.  
  23.   MaxCustomColors = 16;
  24.  
  25. type
  26.  
  27. { TCommonDialog }
  28.  
  29.   TCommonDialog = class(TComponent)
  30.   protected
  31.     procedure DefaultHandler(var Message); override;
  32.     procedure WndProc(var Message: TMessage); virtual;
  33.     function MessageHook(var Msg: TMessage): Boolean; virtual;
  34.     function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; virtual;
  35.     procedure DoClose; dynamic;
  36.     procedure DoShow; dynamic;
  37.     function Execute: Boolean; virtual; abstract;
  38.     property Template: PChar;
  39.   public
  40.     constructor Create(AOwner: TComponent); override;
  41.     destructor Destroy; override;
  42.     property Handle: HWnd;
  43.   published
  44.     property Ctl3D: Boolean default True;
  45.     property HelpContext: THelpContext default 0;
  46.     property OnClose: TNotifyEvent;
  47.     property OnShow: TNotifyEvent;
  48.   end;
  49.  
  50. { TOpenDialog }
  51.  
  52.   TOpenOption = (ofReadOnly, ofOverwritePrompt, ofHideReadOnly,
  53.     ofNoChangeDir, ofShowHelp, ofNoValidate, ofAllowMultiSelect,
  54.     ofExtensionDifferent, ofPathMustExist, ofFileMustExist, ofCreatePrompt,
  55.     ofShareAware, ofNoReadOnlyReturn, ofNoTestFileCreate, ofNoNetworkButton,
  56.     ofNoLongNames, ofOldStyleDialog, ofNoDereferenceLinks);
  57.   TOpenOptions = set of TOpenOption;
  58.  
  59.   TFileEditStyle = (fsEdit, fsComboBox);
  60.  
  61.   TOpenDialog = class(TCommonDialog)
  62.   protected
  63.     procedure DefineProperties(Filer: TFiler); override;
  64.     function DoExecute(Func: Pointer): Bool;
  65.     procedure DoSelectionChange; dynamic;
  66.     procedure DoFolderChange; dynamic;
  67.     procedure DoTypeChange; dynamic;
  68.     function GetStaticRect: TRect; virtual;
  69.   public
  70.     constructor Create(AOwner: TComponent); override;
  71.     destructor Destroy; override;
  72.     function Execute: Boolean; override;
  73.     property FileEditStyle: TFileEditStyle;
  74.     property Files: TStrings;
  75.     property HistoryList: TStrings;
  76.   published
  77.     property DefaultExt: string;
  78.     property FileName: TFileName;
  79.     property Filter: string;
  80.     property FilterIndex: Integer default 1;
  81.     property InitialDir: string;
  82.     property Options: TOpenOptions default [ofHideReadOnly];
  83.     property Title: string;
  84.     property OnFolderChange: TNotifyEvent;
  85.     property OnSelectionChange: TNotifyEvent;
  86.     property OnTypeChange: TNotifyEvent;
  87.   end;
  88.  
  89. { TSaveDialog }
  90.  
  91.   TSaveDialog = class(TOpenDialog)
  92.     function Execute: Boolean; override;
  93.   end;
  94.  
  95. { TColorDialog }
  96.  
  97.   TColorDialogOption = (cdFullOpen, cdPreventFullOpen, cdShowHelp,
  98.     cdSolidColor, cdAnyColor);
  99.   TColorDialogOptions = set of TColorDialogOption;
  100.  
  101.   TCustomColors = array[0..MaxCustomColors - 1] of Longint;
  102.  
  103.   TColorDialog = class(TCommonDialog)
  104.   public
  105.     constructor Create(AOwner: TComponent); override;
  106.     destructor Destroy; override;
  107.     function Execute: Boolean; override;
  108.   published
  109.     property Color: TColor default clBlack;
  110.     property Ctl3D default False;
  111.     property CustomColors: TStrings;
  112.     property Options: TColorDialogOptions default [];
  113.   end;
  114.  
  115. { TFontDialog }
  116.  
  117.   TFontDialogOption = (fdAnsiOnly, fdTrueTypeOnly, fdEffects,
  118.     fdFixedPitchOnly, fdForceFontExist, fdNoFaceSel, fdNoOEMFonts,
  119.     fdNoSimulations, fdNoSizeSel, fdNoStyleSel,  fdNoVectorFonts,
  120.     fdShowHelp, fdWysiwyg, fdLimitSize, fdScalableOnly, fdApplyButton);
  121.   TFontDialogOptions = set of TFontDialogOption;
  122.  
  123.   TFontDialogDevice = (fdScreen, fdPrinter, fdBoth);
  124.  
  125.   TFDApplyEvent = procedure(Sender: TObject; Wnd: HWND) of object;
  126.  
  127.   TFontDialog = class(TCommonDialog)
  128.   protected
  129.     procedure Apply(Wnd: HWND); dynamic;
  130.     procedure WndProc(var Message: TMessage); override;
  131.   public
  132.     constructor Create(AOwner: TComponent); override;
  133.     destructor Destroy; override;
  134.     function Execute: Boolean; override;
  135.   published
  136.     property Font: TFont;
  137.     property Device: TFontDialogDevice default fdScreen;
  138.     property MinFontSize: Integer;
  139.     property MaxFontSize: Integer;
  140.     property Options: TFontDialogOptions default [fdEffects];
  141.     property OnApply: TFDApplyEvent;
  142.   end;
  143.  
  144. { TPrinterSetupDialog }
  145.  
  146.   TPrinterSetupDialog = class(TCommonDialog)
  147.   public
  148.     function Execute: Boolean; override;
  149.   end;
  150.  
  151. { TPrintDialog }
  152.  
  153.   TPrintRange = (prAllPages, prSelection, prPageNums);
  154.   TPrintDialogOption = (poPrintToFile, poPageNums, poSelection, poWarning,
  155.     poHelp, poDisablePrintToFile);
  156.   TPrintDialogOptions = set of TPrintDialogOption;
  157.  
  158.   TPrintDialog = class(TCommonDialog)
  159.   public
  160.     function Execute: Boolean; override;
  161.   published
  162.     property Collate: Boolean default False;
  163.     property Copies: Integer default 0;
  164.     property FromPage: Integer default 0;
  165.     property MinPage: Integer default 0;
  166.     property MaxPage: Integer default 0;
  167.     property Options: TPrintDialogOptions default [];
  168.     property PrintToFile: Boolean default False;
  169.     property PrintRange: TPrintRange default prAllPages;
  170.     property ToPage: Integer default 0;
  171.   end;
  172.  
  173. { TFindDialog }
  174.  
  175.   TFindOption = (frDown, frFindNext, frHideMatchCase, frHideWholeWord,
  176.     frHideUpDown, frMatchCase, frDisableMatchCase, frDisableUpDown,
  177.     frDisableWholeWord, frReplace, frReplaceAll, frWholeWord, frShowHelp);
  178.   TFindOptions = set of TFindOption;
  179.  
  180.   TFindReplaceFunc = function(var FindReplace: TFindReplace): HWnd stdcall;
  181.  
  182.   TFindDialog = class(TCommonDialog)
  183.   protected
  184.     function MessageHook(var Msg: TMessage): Boolean; override;
  185.     procedure Find; dynamic;
  186.     procedure Replace; dynamic;
  187.   public
  188.     constructor Create(AOwner: TComponent); override;
  189.     destructor Destroy; override;
  190.     procedure CloseDialog;
  191.     function Execute: Boolean; override;
  192.     property Left: Integer;
  193.     property Position: TPoint;
  194.     property Top: Integer;
  195.   published
  196.     property FindText: string;
  197.     property Options: TFindOptions default [frDown];
  198.     property OnFind: TNotifyEvent;
  199.   end;
  200.  
  201. { TReplaceDialog }
  202.  
  203.   TReplaceDialog = class(TFindDialog)
  204.   public
  205.     constructor Create(AOwner: TComponent); override;
  206.   published
  207.     property ReplaceText: string;
  208.     property OnReplace: TNotifyEvent;
  209.   end;
  210.  
  211. { Message dialog }
  212.  
  213. type
  214.   TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
  215.   TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
  216.     mbAll, mbNoToAll, mbYesToAll, mbHelp);
  217.   TMsgDlgButtons = set of TMsgDlgBtn;
  218.  
  219. const
  220.   mbYesNoCancel = [mbYes, mbNo, mbCancel];
  221.   mbOKCancel = [mbOK, mbCancel];
  222.   mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
  223.  
  224. function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  225.   Buttons: TMsgDlgButtons): TForm;
  226.  
  227. function MessageDlg(const Msg: string; DlgType: TMsgDlgType;
  228.   Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  229. function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
  230.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
  231. function MessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
  232.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
  233.   const HelpFileName: string): Integer;
  234.  
  235. procedure ShowMessage(const Msg: string);
  236. procedure ShowMessageFmt(const Msg: string; Params: array of const);
  237. procedure ShowMessagePos(const Msg: string; X, Y: Integer);
  238.  
  239. { Input dialog }
  240.  
  241. function InputBox(const ACaption, APrompt, ADefault: string): string;
  242. function InputQuery(const ACaption, APrompt: string;
  243.   var Value: string): Boolean;
  244.  
  245. implementation
  246.