summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prototypes/fpgui2/tests/edittest.dpr3
-rw-r--r--src/corelib/gfx_widget.pas10
-rw-r--r--src/gui/gui_edit.pas120
3 files changed, 113 insertions, 20 deletions
diff --git a/prototypes/fpgui2/tests/edittest.dpr b/prototypes/fpgui2/tests/edittest.dpr
index 29089e93..aa2c5290 100644
--- a/prototypes/fpgui2/tests/edittest.dpr
+++ b/prototypes/fpgui2/tests/edittest.dpr
@@ -373,9 +373,12 @@ begin
w.Left := 140;
edit1 := CreateEdit(self, 10, 40, 120, 22);
+ edit1.AutoSelect := False;
+ edit1.HideSelection := False;
edit1.Text := 'Hello world. Hello world. Hello world.';
edit2 := CreateEdit(self, 10, 70, 200, 22);
edit2.Text := 'UTF-8 text -> Òåñò';
+
// writeln(UTF8Length(edit2.text));
// writeln(Length(edit2.text));
UTF8Insert('ö', edit2.Text, 15);
diff --git a/src/corelib/gfx_widget.pas b/src/corelib/gfx_widget.pas
index 442b3ed8..8aafe95c 100644
--- a/src/corelib/gfx_widget.pas
+++ b/src/corelib/gfx_widget.pas
@@ -19,6 +19,8 @@ type
FAlignRect: TfpgRect;
FOnClick: TNotifyEvent;
FOnDoubleClick: TMouseButtonEvent;
+ FOnEnter: TNotifyEvent;
+ FOnExit: TNotifyEvent;
FOnMouseDown: TMouseButtonEvent;
FOnMouseEnter: TNotifyEvent;
FOnMouseExit: TNotifyEvent;
@@ -83,6 +85,8 @@ type
procedure RePaint;
{ property events }
property OnPaint: TPaintEvent read FOnPaint write FOnPaint;
+ property OnEnter: TNotifyEvent read FOnEnter write FOnEnter;
+ property OnExit: TNotifyEvent read FOnExit write FOnExit;
property OnMouseExit: TNotifyEvent read FOnMouseExit write FOnMouseExit;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
@@ -645,6 +649,9 @@ begin
Parent.ActiveWidget := self;
Parent.SetFocus;
end;
+
+ if Assigned(OnEnter) then
+ OnEnter(self);
end;
procedure TfpgWidget.HandleKillFocus;
@@ -654,6 +661,9 @@ begin
if ActiveWidget <> nil then
ActiveWidget.KillFocus;
+
+ if Assigned(OnExit) then
+ OnExit(self);
end;
procedure TfpgWidget.HandleLMouseDown(x, y: integer; shiftstate: TShiftState);
diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas
index 83ded8ff..c81784bb 100644
--- a/src/gui/gui_edit.pas
+++ b/src/gui/gui_edit.pas
@@ -34,20 +34,24 @@ type
TfpgCustomEdit = class(TfpgWidget)
private
+ FAutoSelect: Boolean;
+ FHideSelection: Boolean;
FText: string;
FBackgroundColor: TfpgColor;
FFont: TfpgFont;
- FPasswordMode: boolean;
+ FPasswordMode: Boolean;
FBorderStyle: TfpgEditBorderStyle;
FOnChange: TNotifyEvent;
FMaxLength: integer;
- FSelecting: boolean;
+ FSelecting: Boolean;
procedure AdjustCursor;
procedure DeleteSelection;
procedure DoCopy;
procedure DoPaste;
+ procedure SetAutoSelect(const AValue: Boolean);
procedure SetBackgroundColor(const AValue: TfpgColor);
procedure SetBorderStyle(const AValue: TfpgEditBorderStyle);
+ procedure SetHideSelection(const AValue: Boolean);
procedure SetPasswordMode(const AValue: boolean);
function GetFontDesc: string;
procedure SetFontDesc(const AValue: string);
@@ -60,43 +64,56 @@ type
FSelOffset: integer;
FCursorPos: integer;
procedure HandlePaint; override;
- procedure HandleKeyChar(var AText: string; var shiftstate: TShiftState; var consumed: boolean); override;
- procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override;
+ procedure HandleKeyChar(var AText: String; var shiftstate: TShiftState; var consumed: Boolean); override;
+ procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: Boolean); override;
procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override;
procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override;
procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); override;
procedure HandleMouseEnter; override;
procedure HandleMouseExit; override;
- function GetDrawText: string;
+ procedure HandleSetFocus; override;
+ procedure HandleKillFocus; override;
+ function GetDrawText: String;
+ property AutoSelect: Boolean read FAutoSelect write SetAutoSelect default True;
property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor default clBoxColor;
property Font: TfpgFont read FFont;
- property FontDesc: string read GetFontDesc write SetFontDesc;
- property PasswordMode: boolean read FPasswordMode write SetPasswordMode default False;
+ property FontDesc: String read GetFontDesc write SetFontDesc;
+ property HideSelection: Boolean read FHideSelection write SetHideSelection default True;
+ property PasswordMode: Boolean read FPasswordMode write SetPasswordMode default False;
property BorderStyle: TfpgEditBorderStyle read FBorderStyle write SetBorderStyle default bsDefault;
- property Text: string read FText write SetText;
- property MaxLength: integer read FMaxLength write FMaxLength;
+ property Text: String read FText write SetText;
+ property MaxLength: Integer read FMaxLength write FMaxLength;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function SelectionText: string;
procedure SelectAll;
+ procedure Clear;
+ procedure ClearSelection;
+ procedure CopyToClipboard;
+ procedure CutToClipboard;
+ procedure PasteFromClipboard;
end;
TfpgEdit = class(TfpgCustomEdit)
published
- property Text;
- property FontDesc;
+ property AutoSelect;
property BackgroundColor;
+ property BorderStyle;
+ property FontDesc;
+ property HideSelection;
property MaxLength;
property PasswordMode;
- property BorderStyle;
+ property Text;
property OnChange;
- property OnPaint;
- property OnMouseExit;
- property OnMouseEnter;
+ property OnEnter;
+ property OnExit;
property OnKeyPress;
+ property OnMouseEnter;
+ property OnMouseExit;
+ property OnPaint;
end;
@@ -157,6 +174,13 @@ begin
RePaint;
end;
+procedure TfpgCustomEdit.SetHideSelection(const AValue: Boolean);
+begin
+ if FHideSelection = AValue then
+ Exit;
+ FHideSelection := AValue;
+end;
+
procedure TfpgCustomEdit.HandlePaint;
var
r: TfpgRect;
@@ -221,24 +245,30 @@ begin
Canvas.SetFont(FFont);
fpgStyle.DrawString(Canvas, -FDrawOffset + FSideMargin, 3, dtext, Enabled);
- // drawing selection
- if FSelOffset <> 0 then
- DrawSelection;
if Focused then
begin
+ // drawing selection
+ if FSelOffset <> 0 then
+ DrawSelection;
+
// drawing cursor
tw := FFont.TextWidth(UTF8copy(dtext, 1, FCursorPos));
fpgCaret.SetCaret(Canvas, -FDrawOffset + FSideMargin + tw, 3, fpgCaret.Width, FFont.Height);
end
else
+ begin
+ // drawing selection
+ if (AutoSelect = False) and (FSelOffset <> 0) and (HideSelection = False) then
+ DrawSelection;
fpgCaret.UnSetCaret(Canvas);
+ end;
Canvas.EndDraw;
end;
-procedure TfpgCustomEdit.HandleKeyChar(var AText: string;
- var shiftstate: TShiftState; var consumed: boolean);
+procedure TfpgCustomEdit.HandleKeyChar(var AText: String;
+ var shiftstate: TShiftState; var consumed: Boolean);
var
s: string;
prevval: string;
@@ -520,6 +550,21 @@ begin
MouseCursor := mcDefault;
end;
+procedure TfpgCustomEdit.HandleSetFocus;
+begin
+ inherited HandleSetFocus;
+ writeln('FSelOffset: ', FSelOffset);
+ if AutoSelect then
+ SelectAll;
+end;
+
+procedure TfpgCustomEdit.HandleKillFocus;
+begin
+ inherited HandleKillFocus;
+ if AutoSelect then
+ FSelOffset := 0;
+end;
+
function TfpgCustomEdit.GetDrawText: string;
begin
if not PassWordMode then
@@ -536,7 +581,9 @@ begin
FHeight := FFont.Height + 6;
FWidth := 120;
FBackgroundColor := clBoxColor;
+ FAutoSelect := True;
FSelecting := False;
+ FHideSelection := True;
FSideMargin := 3;
FMaxLength := 0; // no limit
FText := '';
@@ -663,6 +710,13 @@ begin
Repaint;
end;
+procedure TfpgCustomEdit.SetAutoSelect(const AValue: Boolean);
+begin
+ if FAutoSelect = AValue then
+ Exit; //==>
+ FAutoSelect := AValue;
+end;
+
procedure TfpgCustomEdit.SelectAll;
begin
FSelecting := True;
@@ -672,5 +726,31 @@ begin
Repaint;
end;
+procedure TfpgCustomEdit.Clear;
+begin
+ Text := '';
+end;
+
+procedure TfpgCustomEdit.ClearSelection;
+begin
+ DeleteSelection;
+end;
+
+procedure TfpgCustomEdit.CopyToClipboard;
+begin
+ DoCopy;
+end;
+
+procedure TfpgCustomEdit.CutToClipboard;
+begin
+ DoCopy;
+ DeleteSelection;
+end;
+
+procedure TfpgCustomEdit.PasteFromClipboard;
+begin
+ DoPaste;
+end;
+
end.