/
JvDialogs.pas
663 lines (585 loc) · 19.4 KB
/
JvDialogs.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDialogs.PAS, released Oct 10, 1999.
The Initial Developer of the Original Code is Petr Vones (petr dott v att mujmail dott cz)
Portions created by Petr Vones are Copyright (C) 1999 Petr Vones.
Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
All Rights Reserved.
Contributor(s): Debbie Gregory <Debbie.Gregory att cmsis dott com>
Marcel van Brakel <brakelm att bart dott nl>.
Current Version: 0.50
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvDialogs;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
JVCLVer;
type
TJvOpenDialogAC = (acEdit, acListView);
TJvOpenDialogAS = (asSmallIcon, asReport);
TDialogErrorEvent = procedure(Sender: TObject; ErrorCode:Cardinal) of object;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvOpenDialog = class(TOpenDialog)
private
FAboutJVCL: TJVCLAboutInfo;
FActiveControl: TJvOpenDialogAC;
FActiveStyle: TJvOpenDialogAS;
FActiveSettingDone: Boolean;
FAutoSize: Boolean;
FDefBtnCaption: string;
FFilterLabelCaption: string;
FInitialSize: TSize;
FMakeResizeable: Boolean;
FOriginalRect: TRect;
FParentWndInstance, FOldParentWndInstance: Pointer;
FParentWnd: THandle;
FOnShareViolation: TCloseQueryEvent;
FHeight: Integer;
FWidth: Integer;
FUseUserSize: Boolean;
FOnError: TDialogErrorEvent;
procedure CenterAndSize;
function DoActiveSetting: Boolean;
procedure WMNCDestroy(var Msg: TWMNCDestroy); message WM_NCDESTROY;
procedure SetDefBtnCaption(const Value: string);
procedure SetFilterLabelCaption(const Value: string);
protected
procedure DoFolderChange; override;
function DoShareViolation: Boolean; dynamic;
procedure DoShow; override;
function GetLocalizedSizeCommand: string;
procedure ParentResize; dynamic;
procedure ParentWndProc(var Msg: TMessage); virtual;
function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; override;
procedure UpdateCaptions;
procedure UpdateControlPos; dynamic;
procedure WndProc(var Msg: TMessage); override;
protected
procedure DoError(ErrorCode:Cardinal);virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property ParentWnd: THandle read FParentWnd;
procedure SelectFolder(const FolderName: string);
property Template;
published
property AboutJVCL: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored False;
property ActiveControl: TJvOpenDialogAC read FActiveControl write FActiveControl default acEdit;
property ActiveStyle: TJvOpenDialogAS read FActiveStyle write FActiveStyle default asSmallIcon;
property AutoSize: Boolean read FAutoSize write FAutoSize default False;
property DefBtnCaption: string read FDefBtnCaption write SetDefBtnCaption;
property FilterLabelCaption: string read FFilterLabelCaption write SetFilterLabelCaption;
property Height: Integer read FHeight write FHeight;
property UseUserSize: Boolean read FUseUserSize write FUseUserSize default False;
property Width: Integer read FWidth write FWidth;
property OnError: TDialogErrorEvent read FOnError write FOnError;
property OnShareViolation: TCloseQueryEvent read FOnShareViolation write FOnShareViolation;
end;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvSaveDialog = class(TJvOpenDialog)
function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; override;
end;
TJvCDQueryEvent = procedure(Sender: TObject; SelectedColor: TColor; var Accept: Boolean) of object;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvColorDialog = class(TColorDialog)
private
FAboutJVCL: TJVCLAboutInfo;
FColorOkMessage: DWORD;
FSetRBGMessage: DWORD;
FOnQueryColor: TJvCDQueryEvent;
procedure WMNCDestroy(var Msg: TWMNCDestroy); message WM_NCDESTROY;
protected
procedure DoClose; override;
procedure DoShow; override;
function DoQueryColor(Color: TColor): Boolean; dynamic;
function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; override;
public
constructor Create(AOwner: TComponent); override;
procedure SelectColor(Color: TColor);
published
property AboutJVCL: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored False;
property OnQueryColor: TJvCDQueryEvent read FOnQueryColor write FOnQueryColor;
end;
var
JvDialogsUseFixW2k: Boolean = True;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
CommDlg, CommCtrl, Dlgs,
Types, SysUtils, Math,
JclSysInfo,
{$IFNDEF COMPILER12_UP}
JvJCLUtils, // SetWindowLongPtr
{$ENDIF ~COMPILER12_UP}
JvJVCLUtils;
const
btnOk = 1;
btnCancel = 2;
var
W2kFixMsAcmLibrary: THandle = 0;
function IsWin2kOrAbove: Boolean;
begin
Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and JclCheckWinVersion(5, 0);
end;
procedure UninstallW2kFix;
begin
if W2kFixMsAcmLibrary > 0 then
begin
FreeLibrary(W2kFixMsAcmLibrary);
W2kFixMsAcmLibrary := 0;
end;
end;
procedure InstallW2kFix;
begin
if JvDialogsUseFixW2k and IsWin2K and (W2kFixMsAcmLibrary = 0) then
W2kFixMsAcmLibrary := SafeLoadLibrary('msacm32.dll');
end;
//=== { TJvOpenDialog } ======================================================
constructor TJvOpenDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActiveControl := acEdit;
FActiveStyle := asSmallIcon;
FMakeResizeable := GetWindowsVersion in [wvWin95, wvWin95OSR2, wvWinNT4];
FParentWndInstance := JvMakeObjectInstance(ParentWndProc);
FParentWndInstance := JvMakeObjectInstance(ParentWndProc);
end;
destructor TJvOpenDialog.Destroy;
begin
JvFreeObjectInstance(FParentWndInstance);
inherited Destroy;
end;
procedure TJvOpenDialog.CenterAndSize;
var
Monitor: TMonitor;
begin
if UseUserSize then
begin
if Application.MainForm <> nil then
Monitor := Application.MainForm.Monitor
else
Monitor := Screen.Monitors[0];
SetWindowPos(FParentWnd, 0,
Monitor.Left + ((Monitor.Width - Width) div 2),
Monitor.Top + ((Monitor.Height - Height) div 3),
Width, Height,
SWP_NOACTIVATE or SWP_NOZORDER);
end;
end;
function TJvOpenDialog.DoActiveSetting: Boolean;
var
DefViewWnd, ListViewWnd: HWND;
begin
Result := False;
if not FActiveSettingDone then
begin
DefViewWnd := FindWindowEx(FParentWnd, 0, PChar('SHELLDLL_DefView'), nil);
ListViewWnd := FindWindowEx(DefViewWnd, 0, PChar('SysListView32'), nil);
if (DefViewWnd <> 0) and (ListViewWnd <> 0) then
begin
if FActiveStyle = asReport then
SendMessage(DefViewWnd, WM_COMMAND, $702C, 0);
if FActiveControl = acListView then
begin
SetFocus(ListViewWnd);
PostMessage(ListViewWnd, WM_KEYDOWN, VK_SPACE, 0);
end;
FActiveSettingDone := True;
CenterAndSize;
Result := True;
end;
end;
end;
procedure TJvOpenDialog.DoFolderChange;
begin
DoActiveSetting;
inherited DoFolderChange;
end;
function TJvOpenDialog.DoShareViolation: Boolean;
begin
Result := True;
if Assigned(FOnShareViolation) then
FOnShareViolation(Self, Result);
end;
procedure TJvOpenDialog.DoShow;
var
SysMenu: HMENU;
R: TRect;
begin
FParentWnd := GetParent(Handle);
GetClientRect(FParentWnd, FOriginalRect);
GetWindowRect(FParentWnd, R);
FInitialSize.cx := R.Right - R.Left;
FInitialSize.cy := R.Bottom - R.Top;
Width := Max(Width, FInitialSize.cx);
Height := Max(Height, FInitialSize.cy);
if FMakeResizeable and (ofEnableSizing in Options) then
begin
SetWindowLong(ParentWnd, GWL_STYLE, GetWindowLong(ParentWnd, GWL_STYLE) or WS_THICKFRAME);
SetWindowPos(ParentWnd, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or
SWP_FRAMECHANGED or SWP_DRAWFRAME or SWP_NOCOPYBITS);
SysMenu := GetSystemMenu(ParentWnd, False);
InsertMenu(SysMenu, SC_CLOSE, MF_BYCOMMAND, SC_SIZE, PChar(GetLocalizedSizeCommand));
FOldParentWndInstance := Pointer(SetWindowLongPtr(FParentWnd, GWL_WNDPROC, LONG_PTR(FParentWndInstance)));
UpdateControlPos;
end;
UpdateCaptions;
inherited DoShow;
end;
function TJvOpenDialog.GetLocalizedSizeCommand: string;
var
SysMenu: HMENU;
begin
if not (csDesigning in ComponentState) and Assigned(Application.MainForm) then
begin
SysMenu := GetSystemMenu(Application.MainForm.Handle, False);
SetString(Result, nil, 50);
GetMenuString(SysMenu, SC_SIZE, PChar(Result), 50, MF_BYCOMMAND);
Result := PChar(Result);
end
else
Result := '';
if Result = '' then
Result := 'Size'; // do not localize
end;
procedure TJvOpenDialog.ParentResize;
begin
InvalidateRect(ParentWnd, nil, False);
UpdateControlPos;
end;
procedure TJvOpenDialog.ParentWndProc(var Msg: TMessage);
const
SizeGripRectSize = 15;
function SizeGripRect: TRect;
begin
GetClientRect(ParentWnd, Result);
SetRect(Result, Result.Right - SizeGripRectSize, Result.Bottom - SizeGripRectSize,
Result.Right, Result.Bottom);
end;
procedure PaintSizeGrip;
var
PS: TPaintStruct;
DC: HDC;
R: TRect;
Pen, SavePen: HPen;
I: Integer;
begin
DC := BeginPaint(ParentWnd, PS);
R := SizeGripRect;
Pen := CreatePen(PS_SOLID, 1, ColorToRGB(clBtnShadow));
SavePen := SelectObject(DC, Pen);
for I := 0 to (SizeGripRectSize - 2) div 4 do
begin
MoveToEx(DC, R.Right, R.Bottom - (I * 4), nil);
LineTo(DC, R.Right - (I * 4), R.Bottom);
MoveToEx(DC, R.Right, R.Bottom - (I * 4) - 1, nil);
LineTo(DC, R.Right - (I * 4) - 1, R.Bottom);
end;
SelectObject(DC, SavePen);
DeleteObject(Pen);
Pen := CreatePen(PS_SOLID, 1, ColorToRGB(clWindow));
SavePen := SelectObject(DC, Pen);
for I := 0 to (SizeGripRectSize - 2) div 4 do
begin
MoveToEx(DC, R.Right, R.Bottom - (I * 4) - 2, nil);
LineTo(DC, R.Right - (I * 4) - 2, R.Bottom);
end;
SelectObject(DC, SavePen);
DeleteObject(Pen);
EndPaint(ParentWnd, PS);
end;
begin
with Msg do
begin
case Msg of
{ WM_SIZE:
ParentResize;}
WM_GETMINMAXINFO:
with PMinMaxInfo(LParam)^ do
begin
ptMinTrackSize.X := FInitialSize.cx;
ptMinTrackSize.Y := FInitialSize.cy;
end;
WM_PAINT:
PaintSizeGrip;
end;
Result := CallWindowProc(FOldParentWndInstance, FParentWnd, Msg, WParam, LParam);
if Msg = WM_SIZE then
ParentResize;
end;
end;
procedure TJvOpenDialog.SetDefBtnCaption(const Value: string);
begin
if FDefBtnCaption <> Value then
begin
FDefBtnCaption := Value;
if FParentWnd <> 0 then
UpdateCaptions;
end;
end;
procedure TJvOpenDialog.SetFilterLabelCaption(const Value: string);
begin
if FFilterLabelCaption <> Value then
begin
FFilterLabelCaption := Value;
if FParentWnd <> 0 then
UpdateCaptions;
end;
end;
procedure TJvOpenDialog.SelectFolder(const FolderName: string);
var
LastFocus: HWND;
begin
if ParentWnd = 0 then
Exit;
LastFocus := GetFocus;
SendMessage(ParentWnd, CDM_SETCONTROLTEXT, edt1, LPARAM(PChar(FolderName)));
SendMessage(GetDlgItem(ParentWnd, btnOk), BM_CLICK, 0, 0);
SendMessage(ParentWnd, CDM_SETCONTROLTEXT, edt1, 0);
SetFocus(LastFocus);
end;
function TJvOpenDialog.TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool;
begin
TOpenFileName(DialogData).hInstance := FindClassHInstance(Self.ClassType);
FActiveSettingDone := False;
if IsWin2kOrAbove then
begin
if ActiveStyle = asReport then
InstallW2kFix;
Result := inherited TaskModalDialog(DialogFunc, DialogData);
end
else
Result := inherited TaskModalDialog(DialogFunc, DialogData);
if not Result then
DoError(CommDlgExtendedError);
end;
procedure TJvOpenDialog.UpdateCaptions;
begin
if Length(FDefBtnCaption) > 0 then
SendMessage(ParentWnd, CDM_SETCONTROLTEXT, btnOk, LPARAM(PChar(DefBtnCaption)));
if Length(FFilterLabelCaption) > 0 then
SendMessage(ParentWnd, CDM_SETCONTROLTEXT, stc2, LPARAM(PChar(FilterLabelCaption)));
end;
procedure TJvOpenDialog.UpdateControlPos;
var
WRect: TRect;
CtrlWnd: HWND;
OfsSize: TPoint;
CLeft, CTop, CWidth, CHeight: Integer;
DeferHandle: HDWP;
function GetDlgWndInfo(Wnd: HWND): Boolean;
var
Rect: TRect;
begin
Result := Wnd <> 0;
if not Result then
Exit;
CtrlWnd := Wnd;
GetWindowRect(CtrlWnd, Rect);
MapWindowPoints(0, ParentWnd, Rect, 2);
CLeft := Rect.Left;
CTop := Rect.Top;
CWidth := Rect.Right - Rect.Left;
CHeight := Rect.Bottom - Rect.Top;
end;
function GetDlgItemInfo(ItemNum: Integer): Boolean;
begin
Result := GetDlgWndInfo(GetDlgItem(ParentWnd, ItemNum));
end;
begin
GetClientRect(ParentWnd, WRect);
OfsSize.X := (WRect.Right - WRect.Left) - (FOriginalRect.Right - FOriginalRect.Left);
OfsSize.Y := (WRect.Bottom - WRect.Top) - (FOriginalRect.Bottom - FOriginalRect.Top);
FOriginalRect := WRect;
DeferHandle := BeginDeferWindowPos(12);
GetDlgItemInfo(btnOk); // Default Button
Inc(CLeft, OfsSize.X);
Inc(CTop, OfsSize.Y);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(btnCancel); // Cancel Button
Inc(CLeft, OfsSize.X);
Inc(CTop, OfsSize.Y);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(pshHelp); // Help Button
Inc(CLeft, OfsSize.X);
Inc(CTop, OfsSize.Y);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(edt1); // Filename
Inc(CTop, OfsSize.Y);
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER);
GetDlgItemInfo(cmb1); // File Type
Inc(CTop, OfsSize.Y);
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER);
GetDlgItemInfo(chx1); // Read-only Checkbox
Inc(CTop, OfsSize.Y);
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(stc2); // File Type Label
Inc(CTop, OfsSize.Y);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(stc3); // Filename Label
Inc(CTop, OfsSize.Y);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
GetDlgItemInfo(cmb2); // Folder combobox
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, 0, 0, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE);
if GetDlgItemInfo(lst2) then // ListView run
begin
Inc(CHeight, OfsSize.Y);
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, 0, 0, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE);
end;
if GetDlgItemInfo(lst1) then // ListView init
begin
Inc(CHeight, OfsSize.Y);
Inc(CWidth, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, 0, 0, CWidth, CHeight,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE);
end;
if GetDlgWndInfo(FindWindowEx(FParentWnd, 0, TOOLBARCLASSNAME, nil)) then
begin
Inc(CLeft, OfsSize.X);
DeferHandle := DeferWindowPos(DeferHandle, CtrlWnd, 0, CLeft, CTop, 0, 0,
SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOSIZE);
end;
EndDeferWindowPos(DeferHandle);
end;
procedure TJvOpenDialog.WMNCDestroy(var Msg: TWMNCDestroy);
begin
FParentWnd := 0;
inherited;
end;
procedure TJvOpenDialog.WndProc(var Msg: TMessage);
const
ShareViolResult: array [Boolean] of DWORD = (OFN_SHARENOWARN, OFN_SHAREFALLTHROUGH);
begin
with Msg do
case Msg of
WM_ENTERIDLE:
DoActiveSetting;
WM_NOTIFY:
case POFNotify(LParam)^.hdr.code of
CDN_SHAREVIOLATION:
if Assigned(FOnShareViolation) then
begin
Result := ShareViolResult[DoShareViolation];
SetWindowLong(Handle, DWL_MSGRESULT, Result);
Exit;
end;
end;
end;
inherited;
end;
procedure TJvOpenDialog.DoError(ErrorCode: Cardinal);
begin
if Assigned(FOnError) then
FOnError(Self, ErrorCode);
end;
//=== { TJvSaveDialog } ======================================================
function TJvSaveDialog.TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool;
begin
DialogFunc := @GetSaveFileName;
Result := inherited TaskModalDialog(DialogFunc, DialogData);
end;
//=== { TJvColorDialog } =====================================================
var
GlobalColorDialog: TJvColorDialog = nil;
OldColorDialogHookProc: Pointer = nil;
function ColorDialogHook(Wnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): {$IFDEF RTL230_UP}UINT_PTR{$ELSE}UINT{$ENDIF RTL230_UP}; stdcall;
begin
if Assigned(GlobalColorDialog) and (Msg = GlobalColorDialog.FColorOkMessage) then
Result := Integer(not GlobalColorDialog.DoQueryColor(TColor(PChooseColor(LParam)^.rgbResult)))
else
Result := CallWindowProc(OldColorDialogHookProc, Wnd, Msg, WParam, LParam);
end;
constructor TJvColorDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FColorOkMessage := RegisterWindowMessage(COLOROKSTRING);
FSetRBGMessage := RegisterWindowMessage(SETRGBSTRING);
end;
procedure TJvColorDialog.DoClose;
begin
GlobalColorDialog := nil;
inherited DoClose;
end;
function TJvColorDialog.DoQueryColor(Color: TColor): Boolean;
begin
Result := True;
if Assigned(FOnQueryColor) then
FOnQueryColor(Self, Color, Result);
end;
procedure TJvColorDialog.DoShow;
begin
GlobalColorDialog := Self;
inherited DoShow;
end;
procedure TJvColorDialog.SelectColor(Color: TColor);
begin
if Handle <> 0 then
SendMessage(Handle, FSetRBGMessage, 0, ColorToRGB(Color));
end;
function TJvColorDialog.TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool;
begin
with TChooseColor(DialogData) do
begin
OldColorDialogHookProc := @lpfnHook;
lpfnHook := ColorDialogHook;
end;
Result := inherited TaskModalDialog(DialogFunc, DialogData);
end;
procedure TJvColorDialog.WMNCDestroy(var Msg: TWMNCDestroy);
begin
inherited;
OldColorDialogHookProc := nil;
end;
initialization
{$IFDEF UNITVERSIONING}
RegisterUnitVersion(HInstance, UnitVersioning);
{$ENDIF UNITVERSIONING}
finalization
UninstallW2kFix;
{$IFDEF UNITVERSIONING}
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.