diff -urN ooo_SRC680_m176_src.orig/vcl/aqua/source/window/salframe.cxx ooo_SRC680_m176_src/vcl/aqua/source/window/salframe.cxx --- ooo_SRC680_m176_src.orig/vcl/aqua/source/window/salframe.cxx 2006-07-13 16:08:38.000000000 +0200 +++ ooo_SRC680_m176_src/vcl/aqua/source/window/salframe.cxx 2006-07-13 16:29:46.000000000 +0200 @@ -950,6 +950,63 @@ fprintf(stderr, "==============================\n"); } +static jmp_buf exitRaelJmpBuf; + +static void ExitRaelEventHandlerProc(EventHandlerCallRef callRef, EventRef event, void *userData) +{ + longjmp(exitRaelJmpBuf, 1); +} + +static OSStatus InstallStandardEventHandlersUsingRAEL() +{ + /* + * This is a hack to workaround missing Carbon API to install the standard + * application event handler (InstallStandardEventHandler() does not work + * on the application target). The only way to install the standard app + * handler is to call RunApplicationEventLoop(), but since we are running + * our own event loop, we'll immediately need to break out of RAEL again: + * we do this via longjmp out of the ExitRaelEventHandlerProc event handler + * called first off from RAEL by posting a high priority dummy event. + * This workaround is derived from a similar approach in Technical Q&A 1061. + */ + enum { kExitRaelEvent = 'ExiT' }; + const EventTypeSpec exitRaelEventType = + { kExitRaelEvent, kExitRaelEvent}; + EventHandlerUPP exitRaelEventHandler; + EventHandlerRef exitRaelEventHandlerRef = NULL; + EventRef exitRaelEvent = NULL; + OSStatus err = memFullErr; + + exitRaelEventHandler = NewEventHandlerUPP( + (EventHandlerProcPtr) ExitRaelEventHandlerProc); + if (exitRaelEventHandler) { + err = InstallEventHandler(GetEventDispatcherTarget(), + exitRaelEventHandler, 1, &exitRaelEventType, NULL, + &exitRaelEventHandlerRef); + } + if (err == noErr) { + err = CreateEvent(NULL, kExitRaelEvent, kExitRaelEvent, + GetCurrentEventTime(), kEventAttributeNone, &exitRaelEvent); + } + if (err == noErr) { + err = PostEventToQueue(GetMainEventQueue(), exitRaelEvent, + kEventPriorityHigh); + } + if (err == noErr) { + if (!setjmp(exitRaelJmpBuf)) { + RunApplicationEventLoop(); + /* This point should never be reached ! */ + fprintf(stderr, "RunApplicationEventLoop exited !\n"); + } + } + + if (exitRaelEvent) ReleaseEvent(exitRaelEvent); + if (exitRaelEventHandlerRef) RemoveEventHandler(exitRaelEventHandlerRef); + if (exitRaelEventHandler) DisposeEventHandlerUPP(exitRaelEventHandler); + + return err; +} + void AquaSalFrame::CreateNewSystemWindow(CarbonWindowRef pParent, ULONG nSalFrameStyle) { DbgWhichSalFrameStyle(nSalFrameStyle); @@ -1014,6 +1071,9 @@ // Cache the size of the content area of the window mnHeight = aContentRect.bottom - aContentRect.top; mnWidth = aContentRect.right - aContentRect.left; + + // FIXME: run only once at the initialization time? + InstallStandardEventHandlersUsingRAEL(); InstallAndRegisterEventHandler(NewEventHandlerUPP(HandleWindowCloseEvent), 1, &cWindowCloseEvent); InstallAndRegisterEventHandler(NewEventHandlerUPP(HandleWindowBoundsChangedEvent), 1, &cWindowBoundsChangedEvent);