- Timestamp:
- Feb 24, 2010 11:10:57 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r26729 r26730 157 157 } 158 158 return view; 159 }160 161 void UIMachineView::onViewOpened()162 {163 /* Variable m_bIsMachineWindowResizeIgnored was initially "true" to ignore QT164 * initial resize event in case of auto-resize feature is on.165 * Currently, initial resize event is already processed, so we set166 * m_bIsMachineWindowResizeIgnored to "false" to process all further resize167 * events as user-initiated window resize events. */168 m_bIsMachineWindowResizeIgnored = false;169 }170 171 int UIMachineView::contentsX() const172 {173 return horizontalScrollBar()->value();174 }175 176 int UIMachineView::contentsY() const177 {178 return verticalScrollBar()->value();179 }180 181 QRect UIMachineView::desktopGeometry() const182 {183 QRect rc;184 switch (mDesktopGeo)185 {186 case DesktopGeo_Fixed:187 case DesktopGeo_Automatic:188 rc = QRect(0, 0,189 qMax(mDesktopGeometry.width(), mStoredConsoleSize.width()),190 qMax(mDesktopGeometry.height(), mStoredConsoleSize.height()));191 break;192 case DesktopGeo_Any:193 rc = QRect(0, 0, 0, 0);194 break;195 default:196 AssertMsgFailed(("Bad geometry type %d\n", mDesktopGeo));197 }198 return rc;199 }200 201 void UIMachineView::setIgnoreGuestResize(bool bIgnore)202 {203 m_bIsGuestResizeIgnored = bIgnore;204 159 } 205 160 … … 285 240 , mHideHostPointer (true) 286 241 { 287 Assert (!m_console.isNull() && !m_console.GetDisplay().isNull() && !m_console.GetKeyboard().isNull() && !m_console.GetMouse().isNull());288 289 #ifdef Q_WS_MAC290 /* Overlay logo for the dock icon */291 //mVirtualBoxLogo = ::darwinToCGImageRef("VirtualBox_cube_42px.png");292 QString osTypeId = m_console.GetGuest().GetOSTypeId();293 294 // TODO_NEW_CORE295 // mDockIconPreview = new VBoxDockIconPreview(machineWindowWrapper(), vboxGlobal().vmGuestOSTypeIcon (osTypeId));296 297 # ifdef QT_MAC_USE_COCOA298 /** @todo Carbon -> Cocoa */299 # else /* !QT_MAC_USE_COCOA */300 /* Install the event handler which will proceed external window handling */301 EventHandlerUPP eventHandler = ::NewEventHandlerUPP(::darwinOverlayWindowHandler);302 EventTypeSpec eventTypes[] =303 {304 { kEventClassVBox, kEventVBoxShowWindow },305 { kEventClassVBox, kEventVBoxHideWindow },306 { kEventClassVBox, kEventVBoxMoveWindow },307 { kEventClassVBox, kEventVBoxResizeWindow },308 { kEventClassVBox, kEventVBoxDisposeWindow },309 { kEventClassVBox, kEventVBoxUpdateDock }310 };311 312 mDarwinWindowOverlayHandlerRef = NULL;313 ::InstallApplicationEventHandler(eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0], this, &mDarwinWindowOverlayHandlerRef);314 ::DisposeEventHandlerUPP(eventHandler);315 # endif /* !QT_MAC_USE_COCOA */316 #endif /* QT_WS_MAC */317 318 /* No frame around the view */319 setFrameStyle(QFrame::NoFrame);320 321 #ifdef VBOX_GUI_USE_QGL322 QWidget *pViewport;323 switch (mode)324 {325 // TODO: Fix that!326 //case VBoxDefs::QGLMode:327 // pViewport = new VBoxGLWidget(this, this, NULL);328 // break;329 default:330 pViewport = new VBoxViewport(this);331 }332 #else333 VBoxViewport *pViewport = new VBoxViewport(this);334 #endif335 setViewport(pViewport);336 // pViewport->vboxDoInit();337 338 /* enable MouseMove events */339 viewport()->setMouseTracking(true);340 341 /*342 * QScrollView does the below on its own, but let's do it anyway343 * for the case it will not do it in the future.344 */345 viewport()->installEventFilter(this);346 347 /* to fix some focus issues */348 // TODO: Fix that!349 //machineWindowWrapper()->menuBar()->installEventFilter(this);350 351 /* we want to be notified on some parent's events */352 machineWindowWrapper()->machineWindow()->installEventFilter(this);353 354 #ifdef Q_WS_X11355 /* initialize the X keyboard subsystem */356 initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes"));357 #endif358 359 ::memset(mPressedKeys, 0, sizeof(mPressedKeys));360 361 /* setup rendering */362 363 CDisplay display = m_console.GetDisplay();364 Assert(!display.isNull());365 366 mFrameBuf = NULL;367 368 LogFlowFunc(("Rendering mode: %d\n", mode));369 370 switch (mode)371 {372 #if defined (VBOX_GUI_USE_QGL)373 // TODO: Fix that!374 // case VBoxDefs::QGLMode:375 // mFrameBuf = new VBoxQGLFrameBuffer(this);376 // break;377 // case VBoxDefs::QGLOverlayMode:378 // mFrameBuf = new VBoxQGLOverlayFrameBuffer(this);379 // break;380 #endif381 #if defined (VBOX_GUI_USE_QIMAGE)382 case VBoxDefs::QImageMode:383 mFrameBuf =384 #ifdef VBOX_WITH_VIDEOHWACCEL385 // mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UIFrameBufferQImage>(this, &machineWindowWrapper()->session()) :386 #endif387 new UIFrameBufferQImage(this);388 break;389 #endif390 #if defined (VBOX_GUI_USE_SDL)391 case VBoxDefs::SDLMode:392 /* Indicate that we are doing all393 * drawing stuff ourself */394 pViewport->setAttribute(Qt::WA_PaintOnScreen);395 # ifdef Q_WS_X11396 /* This is somehow necessary to prevent strange X11 warnings on397 * i386 and segfaults on x86_64. */398 XFlush(QX11Info::display());399 # endif400 // mFrameBuf =401 #if defined(VBOX_WITH_VIDEOHWACCEL) && defined(DEBUG_misha) /* not tested yet */402 // mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxSDLFrameBuffer> (this, &machineWindowWrapper()->session()) :403 #endif404 // new VBoxSDLFrameBuffer(this);405 /*406 * disable scrollbars because we cannot correctly draw in a407 * scrolled window using SDL408 */409 horizontalScrollBar()->setEnabled(false);410 verticalScrollBar()->setEnabled(false);411 break;412 #endif413 #if defined (VBOX_GUI_USE_DDRAW)414 case VBoxDefs::DDRAWMode:415 mFrameBuf = new VBoxDDRAWFrameBuffer(this);416 break;417 #endif418 #if defined (VBOX_GUI_USE_QUARTZ2D)419 case VBoxDefs::Quartz2DMode:420 /* Indicate that we are doing all421 * drawing stuff ourself */422 pViewport->setAttribute(Qt::WA_PaintOnScreen);423 // mFrameBuf =424 #ifdef VBOX_WITH_VIDEOHWACCEL425 // TODO_NEW_CORE426 // mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) :427 #endif428 // new UIFrameBufferQuartz2D(this);429 break;430 #endif431 default:432 AssertReleaseMsgFailed(("Render mode must be valid: %d\n", mode));433 LogRel (("Invalid render mode: %d\n", mode));434 qApp->exit (1);435 break;436 }437 438 #if defined (VBOX_GUI_USE_DDRAW)439 if (!mFrameBuf || mFrameBuf->address() == NULL)440 {441 if (mFrameBuf)442 delete mFrameBuf;443 mode = VBoxDefs::QImageMode;444 mFrameBuf = new UIFrameBufferQImage(this);445 }446 #endif447 448 if (mFrameBuf)449 {450 mFrameBuf->AddRef();451 display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(mFrameBuf));452 }453 454 QPalette palette(viewport()->palette());455 palette.setColor(viewport()->backgroundRole(), Qt::black);456 viewport()->setPalette(palette);457 458 setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));459 setMaximumSize(sizeHint());460 461 setFocusPolicy(Qt::WheelFocus);462 463 /* Remember the desktop geometry and register for geometry change464 events for telling the guest about video modes we like. */465 466 QString desktopGeometry = vboxGlobal().settings().publicProperty("GUI/MaxGuestResolution");467 if ((desktopGeometry == QString::null) || (desktopGeometry == "auto"))468 setDesktopGeometry(DesktopGeo_Automatic, 0, 0);469 else if (desktopGeometry == "any")470 setDesktopGeometry(DesktopGeo_Any, 0, 0);471 else472 {473 int width = desktopGeometry.section(',', 0, 0).toInt();474 int height = desktopGeometry.section(',', 1, 1).toInt();475 setDesktopGeometry(DesktopGeo_Fixed, width, height);476 }477 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(doResizeDesktop(int)));478 479 QString passCAD = m_console.GetMachine().GetExtraData(VBoxDefs::GUI_PassCAD);480 if (!passCAD.isEmpty() && ((passCAD != "false") || (passCAD != "no")))481 mPassCAD = true;482 483 #if defined (Q_WS_WIN)484 gView = this;485 #endif486 487 #if defined (Q_WS_PM)488 bool ok = VBoxHlpInstallKbdHook(0, winId(), UM_PREACCEL_CHAR);489 Assert (ok);490 NOREF (ok);491 #endif492 493 #ifdef Q_WS_MAC494 /* Dock icon update connection */495 connect(&vboxGlobal(), SIGNAL(dockIconUpdateChanged(const VBoxChangeDockIconUpdateEvent &)),496 this, SLOT(sltChangeDockIconUpdate(const VBoxChangeDockIconUpdateEvent &)));497 /* Presentation Mode connection */498 connect(&vboxGlobal(), SIGNAL(presentationModeChanged(const VBoxChangePresentationModeEvent &)),499 this, SLOT(sltChangePresentationMode(const VBoxChangePresentationModeEvent &)));500 #endif501 242 } 502 243 503 244 UIMachineView::~UIMachineView() 504 245 { 505 #if 0506 #if defined (Q_WS_PM)507 bool ok = VBoxHlpUninstallKbdHook(0, winId(), UM_PREACCEL_CHAR);508 Assert (ok);509 NOREF (ok);510 #endif511 512 #if defined (Q_WS_WIN)513 if (gKbdHook)514 UnhookWindowsHookEx(gKbdHook);515 gView = 0;516 if (mAlphaCursor)517 DestroyIcon(mAlphaCursor);518 #endif519 520 if (mFrameBuf)521 {522 /* detach our framebuffer from Display */523 CDisplay display = m_console.GetDisplay();524 Assert(!display.isNull());525 display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(NULL));526 /* release the reference */527 mFrameBuf->Release();528 mFrameBuf = NULL;529 }530 531 #if defined (Q_WS_MAC)532 # if !defined (QT_MAC_USE_COCOA)533 if (mDarwinWindowOverlayHandlerRef)534 {535 ::RemoveEventHandler(mDarwinWindowOverlayHandlerRef);536 mDarwinWindowOverlayHandlerRef = NULL;537 }538 # endif539 delete mDockIconPreview;540 mDockIconPreview = NULL;541 #endif542 #endif543 }544 545 void UIMachineView::calculateDesktopGeometry()546 {547 /* This method should not get called until we have initially set up the */548 Assert((mDesktopGeo != DesktopGeo_Invalid));549 /* If we are not doing automatic geometry calculation then there is nothing to do. */550 if (DesktopGeo_Automatic == mDesktopGeo)551 {552 /* Available geometry of the desktop. If the desktop is a single553 * screen, this will exclude space taken up by desktop taskbars554 * and things, but this is unfortunately not true for the more555 * complex case of a desktop spanning multiple screens. */556 QRect desktop = availableGeometry();557 /* The area taken up by the console window on the desktop,558 * including window frame, title and menu bar and whatnot. */559 QRect frame = machineWindowWrapper()->machineWindow()->frameGeometry();560 /* The area taken up by the console window, minus all decorations. */561 //QRect window = machineWindowWrapper()->centralWidget()->geometry(); // TODO check that!562 /* To work out how big we can make the console window while still563 * fitting on the desktop, we calculate desktop - frame + window.564 * This works because the difference between frame and window565 * (or at least its width and height) is a constant. */566 //mDesktopGeometry = QRect(0, 0, desktop.width() - frame.width() + window.width(),567 // desktop.height() - frame.height() + window.height());568 }569 246 } 570 247 … … 584 261 } 585 262 263 int UIMachineView::contentsX() const 264 { 265 return horizontalScrollBar()->value(); 266 } 267 268 int UIMachineView::contentsY() const 269 { 270 return verticalScrollBar()->value(); 271 } 272 273 int UIMachineView::contentsWidth() const 274 { 275 return mFrameBuf->width(); 276 } 277 278 int UIMachineView::contentsHeight() const 279 { 280 return mFrameBuf->height(); 281 } 282 283 int UIMachineView::visibleWidth() const 284 { 285 return horizontalScrollBar()->pageStep(); 286 } 287 288 int UIMachineView::visibleHeight() const 289 { 290 return verticalScrollBar()->pageStep(); 291 } 292 293 void UIMachineView::calculateDesktopGeometry() 294 { 295 /* This method should not get called until we have initially set up the mDesktopGeo: */ 296 Assert((mDesktopGeo != DesktopGeo_Invalid)); 297 /* If we are not doing automatic geometry calculation then there is nothing to do: */ 298 if (DesktopGeo_Automatic == mDesktopGeo) 299 { 300 /* Available geometry of the desktop. If the desktop is a single 301 * screen, this will exclude space taken up by desktop taskbars 302 * and things, but this is unfortunately not true for the more 303 * complex case of a desktop spanning multiple screens: */ 304 QRect desktop = availableGeometry(); 305 /* The area taken up by the console window on the desktop, 306 * including window frame, title and menu bar and whatnot. */ 307 QRect frame = machineWindowWrapper()->machineWindow()->frameGeometry(); 308 /* The area taken up by the console window, minus all decorations. */ 309 QRect window = geometry(); 310 /* To work out how big we can make the console window while still 311 * fitting on the desktop, we calculate desktop - frame + window. 312 * This works because the difference between frame and window 313 * (or at least its width and height) is a constant. */ 314 mDesktopGeometry = QRect(0, 0, desktop.width() - frame.width() + window.width(), 315 desktop.height() - frame.height() + window.height()); 316 } 317 } 318 319 QRect UIMachineView::desktopGeometry() const 320 { 321 QRect rc; 322 switch (mDesktopGeo) 323 { 324 case DesktopGeo_Fixed: 325 case DesktopGeo_Automatic: 326 rc = QRect(0, 0, 327 qMax(mDesktopGeometry.width(), mStoredConsoleSize.width()), 328 qMax(mDesktopGeometry.height(), mStoredConsoleSize.height())); 329 break; 330 case DesktopGeo_Any: 331 rc = QRect(0, 0, 0, 0); 332 break; 333 default: 334 AssertMsgFailed(("Bad geometry type %d\n", mDesktopGeo)); 335 } 336 return rc; 337 } 338 339 void UIMachineView::prepareFrameBuffer() 340 { 341 CDisplay display = m_console.GetDisplay(); 342 Assert(!display.isNull()); 343 mFrameBuf = NULL; 344 345 switch (mode) 346 { 347 #if defined (VBOX_GUI_USE_QIMAGE) 348 case VBoxDefs::QImageMode: 349 #if 0 // TODO: Enable QImage + Video Acceleration! 350 # ifdef VBOX_WITH_VIDEOHWACCEL 351 mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UIFrameBufferQImage>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQImage(this); 352 # else 353 mFrameBuf = new UIFrameBufferQImage(this); 354 # endif 355 #endif 356 mFrameBuf = new UIFrameBufferQImage(this); 357 break; 358 #endif 359 #if 0 // TODO: Enable OpenGL frame buffer! 360 #if defined (VBOX_GUI_USE_QGL) 361 case VBoxDefs::QGLMode: 362 mFrameBuf = new UIQGLFrameBuffer(this); 363 break; 364 case VBoxDefs::QGLOverlayMode: 365 mFrameBuf = new UIQGLOverlayFrameBuffer(this); 366 break; 367 #endif 368 #endif 369 #if 0 // TODO: Enable SDL frame buffer! 370 #if defined (VBOX_GUI_USE_SDL) 371 case VBoxDefs::SDLMode: 372 /* Indicate that we are doing all drawing stuff ourself: */ 373 pViewport->setAttribute(Qt::WA_PaintOnScreen); 374 # ifdef Q_WS_X11 375 /* This is somehow necessary to prevent strange X11 warnings on i386 and segfaults on x86_64: */ 376 XFlush(QX11Info::display()); 377 # endif 378 # if defined(VBOX_WITH_VIDEOHWACCEL) && defined(DEBUG_misha) /* not tested yet */ 379 mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UISDLFrameBuffer> (this, &machineWindowWrapper()->session()) : new UISDLFrameBuffer(this); 380 # else 381 mFrameBuf = new UISDLFrameBuffer(this); 382 # endif 383 /* Disable scrollbars because we cannot correctly draw in a scrolled window using SDL: */ 384 horizontalScrollBar()->setEnabled(false); 385 verticalScrollBar()->setEnabled(false); 386 break; 387 #endif 388 #endif 389 #if 0 // TODO: Enable DDraw frame buffer! 390 #if defined (VBOX_GUI_USE_DDRAW) 391 case VBoxDefs::DDRAWMode: 392 mFrameBuf = new UIDDRAWFrameBuffer(this); 393 if (!mFrameBuf || mFrameBuf->address() == NULL) 394 { 395 if (mFrameBuf) 396 delete mFrameBuf; 397 mode = VBoxDefs::QImageMode; 398 mFrameBuf = new UIFrameBufferQImage(this); 399 } 400 break; 401 #endif 402 #endif 403 #if 0 // TODO: Enable Quartz2D frame buffer! 404 #if defined (VBOX_GUI_USE_QUARTZ2D) 405 case VBoxDefs::Quartz2DMode: 406 /* Indicate that we are doing all drawing stuff ourself: */ 407 pViewport->setAttribute(Qt::WA_PaintOnScreen); 408 # ifdef VBOX_WITH_VIDEOHWACCEL 409 mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQuartz2D(this); 410 # else 411 mFrameBuf = new UIFrameBufferQuartz2D(this); 412 # endif 413 break; 414 #endif 415 #endif 416 default: 417 AssertReleaseMsgFailed(("Render mode must be valid: %d\n", mode)); 418 LogRel(("Invalid render mode: %d\n", mode)); 419 qApp->exit(1); 420 break; 421 } 422 if (mFrameBuf) 423 { 424 mFrameBuf->AddRef(); 425 display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(mFrameBuf)); 426 } 427 } 428 429 void UIMachineView::prepareCommon() 430 { 431 /* Prepare view frame: */ 432 setFrameStyle(QFrame::NoFrame); 433 434 /* Pressed keys: */ 435 ::memset(mPressedKeys, 0, sizeof(mPressedKeys)); 436 437 /* Prepare viewport: */ 438 #ifdef VBOX_GUI_USE_QGL 439 QWidget *pViewport; 440 switch (mode) 441 { 442 #if 0 // TODO: Create Open GL viewport! 443 case VBoxDefs::QGLMode: 444 pViewport = new VBoxGLWidget(this, this, NULL); 445 break; 446 #endif 447 default: 448 pViewport = new VBoxViewport(this); 449 } 450 #else 451 VBoxViewport *pViewport = new VBoxViewport(this); 452 #endif 453 setViewport(pViewport); 454 455 /* Setup palette: */ 456 QPalette palette(viewport()->palette()); 457 palette.setColor(viewport()->backgroundRole(), Qt::black); 458 viewport()->setPalette(palette); 459 460 /* Setup size-policy: */ 461 setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); 462 setMaximumSize(sizeHint()); 463 464 /* Setup focus policy: */ 465 setFocusPolicy(Qt::WheelFocus); 466 467 #if defined Q_WS_WIN 468 gView = this; 469 #endif 470 471 #if defined Q_WS_PM 472 bool ok = VBoxHlpInstallKbdHook(0, winId(), UM_PREACCEL_CHAR); 473 Assert(ok); 474 NOREF(ok); 475 #endif 476 477 #if defined Q_WS_MAC 478 /* Dock icon update connection */ 479 connect(&vboxGlobal(), SIGNAL(dockIconUpdateChanged(const VBoxChangeDockIconUpdateEvent &)), 480 this, SLOT(sltChangeDockIconUpdate(const VBoxChangeDockIconUpdateEvent &))); 481 /* Presentation Mode connection */ 482 connect(&vboxGlobal(), SIGNAL(presentationModeChanged(const VBoxChangePresentationModeEvent &)), 483 this, SLOT(sltChangePresentationMode(const VBoxChangePresentationModeEvent &))); 484 485 /* Overlay logo for the dock icon */ 486 //mVirtualBoxLogo = ::darwinToCGImageRef("VirtualBox_cube_42px.png"); 487 QString osTypeId = m_console.GetGuest().GetOSTypeId(); 488 489 // TODO_NEW_CORE 490 // mDockIconPreview = new VBoxDockIconPreview(machineWindowWrapper(), vboxGlobal().vmGuestOSTypeIcon (osTypeId)); 491 492 # ifdef QT_MAC_USE_COCOA 493 /** @todo Carbon -> Cocoa */ 494 # else /* !QT_MAC_USE_COCOA */ 495 /* Install the event handler which will proceed external window handling */ 496 EventHandlerUPP eventHandler = ::NewEventHandlerUPP(::darwinOverlayWindowHandler); 497 EventTypeSpec eventTypes[] = 498 { 499 { kEventClassVBox, kEventVBoxShowWindow }, 500 { kEventClassVBox, kEventVBoxHideWindow }, 501 { kEventClassVBox, kEventVBoxMoveWindow }, 502 { kEventClassVBox, kEventVBoxResizeWindow }, 503 { kEventClassVBox, kEventVBoxDisposeWindow }, 504 { kEventClassVBox, kEventVBoxUpdateDock } 505 }; 506 507 mDarwinWindowOverlayHandlerRef = NULL; 508 ::InstallApplicationEventHandler(eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0], this, &mDarwinWindowOverlayHandlerRef); 509 ::DisposeEventHandlerUPP(eventHandler); 510 # endif /* !QT_MAC_USE_COCOA */ 511 #endif 512 } 513 514 void UIMachineView::prepareFilters() 515 { 516 /* Enable MouseMove events: */ 517 viewport()->setMouseTracking(true); 518 519 /* QScrollView does the below on its own, but let's 520 * do it anyway for the case it will not do it in the future: */ 521 viewport()->installEventFilter(this); 522 523 /* To fix some focus issues: */ 524 //qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->menuBar()->installEventFilter(this); 525 526 /* We want to be notified on some parent's events: */ 527 machineWindowWrapper()->machineWindow()->installEventFilter(this); 528 } 529 530 void UIMachineView::loadMachineViewSettings() 531 { 532 /* Global settings: */ 533 { 534 /* Remember the desktop geometry and register for geometry 535 * change events for telling the guest about video modes we like: */ 536 QString desktopGeometry = vboxGlobal().settings().publicProperty("GUI/MaxGuestResolution"); 537 if ((desktopGeometry == QString::null) || (desktopGeometry == "auto")) 538 setDesktopGeometry(DesktopGeo_Automatic, 0, 0); 539 else if (desktopGeometry == "any") 540 setDesktopGeometry(DesktopGeo_Any, 0, 0); 541 else 542 { 543 int width = desktopGeometry.section(',', 0, 0).toInt(); 544 int height = desktopGeometry.section(',', 1, 1).toInt(); 545 setDesktopGeometry(DesktopGeo_Fixed, width, height); 546 } 547 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(doResizeDesktop(int))); 548 549 #ifdef Q_WS_X11 550 /* Initialize the X keyboard subsystem: */ 551 initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes")); 552 #endif 553 } 554 555 /* Exatra data settings: */ 556 { 557 /* CAD settings: */ 558 QString passCAD = m_console.GetMachine().GetExtraData(VBoxDefs::GUI_PassCAD); 559 if (!passCAD.isEmpty() && ((passCAD != "false") || (passCAD != "no"))) 560 mPassCAD = true; 561 } 562 } 563 564 void UIMachineView::cleanupCommon() 565 { 566 #if defined (Q_WS_PM) 567 bool ok = VBoxHlpUninstallKbdHook(0, winId(), UM_PREACCEL_CHAR); 568 Assert(ok); 569 NOREF(ok); 570 #endif 571 572 #if defined (Q_WS_WIN) 573 if (gKbdHook) 574 UnhookWindowsHookEx(gKbdHook); 575 gView = 0; 576 if (mAlphaCursor) 577 DestroyIcon(mAlphaCursor); 578 #endif 579 580 #if defined (Q_WS_MAC) 581 # if !defined (QT_MAC_USE_COCOA) 582 if (mDarwinWindowOverlayHandlerRef) 583 { 584 ::RemoveEventHandler(mDarwinWindowOverlayHandlerRef); 585 mDarwinWindowOverlayHandlerRef = NULL; 586 } 587 # endif 588 delete mDockIconPreview; 589 mDockIconPreview = NULL; 590 #endif 591 } 592 593 void UIMachineView::cleanupFrameBuffer() 594 { 595 /* Cleanup: */ 596 if (mFrameBuf) 597 { 598 /* Detach framebuffer from Display: */ 599 CDisplay display = console().GetDisplay(); 600 display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(NULL)); 601 /* Release the reference: */ 602 mFrameBuf->Release(); 603 mFrameBuf = NULL; 604 } 605 } 606 586 607 #ifdef Q_WS_MAC 587 608 void UIMachineView::sltChangeDockIconUpdate(const VBoxChangeDockIconUpdateEvent &event) … … 617 638 # endif /* QT_MAC_USE_COCOA */ 618 639 #endif 619 620 int UIMachineView::contentsWidth() const621 {622 return mFrameBuf->width();623 }624 625 int UIMachineView::contentsHeight() const626 {627 return mFrameBuf->height();628 }629 630 int UIMachineView::visibleWidth() const631 {632 return horizontalScrollBar()->pageStep();633 }634 635 int UIMachineView::visibleHeight() const636 {637 return verticalScrollBar()->pageStep();638 }639 640 640 641 bool UIMachineView::event(QEvent *e) … … 2509 2510 #endif 2510 2511 2511 #if defined(Q_WS_MAC)2512 void UIMachineView::updateDockIcon()2513 {2514 if (mDockIconEnabled)2515 {2516 if (!mPausedShot.isNull())2517 {2518 CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot);2519 /* Use the pause image as background */2520 mDockIconPreview->updateDockPreview (pauseImg);2521 CGImageRelease (pauseImg);2522 }2523 else2524 {2525 # if defined (VBOX_GUI_USE_QUARTZ2D)2526 // TODO_NEW_CORE2527 // if (mode == VBoxDefs::Quartz2DMode)2528 // {2529 /* If the render mode is Quartz2D we could use the CGImageRef2530 * of the framebuffer for the dock icon creation. This saves2531 * some conversion time. */2532 // mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef());2533 // }2534 // else2535 # endif2536 /* In image mode we have to create the image ref out of the2537 * framebuffer */2538 // TODO_NEW_CORE2539 // mDockIconPreview->updateDockPreview (mFrameBuf);2540 }2541 }2542 }2543 2544 void UIMachineView::updateDockOverlay()2545 {2546 /* Only to an update to the realtime preview if this is enabled by the user2547 * & we are in an state where the framebuffer is likely valid. Otherwise to2548 * the overlay stuff only. */2549 if (mDockIconEnabled &&2550 (mLastState == KMachineState_Running ||2551 mLastState == KMachineState_Paused ||2552 mLastState == KMachineState_Teleporting ||2553 mLastState == KMachineState_LiveSnapshotting ||2554 mLastState == KMachineState_Restoring ||2555 mLastState == KMachineState_TeleportingPausedVM ||2556 mLastState == KMachineState_TeleportingIn ||2557 mLastState == KMachineState_Saving))2558 updateDockIcon();2559 else2560 mDockIconPreview->updateDockOverlay();2561 }2562 2563 void UIMachineView::setMouseCoalescingEnabled (bool aOn)2564 {2565 /* Enable mouse event compression if we leave the VM view. This2566 is necessary for having smooth resizing of the VM/other2567 windows.2568 Disable mouse event compression if we enter the VM view. So2569 all mouse events are registered in the VM. Only do this if2570 the keyboard/mouse is grabbed (this is when we have a valid2571 event handler). */2572 if (aOn || mKeyboardGrabbed)2573 ::darwinSetMouseCoalescingEnabled (aOn);2574 }2575 #endif /* Q_WS_MAC */2576 2577 2512 void UIMachineView::onStateChange(KMachineState state) 2578 2513 { … … 3227 3162 } 3228 3163 3164 #if defined(Q_WS_MAC) 3165 void UIMachineView::updateDockIcon() 3166 { 3167 if (mDockIconEnabled) 3168 { 3169 if (!mPausedShot.isNull()) 3170 { 3171 CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot); 3172 /* Use the pause image as background */ 3173 mDockIconPreview->updateDockPreview (pauseImg); 3174 CGImageRelease (pauseImg); 3175 } 3176 else 3177 { 3178 # if defined (VBOX_GUI_USE_QUARTZ2D) 3179 // TODO_NEW_CORE 3180 // if (mode == VBoxDefs::Quartz2DMode) 3181 // { 3182 /* If the render mode is Quartz2D we could use the CGImageRef 3183 * of the framebuffer for the dock icon creation. This saves 3184 * some conversion time. */ 3185 // mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef()); 3186 // } 3187 // else 3188 # endif 3189 /* In image mode we have to create the image ref out of the 3190 * framebuffer */ 3191 // TODO_NEW_CORE 3192 // mDockIconPreview->updateDockPreview (mFrameBuf); 3193 } 3194 } 3195 } 3196 3197 void UIMachineView::updateDockOverlay() 3198 { 3199 /* Only to an update to the realtime preview if this is enabled by the user 3200 * & we are in an state where the framebuffer is likely valid. Otherwise to 3201 * the overlay stuff only. */ 3202 if (mDockIconEnabled && 3203 (mLastState == KMachineState_Running || 3204 mLastState == KMachineState_Paused || 3205 mLastState == KMachineState_Teleporting || 3206 mLastState == KMachineState_LiveSnapshotting || 3207 mLastState == KMachineState_Restoring || 3208 mLastState == KMachineState_TeleportingPausedVM || 3209 mLastState == KMachineState_TeleportingIn || 3210 mLastState == KMachineState_Saving)) 3211 updateDockIcon(); 3212 else 3213 mDockIconPreview->updateDockOverlay(); 3214 } 3215 3216 void UIMachineView::setMouseCoalescingEnabled (bool aOn) 3217 { 3218 /* Enable mouse event compression if we leave the VM view. This 3219 is necessary for having smooth resizing of the VM/other 3220 windows. 3221 Disable mouse event compression if we enter the VM view. So 3222 all mouse events are registered in the VM. Only do this if 3223 the keyboard/mouse is grabbed (this is when we have a valid 3224 event handler). */ 3225 if (aOn || mKeyboardGrabbed) 3226 ::darwinSetMouseCoalescingEnabled (aOn); 3227 } 3228 #endif /* Q_WS_MAC */ 3229 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
r26729 r26730 59 59 , UIVisualStateType visualStateType); 60 60 61 /* Adjust view geometry: */ 61 /* Public setters: */ 62 void setIgnoreGuestResize(bool bIgnore) { m_bIsGuestResizeIgnored = bIgnore; } 63 void setMouseIntegrationEnabled(bool bEnabled); 62 64 virtual void normalizeGeometry(bool bAdjustPosition = false) = 0; 63 64 /* Public members: */ 65 // TODO: Is it needed now? 66 void onViewOpened(); 67 68 /* Public getters: */ 65 //void setMachineViewFinalized(bool fTrue = true) { m_bIsMachineWindowResizeIgnored = !fTrue; } 66 67 signals: 68 69 /* Machine view signals: */ 70 void keyboardStateChanged(int iState); 71 void mouseStateChanged(int iState); 72 73 /* Utility signals: */ 74 void resizeHintDone(); 75 76 protected slots: 77 78 /* Initiate resize request to guest: */ 79 virtual void doResizeHint(const QSize &aSize = QSize()) = 0; 80 81 protected: 82 83 UIMachineView( UIMachineWindow *pMachineWindow 84 , VBoxDefs::RenderMode renderMode 85 #ifdef VBOX_WITH_VIDEOHWACCEL 86 , bool bAccelerate2DVideo 87 #endif 88 ); 89 virtual ~UIMachineView(); 90 91 /* Protected getters: */ 92 UIMachineWindow* machineWindowWrapper() { return m_pMachineWindow; } 93 CConsole &console() { return m_console; } 94 95 /* Protected members: */ 96 QSize sizeHint() const; 69 97 int contentsX() const; 70 98 int contentsY() const; 99 int contentsWidth() const; 100 int contentsHeight() const; 101 int visibleWidth() const; 102 int visibleHeight() const; 103 void calculateDesktopGeometry(); 71 104 QRect desktopGeometry() const; 72 bool isMouseAbsolute() const { return m_bIsMouseAbsolute; } 73 74 /* Public setters: */ 75 void setIgnoreGuestResize(bool bIgnore); 76 void setMouseIntegrationEnabled(bool bEnabled); 77 78 #if defined(Q_WS_MAC) 79 void updateDockIcon(); 80 void updateDockOverlay(); 81 void setDockIconEnabled(bool aOn) { mDockIconEnabled = aOn; }; 82 void setMouseCoalescingEnabled(bool aOn); 83 #endif 84 85 signals: 86 87 void keyboardStateChanged(int iState); 88 void mouseStateChanged(int iState); 89 void machineStateChanged(KMachineState state); 90 void additionsStateChanged(const QString &strVersion, bool bIsActive, bool bIsGraphicSupported, bool bIsSeamlessSupported); 91 void mediaDriveChanged(VBoxDefs::MediumType type); 92 void networkStateChange(); 93 void usbStateChange(); 94 void sharedFoldersChanged(); 95 void resizeHintDone(); 96 97 protected slots: 98 99 virtual void doResizeHint(const QSize &aSize = QSize()) = 0; 100 101 protected: 102 103 UIMachineView( UIMachineWindow *pMachineWindow 104 , VBoxDefs::RenderMode renderMode 105 #ifdef VBOX_WITH_VIDEOHWACCEL 106 , bool bAccelerate2DVideo 107 #endif 108 ); 109 virtual ~UIMachineView(); 110 111 /* Protected members: */ 112 void calculateDesktopGeometry(); 113 114 /* Protected getters: */ 115 UIMachineWindow* machineWindowWrapper() { return m_pMachineWindow; } 116 QSize sizeHint() const; 105 //bool isMouseAbsolute() const { return m_bIsMouseAbsolute; } 106 107 /* Prepare routines: */ 108 void prepareFrameBuffer(); 109 void prepareCommon(); 110 void prepareFilters(); 111 void loadMachineViewSettings(); 112 113 /* Cleanup routines: */ 114 //void saveMachineViewSettings(); 115 //void cleanupFilters(); 116 void cleanupCommon(); 117 void cleanupFrameBuffer(); 117 118 118 119 /* Protected variables: */ … … 125 126 /* Dock icon update handler */ 126 127 void sltChangeDockIconUpdate(const VBoxChangeDockIconUpdateEvent &event); 127 128 128 # ifdef QT_MAC_USE_COCOA 129 129 /* Presentation mode handler */ … … 133 133 134 134 private: 135 136 /* Private getters: */137 int contentsWidth() const;138 int contentsHeight() const;139 int visibleWidth() const;140 int visibleHeight() const;141 const QPixmap& pauseShot() const { return mPausedShot; }142 bool shouldHideHostPointer() const { return m_bIsMouseCaptured || (m_bIsMouseAbsolute && mHideHostPointer); }143 bool isRunning() { return mLastState == KMachineState_Running || mLastState == KMachineState_Teleporting || mLastState == KMachineState_LiveSnapshotting; }144 CConsole &console() { return m_console; }145 135 146 136 /* Event processors: */ … … 192 182 193 183 /* Private members: */ 184 bool shouldHideHostPointer() const { return m_bIsMouseCaptured || (m_bIsMouseAbsolute && mHideHostPointer); } 185 bool isRunning() { return mLastState == KMachineState_Running || mLastState == KMachineState_Teleporting || mLastState == KMachineState_LiveSnapshotting; } 194 186 void fixModifierState(LONG *piCodes, uint *puCount); 195 187 void scrollBy(int dx, int dy); … … 217 209 218 210 static void dimImage(QImage &img); 211 212 #if defined(Q_WS_MAC) 213 void updateDockIcon(); 214 void updateDockOverlay(); 215 void setMouseCoalescingEnabled(bool aOn); 216 void setDockIconEnabled(bool aOn) { mDockIconEnabled = aOn; }; 217 218 const QPixmap& pauseShot() const { return mPausedShot; } 219 #endif 219 220 220 221 /* Private members: */ … … 286 287 bool mHideHostPointer; 287 288 QCursor mLastCursor; 289 290 /* Friend classes: */ 291 friend class UIFrameBuffer; 292 friend class UIFrameBufferQImage; 288 293 }; 289 294 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
r26709 r26730 120 120 strSnapshotName = " (" + snapshot.GetName() + ")"; 121 121 } 122 machineWindow()->setWindowTitle(machine.GetName() + strSnapshotName + " [" + 123 vboxGlobal().toString(machineLogic()->machineState()) + "] - " + 124 m_strWindowTitlePrefix); 122 QString strMachineName = machine.GetName() + strSnapshotName; 123 if (machineLogic()->machineState() != KMachineState_Null) 124 strMachineName += " [" + vboxGlobal().toString(machineLogic()->machineState()) + "] - "; 125 strMachineName += m_strWindowTitlePrefix; 126 machineWindow()->setWindowTitle(strMachineName); 125 127 126 128 // TODO: Move that to fullscreen/seamless update routine: -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp
r26709 r26730 46 46 ) 47 47 { 48 /* Connect view to handlers */ 49 connect(this, SIGNAL(additionsStateChanged(const QString&, bool, bool, bool)), 50 this, SLOT(sltAdditionsStateChanged(const QString &, bool, bool, bool))); 48 /* Prepare frame buffer: */ 49 prepareFrameBuffer(); 50 51 /* Prepare common things: */ 52 prepareCommon(); 53 54 /* Prepare event-filters: */ 55 prepareFilters(); 56 57 /* Load machine view settings: */ 58 loadMachineViewSettings(); 59 } 60 61 UIMachineViewNormal::~UIMachineViewNormal() 62 { 63 /* Cleanup common things: */ 64 cleanupCommon(); 65 66 /* Cleanup frame buffer: */ 67 cleanupFrameBuffer(); 51 68 } 52 69 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h
r26709 r26730 39 39 #endif 40 40 ); 41 virtual ~UIMachineViewNormal(); 41 42 42 43 void normalizeGeometry(bool bAdjustPosition = false); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
r26709 r26730 700 700 void UIMachineWindowNormal::prepareMachineView() 701 701 { 702 return; // TODO: Do not create view for now!703 704 702 CMachine machine = session().GetMachine(); 705 703 … … 710 708 711 709 m_pMachineView = UIMachineView::create( this 712 , vboxGlobal().vmRenderMode() // TODO: use correct variable here!710 , vboxGlobal().vmRenderMode() 713 711 #ifdef VBOX_WITH_VIDEOHWACCEL 714 , bAccelerate2DVideo // TODO: use correct variable here!712 , bAccelerate2DVideo 715 713 #endif 716 714 , machineLogic()->visualStateType()); 717 qobject_cast<QGridLayout*>(centralWidget()->layout())->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); 715 716 //qobject_cast<QGridLayout*>(centralWidget()->layout())->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); 717 setCentralWidget(m_pMachineView); 718 718 719 719 /* Setup machine view <-> indicators connections: */ 720 connect(machineView(), SIGNAL(keyboardStateChanged(int)), 721 indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int))); 720 connect(machineView(), SIGNAL(keyboardStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int))); 722 721 connect(machineView(), SIGNAL(mouseStateChanged(int)), this, SLOT(sltUpdateMouseState(int))); 723 722 }
Note:
See TracChangeset
for help on using the changeset viewer.