783 // the current modal session. So if we need to stop NSApp |
783 // the current modal session. So if we need to stop NSApp |
784 // we need to stop all the modal session first. To avoid changing |
784 // we need to stop all the modal session first. To avoid changing |
785 // the stacking order of the windows while doing so, we put |
785 // the stacking order of the windows while doing so, we put |
786 // up a block that is used in QCocoaWindow and QCocoaPanel: |
786 // up a block that is used in QCocoaWindow and QCocoaPanel: |
787 int stackSize = cocoaModalSessionStack.size(); |
787 int stackSize = cocoaModalSessionStack.size(); |
788 for (int i=stackSize-1; i>=0; --i) { |
788 for (int i=0; i<stackSize; ++i) { |
789 QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; |
789 QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; |
790 if (info.session) { |
790 if (info.session) { |
791 [NSApp endModalSession:info.session]; |
791 [NSApp endModalSession:info.session]; |
792 info.session = 0; |
792 info.session = 0; |
793 } |
793 } |
820 |
820 |
821 ensureNSAppInitialized(); |
821 ensureNSAppInitialized(); |
822 QBoolBlocker block1(blockSendPostedEvents, true); |
822 QBoolBlocker block1(blockSendPostedEvents, true); |
823 info.nswindow = window; |
823 info.nswindow = window; |
824 [(NSWindow*) info.nswindow retain]; |
824 [(NSWindow*) info.nswindow retain]; |
825 // When creating a modal session cocoa will rearrange the windows. |
825 int levelBeforeEnterModal = [window level]; |
826 // In order to avoid windows to be put behind another we need to |
|
827 // keep the window level. |
|
828 int level = [window level]; |
|
829 info.session = [NSApp beginModalSessionForWindow:window]; |
826 info.session = [NSApp beginModalSessionForWindow:window]; |
830 [window setLevel:level]; |
827 // Make sure we don't stack the window lower that it was before |
|
828 // entering modal, in case it e.g. had the stays-on-top flag set: |
|
829 if (levelBeforeEnterModal > [window level]) |
|
830 [window setLevel:levelBeforeEnterModal]; |
831 } |
831 } |
832 currentModalSessionCached = info.session; |
832 currentModalSessionCached = info.session; |
|
833 cleanupModalSessionsNeeded = false; |
833 } |
834 } |
834 return currentModalSessionCached; |
835 return currentModalSessionCached; |
835 } |
836 } |
836 |
837 |
837 static void setChildrenWorksWhenModal(QWidget *widget, bool worksWhenModal) |
838 static void setChildrenWorksWhenModal(QWidget *widget, bool worksWhenModal) |
879 int stackSize = cocoaModalSessionStack.size(); |
880 int stackSize = cocoaModalSessionStack.size(); |
880 |
881 |
881 for (int i=stackSize-1; i>=0; --i) { |
882 for (int i=stackSize-1; i>=0; --i) { |
882 QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; |
883 QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; |
883 if (info.widget) { |
884 if (info.widget) { |
|
885 // This session has a widget, and is therefore not marked |
|
886 // as stopped. So just make it current. There might still be other |
|
887 // stopped sessions on the stack, but those will be stopped on |
|
888 // a later "cleanup" call. |
884 currentModalSessionCached = info.session; |
889 currentModalSessionCached = info.session; |
885 break; |
890 break; |
886 } |
891 } |
887 cocoaModalSessionStack.remove(i); |
892 cocoaModalSessionStack.remove(i); |
888 currentModalSessionCached = 0; |
893 currentModalSessionCached = 0; |
924 if (info.widget == widget) { |
929 if (info.widget == widget) { |
925 info.widget = 0; |
930 info.widget = 0; |
926 if (i == stackSize-1) { |
931 if (i == stackSize-1) { |
927 // The top sessions ended. Interrupt the event dispatcher |
932 // The top sessions ended. Interrupt the event dispatcher |
928 // to start spinning the correct session immidiatly: |
933 // to start spinning the correct session immidiatly: |
|
934 currentModalSessionCached = 0; |
929 cleanupModalSessionsNeeded = true; |
935 cleanupModalSessionsNeeded = true; |
930 QEventDispatcherMac::instance()->interrupt(); |
936 QEventDispatcherMac::instance()->interrupt(); |
931 } |
937 } |
932 } |
938 } |
933 } |
939 } |