{*******************************************************} { } { Delphi Visual Component Library } { } { Copyright (c) 1995,97 Borland International } { } {*******************************************************} unit PCFileDlgs; {$R-} interface uses Messages, Windows, SysUtils, Classes, Controls, StdCtrls, Graphics, ExtCtrls, Buttons, Dialogs,PCTypesUtils,GUIStrings; type { TPCOpenDialog } TPCOpenDialog = class(TOpenDialog) private FPicturePanel: TPanel; FPaintPanel: TPanel; FPaintBox: TImage; FPreviewButton: TSpeedButton; FPictureLabel : TLabel; Procedure PreviewClick(Sender: TObject); Procedure LoadDrawing; protected procedure DoClose; override; procedure DoSelectionChange; override; procedure DoShow; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; function Execute: Boolean; override; end; { TPCSaveDialog } TPCSaveDialog = class(TPCOpenDialog) function Execute: Boolean; override; end; implementation {$R *.RES} {$R *.DCR} uses Consts, Forms, CommDlg, Dlgs; { TPCOpenDialog } constructor TPCOpenDialog.Create(AOwner: TComponent); begin inherited Create(AOwner); Title := titOpenPowerCADDrawing; Filter := fltPowerCADDrawings; FilterIndex := 1; FPicturePanel := TPanel.Create(Self); with FPicturePanel do begin Name := 'PicturePanel'; Caption := ''; SetBounds(204, 5, 169, 200); BevelOuter := bvNone; BorderWidth := 6; TabOrder := 1; FPictureLabel := TLabel.Create(Self); with FPictureLabel do begin Name := 'PictureLabel'; Caption := ''; SetBounds(6, 6, 157, 23); Align := alTop; AutoSize := False; Parent := FPicturePanel; end; FPreviewButton := TSpeedButton.Create(Self); with FPreviewButton do begin Name := 'PreviewButton'; SetBounds(138, 1, 23, 22); Enabled := True; Glyph.LoadFromResourceName(HInstance, 'PGLYPH'); Hint := SPreviewLabel; ParentShowHint := False; ShowHint := True; GroupIndex := 1; AllowAllUp := True; Down := False; OnClick := PreviewClick; Parent := FPicturePanel; end; FPaintPanel := TPanel.Create(Self); with FPaintPanel do begin Name := 'PaintPanel'; Caption := ''; SetBounds(6, 29, 157, 145); Align := alClient; BevelInner := bvRaised; BevelOuter := bvLowered; TabOrder := 0; Parent := FPicturePanel; FPaintBox := TImage.Create(Self); with FPaintBox do begin Name := 'PaintBox'; SetBounds(0, 0, 153, 141); Align := alClient; Parent := FPaintPanel; Stretch := True; end; end; end; end; destructor TPCOpenDialog.Destroy; begin FPaintBox.Free; FPreviewButton.Free; FPictureLabel.Free; FPaintPanel.Free; FPicturePanel.Free; inherited Destroy; end; procedure TPCOpenDialog.DoSelectionChange; begin If FpreviewButton.Down then LoadDrawing; inherited DoSelectionChange; end; Procedure TPCOPenDialog.LoadDrawing; var FullName: string; ValidPicture: Boolean; xBmp: TBitmap; function ValidFile(const FileName: string): Boolean; begin Result := GetFileAttributes(PChar(FileName)) <> $FFFFFFFF; end; begin FullName := FileName; ValidPicture := FileExists(FullName) and ValidFile(FullName); if ValidPicture then try xbmp := GetPreviewImage(FileName); if assigned(xBmp) then FPaintbox.Picture.Bitmap := xBmp else FPaintbox.Picture.Bitmap := nil; except end; end; Procedure TPCOPenDialog.PreviewClick(Sender:TObject); Begin If FPreviewButton.down then LoadDrawing else FPaintbox.Picture.Bitmap := nil; end; procedure TPCOpenDialog.DoClose; begin inherited DoClose; { Hide any hint windows left behind } Application.HideHint; end; procedure TPCOpenDialog.DoShow; var PreviewRect, StaticRect: TRect; begin { Set preview area to entire dialog } GetClientRect(Handle, PreviewRect); StaticRect := GetStaticRect; { Move preview area to right of static area } PreviewRect.Left := StaticRect.Left + (StaticRect.Right - StaticRect.Left); Inc(PreviewRect.Top, 4); FPicturePanel.BoundsRect := PreviewRect; FPicturePanel.ParentWindow := Handle; inherited DoShow; end; //function TPCOpenDialog.Execute; function TPCOpenDialog.Execute: Boolean; begin if NewStyleControls and not (ofOldStyleDialog in Options) then Template := 'DTEMPLATE' else Template := nil; Result := inherited Execute; end; { TPCSaveDialog } function TPCSaveDialog.Execute: Boolean; begin Title := titSavePowerCADDrawing; if NewStyleControls and not (ofOldStyleDialog in Options) then Template := 'DTEMPLATE' else Template := nil; Result := DoExecute(@GetSaveFileName); end; end.