win32: ifdef all vista open/save dialog code

git-svn-id: trunk@28265 -
This commit is contained in:
paul 2010-11-16 07:10:46 +00:00
parent 2228bf61f3
commit 05a43c2437
3 changed files with 44 additions and 15 deletions

View File

@ -253,7 +253,7 @@ type
PROPERTYKEY = _tagpropertykey; PROPERTYKEY = _tagpropertykey;
REFPROPERTYKEY = ^PROPERTYKEY; REFPROPERTYKEY = ^PROPERTYKEY;
REFPROPVARIANT = ^TPROPVARIANT; REFPROPVARIANT = ^TPROPVARIANT;
{$ifdef UseVistaDialogs}
IEnumShellItems = interface(IUnknown) IEnumShellItems = interface(IUnknown)
['{70629033-e363-4a28-a567-0db78006e6d7}'] ['{70629033-e363-4a28-a567-0db78006e6d7}']
function Next(celt: ULONG; out rgelt: IShellItem; var pceltFetched: ULONG): HResult; stdcall; function Next(celt: ULONG; out rgelt: IShellItem; var pceltFetched: ULONG): HResult; stdcall;
@ -361,7 +361,7 @@ type
function GetProperties(var ppStore: IPropertyStore): HResult; stdcall; function GetProperties(var ppStore: IPropertyStore): HResult; stdcall;
function ApplyProperties(psi: IShellItem; pStore: IPropertyStore; hwnd: HWND; pSink: IFileOperationProgressSink): HResult; stdcall; function ApplyProperties(psi: IShellItem; pStore: IPropertyStore; hwnd: HWND; pSink: IFileOperationProgressSink): HResult; stdcall;
end; end;
{$endif}
// AlphaBlend is only defined for win98&2k and up // AlphaBlend is only defined for win98&2k and up
// load dynamic and use ownfunction if not defined // load dynamic and use ownfunction if not defined

View File

