SynEdit: Clean up

git-svn-id: trunk@25822 -
This commit is contained in:
martin 2010-06-01 20:12:35 +00:00
parent 87b1307bcf
commit 2ec8112e71

View File

@ -41,40 +41,29 @@ unit SynCompletion;
interface interface
uses uses
{$IFDEF SYN_LAZARUS}
LCLProc, LCLIntf, LCLType, SynEditMiscProcs, LCLProc, LCLIntf, LCLType, SynEditMiscProcs,
{$ELSE}
Windows, SynEditTypes, Messages,
{$ENDIF}
Classes, Graphics, Forms, Controls, StdCtrls, Menus, Classes, Graphics, Forms, Controls, StdCtrls, Menus,
SysUtils, SynEditKeyCmds, SynEditHighlighter, SysUtils, SynEditKeyCmds, SynEditHighlighter,
SynEdit; SynEdit;
type type
TSynBaseCompletionPaintItem = TSynBaseCompletionPaintItem =
function( function(const AKey: string; ACanvas: TCanvas;
{$IFDEF SYN_LAZARUS}const {$ENDIF}AKey: string; ACanvas: TCanvas; X, Y: integer; Selected: boolean; Index: integer
X, Y: integer ): boolean of object;
{$IFDEF SYN_LAZARUS}; Selected: boolean; Index: integer{$ENDIF}
): boolean of object;
{$IFDEF SYN_LAZARUS}
TSynBaseCompletionMeasureItem = TSynBaseCompletionMeasureItem =
function(const AKey: string; ACanvas: TCanvas; function(const AKey: string; ACanvas: TCanvas;
Selected: boolean; Index: integer): TPoint of object; Selected: boolean; Index: integer): TPoint of object;
{$ENDIF}
TCodeCompletionEvent = procedure(var Value: string; TCodeCompletionEvent = procedure(var Value: string;
SourceValue: string; SourceValue: string;
var SourceStart, SourceEnd: TPoint; var SourceStart, SourceEnd: TPoint;
KeyChar: TUTF8Char; KeyChar: TUTF8Char;
Shift: TShiftState) of object; Shift: TShiftState) of object;
TValidateEvent = procedure(Sender: TObject; TValidateEvent = procedure(Sender: TObject;
{$IFDEF SYN_LAZARUS}
KeyChar: TUTF8Char; KeyChar: TUTF8Char;
{$ENDIF}
Shift: TShiftState) of object; Shift: TShiftState) of object;
TSynBaseCompletionSearchPosition = procedure(var Position :integer) of object; TSynBaseCompletionSearchPosition = procedure(var Position :integer) of object;
{$IFDEF SYN_LAZARUS}
TSynBaseCompletionForm = class; TSynBaseCompletionForm = class;
{ TSynBaseCompletionHint } { TSynBaseCompletionHint }
@ -90,8 +79,7 @@ type
procedure Paint; override; procedure Paint; override;
property Index: Integer read FIndex write FIndex; property Index: Integer read FIndex write FIndex;
end; end;
{$ENDIF}
{ TSynBaseCompletionForm } { TSynBaseCompletionForm }
TSynBaseCompletionForm = class(TForm) TSynBaseCompletionForm = class(TForm)
@ -110,7 +98,6 @@ type
FOnCancel: TNotifyEvent; FOnCancel: TNotifyEvent;
FClSelect: TColor; FClSelect: TColor;
FCaseSensitive: boolean; FCaseSensitive: boolean;
{$IFDEF SYN_LAZARUS}
FBackgroundColor: TColor; FBackgroundColor: TColor;
FOnSearchPosition: TSynBaseCompletionSearchPosition; FOnSearchPosition: TSynBaseCompletionSearchPosition;
FOnKeyCompletePrefix: TNotifyEvent; FOnKeyCompletePrefix: TNotifyEvent;
@ -120,7 +107,6 @@ type
FTextSelectedColor: TColor; FTextSelectedColor: TColor;
FHint: TSynBaseCompletionHint; FHint: TSynBaseCompletionHint;
procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override; procedure UTF8KeyPress(var UTF8Key: TUTF8Char); override;
{$ENDIF}
procedure SetCurrentString(const Value: string); procedure SetCurrentString(const Value: string);
procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override; procedure KeyPress(var Key: char); override;
@ -137,14 +123,10 @@ type
procedure SetNbLinesInWindow(const Value: Integer); procedure SetNbLinesInWindow(const Value: Integer);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override; X, Y: Integer); override;
{$IFDEF SYN_LAZARUS}
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override; procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
{$ENDIF}
procedure StringListChange(Sender: TObject); procedure StringListChange(Sender: TObject);
{$IFDEF SYN_LAZARUS}
procedure DoOnResize; override; procedure DoOnResize; override;
procedure SetBackgroundColor(const AValue: TColor); procedure SetBackgroundColor(const AValue: TColor);
{$ENDIF}
procedure FontChanged(Sender: TObject); override; procedure FontChanged(Sender: TObject); override;
private private
Bitmap: TBitmap; // used for drawing Bitmap: TBitmap; // used for drawing
@ -161,10 +143,8 @@ type
property OnKeyDelete: TNotifyEvent read FOnKeyDelete write FOnKeyDelete; property OnKeyDelete: TNotifyEvent read FOnKeyDelete write FOnKeyDelete;
property OnPaintItem: TSynBaseCompletionPaintItem read FOnPaintItem property OnPaintItem: TSynBaseCompletionPaintItem read FOnPaintItem
write FOnPaintItem; write FOnPaintItem;
{$IFDEF SYN_LAZARUS}
property OnMeasureItem: TSynBaseCompletionMeasureItem read FOnMeasureItem property OnMeasureItem: TSynBaseCompletionMeasureItem read FOnMeasureItem
write FOnMeasureItem; write FOnMeasureItem;
{$ENDIF}
property OnValidate: TValidateEvent read FOnValidate write FOnValidate; property OnValidate: TValidateEvent read FOnValidate write FOnValidate;
property OnCancel: TNotifyEvent read FOnCancel write FOnCancel; property OnCancel: TNotifyEvent read FOnCancel write FOnCancel;
property ItemList: TStrings read FItemList write SetItemList; property ItemList: TStrings read FItemList write SetItemList;
@ -174,7 +154,6 @@ type
property ClSelect: TColor read FClSelect write FClSelect; property ClSelect: TColor read FClSelect write FClSelect;
property CaseSensitive: boolean read FCaseSensitive write FCaseSensitive; property CaseSensitive: boolean read FCaseSensitive write FCaseSensitive;
property CurrentEditor: TComponent read fCurrentEditor write fCurrentEditor; property CurrentEditor: TComponent read fCurrentEditor write fCurrentEditor;
{$IFDEF SYN_LAZARUS}
property FontHeight:integer read FFontHeight; property FontHeight:integer read FFontHeight;
property OnSearchPosition:TSynBaseCompletionSearchPosition property OnSearchPosition:TSynBaseCompletionSearchPosition
read FOnSearchPosition write FOnSearchPosition; read FOnSearchPosition write FOnSearchPosition;
@ -186,7 +165,6 @@ type
property TextColor: TColor read FTextColor write FTextColor; property TextColor: TColor read FTextColor write FTextColor;
property TextSelectedColor: TColor property TextSelectedColor: TColor
read FTextSelectedColor write FTextSelectedColor; read FTextSelectedColor write FTextSelectedColor;
{$ENDIF}
end; end;
{ TSynBaseCompletion } { TSynBaseCompletion }
@ -199,11 +177,9 @@ type
FWidth: Integer; FWidth: Integer;
function GetCaseSensitive: boolean; function GetCaseSensitive: boolean;
function GetClSelect: TColor; function GetClSelect: TColor;
{$IFDEF SYN_LAZARUS}
function GetOnMeasureItem: TSynBaseCompletionMeasureItem; function GetOnMeasureItem: TSynBaseCompletionMeasureItem;
function GetOnPositionChanged: TNotifyEvent; function GetOnPositionChanged: TNotifyEvent;
procedure SetCaseSensitive(const AValue: boolean); procedure SetCaseSensitive(const AValue: boolean);
{$ENDIF}
procedure SetClSelect(const Value: TColor); procedure SetClSelect(const Value: TColor);
function GetCurrentString: string; function GetCurrentString: string;
function GetItemList: TStrings; function GetItemList: TStrings;
@ -218,17 +194,14 @@ type
procedure SetNbLinesInWindow(const Value: Integer); procedure SetNbLinesInWindow(const Value: Integer);
procedure SetOnCancel(const Value: TNotifyEvent); procedure SetOnCancel(const Value: TNotifyEvent);
procedure SetOnKeyPress(const Value: TKeyPressEvent); procedure SetOnKeyPress(const Value: TKeyPressEvent);
{$IFDEF SYN_LAZARUS}
procedure SetOnMeasureItem(const AValue: TSynBaseCompletionMeasureItem); procedure SetOnMeasureItem(const AValue: TSynBaseCompletionMeasureItem);
procedure SetOnPositionChanged(const AValue: TNotifyEvent); procedure SetOnPositionChanged(const AValue: TNotifyEvent);
{$ENDIF}
procedure SetOnPaintItem(const Value: TSynBaseCompletionPaintItem); procedure SetOnPaintItem(const Value: TSynBaseCompletionPaintItem);
procedure SetPosition(const Value: Integer); procedure SetPosition(const Value: Integer);
procedure SetOnValidate(const Value: TValidateEvent); procedure SetOnValidate(const Value: TValidateEvent);
function GetOnKeyDelete: TNotifyEvent; function GetOnKeyDelete: TNotifyEvent;
procedure SetOnKeyDelete(const Value: TNotifyEvent); procedure SetOnKeyDelete(const Value: TNotifyEvent);
procedure SetWidth(Value: Integer); procedure SetWidth(Value: Integer);
{$IFDEF SYN_LAZARUS}
function GetOnUTF8KeyPress: TUTF8KeyPressEvent; function GetOnUTF8KeyPress: TUTF8KeyPressEvent;
procedure SetOnUTF8KeyPress(const AValue: TUTF8KeyPressEvent); procedure SetOnUTF8KeyPress(const AValue: TUTF8KeyPressEvent);
function GetFontHeight:integer; function GetFontHeight:integer;
@ -240,18 +213,15 @@ type
procedure SetOnKeyNextChar(const AValue: TNotifyEvent); procedure SetOnKeyNextChar(const AValue: TNotifyEvent);
function GetOnKeyPrevChar: TNotifyEvent; function GetOnKeyPrevChar: TNotifyEvent;
procedure SetOnKeyPrevChar(const AValue: TNotifyEvent); procedure SetOnKeyPrevChar(const AValue: TNotifyEvent);
{$ENDIF}
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure Execute(s: string; x, y: integer); procedure Execute(s: string; x, y: integer);
procedure Deactivate; procedure Deactivate;
{$IFDEF SYN_LAZARUS}
function IsActive: boolean; function IsActive: boolean;
function TheForm: TSynBaseCompletionForm; function TheForm: TSynBaseCompletionForm;
property OnUTF8KeyPress: TUTF8KeyPressEvent read GetOnUTF8KeyPress property OnUTF8KeyPress: TUTF8KeyPressEvent read GetOnUTF8KeyPress
write SetOnUTF8KeyPress; write SetOnUTF8KeyPress;
{$ENDIF}
property OnKeyPress: TKeyPressEvent read GetOnKeyPress write SetOnKeyPress; property OnKeyPress: TKeyPressEvent read GetOnKeyPress write SetOnKeyPress;
property OnKeyDelete: TNotifyEvent read GetOnKeyDelete write SetOnKeyDelete; property OnKeyDelete: TNotifyEvent read GetOnKeyDelete write SetOnKeyDelete;
property OnValidate: TValidateEvent read GetOnValidate write SetOnValidate; property OnValidate: TValidateEvent read GetOnValidate write SetOnValidate;
@ -261,15 +231,12 @@ type
property OnExecute: TNotifyEvent read FOnExecute write FOnExecute; property OnExecute: TNotifyEvent read FOnExecute write FOnExecute;
property OnPaintItem: TSynBaseCompletionPaintItem property OnPaintItem: TSynBaseCompletionPaintItem
read GetOnPaintItem write SetOnPaintItem; read GetOnPaintItem write SetOnPaintItem;
{$IFDEF SYN_LAZARUS}
property OnMeasureItem: TSynBaseCompletionMeasureItem read GetOnMeasureItem property OnMeasureItem: TSynBaseCompletionMeasureItem read GetOnMeasureItem
write SetOnMeasureItem; write SetOnMeasureItem;
{$ENDIF}
property ItemList: TStrings read GetItemList write SetItemList; property ItemList: TStrings read GetItemList write SetItemList;
property Position: Integer read GetPosition write SetPosition; property Position: Integer read GetPosition write SetPosition;
property NbLinesInWindow: Integer read GetNbLinesInWindow property NbLinesInWindow: Integer read GetNbLinesInWindow
write SetNbLinesInWindow; write SetNbLinesInWindow;
{$IFDEF SYN_LAZARUS}
property FontHeight: integer read GetFontHeight; property FontHeight: integer read GetFontHeight;
property OnSearchPosition: TSynBaseCompletionSearchPosition property OnSearchPosition: TSynBaseCompletionSearchPosition
read GetOnSearchPosition write SetOnSearchPosition; read GetOnSearchPosition write SetOnSearchPosition;
@ -281,7 +248,6 @@ type
write SetOnKeyPrevChar;// e.g. arrow left write SetOnKeyPrevChar;// e.g. arrow left
property OnPositionChanged: TNotifyEvent read GetOnPositionChanged property OnPositionChanged: TNotifyEvent read GetOnPositionChanged
write SetOnPositionChanged; write SetOnPositionChanged;
{$ENDIF}
property ClSelect: TColor read GetClSelect write SetClSelect; property ClSelect: TColor read GetClSelect write SetClSelect;
property CaseSensitive: boolean read GetCaseSensitive write SetCaseSensitive; property CaseSensitive: boolean read GetCaseSensitive write SetCaseSensitive;
property Width: Integer read FWidth write SetWidth; property Width: Integer read FWidth write SetWidth;
@ -373,11 +339,6 @@ procedure PrettyTextOut(c: TCanvas; x, y: integer; s: string);
implementation implementation
{$IFNDEF SYN_LAZARUS}
uses
SynEditStrConst;
{$ENDIF}
{ TSynBaseCompletionForm } { TSynBaseCompletionForm }
constructor TSynBaseCompletionForm.Create(AOwner: TComponent); constructor TSynBaseCompletionForm.Create(AOwner: TComponent);
@ -386,15 +347,7 @@ begin
{$IFNDEF OldAutoSize} {$IFNDEF OldAutoSize}
BeginFormUpdate; BeginFormUpdate;
{$ENDIF} {$ENDIF}
{$IFDEF SYN_LAZARUS}
inherited Create(AOwner); inherited Create(AOwner);
{$ELSE}
{$IFDEF SYN_CPPB_1}
CreateNew(AOwner, 0);
{$ELSE}
CreateNew(AOwner);
{$ENDIF}
{$ENDIF}
FItemList := TStringList.Create; FItemList := TStringList.Create;
BorderStyle := bsNone; BorderStyle := bsNone;
Scroll := TScrollBar.Create(self); Scroll := TScrollBar.Create(self);
@ -407,7 +360,6 @@ begin
Scroll.OnEnter := {$IFDEF FPC}@{$ENDIF}ScrollGetFocus; Scroll.OnEnter := {$IFDEF FPC}@{$ENDIF}ScrollGetFocus;
Scroll.OnScroll := {$IFDEF FPC}@{$ENDIF}ScrollScroll; Scroll.OnScroll := {$IFDEF FPC}@{$ENDIF}ScrollScroll;
Scroll.TabStop := False; Scroll.TabStop := False;
{$IFDEF SYN_LAZARUS}
Scroll.Visible := True; Scroll.Visible := True;
Scroll.Anchors:=[akTop,akRight]; Scroll.Anchors:=[akTop,akRight];
Scroll.Align:=alRight; Scroll.Align:=alRight;
@ -417,21 +369,13 @@ begin
Color:=clNone; Color:=clNone;
FBackgroundColor:=clWhite; FBackgroundColor:=clWhite;
FHint := TSynBaseCompletionHint.Create(Self); FHint := TSynBaseCompletionHint.Create(Self);
{$ENDIF}
Visible := false; Visible := false;
{$IFNDEF SYN_LAZARUS}
Color := clWindow;
{$ENDIF}
ClSelect := clHighlight; ClSelect := clHighlight;
TStringList(FItemList).OnChange := {$IFDEF FPC}@{$ENDIF}StringListChange; TStringList(FItemList).OnChange := {$IFDEF FPC}@{$ENDIF}StringListChange;
bitmap := TBitmap.Create; bitmap := TBitmap.Create;
FNbLinesInWindow := 6; FNbLinesInWindow := 6;
FontChanged(Font); FontChanged(Font);
{$IFNDEF SYN_LAZARUS}
ShowHint := True;
{$ELSE}
ShowHint := False; ShowHint := False;
{$ENDIF}
{$IFNDEF OldAutoSize} {$IFNDEF OldAutoSize}
EndFormUpdate; EndFormUpdate;
{$ENDIF} {$ENDIF}
@ -443,13 +387,11 @@ begin
// completion box lost focus // completion box lost focus
// this can happen when a hint window is clicked => ToDo // this can happen when a hint window is clicked => ToDo
Visible := False; Visible := False;
{$IFDEF SYN_LAZARUS}
FHint.Visible := False; FHint.Visible := False;
if Assigned(OnCancel) then OnCancel(Self); if Assigned(OnCancel) then OnCancel(Self);
if (FCurrentEditor<>nil) and (TCustomSynEdit(fCurrentEditor).HandleAllocated) if (FCurrentEditor<>nil) and (TCustomSynEdit(fCurrentEditor).HandleAllocated)
then then
SetCaretRespondToFocus(TCustomSynEdit(FCurrentEditor).Handle,true); SetCaretRespondToFocus(TCustomSynEdit(FCurrentEditor).Handle,true);
{$ENDIF}
end; end;
destructor TSynBaseCompletionForm.Destroy; destructor TSynBaseCompletionForm.Destroy;
@ -457,9 +399,7 @@ begin
bitmap.free; bitmap.free;
Scroll.Free; Scroll.Free;
FItemList.Free; FItemList.Free;
{$IFDEF SYN_LAZARUS}
FHint.Free; FHint.Free;
{$ENDIF}
inherited destroy; inherited destroy;
end; end;
@ -499,20 +439,16 @@ procedure TSynBaseCompletionForm.KeyDown(var Key: Word;
Shift: TShiftState); Shift: TShiftState);
var var
i: integer; i: integer;
{$IFDEF SYN_LAZARUS}
Handled: Boolean; Handled: Boolean;
{$ENDIF}
begin begin
//debugln('TSynBaseCompletionForm.KeyDown A Key=',dbgs(Key)); //debugln('TSynBaseCompletionForm.KeyDown A Key=',dbgs(Key));
{$IFDEF SYN_LAZARUS}
Handled:=true; Handled:=true;
{$ENDIF}
case Key of case Key of
// added the VK_XXX codes to make it more readable / maintainable // added the VK_XXX codes to make it more readable / maintainable
VK_RETURN: VK_RETURN:
if Assigned(OnValidate) then if Assigned(OnValidate) then
OnValidate(Self, {$IFDEF SYN_LAZARUS}'',{$ENDIF} Shift); OnValidate(Self, '', Shift);
VK_ESCAPE{$IFNDEF SYN_LAZARUS}, VK_SPACE{$ENDIF}: VK_ESCAPE:
if Assigned(OnCancel) then OnCancel(Self); if Assigned(OnCancel) then OnCancel(Self);
// I do not think there is a worst way to do this, but laziness rules :-) // I do not think there is a worst way to do this, but laziness rules :-)
VK_PRIOR: VK_PRIOR:
@ -540,7 +476,6 @@ begin
if Assigned(OnKeyDelete) then OnKeyDelete(Self); if Assigned(OnKeyDelete) then OnKeyDelete(Self);
CurrentString := Copy(CurrentString, 1, Length(CurrentString) - 1); CurrentString := Copy(CurrentString, 1, Length(CurrentString) - 1);
end; end;
{$IFDEF SYN_LAZARUS}
VK_TAB: VK_TAB:
begin begin
if Assigned(OnKeyCompletePrefix) then OnKeyCompletePrefix(Self); if Assigned(OnKeyCompletePrefix) then OnKeyCompletePrefix(Self);
@ -557,12 +492,9 @@ begin
end; end;
else else
Handled:=false; Handled:=false;
{$ENDIF}
end; end;
{$ifdef SYN_LAZARUS}
if Handled then Key:=VK_UNKNOWN; if Handled then Key:=VK_UNKNOWN;
Invalidate; Invalidate;
{$ENDIF}
end; end;
procedure TSynBaseCompletionForm.KeyPress(var Key: char); procedure TSynBaseCompletionForm.KeyPress(var Key: char);
@ -575,15 +507,12 @@ begin
case key of // case key of //
#33..'z': #33..'z':
begin begin
{$ifdef SYN_LAZARUS}
if Key<>#0 then if Key<>#0 then
{$ENDIF}
CurrentString := CurrentString + key; CurrentString := CurrentString + key;
Key:=#0; Key:=#0;
end; end;
#8: ; #8: ;
else else
{$ifdef SYN_LAZARUS}
if (ord(key)>=32) and Assigned(OnValidate) then begin if (ord(key)>=32) and Assigned(OnValidate) then begin
OnValidate(Self, Key, []); OnValidate(Self, Key, []);
Key:=#0; Key:=#0;
@ -591,13 +520,8 @@ begin
if Assigned(OnCancel) then OnCancel(Self); if Assigned(OnCancel) then OnCancel(Self);
Key:=#0; Key:=#0;
end; end;
{$ELSE}
if Assigned(OnCancel) then OnCancel(Self);
{$ENDIF}
end; // case end; // case
{$ifdef SYN_LAZARUS}
Invalidate; Invalidate;
{$ENDIF}
//debugln('TSynBaseCompletionForm.KeyPress END Key="',DbgStr(Key),'"'); //debugln('TSynBaseCompletionForm.KeyPress END Key="',DbgStr(Key),'"');
end; end;
@ -608,14 +532,12 @@ begin
Position := Scroll.Position + y; Position := Scroll.Position + y;
end; end;
{$IFDEF SYN_LAZARUS}
procedure TSynBaseCompletionForm.MouseMove(Shift: TShiftState; X,Y: Integer); procedure TSynBaseCompletionForm.MouseMove(Shift: TShiftState; X,Y: Integer);
begin begin
Y := (Y - 1) div FFontHeight; Y := (Y - 1) div FFontHeight;
ShowItemHint(Scroll.Position + Y); ShowItemHint(Scroll.Position + Y);
end; end;
{$ENDIF}
procedure TSynBaseCompletionForm.Paint; procedure TSynBaseCompletionForm.Paint;
var var
@ -646,23 +568,10 @@ begin
Scroll.PageSize := 0; Scroll.PageSize := 0;
Scroll.Max := 0; Scroll.Max := 0;
end; end;
{$IFNDEF SYN_LAZARUS}
Position := Position;
{$ENDIF}
{$IFDEF SYN_LAZARUS}
bitmap.SetSize(ClientWidth, ClientHeight); bitmap.SetSize(ClientWidth, ClientHeight);
{$ELSE} with bitmap do
bitmap.Width:=ClientWidth;
bitmap.Height:=ClientHeight;
{$ENDIF}
with bitmap do
begin begin
{$IFNDEF SYN_LAZARUS}
canvas.pen.color := fbcolor;
canvas.brush.color := color;
canvas.Rectangle(0, 0, Width, Height);
{$ENDIF}
//DebugLn(['TSynBaseCompletionForm.Paint NbLinesInWindow=',NbLinesInWindow,' ItemList.Count=',ItemList.Count]); //DebugLn(['TSynBaseCompletionForm.Paint NbLinesInWindow=',NbLinesInWindow,' ItemList.Count=',ItemList.Count]);
for i := 0 to min(NbLinesInWindow - 1, ItemList.Count - Scroll.Position - 1) do for i := 0 to min(NbLinesInWindow - 1, ItemList.Count - Scroll.Position - 1) do
begin begin
@ -672,40 +581,26 @@ begin
Canvas.Pen.Color := clSelect; Canvas.Pen.Color := clSelect;
Canvas.Rectangle(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1); Canvas.Rectangle(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1);
Canvas.Pen.Color := clBlack; Canvas.Pen.Color := clBlack;
{$IFDEF SYN_LAZARUS}
Canvas.Font.Color := TextSelectedColor; Canvas.Font.Color := TextSelectedColor;
{$ELSE}
Canvas.Font.Color := clWhite;
{$ENDIF}
Hint := ItemList[Position]; Hint := ItemList[Position];
end end
else else
begin begin
{$IFDEF SYN_LAZARUS}
Canvas.Brush.Color := BackgroundColor; Canvas.Brush.Color := BackgroundColor;
Canvas.Font.Color := TextColor; Canvas.Font.Color := TextColor;
Canvas.FillRect(Rect(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1)); Canvas.FillRect(Rect(0, (FFontHeight * i), width, (FFontHeight * (i + 1))+1));
{$ELSE}
Canvas.Brush.Color := Color;
Canvas.Font.Color := clBlack;
{$ENDIF}
end; end;
//DebugLn(['TSynBaseCompletionForm.Paint ',i,' ',ItemList[Scroll.Position + i]]); //DebugLn(['TSynBaseCompletionForm.Paint ',i,' ',ItemList[Scroll.Position + i]]);
if not Assigned(OnPaintItem) or if not Assigned(OnPaintItem) or
not OnPaintItem(ItemList[Scroll.Position + i], Canvas, not OnPaintItem(ItemList[Scroll.Position + i], Canvas,
{$IFDEF SYN_LAZARUS}
0, FFontHeight * i, i + Scroll.Position = Position, 0, FFontHeight * i, i + Scroll.Position = Position,
i + Scroll.Position i + Scroll.Position
{$ELSE}
0, FFontHeight * i
{$ENDIF}
) then ) then
begin begin
Canvas.TextOut(2, FFontHeight * i, ItemList[Scroll.Position + i]); Canvas.TextOut(2, FFontHeight * i, ItemList[Scroll.Position + i]);
end; end;
end; end;
{$IFDEF SYN_LAZARUS}
// paint the rest of the background // paint the rest of the background
if NbLinesInWindow > ItemList.Count - Scroll.Position then if NbLinesInWindow > ItemList.Count - Scroll.Position then
begin begin
@ -713,15 +608,10 @@ begin
i:=(FFontHeight * ItemList.Count)+1; i:=(FFontHeight * ItemList.Count)+1;
Canvas.FillRect(Rect(0, i, Width, Height)); Canvas.FillRect(Rect(0, i, Width, Height));
end; end;
{$ENDIF}
end; end;
Canvas.Draw(1, 1, bitmap); Canvas.Draw(1, 1, bitmap);
// draw a rectangle around the window // draw a rectangle around the window
{$IFDEF SYN_LAZARUS}
Canvas.Pen.Color := TextColor; Canvas.Pen.Color := TextColor;
{$ELSE}
Canvas.Pen.Color := clBlack;
{$ENDIF}
Canvas.Moveto(0, 0); Canvas.Moveto(0, 0);
Canvas.LineTo(Width - 1, 0); Canvas.LineTo(Width - 1, 0);
Canvas.LineTo(Width - 1, Height - 1); Canvas.LineTo(Width - 1, Height - 1);
@ -763,7 +653,6 @@ begin
Position := Position - 1; Position := Position - 1;
end; end;
{$IFDEF SYN_LAZARUS}
procedure TSynBaseCompletionForm.UTF8KeyPress(var UTF8Key: TUTF8Char); procedure TSynBaseCompletionForm.UTF8KeyPress(var UTF8Key: TUTF8Char);
begin begin
//debugln('TSynBaseCompletionForm.UTF8KeyPress A UTF8Key="',DbgStr(UTF8Key),'" ',dbgsName(TObject(TMethod(OnUTF8KeyPress).Data))); //debugln('TSynBaseCompletionForm.UTF8KeyPress A UTF8Key="',DbgStr(UTF8Key),'" ',dbgsName(TObject(TMethod(OnUTF8KeyPress).Data)));
@ -798,7 +687,6 @@ begin
end; end;
//debugln('TSynBaseCompletionForm.UTF8KeyPress END UTF8Key="',DbgStr(UTF8Key),'"'); //debugln('TSynBaseCompletionForm.UTF8KeyPress END UTF8Key="',DbgStr(UTF8Key),'"');
end; end;
{$ENDIF}
procedure TSynBaseCompletionForm.SetCurrentString(const Value: string); procedure TSynBaseCompletionForm.SetCurrentString(const Value: string);
var var
@ -806,13 +694,11 @@ var
begin begin
FCurrentString := Value; FCurrentString := Value;
//debugln('TSynBaseCompletionForm.SetCurrentString FCurrentString=',FCurrentString); //debugln('TSynBaseCompletionForm.SetCurrentString FCurrentString=',FCurrentString);
{$IFDEF SYN_LAZARUS}
if Assigned(FOnSearchPosition) then begin if Assigned(FOnSearchPosition) then begin
i:=Position; i:=Position;
FOnSearchPosition(i); FOnSearchPosition(i);
Position:=i; Position:=i;
end else begin end else begin
{$ENDIF}
if FCaseSensitive then begin if FCaseSensitive then begin
for i := 0 to Pred(ItemList.Count) do for i := 0 to Pred(ItemList.Count) do
if 0 = CompareStr(fCurrentString, if 0 = CompareStr(fCurrentString,
@ -830,12 +716,9 @@ begin
break; break;
end; end;
end; end;
{$IFDEF SYN_LAZARUS}
end; end;
{$ENDIF}
end; end;
{$IFDEF SYN_LAZARUS}
procedure TSynBaseCompletionForm.DoOnResize; procedure TSynBaseCompletionForm.DoOnResize;
var var
OldHeight: Integer; OldHeight: Integer;
@ -880,15 +763,11 @@ begin
end; end;
end; end;
{$ENDIF}
procedure TSynBaseCompletionForm.SetItemList(const Value: TStrings); procedure TSynBaseCompletionForm.SetItemList(const Value: TStrings);
begin begin
FItemList.Assign(Value); FItemList.Assign(Value);
{$IFDEF SYN_LAZARUS}
if Position>=FItemList.Count then Position:=-1; if Position>=FItemList.Count then Position:=-1;
Invalidate; Invalidate;
{$ENDIF}
end; end;
procedure TSynBaseCompletionForm.SetNbLinesInWindow( procedure TSynBaseCompletionForm.SetNbLinesInWindow(
@ -898,14 +777,8 @@ begin
try try
FNbLinesInWindow := Value; FNbLinesInWindow := Value;
Height := fFontHeight * NbLinesInWindow + 2; Height := fFontHeight * NbLinesInWindow + 2;
{$IFNDEF SYN_LAZARUS}
Scroll.Top := 1;
Scroll.Left := ClientWidth - Scroll.Width - 1;
Scroll.Height := Height - 2;
{$ELSE}
Bitmap.Width := Scroll.Left; Bitmap.Width := Scroll.Left;
Bitmap.Height := Height - 2; Bitmap.Height := Height - 2;
{$ENDIF}
finally finally
dec(FResizeLock); dec(FResizeLock);
end; end;
@ -924,10 +797,8 @@ begin
if Assigned(OnPositionChanged) then OnPositionChanged(Self); if Assigned(OnPositionChanged) then OnPositionChanged(Self);
end; end;
end; end;
{$IFDEF SYN_LAZARUS}
if Showing then if Showing then
ShowItemHint(Position); ShowItemHint(Position);
{$ENDIF}
end; end;
procedure TSynBaseCompletionForm.StringListChange(Sender: TObject); procedure TSynBaseCompletionForm.StringListChange(Sender: TObject);
@ -955,7 +826,6 @@ begin
inherited Destroy; inherited Destroy;
end; end;
{$IFDEF SYN_LAZARUS}
function TSynBaseCompletion.GetOnUTF8KeyPress: TUTF8KeyPressEvent; function TSynBaseCompletion.GetOnUTF8KeyPress: TUTF8KeyPressEvent;
begin begin
Result:=Form.OnUTF8KeyPress; Result:=Form.OnUTF8KeyPress;
@ -1012,20 +882,16 @@ procedure TSynBaseCompletion.SetOnKeyPrevChar(const AValue: TNotifyEvent);
begin begin
Form.OnKeyPrevChar:=AValue; Form.OnKeyPrevChar:=AValue;
end; end;
{$ENDIF}
procedure TSynBaseCompletion.Execute(s: string; x, y: integer); procedure TSynBaseCompletion.Execute(s: string; x, y: integer);
{$IFDEF SYN_LAZARUS}
var var
CurSynEdit: TSynEdit; CurSynEdit: TSynEdit;
{$ENDIF}
begin begin
//writeln(''); //writeln('');
//writeln('TSynBaseCompletion.Execute ',Form.CurrentEditor.Name); //writeln('TSynBaseCompletion.Execute ',Form.CurrentEditor.Name);
CurrentString := s; CurrentString := s;
if Assigned(OnExecute) then if Assigned(OnExecute) then
OnExecute(Self); OnExecute(Self);
{$IFDEF SYN_LAZARUS}
if (ItemList.Count=1) and Assigned(OnValidate) then begin if (ItemList.Count=1) and Assigned(OnValidate) then begin
OnValidate(Form, '', []); OnValidate(Form, '', []);
exit; exit;
@ -1041,14 +907,8 @@ begin
CurSynEdit.Options:=CurSynEdit.Options+[eoPersistentCaret]; CurSynEdit.Options:=CurSynEdit.Options+[eoPersistentCaret];
end; end;
Form.SetBounds(x,y,Form.Width,Form.Height); Form.SetBounds(x,y,Form.Width,Form.Height);
{$ELSE}
Form.Left:=x;
Form.Top:=y;
{$ENDIF}
Form.Show; Form.Show;
{$IFDEF SYN_LAZARUS}
Form.Position := Form.Position; Form.Position := Form.Position;
{$ENDIF}
end; end;
function TSynBaseCompletion.GetCurrentString: string; function TSynBaseCompletion.GetCurrentString: string;
@ -1116,7 +976,6 @@ begin
form.OnKeyPress := Value; form.OnKeyPress := Value;
end; end;
{$IFDEF SYN_LAZARUS}
procedure TSynBaseCompletion.SetOnMeasureItem( procedure TSynBaseCompletion.SetOnMeasureItem(
const AValue: TSynBaseCompletionMeasureItem); const AValue: TSynBaseCompletionMeasureItem);
begin begin
@ -1127,7 +986,6 @@ procedure TSynBaseCompletion.SetOnPositionChanged(const AValue: TNotifyEvent);
begin begin
Form.OnPositionChanged := AValue; Form.OnPositionChanged := AValue;
end; end;
{$ENDIF}
procedure TSynBaseCompletion.SetOnPaintItem(const Value: procedure TSynBaseCompletion.SetOnPaintItem(const Value:
TSynBaseCompletionPaintItem); TSynBaseCompletionPaintItem);
@ -1155,7 +1013,6 @@ begin
Result := Form.CaseSensitive; Result := Form.CaseSensitive;
end; end;
{$IFDEF SYN_LAZARUS}
function TSynBaseCompletion.GetOnMeasureItem: TSynBaseCompletionMeasureItem; function TSynBaseCompletion.GetOnMeasureItem: TSynBaseCompletionMeasureItem;
begin begin
Result := Form.OnMeasureItem; Result := Form.OnMeasureItem;
@ -1171,8 +1028,6 @@ begin
Form.CaseSensitive := AValue; Form.CaseSensitive := AValue;
end; end;
{$ENDIF}
procedure TSynBaseCompletion.SetClSelect(const Value: TColor); procedure TSynBaseCompletion.SetClSelect(const Value: TColor);
begin begin
Form.ClSelect := Value; Form.ClSelect := Value;
@ -1196,22 +1051,17 @@ begin
end; end;
procedure TSynBaseCompletion.Deactivate; procedure TSynBaseCompletion.Deactivate;
{$IFDEF SYN_LAZARUS}
var var
CurSynEdit: TSynEdit; CurSynEdit: TSynEdit;
{$ENDIF}
begin begin
{$IFDEF SYN_LAZARUS}
if (not OldPersistentCaret) if (not OldPersistentCaret)
and (Form<>nil) and (Form.CurrentEditor is TSynEdit) then begin and (Form<>nil) and (Form.CurrentEditor is TSynEdit) then begin
CurSynEdit:=TSynEdit(Form.CurrentEditor); CurSynEdit:=TSynEdit(Form.CurrentEditor);
CurSynEdit.Options:=CurSynEdit.Options-[eoPersistentCaret]; CurSynEdit.Options:=CurSynEdit.Options-[eoPersistentCaret];
end; end;
{$ENDIF}
if Assigned(Form) then Form.Deactivate; if Assigned(Form) then Form.Deactivate;
end; end;
{$IFDEF SYN_LAZARUS}
function TSynBaseCompletion.IsActive: boolean; function TSynBaseCompletion.IsActive: boolean;
begin begin
Result:=(Form<>nil) and (Form.Visible); Result:=(Form<>nil) and (Form.Visible);
@ -1221,30 +1071,17 @@ function TSynBaseCompletion.TheForm: TSynBaseCompletionForm;
begin begin
Result:=Form; Result:=Form;
end; end;
{$ENDIF}
procedure PrettyTextOut(c: TCanvas; x, y: integer; s: string); procedure PrettyTextOut(c: TCanvas; x, y: integer; s: string);
var var
i: integer; i: integer;
{$IFNDEF SYN_LAZARUS}
b: TBrush;
f: TFont;
{$ELSE}
OldFontColor: TColor; OldFontColor: TColor;
OldFontStyle: TFontStyles; OldFontStyle: TFontStyles;
{$ENDIF}
begin begin
{$IFDEF SYN_LAZARUS}
OldFontColor:=c.Font.Color; OldFontColor:=c.Font.Color;
OldFontStyle:=c.Font.Style; OldFontStyle:=c.Font.Style;
c.Font.Style:=[]; c.Font.Style:=[];
c.Font.Color:=clBlack; c.Font.Color:=clBlack;
{$ELSE}
b := TBrush.Create;
b.Assign(c.Brush);
f := TFont.Create;
f.Assign(c.Font);
{$ENDIF}
try try
i := 1; i := 1;
while i <= Length(s) do while i <= Length(s) do
@ -1275,15 +1112,8 @@ begin
end; end;
except except
end; end;
{$IFDEF SYN_LAZARUS}
c.Font.Color:=OldFontColor; c.Font.Color:=OldFontColor;
c.Font.Style:=OldFontStyle; c.Font.Style:=OldFontStyle;
{$ELSE}
c.Font.Assign(f);
f.Free;
c.Brush.Assign(b);
b.Free;
{$ENDIF}
end; end;
{ TSynCompletion } { TSynCompletion }
@ -1409,11 +1239,7 @@ end;
constructor TSynCompletion.Create(AOwner: TComponent); constructor TSynCompletion.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
{$IFDEF SYN_LAZARUS}
Form.OnUTF8KeyPress := @UTF8KeyPress; Form.OnUTF8KeyPress := @UTF8KeyPress;
{$ELSE}
Form.OnKeyPress := {$IFDEF FPC}@{$ENDIF}KeyPress;
{$ENDIF}
Form.OnKeyDelete := {$IFDEF FPC}@{$ENDIF}Backspace; Form.OnKeyDelete := {$IFDEF FPC}@{$ENDIF}Backspace;
Form.OnValidate := {$IFDEF FPC}@{$ENDIF}Validate; Form.OnValidate := {$IFDEF FPC}@{$ENDIF}Validate;
Form.OnCancel := {$IFDEF FPC}@{$ENDIF}Cancel; Form.OnCancel := {$IFDEF FPC}@{$ENDIF}Cancel;
@ -1525,14 +1351,7 @@ end;
function TSynCompletion.GetFEditor: TCustomSynEdit; function TSynCompletion.GetFEditor: TCustomSynEdit;
begin begin
{$IFDEF SYN_LAZARUS}
Result:=TCustomSynEdit(Form.fCurrentEditor); Result:=TCustomSynEdit(Form.fCurrentEditor);
{$ELSE}
if EditorsCount > 0 then
result := Editors[0]
else
result := nil;
{$ENDIF}
end; end;
procedure TSynCompletion.AddEditor(aEditor: TCustomSynEdit); procedure TSynCompletion.AddEditor(aEditor: TCustomSynEdit);
@ -1850,8 +1669,6 @@ begin
end; end;
end; end;
{$IFDEF SYN_LAZARUS}
{ TSynBaseCompletionHint } { TSynBaseCompletionHint }
procedure TSynBaseCompletionHint.Paint; procedure TSynBaseCompletionHint.Paint;
@ -1905,7 +1722,5 @@ begin
Result := Rect(0, 0, Canvas.TextWidth(AHint) + 4, FCompletionForm.FontHeight); Result := Rect(0, 0, Canvas.TextWidth(AHint) + 4, FCompletionForm.FontHeight);
end; end;
{$ENDIF}
end. end.