summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-07 10:37:35 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-07 10:37:35 +0000
commitf3de63bb01c8446e64b65ba650a5ed3cac25f0b3 (patch)
treed5c805a9af3c8a1df034b70f01dc406bc17108b1 /src/corelib
parent10cbd626ab5a9b32941e96f99b2909782864e25d (diff)
downloadfpGUI-f3de63bb01c8446e64b65ba650a5ed3cac25f0b3.tar.xz
* Fixed svn properties on some files.
* Implemented MaxWidth and MaxHeight properties. * Implemented contraint checks on window/widget sizes. * Fixed the bug with anchor issues inside container widgets. * Fixed the initial state of PrevWidth/Height/Top/Left and Dirty state.
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/gfx_widget.pas26
-rw-r--r--src/corelib/gfxbase.pas66
2 files changed, 73 insertions, 19 deletions
diff --git a/src/corelib/gfx_widget.pas b/src/corelib/gfx_widget.pas
index 7c46c6d1..a477c4c5 100644
--- a/src/corelib/gfx_widget.pas
+++ b/src/corelib/gfx_widget.pas
@@ -90,7 +90,7 @@ type
procedure HandleMouseExit; virtual;
procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); virtual;
function FindFocusWidget(startwg: TfpgWidget; direction: TFocusSearchDirection): TfpgWidget;
- procedure HandleAlignments(dwidth, dheight: TfpgCoord); virtual;
+ procedure HandleAlignments(const dwidth, dheight: TfpgCoord); virtual;
procedure HandleShow; virtual;
procedure InternalHandleShow; virtual;
procedure HandleHide; virtual;
@@ -117,7 +117,7 @@ type
procedure Realign;
procedure SetFocus;
procedure KillFocus;
- procedure MoveAndResizeBy(dx, dy, dw, dh: TfpgCoord);
+ procedure MoveAndResizeBy(const dx, dy, dw, dh: TfpgCoord);
procedure SetPosition(aleft, atop, awidth, aheight: TfpgCoord); virtual;
procedure Invalidate; // double check this works as developers expect????
property FormDesigner: TObject read FFormDesigner write FFormDesigner;
@@ -218,12 +218,20 @@ begin
dh := FHeight - FPrevHeight;
if IsContainer and FDirty then
+ begin
+// writeln('DoUpdateWindowPosition ', Classname, ' - w:', dw, ' h:', dh);
HandleAlignments(dw, dh);
+ end;
inherited DoUpdateWindowPosition(aleft, atop, awidth, aheight);
if FDirty and ((dw <> 0) or (dh <> 0)) then
DoResize;
- FDirty := False;
+
+ // We have now handled the difference between old and new values, so reset
+ // them here not to affect the next iteration.
+ FPrevWidth := FWidth;
+ FPrevHeight := FHeight;
+ FDirty := False;
end;
procedure TfpgWidget.SetBackgroundColor(const AValue: TfpgColor);
@@ -911,7 +919,6 @@ var
dw: integer;
dh: integer;
begin
-// writeln('MsgResize - ', Classname);
dw := msg.Params.rect.Width - FWidth;
dh := msg.Params.rect.Height - FHeight;
HandleResize(msg.Params.rect.Width, msg.Params.rect.Height);
@@ -925,7 +932,7 @@ end;
procedure TfpgWidget.MsgMove(var msg: TfpgMessageRec);
begin
- HandleMove(msg.Params.rect.left, msg.Params.rect.top);
+ HandleMove(msg.Params.rect.Left, msg.Params.rect.Top);
if FFormDesigner <> nil then
begin
FFormDesigner.Dispatch(msg);
@@ -935,8 +942,8 @@ end;
procedure TfpgWidget.HandleResize(AWidth, AHeight: TfpgCoord);
begin
// writeln('HandleResize - ', Classname);
- Width := Max(awidth, FMinWidth);
- Height := Max(aheight, FMinHeight);
+ Width := Max(AWidth, FMinWidth);
+ Height := Max(AHeight, FMinHeight);
end;
procedure TfpgWidget.HandleMove(x, y: TfpgCoord);
@@ -945,7 +952,7 @@ begin
Top := y;
end;
-procedure TfpgWidget.HandleAlignments(dwidth, dheight: TfpgCoord);
+procedure TfpgWidget.HandleAlignments(const dwidth, dheight: TfpgCoord);
var
n: integer;
wg: TfpgWidget;
@@ -996,6 +1003,7 @@ end;
procedure TfpgWidget.MoveAndResize(ALeft, ATop, AWidth, AHeight: TfpgCoord);
begin
+// writeln('MoveAndResize: ', Classname, ' t:', ATop, ' l:', ALeft, ' w:', AWidth, ' h:', aHeight);
if HasHandle then
begin
if (ALeft <> FLeft) or (ATop <> FTop) then
@@ -1014,7 +1022,7 @@ begin
end;
end;
-procedure TfpgWidget.MoveAndResizeBy(dx, dy, dw, dh: TfpgCoord);
+procedure TfpgWidget.MoveAndResizeBy(const dx, dy, dw, dh: TfpgCoord);
begin
if (dx <> 0) or (dy <> 0) or
(dw <> 0) or (dh <> 0) then
diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas
index b249d486..67548997 100644
--- a/src/corelib/gfxbase.pas
+++ b/src/corelib/gfxbase.pas
@@ -350,6 +350,8 @@ type
private
FParent: TfpgWindowBase;
procedure SetMouseCursor(const AValue: TMouseCursor);
+ function ConstraintWidth(NewWidth: TfpgCoord): TfpgCoord;
+ function ConstraintHeight(NewHeight: TfpgCoord): TfpgCoord;
protected
FMouseCursor: TMouseCursor;
FWindowType: TWindowType;
@@ -364,6 +366,8 @@ type
FPrevHeight: TfpgCoord;
FMinWidth: TfpgCoord;
FMinHeight: TfpgCoord;
+ FMaxHeight: TfpgCoord;
+ FMaxWidth: TfpgCoord;
FCanvas: TfpgCanvasBase;
FDirty: Boolean;
function HandleIsValid: boolean; virtual; abstract;
@@ -413,6 +417,8 @@ type
property Height: TfpgCoord read FHeight write SetHeight;
property MinWidth: TfpgCoord read FMinWidth write FMinWidth;
property MinHeight: TfpgCoord read FMinHeight write FMinHeight;
+ property MaxWidth: TfpgCoord read FMaxWidth write FMaxWidth;
+ property MaxHeight: TfpgCoord read FMaxHeight write FMaxHeight;
property Canvas: TfpgCanvasBase read GetCanvas;
property Parent: TfpgWindowBase read GetParent write SetParent;
property MouseCursor: TMouseCursor read FMouseCursor write SetMouseCursor;
@@ -919,6 +925,24 @@ begin
DoSetMouseCursor;
end;
+function TfpgWindowBase.ConstraintWidth(NewWidth: TfpgCoord): TfpgCoord;
+begin
+ Result := NewWidth;
+ if (MaxWidth >= MinWidth) and (Result > MaxWidth) and (MaxWidth > 0) then
+ Result := MaxWidth;
+ if Result < MinWidth then
+ Result := MinWidth;
+end;
+
+function TfpgWindowBase.ConstraintHeight(NewHeight: TfpgCoord): TfpgCoord;
+begin
+ Result := NewHeight;
+ if (MaxHeight >= MinHeight) and (Result > MaxHeight) and (MaxHeight > 0) then
+ Result := MaxHeight;
+ if Result < MinHeight then
+ Result := MinHeight;
+end;
+
procedure TfpgWindowBase.SetParent(const AValue: TfpgWindowBase);
begin
FParent := AValue;
@@ -958,36 +982,56 @@ procedure TfpgWindowBase.SetTop(const AValue: TfpgCoord);
begin
if FTop = AValue then
Exit;
- FPrevTop := FTop;
+ // if we don't have a handle we are still setting up, so actual value and
+ // previous value must be the same.
+ if HasHandle then
+ FPrevTop := FTop
+ else
+ FPrevTop := AValue;
FTop := AValue;
- FDirty := True;
+ FDirty := FTop <> FPrevTop;
end;
procedure TfpgWindowBase.SetLeft(const AValue: TfpgCoord);
begin
if FLeft = AValue then
Exit;
- FPrevLeft := FHeight;
+ // if we don't have a handle we are still setting up, so actual value and
+ // previous value must be the same.
+ if HasHandle then
+ FPrevLeft := FHeight
+ else
+ FPrevLeft := AValue;
FLeft := AValue;
- FDirty := True;
+ FDirty := FLeft <> FPrevLeft;
end;
procedure TfpgWindowBase.SetHeight(const AValue: TfpgCoord);
begin
if FHeight = AValue then
Exit;
- FPrevHeight := FHeight;
- FHeight := AValue;
- FDirty := True;
+ // if we don't have a handle we are still setting up, so actual value and
+ // previous value must be the same.
+ if HasHandle then
+ FPrevHeight := FHeight
+ else
+ FPrevHeight := AValue;
+ FHeight := ConstraintHeight(AValue);
+ FDirty := FHeight <> FPrevHeight;
end;
procedure TfpgWindowBase.SetWidth(const AValue: TfpgCoord);
begin
if FWidth = AValue then
Exit;
- FPrevWidth := FWidth;
- FWidth := AValue;
- FDirty := True;
+ // if we don't have a handle we are still setting up, so actual value and
+ // previous value must be the same.
+ if HasHandle then
+ FPrevWidth := FWidth
+ else
+ FPrevWidth := AValue;
+ FWidth := ConstraintWidth(AValue);
+ FDirty := FWidth <> FPrevWidth;
end;
constructor TfpgWindowBase.Create(AOwner: TComponent);
@@ -995,6 +1039,8 @@ begin
inherited Create(AOwner);
FMouseCursor := mcDefault;
FDirty := True;
+ FMaxWidth := 0;
+ FMaxHeight := 0;
end;
procedure TfpgWindowBase.AfterConstruction;