Changeset 52511 in vbox
- Timestamp:
- Aug 28, 2014 11:59:52 AM (10 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.h
r52510 r52511 30 30 31 31 /* Forward declarations: */ 32 class QObject; 32 33 class QWidget; 33 34 … … 40 41 typedef bool (*PFNVBOXCACALLBACK)(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser); 41 42 43 /** Native notification callback type for QObject. */ 44 typedef void (*PfnNativeNotificationCallbackForQObject)(QObject *pObject, const QMap<QString, QString> &userInfo); 42 45 /** Native notification callback type for QWidget. */ 43 46 typedef void (*PfnNativeNotificationCallbackForQWidget)(const QString &strNativeNotificationName, QWidget *pWidget); … … 54 57 ~UICocoaApplication(); 55 58 59 /** Returns whether application is currently active. */ 60 bool isActive() const; 61 56 62 /** Hides the application. */ 57 63 void hide(); … … 62 68 void unregisterForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser); 63 69 70 /** Register passed @a pObject to native notification @a strNativeNotificationName, using @a pCallback as handler. */ 71 void registerToNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject, PfnNativeNotificationCallbackForQObject pCallback); 72 /** Unregister passed @a pWidget from native notification @a strNativeNotificationName. */ 73 void unregisterFromNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject); 74 64 75 /** Register passed @a pWidget to native notification @a strNativeNotificationName, using @a pCallback as handler. */ 65 76 void registerToNotificationOfWindow(const QString &strNativeNotificationName, QWidget *pWidget, PfnNativeNotificationCallbackForQWidget pCallback); … … 67 78 void unregisterFromNotificationOfWindow(const QString &strNativeNotificationName, QWidget *pWidget); 68 79 80 /** Redirects native notification @a pstrNativeNotificationName for application to registered listener. */ 81 void nativeNotificationProxyForObject(NativeNSStringRef pstrNativeNotificationName, const QMap<QString, QString> &userInfo); 69 82 /** Redirects native notification @a pstrNativeNotificationName for window @a pWindow to registered listener. */ 70 83 void nativeNotificationProxyForWidget(NativeNSStringRef pstrNativeNotificationName, NativeNSWindowRef pWindow); … … 83 96 NativeNSAutoreleasePoolRef m_pPool; 84 97 98 /** Map of notification callbacks registered for corresponding QObject(s). */ 99 QMap<QObject*, QMap<QString, PfnNativeNotificationCallbackForQObject> > m_objectCallbacks; 85 100 /** Map of notification callbacks registered for corresponding QWidget(s). */ 86 101 QMap<QWidget*, QMap<QString, PfnNativeNotificationCallbackForQWidget> > m_widgetCallbacks; -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.mm
r52510 r52511 69 69 - (void)unsetCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser; 70 70 71 - (void)registerToNotificationOfWorkspace :(NSString*)pstrNotificationName; 72 - (void)unregisterFromNotificationOfWorkspace :(NSString*)pstrNotificationName; 73 71 74 - (void)registerToNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow; 72 75 - (void)unregisterFromNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow; 73 76 77 - (void)notificationCallbackOfObject :(NSNotification*)notification; 74 78 - (void)notificationCallbackOfWindow :(NSNotification*)notification; 75 79 @end /* @interface UICocoaApplicationPrivate */ … … 166 170 } 167 171 172 /** Register to cocoa notification @a pstrNotificationName. */ 173 - (void) registerToNotificationOfWorkspace :(NSString*)pstrNotificationName 174 { 175 /* Register notification observer: */ 176 NSNotificationCenter *pNotificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; 177 [pNotificationCenter addObserver:self 178 selector:@selector(notificationCallbackOfObject:) 179 name:pstrNotificationName 180 object:nil]; 181 } 182 183 /** Unregister @a pWindow from cocoa notification @a pstrNotificationName. */ 184 - (void) unregisterFromNotificationOfWorkspace :(NSString*)pstrNotificationName 185 { 186 /* Uninstall notification observer: */ 187 NSNotificationCenter *pNotificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; 188 [pNotificationCenter removeObserver:self 189 name:pstrNotificationName 190 object:nil]; 191 } 192 168 193 /** Register @a pWindow to cocoa notification @a pstrNotificationName. */ 169 194 - (void) registerToNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow … … 183 208 name:pstrNotificationName 184 209 object:pWindow]; 210 } 211 212 /** Redirects cocoa @a notification to UICocoaApplication instance. */ 213 - (void) notificationCallbackOfObject :(NSNotification*)notification 214 { 215 /* Get current notification name: */ 216 NSString *pstrName = [notification name]; 217 218 /* Prepare user-info: */ 219 QMap<QString, QString> userInfo; 220 221 /* Process known notifications: */ 222 if ( [pstrName isEqualToString :@"NSWorkspaceDidActivateApplicationNotification"] 223 || [pstrName isEqualToString :@"NSWorkspaceDidDeactivateApplicationNotification"]) 224 { 225 NSDictionary *pUserInfo = [notification userInfo]; 226 NSRunningApplication *pApplication = [pUserInfo valueForKey :@"NSWorkspaceApplicationKey"]; 227 NSString *pstrBundleIndentifier = [pApplication bundleIdentifier]; 228 userInfo.insert("BundleIdentifier", darwinFromNativeString((NativeNSStringRef)pstrBundleIndentifier)); 229 } 230 231 /* Redirect known notifications to objects: */ 232 UICocoaApplication::instance()->nativeNotificationProxyForObject(pstrName, userInfo); 185 233 } 186 234 … … 225 273 } 226 274 275 bool UICocoaApplication::isActive() const 276 { 277 return [m_pNative isActive]; 278 } 279 227 280 void UICocoaApplication::hide() 228 281 { … … 238 291 { 239 292 [m_pNative unsetCallback:fMask :pfnCallback :pvUser]; 293 } 294 295 void UICocoaApplication::registerToNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject, 296 PfnNativeNotificationCallbackForQObject pCallback) 297 { 298 /* Make sure it is not registered yet: */ 299 AssertReturnVoid(!m_objectCallbacks.contains(pObject) || !m_objectCallbacks[pObject].contains(strNativeNotificationName)); 300 301 /* Remember callback: */ 302 m_objectCallbacks[pObject][strNativeNotificationName] = pCallback; 303 304 /* Register observer: */ 305 NativeNSStringRef pstrNativeNotificationName = darwinToNativeString(strNativeNotificationName.toLatin1().constData()); 306 [m_pNative registerToNotificationOfWorkspace :pstrNativeNotificationName]; 307 } 308 309 void UICocoaApplication::unregisterFromNotificationOfWorkspace(const QString &strNativeNotificationName, QObject *pObject) 310 { 311 /* Make sure it is registered yet: */ 312 AssertReturnVoid(m_objectCallbacks.contains(pObject) && m_objectCallbacks[pObject].contains(strNativeNotificationName)); 313 314 /* Forget callback: */ 315 m_objectCallbacks[pObject].remove(strNativeNotificationName); 316 if (m_objectCallbacks[pObject].isEmpty()) 317 m_objectCallbacks.remove(pObject); 318 319 /* Unregister observer: */ 320 NativeNSStringRef pstrNativeNotificationName = darwinToNativeString(strNativeNotificationName.toLatin1().constData()); 321 [m_pNative unregisterFromNotificationOfWorkspace :pstrNativeNotificationName]; 240 322 } 241 323 … … 269 351 NativeNSWindowRef pWindow = darwinToNativeWindow(pWidget); 270 352 [m_pNative unregisterFromNotificationOfWindow :pstrNativeNotificationName :pWindow]; 353 } 354 355 void UICocoaApplication::nativeNotificationProxyForObject(NativeNSStringRef pstrNotificationName, const QMap<QString, QString> &userInfo) 356 { 357 /* Get notification name: */ 358 QString strNotificationName = darwinFromNativeString(pstrNotificationName); 359 360 /* Check if existing object(s) have corresponding notification handler: */ 361 foreach (QObject *pObject, m_objectCallbacks.keys()) 362 { 363 const QMap<QString, PfnNativeNotificationCallbackForQObject> &callbacks = m_objectCallbacks[pObject]; 364 if (callbacks.contains(strNotificationName)) 365 callbacks[strNotificationName](pObject, userInfo); 366 } 271 367 } 272 368
Note:
See TracChangeset
for help on using the changeset viewer.