@ -79,11 +79,13 @@ type
TWin32WSOpenDialog = class(TWSOpenDialog) TWin32WSOpenDialog = class(TWSOpenDialog)
public public
{$ifdef UseVistaDialogs}
class procedure SetupVistaFileDialog(ADialog: IFileDialog; const AOpenDialog: TOpenDialog); class procedure SetupVistaFileDialog(ADialog: IFileDialog; const AOpenDialog: TOpenDialog);
class function ProcessVistaDialogResult(ADialog: IFileDialog; const AOpenDialog: TOpenDialog): HResult; class function ProcessVistaDialogResult(ADialog: IFileDialog; const AOpenDialog: TOpenDialog): HResult;
class procedure VistaDialogShowModal(ADialog: IFileDialog; const AOpenDialog: TOpenDialog); class procedure VistaDialogShowModal(ADialog: IFileDialog; const AOpenDialog: TOpenDialog);
class function GetFileName(ShellItem: IShellItem): String; class function GetFileName(ShellItem: IShellItem): String;
class function GetParentWnd: HWND; class function GetParentWnd: HWND;
{$endif}
published published
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override; class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
class procedure DestroyHandle(const ACommonDialog: TCommonDialog); override; class procedure DestroyHandle(const ACommonDialog: TCommonDialog); override;
@ -127,6 +129,8 @@ type
class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override; class function CreateHandle(const ACommonDialog: TCommonDialog): THandle; override;
end; end;
{$ifdef UseVistaDialogs}
{ TFileDialogEvents } { TFileDialogEvents }
TFileDialogEvents = class(TInterfacedObject, IFileDialogEvents, IFileDialogControlEvents) TFileDialogEvents = class(TInterfacedObject, IFileDialogEvents, IFileDialogControlEvents)
@ -149,6 +153,7 @@ type
public public
constructor Create(ADialog: TOpenDialog); constructor Create(ADialog: TOpenDialog);
end; end;
{$endif}
function OpenFileDialogCallBack(Wnd: HWND; uMsg: UINT; wParam: WPARAM; function OpenFileDialogCallBack(Wnd: HWND; uMsg: UINT; wParam: WPARAM;
lParam: LPARAM): UINT; stdcall; lParam: LPARAM): UINT; stdcall;
@ -158,9 +163,6 @@ procedure RestoreApplicationState(AState: TApplicationState);
function UTF8StringToPWideChar(const s: string) : PWideChar; function UTF8StringToPWideChar(const s: string) : PWideChar;
function UTF8StringToPAnsiChar(const s: string) : PAnsiChar; function UTF8StringToPAnsiChar(const s: string) : PAnsiChar;
const
UseVistaDialogs: Boolean = {$ifdef UseVistaDialogs}True{$else}False{$endif};
implementation implementation
function SaveApplicationState: TApplicationState; function SaveApplicationState: TApplicationState;
@ -749,7 +751,7 @@ begin
end; end;
{ TWin32WSOpenDialog } { TWin32WSOpenDialog }
{$ifdef UseVistaDialogs}
class procedure TWin32WSOpenDialog.SetupVistaFileDialog(ADialog: IFileDialog; const AOpenDialog: TOpenDialog); class procedure TWin32WSOpenDialog.SetupVistaFileDialog(ADialog: IFileDialog; const AOpenDialog: TOpenDialog);
{ non-used flags { non-used flags
FOS_PICKFOLDERS FOS_PICKFOLDERS
@ -940,12 +942,16 @@ begin
else else
Result := WidgetSet.AppHandle; Result := WidgetSet.AppHandle;
end; end;
{$endif}
class function TWin32WSOpenDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle; class function TWin32WSOpenDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
{$ifdef UseVistaDialogs}
var var
Dialog: IFileOpenDialog; Dialog: IFileOpenDialog;
{$endif}
begin begin
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
if Succeeded(CoCreateInstance(CLSID_FileOpenDialog, nil, CLSCTX_INPROC_SERVER, IFileOpenDialog, Dialog)) and Assigned(Dialog) then if Succeeded(CoCreateInstance(CLSID_FileOpenDialog, nil, CLSCTX_INPROC_SERVER, IFileOpenDialog, Dialog)) and Assigned(Dialog) then
begin begin
@ -955,21 +961,26 @@ begin
end; end;
end end
else else
{$endif}
Result := CreateFileDialogHandle(TOpenDialog(ACommonDialog)); Result := CreateFileDialogHandle(TOpenDialog(ACommonDialog));
end; end;
class procedure TWin32WSOpenDialog.DestroyHandle(const ACommonDialog: TCommonDialog); class procedure TWin32WSOpenDialog.DestroyHandle(const ACommonDialog: TCommonDialog);
{$ifdef UseVistaDialogs}
var var
Dialog: IFileDialog; Dialog: IFileDialog;
{$endif}
begin begin
if ACommonDialog.Handle <> 0 then if ACommonDialog.Handle <> 0 then
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
Dialog := IFileDialog(ACommonDialog.Handle); Dialog := IFileDialog(ACommonDialog.Handle);
Dialog._Release; Dialog._Release;
Dialog := nil; Dialog := nil;
end end
else else
{$endif}
DestroyFileDialogHandle(ACommonDialog.Handle) DestroyFileDialogHandle(ACommonDialog.Handle)
end; end;
@ -977,7 +988,9 @@ class procedure TWin32WSOpenDialog.ShowModal(const ACommonDialog: TCommonDialog)
var var
State: TApplicationState; State: TApplicationState;
lOldWorkingDir, lInitialDir: string; lOldWorkingDir, lInitialDir: string;
{$ifdef UseVistaDialogs}
Dialog: IFileOpenDialog; Dialog: IFileOpenDialog;
{$endif}
begin begin
if ACommonDialog.Handle <> 0 then if ACommonDialog.Handle <> 0 then
begin begin
@ -986,12 +999,14 @@ begin
try try
lInitialDir := TOpenDialog(ACommonDialog).InitialDir; lInitialDir := TOpenDialog(ACommonDialog).InitialDir;
if lInitialDir <> '' then SetCurrentDirUTF8(lInitialDir); if lInitialDir <> '' then SetCurrentDirUTF8(lInitialDir);
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
Dialog := IFileOpenDialog(ACommonDialog.Handle); Dialog := IFileOpenDialog(ACommonDialog.Handle);
VistaDialogShowModal(Dialog, TOpenDialog(ACommonDialog)); VistaDialogShowModal(Dialog, TOpenDialog(ACommonDialog));
end end
else else
{$endif}
begin begin
{$ifdef WindowsUnicodeSupport} {$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then if UnicodeEnabledOS then
@ -1015,10 +1030,13 @@ end;
{ TWin32WSSaveDialog } { TWin32WSSaveDialog }
class function TWin32WSSaveDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle; class function TWin32WSSaveDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
{$ifdef UseVistaDialogs}
var var
Dialog: IFileSaveDialog; Dialog: IFileSaveDialog;
{$endif}
begin begin
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
if Succeeded(CoCreateInstance(CLSID_FileSaveDialog, nil, CLSCTX_INPROC_SERVER, IFileSaveDialog, Dialog)) and Assigned(Dialog) then if Succeeded(CoCreateInstance(CLSID_FileSaveDialog, nil, CLSCTX_INPROC_SERVER, IFileSaveDialog, Dialog)) and Assigned(Dialog) then
begin begin
@ -1028,6 +1046,7 @@ begin
end; end;
end end
else else
{$endif}
Result := CreateFileDialogHandle(TOpenDialog(ACommonDialog)); Result := CreateFileDialogHandle(TOpenDialog(ACommonDialog));
end; end;
@ -1035,7 +1054,9 @@ class procedure TWin32WSSaveDialog.ShowModal(const ACommonDialog: TCommonDialog)
var var
State: TApplicationState; State: TApplicationState;
lOldWorkingDir, lInitialDir: string; lOldWorkingDir, lInitialDir: string;
{$ifdef UseVistaDialogs}
Dialog: IFileSaveDialog; Dialog: IFileSaveDialog;
{$endif}
begin begin
if ACommonDialog.Handle <> 0 then if ACommonDialog.Handle <> 0 then
begin begin
@ -1044,12 +1065,14 @@ begin
try try
lInitialDir := TSaveDialog(ACommonDialog).InitialDir; lInitialDir := TSaveDialog(ACommonDialog).InitialDir;
if lInitialDir <> '' then SetCurrentDirUTF8(lInitialDir); if lInitialDir <> '' then SetCurrentDirUTF8(lInitialDir);
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
Dialog := IFileSaveDialog(ACommonDialog.Handle); Dialog := IFileSaveDialog(ACommonDialog.Handle);
TWin32WSOpenDialog.VistaDialogShowModal(Dialog, TOpenDialog(ACommonDialog)); TWin32WSOpenDialog.VistaDialogShowModal(Dialog, TOpenDialog(ACommonDialog));
end end
else else
{$endif}
begin begin
{$ifdef WindowsUnicodeSupport} {$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then if UnicodeEnabledOS then
@ -1366,6 +1389,7 @@ begin
Result := 0; Result := 0;
end; end;
{$ifdef UseVistaDialogs}
{ TFileDialogEvents } { TFileDialogEvents }
function TFileDialogEvents.OnFileOk(pfd: IFileDialog): HResult; stdcall; function TFileDialogEvents.OnFileOk(pfd: IFileDialog): HResult; stdcall;
@ -1466,6 +1490,7 @@ begin
inherited Create; inherited Create;
FDialog := ADialog; FDialog := ADialog;
end; end;
{$endif}
initialization initialization
if (Win32MajorVersion = 4) then if (Win32MajorVersion = 4) then

View File

@ -37,7 +37,7 @@ uses
Windows, Windows,
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
WSExtDlgs, WSLCLClasses, Win32WSDialogs, Win32WSControls, Win32Int, Win32Proc, WSExtDlgs, WSLCLClasses, Win32WSDialogs, Win32WSControls, Win32Int, Win32Proc,
Types, Controls, Dialogs, ExtDlgs, LCLType, Graphics, Themes; Types, Controls, Dialogs, ExtDlgs, LCLType, Graphics, Themes, Win32Extra, ShlObj;
type type
@ -171,11 +171,13 @@ end;
class function TWin32WSOpenPictureDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle; class function TWin32WSOpenPictureDialog.CreateHandle(const ACommonDialog: TCommonDialog): THandle;
begin begin
Result := inherited CreateHandle(ACommonDialog); Result := inherited CreateHandle(ACommonDialog);
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
// ? //?
end end
else else
{$endif}
AddPreviewControl(ACommonDialog, LPOPENFILENAME(Result)); AddPreviewControl(ACommonDialog, LPOPENFILENAME(Result));
end; end;
@ -205,11 +207,13 @@ class function TWin32WSSavePictureDialog.CreateHandle(
const ACommonDialog: TCommonDialog): THandle; const ACommonDialog: TCommonDialog): THandle;
begin begin
Result := inherited CreateHandle(ACommonDialog); Result := inherited CreateHandle(ACommonDialog);
if UseVistaDialogs and (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then {$ifdef UseVistaDialogs}
if (WindowsVersion >= wvVista) and ThemeServices.ThemesEnabled then
begin begin
// ? // ?
end end
else else
{$endif}
AddPreviewControl(ACommonDialog, LPOPENFILENAME(Result)); AddPreviewControl(ACommonDialog, LPOPENFILENAME(Result));
end; end;