2
0
David Rose 19 жил өмнө
parent
commit
27aa0ccc9f

+ 75 - 43
panda/src/osxdisplay/osxGraphicsWindow.cxx

@@ -161,6 +161,13 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
   WindowRef window = NULL;		
   WindowRef window = NULL;		
   GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
   GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
 
 
+  if (osxdisplay_cat.is_spam()) {
+    osxdisplay_cat.spam()
+      << ClockObject::get_global_clock()->get_real_time() 
+      << " event_handler: " << (void *)this << ", " << window << ", "
+      << the_class << ", " << kind << "\n";
+  }
+
   switch (the_class) {
   switch (the_class) {
   case kEventClassMouse:
   case kEventClassMouse:
     result  = handleWindowMouseEvents (myHandler, event);
     result  = handleWindowMouseEvents (myHandler, event);
@@ -169,7 +176,6 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
   case kEventClassWindow:	
   case kEventClassWindow:	
     switch (kind) {
     switch (kind) {
     case kEventWindowCollapsing:
     case kEventWindowCollapsing:
-      cerr << "collapsing\n";
       /*
       /*
       Rect r;
       Rect r;
       GetWindowPortBounds (window, &r);					
       GetWindowPortBounds (window, &r);					
@@ -185,20 +191,8 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
     case kEventWindowClose: // called when window is being closed (close box)
     case kEventWindowClose: // called when window is being closed (close box)
       // This is a message from the window manager indicating that
       // This is a message from the window manager indicating that
       // the user has requested to close the window.
       // the user has requested to close the window.
-      {
-        string close_request_event = get_close_request_event();
-        if (!close_request_event.empty()) {
-          // In this case, the app has indicated a desire to intercept
-          // the request and process it directly.
-          throw_event(close_request_event);
-          result = noErr;
-          
-        } else {
-          // In this case, the default case, the app does not intend
-          // to service the request, so we do by closing the window.
-          close_window();
-        }
-      }
+      user_close_request();
+      result = noErr;
       break;
       break;
     case kEventWindowShown: // called on initial show (not on un-minimize)
     case kEventWindowShown: // called on initial show (not on un-minimize)
       if (window == FrontWindow ())
       if (window == FrontWindow ())
@@ -217,6 +211,28 @@ event_handler(EventHandlerCallRef myHandler, EventRef event) {
   return result;
   return result;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: osxGraphicsWindow::user_close_request
+//       Access: Private
+//  Description: The user has requested to close the window, for
+//               instance with Cmd-W, or by clicking on the close
+//               button.
+////////////////////////////////////////////////////////////////////
+void osxGraphicsWindow::
+user_close_request() {
+  string close_request_event = get_close_request_event();
+  if (!close_request_event.empty()) {
+    // In this case, the app has indicated a desire to intercept
+    // the request and process it directly.
+    throw_event(close_request_event);
+    
+  } else {
+    // In this case, the default case, the app does not intend
+    // to service the request, so we do by closing the window.
+    close_window();
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: osxGraphicsWindow::SystemCloseWindow
 //     Function: osxGraphicsWindow::SystemCloseWindow
 //       Access: private
 //       Access: private
@@ -1129,40 +1145,56 @@ void handleWindowDMEvent (void *userData, short theMessage, void *notifyData)
 	}
 	}
 }
 }
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: osxGraphicsWindow::process_events()
+//     Function: osxGraphicsWindow::handleKeyInput()
 //       Access: virtual, protected
 //       Access: virtual, protected
 //  Description: Required Event upcall . Used to dispatch Window and Aplication Events 
 //  Description: Required Event upcall . Used to dispatch Window and Aplication Events 
 //               back into panda
 //               back into panda
 //               
 //               
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 // key input handler
 // key input handler
-OSStatus osxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown)
-{
-	OSStatus result = eventNotHandledErr;
-
-	result = CallNextEventHandler(myHandler, event);	
-	if (eventNotHandledErr == result) 
-	{ 
-			UInt32 newModifiers = 0;
-			OSStatus error = GetEventParameter(event, kEventParamKeyModifiers,typeUInt32, NULL,sizeof(UInt32), NULL, &newModifiers);
-			if(error == noErr)						   
-				HandleModifireDeleta(newModifiers);
-	
-			UInt32 keyCode;
-			GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
-			if(keyDown)
-			{
-			  SendKeyEvent(OSX_TranslateKey( keyCode , event ),true);
-			  result = noErr; 
-			}
-			else
-			{
-			  SendKeyEvent(OSX_TranslateKey( keyCode , event ),false);
-			  result = noErr; 
-			}
-	}	
-			
-	return result;
+OSStatus osxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown) {
+  OSStatus result = eventNotHandledErr;
+
+  if (osxdisplay_cat.is_spam()) {
+    UInt32 keyCode;
+    GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
+
+    osxdisplay_cat.spam()
+      << ClockObject::get_global_clock()->get_real_time() 
+      << " handleKeyInput: " << (void *)this << ", " << keyCode << "\n";
+  }
+  
+  result = CallNextEventHandler(myHandler, event);	
+  if (eventNotHandledErr == result) { 
+    UInt32 newModifiers = 0;
+    OSStatus error = GetEventParameter(event, kEventParamKeyModifiers,typeUInt32, NULL,sizeof(UInt32), NULL, &newModifiers);
+    if(error == noErr) {						   
+      HandleModifireDeleta(newModifiers);
+    }
+    
+    UInt32 keyCode;
+    GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
+    ButtonHandle button = OSX_TranslateKey(keyCode, event);
+
+    if (keyDown) {
+      if ((newModifiers & cmdKey) != 0) {
+        if (button == KeyboardButton::ascii_key("q") ||
+            button == KeyboardButton::ascii_key("w")) {
+          // Command-Q or Command-W: quit the application or close the
+          // window, respectively.  For now, we treat them both the
+          // same: close the window.
+          user_close_request();
+        }
+      }
+      SendKeyEvent(button, true);
+      result = noErr; 
+    } else {
+      SendKeyEvent(button, false);
+      result = noErr; 
+    }
+  }	
+  
+  return result;
 }
 }
  ////////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////
  //     Function: 
  //     Function: 

+ 1 - 0
panda/src/osxdisplay/osxGraphicsWindow.h

@@ -90,6 +90,7 @@ public: // do not call direct ..
 
 
   OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
   OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
 
 
+  virtual void user_close_request();
   void SystemCloseWindow();
   void SystemCloseWindow();
   void SystemSetWindowForground(bool forground);	
   void SystemSetWindowForground(bool forground);	
   void SystemPointToLocalPoint(Point &qdGlobalPoint);
   void SystemPointToLocalPoint(Point &qdGlobalPoint);