From 1c99781bc582dd9ebba1bfa497ee37c6f91f06c6 Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 14 Nov 2006 00:31:49 +0000 Subject: [PATCH] * Modified utf patch from Felipe Monteiro de Carvalho git-svn-id: trunk@10196 - --- lcl/interfaces/win32/win32callback.inc | 14 ++++-- lcl/interfaces/win32/win32object.inc | 60 ++++++++++++++++++------- lcl/interfaces/win32/win32proc.pp | 41 ++++++++++++++--- lcl/interfaces/win32/win32wscontrols.pp | 20 ++++++++- 4 files changed, 109 insertions(+), 26 deletions(-) diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index 499dee71a7..5b2eca1185 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -81,8 +81,12 @@ begin MessageStackDepth[depthLen] := '#'; {$endif} PrevWndProc := GetWindowInfo(Window)^.DefWndProc; - if PrevWndProc = nil then - Result := Windows.DefWindowProc(Window, Msg, WParam, LParam) + if PrevWndProc = nil + then begin + if UnicodeEnabledOS + then Result := Windows.DefWindowProcW(Window, Msg, WParam, LParam) + else Result := Windows.DefWindowProc(Window, Msg, WParam, LParam) + end else begin // combobox child edit weirdness: combobox handling WM_SIZE will compare text // to list of strings, and if appears in there, will set the text, and select it @@ -2127,8 +2131,10 @@ begin // free our own data associated with window DisposeWindowInfo(Window); end; - else - Result := Windows.DefWindowProc(Window, Msg, WParam, LParam); + else + if UnicodeEnabledOS + then Result := Windows.DefWindowProcW(Window, Msg, WParam, LParam) + else Result := Windows.DefWindowProc(Window, Msg, WParam, LParam); end; end; diff --git a/lcl/interfaces/win32/win32object.inc b/lcl/interfaces/win32/win32object.inc index df19a6ab17..46374dd487 100644 --- a/lcl/interfaces/win32/win32object.inc +++ b/lcl/interfaces/win32/win32object.inc @@ -409,7 +409,13 @@ End; procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin + {$ifdef WindowsUnicodeSupport} + if UnicodeEnabledOS + then Windows.SetWindowTextW(FAppHandle, Utf8ToPWideChar(ATitle)) + else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); + {$else} Windows.SetWindowText(FAppHandle, PChar(ATitle)); + {$endif} end; {------------------------------------------------------------------------------ @@ -499,24 +505,46 @@ end; Function TWin32WidgetSet.WinRegister: Boolean; Var WindowClass: WndClass; + WindowClassW: WndClassW; Begin Assert(False, 'Trace:WinRegister - Start'); - With WindowClass Do - Begin - Style := CS_DBLCLKS{CS_HRedraw or CS_VRedraw}; - LPFnWndProc := @WindowProc; - CbClsExtra := 0; - CbWndExtra := 0; - hInstance := System.HInstance; - hIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); - if hIcon = 0 then - hIcon := Windows.LoadIcon(0, IDI_APPLICATION); - hCursor := LoadCursor(0, IDC_ARROW); - hbrBackground := 0; {GetSysColorBrush(Color_BtnFace);} - LPSzMenuName := Nil; - LPSzClassName := @ClsName; - End; - Result := Windows.RegisterClass(@WindowClass) <> 0; + if UnicodeEnabledOS + then begin + with WindowClassW do + begin + Style := CS_DBLCLKS{CS_HRedraw or CS_VRedraw}; + LPFnWndProc := @WindowProc; + CbClsExtra := 0; + CbWndExtra := 0; + hInstance := System.HInstance; + hIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); + if hIcon = 0 then + hIcon := Windows.LoadIcon(0, IDI_APPLICATION); + hCursor := LoadCursor(0, IDC_ARROW); + hbrBackground := 0; {GetSysColorBrush(Color_BtnFace);} + LPSzMenuName := Nil; + LPSzClassName := Utf8PCharToPWideChar(@ClsName); + end; + Result := Windows.RegisterClassW(@WindowClassW) <> 0; + end + else begin + with WindowClass do + begin + Style := CS_DBLCLKS{CS_HRedraw or CS_VRedraw}; + LPFnWndProc := @WindowProc; + CbClsExtra := 0; + CbWndExtra := 0; + hInstance := System.HInstance; + hIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); + if hIcon = 0 then + hIcon := Windows.LoadIcon(0, IDI_APPLICATION); + hCursor := LoadCursor(0, IDC_ARROW); + hbrBackground := 0; {GetSysColorBrush(Color_BtnFace);} + LPSzMenuName := Nil; + LPSzClassName := @ClsName; + end; + Result := Windows.RegisterClass(@WindowClass) <> 0; + end; Assert(False, 'Trace:WinRegister - Exit'); End; diff --git a/lcl/interfaces/win32/win32proc.pp b/lcl/interfaces/win32/win32proc.pp index 52873982e5..1af90d76e4 100644 --- a/lcl/interfaces/win32/win32proc.pp +++ b/lcl/interfaces/win32/win32proc.pp @@ -107,6 +107,11 @@ procedure RedrawMenus; function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean; function GetControlText(AHandle: HWND): string; +// String functions + +function Utf8PCharToPWideChar(param: PChar): PWideChar; +function Utf8ToPWideChar(param: string): PWideChar; + type PDisableWindowsInfo = ^TDisableWindowsInfo; TDisableWindowsInfo = record @@ -118,6 +123,7 @@ var DefaultWindowInfo: TWindowInfo; WindowInfoAtom: ATOM; ChangedMenus: TList; // list of HWNDs which menus needs to be redrawn + UnicodeEnabledOS: Boolean = False; implementation @@ -1130,6 +1136,34 @@ begin GetWindowText(AHandle, PChar(Result), TextLen + 1); end; +function Utf8PCharToPWideChar(param: PChar): PWideChar; +begin + Result := PWideChar(Utf8Decode(string(param))); +end; + +function Utf8ToPWideChar(param: string): PWideChar; +begin + Result := PWideChar(Utf8Decode(param)); +end; + +procedure DoInitialization; +var + WinVersion: TOSVersionInfo; +begin + FillChar(DefaultWindowInfo, sizeof(DefaultWindowInfo), 0); + DefaultWindowInfo.DrawItemIndex := -1; + WindowInfoAtom := Windows.GlobalAddAtom('WindowInfo'); + ChangedMenus := TList.Create; + + {$ifdef WindowsUnicodeSupport} + + WinVersion.dwOSVersionInfoSize := SizeOf(TOSVersionInfo); + GetVersionEx(WinVersion); + + UnicodeEnabledOS := (WinVersion.dwPlatformID = VER_PLATFORM_WIN32_NT); + + {$endif} +end; {$IFDEF ASSERT_IS_ON} {$UNDEF ASSERT_IS_ON} @@ -1137,11 +1171,8 @@ end; {$ENDIF} initialization - - FillChar(DefaultWindowInfo, sizeof(DefaultWindowInfo), 0); - DefaultWindowInfo.DrawItemIndex := -1; - WindowInfoAtom := Windows.GlobalAddAtom('WindowInfo'); - ChangedMenus := TList.Create; + + DoInitialization; finalization diff --git a/lcl/interfaces/win32/win32wscontrols.pp b/lcl/interfaces/win32/win32wscontrols.pp index af0c75271e..8e206ea1fa 100644 --- a/lcl/interfaces/win32/win32wscontrols.pp +++ b/lcl/interfaces/win32/win32wscontrols.pp @@ -200,8 +200,20 @@ begin end else begin MenuHandle := HMENU(nil); end; - Window := CreateWindowEx(FlagsEx, pClassName, WindowTitle, Flags, + + {$ifdef WindowsUnicodeSupport} + if UnicodeEnabledOS then + Window := CreateWindowExW(FlagsEx, Utf8PCharToPWideChar(pClassName), + Utf8PCharToPWideChar(WindowTitle), Flags, + Left, Top, Width, Height, Parent, MenuHandle, HInstance, Nil) + else + Window := CreateWindowEx(FlagsEx, pClassName, PChar(Utf8ToAnsi(WindowTitle)), Flags, Left, Top, Width, Height, Parent, MenuHandle, HInstance, Nil); + {$else} + Window := CreateWindowEx(FlagsEx, pClassName, WindowTitle, Flags, + Left, Top, Width, Height, Parent, MenuHandle, HInstance, Nil); + {$endif} + if Window = 0 then begin raise exception.create('failed to create win32 control, error: '+IntToStr(GetLastError())); @@ -415,7 +427,13 @@ class procedure TWin32WSWinControl.SetText(const AWinControl: TWinControl; const Begin if not WSCheckHandleAllocated(AWincontrol, 'SetText') then Exit; +{$ifdef WindowsUnicodeSupport} + if UnicodeEnabledOS + then Windows.SetWindowTextW(AWinControl.Handle, Utf8ToPWideChar(AText)) + else Windows.SetWindowText(AWinControl.Handle, PChar(Utf8ToAnsi(AText))); +{$else} Windows.SetWindowText(AWinControl.Handle, PChar(AText)); +{$endif} End; class procedure TWin32WSWinControl.ConstraintsChange(const AWinControl: TWinControl);