Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!yale!ox.com!tbomb.ice.com!time From: time@tbomb.ice.com (Tim Endres) Newsgroups: comp.sys.mac.programmer Subject: Re: Remembering window locations Message-ID: <1CE00001.40bylu@tbomb.ice.com> Date: 19 Jan 91 22:30:24 GMT Reply-To: time@ice.com Organization: ICE Engineering, Inc. Lines: 104 X-Mailer: uAccess - Mac Release: 1.0.5+ In article , es1o+@andrew.cmu.edu (Eric Mitchell Snider) writes: > I need some advice on how to save window locations (so the window will > appear where the user left it when they run the program again...) and > intelligently make them appear. I have no problems with saving the > locations of windows. The problem I'm having is I don't know how to > check if the window will appear on the screen. Suppose someone with a > big monitor drags the window way into the lower right corner. If > someone else with a small screen runs the program and it tries to > display the window, they may not be able to see it... How can I deal > with this? I need to be able to check if the window was saved in a > valid location. This is very similar to examples from Apple. Call it in good health. tim. ---------------- DoCheckWindowRect(windRect, check_size) Rect *windRect; int check_size; /* != 0 if you want the size reduced to fit screen. */ { Rect wrect, thesect, titlerect, screenrect; GDHandle dom_gdev, this_gdev; long sect_area, greatest_area; int bias, title_on_screen; int sect_flag; titlerect = *windRect; titlerect.bottom = titlerect.top; titlerect.top -= 20; wrect = *windRect; if (wrect.bottom == wrect.top) /* Catch titlized windows */ wrect.top--; if (GLOBAL_VARIABLE(theEnviron).hasColorQD) { dom_gdev = this_gdev = GetDeviceList(); greatest_area = 0; title_on_screen = 0; for (; this_gdev != (GDHandle)0; this_gdev=GetNextDevice(this_gdev)) { if (TestDeviceAttribute(this_gdev, screenDevice)) { if (TestDeviceAttribute(this_gdev, screenActive)) { sect_flag = SectRect(&wrect, &(**this_gdev).gdRect, &thesect); sect_area = (long)(thesect.right - thesect.left) * (long)(thesect.bottom - thesect.top); if (sect_area > greatest_area) { greatest_area = sect_area; dom_gdev = this_gdev; } if (SectRect(&titlerect, &(**this_gdev).gdRect, &thesect)) title_on_screen = 1; } /* screenActive */ } /* screenDevice */ } /* for */ if (dom_gdev = GetMainDevice()) bias = GetMBarHeight(); screenrect = (**dom_gdev).gdRect; if (greatest_area == 0) { /* Not on ANY screen! */ OffsetRect(windRect, - ( windRect->left - screenrect.left), - ( windRect->top - (screenrect.top + bias)) ); OffsetRect(windRect, 10, 20); } else if (! title_on_screen) { OffsetRect(windRect, 0, - ( windRect->top - (screenrect.top + bias) ) ); OffsetRect(windRect, 10, 20); } } else { bias = GetMBarHeight(); screenrect = scrnrect; if (! SectRect(&wrect, &screenrect, &thesect)) { OffsetRect(windRect, - ( windRect->left - screenrect.left), - ( windRect->top - screenrect.top + bias) ); OffsetRect(windRect, 10, 20); } else if (! SectRect(&titlerect, &screenrect, &thesect)) { OffsetRect(windRect, 0, - ( windRect->top - screenrect.top + bias) ); OffsetRect(windRect, 10, 20); } } if (check_size) { if ((windRect->bottom - windRect->top) > (screenrect.bottom - screenrect.top)) windRect->bottom = (windRect->top + (screenrect.bottom - screenrect.top)) - bias; if ((windRect->right - windRect->left) > (screenrect.right - screenrect.left)) windRect->right = (windRect->left + (screenrect.right - screenrect.left)) - bias; } } ------------------------------------------------------------- Tim Endres | time@ice.com ICE Engineering | uupsi!ice.com!time 8840 Main Street | Whitmore Lake MI. 48189 | (313) 449 8288