diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-02-12 07:49:20 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-02-12 07:49:20 +0000 |
commit | 7f2beb3c8d52fc037460b597c76dfdcc5556ae6d (patch) | |
tree | d644874a0091494dbf84cb8d07f7b7cd984a6cf1 | |
parent | 0035b9a6a68cc232604963cf086aade2861353c3 (diff) | |
download | fpGUI-7f2beb3c8d52fc037460b597c76dfdcc5556ae6d.tar.xz |
* Applied patch #1890188 from Jean-Marc regarding gui_editcombo.pas
* Removed gui_editcombo.pas from fpgui_package because I'm getting ready for a new release and only want to include stable units. It will get added again after the release.
-rw-r--r-- | src/gui/fpgui_package.lpk | 14 | ||||
-rw-r--r-- | src/gui/fpgui_package.pas | 3 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 15 | ||||
-rw-r--r-- | src/gui/gui_editcombo.pas | 119 | ||||
-rw-r--r-- | src/gui/gui_listbox.pas | 15 |
5 files changed, 118 insertions, 48 deletions
diff --git a/src/gui/fpgui_package.lpk b/src/gui/fpgui_package.lpk index 16be4e12..54ded6b2 100644 --- a/src/gui/fpgui_package.lpk +++ b/src/gui/fpgui_package.lpk @@ -31,7 +31,7 @@ <License Value="Modified LGPL "/> <Version Minor="5" Release="1"/> - <Files Count="29"> + <Files Count="28"> <Item1> <Filename Value="gui_button.pas"/> <UnitName Value="gui_button"/> @@ -144,20 +144,16 @@ <Filename Value="gui_gauge.pas"/> <UnitName Value="gui_gauge"/> </Item28> - <Item29> - <Filename Value="gui_editcombo.pas"/> - <UnitName Value="gui_editcombo"/> - </Item29> </Files> <LazDoc Paths="../../docs/xml/gui/"/> <RequiredPkgs Count="2"> <Item1> - <PackageName Value="FCL"/> - <MinVersion Major="1" Valid="True"/> - </Item1> - <Item2> <PackageName Value="fpgfx_package"/> <MinVersion Minor="5" Valid="True"/> + </Item1> + <Item2> + <PackageName Value="FCL"/> + <MinVersion Major="1" Valid="True"/> </Item2> </RequiredPkgs> <UsageOptions> diff --git a/src/gui/fpgui_package.pas b/src/gui/fpgui_package.pas index 964bea47..ad9e692a 100644 --- a/src/gui/fpgui_package.pas +++ b/src/gui/fpgui_package.pas @@ -11,8 +11,7 @@ uses gui_listbox, gui_memo, gui_scrollbar, gui_bevel, gui_checkbox, gui_radiobutton, gui_trackbar, gui_tab, gui_basegrid, gui_listview, gui_customgrid, gui_progressbar, gui_menu, gui_style, gui_grid, gui_tree, - gui_iniutils, gui_mru, fpgui_db, gui_popupcalendar, gui_gauge, - gui_editcombo; + gui_iniutils, gui_mru, fpgui_db, gui_popupcalendar, gui_gauge; implementation diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index 1811c8f5..8f6358c5 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -157,8 +157,10 @@ begin Result.Left := x; Result.Top := y; Result.Width := w; - if h > 0 then - Result.Height := h; + if h < TfpgEdit(Result).FFont.Height + 6 then + Result.Height:= TfpgEdit(Result).FFont.Height + 6 + else + Result.Height:= h; end; @@ -322,10 +324,9 @@ var s: TfpgChar; prevval: string; begin - prevval := Text; - s := AText; - consumed := False; - + prevval := Text; + s := AText; + consumed := False; // Handle only printable characters // Note: This is now UTF-8 compliant! if (Ord(AText[1]) > 31) and (Ord(AText[1]) < 127) or (Length(AText) > 1) then @@ -690,6 +691,8 @@ procedure TfpgCustomEdit.SetFontDesc(const AValue: string); begin FFont.Free; FFont := fpgGetFont(AValue); + if Height < FFont.Height + 6 then + Height:= FFont.Height + 6; RePaint; end; diff --git a/src/gui/gui_editcombo.pas b/src/gui/gui_editcombo.pas index f03ac42e..1d08fe6b 100644 --- a/src/gui/gui_editcombo.pas +++ b/src/gui/gui_editcombo.pas @@ -61,10 +61,13 @@ uses gfx_popupwindow; type + TAllowNew = (anNo,anYes,anAsk); TfpgAbstractEditCombo = class(TfpgWidget) private FAutoCompletion: Boolean; + FAutoDropDown: Boolean; + FAllowNew: TAllowNew; FDropDownCount: integer; FBackgroundColor: TfpgColor; FTextColor: TfpgColor; @@ -76,7 +79,9 @@ type FInternalBtnRect: TfpgRect; FItems: TStringList; FOnChange: TNotifyEvent; + FNewItem: boolean; function GetFontDesc: string; + procedure SetAllowNew(const AValue: TAllowNew); procedure SetBackgroundColor(const AValue: TfpgColor); procedure SetTextColor(const AValue: TfpgColor); procedure SetDropDownCount(const AValue: integer); @@ -112,6 +117,8 @@ type // property is 1-based property FocusItem: integer read FFocusItem write SetFocusItem; property AutoCompletion: Boolean read FAutocompletion write FAutoCompletion default False; + property AutoDropDown: Boolean read FAutoDropDown write FAutoDropDown default False; + property AllowNew: TAllowNew read FAllowNew write SetAllowNew default anNo; property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor default clBoxColor; property TextColor: TfpgColor read FTextColor write SetTextColor default clText1; property FontDesc: string read GetFontDesc write SetFontDesc; @@ -122,12 +129,15 @@ type destructor Destroy; override; procedure Update; property Font: TfpgFont read FFont; + property NewText: boolean read FNewItem; end; TfpgEditCombo = class(TfpgAbstractEditCombo) published property AutoCompletion; + property AutoDropDown; + property AllowNew; property BackgroundColor; property DropDownCount; property FocusItem; @@ -259,6 +269,12 @@ begin FDropDownCount := AValue; end; +procedure TfpgAbstractEditCombo.SetAllowNew(const AValue: TAllowNew); +begin + if FAllowNew <> AValue then + FAllowNew:= AValue; +end; + procedure TfpgAbstractEditCombo.SetBackgroundColor(const AValue: TfpgColor); begin if FBackgroundColor <> AValue then @@ -293,22 +309,43 @@ begin FText := FItems.Strings[FocusItem-1]; FSelectedItem:= FocusItem-1; end - else if FText <> '' then - begin - for i := 0 to FItems.Count - 1 do - begin - if SameText(UTF8Copy(FItems.Strings[i], 1, UTF8Length(FText)), FText) then + else + if FText <> '' then + if FSelectedItem < -1 then + begin + if Assigned(FDropDown) then + FDropDown.Close; + inc(FSelectedItem); // with FSelectedItem set to -2 for delet key and -4 for return key + end + else begin - FSelectedItem := i; - if FDropDown= nil then - DoDropDown; - TDropDownWindow(FDropDown).ListBox.SetFirstItem(FSelectedItem+1); - TDropDownWindow(FDropDown).ListBox.Invalidate; - Break; + FSelectedItem := -1; + if Assigned(FDropDown) then + FDropDown.Close; + for i := 0 to FItems.Count - 1 do + begin + if SameText(UTF8Copy(FItems.Strings[i], 1, UTF8Length(FText)), FText) then + begin + FSelectedItem := i; + if AutoDropDown then + DoDropDown; + Break; + end; + end; + case FAllowNew of + anNo: + if FSelectedItem= -1 then + begin + UTF8Delete(FText, FCursorPos, 1); + Dec(FCursorPos); + end; + anAsk,anYes: + if FSelectedItem= -1 then + begin + FNewItem:= True; + end; + end; end; - FSelectedItem := -1; - end; - end; FCursorPos := UTF8Length(FText); FSelStart := FCursorPos; Result := FText; @@ -328,7 +365,7 @@ end; procedure TfpgAbstractEditCombo.DoDropDown; var ddw: TDropDownWindow; - rowcount: integer; + rowcount, i: integer; begin if (not Assigned(FDropDown)) or (not FDropDown.HasHandle) then begin @@ -337,18 +374,28 @@ begin FDropDown := TDropDownWindow.Create(nil); ddw := TDropDownWindow(FDropDown); ddw.Width := Width; + ddw.CallerWidget := self; + ddw.ListBox.OnSelect := @InternalListBoxSelect; + + // Assign combobox text items to internal listbox + if FAutoCompletion then + begin + for i := 0 to FItems.Count - 1 do + if SameText(UTF8Copy(FItems.Strings[i], 1, UTF8Length(FText)), FText) then + ddw.ListBox.Items.Add(FItems.Strings[i]); + end + else + ddw.ListBox.Items.Assign(FItems); + // adjust the height of the dropdown - rowcount := FItems.Count; + rowcount := ddw.ListBox.Items.Count; if rowcount > FDropDownCount then rowcount := FDropDownCount; if rowcount < 1 then rowcount := 1; ddw.Height := (ddw.ListBox.RowHeight * rowcount) + 4; - ddw.CallerWidget := self; - ddw.ListBox.OnSelect := @InternalListBoxSelect; - - // Assign combobox text items to internal listbox and set default focusitem - ddw.ListBox.Items.Assign(FItems); + + // set default focusitem ddw.ListBox.FocusItem := FFocusItem; ddw.DontCloseWidget := self; // now we can control when the popup window closes @@ -419,7 +466,7 @@ begin begin if SameText(UTF8Copy(FItems.Strings[i],1,UTF8Length(AVAlue)), AValue) then begin - SetFocusItem(i+1); // our FocusItem is 1-based. TStringList is 0-based. + SetFocusItem(i+1); // our FocusItem is 1-based. TStringList is 0-based. Break; end; end; @@ -460,16 +507,16 @@ var prevval: string; begin prevval := FText; - s := AText; + s := UTF8Encode(AText); consumed := False; // Handle only printable characters // Note: This is not UTF-8 compliant! - if (Ord(AText[1]) > 31) and (Ord(AText[1]) < 127) then + if (Ord(AText[1]) > 31) and (Ord(AText[1]) < 256) and (Ord(AText[1]) <> 127) or (Length(AText) > 1) then begin if (FMaxLength <= 0) or (UTF8Length(FText) < FMaxLength) then begin - UTF8Insert(s, FText, FCursorPos + 1); + UTF8Insert(s, FText, FCursorPos + UTF8Length(s)); Inc(FCursorPos); FSelStart := FCursorPos; end; @@ -512,14 +559,19 @@ begin begin if HasText then FocusItem:= 0; - FSelectedItem:= -1; + FSelectedItem:= -2; // detects delete has been pressed hasChanged := True; end; keyReturn: begin if FSelectedItem > -1 then - FText:= Items[FSelectedItem]; + SetText(Items[FSelectedItem]) + else + SetText(''); + FSelectedItem:= -4; // detects return has been pressed (must be 4 due to number of repaints) + if FNewItem and (FAllowNew = anYes) then + FItems.Add(FText); end; else @@ -580,6 +632,7 @@ procedure TfpgAbstractEditCombo.HandlePaint; var r: TfpgRect; tw, tw2, st, len: integer; + Texte: string; // paint selection rectangle procedure DrawSelection; @@ -667,8 +720,10 @@ begin fpgStyle.DrawString(Canvas, FMargin+1, FMargin, Text, Enabled); end else - if Text<> '' then - if FSelectedItem> -1 then + begin + Texte:= Text; + if Texte <> '' then + if FSelectedItem > -1 then begin FSelOffset:= FFont.TextWidth(UTF8Copy(Items[FSelectedItem], UTF8Length(FText) + 1, UTF8Length(Items[FSelectedItem]) - UTF8Length(FText))); @@ -680,6 +735,7 @@ begin FSelOffset:= 0; fpgStyle.DrawString(Canvas, FMargin+1, FMargin, FText, Enabled); end; + end; if Focused then begin @@ -743,14 +799,15 @@ begin FMargin := 3; FFocusable := True; FBtnPressed := False; - FAutocompletion := False; + FAutocompletion := False; FText := ''; FCursorPos := UTF8Length(FText); FSelStart := FCursorPos; FSelOffset := 0; FDrawOffset := 0; - FSelectedItem := 0; + FSelectedItem := -1; // to allow typing if list is empty + FNewItem := False; FItems := TStringList.Create; CalculateInternalButtonRect; diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas index fb84a5e0..c4c21277 100644 --- a/src/gui/gui_listbox.pas +++ b/src/gui/gui_listbox.pas @@ -52,6 +52,7 @@ type FPopupFrame: boolean; FTextColor: TfpgColor; FBackgroundColor: TfpgColor; // This should move to TfpgWidget + FAutoHeight: boolean; function GetFontDesc: string; procedure SetFocusItem(const AValue: integer); procedure SetFontDesc(const AValue: string); @@ -59,6 +60,7 @@ type procedure SetTextColor(const AValue: TfpgColor); procedure SetBackgroundColor(const AValue: TfpgColor); procedure UpdateScrollbarCoords; + procedure SetAutoHeight(const AValue: boolean); protected FFont: TfpgFont; FScrollBar: TfpgScrollBar; @@ -82,6 +84,7 @@ type procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; procedure HandleShow; override; procedure HandlePaint; override; + property AutoHeight: boolean read FAutoHeight write SetAutoHeight default False; property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor default clBoxColor; property FocusItem: integer read FFocusItem write SetFocusItem; property FontDesc: string read GetFontDesc write SetFontDesc; @@ -120,6 +123,7 @@ type // The standard strings listbox we will actually use in a GUI. TfpgListBox = class(TfpgTextListBox) published + property AutoHeight; property BackgroundColor; property FocusItem; property FontDesc; @@ -216,6 +220,8 @@ procedure TfpgBaseListBox.SetFontDesc(const AValue: string); begin FFont.Free; FFont := fpgGetFont(AValue); + if FAutoHeight then + Height:= ((Height - 6) div RowHeight) * RowHeight + 6; RePaint; end; @@ -262,6 +268,14 @@ begin FScrollBar.UpdateWindowPosition; end; +procedure TfpgBaseListBox.SetAutoHeight(const AValue: boolean); +begin + if FAutoHeight= AValue then + Exit; //==> + FAutoHeight := AValue; + Height := (PageLength * RowHeight) + (2 * FMargin); +end; + procedure TfpgBaseListBox.SetFirstItem(item: integer); begin FFirstItem := item; @@ -636,6 +650,7 @@ begin FMouseDragging := False; FPopupFrame := False; FHotTrack := False; + FAutoHeight := False; FOnChange := nil; FOnSelect := nil; |