2 {*****************************************************************************}
4 { Tnt Delphi Unicode Controls }
5 { http://www.tntware.com/delphicontrols/unicode/ }
8 { Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
10 {*****************************************************************************}
14 {$INCLUDE TntCompilers.inc}
19 Classes
, Windows
, TntDialogs
, TntExtCtrls
, TntStdCtrls
, TntButtons
;
22 {TNT-WARN TOpenPictureDialog}
23 TTntOpenPictureDialog
= class(TTntOpenDialog
)
25 FPicturePanel
: TTntPanel
;
26 FPictureLabel
: TTntLabel
;
27 FPreviewButton
: TTntSpeedButton
;
28 FPaintPanel
: TTntPanel
;
29 FImageCtrl
: TTntImage
;
30 FSavedFilename
: WideString
;
31 function IsFilterStored
: Boolean;
32 procedure PreviewKeyPress(Sender
: TObject
; var Key
: Char{TNT-ALLOW Char});
34 procedure PreviewClick(Sender
: TObject
); virtual;
35 procedure DoClose
; override;
36 procedure DoSelectionChange
; override;
37 procedure DoShow
; override;
38 property ImageCtrl
: TTntImage read FImageCtrl
;
39 property PictureLabel
: TTntLabel read FPictureLabel
;
41 property Filter stored IsFilterStored
;
43 constructor Create(AOwner
: TComponent
); override;
44 function Execute
: Boolean; override;
45 {$IFDEF COMPILER_9_UP}
46 function Execute(ParentWnd
: HWND
): Boolean; override;
50 {TNT-WARN TSavePictureDialog}
51 TTntSavePictureDialog
= class(TTntOpenPictureDialog
)
53 function Execute
: Boolean; override;
54 {$IFDEF COMPILER_9_UP}
55 function Execute(ParentWnd
: HWND
): Boolean; override;
62 ExtDlgs
, {ExtDlgs is needed for a linked resource} Dialogs
, Consts
, Messages
,
63 Graphics
, Math
, Controls
, Forms
, SysUtils
, CommDlg
, TntSysUtils
, TntForms
;
65 { TTntSilentPaintPanel }
68 TTntSilentPaintPanel
= class(TTntPanel
)
70 procedure WMPaint(var Msg
: TWMPaint
); message WM_PAINT
;
73 procedure TTntSilentPaintPanel
.WMPaint(var Msg
: TWMPaint
);
78 Caption
:= SInvalidImage
;
82 { TTntOpenPictureDialog }
84 constructor TTntOpenPictureDialog
.Create(AOwner
: TComponent
);
87 Filter
:= GraphicFilter(TGraphic
);
88 FPicturePanel
:= TTntPanel
.Create(Self
);
91 Name
:= 'PicturePanel';
93 SetBounds(204, 5, 169, 200);
97 FPictureLabel
:= TTntLabel
.Create(Self
);
100 Name
:= 'PictureLabel';
102 SetBounds(6, 6, 157, 23);
105 Parent
:= FPicturePanel
;
107 FPreviewButton
:= TTntSpeedButton
.Create(Self
);
108 with FPreviewButton
do
110 Name
:= 'PreviewButton';
111 SetBounds(77, 1, 23, 22);
113 Glyph
.LoadFromResourceName(FindClassHInstance(TOpenPictureDialog
{TNT-ALLOW TOpenPictureDialog}), 'PREVIEWGLYPH');
114 Hint
:= SPreviewLabel
;
115 ParentShowHint
:= False;
117 OnClick
:= PreviewClick
;
118 Parent
:= FPicturePanel
;
120 FPaintPanel
:= TTntSilentPaintPanel
.Create(Self
);
123 Name
:= 'PaintPanel';
125 SetBounds(6, 29, 157, 145);
127 BevelInner
:= bvRaised
;
128 BevelOuter
:= bvLowered
;
130 FImageCtrl
:= TTntImage
.Create(Self
);
131 Parent
:= FPicturePanel
;
136 OnDblClick
:= PreviewClick
;
137 Parent
:= FPaintPanel
;
138 Proportional
:= True;
141 IncrementalDisplay
:= True;
147 procedure TTntOpenPictureDialog
.DoClose
;
150 { Hide any hint windows left behind }
151 Application
.HideHint
;
154 procedure TTntOpenPictureDialog
.DoSelectionChange
;
156 FullName
: WideString
;
157 ValidPicture
: Boolean;
159 function ValidFile(const FileName
: WideString
): Boolean;
161 Result
:= WideFileGetAttr(FileName
) <> $FFFFFFFF;
165 FullName
:= FileName
;
166 if FullName
<> FSavedFilename
then
168 FSavedFilename
:= FullName
;
169 ValidPicture
:= WideFileExists(FullName
) and ValidFile(FullName
);
172 FImageCtrl
.Picture
.LoadFromFile(FullName
);
173 FPictureLabel
.Caption
:= WideFormat(SPictureDesc
,
174 [FImageCtrl
.Picture
.Width
, FImageCtrl
.Picture
.Height
]);
175 FPreviewButton
.Enabled
:= True;
176 FPaintPanel
.Caption
:= '';
178 ValidPicture
:= False;
180 if not ValidPicture
then
182 FPictureLabel
.Caption
:= SPictureLabel
;
183 FPreviewButton
.Enabled
:= False;
184 FImageCtrl
.Picture
:= nil;
185 FPaintPanel
.Caption
:= srNone
;
191 procedure TTntOpenPictureDialog
.DoShow
;
193 PreviewRect
, StaticRect
: TRect
;
195 { Set preview area to entire dialog }
196 GetClientRect(Handle
, PreviewRect
);
197 StaticRect
:= GetStaticRect
;
198 { Move preview area to right of static area }
199 PreviewRect
.Left
:= StaticRect
.Left
+ (StaticRect
.Right
- StaticRect
.Left
);
200 Inc(PreviewRect
.Top
, 4);
201 FPicturePanel
.BoundsRect
:= PreviewRect
;
202 FPreviewButton
.Left
:= FPaintPanel
.BoundsRect
.Right
- FPreviewButton
.Width
- 2;
203 FImageCtrl
.Picture
:= nil;
204 FSavedFilename
:= '';
205 FPaintPanel
.Caption
:= srNone
;
206 FPicturePanel
.ParentWindow
:= Handle
;
210 function TTntOpenPictureDialog
.Execute
: Boolean;
212 if NewStyleControls
and not (ofOldStyleDialog
in Options
) then
213 Template
:= 'DLGTEMPLATE' else
215 Result
:= inherited Execute
;
218 {$IFDEF COMPILER_9_UP}
219 function TTntOpenPictureDialog
.Execute(ParentWnd
: HWND
): Boolean;
221 if NewStyleControls
and not (ofOldStyleDialog
in Options
) then
222 Template
:= 'DLGTEMPLATE' else
224 Result
:= inherited Execute(ParentWnd
);
228 function TTntOpenPictureDialog
.IsFilterStored
: Boolean;
230 Result
:= not (Filter
= GraphicFilter(TGraphic
));
233 procedure TTntOpenPictureDialog
.PreviewClick(Sender
: TObject
);
235 PreviewForm
: TTntForm
;
238 PreviewForm
:= TTntForm
.Create(Self
);
241 Name
:= 'PreviewForm';
242 BorderStyle
:= bsSizeToolWin
; // By doing this first, it will work on WINE.
244 Caption
:= SPreviewLabel
;
246 Position
:= poScreenCenter
;
247 OnKeyPress
:= PreviewKeyPress
;
248 Panel
:= TTntPanel
.Create(PreviewForm
);
254 BevelOuter
:= bvNone
;
255 BorderStyle
:= bsSingle
;
258 Parent
:= PreviewForm
;
259 DoubleBuffered
:= True;
260 with TTntImage
.Create(PreviewForm
) do
265 Proportional
:= True;
267 Picture
.Assign(FImageCtrl
.Picture
);
271 if FImageCtrl
.Picture
.Width
> 0 then
273 ClientWidth
:= Min(Monitor
.Width
* 3 div 4,
274 FImageCtrl
.Picture
.Width
+ (ClientWidth
- Panel
.ClientWidth
)+ 10);
275 ClientHeight
:= Min(Monitor
.Height
* 3 div 4,
276 FImageCtrl
.Picture
.Height
+ (ClientHeight
- Panel
.ClientHeight
) + 10);
284 procedure TTntOpenPictureDialog
.PreviewKeyPress(Sender
: TObject
; var Key
: Char{TNT-ALLOW Char});
286 if Key
= Char{TNT-ALLOW Char}(VK_ESCAPE
) then
287 (Sender
as TTntForm
).Close
;
290 { TSavePictureDialog }
291 function TTntSavePictureDialog
.Execute
: Boolean;
293 if NewStyleControls
and not (ofOldStyleDialog
in Options
) then
294 Template
:= 'DLGTEMPLATE' else
297 if (not Win32PlatformIsUnicode
) then
298 Result
:= DoExecute(@GetSaveFileNameA
)
300 Result
:= DoExecuteW(@GetSaveFileNameW
);
303 {$IFDEF COMPILER_9_UP}
304 function TTntSavePictureDialog
.Execute(ParentWnd
: HWND
): Boolean;
306 if NewStyleControls
and not (ofOldStyleDialog
in Options
) then
307 Template
:= 'DLGTEMPLATE' else
310 if (not Win32PlatformIsUnicode
) then
311 Result
:= DoExecute(@GetSaveFileNameA
, ParentWnd
)
313 Result
:= DoExecuteW(@GetSaveFileNameW
, ParentWnd
);