Fix window position when shown for the first time
This commit is contained in:
Родитель
226d840c49
Коммит
64aa15d232
|
@ -78,6 +78,23 @@ namespace Xwt.GtkBackend
|
|||
get { return eventSink; }
|
||||
}
|
||||
|
||||
public void Move (double x, double y)
|
||||
{
|
||||
Window.Move ((int)x, (int)y);
|
||||
Toolkit.Invoke (delegate {
|
||||
EventSink.OnBoundsChanged (Bounds);
|
||||
});
|
||||
}
|
||||
|
||||
public void Resize (double width, double height)
|
||||
{
|
||||
Window.Resize ((int)width, (int)height);
|
||||
Window.SetDefaultSize ((int)width, (int)height);
|
||||
Toolkit.Invoke (delegate {
|
||||
EventSink.OnBoundsChanged (Bounds);
|
||||
});
|
||||
}
|
||||
|
||||
public Rectangle Bounds {
|
||||
get {
|
||||
int w, h, x, y;
|
||||
|
|
|
@ -268,6 +268,19 @@ namespace Xwt.Mac
|
|||
child.View.Frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
void IWindowFrameBackend.Move (double x, double y)
|
||||
{
|
||||
var r = FrameRectFor (new System.Drawing.RectangleF ((float)x, (float)y, Frame.Width, Frame.Height));
|
||||
SetFrame (r, true);
|
||||
}
|
||||
|
||||
void IWindowFrameBackend.Resize (double width, double height)
|
||||
{
|
||||
var cr = ContentRectFor (Frame);
|
||||
var r = FrameRectFor (new System.Drawing.RectangleF ((float)cr.X, (float)cr.Y, (float)width, (float)height));
|
||||
SetFrame (r, true);
|
||||
}
|
||||
|
||||
Rectangle IWindowFrameBackend.Bounds {
|
||||
get {
|
||||
|
|
|
@ -33,6 +33,9 @@ namespace Xwt.Backends
|
|||
void Dispose ();
|
||||
|
||||
Rectangle Bounds { get; set; }
|
||||
void Move (double x, double y);
|
||||
void Resize (double width, double height);
|
||||
|
||||
bool Visible { get; set; }
|
||||
string Title { get; set; }
|
||||
|
||||
|
|
|
@ -223,9 +223,6 @@
|
|||
</Compile>
|
||||
<Compile Include="Xwt.Backends\ICheckBoxBackend.cs" />
|
||||
<Compile Include="Xwt\ContentPosition.cs" />
|
||||
<Compile Include="Xwt\Frame.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Xwt.Backends\IFrameBackend.cs" />
|
||||
<Compile Include="Xwt\Separator.cs">
|
||||
<SubType>Component</SubType>
|
||||
|
@ -303,6 +300,7 @@
|
|||
<Compile Include="Xwt\SpinButton.cs" />
|
||||
<Compile Include="Xwt\DatePicker.cs" />
|
||||
<Compile Include="Xwt.Backends\IDatePickerBackend.cs" />
|
||||
<Compile Include="Xwt\Frame.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup />
|
||||
|
|
|
@ -103,15 +103,34 @@ namespace Xwt
|
|||
|
||||
bool widthSet;
|
||||
bool heightSet;
|
||||
bool locationSet;
|
||||
Rectangle initialBounds;
|
||||
|
||||
internal override void SetSize (double width, double height)
|
||||
internal override void SetBackendSize (double width, double height)
|
||||
{
|
||||
if (width != -1)
|
||||
widthSet = true;
|
||||
if (height != -1)
|
||||
heightSet = true;
|
||||
base.SetSize (width, height);
|
||||
if (shown) {
|
||||
base.SetBackendSize (width, height);
|
||||
}
|
||||
else {
|
||||
if (width != -1) {
|
||||
initialBounds.Width = width;
|
||||
widthSet = true;
|
||||
}
|
||||
if (height != -1) {
|
||||
heightSet = true;
|
||||
initialBounds.Height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal override void SetBackendLocation (double x, double y)
|
||||
{
|
||||
if (shown)
|
||||
base.SetBackendLocation (x, y);
|
||||
else {
|
||||
locationSet = true;
|
||||
initialBounds.Location = new Point (x, y);
|
||||
}
|
||||
}
|
||||
|
||||
internal override Rectangle BackendBounds
|
||||
|
@ -124,8 +143,10 @@ namespace Xwt
|
|||
{
|
||||
if (shown)
|
||||
base.BackendBounds = value;
|
||||
else
|
||||
else {
|
||||
widthSet = heightSet = locationSet = true;
|
||||
initialBounds = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +178,15 @@ namespace Xwt
|
|||
|
||||
shown = true;
|
||||
|
||||
if (size != Size)
|
||||
Size = size;
|
||||
if (size != Size) {
|
||||
if (locationSet)
|
||||
Backend.Bounds = initialBounds;
|
||||
else
|
||||
Size = size;
|
||||
}
|
||||
else if (locationSet)
|
||||
Backend.Move (initialBounds.X, initialBounds.Y);
|
||||
|
||||
Location = initialBounds.Location;
|
||||
|
||||
Backend.SetMinSize (new Size (w.MinSize + padding.HorizontalSpacing, h.MinSize + padding.VerticalSpacing));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ namespace Xwt
|
|||
EventHandler shown;
|
||||
EventHandler hidden;
|
||||
|
||||
Rectangle bounds;
|
||||
Point location;
|
||||
Size size;
|
||||
bool pendingReallocation;
|
||||
|
||||
protected class WindowBackendHost: BackendHost<WindowFrame,IWindowFrameBackend>, IWindowFrameEventSink
|
||||
|
@ -71,7 +72,8 @@ namespace Xwt
|
|||
{
|
||||
base.OnBackendCreated ();
|
||||
Backend.Initialize (this);
|
||||
Parent.bounds = Backend.Bounds;
|
||||
Parent.location = Backend.Bounds.Location;
|
||||
Parent.size = Backend.Bounds.Size;
|
||||
Backend.EnableEvent (WindowFrameEvent.BoundsChanged);
|
||||
}
|
||||
|
||||
|
@ -140,19 +142,18 @@ namespace Xwt
|
|||
value.Width = 0;
|
||||
if (value.Height < 0)
|
||||
value.Height = 0;
|
||||
SetSize (value.Width, value.Height);
|
||||
BackendBounds = value;
|
||||
}
|
||||
}
|
||||
|
||||
public double X {
|
||||
get { return BackendBounds.X; }
|
||||
set { BackendBounds = new Xwt.Rectangle (value, Y, Width, Height); }
|
||||
set { SetBackendLocation (value, Y); }
|
||||
}
|
||||
|
||||
public double Y {
|
||||
get { return BackendBounds.Y; }
|
||||
set { BackendBounds = new Xwt.Rectangle (X, value, Width, Height); }
|
||||
set { SetBackendLocation (X, value); }
|
||||
}
|
||||
|
||||
public double Width {
|
||||
|
@ -160,8 +161,7 @@ namespace Xwt
|
|||
set {
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
SetSize (value, -1);
|
||||
BackendBounds = new Rectangle (X, Y, value, Height);
|
||||
SetBackendSize (value, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,8 +170,7 @@ namespace Xwt
|
|||
set {
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
SetSize (-1, value);
|
||||
BackendBounds = new Rectangle (X, Y, Width, value);
|
||||
SetBackendSize (-1, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,14 +181,13 @@ namespace Xwt
|
|||
value.Width = 0;
|
||||
if (value.Height < 0)
|
||||
value.Height = 0;
|
||||
SetSize (value.Width, value.Height);
|
||||
BackendBounds = new Rectangle (Location, value);
|
||||
SetBackendSize (value.Width, value.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public Point Location {
|
||||
get { return BackendBounds.Location; }
|
||||
set { BackendBounds = new Rectangle (value.X, value.Y, Width, Height); }
|
||||
set { SetBackendLocation (value.X, value.Y); }
|
||||
}
|
||||
|
||||
public string Title {
|
||||
|
@ -243,20 +241,36 @@ namespace Xwt
|
|||
hidden (this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal virtual void SetSize (double width, double height)
|
||||
internal virtual void SetBackendSize (double width, double height)
|
||||
{
|
||||
BackendBounds = new Rectangle (X, Y, width != -1 ? width : Width, height != -1 ? height : Height);
|
||||
size = new Size (width != -1 ? width : Width, height != -1 ? height : Height);
|
||||
Backend.Resize (size.Width, size.Height);
|
||||
}
|
||||
|
||||
internal virtual void SetBackendLocation (double x, double y)
|
||||
{
|
||||
location = new Point (x, y);
|
||||
Backend.Move (x, y);
|
||||
}
|
||||
|
||||
internal virtual Rectangle BackendBounds {
|
||||
get { BackendHost.EnsureBackendLoaded (); return bounds; }
|
||||
set { bounds = Backend.Bounds = value; }
|
||||
get {
|
||||
BackendHost.EnsureBackendLoaded ();
|
||||
return new Rectangle (location, size);
|
||||
}
|
||||
set {
|
||||
size = value.Size;
|
||||
location = value.Location;
|
||||
Backend.Bounds = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnBoundsChanged (BoundsChangedEventArgs a)
|
||||
{
|
||||
var bounds = new Rectangle (location, size);
|
||||
if (bounds != a.Bounds) {
|
||||
bounds = a.Bounds;
|
||||
size = a.Bounds.Size;
|
||||
location = a.Bounds.Location;
|
||||
Reallocate ();
|
||||
if (boundsChanged != null)
|
||||
boundsChanged (this, a);
|
||||
|
|
Загрузка…
Ссылка в новой задаче