mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 20:59:06 +02:00
Improved unicode win32 dialogs.
git-svn-id: trunk@12900 -
This commit is contained in:
parent
878c6047c0
commit
e39f7d2f34
@ -328,9 +328,19 @@ var
|
|||||||
FileName: string;
|
FileName: string;
|
||||||
InitialDir: String;
|
InitialDir: String;
|
||||||
FileNameBuffer: PChar;
|
FileNameBuffer: PChar;
|
||||||
|
FileNameWide: WideString;
|
||||||
|
FileNameWideBuffer: PWideChar;
|
||||||
FilterBuffer: WideString;
|
FilterBuffer: WideString;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
FileNameWideBuffer := AllocMem(FileNameBufferLen * 2 + 2)
|
||||||
|
else
|
||||||
FileNameBuffer := AllocMem(FileNameBufferLen + 1);
|
FileNameBuffer := AllocMem(FileNameBufferLen + 1);
|
||||||
|
{$else}
|
||||||
|
FileNameBuffer := AllocMem(FileNameBufferLen + 1);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
FileName := AOpenDialog.FileName;
|
FileName := AOpenDialog.FileName;
|
||||||
InitialDir := AOpenDialog.InitialDir;
|
InitialDir := AOpenDialog.InitialDir;
|
||||||
if (FileName<>'') and (FileName[length(FileName)]=PathDelim) then
|
if (FileName<>'') and (FileName[length(FileName)]=PathDelim) then
|
||||||
@ -340,7 +350,24 @@ begin
|
|||||||
InitialDir := Copy(FileName,1, Length(FileName)-1);
|
InitialDir := Copy(FileName,1, Length(FileName)-1);
|
||||||
FileName := '';
|
FileName := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
begin
|
||||||
|
FileNameWide := UTF8Decode(FileName);
|
||||||
|
|
||||||
|
{ StrLCopy is a PChar function, so it won't create a proper 2-byte
|
||||||
|
sized ending and we ensure that it's there by cleaning the string }
|
||||||
|
FillChar(FileNameWideBuffer^, FileNameBufferLen * 2 + 2, #0);
|
||||||
|
|
||||||
|
StrLCopy(PChar(FileNameWideBuffer), PChar(PWideChar(FileNameWide)), FileNameBufferLen * 2);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
StrLCopy(FileNameBuffer, PChar(UTF8ToAnsi(FileName)), FileNameBufferLen);
|
||||||
|
{$else}
|
||||||
StrLCopy(FileNameBuffer, PChar(FileName), FileNameBufferLen);
|
StrLCopy(FileNameBuffer, PChar(FileName), FileNameBufferLen);
|
||||||
|
{$endif}
|
||||||
|
|
||||||
if AOpenDialog.Filter <> '' then
|
if AOpenDialog.Filter <> '' then
|
||||||
begin
|
begin
|
||||||
Filter := AOpenDialog.Filter;
|
Filter := AOpenDialog.Filter;
|
||||||
@ -357,11 +384,12 @@ begin
|
|||||||
hInstance := System.hInstance;
|
hInstance := System.hInstance;
|
||||||
|
|
||||||
nFilterIndex := AOpenDialog.FilterIndex;
|
nFilterIndex := AOpenDialog.FilterIndex;
|
||||||
lpStrFile := FileNameBuffer;
|
|
||||||
|
|
||||||
{$ifdef WindowsUnicodeSupport}
|
{$ifdef WindowsUnicodeSupport}
|
||||||
if UnicodeEnabledOS then
|
if UnicodeEnabledOS then
|
||||||
begin
|
begin
|
||||||
|
lpStrFile := PChar(FileNameWideBuffer);
|
||||||
|
|
||||||
FilterBuffer := Utf8Decode(Filter);
|
FilterBuffer := Utf8Decode(Filter);
|
||||||
lpStrFilter := GetMem(Length(FilterBuffer) * 2 + 2);
|
lpStrFilter := GetMem(Length(FilterBuffer) * 2 + 2);
|
||||||
Move(FilterBuffer[1], lpStrFilter^, Length(FilterBuffer) * 2 + 2);
|
Move(FilterBuffer[1], lpStrFilter^, Length(FilterBuffer) * 2 + 2);
|
||||||
@ -370,12 +398,16 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
lpStrFile := FileNameBuffer;
|
||||||
|
|
||||||
lpStrFilter := StrAlloc(Length(Filter)+1);
|
lpStrFilter := StrAlloc(Length(Filter)+1);
|
||||||
StrPCopy(lpStrFilter, Utf8ToAnsi(Filter));
|
StrPCopy(lpStrFilter, Utf8ToAnsi(Filter));
|
||||||
|
|
||||||
lpStrTitle := PChar(Utf8ToAnsi(AOpenDialog.Title));
|
lpStrTitle := PChar(Utf8ToAnsi(AOpenDialog.Title));
|
||||||
end;
|
end;
|
||||||
{$else}
|
{$else}
|
||||||
|
lpStrFile := FileNameBuffer;
|
||||||
|
|
||||||
lpStrFilter := StrAlloc(Length(Filter)+1);
|
lpStrFilter := StrAlloc(Length(Filter)+1);
|
||||||
StrPCopy(lpStrFilter, Filter);
|
StrPCopy(lpStrFilter, Filter);
|
||||||
|
|
||||||
@ -404,6 +436,28 @@ var
|
|||||||
var
|
var
|
||||||
I: integer;
|
I: integer;
|
||||||
pName: PChar;
|
pName: PChar;
|
||||||
|
PWideName: PWideChar;
|
||||||
|
begin
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
begin
|
||||||
|
PWideName := PWideChar(OpenFile^.lpStrFile);
|
||||||
|
I:=Length(PWideName);
|
||||||
|
if I < OpenFile^.nFileOffset then
|
||||||
|
begin
|
||||||
|
Inc(PWideName, I * 2 + 2);
|
||||||
|
I:=Length(PWideName);
|
||||||
|
while I > 0 do
|
||||||
|
begin
|
||||||
|
AFiles.Add(ExpandFileName(Utf8Encode(PWideName)));
|
||||||
|
Inc(PWideName, I * 2 + 2);
|
||||||
|
I:=Length(PWideName);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
AFiles.Add(Utf8Encode(PWideName));
|
||||||
|
end
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
pName := OpenFile^.lpStrFile;
|
pName := OpenFile^.lpStrFile;
|
||||||
I:=Length(pName);
|
I:=Length(pName);
|
||||||
@ -421,6 +475,24 @@ var
|
|||||||
else
|
else
|
||||||
AFiles.Add(StrPas(pName));
|
AFiles.Add(StrPas(pName));
|
||||||
end;
|
end;
|
||||||
|
{$else}
|
||||||
|
pName := OpenFile^.lpStrFile;
|
||||||
|
I:=Length(pName);
|
||||||
|
if I < OpenFile^.nFileOffset then
|
||||||
|
begin
|
||||||
|
Inc(pName,Succ(I));
|
||||||
|
I:=Length(pName);
|
||||||
|
while I > 0 do
|
||||||
|
begin
|
||||||
|
AFiles.Add(ExpandFileName(StrPas(pName)));
|
||||||
|
Inc(pName,Succ(I));
|
||||||
|
I:=Length(pName);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
AFiles.Add(StrPas(pName));
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SetFilesPropertyCustomFiles(AFiles:TStrings);
|
procedure SetFilesPropertyCustomFiles(AFiles:TStrings);
|
||||||
var
|
var
|
||||||
@ -475,22 +547,20 @@ begin
|
|||||||
if BufferTooSmall then
|
if BufferTooSmall then
|
||||||
UserResult := true;
|
UserResult := true;
|
||||||
SetDialogResult(AOpenDialog, UserResult);
|
SetDialogResult(AOpenDialog, UserResult);
|
||||||
with AOpenDialog do
|
|
||||||
begin
|
AOpenDialog.Files.Clear;
|
||||||
Files.Clear;
|
|
||||||
if UserResult then
|
if UserResult then
|
||||||
begin
|
begin
|
||||||
AOpenDialog.FilterIndex := OpenFile^.nFilterIndex;
|
AOpenDialog.FilterIndex := OpenFile^.nFilterIndex;
|
||||||
if (ofOldStyleDialog in Options) then
|
if (ofOldStyleDialog in AOpenDialog.Options) then
|
||||||
SetFilesPropertyForOldStyle(Files)
|
SetFilesPropertyForOldStyle(AOpenDialog.Files)
|
||||||
else if BufferTooSmall then
|
else if BufferTooSmall then
|
||||||
SetFilesPropertyCustomFiles(Files)
|
SetFilesPropertyCustomFiles(AOpenDialog.Files)
|
||||||
else
|
else
|
||||||
SetFilesProperty(Files);
|
SetFilesProperty(AOpenDialog.Files);
|
||||||
FileName := Files[0];
|
AOpenDialog.FileName := AOpenDialog.Files[0];
|
||||||
end else
|
end else
|
||||||
FileName := '';
|
AOpenDialog.FileName := '';
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWin32WSSaveDialog }
|
{ TWin32WSSaveDialog }
|
||||||
|
Loading…
Reference in New Issue
Block a user