summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-11-12 15:39:55 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-11-12 15:39:55 +0200
commit9006eadb7ebc2ea187af025b2355deb7c4fa4cfa (patch)
tree8dd197d792675f52400b0a4bc9512b2fc71b298b /src/gui
parentd982b1f93c1af52552cc8d1e6e1665d3770d8f07 (diff)
downloadfpGUI-9006eadb7ebc2ea187af025b2355deb7c4fa4cfa.tar.xz
ComboBox widget now has a AutoSize property default set to False
* ComboBox was always auto sized which is not always desired. We now have a property to control that behaviour. * Default is False, in preperation for layout managers which control the size. * Widget frame borders are now retrieved from the current Style instance. * default Height is set to 24px. The same default used for TfpgEdit widget. Default sizes have been moved up into TfpgBaseComboBox, out of TfpgBaseStaticCombo.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/fpg_combobox.pas41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/gui/fpg_combobox.pas b/src/gui/fpg_combobox.pas
index 5afbf326..b27d3fc2 100644
--- a/src/gui/fpg_combobox.pas
+++ b/src/gui/fpg_combobox.pas
@@ -76,12 +76,14 @@ type
procedure SetFontDesc(const AValue: string);
procedure SetExtraHint(const AValue: string);
protected
+ FAutoSize: Boolean;
FMargin: integer;
FInternalBtnRect: TfpgRect;
FFocusItem: integer;
FItems: TStringList;
FBtnPressed: Boolean;
- procedure SetMargin(const AValue: integer);
+ procedure SetMargin(const AValue: integer); virtual;
+ procedure SetAutoSize(const AValue: Boolean); virtual;
procedure CalculateInternalButtonRect; virtual;
procedure InternalOnClose(Sender: TObject); virtual;
procedure InternalItemsChanged(Sender: TObject); virtual;
@@ -92,6 +94,7 @@ type
procedure DoOnCloseUp; virtual;
procedure PaintInternalButton; virtual;
function GetDropDownPos(AParent, AComboBox, ADropDown: TfpgWidget): TfpgRect; virtual;
+ property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
property DropDownCount: integer read FDropDownCount write SetDropDownCount default 8;
property ExtraHint: string read FExtraHint write SetExtraHint;
property FocusItem: integer read FFocusItem write SetFocusItem;
@@ -137,6 +140,7 @@ type
published
property AcceptDrops;
property Align;
+ property AutoSize;
property BackgroundColor default clBoxColor;
property DropDownCount;
property Enabled;
@@ -233,8 +237,10 @@ procedure TfpgBaseComboBox.SetFontDesc(const AValue: string);
begin
FFont.Free;
FFont := fpgGetFont(AValue);
- if Height < FFont.Height + (FMargin * 2) then
+ if FAutoSize then
+ begin
Height := FFont.Height + (FMargin * 2);
+ end;
RePaint;
end;
@@ -254,6 +260,22 @@ begin
Height := FFont.Height + (FMargin * 2);
end;
+procedure TfpgBaseComboBox.SetAutoSize(const AValue: Boolean);
+var
+ r: TRect;
+begin
+ if FAutoSize = AValue then
+ exit;
+ FAutoSize := AValue;
+ if FAutoSize then
+ begin
+ r := fpgStyle.GetControlFrameBorders;
+ FHeight := FFont.Height + (Margin*2) + (r.Top+r.Bottom);
+ CalculateInternalButtonRect;
+ UpdateWindowPosition;
+ end;
+end;
+
procedure TfpgBaseComboBox.CalculateInternalButtonRect;
begin
FInternalBtnRect.SetRect(Width - Min(Height, 20), 2, Min(Height, 20)-2, Height-4);
@@ -392,12 +414,15 @@ end;
constructor TfpgBaseComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
- FDropDownCount := 8;
- FMargin := 3;
- FFocusItem := -1; // nothing is selected
- FItems := TStringList.Create;
+ FWidth := 120;
+ FHeight := 24;
+ FAutoSize := False;
+ FDropDownCount := 8;
+ FMargin := 3;
+ FFocusItem := -1; // nothing is selected
+ FItems := TStringList.Create;
FItems.OnChange := @InternalItemsChanged;
- FFont := fpgGetFont('#List');
+ FFont := fpgGetFont('#List');
FOptions := [];
FBtnPressed := False;
FOnChange := nil;
@@ -697,8 +722,6 @@ begin
inherited Create(AOwner);
FBackgroundColor := clBoxColor;
FTextColor := Parent.TextColor;
- FWidth := 120;
- FHeight := Font.Height + (2*FMargin);
FFocusable := True;
CalculateInternalButtonRect;