home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Doc / DIALOGS.INT < prev    next >
Text File  |  1999-08-11  |  9KB  |  265 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1995,99 Inprise Corporation       }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit Dialogs;
  11.  
  12. {$R-,T-,H+,X+}
  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 DoClose; dynamic;
  32.     procedure DoShow; dynamic;
  33.     procedure WndProc(var Message: TMessage); virtual;
  34.     function MessageHook(var Msg: TMessage): Boolean; virtual;
  35.     function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; virtual;
  36.     function Execute: Boolean; virtual; abstract;
  37.     property Template: PChar;
  38.   public
  39.     constructor Create(AOwner: TComponent); override;
  40.     destructor Destroy; override;
  41.     procedure DefaultHandler(var Message); 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, ofEnableIncludeNotify,
  57.     ofEnableSizing);
  58.   TOpenOptions = set of TOpenOption;
  59.  
  60.   TFileEditStyle = (fsEdit, fsComboBox);
  61.   TOFNotifyEx = type CommDlg.TOFNotifyEx;
  62.   {$NODEFINE TOFNotifyEx}
  63.   TIncludeItemEvent = procedure (const OFN: TOFNotifyEx; var Include: Boolean) of object;
  64.  
  65.   TOpenDialog = class(TCommonDialog)
  66.   protected
  67.     function CanClose(var OpenFileName: TOpenFileName): Boolean;
  68.     function DoCanClose: Boolean; dynamic;
  69.     function DoExecute(Func: Pointer): Bool;
  70.     procedure DoSelectionChange; dynamic;
  71.     procedure DoFolderChange; dynamic;
  72.     procedure DoTypeChange; dynamic;
  73.     procedure DoIncludeItem(const OFN: TOFNotifyEx; var Include: Boolean); dynamic;
  74.     procedure DefineProperties(Filer: TFiler); override;
  75.     procedure GetFileNames(var OpenFileName: TOpenFileName);
  76.     function GetStaticRect: TRect; virtual;
  77.     procedure WndProc(var Message: TMessage); override;
  78.   public
  79.     constructor Create(AOwner: TComponent); override;
  80.     destructor Destroy; override;
  81.     function Execute: Boolean; override;
  82.     property FileEditStyle: TFileEditStyle;
  83.     property Files: TStrings;
  84.     property HistoryList: TStrings;
  85.   published
  86.     property DefaultExt: string;
  87.     property FileName: TFileName;
  88.     property Filter: string;
  89.     property FilterIndex: Integer default 1;
  90.     property InitialDir: string;
  91.     property Options: TOpenOptions default [ofHideReadOnly, ofEnableSizing];
  92.     property Title: string;
  93.     property OnCanClose: TCloseQueryEvent;
  94.     property OnFolderChange: TNotifyEvent;
  95.     property OnSelectionChange: TNotifyEvent;
  96.     property OnTypeChange: TNotifyEvent;
  97.     property OnIncludeItem: TIncludeItemEvent;
  98.   end;
  99.  
  100. { TSaveDialog }
  101.  
  102.   TSaveDialog = class(TOpenDialog)
  103.     function Execute: Boolean; override;
  104.   end;
  105.  
  106. { TColorDialog }
  107.  
  108.   TColorDialogOption = (cdFullOpen, cdPreventFullOpen, cdShowHelp,
  109.     cdSolidColor, cdAnyColor);
  110.   TColorDialogOptions = set of TColorDialogOption;
  111.  
  112.   TCustomColors = array[0..MaxCustomColors - 1] of Longint;
  113.  
  114.   TColorDialog = class(TCommonDialog)
  115.   public
  116.     constructor Create(AOwner: TComponent); override;
  117.     destructor Destroy; override;
  118.     function Execute: Boolean; override;
  119.   published
  120.     property Color: TColor default clBlack;
  121.     property Ctl3D default False;
  122.     property CustomColors: TStrings;
  123.     property Options: TColorDialogOptions default [];
  124.   end;
  125.  
  126. { TFontDialog }
  127.  
  128.   TFontDialogOption = (fdAnsiOnly, fdTrueTypeOnly, fdEffects,
  129.     fdFixedPitchOnly, fdForceFontExist, fdNoFaceSel, fdNoOEMFonts,
  130.     fdNoSimulations, fdNoSizeSel, fdNoStyleSel,  fdNoVectorFonts,
  131.     fdShowHelp, fdWysiwyg, fdLimitSize, fdScalableOnly, fdApplyButton);
  132.   TFontDialogOptions = set of TFontDialogOption;
  133.  
  134.   TFontDialogDevice = (fdScreen, fdPrinter, fdBoth);
  135.  
  136.   TFDApplyEvent = procedure(Sender: TObject; Wnd: HWND) of object;
  137.  
  138.   TFontDialog = class(TCommonDialog)
  139.   protected
  140.     procedure Apply(Wnd: HWND); dynamic;
  141.     procedure WndProc(var Message: TMessage); override;
  142.   public
  143.     constructor Create(AOwner: TComponent); override;
  144.     destructor Destroy; override;
  145.     function Execute: Boolean; override;
  146.   published
  147.     property Font: TFont;
  148.     property Device: TFontDialogDevice default fdScreen;
  149.     property MinFontSize: Integer;
  150.     property MaxFontSize: Integer;
  151.     property Options: TFontDialogOptions default [fdEffects];
  152.     property OnApply: TFDApplyEvent;
  153.   end;
  154.  
  155. { TPrinterSetupDialog }
  156.  
  157.   TPrinterSetupDialog = class(TCommonDialog)
  158.   public
  159.     function Execute: Boolean; override;
  160.   end;
  161.  
  162. { TPrintDialog }
  163.  
  164.   TPrintRange = (prAllPages, prSelection, prPageNums);
  165.   TPrintDialogOption = (poPrintToFile, poPageNums, poSelection, poWarning,
  166.     poHelp, poDisablePrintToFile);
  167.   TPrintDialogOptions = set of TPrintDialogOption;
  168.  
  169.   TPrintDialog = class(TCommonDialog)
  170.   public
  171.     function Execute: Boolean; override;
  172.   published
  173.     property Collate: Boolean default False;
  174.     property Copies: Integer default 0;
  175.     property FromPage: Integer default 0;
  176.     property MinPage: Integer default 0;
  177.     property MaxPage: Integer default 0;
  178.     property Options: TPrintDialogOptions default [];
  179.     property PrintToFile: Boolean default False;
  180.     property PrintRange: TPrintRange default prAllPages;
  181.     property ToPage: Integer default 0;
  182.   end;
  183.  
  184. { TFindDialog }
  185.  
  186.   TFindOption = (frDown, frFindNext, frHideMatchCase, frHideWholeWord,
  187.     frHideUpDown, frMatchCase, frDisableMatchCase, frDisableUpDown,
  188.     frDisableWholeWord, frReplace, frReplaceAll, frWholeWord, frShowHelp);
  189.   TFindOptions = set of TFindOption;
  190.  
  191.   TFindReplaceFunc = function(var FindReplace: TFindReplace): HWnd stdcall;
  192.  
  193.   TFindDialog = class(TCommonDialog)
  194.   protected
  195.     function MessageHook(var Msg: TMessage): Boolean; override;
  196.     procedure Find; dynamic;
  197.     procedure Replace; dynamic;
  198.   public
  199.     constructor Create(AOwner: TComponent); override;
  200.     destructor Destroy; override;
  201.     procedure CloseDialog;
  202.     function Execute: Boolean; override;
  203.     property Left: Integer;
  204.     property Position: TPoint;
  205.     property Top: Integer;
  206.   published
  207.     property FindText: string;
  208.     property Options: TFindOptions default [frDown];
  209.     property OnFind: TNotifyEvent;
  210.   end;
  211.  
  212. { TReplaceDialog }
  213.  
  214.   TReplaceDialog = class(TFindDialog)
  215.   public
  216.     constructor Create(AOwner: TComponent); override;
  217.   published
  218.     property ReplaceText;
  219.     property OnReplace;
  220.   end;
  221.  
  222. { Message dialog }
  223.  
  224. type
  225.   TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
  226.   TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
  227.     mbAll, mbNoToAll, mbYesToAll, mbHelp);
  228.   TMsgDlgButtons = set of TMsgDlgBtn;
  229.  
  230. const
  231.   mbYesNoCancel = [mbYes, mbNo, mbCancel];
  232.   mbOKCancel = [mbOK, mbCancel];
  233.   mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
  234.  
  235. function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  236.   Buttons: TMsgDlgButtons): TForm;
  237.  
  238. function MessageDlg(const Msg: string; DlgType: TMsgDlgType;
  239.   Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
  240. function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
  241.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
  242. function MessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
  243.   Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
  244.   const HelpFileName: string): Integer;
  245.  
  246. procedure ShowMessage(const Msg: string);
  247. procedure ShowMessageFmt(const Msg: string; Params: array of const);
  248. procedure ShowMessagePos(const Msg: string; X, Y: Integer);
  249.  
  250. { Input dialog }
  251.  
  252. function InputBox(const ACaption, APrompt, ADefault: string): string;
  253. function InputQuery(const ACaption, APrompt: string;
  254.   var Value: string): Boolean;
  255.  
  256. { Win98 and Win2k will default to the "My Documents" folder if the InitialDir
  257.   property is empty and no files of the filtered type are contained in the
  258.   current directory. Set this flag to True to force TOpenDialog and descendents
  259.   to always open in the current directory when InitialDir is empty. (Same
  260.   behavior as setting InitialDir to '.') }
  261. var
  262.   ForceCurrentDirectory: Boolean = False;
  263.  
  264. implementation
  265.