C++ (Qt)bool QCocoaMenuBar::shouldDisable(QCocoaWindow *active) const{ if (active && (active->window()->modality() == Qt::NonModal)) return false; if (m_window == active) { // modal window owns us, we should be enabled! return false; } QWindowList topWindows(qApp->topLevelWindows()); // When there is an application modal window on screen, the entries of // the menubar should be disabled. The exception in Qt is that if the // modal window is the only window on screen, then we enable the menu bar. foreach (QWindow *w, topWindows) { if (w->isVisible() && w->modality() == Qt::ApplicationModal) { // check for other visible windows foreach (QWindow *other, topWindows) { if ((w != other) && (other->isVisible())) { // INVARIANT: we found another visible window // on screen other than our modalWidget. We therefore // disable the menu bar to follow normal modality logic: return true; } } // INVARIANT: We have only one window on screen that happends // to be application modal. We choose to enable the menu bar // in that case to e.g. enable the quit menu item. return false; } } return true;}