mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 07:19:18 +02:00
added history to identifier completion
git-svn-id: trunk@3766 -
This commit is contained in:
parent
d25a61111f
commit
a0bcf62aa6
@ -128,6 +128,7 @@ type
|
|||||||
SourceChangeCache: TSourceChangeCache; // cache for write accesses
|
SourceChangeCache: TSourceChangeCache; // cache for write accesses
|
||||||
GlobalValues: TExpressionEvaluator;
|
GlobalValues: TExpressionEvaluator;
|
||||||
IdentifierList: TIdentifierList;
|
IdentifierList: TIdentifierList;
|
||||||
|
IdentifierHistory: TIdentifierHistoryList;
|
||||||
|
|
||||||
procedure ActivateWriteLock;
|
procedure ActivateWriteLock;
|
||||||
procedure DeactivateWriteLock;
|
procedure DeactivateWriteLock;
|
||||||
@ -384,10 +385,13 @@ begin
|
|||||||
FCursorBeyondEOL:=true;
|
FCursorBeyondEOL:=true;
|
||||||
FIndentSize:=2;
|
FIndentSize:=2;
|
||||||
FJumpCentered:=true;
|
FJumpCentered:=true;
|
||||||
FSourceExtensions:='.pp;.pas;.lpr;.dpr;.dpk';
|
FSourceExtensions:='.pp;.pas;.lpr;.lpk;.dpr;.dpk';
|
||||||
FVisibleEditorLines:=20;
|
FVisibleEditorLines:=20;
|
||||||
FWriteExceptions:=true;
|
FWriteExceptions:=true;
|
||||||
FSourceTools:=TAVLTree.Create(@CompareCodeToolMainSources);
|
FSourceTools:=TAVLTree.Create(@CompareCodeToolMainSources);
|
||||||
|
IdentifierList:=TIdentifierList.Create;
|
||||||
|
IdentifierHistory:=TIdentifierHistoryList.Create;
|
||||||
|
IdentifierList.History:=IdentifierHistory;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCodeToolManager.Destroy;
|
destructor TCodeToolManager.Destroy;
|
||||||
@ -399,6 +403,7 @@ begin
|
|||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln('[TCodeToolManager.Destroy] B');
|
writeln('[TCodeToolManager.Destroy] B');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
IdentifierHistory.Free;
|
||||||
IdentifierList.Free;
|
IdentifierList.Free;
|
||||||
FSourceTools.FreeAndClear;
|
FSourceTools.FreeAndClear;
|
||||||
FSourceTools.Free;
|
FSourceTools.Free;
|
||||||
@ -559,6 +564,7 @@ begin
|
|||||||
fErrorMsg:='';
|
fErrorMsg:='';
|
||||||
fErrorCode:=nil;
|
fErrorCode:=nil;
|
||||||
fErrorLine:=-1;
|
fErrorLine:=-1;
|
||||||
|
if IdentifierList<>nil then IdentifierList.Clear;
|
||||||
MainCode:=GetMainCode(Code);
|
MainCode:=GetMainCode(Code);
|
||||||
if MainCode=nil then begin
|
if MainCode=nil then begin
|
||||||
fErrorMsg:='TCodeToolManager.InitCurCodeTool MainCode=nil';
|
fErrorMsg:='TCodeToolManager.InitCurCodeTool MainCode=nil';
|
||||||
|
@ -44,6 +44,7 @@ interface
|
|||||||
{$DEFINE CTDEBUG}
|
{$DEFINE CTDEBUG}
|
||||||
{ $DEFINE ShowFoundIdents}
|
{ $DEFINE ShowFoundIdents}
|
||||||
{ $DEFINE ShowFilteredIdents}
|
{ $DEFINE ShowFilteredIdents}
|
||||||
|
{$DEFINE ShowHistory}
|
||||||
|
|
||||||
// new features
|
// new features
|
||||||
{ $DEFINE IgnoreErrorAfterCursor}
|
{ $DEFINE IgnoreErrorAfterCursor}
|
||||||
@ -60,6 +61,10 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
TIdentCompletionTool = class;
|
TIdentCompletionTool = class;
|
||||||
|
TIdentifierHistoryList = class;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// gathered identifier list
|
||||||
|
|
||||||
TIdentifierCompatibility = (
|
TIdentifierCompatibility = (
|
||||||
icompExact,
|
icompExact,
|
||||||
@ -88,8 +93,10 @@ type
|
|||||||
private
|
private
|
||||||
FFilteredList: TList;
|
FFilteredList: TList;
|
||||||
FFlags: TIdentifierListFlags;
|
FFlags: TIdentifierListFlags;
|
||||||
FItems: TAVLTree;
|
FHistory: TIdentifierHistoryList;
|
||||||
|
FItems: TAVLTree; // tree of TIdentifierListItem
|
||||||
FPrefix: string;
|
FPrefix: string;
|
||||||
|
procedure SetHistory(const AValue: TIdentifierHistoryList);
|
||||||
procedure UpdateFilteredList;
|
procedure UpdateFilteredList;
|
||||||
function GetFilteredItems(Index: integer): TIdentifierListItem;
|
function GetFilteredItems(Index: integer): TIdentifierListItem;
|
||||||
procedure SetPrefix(const AValue: string);
|
procedure SetPrefix(const AValue: string);
|
||||||
@ -104,7 +111,39 @@ type
|
|||||||
property Prefix: string read FPrefix write SetPrefix;
|
property Prefix: string read FPrefix write SetPrefix;
|
||||||
property FilteredItems[Index: integer]: TIdentifierListItem
|
property FilteredItems[Index: integer]: TIdentifierListItem
|
||||||
read GetFilteredItems;
|
read GetFilteredItems;
|
||||||
|
property History: TIdentifierHistoryList read FHistory write SetHistory;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// history list
|
||||||
|
|
||||||
|
TIdentHistListItem = class
|
||||||
|
public
|
||||||
|
Identifier: string;
|
||||||
|
NodeDesc: TCodeTreeNodeDesc;
|
||||||
|
ParamList: string;
|
||||||
|
HistoryIndex: integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TIdentifierHistoryList = class
|
||||||
|
private
|
||||||
|
FCapacity: integer;
|
||||||
|
FItems: TAVLTree; // tree of TIdentHistListItem
|
||||||
|
procedure SetCapacity(const AValue: integer);
|
||||||
|
function FindItem(NewItem: TIdentifierListItem): TAVLTreeNode;
|
||||||
|
public
|
||||||
|
constructor Create;
|
||||||
|
destructor Destroy; override;
|
||||||
|
procedure Clear;
|
||||||
|
procedure Add(NewItem: TIdentifierListItem);
|
||||||
|
function GetHistoryIndex(AnItem: TIdentifierListItem): integer;
|
||||||
|
function Count: integer;
|
||||||
|
public
|
||||||
|
property Capacity: integer read FCapacity write SetCapacity;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// TIdentCompletionTool
|
||||||
|
|
||||||
TIdentCompletionTool = class(TFindDeclarationTool)
|
TIdentCompletionTool = class(TFindDeclarationTool)
|
||||||
private
|
private
|
||||||
@ -167,10 +206,47 @@ begin
|
|||||||
|
|
||||||
// then sort alpabetically (lower is better)
|
// then sort alpabetically (lower is better)
|
||||||
Result:=CompareIdentifiers(Item1.Identifier,Item2.Identifier);
|
Result:=CompareIdentifiers(Item1.Identifier,Item2.Identifier);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CompareIdentHistListItem(Data1, Data2: Pointer): integer;
|
||||||
|
var
|
||||||
|
Item1: TIdentHistListItem;
|
||||||
|
Item2: TIdentHistListItem;
|
||||||
|
begin
|
||||||
|
Item1:=TIdentHistListItem(Data1);
|
||||||
|
Item2:=TIdentHistListItem(Data2);
|
||||||
|
|
||||||
|
Result:=CompareIdentifiers(PChar(Item1.Identifier),PChar(Item2.Identifier));
|
||||||
if Result<>0 then exit;
|
if Result<>0 then exit;
|
||||||
|
|
||||||
// no difference found
|
Result:=CompareIdentifiers(PChar(Item1.ParamList),PChar(Item2.ParamList));
|
||||||
Result:=0;
|
end;
|
||||||
|
|
||||||
|
function GetParamList(IdentItem: TIdentifierListItem): string;
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
case IdentItem.Node.Desc of
|
||||||
|
ctnProcedure:
|
||||||
|
Result:=IdentItem.Tool.ExtractProcHead(IdentItem.Node,
|
||||||
|
[phpWithoutClassKeyword,phpWithoutClassName,phpWithoutName,phpInUpperCase]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CompareIdentItemWithHistListItem(Data1, Data2: Pointer): integer;
|
||||||
|
var
|
||||||
|
IdentItem: TIdentifierListItem;
|
||||||
|
HistItem: TIdentHistListItem;
|
||||||
|
ParamList: String;
|
||||||
|
begin
|
||||||
|
IdentItem:=TIdentifierListItem(Data1);
|
||||||
|
HistItem:=TIdentHistListItem(Data2);
|
||||||
|
|
||||||
|
Result:=CompareIdentifiers(IdentItem.Identifier,PChar(HistItem.Identifier));
|
||||||
|
if Result<>0 then exit;
|
||||||
|
|
||||||
|
ParamList:=GetParamList(IdentItem);
|
||||||
|
if (ParamList<>'') then
|
||||||
|
Result:=AnsiCompareText(ParamList,HistItem.ParamList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIdentifierList }
|
{ TIdentifierList }
|
||||||
@ -208,6 +284,12 @@ begin
|
|||||||
Exclude(FFlags,ilfFilteredListNeedsUpdate);
|
Exclude(FFlags,ilfFilteredListNeedsUpdate);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TIdentifierList.SetHistory(const AValue: TIdentifierHistoryList);
|
||||||
|
begin
|
||||||
|
if FHistory=AValue then exit;
|
||||||
|
FHistory:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
function TIdentifierList.GetFilteredItems(Index: integer): TIdentifierListItem;
|
function TIdentifierList.GetFilteredItems(Index: integer): TIdentifierListItem;
|
||||||
begin
|
begin
|
||||||
UpdateFilteredList;
|
UpdateFilteredList;
|
||||||
@ -239,6 +321,8 @@ end;
|
|||||||
|
|
||||||
procedure TIdentifierList.Add(NewItem: TIdentifierListItem);
|
procedure TIdentifierList.Add(NewItem: TIdentifierListItem);
|
||||||
begin
|
begin
|
||||||
|
if History<>nil then
|
||||||
|
NewItem.HistoryIndex:=History.GetHistoryIndex(NewItem);
|
||||||
FItems.Add(NewItem);
|
FItems.Add(NewItem);
|
||||||
Include(FFlags,ilfFilteredListNeedsUpdate);
|
Include(FFlags,ilfFilteredListNeedsUpdate);
|
||||||
end;
|
end;
|
||||||
@ -299,7 +383,10 @@ begin
|
|||||||
Ident:=FoundContext.Tool.GetProcNameIdentifier(FoundContext.Node);
|
Ident:=FoundContext.Tool.GetProcNameIdentifier(FoundContext.Node);
|
||||||
|
|
||||||
ctnProperty:
|
ctnProperty:
|
||||||
Ident:=FoundContext.Tool.GetPropertyNameIdentifier(FoundContext.Node);
|
begin
|
||||||
|
if FoundContext.Tool.PropNodeIsTypeLess(FoundContext.Node) then exit;
|
||||||
|
Ident:=FoundContext.Tool.GetPropertyNameIdentifier(FoundContext.Node);
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
if Ident=nil then exit;
|
if Ident=nil then exit;
|
||||||
@ -434,5 +521,106 @@ begin
|
|||||||
+' "'+StringToPascalConst(copy(Tool.Src,Node.StartPos,50))+'"';
|
+' "'+StringToPascalConst(copy(Tool.Src,Node.StartPos,50))+'"';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TIdentifierHistoryList }
|
||||||
|
|
||||||
|
procedure TIdentifierHistoryList.SetCapacity(const AValue: integer);
|
||||||
|
begin
|
||||||
|
if FCapacity=AValue then exit;
|
||||||
|
FCapacity:=AValue;
|
||||||
|
if FCapacity<1 then FCapacity:=1;
|
||||||
|
while (FItems.Count>0) and (FItems.Count>=FCapacity) do
|
||||||
|
FItems.FreeAndDelete(FItems.FindHighest);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIdentifierHistoryList.FindItem(NewItem: TIdentifierListItem
|
||||||
|
): TAVLTreeNode;
|
||||||
|
begin
|
||||||
|
if NewItem<>nil then
|
||||||
|
Result:=FItems.FindKey(NewItem,@CompareIdentItemWithHistListItem)
|
||||||
|
else
|
||||||
|
Result:=nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TIdentifierHistoryList.Create;
|
||||||
|
begin
|
||||||
|
FItems:=TAVLTree.Create(@CompareIdentHistListItem);
|
||||||
|
FCapacity:=30;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TIdentifierHistoryList.Destroy;
|
||||||
|
begin
|
||||||
|
Clear;
|
||||||
|
FItems.Free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TIdentifierHistoryList.Clear;
|
||||||
|
begin
|
||||||
|
FItems.FreeAndClear;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TIdentifierHistoryList.Add(NewItem: TIdentifierListItem);
|
||||||
|
var
|
||||||
|
OldAVLNode: TAVLTreeNode;
|
||||||
|
NewHistItem: TIdentHistListItem;
|
||||||
|
AnAVLNode: TAVLTreeNode;
|
||||||
|
AdjustIndex: Integer;
|
||||||
|
AnHistItem: TIdentHistListItem;
|
||||||
|
begin
|
||||||
|
if NewItem=nil then exit;
|
||||||
|
OldAVLNode:=FindItem(NewItem);
|
||||||
|
{$IFDEF ShowHistory}
|
||||||
|
writeln('TIdentifierHistoryList.Add Count=',Count,' Found=',OldAVLNode<>nil,
|
||||||
|
' ITEM: ',NewItem.AsString);
|
||||||
|
{$ENDIF}
|
||||||
|
if OldAVLNode<>nil then begin
|
||||||
|
// already in tree
|
||||||
|
NewHistItem:=TIdentHistListItem(OldAVLNode.Data);
|
||||||
|
if NewHistItem.HistoryIndex=0 then exit;
|
||||||
|
// must be moved -> remove it from the tree
|
||||||
|
AdjustIndex:=NewHistItem.HistoryIndex;
|
||||||
|
FItems.Delete(OldAVLNode);
|
||||||
|
end else begin
|
||||||
|
// create a new history item
|
||||||
|
NewHistItem:=TIdentHistListItem.Create;
|
||||||
|
NewHistItem.Identifier:=GetIdentifier(NewItem.Identifier);
|
||||||
|
NewHistItem.NodeDesc:=NewItem.Node.Desc;
|
||||||
|
NewHistItem.ParamList:=GetParamList(NewItem);
|
||||||
|
AdjustIndex:=0;
|
||||||
|
end;
|
||||||
|
NewHistItem.HistoryIndex:=0;
|
||||||
|
// adjust all other HistoryIndex
|
||||||
|
AnAVLNode:=Fitems.FindLowest;
|
||||||
|
while AnAVLNode<>nil do begin
|
||||||
|
AnHistItem:=TIdentHistListItem(AnAVLNode.Data);
|
||||||
|
if AnHistItem.HistoryIndex>=AdjustIndex then
|
||||||
|
inc(AnHistItem.HistoryIndex);
|
||||||
|
AnAVLNode:=FItems.FindSuccessor(AnAVLNode);
|
||||||
|
end;
|
||||||
|
if (FItems.Count>0) and (FItems.Count>=FCapacity) then
|
||||||
|
FItems.FreeAndDelete(FItems.FindHighest);
|
||||||
|
FItems.Add(NewHistItem);
|
||||||
|
{$IFDEF ShowHistory}
|
||||||
|
writeln('TIdentifierHistoryList.Added Count=',Count);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIdentifierHistoryList.GetHistoryIndex(AnItem: TIdentifierListItem
|
||||||
|
): integer;
|
||||||
|
var
|
||||||
|
AnAVLNode: TAVLTreeNode;
|
||||||
|
begin
|
||||||
|
AnAVLNode:=FindItem(AnItem);
|
||||||
|
if AnAVLNode=nil then
|
||||||
|
Result:=3333333 // a very high value
|
||||||
|
else
|
||||||
|
Result:=TIdentHistListItem(AnAVLNode.Data).HistoryIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIdentifierHistoryList.Count: integer;
|
||||||
|
begin
|
||||||
|
Result:=FItems.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -255,6 +255,7 @@ type
|
|||||||
function NodeIsPartOfTypeDefinition(ANode: TCodeTreeNode): boolean;
|
function NodeIsPartOfTypeDefinition(ANode: TCodeTreeNode): boolean;
|
||||||
function PropertyIsDefault(PropertyNode: TCodeTreeNode): boolean;
|
function PropertyIsDefault(PropertyNode: TCodeTreeNode): boolean;
|
||||||
function PropertyNodeHasParamList(PropNode: TCodeTreeNode): boolean;
|
function PropertyNodeHasParamList(PropNode: TCodeTreeNode): boolean;
|
||||||
|
function PropNodeIsTypeLess(PropNode: TCodeTreeNode): boolean;
|
||||||
function ProcNodeHasParamList(ProcNode: TCodeTreeNode): boolean;
|
function ProcNodeHasParamList(ProcNode: TCodeTreeNode): boolean;
|
||||||
|
|
||||||
procedure MoveCursorToUsesEnd(UsesNode: TCodeTreeNode);
|
procedure MoveCursorToUsesEnd(UsesNode: TCodeTreeNode);
|
||||||
@ -3966,7 +3967,24 @@ begin
|
|||||||
ReadNextAtom; // read 'property'
|
ReadNextAtom; // read 'property'
|
||||||
ReadNextAtom; // read name
|
ReadNextAtom; // read name
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
Result:=AtomIsChar('[');
|
Result:=(CurPos.Flag=cafEdgedBracketOpen);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPascalParserTool.PropNodeIsTypeLess(PropNode: TCodeTreeNode
|
||||||
|
): boolean;
|
||||||
|
begin
|
||||||
|
|
||||||
|
// ToDo: ppu, ppw, dcu
|
||||||
|
|
||||||
|
Result:=false;
|
||||||
|
MoveCursorToNodeStart(PropNode);
|
||||||
|
ReadNextAtom; // read 'property'
|
||||||
|
ReadNextAtom; // read name
|
||||||
|
ReadNextAtom;
|
||||||
|
if CurPos.Flag=cafEdgedBracketOpen then
|
||||||
|
ReadTilBracketClose(true);
|
||||||
|
ReadNextAtom;
|
||||||
|
Result:=(CurPos.Flag<>cafColon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPascalParserTool.ProcNodeHasParamList(ProcNode: TCodeTreeNode
|
function TPascalParserTool.ProcNodeHasParamList(ProcNode: TCodeTreeNode
|
||||||
|
@ -135,6 +135,7 @@ type
|
|||||||
TSynBaseCompletion = class(TComponent)
|
TSynBaseCompletion = class(TComponent)
|
||||||
private
|
private
|
||||||
Form: TSynBaseCompletionForm;
|
Form: TSynBaseCompletionForm;
|
||||||
|
OldPersistentCaret: boolean;
|
||||||
FOnExecute: TNotifyEvent;
|
FOnExecute: TNotifyEvent;
|
||||||
FWidth: Integer;
|
FWidth: Integer;
|
||||||
RFAnsi: boolean;
|
RFAnsi: boolean;
|
||||||
@ -307,6 +308,7 @@ begin
|
|||||||
Scroll.Visible := True;
|
Scroll.Visible := True;
|
||||||
FTextColor:=clBlack;
|
FTextColor:=clBlack;
|
||||||
FTextSelectedColor:=clWhite;
|
FTextSelectedColor:=clWhite;
|
||||||
|
Caption:='Completion';
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Visible := false;
|
Visible := false;
|
||||||
FFontHeight := Canvas.TextHeight('Cyrille de Brebisson')+2;
|
FFontHeight := Canvas.TextHeight('Cyrille de Brebisson')+2;
|
||||||
@ -655,8 +657,13 @@ end;
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
|
procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
|
||||||
|
{$IFDEF SYN_LAZARUS}
|
||||||
|
var
|
||||||
|
CurSynEdit: TSynEdit;
|
||||||
|
{$ENDIF}
|
||||||
begin
|
begin
|
||||||
SetCaretRespondToFocus(TCustomSynEdit(Form.CurrentEditor).Handle,false);
|
//writeln('');
|
||||||
|
//writeln('TSynBaseCompletion.Execute ',Form.CurrentEditor.Name);
|
||||||
CurrentString := s;
|
CurrentString := s;
|
||||||
if Assigned(OnExecute) then
|
if Assigned(OnExecute) then
|
||||||
OnExecute(Self);
|
OnExecute(Self);
|
||||||
@ -669,7 +676,12 @@ begin
|
|||||||
OnCancel(Form);
|
OnCancel(Form);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if (Form.CurrentEditor is TSynEdit) then begin
|
||||||
|
CurSynEdit:=TSynEdit(Form.CurrentEditor);
|
||||||
|
OldPersistentCaret:=eoPersistentCaret in CurSynEdit.Options;
|
||||||
|
CurSynEdit.Options:=CurSynEdit.Options+[eoPersistentCaret];
|
||||||
|
end;
|
||||||
Form.SetBounds(x,y,Form.Width,Form.Height);
|
Form.SetBounds(x,y,Form.Width,Form.Height);
|
||||||
Form.Color:=clNone;
|
Form.Color:=clNone;
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
@ -790,7 +802,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynBaseCompletion.Deactivate;
|
procedure TSynBaseCompletion.Deactivate;
|
||||||
|
{$IFDEF SYN_LAZARUS}
|
||||||
|
var
|
||||||
|
CurSynEdit: TSynEdit;
|
||||||
|
{$ENDIF}
|
||||||
begin
|
begin
|
||||||
|
{$IFDEF SYN_LAZARUS}
|
||||||
|
if (not OldPersistentCaret)
|
||||||
|
and (Form<>nil) and (Form.CurrentEditor is TSynEdit) then begin
|
||||||
|
CurSynEdit:=TSynEdit(Form.CurrentEditor);
|
||||||
|
CurSynEdit.Options:=CurSynEdit.Options-[eoPersistentCaret];
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
if Assigned(Form) then Form.Deactivate;
|
if Assigned(Form) then Form.Deactivate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -34,8 +34,6 @@ unit GTKWinapiWindow;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
{$DEFINE WinAPIChilds : use GtkFixed as client area, to allow childs }
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF gtk2}
|
{$IFDEF gtk2}
|
||||||
glib2, gdk2pixbuf, gdk2, gtk2,
|
glib2, gdk2pixbuf, gdk2, gtk2,
|
||||||
@ -44,6 +42,8 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
|
{ $Define VerboseCaret}
|
||||||
|
|
||||||
type
|
type
|
||||||
PGTKAPIWidget = ^TGTKAPIWidget;
|
PGTKAPIWidget = ^TGTKAPIWidget;
|
||||||
TGTKAPIWidget = record
|
TGTKAPIWidget = record
|
||||||
@ -68,6 +68,8 @@ procedure GTKAPIWidget_SetCaretPos(APIWidget: PGTKAPIWidget; X, Y: Integer);
|
|||||||
procedure GTKAPIWidget_GetCaretPos(APIWidget: PGTKAPIWidget; var X, Y: Integer);
|
procedure GTKAPIWidget_GetCaretPos(APIWidget: PGTKAPIWidget; var X, Y: Integer);
|
||||||
procedure GTKAPIWidget_SetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
procedure GTKAPIWidget_SetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
||||||
ShowHideOnFocus: boolean);
|
ShowHideOnFocus: boolean);
|
||||||
|
procedure GTKAPIWidget_GetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
||||||
|
var ShowHideOnFocus: boolean);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -92,10 +94,7 @@ type
|
|||||||
PGTKAPIWidgetClient = ^TGTKAPIWidgetClient;
|
PGTKAPIWidgetClient = ^TGTKAPIWidgetClient;
|
||||||
TGTKAPIWidgetClient = record
|
TGTKAPIWidgetClient = record
|
||||||
// ! the Widget must be the first attribute of the record !
|
// ! the Widget must be the first attribute of the record !
|
||||||
Widget: {$IFDEF WinApiChilds}TGtkFixed{$ELSE}TGtkWidget{$ENDIF};
|
Widget: TGtkFixed;
|
||||||
{$IFNDEF WinApiChilds}
|
|
||||||
OtherWindow: PGDKWindow;
|
|
||||||
{$ENDIF}
|
|
||||||
Caret: TCaretInfo;
|
Caret: TCaretInfo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -135,7 +134,8 @@ procedure GTKAPIWidgetClient_GetCaretPos(Client: PGTKAPIWidgetClient;
|
|||||||
var X, Y: Integer); forward;
|
var X, Y: Integer); forward;
|
||||||
procedure GTKAPIWidgetClient_SetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
procedure GTKAPIWidgetClient_SetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
||||||
ShowHideOnFocus: boolean); forward;
|
ShowHideOnFocus: boolean); forward;
|
||||||
|
procedure GTKAPIWidgetClient_GetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
||||||
|
var ShowHideOnFocus: boolean); forward;
|
||||||
|
|
||||||
|
|
||||||
function GTKAPIWidgetClient_Timer(Client: Pointer): gint; cdecl;
|
function GTKAPIWidgetClient_Timer(Client: Pointer): gint; cdecl;
|
||||||
@ -156,17 +156,10 @@ procedure GTKAPIWidgetClient_Realize(Widget: PGTKWidget); cdecl;
|
|||||||
var
|
var
|
||||||
Attributes: TGdkWindowAttr;
|
Attributes: TGdkWindowAttr;
|
||||||
AttributesMask: gint;
|
AttributesMask: gint;
|
||||||
{$IFNDEF WinAPIChilds}
|
|
||||||
Client: PGTKAPIWidgetClient;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
// Assert(False, 'Trace:[GTKAPIWidgetClient_Realize]');
|
// Assert(False, 'Trace:[GTKAPIWidgetClient_Realize]');
|
||||||
gtk_widget_set_flags(Widget, GTK_REALIZED);
|
gtk_widget_set_flags(Widget, GTK_REALIZED);
|
||||||
|
|
||||||
{$IFNDEF WinAPIChilds}
|
|
||||||
Client := PGTKAPIWidgetClient(Widget);
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
with Attributes do
|
with Attributes do
|
||||||
begin
|
begin
|
||||||
Window_type := gdk_window_child;
|
Window_type := gdk_window_child;
|
||||||
@ -199,11 +192,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
// AttributesMask := AttributesMask or GDK_WA_CURSOR;
|
// AttributesMask := AttributesMask or GDK_WA_CURSOR;
|
||||||
|
|
||||||
{$IFNDEF WinApiChilds}
|
|
||||||
Client^.OtherWindow := gdk_window_new(Widget^.Window, @Attributes, AttributesMask);
|
|
||||||
gdk_window_set_user_data (Client^.OtherWindow, Client);
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
Widget^.theStyle := gtk_style_attach(Widget^.theStyle, Widget^.Window);
|
Widget^.theStyle := gtk_style_attach(Widget^.theStyle, Widget^.Window);
|
||||||
|
|
||||||
gtk_style_set_background (Widget^.theStyle, Widget^.Window, GTK_STATE_NORMAL);
|
gtk_style_set_background (Widget^.theStyle, Widget^.Window, GTK_STATE_NORMAL);
|
||||||
@ -357,9 +345,7 @@ const
|
|||||||
);
|
);
|
||||||
begin
|
begin
|
||||||
if (TheType = 0) then
|
if (TheType = 0) then
|
||||||
TheType := gtk_type_unique(
|
TheType := gtk_type_unique(gtk_fixed_type,@Info);
|
||||||
{$IFDEF WinApiChilds}gtk_fixed_type{$ELSE}gtk_widget_type{$ENDIF},
|
|
||||||
@Info);
|
|
||||||
Result := TheType;
|
Result := TheType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -376,6 +362,9 @@ begin
|
|||||||
WriteLn('WARNING: [GTKAPIWidgetClient_HideCaret] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidgetClient_HideCaret] Got nil client');
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('GTKAPIWidgetClient_HideCaret ',HexStr(Cardinal(Client),8),' ShowHideOnFocus=',Client^.Caret.ShowHideOnFocus);
|
||||||
|
{$ENDIF}
|
||||||
Client^.Caret.Visible := False;
|
Client^.Caret.Visible := False;
|
||||||
GTKAPIWidgetClient_DrawCaret(Client);
|
GTKAPIWidgetClient_DrawCaret(Client);
|
||||||
end;
|
end;
|
||||||
@ -408,6 +397,10 @@ begin
|
|||||||
Timer := 0;
|
Timer := 0;
|
||||||
end;
|
end;
|
||||||
if IsDrawn and ((not Visible) or Blinking) then begin
|
if IsDrawn and ((not Visible) or Blinking) then begin
|
||||||
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('GTKAPIWidgetClient_DrawCaret ',HexStr(Cardinal(Client),8),
|
||||||
|
' Hiding Caret IsDrawn=',IsDrawn,' Visible=',Visible,' Blinking=',Blinking);
|
||||||
|
{$ENDIF}
|
||||||
// hide caret
|
// hide caret
|
||||||
if (BackPixmap <> nil) and (Widget<>nil) and (Widget^.theStyle<>nil)
|
if (BackPixmap <> nil) and (Widget<>nil) and (Widget^.theStyle<>nil)
|
||||||
then gdk_draw_pixmap(
|
then gdk_draw_pixmap(
|
||||||
@ -446,12 +439,14 @@ begin
|
|||||||
);
|
);
|
||||||
|
|
||||||
// draw caret
|
// draw caret
|
||||||
{writeln('GTKAPIWidgetClient_DrawCaret B Client=',HexStr(Cardinal(Client),8)
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('GTKAPIWidgetClient_DrawCaret B Client=',HexStr(Cardinal(Client),8)
|
||||||
,' ',cardinal(PGTKWidget(Client)^.theStyle)
|
,' ',cardinal(PGTKWidget(Client)^.theStyle)
|
||||||
,' ',cardinal(PGTKWidget(Client)^.Window)
|
,' ',cardinal(PGTKWidget(Client)^.Window)
|
||||||
,' ',Width
|
,' ',Width
|
||||||
,' ',Height
|
,' ',Height
|
||||||
);}
|
);
|
||||||
|
{$ENDIF}
|
||||||
if (PGTKWidget(Client)^.theStyle<>nil)
|
if (PGTKWidget(Client)^.theStyle<>nil)
|
||||||
and (PGTKWidget(Client)^.Window<>nil)
|
and (PGTKWidget(Client)^.Window<>nil)
|
||||||
and (Width>0) and (Height>0) then begin
|
and (Width>0) and (Height>0) then begin
|
||||||
@ -460,6 +455,9 @@ begin
|
|||||||
PGTKWidget(Client)^.theStyle)^.fg_gc[GC_STATE[Integer(Pixmap) <> 1]];
|
PGTKWidget(Client)^.theStyle)^.fg_gc[GC_STATE[Integer(Pixmap) <> 1]];
|
||||||
//gdk_gc_get_values(ForeGroundGC,@ForeGroundGCValues);
|
//gdk_gc_get_values(ForeGroundGC,@ForeGroundGCValues);
|
||||||
//OldGdkFunction:=ForeGroundGCValues.thefunction;
|
//OldGdkFunction:=ForeGroundGCValues.thefunction;
|
||||||
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('GTKAPIWidgetClient_DrawCaret ',HexStr(Cardinal(Client),8),' Real Drawing Caret ');
|
||||||
|
{$ENDIF}
|
||||||
gdk_gc_set_function(ForeGroundGC,GDK_invert);
|
gdk_gc_set_function(ForeGroundGC,GDK_invert);
|
||||||
try
|
try
|
||||||
// draw the caret
|
// draw the caret
|
||||||
@ -497,6 +495,9 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('GTKAPIWidgetClient_ShowCaret ',HexStr(Cardinal(Client),8));
|
||||||
|
{$ENDIF}
|
||||||
Client^.Caret.Visible := True;
|
Client^.Caret.Visible := True;
|
||||||
GTKAPIWidgetClient_DrawCaret(Client);
|
GTKAPIWidgetClient_DrawCaret(Client);
|
||||||
end;
|
end;
|
||||||
@ -506,7 +507,9 @@ procedure GTKAPIWidgetClient_CreateCaret(Client: PGTKAPIWidgetClient;
|
|||||||
var
|
var
|
||||||
IsVisible: Boolean;
|
IsVisible: Boolean;
|
||||||
begin
|
begin
|
||||||
//writeln('********** [GTKAPIWidgetClient_CreateCaret] A Client=',HexStr(Cardinal(Client),8),' Width=',AWidth,' Height=',AHeight,' Bitmap=',ABitmap<>nil);
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('********** [GTKAPIWidgetClient_CreateCaret] A Client=',HexStr(Cardinal(Client),8),' Width=',AWidth,' Height=',AHeight,' Bitmap=',ABitmap<>nil);
|
||||||
|
{$ENDIF}
|
||||||
if Client = nil
|
if Client = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidgetClient_CreateCaret] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidgetClient_CreateCaret] Got nil client');
|
||||||
@ -534,7 +537,9 @@ end;
|
|||||||
|
|
||||||
procedure GTKAPIWidgetClient_DestroyCaret(Client: PGTKAPIWidgetClient);
|
procedure GTKAPIWidgetClient_DestroyCaret(Client: PGTKAPIWidgetClient);
|
||||||
begin
|
begin
|
||||||
//writeln('********** [GTKAPIWidgetClient_DestroyCaret] A Client=',HexStr(Cardinal(Client),8));
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('********** [GTKAPIWidgetClient_DestroyCaret] A Client=',HexStr(Cardinal(Client),8));
|
||||||
|
{$ENDIF}
|
||||||
if Client = nil
|
if Client = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidgetClient_DestroyCaret] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidgetClient_DestroyCaret] Got nil client');
|
||||||
@ -550,7 +555,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
Pixmap := nil;
|
Pixmap := nil;
|
||||||
end;
|
end;
|
||||||
//writeln('********** B[GTKAPIWidgetClient_DestroyCaret] A Client=',HexStr(Cardinal(Client),8));
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('********** B[GTKAPIWidgetClient_DestroyCaret] A Client=',HexStr(Cardinal(Client),8));
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure GTKAPIWidgetClient_SetCaretPos(Client: PGTKAPIWidgetClient;
|
procedure GTKAPIWidgetClient_SetCaretPos(Client: PGTKAPIWidgetClient;
|
||||||
@ -558,7 +565,9 @@ procedure GTKAPIWidgetClient_SetCaretPos(Client: PGTKAPIWidgetClient;
|
|||||||
var
|
var
|
||||||
IsVisible: Boolean;
|
IsVisible: Boolean;
|
||||||
begin
|
begin
|
||||||
//Writeln('[GTKAPIWIDGETCLIENT] SetCaretPos '+inttostr(ax)+','+Inttostr(ay));
|
{$IFDEF VerboseCaret}
|
||||||
|
Writeln('[GTKAPIWIDGETCLIENT] SetCaretPos '+inttostr(ax)+','+Inttostr(ay));
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
if Client = nil
|
if Client = nil
|
||||||
then begin
|
then begin
|
||||||
@ -592,7 +601,10 @@ end;
|
|||||||
procedure GTKAPIWidgetClient_SetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
procedure GTKAPIWidgetClient_SetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
||||||
ShowHideOnFocus: boolean);
|
ShowHideOnFocus: boolean);
|
||||||
begin
|
begin
|
||||||
if Client = nil
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('[GTKAPIWidgetClient_SetCaretRespondToFocus] A ',ShowHideOnFocus);
|
||||||
|
{$ENDIF}
|
||||||
|
if Client = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn(
|
WriteLn(
|
||||||
'WARNING: [GTKAPIWidgetClient_SetCaretRespondToFocus] Got nil client');
|
'WARNING: [GTKAPIWidgetClient_SetCaretRespondToFocus] Got nil client');
|
||||||
@ -602,6 +614,19 @@ begin
|
|||||||
Client^.Caret.ShowHideOnFocus:=ShowHideOnFocus;
|
Client^.Caret.ShowHideOnFocus:=ShowHideOnFocus;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure GTKAPIWidgetClient_GetCaretRespondToFocus(Client: PGTKAPIWidgetClient;
|
||||||
|
var ShowHideOnFocus: boolean);
|
||||||
|
begin
|
||||||
|
if Client = nil
|
||||||
|
then begin
|
||||||
|
WriteLn(
|
||||||
|
'WARNING: [GTKAPIWidgetClient_GetCaretRespondToFocus] Got nil client');
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
ShowHideOnFocus:=Client^.Caret.ShowHideOnFocus;
|
||||||
|
end;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// GTKAPIWidget
|
// GTKAPIWidget
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@ -721,7 +746,9 @@ end;
|
|||||||
|
|
||||||
procedure GTKAPIWidget_HideCaret(APIWidget: PGTKAPIWidget);
|
procedure GTKAPIWidget_HideCaret(APIWidget: PGTKAPIWidget);
|
||||||
begin
|
begin
|
||||||
//writeln('[GTKAPIWidget_HideCaret] A');
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('[GTKAPIWidget_HideCaret] A');
|
||||||
|
{$ENDIF}
|
||||||
if APIWidget = nil
|
if APIWidget = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidget_HideCaret] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidget_HideCaret] Got nil client');
|
||||||
@ -732,7 +759,10 @@ end;
|
|||||||
|
|
||||||
procedure GTKAPIWidget_ShowCaret(APIWidget: PGTKAPIWidget);
|
procedure GTKAPIWidget_ShowCaret(APIWidget: PGTKAPIWidget);
|
||||||
begin
|
begin
|
||||||
if APIWidget = nil
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('[GTKAPIWidget_ShowCaret] A');
|
||||||
|
{$ENDIF}
|
||||||
|
if APIWidget = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidget_ShowCaret] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidget_ShowCaret] Got nil client');
|
||||||
Exit;
|
Exit;
|
||||||
@ -742,7 +772,10 @@ end;
|
|||||||
|
|
||||||
procedure GTKAPIWidget_SetCaretPos(APIWidget: PGTKAPIWidget; X, Y: Integer);
|
procedure GTKAPIWidget_SetCaretPos(APIWidget: PGTKAPIWidget; X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
if APIWidget = nil
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('[GTKAPIWidget_SetCaretPos] A');
|
||||||
|
{$ENDIF}
|
||||||
|
if APIWidget = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidget_SetCaretPos] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidget_SetCaretPos] Got nil client');
|
||||||
Exit;
|
Exit;
|
||||||
@ -763,7 +796,10 @@ end;
|
|||||||
procedure GTKAPIWidget_SetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
procedure GTKAPIWidget_SetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
||||||
ShowHideOnFocus: boolean);
|
ShowHideOnFocus: boolean);
|
||||||
begin
|
begin
|
||||||
if APIWidget = nil
|
{$IFDEF VerboseCaret}
|
||||||
|
writeln('[GTKAPIWidget_SetCaretRespondToFocus] A ',ShowHideOnFocus);
|
||||||
|
{$ENDIF}
|
||||||
|
if APIWidget = nil
|
||||||
then begin
|
then begin
|
||||||
WriteLn('WARNING: [GTKAPIWidget_SetCaretRespondToFocus] Got nil client');
|
WriteLn('WARNING: [GTKAPIWidget_SetCaretRespondToFocus] Got nil client');
|
||||||
Exit;
|
Exit;
|
||||||
@ -772,11 +808,27 @@ begin
|
|||||||
PGTKAPIWidgetClient(APIWidget^.Client), ShowHideOnFocus);
|
PGTKAPIWidgetClient(APIWidget^.Client), ShowHideOnFocus);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure GTKAPIWidget_GetCaretRespondToFocus(APIWidget: PGTKAPIWidget;
|
||||||
|
var ShowHideOnFocus: boolean);
|
||||||
|
begin
|
||||||
|
if APIWidget = nil
|
||||||
|
then begin
|
||||||
|
WriteLn('WARNING: [GTKAPIWidget_GetCaretRespondToFocus] Got nil client');
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
GTKAPIWidgetClient_GetCaretRespondToFocus(
|
||||||
|
PGTKAPIWidgetClient(APIWidget^.Client), ShowHideOnFocus);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.43 2002/12/30 17:24:08 mattias
|
||||||
|
added history to identifier completion
|
||||||
|
|
||||||
Revision 1.42 2002/12/23 10:28:02 mattias
|
Revision 1.42 2002/12/23 10:28:02 mattias
|
||||||
fixed setting background
|
fixed setting background
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user