]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
Must call DoMoveWindow in Create() or buttons may not be
[wxWidgets.git] / src / mac / carbon / app.cpp
index 1af5aa871fc86c6651f16618c7b8d4a55ce34c6d..fd5c1b0d4f27084b82632c002cd13d8efb791a49 100644 (file)
@@ -288,6 +288,9 @@ void wxApp::MacNewFile()
         { kEventClassCommand, kEventProcessCommand } ,
         { kEventClassCommand, kEventCommandUpdateStatus } ,
 
+        { kEventClassMenu, kEventMenuOpening },
+        { kEventClassMenu, kEventMenuClosed },
+
         { kEventClassApplication , kEventAppActivated } ,
         { kEventClassApplication , kEventAppDeactivated } ,
         // handling the quit event is not recommended by apple
@@ -299,9 +302,35 @@ void wxApp::MacNewFile()
         { 'WXMC' , 'WXMC' }
     } ;
 
-static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+static pascal OSStatus
+MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
 {
-    return eventNotHandledErr ;
+    // FIXME: this doesn't work for multiple windows
+    wxWindow *win = wxTheApp->GetTopWindow();
+    if ( win )
+    {
+        // VZ: we could find the menu from its handle here by examining all
+        //     the menus in the menu bar recursively but knowing that neither
+        //     wxMSW nor wxGTK do it why bother...
+#if 0
+        MenuRef menuRef;
+
+        GetEventParameter(event,
+                          kEventParamDirectObject,
+                          typeMenuRef, NULL,
+                          sizeof(menuRef), NULL,
+                          &menuRef);
+#endif // 0
+
+        wxMenuEvent wxevent(GetEventKind(event) == kEventMenuOpening
+                        ? wxEVT_MENU_OPEN
+                        : wxEVT_MENU_CLOSE);
+        wxevent.SetEventObject(win);
+
+        (void)win->GetEventHandler()->ProcessEvent(wxevent);
+    }
+
+    return eventNotHandledErr;
 }
 
 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
@@ -941,12 +970,6 @@ pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , Even
 
 wxApp::wxApp()
 {
-  m_topWindow = NULL;
-  wxTheApp = this;
-
-  argc = 0;
-  argv = NULL;
-
   m_printMode = wxPRINT_WINDOWS;
   m_auto3D = TRUE;
 }
@@ -996,33 +1019,13 @@ void wxApp::Dispatch()
 
 void wxApp::OnIdle(wxIdleEvent& event)
 {
-    // Avoid recursion (via ProcessEvent default case)
-    if ( s_inOnIdle )
-        return;
-
-
-  s_inOnIdle = TRUE;
-
-  // 'Garbage' collection of windows deleted with Close().
-  DeletePendingObjects();
-
-  // flush the logged messages if any
-  wxLog *pLog = wxLog::GetActiveTarget();
-  if ( pLog != NULL && pLog->HasPendingMessages() )
-    pLog->Flush();
-
-  // Send OnIdle events to all windows
-  bool needMore = SendIdleEvents();
-
-  if (needMore)
-    event.RequestMore(TRUE);
-
+    wxAppBase::OnIdle(event);
+    
     // If they are pending events, we must process them: pending events are
     // either events to the threads other than main or events posted with
     // wxPostEvent() functions
     wxMacProcessNotifierAndPendingEvents();
 
-  s_inOnIdle = FALSE;
   if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
     wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
 }