Changeset 30114 in vbox for trunk/src/VBox
- Timestamp:
- Jun 9, 2010 12:40:16 PM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r30023 r30114 523 523 VirtualBox_DEFS += VBOX_DARWIN_USE_NATIVE_CONTROLS 524 524 VirtualBox_SOURCES.darwin += \ 525 src/darwin/ VBoxCocoaApplication.m \525 src/darwin/UICocoaApplication.mm \ 526 526 src/darwin/VBoxUtils-darwin-cocoa.mm \ 527 527 src/darwin/VBoxCocoaSpecialControls.mm … … 850 850 src/darwin/DarwinKeyboard.cpp 851 851 tstDarwinKeyboard_SOURCES.amd64 = \ 852 src/darwin/ VBoxCocoaApplication.m852 src/darwin/UICocoaApplication.mm 853 853 tstDarwinKeyboard_LDFLAGS = -framework IOKit -framework Carbon -framework AppKit 854 854 tstDarwinKeyboard_LIBS = \ -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/DarwinKeyboard.cpp
r28800 r30114 1 /* $Id$ */ 1 2 /** @file 2 3 * Common GUI Library - Darwin Keyboard routines. … … 44 45 45 46 #ifndef USE_HID_FOR_MODIFIERS 46 # include "VBox CocoaApplication.h"47 # include "VBoxUtils-darwin.h" 47 48 #endif 48 49 … … 986 987 */ 987 988 AssertPtr(pvCocoaEvent); 988 // VBoxCocoaApplication_printEvent("dbg-adjMods: ", pvCocoaEvent);989 uint32_t fAltModifiers = VBoxCocoaApplication_getEventModifierFlagsXlated(pvCocoaEvent);989 //::darwinPrintEvent("dbg-adjMods: ", pvCocoaEvent); 990 uint32_t fAltModifiers = ::darwinEventModifierFlagsXlated(pvCocoaEvent); 990 991 991 992 #else /* USE_HID_FOR_MODIFIERS */ -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaApplication.h
r30085 r30114 1 /* $Id$ */2 1 /** @file 3 * VBoxCocoaApplication - NSApplication subclassfor handling -sendEvent.2 * UICocoaApplication - C++ interface to NSApplication for handling -sendEvent. 4 3 */ 5 4 6 5 /* 7 * Copyright (C) 2009 Oracle Corporation6 * Copyright (C) 2009-2010 Oracle Corporation 8 7 * 9 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 18 #define ___darwin_VBoxCocoaApplication_h 20 19 21 #include <iprt/cdefs.h> 22 #ifdef __OBJC__ 23 # import <AppKit/NSApplication.h> 24 #endif 25 26 RT_C_DECLS_BEGIN 20 #include "VBoxCocoaHelper.h" 21 ADD_COCOA_NATIVE_REF(UICocoaApplicationPrivate); 22 ADD_COCOA_NATIVE_REF(NSAutoreleasePool); 27 23 28 24 /** Event handler callback. … … 34 30 typedef bool (*PFNVBOXCACALLBACK)(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser); 35 31 32 /* C++ singleton for our private NSApplication object */ 33 class UICocoaApplication 34 { 35 public: 36 static UICocoaApplication* instance(); 37 ~UICocoaApplication(); 36 38 37 #ifdef __OBJC__ 39 void registerForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser); 40 void unregisterForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser); 38 41 39 /** Structure for tracking a callback. */ 40 typedef struct VBOXCAENTRY 41 { 42 /** Mask of events to send to this callback. */ 43 uint32_t fMask; 44 /** The callback. */ 45 PFNVBOXCACALLBACK pfnCallback; 46 /** The user argument. */ 47 void *pvUser; 48 } VBOXCAENTRY; 49 typedef VBOXCAENTRY *PVBOXCAENTRY; 50 typedef VBOXCAENTRY const *PCVBOXCAENTRY; 42 private: 43 UICocoaApplication(); 44 static UICocoaApplication *m_pInstance; 45 NativeUICocoaApplicationPrivateRef m_pNative; 46 NativeNSAutoreleasePoolRef m_pPool; 47 }; 51 48 49 #endif /* ___darwin_VBoxCocoaApplication_h */ 52 50 53 /**54 * Subclass for intercepting sendEvent messages.55 */56 @interface VBoxCocoaApplication : NSApplication57 {58 /** The event mask for which there currently are callbacks. */59 uint32_t m_fMask;60 /** The number of current callbacks. */61 uint32_t m_cCallbacks;62 /** Array of callbacks. */63 VBOXCAENTRY m_aCallbacks[4];64 }65 - (void)sendEvent:(NSEvent *)theEvent;66 - (void)setCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;67 - (void)unsetCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;68 69 @end /* @interface VBoxCocoaApplication */70 71 extern VBoxCocoaApplication *g_pVBoxCocoaApp;72 73 #endif /* __OBJC__ */74 75 /** @name The C/C++ interface.76 *77 * @remarks This is a bit illogical as both NSApplication and NSEvent stuff78 * ended up here...79 * @{80 */81 void VBoxCocoaApplication_sharedApplication(void);82 void VBoxCocoaApplication_setCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);83 void VBoxCocoaApplication_unsetCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);84 unsigned long VBoxCocoaApplication_getEventModifierFlags(const void *pvEvent);85 uint32_t VBoxCocoaApplication_getEventModifierFlagsXlated(const void *pvEvent);86 void VBoxCocoaApplication_setMouseCoalescingEnabled(bool fEnabled);87 const char *VBoxCocoaApplication_eventTypeName(unsigned long eEvtType);88 bool VBoxCocoaApplication_isApplicationCommand(const void *pvEvent);89 void VBoxCocoaApplication_printEvent(const char *pszPrefix, const void *pvEvent);90 /** @} */91 92 RT_C_DECLS_END93 94 #endif95 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaApplication.mm
r30085 r30114 1 1 /* $Id$ */ 2 2 /** @file 3 * VBoxCocoaApplication - NSApplication subclassfor handling -sendEvent.3 * UICocoaApplication - C++ interface to NSApplication for handling -sendEvent. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009 Oracle Corporation7 * Copyright (C) 2009-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 /******************************************************************************* 19 * Header Files * 20 *******************************************************************************/ 21 #include "VBoxCocoaApplication.h" 22 #include "DarwinKeyboard.h" 18 /* Local includes */ 19 #include "UICocoaApplication.h" 20 #include "VBoxUtils-darwin.h" 21 22 /* Global includes */ 23 #import <AppKit/NSEvent.h> 24 #import <AppKit/NSApplication.h> 25 #import <Foundation/NSArray.h> 26 23 27 #include <iprt/assert.h> 24 #import <AppKit/NSWindow.h> 25 #import <AppKit/NSEvent.h> 26 27 #include <Carbon/Carbon.h> 28 29 #include <stdio.h> 30 31 32 /******************************************************************************* 33 * Global Variables * 34 *******************************************************************************/ 35 /** Pointer to the VBoxCocoaApplication instance. 36 * This is also available thru NSApp, but this way there is no need to cast any thing. 37 */ 38 VBoxCocoaApplication *g_pVBoxCocoaApp = NULL; 39 40 @implementation VBoxCocoaApplication 41 42 28 29 /** Class for tracking a callback. */ 30 @interface CallbackData: NSObject 31 { 32 @public 33 /** Mask of events to send to this callback. */ 34 uint32_t fMask; 35 /** The callback. */ 36 PFNVBOXCACALLBACK pfnCallback; 37 /** The user argument. */ 38 void *pvUser; 39 } 40 - (id) initWithMask:(uint32)mask callback:(PFNVBOXCACALLBACK)callback user:(void*)user; 41 @end /* @interface CallbackData */ 42 43 @implementation CallbackData 44 - (id) initWithMask:(uint32)mask callback:(PFNVBOXCACALLBACK)callback user:(void*)user 45 { 46 self = [super init]; 47 if (self) 48 { 49 fMask = mask; 50 pfnCallback = callback; 51 pvUser = user; 52 } 53 return self; 54 } 55 @end /* @implementation CallbackData */ 56 57 /** Class for event handling */ 58 @interface UICocoaApplicationPrivate: NSApplication 59 { 60 /** The event mask for which there currently are callbacks. */ 61 uint32_t m_fMask; 62 /** Array of callbacks. */ 63 NSMutableArray *m_pCallbacks; 64 } 65 - (id)init; 66 - (void)sendEvent:(NSEvent *)theEvent; 67 - (void)setCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser; 68 - (void)unsetCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser; 69 @end /* @interface UICocoaApplicationPrivate */ 70 71 @implementation UICocoaApplicationPrivate 43 72 -(id) init 44 73 { 45 74 self = [super init]; 46 self->m_cCallbacks = 0; 75 if (self) 76 m_pCallbacks = [[NSMutableArray alloc] init]; 77 47 78 return self; 48 79 } 49 50 80 51 81 -(void) sendEvent:(NSEvent *)pEvent … … 54 84 * Check if the type matches any of the registered callbacks. 55 85 */ 56 uint32_t const fMask = self->m_fMask;86 uint32_t const fMask = m_fMask; 57 87 #if 0 /* for debugging */ 58 VBoxCocoaApplication_printEvent("sendEvent: ", pEvent);88 ::darwinPrintEvent("sendEvent: ", pEvent); 59 89 #endif 60 90 if (fMask != 0) 61 91 { 62 92 NSEventType EvtType = [pEvent type]; 63 uint32_t 93 uint32_t fEvtMask = RT_LIKELY(EvtType < 32) ? RT_BIT_32(EvtType) : 0; 64 94 if (fMask & fEvtMask) 65 95 { … … 67 97 * Do the callouts in LIFO order. 68 98 */ 69 int i = self->m_cCallbacks; 70 PCVBOXCAENTRY pCur = &self->m_aCallbacks[i]; 71 while (i-- > 0) 99 for (CallbackData *pData in [m_pCallbacks reverseObjectEnumerator]) 72 100 { 73 pCur--; 74 if (pCur->fMask & fEvtMask) 101 if (pData->fMask & fEvtMask) 75 102 { 76 if (p Cur->pfnCallback(pEvent, [pEvent eventRef], pCur->pvUser))103 if (pData->pfnCallback(pEvent, [pEvent eventRef], pData->pvUser)) 77 104 return; 78 105 } 106 79 107 } 80 108 } … … 86 114 [super sendEvent:pEvent]; 87 115 } 88 89 116 90 117 /** … … 97 124 -(void) setCallback: (uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser 98 125 { 99 unsigned i = self->m_cCallbacks; 100 AssertReleaseReturnVoid(i < RT_ELEMENTS(self->m_aCallbacks)); 101 102 self->m_aCallbacks[i].pfnCallback = pfnCallback; 103 self->m_aCallbacks[i].pvUser = pvUser; 104 self->m_aCallbacks[i].fMask = fMask; 105 self->m_cCallbacks++; 106 self->m_fMask |= fMask; 107 } 108 126 /* Add the callback data to the array */ 127 CallbackData *pData = [[[CallbackData alloc] initWithMask: fMask callback: pfnCallback user: pvUser] autorelease]; 128 [m_pCallbacks addObject: pData]; 129 130 /* Update the global mask */ 131 m_fMask |= fMask; 132 } 109 133 110 134 /** … … 120 144 * Loop the event array LIFO fashion searching for a matching callback. 121 145 */ 122 int i = self->m_cCallbacks; 123 while (i-- > 0) 146 for (CallbackData *pData in [m_pCallbacks reverseObjectEnumerator]) 124 147 { 125 if ( self->m_aCallbacks[i].pfnCallback == pfnCallback126 && self->m_aCallbacks[i].pvUser == pvUser127 && self->m_aCallbacks[i].fMask == fMask)148 if ( pData->pfnCallback == pfnCallback 149 && pData->pvUser == pvUser 150 && pData->fMask == fMask) 128 151 { 129 uint32_t fNewMask; 130 131 if (i + 1 != (int)self->m_cCallbacks) 132 self->m_aCallbacks[i] = self->m_aCallbacks[self->m_cCallbacks - 1]; 133 self->m_cCallbacks--; 134 135 /* 136 * Recalculate the event type mask. 137 */ 138 fNewMask = 0; 139 i = self->m_cCallbacks; 140 while (i-- > 0) 141 fNewMask |= self->m_aCallbacks[i].fMask; 142 self->m_fMask = fNewMask; 143 return; 152 [m_pCallbacks removeObject: pData]; 153 break; 144 154 } 145 155 } 146 AssertFailed(); 147 } 148 149 150 @end /* @implementation VBoxCocoaApplication */ 151 152 153 /** 154 * C/C++ interface for calling VBoxCocoaApplication::sharedApplication. 155 * 156 */ 157 void VBoxCocoaApplication_sharedApplication(void) 158 { 159 if (!g_pVBoxCocoaApp) 160 { 161 /* 162 * It is essential that we use the inherited sharedApplication class 163 * method, otherwise we'll be screwed later by static variables in it. 164 */ 165 NSApplication *pApp = [VBoxCocoaApplication sharedApplication]; 166 g_pVBoxCocoaApp = (VBoxCocoaApplication *)pApp; 167 } 168 } 169 170 171 /** 172 * Register an event callback. 173 * 174 * @param fMask The event mask for which the callback is to be invoked. 175 * @param pfnCallback The callback function. 176 * @param pvUser The user argument. 177 */ 178 void VBoxCocoaApplication_setCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser) 179 { 180 [g_pVBoxCocoaApp setCallback:fMask :pfnCallback :pvUser]; 181 } 182 183 184 /** 185 * Deregister an event callback. 186 * 187 * @param fMask Same as setCallback. 188 * @param pfnCallback Same as setCallback. 189 * @param pvUser Same as setCallback. 190 */ 191 void VBoxCocoaApplication_unsetCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser) 192 { 193 [g_pVBoxCocoaApp unsetCallback:fMask :pfnCallback :pvUser]; 194 } 195 196 197 /** 198 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object. 199 * 200 * @return The Cocoa event modifier mask. 201 * @param pvEvent The NSEvent object. 202 */ 203 unsigned long VBoxCocoaApplication_getEventModifierFlags(const void *pvEvent) 204 { 205 NSEvent *pEvent = (NSEvent *)pvEvent; 206 return [pEvent modifierFlags]; 207 } 208 209 210 /** 211 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object and 212 * converts the flags to carbon style. 213 * 214 * @return The Carbon modifier mask. 215 * @param pvEvent The NSEvent object. 216 */ 217 uint32_t VBoxCocoaApplication_getEventModifierFlagsXlated(const void *pvEvent) 218 { 219 NSEvent *pEvent = (NSEvent *)pvEvent; 220 NSUInteger fCocoa = [pEvent modifierFlags]; 221 uint32_t fCarbon = 0; 222 if (fCocoa) 223 { 224 if (fCocoa & NSAlphaShiftKeyMask) 225 fCarbon |= alphaLock; 226 if (fCocoa & (NSShiftKeyMask | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK)) 227 { 228 if (fCocoa & (NX_DEVICERSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK)) 229 { 230 if (fCocoa & NX_DEVICERSHIFTKEYMASK) 231 fCarbon |= rightShiftKey; 232 if (fCocoa & NX_DEVICELSHIFTKEYMASK) 233 fCarbon |= shiftKey; 234 } 235 else 236 fCarbon |= shiftKey; 237 } 238 239 if (fCocoa & (NSControlKeyMask | NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK)) 240 { 241 if (fCocoa & (NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK)) 242 { 243 if (fCocoa & NX_DEVICERCTLKEYMASK) 244 fCarbon |= rightControlKey; 245 if (fCocoa & NX_DEVICELCTLKEYMASK) 246 fCarbon |= controlKey; 247 } 248 else 249 fCarbon |= controlKey; 250 } 251 252 if (fCocoa & (NSAlternateKeyMask | NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK)) 253 { 254 if (fCocoa & (NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK)) 255 { 256 if (fCocoa & NX_DEVICERALTKEYMASK) 257 fCarbon |= rightOptionKey; 258 if (fCocoa & NX_DEVICELALTKEYMASK) 259 fCarbon |= optionKey; 260 } 261 else 262 fCarbon |= optionKey; 263 } 264 265 if (fCocoa & (NSCommandKeyMask | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK)) 266 { 267 if (fCocoa & (NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK)) 268 { 269 if (fCocoa & NX_DEVICERCMDKEYMASK) 270 fCarbon |= kEventKeyModifierRightCmdKeyMask; 271 if (fCocoa & NX_DEVICELCMDKEYMASK) 272 fCarbon |= cmdKey; 273 } 274 else 275 fCarbon |= cmdKey; 276 } 277 278 /* 279 if (fCocoa & NSNumericPadKeyMask) 280 fCarbon |= ???; 281 282 if (fCocoa & NSHelpKeyMask) 283 fCarbon |= ???; 284 285 if (fCocoa & NSFunctionKeyMask) 286 fCarbon |= ???; 287 */ 288 } 289 290 return fCarbon; 291 } 292 293 294 /** 295 * Get the name for a Cocoa event type. 296 * 297 * @returns Read-only name string. 298 * @param eEvtType The Cocoa event type. 299 */ 300 const char *VBoxCocoaApplication_eventTypeName(unsigned long eEvtType) 301 { 302 switch (eEvtType) 303 { 304 #define EVT_CASE(nm) case nm: return #nm 305 EVT_CASE(NSLeftMouseDown); 306 EVT_CASE(NSLeftMouseUp); 307 EVT_CASE(NSRightMouseDown); 308 EVT_CASE(NSRightMouseUp); 309 EVT_CASE(NSMouseMoved); 310 EVT_CASE(NSLeftMouseDragged); 311 EVT_CASE(NSRightMouseDragged); 312 EVT_CASE(NSMouseEntered); 313 EVT_CASE(NSMouseExited); 314 EVT_CASE(NSKeyDown); 315 EVT_CASE(NSKeyUp); 316 EVT_CASE(NSFlagsChanged); 317 EVT_CASE(NSAppKitDefined); 318 EVT_CASE(NSSystemDefined); 319 EVT_CASE(NSApplicationDefined); 320 EVT_CASE(NSPeriodic); 321 EVT_CASE(NSCursorUpdate); 322 EVT_CASE(NSScrollWheel); 323 EVT_CASE(NSTabletPoint); 324 EVT_CASE(NSTabletProximity); 325 EVT_CASE(NSOtherMouseDown); 326 EVT_CASE(NSOtherMouseUp); 327 EVT_CASE(NSOtherMouseDragged); 328 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 329 EVT_CASE(NSEventTypeGesture); 330 EVT_CASE(NSEventTypeMagnify); 331 EVT_CASE(NSEventTypeSwipe); 332 EVT_CASE(NSEventTypeRotate); 333 EVT_CASE(NSEventTypeBeginGesture); 334 EVT_CASE(NSEventTypeEndGesture); 335 #endif 336 #undef EVT_CASE 337 default: 338 return "Unknown!"; 339 } 340 } 341 342 /** 343 * Check for some default application key combinations a Mac user expect, like 344 * CMD+Q or CMD+H. 345 * 346 * @returns true if such a key combo was hit, false otherwise. 347 * @param eEvtType The Cocoa event type. 348 */ 349 bool VBoxCocoaApplication_isApplicationCommand(const void *pvEvent) 350 { 351 NSEvent *pEvent = (NSEvent *)pvEvent; 352 NSEventType eEvtType = [pEvent type]; 353 bool fGlobalHotkey = false; 354 355 switch (eEvtType) 356 { 357 case NSKeyDown: 358 case NSKeyUp: 359 { 360 NSUInteger fEvtMask = [pEvent modifierFlags]; 361 unsigned short KeyCode = [pEvent keyCode]; 362 if ( ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) /* L+CMD */ 363 || ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK))) /* R+CMD */ 364 { 365 if ( KeyCode == 0x0c /* CMD+Q (Quit) */ 366 || KeyCode == 0x04) /* CMD+H (Hide) */ 367 fGlobalHotkey = true; 368 } 369 else if ( ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) /* L+ALT+CMD */ 370 || ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK))) /* R+ALT+CMD */ 371 { 372 if (KeyCode == 0x04) /* ALT+CMD+H (Hide-Others) */ 373 fGlobalHotkey = true; 374 } 375 break; 376 } 377 default: break; 378 } 379 return fGlobalHotkey; 380 } 381 382 /** 383 * Debug helper function for dumping a Cocoa event to stdout. 384 * 385 * @param pszPrefix Message prefix. 386 * @param pvEvent The Cocoa event. 387 */ 388 void VBoxCocoaApplication_printEvent(const char *pszPrefix, const void *pvEvent) 389 { 390 NSEvent *pEvent = (NSEvent *)pvEvent; 391 NSEventType eEvtType = [pEvent type]; 392 NSUInteger fEvtMask = [pEvent modifierFlags]; 393 NSWindow *pEvtWindow = [pEvent window]; 394 NSInteger iEvtWindow = [pEvent windowNumber]; 395 NSGraphicsContext *pEvtGraphCtx = [pEvent context]; 396 397 printf("%s%p: Type=%lu Modifiers=%08lx pWindow=%p #Wnd=%ld pGraphCtx=%p %s\n", 398 pszPrefix, pvEvent, (unsigned long)eEvtType, (unsigned long)fEvtMask, (void*)pEvtWindow, 399 (long)iEvtWindow, (void*)pEvtGraphCtx, VBoxCocoaApplication_eventTypeName(eEvtType)); 400 401 /* dump type specific into. */ 402 switch (eEvtType) 403 { 404 case NSLeftMouseDown: 405 case NSLeftMouseUp: 406 case NSRightMouseDown: 407 case NSRightMouseUp: 408 case NSMouseMoved: 409 410 case NSLeftMouseDragged: 411 case NSRightMouseDragged: 412 case NSMouseEntered: 413 case NSMouseExited: 414 break; 415 416 case NSKeyDown: 417 case NSKeyUp: 418 { 419 NSUInteger i; 420 NSUInteger cch; 421 NSString *pChars = [pEvent characters]; 422 NSString *pCharsIgnMod = [pEvent charactersIgnoringModifiers]; 423 BOOL fIsARepeat = [pEvent isARepeat]; 424 unsigned short KeyCode = [pEvent keyCode]; 425 426 printf(" KeyCode=%04x isARepeat=%d", KeyCode, fIsARepeat); 427 if (pChars) 428 { 429 cch = [pChars length]; 430 printf(" characters={"); 431 for (i = 0; i < cch; i++) 432 printf(i == 0 ? "%02x" : ",%02x", [pChars characterAtIndex: i]); 433 printf("}"); 434 } 435 436 if (pCharsIgnMod) 437 { 438 cch = [pCharsIgnMod length]; 439 printf(" charactersIgnoringModifiers={"); 440 for (i = 0; i < cch; i++) 441 printf(i == 0 ? "%02x" : ",%02x", [pCharsIgnMod characterAtIndex: i]); 442 printf("}"); 443 } 444 printf("\n"); 445 break; 446 } 447 448 case NSFlagsChanged: 449 { 450 NSUInteger fOddBits = NSAlphaShiftKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask 451 | NSCommandKeyMask | NSNumericPadKeyMask | NSHelpKeyMask | NSFunctionKeyMask 452 | NX_DEVICELCTLKEYMASK | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK 453 | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK | NX_DEVICELALTKEYMASK 454 | NX_DEVICERALTKEYMASK | NX_DEVICERCTLKEYMASK; 455 456 printf(" KeyCode=%04x", (int)[pEvent keyCode]); 457 #define PRINT_MOD(cnst, nm) do { if (fEvtMask & (cnst)) printf(" %s", #nm); } while (0) 458 /* device-independent: */ 459 PRINT_MOD(NSAlphaShiftKeyMask, "AlphaShift"); 460 PRINT_MOD(NSShiftKeyMask, "Shift"); 461 PRINT_MOD(NSControlKeyMask, "Ctrl"); 462 PRINT_MOD(NSAlternateKeyMask, "Alt"); 463 PRINT_MOD(NSCommandKeyMask, "Cmd"); 464 PRINT_MOD(NSNumericPadKeyMask, "NumLock"); 465 PRINT_MOD(NSHelpKeyMask, "Help"); 466 PRINT_MOD(NSFunctionKeyMask, "Fn"); 467 /* device-dependent (sort of): */ 468 PRINT_MOD(NX_DEVICELCTLKEYMASK, "$L-Ctrl"); 469 PRINT_MOD(NX_DEVICELSHIFTKEYMASK, "$L-Shift"); 470 PRINT_MOD(NX_DEVICERSHIFTKEYMASK, "$R-Shift"); 471 PRINT_MOD(NX_DEVICELCMDKEYMASK, "$L-Cmd"); 472 PRINT_MOD(NX_DEVICERCMDKEYMASK, "$R-Cmd"); 473 PRINT_MOD(NX_DEVICELALTKEYMASK, "$L-Alt"); 474 PRINT_MOD(NX_DEVICERALTKEYMASK, "$R-Alt"); 475 PRINT_MOD(NX_DEVICERCTLKEYMASK, "$R-Ctrl"); 476 #undef PRINT_MOD 477 478 fOddBits = fEvtMask & ~fOddBits; 479 if (fOddBits) 480 printf(" fOddBits=%#08lx", (unsigned long)fOddBits); 481 #undef KNOWN_BITS 482 printf("\n"); 483 break; 484 } 485 486 case NSAppKitDefined: 487 case NSSystemDefined: 488 case NSApplicationDefined: 489 case NSPeriodic: 490 case NSCursorUpdate: 491 case NSScrollWheel: 492 case NSTabletPoint: 493 case NSTabletProximity: 494 case NSOtherMouseDown: 495 case NSOtherMouseUp: 496 case NSOtherMouseDragged: 497 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 498 case NSEventTypeGesture: 499 case NSEventTypeMagnify: 500 case NSEventTypeSwipe: 501 case NSEventTypeRotate: 502 case NSEventTypeBeginGesture: 503 case NSEventTypeEndGesture: 504 #endif 505 default: 506 printf(" Unknown!\n"); 507 break; 508 } 509 510 } 511 156 uint32_t fNewMask = 0; 157 for (CallbackData *pData in m_pCallbacks) 158 fNewMask |= pData->fMask; 159 m_fMask = fNewMask; 160 } 161 @end /* @implementation UICocoaApplicationPrivate */ 162 163 /* C++ singleton for our private NSApplication object */ 164 UICocoaApplication* UICocoaApplication::m_pInstance = 0; 165 166 /* static */ 167 UICocoaApplication* UICocoaApplication::instance() 168 { 169 if (!m_pInstance) 170 m_pInstance = new UICocoaApplication(); 171 172 return m_pInstance; 173 } 174 175 UICocoaApplication::UICocoaApplication() 176 { 177 /* Make sure our private NSApplication object is created */ 178 m_pNative = (UICocoaApplicationPrivate*)[UICocoaApplicationPrivate sharedApplication]; 179 /* Create one auto release pool which is in place for all the 180 initialization and deinitialization stuff. That is when the 181 NSApplication is not running the run loop (there is a separate auto 182 release pool defined). */ 183 m_pPool = [[NSAutoreleasePool alloc] init]; 184 } 185 186 UICocoaApplication::~UICocoaApplication() 187 { 188 [m_pNative release]; 189 [m_pPool release]; 190 } 191 192 void UICocoaApplication::registerForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser) 193 { 194 [m_pNative setCallback:fMask :pfnCallback :pvUser]; 195 } 196 197 void UICocoaApplication::unregisterForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser) 198 { 199 [m_pNative unsetCallback:fMask :pfnCallback :pvUser]; 200 } 201 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaHelper.h
r28800 r30114 22 22 /* Macro which add a typedef of the given Cocoa class in an appropriate form 23 23 * for the current context. This means void* in the C/CPP context and 24 * NSWhatever* in the ObjC/ObjCPP context. Use NativeNSWhateverRef when you 25 * reference the Cocoa type somewhere. The use of this prevents extensive 26 * casting of void* to the right type in the Cocoa context. */ 24 * NSWhatever* in the ObjC/ObjCPP context. Use 25 * NativeNSWhateverRef/ConstNativeNSWhateverRef when you reference the Cocoa 26 * type somewhere. The use of this prevents extensive casting of void* to the 27 * right type in the Cocoa context. */ 27 28 #ifdef __OBJC__ 28 29 #define ADD_COCOA_NATIVE_REF(CocoaClass) \ 29 30 @class CocoaClass; \ 30 typedef CocoaClass *Native##CocoaClass##Ref 31 typedef CocoaClass *Native##CocoaClass##Ref; \ 32 typedef const CocoaClass *ConstNative##CocoaClass##Ref 31 33 #else /* __OBJC__ */ 32 #define ADD_COCOA_NATIVE_REF(CocoaClass) typedef void *Native##CocoaClass##Ref 34 #define ADD_COCOA_NATIVE_REF(CocoaClass) \ 35 typedef void *Native##CocoaClass##Ref; \ 36 typedef const void *ConstNative##CocoaClass##Ref 33 37 #endif /* __OBJC__ */ 34 38 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm
r30022 r30114 30 30 #import <AppKit/NSFont.h> 31 31 32 NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView) 33 { 34 CocoaAutoreleasePool pool; 35 32 /* For the keyboard stuff */ 33 #include <Carbon/Carbon.h> 34 #include "DarwinKeyboard.h" 35 36 NativeWindowRef darwinToNativeWindowImpl(NativeViewRef aView) 37 { 36 38 NativeWindowRef window = NULL; 37 39 if (aView) … … 41 43 } 42 44 43 NativeViewRef darwinToNativeViewImpl (NativeWindowRef aWindow) 44 { 45 CocoaAutoreleasePool pool; 46 45 NativeViewRef darwinToNativeViewImpl(NativeWindowRef aWindow) 46 { 47 47 NativeViewRef view = NULL; 48 48 if (aWindow) … … 52 52 } 53 53 54 void darwinSetShowsToolbarButtonImpl (NativeWindowRef aWindow, bool aEnabled) 55 { 56 CocoaAutoreleasePool pool; 57 54 void darwinSetShowsToolbarButtonImpl(NativeWindowRef aWindow, bool aEnabled) 55 { 58 56 [aWindow setShowsToolbarButton:aEnabled]; 59 57 } 60 58 61 void darwinSetShowsResizeIndicatorImpl (NativeWindowRef aWindow, bool aEnabled) 62 { 63 CocoaAutoreleasePool pool; 64 59 void darwinSetShowsResizeIndicatorImpl(NativeWindowRef aWindow, bool aEnabled) 60 { 65 61 [aWindow setShowsResizeIndicator:aEnabled]; 66 62 } 67 63 68 void darwinSetHidesAllTitleButtonsImpl (NativeWindowRef aWindow) 69 { 70 CocoaAutoreleasePool pool; 71 64 void darwinSetHidesAllTitleButtonsImpl(NativeWindowRef aWindow) 65 { 72 66 /* Remove all title buttons by changing the style mask. This method is 73 67 available from 10.6 on only. */ … … 94 88 } 95 89 96 void darwinSetShowsWindowTransparentImpl (NativeWindowRef aWindow, bool aEnabled) 97 { 98 CocoaAutoreleasePool pool; 99 90 void darwinSetShowsWindowTransparentImpl(NativeWindowRef aWindow, bool aEnabled) 91 { 100 92 if (aEnabled) 101 93 { … … 114 106 void darwinSetDockIconMenu(QMenu* pMenu) 115 107 { 116 CocoaAutoreleasePool pool;117 118 108 extern void qt_mac_set_dock_menu(QMenu *); 119 109 qt_mac_set_dock_menu(pMenu); … … 125 115 * @param fEnabled Whether to enable or disable coalescing. 126 116 */ 127 void darwinSetMouseCoalescingEnabled (bool aEnabled) 128 { 129 CocoaAutoreleasePool pool; 130 117 void darwinSetMouseCoalescingEnabled(bool aEnabled) 118 { 131 119 [NSEvent setMouseCoalescingEnabled:aEnabled]; 132 120 } 133 121 134 void darwinWindowAnimateResizeImpl (NativeWindowRef aWindow, int x, int y, int width, int height) 135 { 136 CocoaAutoreleasePool pool; 137 122 void darwinWindowAnimateResizeImpl(NativeWindowRef aWindow, int x, int y, int width, int height) 123 { 138 124 /* It seems that Qt doesn't return the height of the window with the 139 125 * toolbar height included. So add this size manually. Could easily be that … … 143 129 int toolbarHeight = 0; 144 130 if(toolbar && [toolbar isVisible]) 145 toolbarHeight = NSHeight (windowFrame) - NSHeight([[aWindow contentView] frame]);131 toolbarHeight = NSHeight(windowFrame) - NSHeight([[aWindow contentView] frame]); 146 132 int h = height + toolbarHeight; 147 int h1 = h - NSHeight 133 int h1 = h - NSHeight(windowFrame); 148 134 windowFrame.size.height = h; 149 135 windowFrame.origin.y -= h1; … … 152 138 } 153 139 154 void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow) 155 { 156 CocoaAutoreleasePool pool; 157 140 void darwinWindowInvalidateShadowImpl(NativeWindowRef aWindow) 141 { 158 142 [aWindow invalidateShadow]; 159 143 } 160 144 161 int darwinWindowToolBarHeight (NativeWindowRef aWindow) 162 { 163 CocoaAutoreleasePool pool; 164 145 int darwinWindowToolBarHeight(NativeWindowRef aWindow) 146 { 165 147 NSToolbar *toolbar = [aWindow toolbar]; 166 148 NSRect windowFrame = [aWindow frame]; … … 170 152 if(toolbar && [toolbar isVisible]) 171 153 /* title bar height: */ 172 toolbarHeight = NSHeight (windowFrame) - NSHeight([[aWindow contentView] frame]) - theight;154 toolbarHeight = NSHeight(windowFrame) - NSHeight([[aWindow contentView] frame]) - theight; 173 155 174 156 return toolbarHeight; … … 177 159 bool darwinIsToolbarVisible(NativeWindowRef pWindow) 178 160 { 179 CocoaAutoreleasePool pool;180 181 161 NSToolbar *pToolbar = [pWindow toolbar]; 182 162 … … 186 166 bool darwinIsWindowMaximized(NativeWindowRef aWindow) 187 167 { 188 CocoaAutoreleasePool pool;189 190 168 bool fResult = [aWindow isZoomed]; 191 169 … … 195 173 float darwinSmallFontSize() 196 174 { 197 CocoaAutoreleasePool pool;198 199 175 float size = [NSFont systemFontSizeForControlSize: NSSmallControlSize]; 200 176 … … 231 207 } 232 208 209 /** 210 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object. 211 * 212 * @return The Cocoa event modifier mask. 213 * @param pEvent The Cocoa event. 214 */ 215 unsigned long darwinEventModifierFlags(ConstNativeNSEventRef pEvent) 216 { 217 return [pEvent modifierFlags]; 218 } 219 220 /** 221 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object and 222 * converts the flags to carbon style. 223 * 224 * @return The Carbon modifier mask. 225 * @param pEvent The Cocoa event. 226 */ 227 uint32_t darwinEventModifierFlagsXlated(ConstNativeNSEventRef pEvent) 228 { 229 NSUInteger fCocoa = [pEvent modifierFlags]; 230 uint32_t fCarbon = 0; 231 if (fCocoa) 232 { 233 if (fCocoa & NSAlphaShiftKeyMask) 234 fCarbon |= alphaLock; 235 if (fCocoa & (NSShiftKeyMask | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK)) 236 { 237 if (fCocoa & (NX_DEVICERSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK)) 238 { 239 if (fCocoa & NX_DEVICERSHIFTKEYMASK) 240 fCarbon |= rightShiftKey; 241 if (fCocoa & NX_DEVICELSHIFTKEYMASK) 242 fCarbon |= shiftKey; 243 } 244 else 245 fCarbon |= shiftKey; 246 } 247 248 if (fCocoa & (NSControlKeyMask | NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK)) 249 { 250 if (fCocoa & (NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK)) 251 { 252 if (fCocoa & NX_DEVICERCTLKEYMASK) 253 fCarbon |= rightControlKey; 254 if (fCocoa & NX_DEVICELCTLKEYMASK) 255 fCarbon |= controlKey; 256 } 257 else 258 fCarbon |= controlKey; 259 } 260 261 if (fCocoa & (NSAlternateKeyMask | NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK)) 262 { 263 if (fCocoa & (NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK)) 264 { 265 if (fCocoa & NX_DEVICERALTKEYMASK) 266 fCarbon |= rightOptionKey; 267 if (fCocoa & NX_DEVICELALTKEYMASK) 268 fCarbon |= optionKey; 269 } 270 else 271 fCarbon |= optionKey; 272 } 273 274 if (fCocoa & (NSCommandKeyMask | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK)) 275 { 276 if (fCocoa & (NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK)) 277 { 278 if (fCocoa & NX_DEVICERCMDKEYMASK) 279 fCarbon |= kEventKeyModifierRightCmdKeyMask; 280 if (fCocoa & NX_DEVICELCMDKEYMASK) 281 fCarbon |= cmdKey; 282 } 283 else 284 fCarbon |= cmdKey; 285 } 286 287 /* 288 if (fCocoa & NSNumericPadKeyMask) 289 fCarbon |= ???; 290 291 if (fCocoa & NSHelpKeyMask) 292 fCarbon |= ???; 293 294 if (fCocoa & NSFunctionKeyMask) 295 fCarbon |= ???; 296 */ 297 } 298 299 return fCarbon; 300 } 301 302 /** 303 * Check for some default application key combinations a Mac user expect, like 304 * CMD+Q or CMD+H. 305 * 306 * @returns true if such a key combo was hit, false otherwise. 307 * @param pEvent The Cocoa event. 308 */ 309 bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent) 310 { 311 NSEventType eEvtType = [pEvent type]; 312 bool fGlobalHotkey = false; 313 314 switch (eEvtType) 315 { 316 case NSKeyDown: 317 case NSKeyUp: 318 { 319 NSUInteger fEvtMask = [pEvent modifierFlags]; 320 unsigned short KeyCode = [pEvent keyCode]; 321 if ( ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) /* L+CMD */ 322 || ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK))) /* R+CMD */ 323 { 324 if ( KeyCode == 0x0c /* CMD+Q (Quit) */ 325 || KeyCode == 0x04) /* CMD+H (Hide) */ 326 fGlobalHotkey = true; 327 } 328 else if ( ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICELALTKEYMASK | NX_COMMANDMASK | NX_DEVICELCMDKEYMASK)) /* L+ALT+CMD */ 329 || ((fEvtMask & (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK)) == (NX_NONCOALSESCEDMASK | NX_ALTERNATEMASK | NX_DEVICERCMDKEYMASK | NX_COMMANDMASK | NX_DEVICERCMDKEYMASK))) /* R+ALT+CMD */ 330 { 331 if (KeyCode == 0x04) /* ALT+CMD+H (Hide-Others) */ 332 fGlobalHotkey = true; 333 } 334 break; 335 } 336 default: break; 337 } 338 return fGlobalHotkey; 339 } 340 341 /** 342 * Get the name for a Cocoa event type. 343 * 344 * @returns Read-only name string. 345 * @param eEvtType The Cocoa event type. 346 */ 347 const char *darwinEventTypeName(unsigned long eEvtType) 348 { 349 switch (eEvtType) 350 { 351 #define EVT_CASE(nm) case nm: return #nm 352 EVT_CASE(NSLeftMouseDown); 353 EVT_CASE(NSLeftMouseUp); 354 EVT_CASE(NSRightMouseDown); 355 EVT_CASE(NSRightMouseUp); 356 EVT_CASE(NSMouseMoved); 357 EVT_CASE(NSLeftMouseDragged); 358 EVT_CASE(NSRightMouseDragged); 359 EVT_CASE(NSMouseEntered); 360 EVT_CASE(NSMouseExited); 361 EVT_CASE(NSKeyDown); 362 EVT_CASE(NSKeyUp); 363 EVT_CASE(NSFlagsChanged); 364 EVT_CASE(NSAppKitDefined); 365 EVT_CASE(NSSystemDefined); 366 EVT_CASE(NSApplicationDefined); 367 EVT_CASE(NSPeriodic); 368 EVT_CASE(NSCursorUpdate); 369 EVT_CASE(NSScrollWheel); 370 EVT_CASE(NSTabletPoint); 371 EVT_CASE(NSTabletProximity); 372 EVT_CASE(NSOtherMouseDown); 373 EVT_CASE(NSOtherMouseUp); 374 EVT_CASE(NSOtherMouseDragged); 375 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 376 EVT_CASE(NSEventTypeGesture); 377 EVT_CASE(NSEventTypeMagnify); 378 EVT_CASE(NSEventTypeSwipe); 379 EVT_CASE(NSEventTypeRotate); 380 EVT_CASE(NSEventTypeBeginGesture); 381 EVT_CASE(NSEventTypeEndGesture); 382 #endif 383 #undef EVT_CASE 384 default: 385 return "Unknown!"; 386 } 387 } 388 389 /** 390 * Debug helper function for dumping a Cocoa event to stdout. 391 * 392 * @param pszPrefix Message prefix. 393 * @param pEvent The Cocoa event. 394 */ 395 void darwinPrintEvent(const char *pszPrefix, ConstNativeNSEventRef pEvent) 396 { 397 NSEventType eEvtType = [pEvent type]; 398 NSUInteger fEvtMask = [pEvent modifierFlags]; 399 NSWindow *pEvtWindow = [pEvent window]; 400 NSInteger iEvtWindow = [pEvent windowNumber]; 401 NSGraphicsContext *pEvtGraphCtx = [pEvent context]; 402 403 printf("%s%p: Type=%lu Modifiers=%08lx pWindow=%p #Wnd=%ld pGraphCtx=%p %s\n", 404 pszPrefix, (void*)pEvent, (unsigned long)eEvtType, (unsigned long)fEvtMask, (void*)pEvtWindow, 405 (long)iEvtWindow, (void*)pEvtGraphCtx, darwinEventTypeName(eEvtType)); 406 407 /* dump type specific into. */ 408 switch (eEvtType) 409 { 410 case NSLeftMouseDown: 411 case NSLeftMouseUp: 412 case NSRightMouseDown: 413 case NSRightMouseUp: 414 case NSMouseMoved: 415 416 case NSLeftMouseDragged: 417 case NSRightMouseDragged: 418 case NSMouseEntered: 419 case NSMouseExited: 420 break; 421 422 case NSKeyDown: 423 case NSKeyUp: 424 { 425 NSUInteger i; 426 NSUInteger cch; 427 NSString *pChars = [pEvent characters]; 428 NSString *pCharsIgnMod = [pEvent charactersIgnoringModifiers]; 429 BOOL fIsARepeat = [pEvent isARepeat]; 430 unsigned short KeyCode = [pEvent keyCode]; 431 432 printf(" KeyCode=%04x isARepeat=%d", KeyCode, fIsARepeat); 433 if (pChars) 434 { 435 cch = [pChars length]; 436 printf(" characters={"); 437 for (i = 0; i < cch; i++) 438 printf(i == 0 ? "%02x" : ",%02x", [pChars characterAtIndex: i]); 439 printf("}"); 440 } 441 442 if (pCharsIgnMod) 443 { 444 cch = [pCharsIgnMod length]; 445 printf(" charactersIgnoringModifiers={"); 446 for (i = 0; i < cch; i++) 447 printf(i == 0 ? "%02x" : ",%02x", [pCharsIgnMod characterAtIndex: i]); 448 printf("}"); 449 } 450 printf("\n"); 451 break; 452 } 453 454 case NSFlagsChanged: 455 { 456 NSUInteger fOddBits = NSAlphaShiftKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask 457 | NSCommandKeyMask | NSNumericPadKeyMask | NSHelpKeyMask | NSFunctionKeyMask 458 | NX_DEVICELCTLKEYMASK | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK 459 | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK | NX_DEVICELALTKEYMASK 460 | NX_DEVICERALTKEYMASK | NX_DEVICERCTLKEYMASK; 461 462 printf(" KeyCode=%04x", (int)[pEvent keyCode]); 463 #define PRINT_MOD(cnst, nm) do { if (fEvtMask & (cnst)) printf(" %s", #nm); } while (0) 464 /* device-independent: */ 465 PRINT_MOD(NSAlphaShiftKeyMask, "AlphaShift"); 466 PRINT_MOD(NSShiftKeyMask, "Shift"); 467 PRINT_MOD(NSControlKeyMask, "Ctrl"); 468 PRINT_MOD(NSAlternateKeyMask, "Alt"); 469 PRINT_MOD(NSCommandKeyMask, "Cmd"); 470 PRINT_MOD(NSNumericPadKeyMask, "NumLock"); 471 PRINT_MOD(NSHelpKeyMask, "Help"); 472 PRINT_MOD(NSFunctionKeyMask, "Fn"); 473 /* device-dependent (sort of): */ 474 PRINT_MOD(NX_DEVICELCTLKEYMASK, "$L-Ctrl"); 475 PRINT_MOD(NX_DEVICELSHIFTKEYMASK, "$L-Shift"); 476 PRINT_MOD(NX_DEVICERSHIFTKEYMASK, "$R-Shift"); 477 PRINT_MOD(NX_DEVICELCMDKEYMASK, "$L-Cmd"); 478 PRINT_MOD(NX_DEVICERCMDKEYMASK, "$R-Cmd"); 479 PRINT_MOD(NX_DEVICELALTKEYMASK, "$L-Alt"); 480 PRINT_MOD(NX_DEVICERALTKEYMASK, "$R-Alt"); 481 PRINT_MOD(NX_DEVICERCTLKEYMASK, "$R-Ctrl"); 482 #undef PRINT_MOD 483 484 fOddBits = fEvtMask & ~fOddBits; 485 if (fOddBits) 486 printf(" fOddBits=%#08lx", (unsigned long)fOddBits); 487 #undef KNOWN_BITS 488 printf("\n"); 489 break; 490 } 491 492 case NSAppKitDefined: 493 case NSSystemDefined: 494 case NSApplicationDefined: 495 case NSPeriodic: 496 case NSCursorUpdate: 497 case NSScrollWheel: 498 case NSTabletPoint: 499 case NSTabletProximity: 500 case NSOtherMouseDown: 501 case NSOtherMouseUp: 502 case NSOtherMouseDragged: 503 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 504 case NSEventTypeGesture: 505 case NSEventTypeMagnify: 506 case NSEventTypeSwipe: 507 case NSEventTypeRotate: 508 case NSEventTypeBeginGesture: 509 case NSEventTypeEndGesture: 510 #endif 511 default: 512 printf(" Unknown!\n"); 513 break; 514 } 515 } 516 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp
r30022 r30114 17 17 18 18 #include "VBoxUtils-darwin.h" 19 #include " VBoxCocoaApplication.h"19 #include "UICocoaApplication.h" 20 20 21 21 #include <iprt/mem.h> … … 304 304 void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow) 305 305 { 306 ::VBoxCocoaApplication_setCallback(UINT32_MAX, ::darwinUnifiedToolbarEvents, pWindow);306 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(3) /* NSRightMouseDown */, ::darwinUnifiedToolbarEvents, pWindow); 307 307 } 308 308 309 309 void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow) 310 310 { 311 ::VBoxCocoaApplication_unsetCallback(UINT32_MAX, ::darwinUnifiedToolbarEvents, pWindow);311 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(3) /* NSRightMouseDown */, ::darwinUnifiedToolbarEvents, pWindow); 312 312 } 313 313 -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.h
r30022 r30114 52 52 #endif /* __OBJC__ */ 53 53 54 #include "VBoxCocoaHelper.h" 54 55 #include <iprt/cdefs.h> /* for RT_C_DECLS_BEGIN/RT_C_DECLS_END & stuff */ 55 56 #include <QRect> 56 57 57 58 class QWidget; 59 60 ADD_COCOA_NATIVE_REF(NSEvent); 58 61 59 62 RT_C_DECLS_BEGIN … … 96 99 bool darwinUnifiedToolbarEvents(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser); 97 100 void darwinCreateContextMenuEvent(void *pvWin, int x, int y); 101 102 /******************************************************************************** 103 * 104 * Event/Keyboard helpers (OS System native) 105 * 106 ********************************************************************************/ 107 unsigned long darwinEventModifierFlags(ConstNativeNSEventRef pEvent); 108 uint32_t darwinEventModifierFlagsXlated(ConstNativeNSEventRef pEvent); 109 bool darwinIsApplicationCommand(ConstNativeNSEventRef pEvent); 110 const char *darwinEventTypeName(unsigned long eEvtType); 111 void darwinPrintEvent(const char *pszPrefix, ConstNativeNSEventRef pEvent); 98 112 99 113 RT_C_DECLS_END -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIHotKeyEdit.cpp
r29921 r30114 67 67 68 68 #ifdef Q_WS_MAC 69 # include "UICocoaApplication.h" 69 70 # include "DarwinKeyboard.h" 71 # include "VBoxUtils.h" 70 72 # include <Carbon/Carbon.h> 71 # include "darwin/VBoxCocoaApplication.h"72 # include "VBoxUtils.h"73 73 #endif 74 74 … … 141 141 #ifdef Q_WS_MAC 142 142 mDarwinKeyModifiers = GetCurrentEventKeyModifiers(); 143 ::VBoxCocoaApplication_setCallback (UINT32_MAX, QIHotKeyEdit::darwinEventHandlerProc, this);143 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, QIHotKeyEdit::darwinEventHandlerProc, this); 144 144 ::DarwinGrabKeyboard (false /* just modifiers */); 145 145 #endif … … 150 150 #ifdef Q_WS_MAC 151 151 ::DarwinReleaseKeyboard(); 152 ::VBoxCocoaApplication_unsetCallback (UINT32_MAX, QIHotKeyEdit::darwinEventHandlerProc, this);152 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, QIHotKeyEdit::darwinEventHandlerProc, this); 153 153 #endif 154 154 } -
trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
r29794 r30114 19 19 20 20 #ifdef VBOX_WITH_PRECOMPILED_HEADERS 21 # 22 # ifdef QT_MAC_USE_COCOA23 # include "darwin/VBoxCocoaApplication.h"24 # endif21 #include "precomp.h" 22 #ifdef Q_WS_MAC 23 # include "UICocoaApplication.h" 24 #endif /* Q_WS_MAC */ 25 25 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 26 26 #include "VBoxGlobal.h" … … 28 28 #include "VBoxSelectorWnd.h" 29 29 #include "VBoxUtils.h" 30 #ifdef Q T_MAC_USE_COCOA31 # include " darwin/VBoxCocoaApplication.h"30 #ifdef Q_WS_MAC 31 # include "UICocoaApplication.h" 32 32 #endif 33 33 … … 325 325 /* Instantiate our NSApplication derivative before QApplication 326 326 * forces NSApplication to be instantiated. */ 327 VBoxCocoaApplication_sharedApplication();327 UICocoaApplication::instance(); 328 328 #endif 329 329 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r30074 r30114 82 82 # include "DockIconPreview.h" 83 83 # include "DarwinKeyboard.h" 84 # include " VBoxCocoaApplication.h"84 # include "UICocoaApplication.h" 85 85 # include <VBox/err.h> 86 86 # include <Carbon/Carbon.h> … … 2346 2346 2347 2347 /* Register the event callback/hook and grab the keyboard. */ 2348 ::VBoxCocoaApplication_setCallback (UINT32_MAX, /** @todo fix mask */2349 UIMachineView::darwinEventHandlerProc, this);2348 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 2349 UIMachineView::darwinEventHandlerProc, this); 2350 2350 2351 2351 ::DarwinGrabKeyboard (false); … … 2354 2354 { 2355 2355 ::DarwinReleaseKeyboard(); 2356 ::VBoxCocoaApplication_unsetCallback(UINT32_MAX, /** @todo fix mask */2357 UIMachineView::darwinEventHandlerProc, this);2356 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 2357 UIMachineView::darwinEventHandlerProc, this); 2358 2358 } 2359 2359 } … … 2367 2367 /* Check if this is an application key combo. In that case we will not pass 2368 2368 * the event to the guest, but let the host process it. */ 2369 if ( VBoxCocoaApplication_isApplicationCommand(pvCocoaEvent))2369 if (::darwinIsApplicationCommand(pvCocoaEvent)) 2370 2370 return false; 2371 2371
Note:
See TracChangeset
for help on using the changeset viewer.