diff --git a/components/synedit/syncompletion.pas b/components/synedit/syncompletion.pas index 47c10aa65d..cfad82d03c 100644 --- a/components/synedit/syncompletion.pas +++ b/components/synedit/syncompletion.pas @@ -455,6 +455,8 @@ end; procedure TSynBaseCompletionForm.Deactivate; begin + // completion box lost focus + // this can happen when a hint window is clicked => ToDo Visible := False; {$IFDEF SYN_LAZARUS} FHint.Visible := False; diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 9eb41fd742..076177dd3c 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -2411,7 +2411,9 @@ var TextS, TextS2: String; LogCaret: TPoint; begin - //debugln('TSourceEditor.StartIdentCompletion'); + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceEditor.StartIdentCompletion JumpToError: ',JumpToError]); + {$ENDIF} if (FEditor.ReadOnly) or (CurrentCompletionType<>ctNone) then exit; SourceNotebook.fIdentCompletionJumpToError:=JumpToError; SourceNotebook.CreateCompletionForm; @@ -2433,6 +2435,9 @@ begin end; aCompletion.Editor:=FEditor; aCompletion.Execute(TextS2,P.X,P.Y); + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceEditor.StartIdentCompletion END aCompletion.TheForm.Visible=',aCompletion.TheForm.Visible]); + {$ENDIF} end; procedure TSourceEditor.IncreaseIgnoreCodeBufferLock; @@ -3160,6 +3165,9 @@ procedure TSourceNotebook.CreateCompletionForm; var i: Integer; begin + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceNotebook.CreateCompletionForm START ',dbgsname(aCompletion)]); + {$ENDIF} // completion form if aCompletion<>nil then exit; aCompletion := TSynCompletion.Create(Self); @@ -3676,7 +3684,10 @@ var Editor: TSynEdit; OldCompletionType: TCompletionType; Begin - if CurCompletionControl=nil then + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceNotebook.ccComplete START']); + {$ENDIF} + if CurCompletionControl=nil then begin Value := SourceValue; exit; @@ -3756,6 +3767,10 @@ Procedure TSourceNotebook.ccCancel(Sender: TObject); // user cancels completion form begin if CurCompletionControl=nil then exit; + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceNotebook.ccCancel START']); + //debugln(GetStackTrace(true)); + {$ENDIF} DeactivateCompletionForm; end; @@ -3769,6 +3784,9 @@ var NewStr: String; CurEdit: TSynEdit; Begin + {$IFDEF VerboseIDECompletionBox} + debugln(['TSourceNotebook.ccExecute START']); + {$ENDIF} CurCompletionControl := Sender as TSynCompletion; S := TStringList.Create; Prefix := CurCompletionControl.CurrentString; diff --git a/lcl/forms.pp b/lcl/forms.pp index 277e163cbd..c1c61f5942 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -460,6 +460,7 @@ type FFormBorderStyle: TFormBorderStyle; FActionLists: TList; procedure CMShowingChanged(var Message: TLMessage); message CM_SHOWINGCHANGED; + procedure DoShowWindow; dynamic; procedure Activate; dynamic; procedure ActiveChanged; dynamic; procedure BeginFormUpdate; @@ -724,6 +725,8 @@ type procedure SetAutoHide(Value : Boolean); procedure AutoHideHint(Sender : TObject); procedure SetHideInterval(Value : Integer); + protected + procedure DoShowWindow; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 8001971a10..ec54846b01 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -392,8 +392,6 @@ end; ShowWindow event handler. ------------------------------------------------------------------------------} procedure TCustomForm.WMShowWindow(var message: TLMShowWindow); -var - NewFocusControl: TWinControl; begin {$IFDEF VerboseFocus} DbgOut('TCustomForm.WMShowWindow A ',Name,':'+ClassName+' fsShowing='+dbgs(fsShowing in FFormState)+' Msg.Show='+dbgs(Message.Show)); @@ -411,29 +409,7 @@ begin if Message.Status = 0 then begin if Message.Show then begin - if (ActiveControl = nil) and (not (csDesigning in ComponentState)) - and (Parent=nil) then begin - // automatically choose a control to focus - {$IFDEF VerboseFocus} - DebugLn('TCustomForm.WMShowWindow ',DbgSName(Self),' Set ActiveControl := ',DbgSName(FindDefaultForActiveControl)); - {$ENDIF} - ActiveControl := FindDefaultForActiveControl; - end; - if ([csLoading,csDestroying]*ComponentState=[]) - and (Parent=nil) then begin - NewFocusControl:=FActiveControl; - if (NewFocusControl=nil) - or (not NewFocusControl.CanFocus) - then - NewFocusControl:=Self; - if NewFocusControl.HandleAllocated and NewFocusControl.IsVisible - then begin - {$IFDEF VerboseFocus} - DebugLn('TCustomForm.WMShowWindow ',DbgSName(Self),' SetFocus NewFocusControl=',DbgSName(NewFocusControl),' FActiveControl=',DbgSName(FActiveControl)); - {$ENDIF} - LCLIntf.SetFocus(NewFocusControl.Handle); - end; - end; + DoShowWindow; end; end; finally @@ -482,6 +458,36 @@ begin DoHide; inherited; end; + +procedure TCustomForm.DoShowWindow; +var + NewFocusControl: TWinControl; +begin + if (ActiveControl = nil) and (not (csDesigning in ComponentState)) + and (Parent=nil) then begin + // automatically choose a control to focus + {$IFDEF VerboseFocus} + DebugLn('TCustomForm.DoShowWindow ',DbgSName(Self),' Set ActiveControl := ',DbgSName(FindDefaultForActiveControl)); + {$ENDIF} + ActiveControl := FindDefaultForActiveControl; + end; + if ([csLoading,csDestroying]*ComponentState=[]) + and (Parent=nil) then begin + NewFocusControl:=FActiveControl; + if (NewFocusControl=nil) + or (not NewFocusControl.CanFocus) + then + NewFocusControl:=Self; + if NewFocusControl.HandleAllocated and NewFocusControl.IsVisible + then begin + {$IFDEF VerboseFocus} + DebugLn('TCustomForm.DoShowWindow ',DbgSName(Self),' SetFocus NewFocusControl=',DbgSName(NewFocusControl),' FActiveControl=',DbgSName(FActiveControl)); + {$ENDIF} + LCLIntf.SetFocus(NewFocusControl.Handle); + end; + end; +end; + {------------------------------------------------------------------------------ Method: TCustomForm.Activate Params: none diff --git a/lcl/include/hintwindow.inc b/lcl/include/hintwindow.inc index ff6ae38c8b..051736a3e9 100644 --- a/lcl/include/hintwindow.inc +++ b/lcl/include/hintwindow.inc @@ -59,6 +59,18 @@ Begin TCustomTimer(FAutoHideTimer).Interval := FHideInterval; end; +procedure THintWindow.DoShowWindow; +begin + if (ActiveControl = nil) and (not (csDesigning in ComponentState)) + and (Parent=nil) then begin + // automatically choose a control to focus + {$IFDEF VerboseFocus} + DebugLn('THintWindow.WMShowWindow ',DbgSName(Self),' Set ActiveControl := ',DbgSName(FindDefaultForActiveControl)); + {$ENDIF} + ActiveControl := FindDefaultForActiveControl; + end; +end; + procedure THintWindow.SetAutoHide(Value : Boolean); Begin FAutoHide := Value; diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index 54e2f74b11..790312d679 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -8620,6 +8620,7 @@ begin {$IfDef VerboseFocus} DebugLn(''); debugln('[TGtkWidgetSet.SetFocus] A hWnd=',GetWidgetDebugReport(Widget)); + //DebugLn(getStackTrace(true)); {$EndIf} // return the old focus handle