Changeset 50491 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 18, 2014 12:11:28 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92332
- 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
r49595 r50491 18 18 #define ___darwin_VBoxCocoaApplication_h 19 19 20 /* Qt includes: */ 21 #include <QMap> 22 23 /* GUI includes: */ 20 24 #include "VBoxCocoaHelper.h" 25 21 26 ADD_COCOA_NATIVE_REF(UICocoaApplicationPrivate); 22 27 ADD_COCOA_NATIVE_REF(NSAutoreleasePool); 28 ADD_COCOA_NATIVE_REF(NSString); 29 ADD_COCOA_NATIVE_REF(NSWindow); 30 31 /* Forward declarations: */ 32 class QWidget; 23 33 24 34 /** Event handler callback. … … 29 39 */ 30 40 typedef bool (*PFNVBOXCACALLBACK)(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser); 41 42 /** Native notification callback type for QWidget. */ 43 typedef void (*PfnNativeNotificationCallbackForQWidget)(const QString &strNativeNotificationName, QWidget *pWidget); 31 44 32 45 /* C++ singleton for our private NSApplication object */ … … 41 54 void unregisterForNativeEvents(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser); 42 55 56 /** Register passed @a pWidget to native notification @a strNativeNotificationName, using @a pCallback as handler. */ 57 void registerToNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget, PfnNativeNotificationCallbackForQWidget pCallback); 58 /** Unregister passed @a pWidget from native notification @a strNativeNotificationName. */ 59 void unregisterFromNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget); 60 /** Redirects native notification @a pstrNativeNotificationName for window @a pWindow to registered listener. */ 61 void nativeNotificationProxy(NativeNSStringRef pstrNativeNotificationName, NativeNSWindowRef pWindow); 62 43 63 private: 44 64 UICocoaApplication(); … … 46 66 NativeUICocoaApplicationPrivateRef m_pNative; 47 67 NativeNSAutoreleasePoolRef m_pPool; 68 69 /** Map of notification callbacks registered for corresponding QWidget(s). */ 70 QMap<QWidget*, QMap<QString, PfnNativeNotificationCallbackForQWidget> > m_callbacks; 48 71 }; 49 72 -
trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.mm
r49595 r50491 16 16 */ 17 17 18 /* Local includes*/18 /* GUI includes: */ 19 19 #include "UICocoaApplication.h" 20 20 #include "VBoxUtils-darwin.h" … … 68 68 - (void)setCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser; 69 69 - (void)unsetCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser; 70 71 - (void)registerToNotification :(NSString*)pstrNotificationName :(NSWindow*)pWindow; 72 - (void)unregisterFromNotification :(NSString*)pstrNotificationName :(NSWindow*)pWindow; 73 - (void)notificationCallback :(NSNotification*)notification; 70 74 @end /* @interface UICocoaApplicationPrivate */ 71 75 … … 160 164 m_fMask = fNewMask; 161 165 } 166 167 /** Register @a pWindow to cocoa notification @a pstrNotificationName. */ 168 - (void) registerToNotification :(NSString*)pstrNotificationName :(NSWindow*)pWindow 169 { 170 /* Register notification observer: */ 171 [[NSNotificationCenter defaultCenter] addObserver:self 172 selector:@selector(notificationCallback:) 173 name:pstrNotificationName 174 object:pWindow]; 175 } 176 177 /** Unregister @a pWindow from cocoa notification @a pstrNotificationName. */ 178 - (void) unregisterFromNotification :(NSString*)pstrNotificationName :(NSWindow*)pWindow 179 { 180 /* Uninstall notification observer: */ 181 [[NSNotificationCenter defaultCenter] removeObserver:self 182 name:pstrNotificationName 183 object:pWindow]; 184 } 185 186 /** Redirects cocoa @a notification to UICocoaApplication instance. */ 187 - (void) notificationCallback :(NSNotification*)notification 188 { 189 /* Get current notification name: */ 190 NSString *pstrName = [notification name]; 191 192 /* Define known notification names: */ 193 NSString *spstrWillEnterFullscreenNotification = @"NSWindowWillEnterFullScreenNotification"; 194 NSString *spstrDidEnterFullscreenNotification = @"NSWindowDidEnterFullScreenNotification"; 195 NSString *spstrWillExitFullscreenNotification = @"NSWindowWillExitFullScreenNotification"; 196 NSString *spstrDidExitFullscreenNotification = @"NSWindowDidExitFullScreenNotification"; 197 198 /* Redirect known notifications to UICocoaApplication instance: */ 199 if ( [pstrName isEqualToString :spstrWillEnterFullscreenNotification] 200 || [pstrName isEqualToString :spstrDidEnterFullscreenNotification] 201 || [pstrName isEqualToString :spstrWillExitFullscreenNotification] 202 || [pstrName isEqualToString :spstrDidExitFullscreenNotification]) 203 UICocoaApplication::instance()->nativeNotificationProxy(pstrName, [notification object]); 204 } 162 205 @end /* @implementation UICocoaApplicationPrivate */ 163 206 … … 206 249 } 207 250 251 void UICocoaApplication::registerToNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget, PfnNativeNotificationCallbackForQWidget pCallback) 252 { 253 /* Make sure it is not registered yet: */ 254 AssertReturnVoid(!m_callbacks.contains(pWidget) || !m_callbacks[pWidget].contains(strNativeNotificationName)); 255 256 /* Remember callback: */ 257 m_callbacks[pWidget][strNativeNotificationName] = pCallback; 258 259 /* Register observer: */ 260 NativeNSStringRef pstrNativeNotificationName = darwinToNativeString(strNativeNotificationName.toLatin1().constData()); 261 NativeNSWindowRef pWindow = darwinToNativeWindow(pWidget); 262 [m_pNative registerToNotification :pstrNativeNotificationName :pWindow]; 263 } 264 265 void UICocoaApplication::unregisterFromNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget) 266 { 267 /* Make sure it is registered yet: */ 268 AssertReturnVoid(m_callbacks.contains(pWidget) && m_callbacks[pWidget].contains(strNativeNotificationName)); 269 270 /* Forget callback: */ 271 m_callbacks[pWidget].remove(strNativeNotificationName); 272 if (m_callbacks[pWidget].isEmpty()) 273 m_callbacks.remove(pWidget); 274 275 /* Unregister observer: */ 276 NativeNSStringRef pstrNativeNotificationName = darwinToNativeString(strNativeNotificationName.toLatin1().constData()); 277 NativeNSWindowRef pWindow = darwinToNativeWindow(pWidget); 278 [m_pNative unregisterFromNotification :pstrNativeNotificationName :pWindow]; 279 } 280 281 void UICocoaApplication::nativeNotificationProxy(NativeNSStringRef pstrNotificationName, NativeNSWindowRef pWindow) 282 { 283 /* Get notification name: */ 284 QString strNotificationName = darwinFromNativeString(pstrNotificationName); 285 286 /* Check if existing widget(s) have corresponding notification handler: */ 287 const QList<QWidget*> &keys1 = m_callbacks.keys(); 288 for (int i = 0; i < keys1.size(); ++i) 289 { 290 QWidget *pWidget = keys1[i]; 291 if (darwinToNativeWindow(pWidget) == pWindow) 292 { 293 const QMap<QString, PfnNativeNotificationCallbackForQWidget> &callbacks = m_callbacks[pWidget]; 294 if (callbacks.contains(strNotificationName)) 295 callbacks[strNotificationName](strNotificationName, pWidget); 296 } 297 } 298 } 299
Note:
See TracChangeset
for help on using the changeset viewer.