diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-24 14:36:43 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-24 14:36:43 +0000 |
commit | a2a390ed6d9f31e144d725dcab5b0fe014a95402 (patch) | |
tree | 1245fecac3a2fde7b518c710176f41187bd82967 /src/gui | |
parent | 91e7bc73a36017ccc7a8d94727b2f6f51c0c83f6 (diff) | |
download | fpGUI-a2a390ed6d9f31e144d725dcab5b0fe014a95402.tar.xz |
* Implement MaxLength in TfpgEdit
* Published some missing properties in TfpgTrackBar.
* TfpgEdit now correctl fires off the OnChange event.
* A new Text property has been implemented in TfpgComboBox.
* Minor fixes to the generic Edit mediators used for tiOPF.
* Added a Edit Mediator demo which tests the implementation. It works!
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui_combobox.pas | 42 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 72 | ||||
-rw-r--r-- | src/gui/gui_trackbar.pas | 1 |
3 files changed, 83 insertions, 32 deletions
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas index 38594794..bcf3de8a 100644 --- a/src/gui/gui_combobox.pas +++ b/src/gui/gui_combobox.pas @@ -28,6 +28,7 @@ type FItems: TStringList; FOnChange: TNotifyEvent; function GetFontDesc: string; + function GetText: string; procedure SetBackgroundColor(const AValue: TfpgColor); procedure SetDropDownCount(const AValue: integer); procedure DoDropDown; @@ -35,6 +36,7 @@ type procedure InternalListBoxSelect(Sender: TObject); procedure SetFocusItem(const AValue: integer); procedure SetFontDesc(const AValue: string); + procedure SetText(const AValue: string); protected FMargin: integer; procedure SetEnabled(const AValue: boolean); override; @@ -46,10 +48,10 @@ type property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor; property FontDesc: string read GetFontDesc write SetFontDesc; property OnChange: TNotifyEvent read FOnChange write FOnChange; + property Text: string read GetText write SetText; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - function Text: string; procedure AfterConstruction; override; property Font: TfpgFont read FFont; end; @@ -62,6 +64,7 @@ type property FocusItem; property FontDesc; property Items; + property Text; property OnChange; end; @@ -192,6 +195,14 @@ begin Result := FFont.FontDesc; end; +function TfpgCustomComboBox.GetText: string; +begin + if (FocusItem > 0) and (FocusItem <= FItems.Count) then + Result := FItems.Strings[FocusItem-1] + else + Result := ''; +end; + procedure TfpgCustomComboBox.DoDropDown; var ddw: TDropDownWindow; @@ -267,6 +278,27 @@ begin RePaint; end; +procedure TfpgCustomComboBox.SetText(const AValue: string); +var + i: integer; +begin + if AValue = '' then + SetFocusItem(0) // nothing selected + else + begin + for i := 0 to FItems.Count - 1 do + begin + if SameText(FItems.Strings[i], AValue) then + begin + SetFocusItem(i+1); + Break; + end; + end; + // if we get here, we didn't find a match + SetFocusItem(0); + end; +end; + procedure TfpgCustomComboBox.SetEnabled(const AValue: boolean); begin inherited SetEnabled(AValue); @@ -328,14 +360,6 @@ begin Canvas.EndDraw; end; -function TfpgCustomComboBox.Text: string; -begin - if (FocusItem > 0) and (FocusItem <= FItems.Count) then - Result := FItems.Strings[FocusItem-1] - else - Result := ''; -end; - constructor TfpgCustomComboBox.Create(AOwner: TComponent); begin inherited Create(AOwner); diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index adec0a54..c67edaca 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -54,6 +54,7 @@ type property Text: string read FText write SetText; property FontDesc: string read GetFontDesc write SetFontDesc; property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor; + property MaxLength: integer read FMaxLength write FMaxLength; end; function CreateEdit(AOwner: TComponent; x, y, w, h: TfpgCoord): TfpgEdit; @@ -83,18 +84,18 @@ begin FFont := fpgGetFont('#Edit1'); // owned object ! - FHeight := FFont.Height + 6; - FWidth := 120; + FHeight := FFont.Height + 6; + FWidth := 120; FBackgroundColor := clBoxColor; - FSelecting := False; - FSideMargin := 3; - FMaxLength := 0; - FText := ''; - FCursorPos := UTF8Length(FText); - FSelStart := FCursorPos; - FSelOffset := 0; - FDrawOffset := 0; - PasswordMode := False; + FSelecting := False; + FSideMargin := 3; + FMaxLength := 0; // no limit + FText := ''; + FCursorPos := UTF8Length(FText); + FSelStart := FCursorPos; + FSelOffset := 0; + FDrawOffset := 0; + PasswordMode := False; OnChange := nil; end; @@ -106,19 +107,30 @@ begin end; procedure TfpgEdit.SetText(const AValue: string); +var + s: string; begin if FText = AValue then Exit; + + if FMaxLength <> 0 then + begin + if UTF8Length(FText) > FMaxLength then + s := UTF8Copy(AValue, 1, FMaxLength) + else + s := AValue; + end + else + s := AValue; - FText := AValue; + FText := s; FCursorPos := UTF8Length(FText); FSelStart := FCursorPos; FSelOffset := 0; FDrawOffset := 0; AdjustCursor; - if FWinHandle > 0 then - RePaint; + RePaint; end; function TfpgEdit.GetFontDesc: string; @@ -307,6 +319,7 @@ procedure TfpgEdit.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var lpos: integer; + hasChanged: boolean; procedure StopSelection; begin @@ -318,6 +331,7 @@ begin // writeln(Classname, '.Keypress'); Consumed := False; lpos := FCursorPos; + hasChanged := False; Consumed := True; case CheckClipBoardKey(keycode, shiftstate) of @@ -330,12 +344,14 @@ begin begin // writeln('ckPaste'); DoPaste; + hasChanged := True; end; ckCut: begin // writeln('ckCut'); DoCopy; DeleteSelection; + hasChanged := True; end; else Consumed := False; @@ -408,18 +424,24 @@ begin case keycode of keyBackSpace: - if FCursorPos > 0 then - begin - Delete(FText, FCursorPos, 1); - Dec(FCursorPos); - end;// backspace + begin + if FCursorPos > 0 then + begin + Delete(FText, FCursorPos, 1); + Dec(FCursorPos); + hasChanged := True; + end;// backspace + end; keyDelete: - if FSelOffset <> 0 then - DeleteSelection - else if FCursorPos < UTF8Length(FText) then - Delete(FText, FCursorPos + 1, 1); + begin + if FSelOffset <> 0 then + DeleteSelection + else if FCursorPos < UTF8Length(FText) then + Delete(FText, FCursorPos + 1, 1); + hasChanged := True; + end; else Consumed := False; end; @@ -435,6 +457,10 @@ begin RePaint else inherited; + + if hasChanged then + if Assigned(OnChange) then + OnChange(self); end; procedure TfpgEdit.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); diff --git a/src/gui/gui_trackbar.pas b/src/gui/gui_trackbar.pas index cc5345bc..1ff04486 100644 --- a/src/gui/gui_trackbar.pas +++ b/src/gui/gui_trackbar.pas @@ -99,6 +99,7 @@ type public constructor Create(AOwner: TComponent); override; destructor Destroy; override; + published property Position: integer read FPosition write SetPosition default 10; property ScrollStep: integer read FScrollStep write FScrollStep default 1; property Min: integer read FMin write SetMin default 0; |