added some TEdit ideas to TSpinEdit

git-svn-id: trunk@5158 -
This commit is contained in:
mattias 2004-02-04 00:04:37 +00:00
parent e79cacbb9c
commit 2f6b16b01a
5 changed files with 227 additions and 54 deletions

View File

@ -336,12 +336,12 @@ End;
Procedure TCustomEdit.Change;
Begin
//inherited Change;
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TCustomEdit.InitializeWnd;
var ASelStart, ASelLength : integer;
var
ASelStart, ASelLength : integer;
begin
inherited InitializeWnd;
if FSelStart <> FSelLength then begin
@ -357,6 +357,9 @@ end;
{ =============================================================================
$Log$
Revision 1.22 2004/02/04 00:04:37 mattias
added some TEdit ideas to TSpinEdit
Revision 1.21 2004/01/23 20:31:43 mattias
fixed TCustomEdit copying to clipboard

View File

@ -17,7 +17,7 @@
}
{-----------------------------------------------------------------------------}
procedure TSpinEdit.UpdateControl;
procedure TCustomSpinEdit.UpdateControl;
begin
if MaxValue<MinValue then fMaxValue:=MinValue;
if Value<fMinValue then Value:=fMinValue;
@ -31,29 +31,61 @@ begin
fValueNeedsUpdate:=false;
end;
function TSpinEdit.ValueIsStored: boolean;
function TCustomSpinEdit.ValueIsStored: boolean;
begin
Result:=true; // fpc bug, default value is always 0
end;
procedure TSpinEdit.SetMaxValue(const AValue: single);
procedure TCustomSpinEdit.CMTextChanged(var Message: TLMessage);
begin
if Value=fLastValueOnChange then exit;
fLastValueOnChange:=Value;
Modified := True;
if HandleAllocated and (not (csLoading in ComponentState)) then Change;
end;
procedure TCustomSpinEdit.SetMaxValue(const AValue: single);
begin
if FMaxValue=AValue then exit;
FMaxValue:=AValue;
UpdateControl;
end;
function TSpinEdit.Climb_RateIsStored: boolean;
function TCustomSpinEdit.Climb_RateIsStored: boolean;
begin
Result:=fClimbRate<>1;
end;
function TSpinEdit.MaxValueIsStored: boolean;
function TCustomSpinEdit.GetModified: Boolean;
begin
Result := FModified;
end;
function TCustomSpinEdit.GetSelLength: integer;
begin
if HandleAllocated then
FSelLength := CNSendMessage(LM_GETSELLEN, Self, nil);
Result:= FSelLength;
end;
function TCustomSpinEdit.GetSelStart: integer;
begin
if HandleAllocated then
FSelStart:= CNSendMessage(LM_GETSELSTART, Self, nil);
Result:= FSelStart;
end;
function TCustomSpinEdit.GetSelText: String;
begin
Result:= Copy(Text, SelStart + 1, SelLength)
end;
function TCustomSpinEdit.MaxValueIsStored: boolean;
begin
Result:=true; // fpc bug, default value is always 0
end;
function TSpinEdit.MinValueIsStored: boolean;
function TCustomSpinEdit.MinValueIsStored: boolean;
begin
Result:=true; // fpc bug, default value is always 0
end;
@ -61,43 +93,86 @@ end;
{-----------------------------------------------------------------------------}
procedure TSpinEdit.SetMinValue(const AValue: single);
procedure TCustomSpinEdit.SetMinValue(const AValue: single);
begin
if FMinValue=AValue then exit;
FMinValue:=AValue;
UpdateControl;
end;
procedure TSpinEdit.SetClimbRate(Num : Single);
procedure TCustomSpinEdit.SetModified(const AValue: Boolean);
begin
FModified := AValue;
end;
procedure TCustomSpinEdit.SetSelLength(const AValue: integer);
begin
FSelLength:= AValue;
if HandleAllocated then
CNSendMessage(LM_SETSELLEN, Self, Pointer(FSelLength));
end;
procedure TCustomSpinEdit.SetSelStart(const AValue: integer);
begin
FSelStart:= AValue;
if HandleAllocated then
CNSendMessage(LM_SETSELSTART, Self, Pointer(FSelStart));
end;
procedure TCustomSpinEdit.SetSelText(const AValue: String);
var
OldText, NewText: string;
begin
OldText:=Text;
NewText:=LeftStr(OldText,SelStart)+AValue
+RightStr(OldText,length(OldText)-SelStart-SelLength);
Text:=NewText;
end;
procedure TCustomSpinEdit.SetClimbRate(Num : Single);
begin
if fClimbRate = Num then exit;
fClimbRate := Num;
UpdateControl;
end;
procedure TSpinEdit.InitializeWnd;
procedure TCustomSpinEdit.InitializeWnd;
var
ASelStart, ASelLength : integer;
begin
inherited InitializeWnd;
UpdateControl;
if FSelStart <> FSelLength then begin
ASelStart:= FSelStart;
ASelLength:= FSelLength;
SelStart:= ASelStart;
SelLength:= ASelLength;
end;
end;
procedure TSpinEdit.Loaded;
procedure TCustomSpinEdit.Loaded;
begin
inherited Loaded;
if fValueNeedsUpdate then UpdateControl;
end;
procedure TCustomSpinEdit.Change;
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
{-----------------------------------------------------------------------------}
Procedure TSpinEdit.SetValue(num : Single);
Procedure TCustomSpinEdit.SetValue(num : Single);
begin
if FValue = Num then exit;
FValue := Num;
fLastValueOnChange := FValue;
fValueNeedsUpdate:=true;
UpdateControl;
end;
{-----------------------------------------------------------------------------}
Function TSpinEdit.GetValue : Single;
Function TCustomSpinEdit.GetValue: Single;
Var
Temp : Single;
begin
@ -109,7 +184,7 @@ begin
end;
{-----------------------------------------------------------------------------}
procedure TSpinEdit.SetDecimals(Num : Integer);
procedure TCustomSpinEdit.SetDecimals(Num : Integer);
begin
if fDecimals = Num then exit;
fDecimals := Num;
@ -117,11 +192,11 @@ begin
end;
{-----------------------------------------------------------------------------}
constructor TSpinEdit.Create(AOwner : TComponent);
constructor TCustomSpinEdit.Create(TheOwner : TComponent);
begin
inherited Create(AOwner);
inherited Create(TheOwner);
fCompStyle := csSpinEdit;
fClimbRate := 1;
fDecimals := 2;
fValue := 0;
@ -129,14 +204,45 @@ begin
fMinValue := 0;
fMaxValue := 100;
SetBounds(1,1,50,20);
SetInitialBounds(1,1,50,20);
end;
{-----------------------------------------------------------------------------}
destructor TSpinEdit.Destroy;
destructor TCustomSpinEdit.Destroy;
begin
inherited Destroy;
end;
procedure TCustomSpinEdit.SelectAll;
begin
if Text <> '' then begin
SetSelStart(0);
SetSelLength(Length(Text));
end;
end;
procedure TCustomSpinEdit.ClearSelection;
begin
if SelLength > 0 then
SelText := '';
end;
procedure TCustomSpinEdit.CopyToClipboard;
begin
Clipboard.AsText := SelText;
end;
procedure TCustomSpinEdit.CutToClipboard;
begin
CopyToClipboard;
ClearSelection;
end;
procedure TCustomSpinEdit.PasteFromClipboard;
begin
if Clipboard.HasFormat(CF_TEXT) then
SelText := Clipboard.AsText;
end;
// included by spin.pp

