fix combobox selection of text when resizing (fixes #1180)

improve message debugging (display # in front of message when sent by win32 default handler)

git-svn-id: trunk@7821 -
This commit is contained in:
micha 2005-09-25 18:35:08 +00:00
parent 418c53918e
commit 86a7e13da6
3 changed files with 64 additions and 33 deletions

View File

@ -70,12 +70,36 @@ function CallDefaultWindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
LParam: Windows.LParam): LResult;
var
PrevWndProc: Windows.WNDPROC;
{$ifdef MSG_DEBUG}
depthLen: integer;
{$endif}
setComboWindow: boolean;
begin
{$ifdef MSG_DEBUG}
depthLen := Length(MessageStackDepth);
if depthLen > 0 then
MessageStackDepth[depthLen] := '#';
{$endif}
PrevWndProc := GetWindowInfo(Window)^.DefWndProc;
if PrevWndProc = nil then
Result := Windows.DefWindowProc(Window, Msg, WParam, LParam)
else
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
// WM_GETTEXTLENGTH, WM_GETTEXT, WM_SETTEXT, EM_SETSEL
// combobox sends WM_SIZE to itself indirectly, check recursion
setComboWindow := (Msg = WM_SIZE) and (ComboBoxHandleSizeWindow = 0)
and GetWindowInfo(Windows.GetTopWindow(Window))^.isComboEdit;
if setComboWindow then
ComboBoxHandleSizeWindow := Window;
Result := Windows.CallWindowProc(PrevWndProc, Window, Msg, WParam, LParam);
if setComboWindow then
ComboBoxHandleSizeWindow := 0;
end;
{$ifdef MSG_DEBUG}
if depthLen > 0 then
MessageStackDepth[depthLen] := ' ';
{$endif}
end;
type
@ -84,10 +108,7 @@ const
EraseBkgndStackMask = $3;
EraseBkgndStackShift = 2;
var
EraseBkgndStack: dword;
{$ifdef MSG_DEBUG}
MessageStackDepth: string;
{$endif}
EraseBkgndStack: dword = 0;
procedure PushEraseBkgndCommand(Command: TEraseBkgndCommand);
begin
@ -561,6 +582,11 @@ Var
end
end;
function IsComboEditSelection: boolean;
begin
Result := WindowInfo^.isComboEdit and (ComboBoxHandleSizeWindow = Windows.GetParent(Window));
end;
Begin
Assert(False, 'Trace:WindowProc - Start');
@ -574,6 +600,25 @@ Begin
WindowInfo := GetWindowInfo(Window);
if WindowInfo^.isChildEdit then
begin
// combobox child edit weirdness
// prevent combobox WM_SIZE message to get/set/compare text to list, to select text
if IsComboEditSelection then
begin
case Msg of
WM_GETTEXTLENGTH, EM_SETSEL:
begin
Result := 0;
exit;
end;
WM_GETTEXT:
begin
if WParam > 0 then
PChar(LParam)^ := #0;
Result := 0;
exit;
end;
end;
end;
lWinControl := WindowInfo^.AWinControl;
// filter messages we want to pass on to LCL
if (Msg <> WM_KILLFOCUS) and (Msg <> WM_SETFOCUS) and (Msg <> WM_NCDESTROY)

View File

@ -246,10 +246,14 @@ type
var
MouseDownTime: dword;
MouseDownPos: TPoint;
MouseDownWindow: HWND;
MouseDownWindow: HWND = 0;
MouseDownFocusWindow: HWND;
MouseDownFocusStatus: TMouseDownFocusStatus;
MouseDownFocusStatus: TMouseDownFocusStatus = mfNone;
ComboBoxHandleSizeWindow: HWND = 0;
OnClipBoardRequest: TClipboardRequestEvent;
{$ifdef MSG_DEBUG}
MessageStackDepth: string = '';
{$endif}
{$I win32listsl.inc}
{$I win32callback.inc}
@ -260,15 +264,8 @@ var
Initialization
Assert(False, 'Trace:win32int.pp - Initialization');
{$ifdef MSG_DEBUG}
MessageStackDepth := '';
{$endif}
EraseBkgndStack := 0;
{ initialize mousedownclick to far before double click time }
MouseDownFocusStatus := mfNone;
MouseDownTime := GetTickCount - 5000;
MouseDownWindow := 0;
finalization

View File

@ -672,21 +672,15 @@ end;
function TWin32WSCustomComboBox.GetText(const AWinControl: TWinControl; var AText: string): boolean;
var
Handle: HWND;
CapLen: dword;
Caption: PChar;
TextLen: dword;
begin
Result := AWinControl.HandleAllocated;
if not Result then
exit;
AText := '';
Handle := AWinControl.Handle;
// TODO: this can be made shorter probably, using SetLength(AText, ...)
// + 1 = terminating null character
CapLen := Windows.SendMessage(Handle, WM_GETTEXTLENGTH, 0, 0) + 1;
Caption := StrAlloc(CapLen);
Windows.SendMessage(Handle, WM_GETTEXT, CapLen, LPARAM(Caption));
AText := StrPas(Caption);
StrDispose(Caption);
TextLen := GetWindowTextLength(Handle);
SetLength(AText, TextLen);
GetWindowText(Handle, PChar(AText), TextLen + 1);
end;
procedure TWin32WSCustomComboBox.SetArrowKeysTraverseList(const ACustomComboBox: TCustomComboBox;
@ -825,21 +819,16 @@ end;
function TWin32WSCustomEdit.GetText(const AWinControl: TWinControl; var AText: string): boolean;
var
CapLen: dword;
Caption: PChar;
TextLen: dword;
Handle: HWND;
begin
Result := AWinControl.HandleAllocated;
if not Result then
exit;
AText := '';
Handle := AWinControl.Handle;
// TODO: this can be made shorter probably, using SetLength(AText, ...)
CapLen := GetWindowTextLength(Handle);
Caption := StrAlloc(CapLen + 1);
GetWindowText(Handle, Caption, CapLen + 1);
AText := StrPas(Caption);
StrDispose(Caption);
TextLen := GetWindowTextLength(Handle);
SetLength(AText, TextLen);
GetWindowText(Handle, PChar(AText), TextLen + 1);
end;
procedure TWin32WSCustomEdit.SetCharCase(const ACustomEdit: TCustomEdit; NewCase: TEditCharCase);