- Timestamp:
- Feb 25, 2009 1:03:29 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 added
- 12 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r17070 r17126 152 152 VirtualBox_DEFS.debug = VBOX_CHECK_STATE # QT_FATAL_ASSERT 153 153 VirtualBox_DEFS.darwin = VBOX_GUI_USE_QIMAGE VBOX_WITHOUT_QHTTP 154 ifndef VBOX_WITH_COCOA_QT 154 155 VirtualBox_DEFS.darwin.x86= VBOX_GUI_USE_QUARTZ2D USE_HID_FOR_MODIFIERS 156 endif 155 157 VirtualBox_DEFS.freebsd = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL 156 158 VirtualBox_DEFS.linux = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL … … 403 405 ifdef VBOX_WITH_COCOA_QT 404 406 VirtualBox_SOURCES.darwin += \ 405 src/darwin/VBoxCocoaApplication.m 407 src/darwin/VBoxCocoaApplication.m \ 408 src/darwin/VBoxUtils-darwin-cocoa.m 409 else 410 VirtualBox_SOURCES.darwin += \ 411 src/darwin/VBoxUtils-darwin-carbon.cpp 406 412 endif 407 413 -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxToolBar.h
r16469 r17126 81 81 /** @todo Carbon -> Cocoa */ 82 82 # else /* !QT_MAC_USE_COCOA */ 83 WindowRef window = ::darwinTo WindowRef(this);83 WindowRef window = ::darwinToNativeWindow (this); 84 84 EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxToolBar::macEventFilter); 85 85 EventTypeSpec eventTypes[2]; … … 123 123 { 124 124 #ifdef Q_WS_MAC 125 ::darwinSetShow ToolBarButton (this, aShow);125 ::darwinSetShowsToolbarButton (this, aShow); 126 126 #else /* Q_WS_MAC */ 127 127 NOREF (aShow); -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils.h
r16691 r17126 128 128 129 129 #ifdef Q_WS_MAC 130 class QImage; 131 class QPixmap; 132 class QToolBar; 133 class VBoxFrameBuffer; 134 135 # ifdef QT_MAC_USE_COCOA 136 /** @todo Carbon -> Cocoa */ 137 # else /* !QT_MAC_USE_COCOA */ 138 # undef PAGE_SIZE 139 # undef PAGE_SHIFT 140 # include <Carbon/Carbon.h> 141 142 /* Asserts if a != noErr and prints the error code */ 143 # define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a))) 144 145 /* Converting stuff */ 146 CGImageRef darwinToCGImageRef (const QImage *aImage); 147 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap); 148 CGImageRef darwinToCGImageRef (const char *aSource); 149 150 /** 151 * Returns a reference to the HIView of the QWidget. 152 * 153 * @returns HIViewRef of the QWidget. 154 * @param aWidget Pointer to the QWidget 155 */ 156 DECLINLINE(HIViewRef) darwinToHIViewRef (QWidget *aWidget) 157 { 158 return HIViewRef(aWidget->winId()); 159 } 160 161 /** 162 * Returns a reference to the Window of the HIView. 163 * 164 * @returns WindowRef of the HIView. 165 * @param aViewRef Reference to the HIView 166 */ 167 DECLINLINE(WindowRef) darwinToWindowRef (HIViewRef aViewRef) 168 { 169 return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef)); 170 } 171 172 /** 173 * Returns a reference to the Window of the QWidget. 174 * 175 * @returns WindowRef of the QWidget. 176 * @param aWidget Pointer to the QWidget 177 */ 178 DECLINLINE(WindowRef) darwinToWindowRef (QWidget *aWidget) 179 { 180 return ::darwinToWindowRef (::darwinToHIViewRef (aWidget)); 181 } 182 183 /** 184 * Returns a reference to the CGContext of the QWidget. 185 * 186 * @returns CGContextRef of the QWidget. 187 * @param aWidget Pointer to the QWidget 188 */ 189 DECLINLINE(CGContextRef) darwinToCGContextRef (QWidget *aWidget) 190 { 191 return static_cast<CGContext *> (aWidget->macCGHandle()); 192 } 193 194 /** 195 * Converts a QRect to a HIRect. 196 * 197 * @returns HIRect for the converted QRect. 198 * @param aRect the QRect to convert 199 */ 200 DECLINLINE(HIRect) darwinToHIRect (const QRect &aRect) 201 { 202 return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); 203 } 204 #endif /* !QT_MAC_USE_COCOA */ 205 206 QString darwinSystemLanguage (void); 207 208 bool darwinIsMenuOpen (void); 209 210 void darwinSetShowToolBarButton (QToolBar *aToolBar, bool aShow); 211 212 void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget); 213 214 /* Proxy icon creation */ 215 QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText); 216 217 /* Icons in the menu of an mac application are unusual. */ 218 void darwinDisableIconsInMenus (void); 219 220 # ifdef DEBUG 221 void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent); 222 # endif 223 224 # ifdef QT_MAC_USE_COCOA 225 /** @todo Carbon -> Cocoa */ 226 # else /* !QT_MAC_USE_COCOA */ 227 /* Experimental region handler for the seamless mode */ 228 OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData); 229 230 /* Handler for the OpenGL overlay window stuff & the possible messages. */ 231 enum 232 { 233 /* Event classes */ 234 kEventClassVBox = 'vbox', 235 /* Event kinds */ 236 kEventVBoxShowWindow = 'swin', 237 kEventVBoxMoveWindow = 'mwin', 238 kEventVBoxResizeWindow = 'rwin', 239 kEventVBoxUpdateDock = 'udck' 240 }; 241 OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData); 242 # endif /* !QT_MAC_USE_COCOA*/ 130 # include "VBoxUtils-darwin.h" 243 131 #endif /* Q_WS_MAC */ 244 132 -
trunk/src/VBox/Frontends/VirtualBox/src/QIDialog.cpp
r16469 r17126 50 50 /** @todo Carbon -> Cocoa */ 51 51 # else 52 ChangeWindowAttributes (::darwinTo WindowRef(this), kWindowNoAttributes, kWindowResizableAttribute);52 ChangeWindowAttributes (::darwinToNativeWindow (this), kWindowNoAttributes, kWindowResizableAttribute); 53 53 # endif 54 54 #endif /* Q_WS_MAC */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
r16953 r17126 4091 4091 event handler). */ 4092 4092 if (aOn || mKeyboardGrabbed) 4093 # ifdef QT_MAC_USE_COCOA 4094 ::VBoxCocoaApplication_setMouseCoalescingEnabled (aOn); 4095 # else 4096 ::SetMouseCoalescingEnabled (aOn, NULL); 4097 # endif 4093 ::darwinSetMouseCoalescingEnabled (aOn); 4098 4094 } 4099 4095 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r17071 r17126 1270 1270 # else 1271 1271 HIRect viewRect; 1272 HIViewGetBounds (::darwinTo HIViewRef(this), &viewRect);1272 HIViewGetBounds (::darwinToNativeView (this), &viewRect); 1273 1273 CGContextClearRect (::darwinToCGContextRef (this), viewRect); 1274 1274 # endif … … 2385 2385 # else /* !QT_MAC_USE_COCOA */ 2386 2386 OSStatus status; 2387 WindowRef windowRef = ::darwinTo WindowRef(this);2387 WindowRef windowRef = ::darwinToNativeWindow (this); 2388 2388 Assert (VALID_PTR (windowRef)); 2389 2389 /* See above. … … 2432 2432 # else /* !QT_MAC_USE_COCOA */ 2433 2433 OSStatus status; 2434 HIViewRef viewRef = ::darwinTo HIViewRef(console->viewport());2434 HIViewRef viewRef = ::darwinToNativeView (console->viewport()); 2435 2435 Assert (VALID_PTR (viewRef)); 2436 WindowRef windowRef = ::darwinTo WindowRef(viewRef);2436 WindowRef windowRef = ::darwinToNativeWindow (viewRef); 2437 2437 Assert (VALID_PTR (windowRef)); 2438 2438 /* @todo=poetzsch: Currently this isn't necessary. I should … … 2518 2518 /* setWindowState removes the window group connection somehow. So save it 2519 2519 * temporary. */ 2520 WindowGroupRef g = GetWindowGroup (::darwinTo WindowRef(this));2520 WindowGroupRef g = GetWindowGroup (::darwinToNativeWindow (this)); 2521 2521 if (aSeamless) 2522 2522 if (aOn) … … 2540 2540 setWindowState (windowState() ^ Qt::WindowFullScreen); 2541 2541 /* Reassign the correct window group. */ 2542 SetWindowGroup (::darwinTo WindowRef(this), g);2542 SetWindowGroup (::darwinToNativeWindow (this), g); 2543 2543 # endif /* !QT_MAC_USE_COCOA */ 2544 2544 #else … … 3031 3031 * an repaint only. All the magic clipping stuff is done 3032 3032 * in the paint engine. */ 3033 HIViewReshapeStructure (::darwinTo HIViewRef(console->viewport()));3033 HIViewReshapeStructure (::darwinToNativeView (console->viewport())); 3034 3034 // HIWindowInvalidateShadow (::darwinToWindowRef (console->viewport())); 3035 3035 // ReshapeCustomWindow (::darwinToWindowRef (this)); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp
r12628 r17126 164 164 Assert (VALID_PTR (viewport)); 165 165 166 HIViewRef viewRef = ::darwinTo HIViewRef(viewport);166 HIViewRef viewRef = ::darwinToNativeView (viewport); 167 167 Assert (VALID_PTR (viewRef)); 168 168 /* Get the dimensions of this HIView */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSettingsDialog.cpp
r15103 r17126 20 20 * additional information or have any questions. 21 21 */ 22 23 22 #include "VBoxSettingsDialog.h" 24 23 #include "VBoxSettingsUtils.h" … … 39 38 #include <QStackedWidget> 40 39 41 42 40 #if MAC_LEOPARD_STYLE 43 41 # define VBOX_GUI_WITH_TOOLBAR_SETTINGS … … 56 54 Ui::VBoxSettingsDialog::setupUi (this); 57 55 56 // setToolbar (new VBoxToolBar (this)); 58 57 #ifdef Q_WS_MAC 59 58 // VBoxGlobal::setLayoutMargin (centralWidget()->layout(), 0); … … 277 276 mStack->setCurrentIndex (mStack->indexOf (rootPage)); 278 277 #else /* Q_WS_MAC */ 278 # ifndef QT_MAC_USE_COCOA 279 279 QSize cs = size(); 280 280 /* First make all fully resizeable */ … … 300 300 setFixedSize (ss); 301 301 } 302 # else /* QT_MAC_USE_COCOA */ 303 for (int i = 0; i < mStack->count(); ++i) 304 mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred); 305 mStack->setCurrentIndex (mStack->indexOf (rootPage)); 306 # endif /* QT_MAC_USE_COCOA */ 302 307 #endif /* !Q_WS_MAC */ 303 308 # ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS … … 415 420 int minWidth = mSelector->minWidth(); 416 421 #ifdef Q_WS_MAC 422 # ifndef QT_MAC_USE_COCOA 417 423 /* Set all size policies to ignored */ 418 424 for (int i = 0; i < mStack->count(); ++i) … … 432 438 433 439 categoryChanged (mSelector->currentId()); 440 # else /* QT_MAC_USE_COCOA */ 441 categoryChanged (mSelector->currentId()); 442 # endif /* QT_MAC_USE_COCOA */ 434 443 #else /* Q_WS_MAC */ 435 444 /* Resize to the minimum possible size */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSettingsSelector.cpp
r12130 r17126 368 368 mTbSelector->setUsesTextLabel (true); 369 369 mTbSelector->setIconSize (QSize (32, 32)); 370 mTbSelector->setShowToolBarButton (false); 370 371 /* Init the action group for house keeping */ 371 372 mActionGroup = new QActionGroup (this); -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaApplication.m
r16699 r17126 27 27 #include "DarwinKeyboard.h" 28 28 #include <iprt/assert.h> 29 #import <AppKit/NSWindow.h> 29 30 #import <AppKit/NSEvent.h> 30 31 … … 289 290 290 291 return fCarbon; 291 }292 293 294 /**295 * Calls the + (void)setMouseCoalescingEnabled:(BOOL)flag class method.296 *297 * @param fEnabled Whether to enable or disable coalescing.298 */299 void VBoxCocoaApplication_setMouseCoalescingEnabled(bool fEnabled)300 {301 [NSEvent setMouseCoalescingEnabled:fEnabled];302 292 } 303 293 … … 337 327 EVT_CASE(NSOtherMouseUp); 338 328 EVT_CASE(NSOtherMouseDragged); 339 #if MAC_OS_X_VERSION_MAX_ALLOWED > =MAC_OS_X_VERSION_10_5329 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 340 330 EVT_CASE(NSEventTypeGesture); 341 331 EVT_CASE(NSEventTypeMagnify); … … 467 457 case NSOtherMouseUp: 468 458 case NSOtherMouseDragged: 469 #if MAC_OS_X_VERSION_MAX_ALLOWED > =MAC_OS_X_VERSION_10_5459 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 470 460 case NSEventTypeGesture: 471 461 case NSEventTypeMagnify: -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxDockIconPreview.cpp
r16469 r17126 252 252 253 253 /* Process the content of any external OpenGL window. */ 254 WindowRef w = darwinTo WindowRef(mMainWnd);254 WindowRef w = darwinToNativeWindow (mMainWnd); 255 255 WindowGroupRef g = GetWindowGroup (w); 256 256 WindowGroupContentOptions wgco = kWindowGroupContentsReturnWindows | kWindowGroupContentsRecurse | kWindowGroupContentsVisible; -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-carbon.cpp
r17108 r17126 1 /* $Id$ */2 1 /** @file 3 * Qt GUI - Utility Classes and Functions specific to Darwin. 2 * 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * Declarations of utility classes and functions for handling Darwin Carbon 5 * specific tasks 4 6 */ 5 7 6 8 /* 7 * Copyright (C) 200 6-2007Sun Microsystems, Inc.9 * Copyright (C) 2009 Sun Microsystems, Inc. 8 10 * 9 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 22 */ 21 23 22 23 24 #include "VBoxUtils.h" 25 #include "VBoxFrameBuffer.h" 24 #include "VBoxUtils-darwin.h" 25 26 #include <iprt/assert.h> 27 28 #include <Carbon/Carbon.h> 29 30 NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView) 31 { 32 return reinterpret_cast<WindowRef> (::HIViewGetWindow (aView)); 33 } 34 35 void darwinSetShowsToolbarButtonImpl (NativeWindowRef aWindow, bool aEnabled) 36 { 37 int err = ::ChangeWindowAttributes (aWindow, aEnabled ? kWindowToolbarButtonAttribute:kWindowNoAttributes, 38 aEnabled ? kWindowNoAttributes:kWindowToolbarButtonAttribute); 39 AssertCarbonOSStatus (err); 40 } 41 42 void darwinSetMouseCoalescingEnabled (bool aEnabled) 43 { 44 ::SetMouseCoalescingEnabled (aEnabled, NULL); 45 } 46 47 48 49 50 51 /******************************************************************************** 52 * 53 * Old carbon stuff. Have to converted soon! 54 * 55 ********************************************************************************/ 26 56 #include "VBoxConsoleView.h" 27 28 #include <iprt/assert.h>29 #include <iprt/mem.h>30 31 #include <CoreFoundation/CFBundle.h>32 #include <Carbon/Carbon.h>33 34 /* Qt includes */35 #include <QImage>36 #include <QPixmap>37 #include <QPainter>38 #include <QApplication>39 #include <QToolBar>40 #include <QMainWindow>41 #include <QStatusBar>42 43 #if QT_VERSION < 0x04040044 extern void qt_mac_set_menubar_icons(bool b);45 #endif /* QT_VERSION < 0x040400 */46 47 #ifndef QT_MAC_USE_COCOA48 57 49 58 /** … … 111 120 } 112 121 113 #endif /* !QT_MAC_USE_COCOA */114 115 void darwinSetShowToolBarButton (QToolBar *aToolBar, bool aShow)116 {117 QWidget *parent = aToolBar->parentWidget();118 if (parent)119 {120 #ifdef QT_MAC_USE_COCOA121 /** @todo Carbon -> Cocoa */122 #else123 int err = ChangeWindowAttributes (::darwinToWindowRef (parent), aShow ? kWindowToolbarButtonAttribute:kWindowNoAttributes,124 aShow ? kWindowNoAttributes:kWindowToolbarButtonAttribute);125 AssertCarbonOSStatus (err);126 #endif127 }128 }129 130 122 void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget) 131 123 { 132 #ifdef QT_MAC_USE_COCOA133 /** @todo Carbon -> Cocoa */134 #else135 124 HIRect r = ::darwinToHIRect (aTarget); 136 TransitionWindowWithOptions (::darwinToWindowRef (aWidget), kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &r, false, NULL); 137 #endif 138 } 139 140 /* Proxy icon creation */ 141 QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText) 142 { 143 QFontMetrics fm (qApp->font()); 144 QRect tbRect = fm.boundingRect (aText); 145 const int h = qMax (aPixmap.height(), fm.ascent() + 1); 146 const int m = 2; 147 QPixmap dragPixmap (aPixmap.width() + tbRect.width() + m, h); 148 dragPixmap.fill (Qt::transparent); 149 QPainter painter (&dragPixmap); 150 painter.drawPixmap (0, qAbs (h - aPixmap.height()) / 2.0, aPixmap); 151 painter.setPen (Qt::white); 152 painter.drawText (QRect (aPixmap.width() + m, 1, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText); 153 painter.setPen (Qt::black); 154 painter.drawText (QRect (aPixmap.width() + m, 0, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText); 155 painter.end(); 156 return dragPixmap; 157 } 158 159 QString darwinSystemLanguage (void) 160 { 161 /* Get the locales supported by our bundle */ 162 CFArrayRef supportedLocales = CFBundleCopyBundleLocalizations (CFBundleGetMainBundle()); 163 /* Check them against the languages currently selected by the user */ 164 CFArrayRef preferredLocales = CFBundleCopyPreferredLocalizationsFromArray (supportedLocales); 165 /* Get the one which is on top */ 166 CFStringRef localeId = (CFStringRef)CFArrayGetValueAtIndex (preferredLocales, 0); 167 /* Convert them to a C-string */ 168 char localeName[20]; 169 CFStringGetCString (localeId, localeName, sizeof (localeName), kCFStringEncodingUTF8); 170 /* Some cleanup */ 171 CFRelease (supportedLocales); 172 CFRelease (preferredLocales); 173 QString id(localeName); 174 /* Check for some misbehavior */ 175 if (id.isEmpty() || 176 id.toLower() == "english") 177 id = "en"; 178 return id; 125 TransitionWindowWithOptions (::darwinToNativeWindow (aWidget), kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &r, false, NULL); 179 126 } 180 127 181 128 bool darwinIsMenuOpen (void) 182 129 { 183 #ifdef QT_MAC_USE_COCOA184 /** @todo Carbon -> Cocoa */185 return false;186 #else187 130 MenuTrackingData outData; 188 131 return (GetMenuTrackingData (NULL, &outData) != menuNotFoundErr); 189 #endif 190 } 191 192 void darwinDisableIconsInMenus (void) 193 { 194 /* No icons in the menu of a mac application. */ 195 #if QT_VERSION < 0x040400 196 qt_mac_set_menubar_icons (false); 197 #else /* QT_VERSION < 0x040400 */ 198 /* Available since Qt 4.4 only */ 199 QApplication::instance()->setAttribute (Qt::AA_DontShowIconsInMenus, true); 200 #endif /* QT_VERSION >= 0x040400 */ 201 } 202 203 #ifndef QT_MAC_USE_COCOA 132 } 204 133 205 134 /* Currently not used! */ … … 236 165 if (!pRegion->isEmpty() && pRegion) 237 166 { 238 CopyRgn (pRegion->handle(), rgn);167 //CopyRgn (pRegion->handle(), rgn); 239 168 status = noErr; 240 169 } … … 326 255 } 327 256 328 #endif /* !QT_MAC_USE_COCOA */329 330 331 /* Event debugging stuff. Borrowed from Knuts Qt patch. */332 #if defined (DEBUG)333 334 # define MY_CASE(a) case a: return #a335 const char * DarwinDebugEventName (UInt32 ekind)336 {337 switch (ekind)338 {339 # if !__LP64__340 MY_CASE(kEventWindowUpdate );341 MY_CASE(kEventWindowDrawContent );342 # endif343 MY_CASE(kEventWindowActivated );344 MY_CASE(kEventWindowDeactivated );345 MY_CASE(kEventWindowHandleActivate );346 MY_CASE(kEventWindowHandleDeactivate );347 MY_CASE(kEventWindowGetClickActivation );348 MY_CASE(kEventWindowGetClickModality );349 MY_CASE(kEventWindowShowing );350 MY_CASE(kEventWindowHiding );351 MY_CASE(kEventWindowShown );352 MY_CASE(kEventWindowHidden );353 MY_CASE(kEventWindowCollapsing );354 MY_CASE(kEventWindowCollapsed );355 MY_CASE(kEventWindowExpanding );356 MY_CASE(kEventWindowExpanded );357 MY_CASE(kEventWindowZoomed );358 MY_CASE(kEventWindowBoundsChanging );359 MY_CASE(kEventWindowBoundsChanged );360 MY_CASE(kEventWindowResizeStarted );361 MY_CASE(kEventWindowResizeCompleted );362 MY_CASE(kEventWindowDragStarted );363 MY_CASE(kEventWindowDragCompleted );364 MY_CASE(kEventWindowClosed );365 MY_CASE(kEventWindowTransitionStarted );366 MY_CASE(kEventWindowTransitionCompleted );367 # if !__LP64__368 MY_CASE(kEventWindowClickDragRgn );369 MY_CASE(kEventWindowClickResizeRgn );370 MY_CASE(kEventWindowClickCollapseRgn );371 MY_CASE(kEventWindowClickCloseRgn );372 MY_CASE(kEventWindowClickZoomRgn );373 MY_CASE(kEventWindowClickContentRgn );374 MY_CASE(kEventWindowClickProxyIconRgn );375 MY_CASE(kEventWindowClickToolbarButtonRgn );376 MY_CASE(kEventWindowClickStructureRgn );377 # endif378 MY_CASE(kEventWindowCursorChange );379 MY_CASE(kEventWindowCollapse );380 MY_CASE(kEventWindowCollapseAll );381 MY_CASE(kEventWindowExpand );382 MY_CASE(kEventWindowExpandAll );383 MY_CASE(kEventWindowClose );384 MY_CASE(kEventWindowCloseAll );385 MY_CASE(kEventWindowZoom );386 MY_CASE(kEventWindowZoomAll );387 MY_CASE(kEventWindowContextualMenuSelect );388 MY_CASE(kEventWindowPathSelect );389 MY_CASE(kEventWindowGetIdealSize );390 MY_CASE(kEventWindowGetMinimumSize );391 MY_CASE(kEventWindowGetMaximumSize );392 MY_CASE(kEventWindowConstrain );393 # if !__LP64__394 MY_CASE(kEventWindowHandleContentClick );395 # endif396 MY_CASE(kEventWindowGetDockTileMenu );397 MY_CASE(kEventWindowProxyBeginDrag );398 MY_CASE(kEventWindowProxyEndDrag );399 MY_CASE(kEventWindowToolbarSwitchMode );400 MY_CASE(kEventWindowFocusAcquired );401 MY_CASE(kEventWindowFocusRelinquish );402 MY_CASE(kEventWindowFocusContent );403 MY_CASE(kEventWindowFocusToolbar );404 MY_CASE(kEventWindowFocusDrawer );405 MY_CASE(kEventWindowSheetOpening );406 MY_CASE(kEventWindowSheetOpened );407 MY_CASE(kEventWindowSheetClosing );408 MY_CASE(kEventWindowSheetClosed );409 MY_CASE(kEventWindowDrawerOpening );410 MY_CASE(kEventWindowDrawerOpened );411 MY_CASE(kEventWindowDrawerClosing );412 MY_CASE(kEventWindowDrawerClosed );413 MY_CASE(kEventWindowDrawFrame );414 MY_CASE(kEventWindowDrawPart );415 MY_CASE(kEventWindowGetRegion );416 MY_CASE(kEventWindowHitTest );417 MY_CASE(kEventWindowInit );418 MY_CASE(kEventWindowDispose );419 MY_CASE(kEventWindowDragHilite );420 MY_CASE(kEventWindowModified );421 MY_CASE(kEventWindowSetupProxyDragImage );422 MY_CASE(kEventWindowStateChanged );423 MY_CASE(kEventWindowMeasureTitle );424 MY_CASE(kEventWindowDrawGrowBox );425 MY_CASE(kEventWindowGetGrowImageRegion );426 MY_CASE(kEventWindowPaint );427 }428 static char s_sz[64];429 sprintf(s_sz, "kind=%u", (uint)ekind);430 return s_sz;431 }432 # undef MY_CASE433 434 /* Convert a class into the 4 char code defined in435 * 'Developer/Headers/CFMCarbon/CarbonEvents.h' to436 * identify the event. */437 const char * darwinDebugClassName (UInt32 eclass)438 {439 char *pclass = (char*)&eclass;440 static char s_sz[11];441 sprintf(s_sz, "class=%c%c%c%c", pclass[3],442 pclass[2],443 pclass[1],444 pclass[0]);445 return s_sz;446 }447 448 void darwinDebugPrintEvent (const char *psz, EventRef evtRef)449 {450 if (!evtRef)451 return;452 UInt32 ekind = GetEventKind (evtRef), eclass = GetEventClass (evtRef);453 if (eclass == kEventClassWindow)454 {455 switch (ekind)456 {457 # if !__LP64__458 case kEventWindowDrawContent:459 case kEventWindowUpdate:460 # endif461 case kEventWindowBoundsChanged:462 break;463 default:464 {465 WindowRef wid = NULL;466 GetEventParameter(evtRef, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &wid);467 QWidget *widget = QWidget::find((WId)wid);468 printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName (eclass), (uint)ekind, wid, widget, DarwinDebugEventName (ekind));469 break;470 }471 }472 }473 else if (eclass == kEventClassCommand)474 {475 WindowRef wid = NULL;476 GetEventParameter(evtRef, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &wid);477 QWidget *widget = QWidget::find((WId)wid);478 const char *name = "Unknown";479 switch (ekind)480 {481 case kEventCommandProcess:482 name = "kEventCommandProcess";483 break;484 case kEventCommandUpdateStatus:485 name = "kEventCommandUpdateStatus";486 break;487 }488 printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName (eclass), (uint)ekind, wid, widget, name);489 }490 else if (eclass == kEventClassKeyboard)491 {492 printf("%d %s: %#x(%s) %#x (kEventClassKeyboard)", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName (eclass), (uint)ekind);493 494 UInt32 keyCode = 0;495 ::GetEventParameter (evtRef, kEventParamKeyCode, typeUInt32, NULL,496 sizeof (keyCode), NULL, &keyCode);497 printf(" keyCode=%d (%#x) ", keyCode, keyCode);498 499 char macCharCodes[8] = {0,0,0,0, 0,0,0,0};500 ::GetEventParameter (evtRef, kEventParamKeyCode, typeChar, NULL,501 sizeof (macCharCodes), NULL, &macCharCodes[0]);502 printf(" macCharCodes={");503 for (unsigned i =0; i < 8 && macCharCodes[i]; i++)504 printf( i == 0 ? "%02x" : ",%02x", macCharCodes[i]);505 printf("}");506 507 UInt32 modifierMask = 0;508 ::GetEventParameter (evtRef, kEventParamKeyModifiers, typeUInt32, NULL,509 sizeof (modifierMask), NULL, &modifierMask);510 printf(" modifierMask=%08x", modifierMask);511 512 UniChar keyUnicodes[8] = {0,0,0,0, 0,0,0,0};513 ::GetEventParameter (evtRef, kEventParamKeyUnicodes, typeUnicodeText, NULL,514 sizeof (keyUnicodes), NULL, &keyUnicodes[0]);515 printf(" keyUnicodes={");516 for (unsigned i =0; i < 8 && keyUnicodes[i]; i++)517 printf( i == 0 ? "%02x" : ",%02x", keyUnicodes[i]);518 printf("}");519 520 UInt32 keyboardType = 0;521 ::GetEventParameter (evtRef, kEventParamKeyboardType, typeUInt32, NULL,522 sizeof (keyboardType), NULL, &keyboardType);523 printf(" keyboardType=%08x", keyboardType);524 525 EventHotKeyID evtHotKeyId = {0,0};526 ::GetEventParameter (evtRef, typeEventHotKeyID, typeEventHotKeyID, NULL,527 sizeof (evtHotKeyId), NULL, &evtHotKeyId);528 printf(" evtHotKeyId={signature=%08x, .id=%08x}", evtHotKeyId.signature, evtHotKeyId.id);529 printf("\n");530 }531 else532 printf("%d %s: %#x(%s) %#x\n", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName (eclass), (uint)ekind);533 }534 535 #endif /* DEBUG */ -
trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp
r16691 r17126 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 */ 21 21 22 23 24 #include "VBoxUtils.h" 25 #include "VBoxFrameBuffer.h" 26 #include "VBoxConsoleView.h" 27 28 #include <iprt/assert.h> 29 #include <iprt/mem.h> 30 31 #include <CoreFoundation/CFBundle.h> 22 #include "VBoxUtils-darwin.h" 23 24 #include <QApplication> 25 #include <QWidget> 26 #include <QToolBar> 27 #include <QPainter> 28 #include <QPixmap> 29 32 30 #include <Carbon/Carbon.h> 33 34 /* Qt includes */35 #include <QImage>36 #include <QPixmap>37 #include <QPainter>38 #include <QApplication>39 #include <QToolBar>40 #include <QMainWindow>41 #include <QStatusBar>42 31 43 32 #if QT_VERSION < 0x040400 … … 45 34 #endif /* QT_VERSION < 0x040400 */ 46 35 47 #ifndef QT_MAC_USE_COCOA 48 49 /** 50 * Callback for deleting the QImage object when CGImageCreate is done 51 * with it (which is probably not until the returned CFGImageRef is released). 52 * 53 * @param info Pointer to the QImage. 54 */ 55 static void darwinDataProviderReleaseQImage (void *info, const void *, size_t) 56 { 57 QImage *qimg = (QImage *)info; 58 delete qimg; 59 } 60 61 /** 62 * Converts a QPixmap to a CGImage. 63 * 64 * @returns CGImageRef for the new image. (Remember to release it when finished with it.) 65 * @param aPixmap Pointer to the QPixmap instance to convert. 66 */ 67 CGImageRef darwinToCGImageRef (const QImage *aImage) 68 { 69 QImage *imageCopy = new QImage (*aImage); 70 /** @todo this code assumes 32-bit image input, the lazy bird convert image to 32-bit method is anything but optimal... */ 71 if (imageCopy->format() != QImage::Format_ARGB32) 72 *imageCopy = imageCopy->convertToFormat (QImage::Format_ARGB32); 73 Assert (!imageCopy->isNull()); 74 75 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); 76 CGDataProviderRef dp = CGDataProviderCreateWithData (imageCopy, aImage->bits(), aImage->numBytes(), darwinDataProviderReleaseQImage); 77 78 CGBitmapInfo bmpInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; 79 CGImageRef ir = CGImageCreate (imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs, 80 bmpInfo, dp, 0 /*decode */, 0 /* shouldInterpolate */, 81 kCGRenderingIntentDefault); 82 CGColorSpaceRelease (cs); 83 CGDataProviderRelease (dp); 84 85 Assert (ir); 86 return ir; 87 } 88 89 /** 90 * Converts a QPixmap to a CGImage. 91 * 92 * @returns CGImageRef for the new image. (Remember to release it when finished with it.) 93 * @param aPixmap Pointer to the QPixmap instance to convert. 94 */ 95 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap) 96 { 97 return aPixmap->toMacCGImageRef(); 98 } 99 100 /** 101 * Loads an image using Qt and converts it to a CGImage. 102 * 103 * @returns CGImageRef for the new image. (Remember to release it when finished with it.) 104 * @param aSource The source name. 105 */ 106 CGImageRef darwinToCGImageRef (const char *aSource) 107 { 108 QPixmap qpm (QString(":/") + aSource); 109 Assert (!qpm.isNull()); 110 return ::darwinToCGImageRef (&qpm); 111 } 112 113 #endif /* !QT_MAC_USE_COCOA */ 114 115 void darwinSetShowToolBarButton (QToolBar *aToolBar, bool aShow) 36 NativeViewRef darwinToNativeView (QWidget *aWidget) 37 { 38 return reinterpret_cast<NativeViewRef>(aWidget->winId()); 39 } 40 41 NativeWindowRef darwinToNativeWindow (QWidget *aWidget) 42 { 43 return darwinToNativeWindowImpl (::darwinToNativeView (aWidget)); 44 } 45 46 NativeWindowRef darwinToNativeWindow (NativeViewRef aView) 47 { 48 return darwinToNativeWindowImpl (aView); 49 } 50 51 void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled) 116 52 { 117 53 QWidget *parent = aToolBar->parentWidget(); 118 54 if (parent) 119 { 120 #ifdef QT_MAC_USE_COCOA 121 /** @todo Carbon -> Cocoa */ 122 #else 123 int err = ChangeWindowAttributes (::darwinToWindowRef (parent), aShow ? kWindowToolbarButtonAttribute:kWindowNoAttributes, 124 aShow ? kWindowNoAttributes:kWindowToolbarButtonAttribute); 125 AssertCarbonOSStatus (err); 126 #endif 127 } 128 } 129 130 void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget) 131 { 132 #ifdef QT_MAC_USE_COCOA 133 /** @todo Carbon -> Cocoa */ 134 #else 135 HIRect r = ::darwinToHIRect (aTarget); 136 TransitionWindowWithOptions (::darwinToWindowRef (aWidget), kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &r, false, NULL); 137 #endif 55 darwinSetShowsToolbarButtonImpl (::darwinToNativeWindow (parent), aEnabled); 56 } 57 58 QString darwinSystemLanguage (void) 59 { 60 /* Get the locales supported by our bundle */ 61 CFArrayRef supportedLocales = ::CFBundleCopyBundleLocalizations (::CFBundleGetMainBundle()); 62 /* Check them against the languages currently selected by the user */ 63 CFArrayRef preferredLocales = ::CFBundleCopyPreferredLocalizationsFromArray (supportedLocales); 64 /* Get the one which is on top */ 65 CFStringRef localeId = (CFStringRef)::CFArrayGetValueAtIndex (preferredLocales, 0); 66 /* Convert them to a C-string */ 67 char localeName[20]; 68 ::CFStringGetCString (localeId, localeName, sizeof (localeName), kCFStringEncodingUTF8); 69 /* Some cleanup */ 70 ::CFRelease (supportedLocales); 71 ::CFRelease (preferredLocales); 72 QString id(localeName); 73 /* Check for some misbehavior */ 74 if (id.isEmpty() || 75 id.toLower() == "english") 76 id = "en"; 77 return id; 78 } 79 80 void darwinDisableIconsInMenus (void) 81 { 82 /* No icons in the menu of a mac application. */ 83 #if QT_VERSION < 0x040400 84 qt_mac_set_menubar_icons (false); 85 #else /* QT_VERSION < 0x040400 */ 86 /* Available since Qt 4.4 only */ 87 QApplication::instance()->setAttribute (Qt::AA_DontShowIconsInMenus, true); 88 #endif /* QT_VERSION >= 0x040400 */ 138 89 } 139 90 … … 157 108 } 158 109 159 QString darwinSystemLanguage (void) 160 { 161 /* Get the locales supported by our bundle */ 162 CFArrayRef supportedLocales = CFBundleCopyBundleLocalizations (CFBundleGetMainBundle()); 163 /* Check them against the languages currently selected by the user */ 164 CFArrayRef preferredLocales = CFBundleCopyPreferredLocalizationsFromArray (supportedLocales); 165 /* Get the one which is on top */ 166 CFStringRef localeId = (CFStringRef)CFArrayGetValueAtIndex (preferredLocales, 0); 167 /* Convert them to a C-string */ 168 char localeName[20]; 169 CFStringGetCString (localeId, localeName, sizeof (localeName), kCFStringEncodingUTF8); 170 /* Some cleanup */ 171 CFRelease (supportedLocales); 172 CFRelease (preferredLocales); 173 QString id(localeName); 174 /* Check for some misbehavior */ 175 if (id.isEmpty() || 176 id.toLower() == "english") 177 id = "en"; 178 return id; 179 } 180 181 bool darwinIsMenuOpen (void) 182 { 183 #ifdef QT_MAC_USE_COCOA 184 /** @todo Carbon -> Cocoa */ 185 return false; 186 #else 187 MenuTrackingData outData; 188 return (GetMenuTrackingData (NULL, &outData) != menuNotFoundErr); 189 #endif 190 } 191 192 void darwinDisableIconsInMenus (void) 193 { 194 /* No icons in the menu of a mac application. */ 195 #if QT_VERSION < 0x040400 196 qt_mac_set_menubar_icons (false); 197 #else /* QT_VERSION < 0x040400 */ 198 /* Available since Qt 4.4 only */ 199 QApplication::instance()->setAttribute (Qt::AA_DontShowIconsInMenus, true); 200 #endif /* QT_VERSION >= 0x040400 */ 201 } 202 203 #ifndef QT_MAC_USE_COCOA 204 205 /* Currently not used! */ 206 OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData) 207 { 208 NOREF (aInHandlerCallRef); 209 210 OSStatus status = eventNotHandledErr; 211 212 switch (GetEventKind (aInEvent)) 213 { 214 case kEventWindowGetRegion: 215 { 216 WindowRegionCode code; 217 RgnHandle rgn; 218 219 /* which region code is being queried? */ 220 GetEventParameter (aInEvent, kEventParamWindowRegionCode, typeWindowRegionCode, NULL, sizeof (code), NULL, &code); 221 222 /* if it is the opaque region code then set the region to Empty and return noErr to stop the propagation */ 223 if (code == kWindowOpaqueRgn) 224 { 225 printf("test1\n"); 226 GetEventParameter (aInEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof (rgn), NULL, &rgn); 227 SetEmptyRgn (rgn); 228 status = noErr; 229 } 230 /* if the content of the whole window is queried return a copy of our saved region. */ 231 else if (code == (kWindowStructureRgn))// || kWindowGlobalPortRgn || kWindowUpdateRgn)) 232 { 233 printf("test2\n"); 234 GetEventParameter (aInEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof (rgn), NULL, &rgn); 235 QRegion *pRegion = static_cast <QRegion*> (aInUserData); 236 if (!pRegion->isEmpty() && pRegion) 237 { 238 CopyRgn (pRegion->handle(), rgn); 239 status = noErr; 240 } 241 } 242 break; 243 } 244 case kEventControlDraw: 245 { 246 printf("test3\n"); 247 CGContextRef ctx; 248 HIRect bounds; 249 250 GetEventParameter (aInEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (ctx), NULL, &ctx); 251 HIViewGetBounds ((HIViewRef)aInUserData, &bounds); 252 253 CGContextClearRect (ctx, bounds); 254 status = noErr; 255 break; 256 } 257 } 258 259 return status; 260 } 261 262 OSStatus darwinOverlayWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData) 263 { 264 if (!aInUserData) 265 return ::CallNextEventHandler (aInHandlerCallRef, aInEvent); 266 267 UInt32 eventClass = ::GetEventClass (aInEvent); 268 UInt32 eventKind = ::GetEventKind (aInEvent); 269 /* For debugging events */ 270 /* 271 if (!(eventClass == 'cute')) 272 ::darwinDebugPrintEvent ("view: ", aInEvent); 273 */ 274 VBoxConsoleView *view = static_cast<VBoxConsoleView *> (aInUserData); 275 276 if (eventClass == kEventClassVBox) 277 { 278 if (eventKind == kEventVBoxShowWindow) 279 { 280 // printf ("ShowWindow requested\n"); 281 WindowRef w; 282 if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr) 283 return noErr; 284 ShowWindow (w); 285 SelectWindow (w); 286 return noErr; 287 } 288 if (eventKind == kEventVBoxMoveWindow) 289 { 290 // printf ("MoveWindow requested\n"); 291 WindowPtr w; 292 if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr) 293 return noErr; 294 HIPoint p; 295 if (GetEventParameter (aInEvent, kEventParamOrigin, typeHIPoint, NULL, sizeof (p), NULL, &p) != noErr) 296 return noErr; 297 ChangeWindowGroupAttributes (GetWindowGroup (w), 0, kWindowGroupAttrMoveTogether); 298 QPoint p1 = view->mapToGlobal (QPoint (p.x, p.y)); 299 MoveWindow (w, p1.x(), p1.y(), true); 300 ChangeWindowGroupAttributes (GetWindowGroup (w), kWindowGroupAttrMoveTogether, 0); 301 return noErr; 302 } 303 if (eventKind == kEventVBoxResizeWindow) 304 { 305 // printf ("ResizeWindow requested\n"); 306 WindowPtr w; 307 if (GetEventParameter (aInEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof (w), NULL, &w) != noErr) 308 return noErr; 309 HISize s; 310 if (GetEventParameter (aInEvent, kEventParamDimensions, typeHISize, NULL, sizeof (s), NULL, &s) != noErr) 311 return noErr; 312 ChangeWindowGroupAttributes (GetWindowGroup (w), 0, kWindowGroupAttrMoveTogether); 313 SizeWindow (w, s.width, s.height, true); 314 ChangeWindowGroupAttributes (GetWindowGroup (w), kWindowGroupAttrMoveTogether, 0); 315 return noErr; 316 } 317 if (eventKind == kEventVBoxUpdateDock) 318 { 319 // printf ("UpdateDock requested\n"); 320 view->updateDockIcon(); 321 return noErr; 322 } 323 } 324 325 return ::CallNextEventHandler (aInHandlerCallRef, aInEvent); 326 } 327 328 #endif /* !QT_MAC_USE_COCOA */ 329 110 111 /******************************************************************************** 112 * 113 * Old carbon stuff. Have to converted soon! 114 * 115 ********************************************************************************/ 330 116 331 117 /* Event debugging stuff. Borrowed from Knuts Qt patch. */ … … 534 320 535 321 #endif /* DEBUG */ 322
Note:
See TracChangeset
for help on using the changeset viewer.