View File

@ -4008,7 +4008,8 @@ begin
end;
{$IfDef GTK1}
csEdit: Text:= StrPas(gtk_entry_get_text(PgtkEntry(TWinControl(Sender).Handle)));
csEdit, csSpinEdit:
Text:= StrPas(gtk_entry_get_text(PgtkEntry(TWinControl(Sender).Handle)));
csMemo : begin
CS := gtk_editable_get_chars(PGtkOldEditable(
@ -4434,6 +4435,7 @@ begin
end;
LM_CHANGED :
begin
if Sender is TTrackBar then
begin
ConnectSenderSignal(gtk_Object(
@ -4446,12 +4448,13 @@ begin
else
if Sender is TCustomCombobox then
ConnectSenderSignal (PGtkObject(
PGtkCombo(gobject)^.entry), 'changed', @gtkchangedCB)
PGtkCombo(gObject)^.entry), 'changed', @gtkchangedCB)
else
if Sender is TCustomMemo then
ConnectSenderSignal(gCore, 'changed', @gtkchanged_editbox)
else
ConnectSenderSignal(gObject, 'changed', @gtkchanged_editbox);
end;
LM_CLICKED :
begin
@ -5115,7 +5118,7 @@ begin
End;
{$IfDef GTK1}
csEdit:
csEdit, csSpinEdit:
begin
SetCallback(LM_CHANGED, Sender);
SetCallback(LM_ACTIVATE, Sender);
@ -7991,12 +7994,10 @@ begin
csSpinEdit:
Begin
AnAdjustment:=gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(wHandle));
writeln('SetProperties ',AnAdjustment^.lower,' ',TSpinEdit(Sender).MinValue);
if (AnAdjustment^.lower<>TSpinEdit(Sender).MinValue)
or (AnAdjustment^.upper<>TSpinEdit(Sender).MaxValue) then
begin
AnAdjustment^.lower:=TSpinEdit(Sender).MinValue;
writeln('SetProperties ',AnAdjustment^.lower,' ',TSpinEdit(Sender).MinValue);
AnAdjustment^.upper:=TSpinEdit(Sender).MaxValue;
gtk_adjustment_changed(AnAdjustment);
end;
@ -9183,6 +9184,9 @@ end;
{ =============================================================================
$Log$
Revision 1.462 2004/02/04 00:04:37 mattias
added some TEdit ideas to TSpinEdit
Revision 1.461 2004/02/03 20:01:29 mattias
fixed gtk intf WaitMessages

View File

@ -30,49 +30,104 @@ unit Spin;
interface
uses
Classes, Controls, SysUtils, StdCtrls, VCLGlobals, LMessages;
Classes, Controls, SysUtils, VCLGlobals, LMessages, ClipBrd, StdCtrls;
type
TSpinEdit = class(TWinControl)
{ TCustomSpinEdit }
TCustomSpinEdit = class(TWinControl)
private
fDecimals : Integer;
fClimbRate: Single;
fDecimals: Integer;
fLastValueOnChange: single;
FMaxValue: single;
FMinValue: single;
fValue : Single;
fClimbRate : Single;
FModified: boolean;
FOnChange: TNotifyEvent;
FSelLength: integer;
FSelStart: integer;
fValue: Single;
fValueNeedsUpdate: boolean;
function Climb_RateIsStored: boolean;
function GetModified: Boolean;
function GetSelLength: integer;
function GetSelStart: integer;
function GetSelText: String;
function MaxValueIsStored: boolean;
function MinValueIsStored: boolean;
procedure SetMaxValue(const AValue: single);
procedure SetMinValue(const AValue: single);
procedure SetModified(const AValue: Boolean);
procedure SetSelLength(const AValue: integer);
procedure SetSelStart(const AValue: integer);
procedure SetSelText(const AValue: String);
Procedure UpdateControl;
function ValueIsStored: boolean;
protected
procedure SetDecimals(num : Integer);
Function GetValue : Single;
procedure SetValue(Num : Single);
procedure SetClimbRate(num : Single);
procedure CMTextChanged(Var Message: TLMessage); message CM_TextChanged;
procedure SetDecimals(Num: Integer);
Function GetValue: Single;
procedure SetValue(Num: Single);
procedure SetClimbRate(Num: Single);
procedure InitializeWnd; override;
procedure Loaded; override;
procedure Change; dynamic;
public
constructor Create(AOwner : TComponent); override;
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure SelectAll;
procedure ClearSelection; virtual;
procedure CopyToClipboard; virtual;
procedure CutToClipboard; virtual;
procedure PasteFromClipboard; virtual;
property SelLength: integer read GetSelLength write SetSelLength;
property SelStart: integer read GetSelStart write SetSelStart;
property SelText: String read GetSelText write SetSelText;
property Modified: Boolean read GetModified write SetModified;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Text;
published
property Align;
property Decimal_Places: Integer read fDecimals write SetDecimals default 2;
property Enabled;
property Climb_Rate : Single read fClimbRate write SetClimbRate stored Climb_RateIsStored;
property MinValue: single read FMinValue write SetMinValue stored MinValueIsStored;
property MaxValue: single read FMaxValue write SetMaxValue stored MaxValueIsStored;
property Value: Single read GetValue write SetValue stored ValueIsStored;
end;
{ TSpinEdit }
TSpinEdit = class(TCustomSpinEdit)
published
property Align;
property Anchors;
property Climb_Rate;
property Constraints;
property Decimal_Places;
property Enabled;
property MaxValue;
property MinValue;
property OnChange;
property OnChangeBounds;
property OnClick;
property OnEnter;
property OnExit;
Property OnKeyDown;
property OnKeyPress;
Property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Value: Single read GetValue write SetValue stored ValueIsStored;
property TabStop;
property TabOrder;
property Value;
property Visible;
end;
procedure Register;

View File

@ -451,15 +451,15 @@ type
TCustomEdit = class(TWinControl)
private
FCharCase : TEditCharCase;
FEchoMode : TEchoMode;
FMaxLength : Integer;
FModified : Boolean;
FCharCase: TEditCharCase;
FEchoMode: TEchoMode;
FMaxLength: Integer;
FModified: Boolean;
FPasswordChar: Char;
FReadOnly : Boolean;
FOnChange : TNotifyEvent;
FSelLength : integer;
FSelStart : integer;
FReadOnly: Boolean;
FOnChange: TNotifyEvent;
FSelLength: integer;
FSelStart: integer;
function GetModified : Boolean;
procedure SetCharCase(Value : TEditCharCase);
procedure SetMaxLength(Value : Integer);
@ -481,8 +481,6 @@ type
procedure SetSelStart(Val : integer); virtual;
procedure SetSelText(const Val : string); virtual;
procedure SetText(const Value: TCaption); override;
property OnChange : TNotifyEvent read FOnChange write FOnChange;
public
constructor Create(AOwner: TComponent); override;
procedure SelectAll;
@ -490,16 +488,17 @@ type
procedure CopyToClipboard; virtual;
procedure CutToClipboard; virtual;
procedure PasteFromClipboard; virtual;
property CharCase : TEditCharCase read FCharCase write SetCharCase default ecNormal;
property EchoMode : TEchoMode read FEchoMode write SetEchoMode default emNormal;
property MaxLength : Integer read FMaxLength write SetMaxLength default -1;
property ReadOnly : Boolean read FReadOnly write SetReadOnly default false;
property CharCase: TEditCharCase read FCharCase write SetCharCase default ecNormal;
property EchoMode: TEchoMode read FEchoMode write SetEchoMode default emNormal;
property MaxLength: Integer read FMaxLength write SetMaxLength default -1;
property ReadOnly: Boolean read FReadOnly write SetReadOnly default false;
property SelLength: integer read GetSelLength write SetSelLength;
property SelStart: integer read GetSelStart write SetSelStart;
property SelText: String read GetSelText write SetSelText;
property Modified : Boolean read GetModified write SetModified;
property Modified: Boolean read GetModified write SetModified;
property PasswordChar: Char read FPasswordChar write SetPasswordChar default #0;
property Text;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
property PopupMenu;
property TabStop default true;
@ -568,6 +567,7 @@ type
property Align;
property Anchors;
property AutoSize;
property Constraints;
property CharCase;
property DragMode;
property EchoMode;
@ -591,6 +591,8 @@ type
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabStop;
property TabOrder;
property Text;
property Visible;
end;
@ -1476,6 +1478,9 @@ end.
{ =============================================================================
$Log$
Revision 1.121 2004/02/04 00:04:37 mattias
added some TEdit ideas to TSpinEdit
Revision 1.120 2004/02/02 12:44:45 mattias
implemented interface constraints