void PainterTest_App::WindowRosterChanged() { auto_ptr<ZOSWindowRoster> theRoster(fOSApp->CreateOSWindowRoster()); for (;;) { ZOSWindow* theOSWindow; if (!theRoster->GetNextOSWindow(2000000, theOSWindow)) { // Timed out, just try again. This is a bad thing // if the window is deadlocked against our lock, but // that shouldn't be the case, and in fact the timeout // shouldn't happen either. continue; } if (!theOSWindow) { // No more windows, drop out of the loop. break; } if (PainterTest_Window* theWindow = dynamic_cast<PainterTest_Window*>(theOSWindow->GetOwner())) { // We've got a painter window, so just return. theRoster->UnlockCurrentOSWindow(); return; } theRoster->UnlockCurrentOSWindow(); } // There are no open painter windows, so quit. if (!TESTING && this->QuitRequested()) fOSApp->ExitRun(); }
PainterTest_Window* PainterTest_App::GetPainterWindow(const ZFileSpec& inFileSpec) { auto_ptr<ZOSWindowRoster> theRoster(fOSApp->CreateOSWindowRoster()); bool allOkay = true; while (allOkay) { bool askedAnyWindows = false; while (allOkay) { ZOSWindow* theOSWindow; if (theRoster->GetNextOSWindow(2000000, theOSWindow)) { if (!theOSWindow) break; if (PainterTest_Window* theWindow = dynamic_cast<PainterTest_Window*>(theOSWindow->GetOwner())) { askedAnyWindows = true; if (sFileSpec_Equal(inFileSpec, theWindow->GetFileSpec())) return theWindow; } theRoster->UnlockCurrentOSWindow(); } else { // If we timed out, treat it as if the user had explicitly cancelled. allOkay = false; } } if (!askedAnyWindows) break; } return nil; }
bool ZApp::QuitRequested() { auto_ptr<ZOSWindowRoster> theRoster(fOSApp->CreateOSWindowRoster()); bool allOkay = true; while (allOkay) { bool askedAnyWindows = false; // First work through every window and ask those that are active and visible (tautological, I know) if it's okay to quit while (allOkay) { ZOSWindow* theOSWindow; if (theRoster->GetNextOSWindow(2000000, theOSWindow)) { if (!theOSWindow) break; if (ZWindow* theWindow = dynamic_cast<ZWindow*>(theOSWindow->GetOwner())) { askedAnyWindows = true; if (theWindow->GetWindowActive() && theWindow->GetShown()) { theRoster->DropCurrentOSWindow(); allOkay = theWindow->WindowQuitRequested(); } } theRoster->UnlockCurrentOSWindow(); } else { // If we timed out, treat it as if the user had explicitly cancelled. allOkay = false; } } // Reset the roster, which empties the list of visited windows but remembers the dropped windows. theRoster->Reset(); // Now work through every window and ask those that are at least visible while (allOkay) { ZOSWindow* theOSWindow; if (theRoster->GetNextOSWindow(2000000, theOSWindow)) { if (!theOSWindow) break; if (ZWindow* theWindow = dynamic_cast<ZWindow*>(theOSWindow->GetOwner())) { askedAnyWindows = true; if (theWindow->GetShown()) { theRoster->DropCurrentOSWindow(); allOkay = theWindow->WindowQuitRequested(); } } theRoster->UnlockCurrentOSWindow(); } else { allOkay = false; } } // Once more, reset the roster theRoster->Reset(); // And work through every window, regardless of whether it's visible or active. while (allOkay) { ZOSWindow* theOSWindow; if (theRoster->GetNextOSWindow(2000000, theOSWindow)) { if (!theOSWindow) break; if (ZWindow* theWindow = dynamic_cast<ZWindow*>(theOSWindow->GetOwner())) { askedAnyWindows = true; theRoster->DropCurrentOSWindow(); allOkay = theWindow->WindowQuitRequested(); } theRoster->UnlockCurrentOSWindow(); } else { allOkay = false; } } if (!askedAnyWindows) break; } return allOkay; }