summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/gui/alignment_resize/alignment_resize.lpr3
-rw-r--r--examples/gui/splitter/splitter_test.lpi132
-rw-r--r--examples/gui/splitter/splitter_test.lpr4
-rw-r--r--src/corelib/gfx_widget.pas26
-rw-r--r--src/corelib/gfxbase.pas66
-rw-r--r--src/gui/gui_form.pas1
-rw-r--r--src/gui/gui_memo.pas2
7 files changed, 146 insertions, 88 deletions
diff --git a/examples/gui/alignment_resize/alignment_resize.lpr b/examples/gui/alignment_resize/alignment_resize.lpr
index 8c6b2b03..b78745f4 100644
--- a/examples/gui/alignment_resize/alignment_resize.lpr
+++ b/examples/gui/alignment_resize/alignment_resize.lpr
@@ -76,7 +76,7 @@ begin
SetPosition(316, 186, 467, 284);
WindowTitle := 'Runtime resize/alignment test';
WindowPosition := wpScreenCenter;
- Sizeable := False;
+// Sizeable := False;
btnName1 := TfpgButton.Create(self);
with btnName1 do
@@ -213,6 +213,7 @@ begin
SetPosition(272, 104, 184, 164);
FontDesc := '#Edit1';
TabOrder := 8;
+ Anchors := AllAnchors;
end;
{@VFD_BODY_END: MainForm}
diff --git a/examples/gui/splitter/splitter_test.lpi b/examples/gui/splitter/splitter_test.lpi
index 48d5b09b..b01ce023 100644
--- a/examples/gui/splitter/splitter_test.lpi
+++ b/examples/gui/splitter/splitter_test.lpi
@@ -1,66 +1,66 @@
-<?xml version="1.0"?>
-<CONFIG>
- <ProjectOptions>
- <PathDelim Value="\"/>
- <Version Value="5"/>
- <General>
- <Flags>
- <SaveOnlyProjectUnits Value="True"/>
- </Flags>
- <SessionStorage Value="InProjectDir"/>
- <MainUnit Value="0"/>
- <IconPath Value=".\"/>
- <TargetFileExt Value=".exe"/>
- </General>
- <VersionInfo>
- <ProjectVersion Value=""/>
- </VersionInfo>
- <PublishOptions>
- <Version Value="2"/>
- <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
- <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
- </PublishOptions>
- <RunParams>
- <local>
- <FormatVersion Value="1"/>
- <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
- </local>
- </RunParams>
- <RequiredPackages Count="1">
- <Item1>
- <PackageName Value="fpgui_toolkit"/>
- </Item1>
- </RequiredPackages>
- <Units Count="1">
- <Unit0>
- <Filename Value="splitter_test.lpr"/>
- <IsPartOfProject Value="True"/>
- <UnitName Value="splitter_test"/>
- </Unit0>
- </Units>
- </ProjectOptions>
- <CompilerOptions>
- <Version Value="5"/>
- <PathDelim Value="\"/>
- <CodeGeneration>
- <SmartLinkUnit Value="True"/>
- <Checks>
- <IOChecks Value="True"/>
- <RangeChecks Value="True"/>
- <OverflowChecks Value="True"/>
- <StackChecks Value="True"/>
- </Checks>
- <Generate Value="Faster"/>
- </CodeGeneration>
- <Linking>
- <Debugging>
- <StripSymbols Value="True"/>
- </Debugging>
- <LinkSmart Value="True"/>
- </Linking>
- <Other>
- <CustomOptions Value="-FUunits "/>
- <CompilerPath Value="$(CompPath)"/>
- </Other>
- </CompilerOptions>
-</CONFIG>
+<?xml version="1.0"?>
+<CONFIG>
+ <ProjectOptions>
+ <PathDelim Value="/"/>
+ <Version Value="6"/>
+ <General>
+ <Flags>
+ <SaveOnlyProjectUnits Value="True"/>
+ </Flags>
+ <SessionStorage Value="InProjectDir"/>
+ <MainUnit Value="0"/>
+ <IconPath Value="./"/>
+ <TargetFileExt Value=".exe"/>
+ </General>
+ <VersionInfo>
+ <ProjectVersion Value=""/>
+ </VersionInfo>
+ <PublishOptions>
+ <Version Value="2"/>
+ <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
+ <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
+ </PublishOptions>
+ <RunParams>
+ <local>
+ <FormatVersion Value="1"/>
+ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
+ </local>
+ </RunParams>
+ <RequiredPackages Count="1">
+ <Item1>
+ <PackageName Value="fpgui_toolkit"/>
+ </Item1>
+ </RequiredPackages>
+ <Units Count="1">
+ <Unit0>
+ <Filename Value="splitter_test.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="splitter_test"/>
+ </Unit0>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="5"/>
+ <CodeGeneration>
+ <SmartLinkUnit Value="True"/>
+ <Checks>
+ <IOChecks Value="True"/>
+ <RangeChecks Value="True"/>
+ <OverflowChecks Value="True"/>
+ <StackChecks Value="True"/>
+ </Checks>
+ <Generate Value="Faster"/>
+ </CodeGeneration>
+ <Linking>
+ <Debugging>
+ <StripSymbols Value="True"/>
+ </Debugging>
+ <LinkSmart Value="True"/>
+ </Linking>
+ <Other>
+ <CustomOptions Value="-FUunits
+"/>
+ <CompilerPath Value="$(CompPath)"/>
+ </Other>
+ </CompilerOptions>
+</CONFIG>
diff --git a/examples/gui/splitter/splitter_test.lpr b/examples/gui/splitter/splitter_test.lpr
index 9f8d3313..82374f7a 100644
--- a/examples/gui/splitter/splitter_test.lpr
+++ b/examples/gui/splitter/splitter_test.lpr
@@ -73,8 +73,8 @@ begin
begin
Name := 'mmSource';
SetPosition(164, 0, 257, 90);
- Lines.Add('Memo1 Line #1');
- Lines.Add('Memo1 Line #2');
+ Lines.Add('Memo has a MinHeight=30 so the splitter');
+ Lines.Add('snap effect will not take affect - as expected.');
FontDesc := '#Edit1';
TabOrder := 2;
Align := alTop;
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;
diff --git a/src/gui/gui_form.pas b/src/gui/gui_form.pas
index 1ec52a88..27877bf9 100644
--- a/src/gui/gui_form.pas
+++ b/src/gui/gui_form.pas
@@ -310,6 +310,7 @@ end;
procedure TfpgBaseForm.HandleShow;
begin
inherited HandleShow;
+ HandleAlignments(0, 0);
if Assigned(FOnShow) then
FOnShow(self);
end;
diff --git a/src/gui/gui_memo.pas b/src/gui/gui_memo.pas
index 34e4cef9..58ea1120 100644
--- a/src/gui/gui_memo.pas
+++ b/src/gui/gui_memo.pas
@@ -286,6 +286,8 @@ begin
FBackgroundColor := clBoxColor;
FUseTabs := False;
FTabWidth := 4;
+ FMinWidth := 20;
+ FMinHeight := 30;
FLines := TfpgMemoStrings.Create(self);
FFirstLine := 0;