Hi,

> Just fixed a bug with windows that had the -parent option given, and were
> then positioned with the Left() and Top() methods. These methods were
> detecting that the window had a parent and were translating X (in the case
> of Top() ) and Y (in the case of Left() ) into the current X or Y
> co-ordinate minus the parent X or Y co-ordinate, causing child windows
that
> were sent multiple Top(somenumber) or Left(somenumber) calls to "walk"
> horizontally or vertically across the desktop in steps dependent on the
> position of their parent window. Nasty.

I'm not understand your problem and bug fix.
For me, coordinate of a child windows is relative to parent window and not
screen relative.
Only main window are screen coordinate.

I have test sample below with your change, and button move when sizing or
main window move.
Button should alway be at 5,5 in main window, with AddButton or with new
GUI::Button + parent option.

use Win32::GUI;
$W = new Win32::GUI::Window(
    -title  => "test",
    -left   => 100,
    -top    => 100,
    -width  => 280,
    -height => 280,
    -name   => "Window",
);
# $button = $W->AddButton(                        # This keep button as 5,5
$button = new Win32::GUI::Button( -parent => $W,  # This move button
    -name    => "Simple1",
    -left    => 5,
    -top     => 5,
    -width  => 122,
    -height => 400,
    -text    => "Just button",
);
$W->Show;
Win32::GUI::Dialog();

sub Window_Terminate {
  return -1;
}

sub Window_Resize {
 $button->Left(5);
 $button->Top(5);
 print "Resize !!!\n";
}

>
> You might be confused as to why I fixed this in quite the way I did
(setting
> a flag in userdata if the user specifies -parent).
>
> I did this because I wanted to preserve the ability to explicitly call
> SetParent on a window to insert it into another window's client area. This
> is an especially handy trick for making hidable/moveable panes without
> moving all the widgets one by one. If I simply detected if the thing that
> was having Top/Left set was a window or not, it would not translate the
> co-ordinates when it should do.

If you want move or hide a group of widget, it's better to create all widget
directly to a parent/container window.
And move or hide this container window.
Some thing like that :

use Win32::GUI;

$W = new Win32::GUI::Window(
    -title  => "test",
    -pos    => [100, 100],
    -size   => [280, 280],
    -name   => "Window",
);

$Grp1 = $W->AddGroupbox(
    -name    => "Groupe",
    -text    =>  "Groupe",
    -pos     => [5, 5],
    -size    => [122, 200],
);

new Win32::GUI::Button (
    -parent  => $Grp1,
    -name    => "Test",
    -text    => "Test!!!",
    -pos     => [20, 20]
);

$W->AddButton (
    -name    => "Hide",
    -text    => "Hide it",
    -pos     => [200, 5],
);

$W->AddButton (
    -name    => "Show",
    -text    => "Show it",
    -pos     => [ 200, 40],
);

$W->AddButton (
    -name    => "Move",
    -text    => "Move it",
    -pos     => [200, 75],
);

$W->Show;
Win32::GUI::Dialog();

sub Window_Terminate { return -1; }
sub Test_Click { print "test !!!\n"; }
sub Hide_Click { $Grp1->Hide(); }
sub Show_Click { $Grp1->Show(); }
sub Move_Click { $Grp1->Top($Grp1->Top + 2); }

You can look on my TabFrame package, i have a Frame.pm class with act as
window container.
Frame heritate from Win32::GUI::Window so you can use standard Add<Control>
method.

If you really need use SetParent for runtime change, i think it's probably
better to add set functionnality to AbsLeft and AbsTop.
And use those functions rather Left and Top.

Laurent.


Reply via email to