summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-23 14:17:56 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-23 14:17:56 +0000
commit626b9d82f7c6351d5f8dbf1bc5011fc48387e210 (patch)
tree8d26b540787e5cada3811aa06e9734a815c65113 /src
parent8ff503a46409a7ca024e9f85b65c2baebcc5982e (diff)
downloadfpGUI-626b9d82f7c6351d5f8dbf1bc5011fc48387e210.tar.xz
* TfpgListBox now handles the Resize message. This fixes the scrollbar issue in the UI Designer and at runtime resizing.
* Implemented correct 'lazy refresh' in TfpgWidget when setting the size and position with .SetPostion() method. * Refactored the Combo components removing some code duplication. Some paint methods are now inthe BasicCombobox component.
Diffstat (limited to 'src')
-rw-r--r--src/corelib/gfx_widget.pas26
-rw-r--r--src/gui/gui_combobox.pas85
-rw-r--r--src/gui/gui_editcombo.pas43
-rw-r--r--src/gui/gui_listbox.pas10
4 files changed, 75 insertions, 89 deletions
diff --git a/src/corelib/gfx_widget.pas b/src/corelib/gfx_widget.pas
index 9b99baa9..85bf059b 100644
--- a/src/corelib/gfx_widget.pas
+++ b/src/corelib/gfx_widget.pas
@@ -90,7 +90,7 @@ type
procedure HandleShow; virtual;
procedure InternalHandleShow; virtual;
procedure HandleHide; virtual;
- procedure MoveAndResize(aleft, atop, awidth, aheight: TfpgCoord);
+ procedure MoveAndResize(ALeft, ATop, AWidth, AHeight: TfpgCoord);
procedure RePaint;
{ property events }
property OnClick: TNotifyEvent read FOnClick write FOnClick;
@@ -954,14 +954,24 @@ begin
RePaint;
end;
-procedure TfpgWidget.MoveAndResize(aleft, atop, awidth, aheight: TfpgCoord);
+procedure TfpgWidget.MoveAndResize(ALeft, ATop, AWidth, AHeight: TfpgCoord);
begin
- if (aleft <> FLeft) or (atop <> FTop) then
- HandleMove(aleft, atop);
- if (awidth <> FWidth) or (aheight <> FHeight) then
- HandleResize(awidth, aheight);
-
- UpdateWindowPosition;
+ if HasHandle then
+ begin
+ if (aleft <> FLeft) or (atop <> FTop) then
+ HandleMove(aleft, atop);
+ if (awidth <> FWidth) or (aheight <> FHeight) then
+ HandleResize(awidth, aheight);
+ UpdateWindowPosition;
+ end
+ else
+ begin
+ // When the widget is created, it's position will be applied
+ FLeft := ALeft;
+ FTop := ATop;
+ FWidth := AWidth;
+ FHeight := AHeight;
+ end;
end;
procedure TfpgWidget.MoveAndResizeBy(dx, dy, dw, dh: TfpgCoord);
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas
index 8452495c..31dc8989 100644
--- a/src/gui/gui_combobox.pas
+++ b/src/gui/gui_combobox.pas
@@ -77,6 +77,8 @@ type
FInternalBtnRect: TfpgRect;
FFocusItem: integer;
FItems: TStringList;
+ FBtnPressed: Boolean;
+ procedure CalculateInternalButtonRect; virtual;
procedure InternalOnClose(Sender: TObject);
procedure InternalItemsChanged(Sender: TObject); virtual;
procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override;
@@ -84,6 +86,7 @@ type
procedure DoOnDropDown; virtual;
procedure DoDropDown; virtual; abstract;
procedure DoOnCloseUp; virtual;
+ procedure PaintInternalButton; virtual;
function GetDropDownPos(AParent, AComboBox, ADropDown: TfpgWidget): TfpgRect; virtual;
property DropDownCount: integer read FDropDownCount write SetDropDownCount default 8;
property FocusItem: integer read FFocusItem write SetFocusItem;
@@ -96,6 +99,7 @@ type
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
+ procedure SetPosition(aleft, atop, awidth, aheight: TfpgCoord); override;
property Font: TfpgFont read FFont;
end;
@@ -103,10 +107,8 @@ type
TfpgAbstractComboBox = class(TfpgBaseComboBox)
private
procedure InternalBtnClick(Sender: TObject);
- procedure CalculateInternalButtonRect;
protected
FMargin: integer;
- FBtnPressed: Boolean;
FDropDown: TfpgPopupWindow;
procedure DoDropDown; override;
function GetText: string; virtual;
@@ -120,7 +122,6 @@ type
procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override;
procedure HandleResize(awidth, aheight: TfpgCoord); override;
procedure HandlePaint; override;
- procedure PaintInternalButton; virtual;
property Text: string read GetText write SetText;
public
constructor Create(AOwner: TComponent); override;
@@ -221,6 +222,11 @@ begin
RePaint;
end;
+procedure TfpgBaseComboBox.CalculateInternalButtonRect;
+begin
+ FInternalBtnRect.SetRect(Width - Min(Height, 20), 2, Min(Height, 20)-2, Height-4);
+end;
+
procedure TfpgBaseComboBox.InternalOnClose(Sender: TObject);
begin
DoOnCloseUp;
@@ -284,6 +290,36 @@ begin
OnCloseUp(self);
end;
+procedure TfpgBaseComboBox.PaintInternalButton;
+var
+ ar: TfpgRect;
+ btnflags: TFButtonFlags;
+begin
+ Canvas.BeginDraw;
+ btnflags := [];
+ ar := FInternalBtnRect;
+ InflateRect(ar, -2, -2);
+ if FBtnPressed then
+ begin
+ Include(btnflags, btfIsPressed);
+ OffsetRect(ar, 1, 1);
+ end;
+ // paint button face
+ fpgStyle.DrawButtonFace(Canvas,
+ FInternalBtnRect.Left,
+ FInternalBtnRect.Top,
+ FInternalBtnRect.Width,
+ FInternalBtnRect.Height, btnflags);
+ if Enabled then
+ Canvas.SetColor(clText1)
+ else
+ Canvas.SetColor(clShadow1);
+
+ // paint arrow
+ fpgStyle.DrawDirectionArrow(Canvas, ar.Left, ar.Top, ar.Width, ar.Height, 1);
+ Canvas.EndDraw(FInternalBtnRect);
+end;
+
function TfpgBaseComboBox.GetDropDownPos(AParent, AComboBox, ADropDown: TfpgWidget): TfpgRect;
var
pt: TPoint;
@@ -320,6 +356,7 @@ begin
FItems.OnChange := @InternalItemsChanged;
FFont := fpgGetFont('#List');
FOptions := [];
+ FBtnPressed := False;
FOnChange := nil;
end;
@@ -330,6 +367,11 @@ begin
inherited Destroy;
end;
+procedure TfpgBaseComboBox.SetPosition(aleft, atop, awidth, aheight: TfpgCoord);
+begin
+ inherited SetPosition(aleft, atop, awidth, aheight);
+ CalculateInternalButtonRect
+end;
{ TComboboxDropdownWindow }
@@ -515,11 +557,6 @@ begin
RePaint
end;
-procedure TfpgAbstractComboBox.CalculateInternalButtonRect;
-begin
- FInternalBtnRect.SetRect(Width - Min(Height, 20), 2, Min(Height, 20)-2, Height-4);
-end;
-
procedure TfpgAbstractComboBox.SetHeight(const AValue: TfpgCoord);
begin
inherited SetHeight(AValue);
@@ -622,37 +659,6 @@ begin
fpgStyle.DrawString(Canvas, FMargin+1, FMargin, Text, Enabled);
end;
-procedure TfpgAbstractComboBox.PaintInternalButton;
-var
- ar: TfpgRect;
- btnflags: TFButtonFlags;
-begin
- Canvas.BeginDraw;
- btnflags := [];
- ar := FInternalBtnRect;
- InflateRect(ar, -2, -2);
- if FBtnPressed then
- begin
- Include(btnflags, btfIsPressed);
- OffsetRect(ar, 1, 1);
- end;
- // paint button face
- fpgStyle.DrawButtonFace(Canvas,
- FInternalBtnRect.Left,
- FInternalBtnRect.Top,
- FInternalBtnRect.Width,
- FInternalBtnRect.Height, btnflags);
- if Enabled then
- Canvas.SetColor(clText1)
- else
- begin
- Canvas.SetColor(clShadow1);
- end;
- // paint arrow
- fpgStyle.DrawDirectionArrow(Canvas, ar.Left, ar.Top, ar.Width, ar.Height, 1);
- Canvas.EndDraw(FInternalBtnRect);
-end;
-
constructor TfpgAbstractComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
@@ -662,7 +668,6 @@ begin
FMargin := 3;
FHeight := Font.Height + (2*FMargin);
FFocusable := True;
- FBtnPressed := False;
CalculateInternalButtonRect;
end;
diff --git a/src/gui/gui_editcombo.pas b/src/gui/gui_editcombo.pas
index 154d130c..dc1f271d 100644
--- a/src/gui/gui_editcombo.pas
+++ b/src/gui/gui_editcombo.pas
@@ -76,10 +76,8 @@ type
procedure SetAllowNew(const AValue: TAllowNew);
procedure InternalBtnClick(Sender: TObject);
procedure InternalListBoxSelect(Sender: TObject);
- procedure CalculateInternalButtonRect;
protected
FMargin: integer;
- FBtnPressed: Boolean;
FDropDown: TfpgPopupWindow;
FDrawOffset: integer;
FSelStart: integer;
@@ -97,12 +95,11 @@ type
procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
procedure HandleResize(awidth, aheight: TfpgCoord); override;
procedure HandlePaint; override;
- procedure PaintInternalButton; virtual;
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 BackgroundColor default clBoxColor;
+ property TextColor default clText1;
property Text: string read GetText write SetText;
public
constructor Create(AOwner: TComponent); override;
@@ -385,12 +382,6 @@ begin
RePaint;
end;
-procedure TfpgAbstractEditCombo.CalculateInternalButtonRect;
-begin
- FInternalBtnRect.SetRect(Width - Min(Height, 20), 2, Min(Height, 20)-2,
- Height-4);
-end;
-
procedure TfpgAbstractEditCombo.SetHeight(const AValue: TfpgCoord);
begin
inherited SetHeight(AValue);
@@ -726,35 +717,6 @@ begin
Canvas.EndDraw;
end;
-procedure TfpgAbstractEditCombo.PaintInternalButton;
-var
- ar: TfpgRect;
- btnflags: TFButtonFlags;
-begin
- Canvas.BeginDraw;
- btnflags := [];
- ar := FInternalBtnRect;
- InflateRect(ar, -2, -2);
- if FBtnPressed then
- begin
- Include(btnflags, btfIsPressed);
- OffsetRect(ar, 1, 1);
- end;
- // paint button face
- fpgStyle.DrawButtonFace(Canvas,
- FInternalBtnRect.Left,
- FInternalBtnRect.Top,
- FInternalBtnRect.Width,
- FInternalBtnRect.Height, btnflags);
- if Enabled then
- Canvas.SetColor(clText1)
- else
- Canvas.SetColor(clShadow1);
- // paint arrow
- fpgStyle.DrawDirectionArrow(Canvas, ar.Left, ar.Top, ar.Width, ar.Height, 1);
- Canvas.EndDraw(FInternalBtnRect);
-end;
-
constructor TfpgAbstractEditCombo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
@@ -764,7 +726,6 @@ begin
FHeight := Font.Height + 6;
FMargin := 3;
FFocusable := True;
- FBtnPressed := False;
FAutocompletion := False;
FAutoDropDown := False;
FAllowNew := anNo;
diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas
index dd631dd7..bd493efd 100644
--- a/src/gui/gui_listbox.pas
+++ b/src/gui/gui_listbox.pas
@@ -81,6 +81,7 @@ type
procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override;
procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override;
+ procedure HandleResize(awidth, aheight: TfpgCoord); override;
procedure HandleShow; override;
procedure HandlePaint; override;
property AutoHeight: boolean read FAutoHeight write SetAutoHeight default False;
@@ -571,6 +572,15 @@ begin
end;
end;
+procedure TfpgBaseListBox.HandleResize(awidth, aheight: TfpgCoord);
+begin
+ inherited HandleResize(awidth, aheight);
+ if (csLoading in ComponentState) then
+ Exit;
+ UpdateScrollbarCoords;
+ UpdateScrollBar;
+end;
+
procedure TfpgBaseListBox.HandleShow;
begin
inherited HandleShow;