1b39c5158Smillert#! /usr/bin/perl -w 2b39c5158Smillert 3b39c5158Smillert#END { 4b39c5158Smillert# sleep 10; 5b39c5158Smillert#} 6b39c5158Smillert 7b39c5158Smillertsub propagate_INC { 8b39c5158Smillert my $inc = $ENV{PERL5LIB}; 9b39c5158Smillert $inc = $ENV{PERLLIB} unless defined $inc; 10b39c5158Smillert $inc = '' unless defined $inc; 11b39c5158Smillert $ENV{PERL5LIB} = join ';', @INC, split /;/, $inc; 12b39c5158Smillert} 13b39c5158Smillert 14b39c5158Smillertmy $separate_session; 15b39c5158SmillertBEGIN { # Remap I/O to the parent's window 16b39c5158Smillert $separate_session = $ENV{OS2_PROCESS_TEST_SEPARATE_SESSION}; 17b39c5158Smillert propagate_INC, return unless $separate_session; # done by the parent 18b39c5158Smillert my @fn = split " ", $ENV{NEW_FD}; 19b39c5158Smillert my @fh = (*STDOUT, *STDERR); 20b39c5158Smillert my @how = qw( > > ); 21b39c5158Smillert # warn $_ for @fn; 22b39c5158Smillert open $fh[$_], "$how[$_]&=$fn[$_]" 23b39c5158Smillert or warn "Cannot reopen $fh[$_], $how[$_]&=$fn[$_]: $!" for 0..1; 24b39c5158Smillert} 25b39c5158Smillert 26b39c5158Smillertuse strict; 27b39c5158Smillertuse Test::More tests => 235; 28b39c5158Smillertuse OS2::Process; 29b39c5158Smillert 30b39c5158Smillertsub SWP_flags ($) { 31b39c5158Smillert my @nkpos = WindowPos shift; 32b39c5158Smillert $nkpos[2]; 33b39c5158Smillert} 34b39c5158Smillert 35b39c5158Smillertmy $interactive_wait = @ARGV && $ARGV[0] eq 'wait'; 36b39c5158Smillert 37b39c5158Smillertmy @l = OS2::Process::process_entry(); 38b39c5158Smillertok(@l == 11, 'all the fields of the process_entry() are there'); 39b39c5158Smillert 40b39c5158Smillert# 1: FS 2: Window-VIO 41b39c5158Smillertok( ($l[9] == 1 or $l[9] == 2), 'we are FS or Windowed-VIO'); 42b39c5158Smillert 43b39c5158Smillert#print "# $_\n" for @l; 44b39c5158Smillert 45b39c5158Smillerteval <<'EOE' or die; 46b39c5158Smillert#use OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST FID_CLIENT HWND_DESKTOP); 47b39c5158Smillertuse OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST HWND_DESKTOP); 48b39c5158Smillert 49b39c5158Smillertok( WM_SYSCOMMAND == 0x0021, 'correct WM_SYSCOMMAND' ); 50b39c5158Smillertok( WM_DBCSLAST == 0x00cf, 'correct WM_DBCSLAST' ); 51b39c5158Smillert#ok( FID_CLIENT == 0x8008 ); 52b39c5158Smillertok( HWND_DESKTOP == 0x0001, 'correct HWND_DESKTOP' ); 53b39c5158Smillert1; 54b39c5158SmillertEOE 55b39c5158Smillert 56b39c5158Smillertmy $t = Title; 57b39c5158Smillertmy $wint = winTitle; 58b39c5158Smillert 59b39c5158Smillertok($t, 'got session title'); 60b39c5158Smillertok($wint, 'got titlebar text'); 61b39c5158Smillert 62b39c5158Smillertmy $newt = "test OS2::Process $$"; 63b39c5158Smillertok(Title_set($newt), 'successfully set Title'); 64b39c5158Smillertis(Title, $newt, 'correctly set Title'); 65b39c5158Smillertmy $wt = winTitle or warn "winTitle: $!, $^E"; 66b39c5158Smillertis(winTitle, $newt, 'winTitle changed its value too'); 67b39c5158Smillertok(Title_set $t, 'successfully set Title back'); 68b39c5158Smillertis(Title, $t, 'correctly set Title back'); 69b39c5158Smillertis(winTitle, $wint, 'winTitle restored its value too'); 70b39c5158Smillert 71b39c5158Smillert$newt = "test OS2::Process both-$$"; 72b39c5158Smillertok(bothTitle_set($newt), 'successfully set both titles via Win* API'); 73b39c5158Smillertis(Title, $newt, 'session title correctly set'); 74b39c5158Smillertis(winTitle, $newt, 'winTitle correctly set'); 75b39c5158Smillertok(bothTitle_set($t), 'successfully reset both titles via Win* API'); 76b39c5158Smillertis(Title, $t, 'session title correctly reset'); 77b39c5158Smillertis(winTitle, $wint, 'winTitle correctly reset'); 78b39c5158Smillert 79b39c5158Smillert$newt = "test OS2::Process win-$$"; 80b39c5158Smillertok(winTitle_set($newt), 'successfully set titlebar title via Win* API'); 81b39c5158Smillertis(Title, $t, 'session title remained the same'); 82b39c5158Smillertis(winTitle, $newt, 'winTitle changed value'); 83b39c5158Smillertok(winTitle_set($wint), 'successfully reset titlebar title via Win* API'); 84b39c5158Smillertis(Title, $t, 'session title remained the same'); 85b39c5158Smillertis(winTitle, $wint, 'winTitle restored value'); 86b39c5158Smillert 87b39c5158Smillert$newt = "test OS2::Process sw-$$"; 88b39c5158Smillertok(swTitle_set($newt), 'successfully set session title via Win* API'); 89b39c5158Smillertis(Title, $newt, 'session title correctly set'); 90b39c5158Smillertis(winTitle, $wint, 'winTitle has unchanged value'); 91b39c5158Smillertok(swTitle_set($t), 'successfully reset session title via Win* API'); 92b39c5158Smillertis(Title, $t, 'session title correctly set'); 93b39c5158Smillertis(winTitle, $wint, 'winTitle has unchanged value'); 94b39c5158Smillert 95b39c5158Smillert$newt = "test OS2::Process again-$$"; 96b39c5158Smillertok(Title_set($newt), 'successfully set Title again'); 97b39c5158Smillertis(Title, $newt, 'correctly set Title again'); 98b39c5158Smillertis(winTitle, $newt, 'winTitle changed its value too again'); 99b39c5158Smillertok(Title_set($t), 'successfully set Title back'); 100b39c5158Smillertis(Title, $t, 'correctly set Title back'); 101b39c5158Smillertis(winTitle, $wint, 'winTitle restored its value too again'); 102b39c5158Smillert 103b39c5158Smillertmy $hwnd = process_hwnd; 104b39c5158Smillertok($hwnd, 'found session owner hwnd'); 105b39c5158Smillertmy $c_subhwnd = WindowFromId $hwnd, 0x8008; # FID_CLIENT; 106b39c5158Smillertok($c_subhwnd, 'found client hwnd'); 107b39c5158Smillertmy $a_subhwnd = ActiveWindow $hwnd; # or $^E and warn $^E; 108b39c5158Smillertok((not $a_subhwnd and not $^E), 'No active subwindow in a VIO frame'); 109b39c5158Smillert 110b39c5158Smillertmy $ahwnd = ActiveWindow; 111b39c5158Smillertok($ahwnd, 'found active window'); 112b39c5158Smillertmy $fhwnd = FocusWindow; 113b39c5158Smillertok($fhwnd, 'found focus window'); 114b39c5158Smillert 115b39c5158Smillert# This call without morphing results in VIO window with active highlight, but 116b39c5158Smillert# no keyboard focus (even after Alt-Tabbing to it; you cannot Alt-Tab off it!) 117b39c5158Smillert 118b39c5158Smillert# Interestingly, Desktop is active on the switch list, but the 119b39c5158Smillert# switch list is not acting on keyboard events. 120b39c5158Smillert 121b39c5158Smillert# Give up focus 122b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 123b39c5158Smillert ok $force_PM, 'morphed to PM locally'; 124b39c5158Smillert ok FocusWindow_set(1), 'set focus to DESKTOP'; # HWND_DESKTOP 125b39c5158Smillert} 126b39c5158Smillertmy $dtop = DesktopWindow; 127b39c5158Smillertok($dtop, 'found the desktop window'); 128b39c5158Smillert 129b39c5158Smillert#OS2::Process::ResetWinError; # XXXX Should not be needed! 130b39c5158Smillert$ahwnd = ActiveWindow or $^E and warn $^E; 131b39c5158Smillertok( (not $ahwnd and not $^E), 'desktop is not active'); 132b39c5158Smillert$fhwnd = FocusWindow; 133b39c5158Smillertok($fhwnd, 'there is a focus window'); 134b39c5158Smillertis($fhwnd, $dtop, 'which is the desktop'); 135b39c5158Smillert 136b39c5158Smillert# XXXX Well, no need to skip it now... 137b39c5158SmillertSKIP: { 138b39c5158Smillert skip 'We already have focus', 4 if $hwnd == $ahwnd; 139b39c5158Smillert my $force_PM = OS2::localMorphPM->new(0); 140b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 141b39c5158Smillert ok FocusWindow_set($c_subhwnd), 'set focus to the client of the session owner'; 142b39c5158Smillert # If we do not morph, then when the focus is in another VIO frame, 143b39c5158Smillert # we get two VIO frames with activated titlebars. 144b39c5158Smillert # The only (?) way to take the activated state from another frame 145b39c5158Smillert # is to switch to it via the switch list 146b39c5158Smillert $ahwnd = ActiveWindow; 147b39c5158Smillert ok($ahwnd, 'there is an active window'); 148b39c5158Smillert $fhwnd = FocusWindow; 149b39c5158Smillert ok($fhwnd, 'there is a focus window'); 150b39c5158Smillert is($hwnd, $ahwnd, 'the active window is the session owner'); 151b39c5158Smillert is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner'); 152b39c5158Smillert} 153b39c5158Smillert 154b39c5158Smillert# Give up focus again 155b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 156b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 157b39c5158Smillert ok FocusWindow_set(1), 'set focus to DESKTOP again'; # HWND_DESKTOP 158b39c5158Smillert} 159b39c5158Smillert 160b39c5158Smillert$ahwnd = ActiveWindow or $^E and warn $^E; 161b39c5158Smillertok( (not $ahwnd and not $^E), 'desktop is not active again'); 162b39c5158Smillert$fhwnd = FocusWindow; 163b39c5158Smillertok($fhwnd, 'there is a focus window'); 164b39c5158Smillertis($fhwnd, $dtop, 'which is the desktop'); 165b39c5158Smillert 166b39c5158Smillert# XXXX Well, no need to skip it now... 167b39c5158SmillertSKIP: { 168b39c5158Smillert skip 'We already have focus', 4 if $hwnd == $ahwnd; 169b39c5158Smillert my $force_PM = OS2::localMorphPM->new(0); 170b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 171b39c5158Smillert ok ActiveWindow_set($hwnd), 'activate the session owner'; 172b39c5158Smillert $ahwnd = ActiveWindow; 173b39c5158Smillert ok($ahwnd, 'there is an active window'); 174b39c5158Smillert $fhwnd = FocusWindow; 175b39c5158Smillert ok($fhwnd, 'there is a focus window'); 176b39c5158Smillert is($hwnd, $ahwnd, 'the active window is the session owner'); 177b39c5158Smillert} 178b39c5158Smillert 179b39c5158Smillert# XXXX Well, no need to skip it now... 180b39c5158SmillertSKIP: { 181b39c5158Smillert skip 'Tests assume we have focus', 1 unless $hwnd == $ahwnd; 182b39c5158Smillert # We have focus 183b39c5158Smillert # is($fhwnd, $ahwnd); 184b39c5158Smillert # is($a_subhwnd, $c_subhwnd); 185b39c5158Smillert is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner'); 186b39c5158Smillert} 187b39c5158Smillert 188b39c5158Smillert# Check enumeration of switch entries: 189b39c5158Smillertmy $skid_title = "temporary s-kid ppid=$$"; 190b39c5158Smillertmy $spid = system P_SESSION, $^X, '-wle', "END {sleep 25} use OS2::Process; eval {Title_set '$skid_title'} or warn \$@; \$SIG{TERM} = sub {exit 0}"; 191b39c5158Smillertok ($spid, 'start the new VIO session with unique title'); 192b39c5158Smillertsleep 1; 193b39c5158Smillertmy @sw = grep $_->{title} eq $skid_title, process_hentries; 194b39c5158Smillertsleep 1000 unless @sw; 195b39c5158Smillertis(scalar @sw, 1, 'exactly one session with this title'); 196b39c5158Smillertmy $sw = $sw[0]; 197b39c5158Smillertok $sw, 'have the data about the session'; 198b39c5158Smillertis($sw->{owner_pid}, $spid, 'session has a correct pid'); 199b39c5158Smillertmy $k_hwnd = $sw->{owner_hwnd}; 200b39c5158Smillertok $k_hwnd, 'found the session window handle'; 201b39c5158Smillertis sidOf($spid), $sw->{owner_sid}, 'we know sid of the session'; 202b39c5158Smillert 203b39c5158Smillert# Give up focus again 204b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 205b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 206b39c5158Smillert ok FocusWindow_set($k_hwnd), 'set focus to kid session window'; 207b39c5158Smillert} 208b39c5158Smillert 209b39c5158Smillert$ahwnd = ActiveWindow; 210b39c5158Smillertok $ahwnd, 'there is an active window'; 211b39c5158Smillertis $ahwnd, $k_hwnd, 'after focusing the active window is the owner_hwnd'; 212b39c5158Smillert$fhwnd = FocusWindow; 213b39c5158Smillertok $fhwnd, 'there is a focus window'; 214b39c5158Smillertmy $c_sub_ahwnd = WindowFromId $ahwnd, 0x8008; # FID_CLIENT; 215b39c5158Smillertok $c_sub_ahwnd, 'the active window has a FID_CLIENT'; 216b39c5158Smillertis($fhwnd, $ahwnd, 'the focus window = the active window'); 217b39c5158Smillert 218b39c5158Smillertok hWindowPos_set({behind => 3}, $k_hwnd), # HWND_TOP 219b39c5158Smillert 'put kid to the front'; 220b39c5158Smillert 221b39c5158Smillert# After Alt-Tab a WS_TOPMOST, WS_DISABLED window of class 'AltTabWindow' exists 222b39c5158Smillertmy $top = (hWindowPos $k_hwnd)->{behind}; 223b39c5158Smillertok(($top == 3 or WindowStyle($top) & 0x200000), # HWND_TOP, WS_TOPMOST 224b39c5158Smillert 'kid is at front'); 225b39c5158Smillert# is((hWindowPos $k_hwnd)->{behind}, 3, 'kid is at front'); 226b39c5158Smillert 227b39c5158Smillertmy ($enum_handle, $first_zorder, $first_non_TOPMOST); 228b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 229b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 230b39c5158Smillert $enum_handle = BeginEnumWindows 1; # HWND_DESKTOP 231b39c5158Smillert ok $enum_handle, 'start enumeration'; 232b39c5158Smillert $first_non_TOPMOST = $first_zorder = GetNextWindow $enum_handle; 233b39c5158Smillert ok $first_zorder, 'GetNextWindow works'; 234b39c5158Smillert my $f = WindowStyle $first_non_TOPMOST; 235b39c5158Smillert ok $f, 'WindowStyle works'; 236b39c5158Smillert $f = WindowStyle($first_non_TOPMOST = GetNextWindow $enum_handle) 237b39c5158Smillert while $f & 0x200000; # WS_TOPMOST 238b39c5158Smillert ok($first_non_TOPMOST, 'There is non-TOPMOST window'); 239b39c5158Smillert ok(!(WindowStyle($first_non_TOPMOST) & 0x200000), 'Indeed non-TOPMOST'); 240b39c5158Smillert ok EndEnumWindows($enum_handle), 'end enumeration'; 241b39c5158Smillert} 242b39c5158Smillertis ($first_non_TOPMOST, $k_hwnd, 'kid is the first in z-order enumeration'); 243b39c5158Smillert 244b39c5158Smillertok hWindowPos_set({behind => 4}, $k_hwnd), # HWND_BOTTOM 245b39c5158Smillert 'put kid to the back'; 246b39c5158Smillert 247b39c5158Smillert# This does not work, the result is the handle of "Window List" 248b39c5158Smillert# is((hWindowPos $k_hwnd)->{behind}, 4, 'kis is at back'); 249b39c5158Smillert 250b39c5158Smillertmy (@list, $next, @list1); 251b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 252b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 253b39c5158Smillert $enum_handle = BeginEnumWindows 1; # HWND_DESKTOP 254b39c5158Smillert ok $enum_handle, 'start enumeration'; 255b39c5158Smillert push @list, $next while $next = GetNextWindow $enum_handle; 256b39c5158Smillert @list1 = ChildWindows; 257b39c5158Smillert ok 1, 'embedded ChildWindows()'; 258b39c5158Smillert ok EndEnumWindows($enum_handle), 'end enumeration'; 259b39c5158Smillert 260b39c5158Smillert is_deeply \@list, \@list1, 'Manual list same as by ChildWindows()'; 261b39c5158Smillert # Apparently, the 'Desktop' window is still behind us; 262b39c5158Smillert # Note that this window is *not* what is returned by DesktopWindow 263b39c5158Smillert pop @list if WindowText($list[-1]) eq 'Desktop'; 264b39c5158Smillert} 265b39c5158Smillertis ($list[-1], $k_hwnd, 'kid is the last in z-order enumeration'); 266b39c5158Smillert# print "# kid=$k_hwnd in @list\n"; 267b39c5158Smillert@list = ChildWindows; 268b39c5158Smillertis_deeply \@list, \@list1, 'Other ChildWindows(), same result'; 269b39c5158Smillertok scalar @list, 'ChildWindows works'; 270b39c5158Smillertis $list[-2], $k_hwnd, 'kid is the last but one in ChildWindows'; 271b39c5158Smillert 272b39c5158Smillertok hWindowPos_set({behind => 3}, $k_hwnd), # HWND_TOP 273b39c5158Smillert 'put kid to the front again'; 274b39c5158Smillert 275b39c5158Smillert$top = (hWindowPos $k_hwnd)->{behind}; 276b39c5158Smillertok(($top == 3 or WindowStyle($top) & 0x200000), # WS_TOPMOST 277b39c5158Smillert 'kid is at front again'); 278b39c5158Smillertsleep 5 if $interactive_wait; 279b39c5158Smillert 280b39c5158Smillertok IsWindow($k_hwnd), 'IsWindow works'; 281b39c5158Smillert#print "# win=$k_hwnd => err=$^E\n"; 282b39c5158Smillertmy $c_sub_khwnd = WindowFromId $k_hwnd, 0x8008; # FID_CLIENT 283b39c5158Smillertok $c_sub_khwnd, 'have kids client window'; 284b39c5158Smillertok IsWindow($c_sub_khwnd), 'IsWindow works on the client'; 285b39c5158Smillert#print "# win=$c_sub_khwnd => IsWindow err=$^E\n"; 286b39c5158Smillertmy ($pkid,$tkid) = WindowProcess $c_sub_khwnd; 287b39c5158Smillertmy ($pkid1,$tkid1) = WindowProcess $hwnd; 288b39c5158Smillertok($pkid1 > 0, 'our window has a governing process'); 289b39c5158Smillertok($tkid1 > 0, 'our window has a governing thread'); 290b39c5158Smillertis($pkid, $pkid1, 'kid\'s window is governed by the same process as our (PMSHELL:1)'); 291b39c5158Smillertis($tkid, $tkid1, 'likewise for threads'); 292*898184e3Ssthenis $pkid, ppidOf($spid), 'the governor is the parent of the kid session'; 293b39c5158Smillert 294b39c5158Smillertmy $my_pos = hWindowPos($hwnd); 295b39c5158Smillertok $my_pos, 'got my position'; 296b39c5158Smillert{ my $force_PM = OS2::localMorphPM->new(0); 297b39c5158Smillert ok $force_PM, 'morphed to PM locally again'; 298b39c5158Smillert my @pos = WindowPos $hwnd; 299b39c5158Smillert my @ppos = WindowPos $k_hwnd; 300b39c5158Smillert # ok hWindowPos_set({%$my_pos, behind => $hwnd}, $k_hwnd), 'hide the kid behind us'; 301b39c5158Smillert # Hide it completely behind our window 302b39c5158Smillert ok hWindowPos_set({x => $my_pos->{x}, y => $my_pos->{y}, behind => $hwnd, 303b39c5158Smillert width => $my_pos->{width}, height => $my_pos->{height}}, 304b39c5158Smillert $k_hwnd), 'hide the kid behind us'; 305b39c5158Smillert # ok WindowPos_set($k_hwnd, $pos[0], $pos[1]), 'hide the kid behind us'; 306b39c5158Smillert my @kpos = WindowPos $k_hwnd; 307b39c5158Smillert # print "# kidpos=@ppos\n"; 308b39c5158Smillert # print "# mypos=@pos\n"; 309b39c5158Smillert # print "# kidpos=@kpos\n"; 310b39c5158Smillert# kidpos=252 630 4111 808 478 3 66518088 502482793 311b39c5158Smillert# mypos=276 78 4111 491 149 2147484137 66518060 502532977 312b39c5158Smillert# kidpos=276 78 4111 491 149 2147484255 1392374582 213000 313b39c5158Smillert print "# Before window position\n" if $interactive_wait; 314b39c5158Smillert sleep 5 if $interactive_wait; 315b39c5158Smillert 316b39c5158Smillert my $w_at = WindowFromPoint($kpos[0] + 5, $kpos[0] + 5, 1, 0); # HWND_DESKTOP, no grandchildren 317b39c5158Smillert ok $w_at, 'got window near LL corner of the kid'; 318b39c5158Smillert print "# we=$hwnd, our client=$c_subhwnd, kid=$k_hwnd, kid's client=$c_sub_khwnd\n"; 319b39c5158Smillert #is $w_at, $c_sub_khwnd, 'it is the kids client'; 320b39c5158Smillert #is $w_at, $k_hwnd, 'it is the kids frame'; 321b39c5158Smillert # Apparently, this result is accidental only... 322b39c5158Smillert# is $w_at, $hwnd, 'it is our frame - is on top, but no focus'; 323b39c5158Smillert #is $w_at, $c_subhwnd, 'it is our client'; 324b39c5158Smillert print "# text: `", WindowText $w_at, "'.\n"; 325b39c5158Smillert $w_at = WindowFromPoint($kpos[0] + 5, $kpos[0] + 5); # HWND_DESKTOP, grandchildren too 326b39c5158Smillert ok $w_at, 'got grandkid window near LL corner of the kid'; 327b39c5158Smillert # Apparently, this result is accidental only... 328b39c5158Smillert# is $w_at, $c_subhwnd, 'it is our client'; 329b39c5158Smillert print "# text: `", WindowText $w_at, "'.\n"; 330b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 331b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 332b39c5158Smillert ok IsWindowShowing $hwnd, 'we are showing'; 333b39c5158Smillert ok ((not IsWindowShowing $k_hwnd), 'kid is not showing'); 334b39c5158Smillert ok ((not eval { IsWindowShowing 12; 1 }), 'wrong kid causes errors'); 335b39c5158Smillert is $^E+0, 0x1001, 'error is 0x1001'; 336b39c5158Smillert like $@, qr/\Q[Win]IsWindowShowing/, 'error message shows function'; 337b39c5158Smillert like $@, qr/SYS4097\b/, 'error message shows error number'; 338b39c5158Smillert like $@, qr/\b0x1001\b/, 'error message shows error number in hex'; 339b39c5158Smillert 340b39c5158Smillert ok WindowPos_set($k_hwnd, @ppos[0..5]), 'restore the kid position'; 341b39c5158Smillert my @nkpos = WindowPos $k_hwnd; 342b39c5158Smillert my $fl = $nkpos[2]; 343b39c5158Smillert is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored'); 344b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 345b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 346b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 347b39c5158Smillert sleep 5 if $interactive_wait; 348b39c5158Smillert ok EnableWindow($k_hwnd, 0), 'disable the kid'; 349b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 350b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 351b39c5158Smillert ok !IsWindowEnabled $k_hwnd, 'kid is flaged as not enabled'; 352b39c5158Smillert ok EnableWindow($k_hwnd), 'enable the kid'; 353b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 354b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 355b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 356b39c5158Smillert ok ShowWindow($k_hwnd, 0), 'hide the kid'; 357b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 358b39c5158Smillert ok !IsWindowVisible $k_hwnd, 'kid is flaged as not visible'; 359b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 360b39c5158Smillert ok ShowWindow($k_hwnd), 'show the kid'; 361b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 362b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 363b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 364b39c5158Smillert ok( ($fl & 0x1800), 'window is maximized or restored'); # SWP_MAXIMIZE SWP_RESTORE 365b39c5158Smillert ok( ($fl & 0x1800) != 0x1800, 'window is not maximized AND restored'); # SWP_MAXIMIZE SWP_RESTORE 366b39c5158Smillert 367b39c5158Smillert ok PostMsg( $k_hwnd, 0x21, # WM_SYSCOMMAND, SC_MINIMIZE 368b39c5158Smillert OS2::Process::MPFROMSHORT 0x8002), 'post minimize message'; 369b39c5158Smillert sleep 1; 370b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 371b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 372b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 373b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 374b39c5158Smillert 375b39c5158Smillert ok PostMsg($k_hwnd, 0x21, # WM_SYSCOMMAND, SC_RESTORE 376b39c5158Smillert OS2::Process::MPFROMSHORT 0x8008), 'post restore message'; 377b39c5158Smillert sleep 1; 378b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 379b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 380b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 381b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE 382b39c5158Smillert 383b39c5158Smillert ok PostMsg($k_hwnd, 0x21, # WM_SYSCOMMAND, SC_MAXIMIZE 384b39c5158Smillert OS2::Process::MPFROMSHORT 0x8003), 'post maximize message'; 385b39c5158Smillert sleep 1; 386b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 387b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 388b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 389b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x800, 'kid is maximized'; # SWP_MAXIMIZE 390b39c5158Smillert 391b39c5158Smillert ok PostMsg( $k_hwnd, 0x21, # WM_SYSCOMMAND, SC_MINIMIZE 392b39c5158Smillert OS2::Process::MPFROMSHORT 0x8002), 'post minimize message again'; 393b39c5158Smillert sleep 1; 394b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 395b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 396b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 397b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 398b39c5158Smillert 399b39c5158Smillert ok PostMsg($k_hwnd, 0x21, # WM_SYSCOMMAND, SC_RESTORE 400b39c5158Smillert OS2::Process::MPFROMSHORT 0x8008), 'post restore message again'; 401b39c5158Smillert sleep 1; 402b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 403b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 404b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 405b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE 406b39c5158Smillert 407b39c5158Smillert ok PostMsg( $k_hwnd, 0x21, # WM_SYSCOMMAND, SC_MINIMIZE 408b39c5158Smillert OS2::Process::MPFROMSHORT 0x8002), 'post minimize message again'; 409b39c5158Smillert sleep 1; 410b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 411b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 412b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 413b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 414b39c5158Smillert 415b39c5158Smillert ok PostMsg($k_hwnd, 0x21, # WM_SYSCOMMAND, SC_RESTORE 416b39c5158Smillert OS2::Process::MPFROMSHORT (($fl & 0x800) ? 0x8003 : 0x8008)), # SWP_MAXIMIZE 417b39c5158Smillert 'return back to the initial MAXIMIZE/RESTORE state'; 418b39c5158Smillert sleep 1; 419b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 420b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 421b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 422b39c5158Smillert SKIP: { 423b39c5158Smillert skip 'if defaultVIO=MAXIMIZED, new windows are shifted, but maximize to UL corner', 1 unless $fl & 0x800; 424b39c5158Smillert ok hWindowPos_set({x => $ppos[0], y => $ppos[1]}, $k_hwnd), 'x,y-restore for de-minimization of MAXIMIZED'; 425b39c5158Smillert } 426b39c5158Smillert @nkpos = WindowPos $k_hwnd; 427b39c5158Smillert is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored'); 428b39c5158Smillert 429b39c5158Smillert 430b39c5158Smillert # Now the other way 431b39c5158Smillert ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized'; 432b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 433b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 434b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 435b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 436b39c5158Smillert 437b39c5158Smillert ok hWindowPos_set( {flags => 0x1000}, $k_hwnd), 'set to restore'; 438b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 439b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 440b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 441b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE 442b39c5158Smillert 443b39c5158Smillert ok hWindowPos_set( {flags => 0x800}, $k_hwnd), 'set to maximized'; 444b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 445b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 446b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 447b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x800, 'kid is maximized'; # SWP_MAXIMIZE 448b39c5158Smillert 449b39c5158Smillert ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized again'; 450b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 451b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 452b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 453b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 454b39c5158Smillert 455b39c5158Smillert ok hWindowPos_set( {flags => 0x1000}, $k_hwnd), 'set to restore again'; 456b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 457b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 458b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 459b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE 460b39c5158Smillert 461b39c5158Smillert ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized again'; 462b39c5158Smillert ok !IsWindowShowing $k_hwnd, 'kid is not showing'; 463b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 464b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 465b39c5158Smillert is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE 466b39c5158Smillert 467b39c5158Smillert ok hWindowPos_set( {flags => ($fl & 0x1800)}, $k_hwnd), 468b39c5158Smillert 'set back to the initial MAXIMIZE/RESTORE state'; 469b39c5158Smillert ok IsWindowShowing $k_hwnd, 'kid is showing'; 470b39c5158Smillert ok IsWindowVisible $k_hwnd, 'kid is flaged as visible'; 471b39c5158Smillert ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled'; 472b39c5158Smillert SKIP: { 473b39c5158Smillert skip 'if defaultVIO=MAXIMIZED, new windows are shifted, but maximize to UL corner', 1 unless $fl & 0x800; 474b39c5158Smillert ok hWindowPos_set({x => $ppos[0], y => $ppos[1]}, $k_hwnd), 'x,y-restore for de-minimization of MAXIMIZED'; 475b39c5158Smillert } 476b39c5158Smillert @nkpos = WindowPos $k_hwnd; 477b39c5158Smillert is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored'); 478b39c5158Smillert 479b39c5158Smillert} 480b39c5158Smillert 481b39c5158Smillert# XXXX Well, no need to skip it now... 482b39c5158SmillertSKIP: { 483b39c5158Smillert skip 'We already have focus', 4 if $hwnd == $ahwnd; 484b39c5158Smillert my $force_PM = OS2::localMorphPM->new(0); 485b39c5158Smillert ok($force_PM, 'morphed to catch focus again'); 486b39c5158Smillert ok FocusWindow_set($c_subhwnd), 'set focus to the client of the session owner'; 487b39c5158Smillert # If we do not morph, then when the focus is in another VIO frame, 488b39c5158Smillert # we get two VIO frames with activated titlebars. 489b39c5158Smillert # The only (?) way to take the activated state from another frame 490b39c5158Smillert # is to switch to it via the switch list 491b39c5158Smillert $ahwnd = ActiveWindow; 492b39c5158Smillert ok($ahwnd, 'there is an active window'); 493b39c5158Smillert $fhwnd = FocusWindow; 494b39c5158Smillert ok($fhwnd, 'there is a focus window'); 495b39c5158Smillert is($hwnd, $ahwnd, 'the active window is the session owner'); 496b39c5158Smillert is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner'); 497b39c5158Smillert} 498b39c5158Smillert 499b39c5158SmillertSKIP: { 500b39c5158Smillert skip 'Potentially destructive session modifications, done in a separate session only', 501b39c5158Smillert 12, unless $separate_session; 502b39c5158Smillert # Manipulate process' hentry 503b39c5158Smillert my $he = process_hentry; 504b39c5158Smillert ok($he, 'got process hentry'); 505b39c5158Smillert ok($he->{visible}, 'session switch is visible');# 4? Assume nobody manipulated it... 506b39c5158Smillert 507b39c5158Smillert ok change_entryh($he), 'can change it (without modifications)'; 508b39c5158Smillert my $nhe = process_hentry; 509b39c5158Smillert ok $nhe, 'could refetch the process hentry'; 510b39c5158Smillert is_deeply($nhe, $he, 'it did not change'); 511b39c5158Smillert 512b39c5158Smillert sleep 5 if $interactive_wait; 513b39c5158Smillert # Try removing the process entry from the switch list 514b39c5158Smillert $nhe->{visible} = 0; 515b39c5158Smillert ok change_entryh($nhe), 'can change it to be invisible'; 516b39c5158Smillert my $nnhe = process_hentry; 517b39c5158Smillert ok($nnhe, 'could refetch the process hentry'); 518b39c5158Smillert is_deeply($nnhe, $nhe, 'it is modified as expected'); 519b39c5158Smillert is($nnhe->{visible}, 0, 'it is not visible'); 520b39c5158Smillert 521b39c5158Smillert sleep 5 if $interactive_wait; 522b39c5158Smillert 523b39c5158Smillert $nhe->{visible} = 1; 524b39c5158Smillert ok change_entryh ($nhe), 'can change it to be visible'; 525b39c5158Smillert $nnhe = process_hentry; 526b39c5158Smillert ok($nnhe, 'could refetch the process hentry'); 527b39c5158Smillert ok($nnhe->{visible}, 'it is visible'); 528b39c5158Smillert sleep 5 if $interactive_wait; 529b39c5158Smillert} 530