From 8d7812da866bc4a4788060bcd20a44b2deb3ea2d Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 12 May 2007 09:39:20 +0000 Subject: [PATCH] IDE: completion form is now created on demand and the internal double buffer bitmap is resized correct git-svn-id: trunk@11130 - --- components/synedit/syncompletion.pas | 2 + ide/uniteditor.pp | 59 +++++++++++++++++----------- lcl/include/bitmap.inc | 3 -- lcl/interfaces/gtk/gtkwinapi.inc | 4 +- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/components/synedit/syncompletion.pas b/components/synedit/syncompletion.pas index 3f2c854a26..95e5e58512 100644 --- a/components/synedit/syncompletion.pas +++ b/components/synedit/syncompletion.pas @@ -642,6 +642,8 @@ begin {$ENDIF} Scroll.LargeChange := NbLinesInWindow; + bitmap.Width:=ClientWidth; + bitmap.Height:=ClientHeight; with bitmap do begin {$IFNDEF SYN_LAZARUS} canvas.pen.color := fbcolor; diff --git a/ide/uniteditor.pp b/ide/uniteditor.pp index 28be5150e6..7c2693b2cf 100644 --- a/ide/uniteditor.pp +++ b/ide/uniteditor.pp @@ -599,6 +599,7 @@ type constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure InitMacros(AMacroList: TTransferMacroList); + procedure CreateCompletionForm; procedure ShowLazDoc; procedure UpdateLazDoc; @@ -1450,6 +1451,7 @@ Begin ecWordCompletion : if not TCustomSynEdit(Sender).ReadOnly then begin + SourceNotebook.CreateCompletionForm; CurrentCompletionType:=ctWordCompletion; TextS := FEditor.LineText; LogCaret:=FEditor.LogicalCaretXY; @@ -2118,7 +2120,8 @@ Begin end; if FCodeTemplates<>nil then FCodeTemplates.AddEditor(FEditor); - aCompletion.AddEditor(FEditor); + if aCompletion<>nil then + aCompletion.AddEditor(FEditor); RefreshEditorSettings; FEditor.EndUpdate; end else begin @@ -2246,7 +2249,7 @@ begin //debugln('TSourceEditor.StartIdentCompletion'); if (FEditor.ReadOnly) or (CurrentCompletionType<>ctNone) then exit; SourceNotebook.fIdentCompletionJumpToError:=JumpToError; - + SourceNotebook.CreateCompletionForm; CurrentCompletionType:=ctIdentCompletion; TextS := FEditor.LineText; LogCaret:=FEditor.LogicalCaretXY; @@ -2414,7 +2417,8 @@ Begin FOnBeforeClose(Self); Visible := False; - aCompletion.RemoveEditor(FEditor); + if aCompletion<>nil then + aCompletion.RemoveEditor(FEditor); SourceEditorMarks.DeleteAllForEditor(FEditor); FEditor.Parent:=nil; CodeBuffer := nil; @@ -2903,26 +2907,6 @@ begin // popup menu BuildPopupMenu; - // completion form - aCompletion := TSynCompletion.Create(Self); - with aCompletion do - Begin - EndOfTokenChr:='()[].,;:-+=^*<>/'; - Width:=400; - OnExecute := @ccExecute; - OnCancel := @ccCancel; - OnCodeCompletion := @ccComplete; - OnPaintItem:=@OnSynCompletionPaintItem; - OnMeasureItem := @OnSynCompletionMeasureItem; - OnSearchPosition:=@OnSynCompletionSearchPosition; - OnKeyCompletePrefix:=@OnSynCompletionCompletePrefix; - OnKeyNextChar:=@OnSynCompletionNextChar; - OnKeyPrevChar:=@OnSynCompletionPrevChar; - OnKeyPress:=@OnSynCompletionKeyPress; - OnUTF8KeyPress:=@OnSynCompletionUTF8KeyPress; - ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]); - end; - // HintTimer FHintTimer := TTimer.Create(Self); with FHintTimer do begin @@ -2985,6 +2969,34 @@ begin lisPromptForValue,@MacroFuncPrompt,[tmfInteractive])); end; +procedure TSourceNotebook.CreateCompletionForm; +var + i: Integer; +begin + // completion form + aCompletion := TSynCompletion.Create(Self); + with aCompletion do + Begin + EndOfTokenChr:='()[].,;:-+=^*<>/'; + Width:=400; + OnExecute := @ccExecute; + OnCancel := @ccCancel; + OnCodeCompletion := @ccComplete; + OnPaintItem:=@OnSynCompletionPaintItem; + OnMeasureItem := @OnSynCompletionMeasureItem; + OnSearchPosition:=@OnSynCompletionSearchPosition; + OnKeyCompletePrefix:=@OnSynCompletionCompletePrefix; + OnKeyNextChar:=@OnSynCompletionNextChar; + OnKeyPrevChar:=@OnSynCompletionPrevChar; + OnKeyPress:=@OnSynCompletionKeyPress; + OnUTF8KeyPress:=@OnSynCompletionUTF8KeyPress; + ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]); + end; + + for i:=0 to EditorCount-1 do + aCompletion.AddEditor(Editors[i].FEditor); +end; + procedure TSourceNotebook.ShowLazDoc; begin DoShowLazDoc; @@ -3096,6 +3108,7 @@ var P:TPoint; begin //writeln('TSourceNotebook.OnCodeTemplateTokenNotFound ',AToken,',',AnEditor.ReadOnly,',',CurrentCompletionType=ctNone); if (AnEditor.ReadOnly=false) and (CurrentCompletionType=ctNone) then begin + SourceNotebook.CreateCompletionForm; CurrentCompletionType:=ctTemplateCompletion; with AnEditor do begin P := Point(CaretXPix - length(AToken)*CharWidth,CaretYPix + LineHeight); diff --git a/lcl/include/bitmap.inc b/lcl/include/bitmap.inc index 19e785c3a0..29406c5496 100644 --- a/lcl/include/bitmap.inc +++ b/lcl/include/bitmap.inc @@ -151,10 +151,7 @@ end; function TBitmap.GetCanvas: TCanvas; begin if FCanvas = nil then - begin - HandleNeeded; CreateCanvas; - end; Result := FCanvas; end; diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index ba6105cddb..33ad7dd3a7 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -7974,8 +7974,8 @@ begin Drawable := nil; end; if Drawable<>nil then begin - //DebugLn('TGtkWidgetSet.SelectObject DC=',DbgS(DC),8),' GDIBitmap=',DbgS(Cardinal(CurrentBitmap), - //' GDIBitmapType=',ord(CurrentBitmap^.GDIBitmapType),' Drawable=',DbgS(Drawable)); + //DebugLn(['TGtkWidgetSet.SelectObject DC=',DbgS(Pointer(DC)),' GDIBitmap=',DbgS(CurrentBitmap), + //' GDIBitmapType=',ord(CurrentBitmap^.GDIBitmapType),' Drawable=',DbgS(Drawable)]); if GC <> nil then begin gdk_gc_unref(GC); GC:=nil;