VirtualBox

Changeset 26815 in vbox for trunk


Ignore:
Timestamp:
Feb 26, 2010 2:43:37 AM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: New running VM core: cumulative patch to let uimachine to restore mouse/keyboard states when switching modes.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r26709 r26815  
    162162UIMachine::UIMachine(UIMachine **ppSelf, const CSession &session)
    163163    : QObject(0)
     164    , m_pActionsPool(new UIActionsPool(this))
    164165    , m_pSession(new UISession(this, session))
    165     , m_pActionsPool(new UIActionsPool(this))
    166166    , m_pVisualState(0)
    167167{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r26709 r26815  
    5858    /* Private getters: */
    5959    UIMachineLogic* machineLogic() const;
     60    UIActionsPool* actionsPool() const { return m_pActionsPool; }
    6061
    6162    /* Private variables: */
     63    UIActionsPool *m_pActionsPool;
    6264    UISession *m_pSession;
    63     UIActionsPool *m_pActionsPool;
    6465    UIVisualState *m_pVisualState;
    6566
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r26795 r26815  
    2525#include <QDir>
    2626#include <QFileInfo>
    27 #include <QProgressBar>
    2827#include <QDesktopWidget>
    2928
    3029/* Local includes */
    31 #include "VBoxGlobal.h"
     30#include "COMDefs.h"
    3231#include "VBoxProblemReporter.h"
    3332
     
    4039
    4140#include "QIFileDialog.h"
    42 #include "QIHttp.h"
     41//#include "QIHttp.h"
    4342
    4443#include "UISession.h"
     
    5150#include "UIMachineView.h"
    5251
    53 #include <iprt/param.h>
    5452#include <iprt/path.h>
    5553#include <VBox/VMMDev.h>
     
    8785{
    8886    USBTarget() : attach(false), id(QString()) {}
    89     USBTarget(bool bAttach, const QString &strId)
    90         : attach(bAttach), id(strId) {}
     87    USBTarget(bool fAttach, const QString &strId)
     88        : attach(fAttach), id(strId) {}
    9189    bool attach;
    9290    QString id;
     
    372370    , m_pSession(pSession)
    373371    , m_pActionsPool(pActionsPool)
    374     , m_machineState(KMachineState_Null)
    375372    , m_visualStateType(visualStateType)
    376373    , m_pMachineWindowWrapper(0)
    377374    , m_pRunningActions(0)
    378375    , m_pRunningOrPausedActions(0)
    379     , m_fIsFirstTimeStarted(false)
    380     , m_fIsIgnoringRutimeMediums(false)
    381     , m_fIsAdditionsActive(false)
    382     , m_fIsGuestSupportsGraphics(false)
    383     , m_fIsGuestSupportsSeamless(false)
    384     , m_fIsMouseSupportsAbsolute(false)
    385     , m_fIsMouseSupportsRelative(false)
    386     , m_fIsHostCursorNeeded(false)
    387376    , m_fIsPreventAutoClose(false)
    388377{
     
    399388CSession& UIMachineLogic::session()
    400389{
    401     return m_pSession->session();
     390    return uisession()->session();
    402391}
    403392
     
    405394{
    406395    /* Machine state-change updater: */
    407     connect(uisession(), SIGNAL(sigStateChange(KMachineState)), this, SLOT(sltMachineStateChanged(KMachineState)));
     396    connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
    408397
    409398    /* Guest additions state-change updater: */
     
    411400
    412401    /* Mouse capability state-change updater: */
    413     connect(uisession(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool)), this, SLOT(sltMouseCapabilityChanged(bool, bool, bool)));
     402    connect(uisession(), SIGNAL(sigMouseCapabilityChange()), this, SLOT(sltMouseCapabilityChanged()));
    414403
    415404    /* USB devices state-change updater: */
     
    534523
    535524    /* Check if the virtualization feature is required. */
    536     bool bIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetIs64Bit();
     525    bool fIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetIs64Bit();
    537526    bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetRecommendedVirtEx();
    538     AssertMsg(!bIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
    539     bool bIsVirtEnabled = console.GetDebugger().GetHWVirtExEnabled();
    540     if (fRecommendVirtEx && !bIsVirtEnabled)
    541     {
    542         bool result;
    543 
    544         pause();
     527    AssertMsg(!fIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
     528    bool fIsVirtEnabled = console.GetDebugger().GetHWVirtExEnabled();
     529    if (fRecommendVirtEx && !fIsVirtEnabled)
     530    {
     531        bool fResult;
     532
     533        uisession()->pause();
    545534
    546535        bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
    547536
    548         if (bIs64BitsGuest)
    549             result = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
     537        if (fIs64BitsGuest)
     538            fResult = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
    550539        else
    551             result = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
    552 
    553         if (result == true)
     540            fResult = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
     541
     542        if (fResult == true)
    554543            sltClose();
    555544        else
    556             unpause();
     545            uisession()->unpause();
    557546    }
    558547
     
    564553}
    565554
    566 void UIMachineLogic::loadLogicSettings()
    567 {
    568     /* Get current machine: */
    569     CMachine machine = session().GetMachine();
    570 
    571     /* Extra-data settings: */
    572     {
    573         QString strSettings;
    574 
    575         strSettings = machine.GetExtraData(VBoxDefs::GUI_AutoresizeGuest);
    576         if (strSettings != "off")
    577             actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setChecked(true);
    578 
    579         strSettings = machine.GetExtraData(VBoxDefs::GUI_FirstRun);
    580         if (strSettings == "yes")
    581             m_fIsFirstTimeStarted = true;
    582 
    583         strSettings = machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
    584         if (strSettings == "no")
    585             m_fIsIgnoringRutimeMediums = true;
    586     }
    587 
    588     /* Initial settings: */
    589     {
    590         /* Initialize storage stuff: */
    591         int iDevicesCountCD = 0;
    592         int iDevicesCountFD = 0;
    593         const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
    594         foreach (const CMediumAttachment &attachment, attachments)
    595         {
    596             if (attachment.GetType() == KDeviceType_DVD)
    597                 ++ iDevicesCountCD;
    598             if (attachment.GetType() == KDeviceType_Floppy)
    599                 ++ iDevicesCountFD;
    600         }
    601         actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setData(iDevicesCountCD);
    602         actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setData(iDevicesCountFD);
    603         actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setVisible(iDevicesCountCD);
    604         actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setVisible(iDevicesCountFD);
    605     }
    606 
    607     /* Availability settings: */
    608     {
    609         /* USB Stuff: */
    610         CUSBController usbController = machine.GetUSBController();
    611         if (usbController.isNull())
    612         {
    613             /* Hide USB menu if controller is NULL: */
    614             actionsPool()->action(UIActionIndex_Menu_USBDevices)->setVisible(false);
    615         }
    616         else
    617         {
    618             /* Enable/Disable USB menu depending on USB controller: */
    619             actionsPool()->action(UIActionIndex_Menu_USBDevices)->setEnabled(usbController.GetEnabled());
    620         }
    621 
    622         /* VRDP Stuff: */
    623         CVRDPServer vrdpServer = machine.GetVRDPServer();
    624         if (vrdpServer.isNull())
    625         {
    626             /* Hide VRDP Action: */
    627             actionsPool()->action(UIActionIndex_Toggle_VRDP)->setVisible(false);
    628         }
    629     }
    630 
    631 #if 0
    632     /* Dynamical property settings: */
    633     {
    634         /* Load dynamical properties: */
    635         m_machineState = uisession()->property("MachineLogic/MachineState").value<KMachineState>();
    636         m_fIsAdditionsActive = uisession()->property("MachineLogic/IsAdditionsActive").toBool();
    637         m_fIsGuestSupportsGraphics = uisession()->property("MachineLogic/IsGuestSupportsGraphics").toBool();
    638         m_fIsGuestSupportsSeamless = uisession()->property("MachineLogic/IsGuestSupportsSeamless").toBool();
    639         m_fIsMouseSupportsAbsolute = uisession()->property("MachineLogic/IsMouseSupportsAbsolute").toBool();
    640         m_fIsMouseSupportsRelative = uisession()->property("MachineLogic/IsMouseSupportsRelative").toBool();
    641         m_fIsHostCursorNeeded = uisession()->property("MachineLogic/IsHostCursorNeeded").toBool();
    642 
    643         /* Update relative things: */
    644         updateMachineState();
    645         updateAdditionsState();
    646         updateMouseCapability();
    647     }
    648 #endif
    649 }
    650 
    651 void UIMachineLogic::saveLogicSettings()
    652 {
    653     /* Get current machine: */
    654     CMachine machine = session().GetMachine();
    655 
    656     /* Extra-data settings: */
    657     {
    658         machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
    659                              actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->isChecked() ? "on" : "off");
    660 
    661         machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
    662 
    663         // TODO: Move to fullscreen/seamless logic:
    664         //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
    665     }
    666 
    667 #if 0
    668     /* Dynamical property settings: */
    669     {
    670         /* Save dynamical properties: */
    671         uisession()->setProperty("MachineLogic/MachineState", QVariant::fromValue(machineState()));
    672         uisession()->setProperty("MachineLogic/IsAdditionsActive", m_fIsAdditionsActive);
    673         uisession()->setProperty("MachineLogic/IsGuestSupportsGraphics", m_fIsGuestSupportsGraphics);
    674         uisession()->setProperty("MachineLogic/IsGuestSupportsSeamless", m_fIsGuestSupportsSeamless);
    675         uisession()->setProperty("MachineLogic/IsMouseSupportsAbsolute", m_fIsMouseSupportsAbsolute);
    676         uisession()->setProperty("MachineLogic/IsMouseSupportsRelative", m_fIsMouseSupportsRelative);
    677         uisession()->setProperty("MachineLogic/IsHostCursorNeeded", m_fIsHostCursorNeeded);
    678     }
    679 #endif
    680 }
    681 
    682 void UIMachineLogic::updateMachineState()
    683 {
    684     /* State flags: */
    685     bool fIsRunning = machineState() == KMachineState_Running ||
    686                       machineState() == KMachineState_Teleporting ||
    687                       machineState() == KMachineState_LiveSnapshotting;
    688     bool fIsRunningOrPaused = fIsRunning ||
    689                               machineState() == KMachineState_Paused;
     555void UIMachineLogic::sltMachineStateChanged()
     556{
     557    /* Get machine state: */
     558    KMachineState state = uisession()->machineState();
    690559
    691560    /* Update action groups: */
    692     m_pRunningActions->setEnabled(fIsRunning);
    693     m_pRunningOrPausedActions->setEnabled(fIsRunningOrPaused);
     561    m_pRunningActions->setEnabled(uisession()->isRunning());
     562    m_pRunningOrPausedActions->setEnabled(uisession()->isRunning() || uisession()->isPaused());
    694563
    695564    /* Do we have GURU? */
    696565    bool fIsGuruMeditation = false;
    697566
    698     switch (machineState())
     567    switch (state)
    699568    {
    700569        case KMachineState_Stuck:
    701570        {
    702             /* We will handle GURU later: */
     571            /* We will process GURU later: */
    703572            fIsGuruMeditation = true;
    704573            break;
    705574        }
    706575        case KMachineState_Paused:
     576        case KMachineState_TeleportingPausedVM:
    707577        {
    708578            QAction *pPauseAction = actionsPool()->action(UIActionIndex_Toggle_Pause);
     
    746616
    747617    /* Close VM if was closed someway: */
    748     if (machineState() == KMachineState_PoweredOff || machineState() == KMachineState_Saved ||
    749         machineState() == KMachineState_Teleported || machineState() == KMachineState_Aborted)
     618    if (uisession()->isTurnedOff())
    750619    {
    751620        /* VM has been powered off or saved or aborted, no matter internally or externally.
     
    755624    }
    756625
    757     /* Process GURU: */
     626    /* Postprocess GURU: */
    758627    if (fIsGuruMeditation)
    759628    {
    760         if (machineWindowWrapper()->machineView())
    761             machineWindowWrapper()->machineView()->setIgnoreGuestResize(true);
     629        uisession()->setGuestResizeIgnored(true);
    762630
    763631        CConsole console = session().GetConsole();
     
    780648        }
    781649    }
    782 
    783 #ifdef Q_WS_MAC
    784     /* Update Dock Overlay: */
    785     if (machineWindowWrapper() && machineWindowWrapper()->machineView())
    786         machineWindowWrapper()->machineView()->updateDockOverlay();
    787 #endif /* Q_WS_MAC */
    788 }
    789 
    790 void UIMachineLogic::updateAdditionsState()
    791 {
    792     /* Update action groups: */
    793     actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setEnabled(m_fIsAdditionsActive && m_fIsGuestSupportsGraphics);
    794     actionsPool()->action(UIActionIndex_Toggle_Seamless)->setEnabled(m_fIsAdditionsActive && m_fIsGuestSupportsGraphics && m_fIsGuestSupportsSeamless);
    795 
    796 #if 0 // TODO: Enter seamless if necessary!
    797     /* If seamless mode should be enabled then check if it is enabled currently and re-enable it if open-view procedure is finished */
    798     if (actionsPool()->action(UIActionIndex_Toggle_Seamless)->isChecked() &&
    799         m_fIsAdditionsActive && m_fIsGuestSupportsGraphics && m_fIsGuestSupportsSeamless)
    800         toggleFullscreenMode(true, true);
    801 #endif
     650}
     651
     652void UIMachineLogic::sltAdditionsStateChanged()
     653{
     654    /* Variable falgs: */
     655    bool fIsAdditionsActive = uisession()->isGuestAdditionsActive();
     656    bool fIsSupportsGraphics = fIsAdditionsActive && uisession()->isGuestSupportsGraphics();
     657    bool fIsSupportsSeamless = fIsSupportsGraphics && uisession()->isGuestSupportsSeamless();
     658
     659    /* Update action states: */
     660    actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setEnabled(fIsSupportsGraphics);
     661    actionsPool()->action(UIActionIndex_Toggle_Seamless)->setEnabled(fIsSupportsSeamless);
    802662
    803663    /* Check the GA version only in case of additions are active: */
    804     if (!m_fIsAdditionsActive)
     664    if (!fIsAdditionsActive)
    805665        return;
    806 
    807666    /* Check the Guest Additions version and warn the user about possible compatibility issues in case if the installed version is outdated. */
    808667    CGuest guest = session().GetConsole().GetGuest();
     
    826685}
    827686
    828 void UIMachineLogic::updateMouseCapability()
    829 {
    830     /* Update related things: */
     687void UIMachineLogic::sltMouseCapabilityChanged()
     688{
     689    /* Variable falgs: */
     690    bool fIsMouseSupportsAbsolute = uisession()->isMouseSupportsAbsolute();
     691    /* bool fIsMouseSupportsRelative = uisession()->isMouseSupportsRelative(); */
     692    bool fIsMouseHostCursorNeeded = uisession()->isMouseHostCursorNeeded();
     693
     694    /* Update action state: */
    831695    QAction *pAction = actionsPool()->action(UIActionIndex_Toggle_MouseIntegration);
    832     pAction->setEnabled(m_fIsMouseSupportsAbsolute && m_fIsMouseSupportsRelative && !m_fIsHostCursorNeeded);
    833     pAction->setChecked(m_fIsHostCursorNeeded || pAction->isChecked());
    834 }
    835 
    836 void UIMachineLogic::sltMachineStateChanged(KMachineState state)
    837 {
    838     /* Check if something had changed: */
    839     if (m_machineState != state)
    840     {
    841         /* Store new data: */
    842         m_machineState = state;
    843 
    844         /* Update machine state: */
    845         updateMachineState();
    846     }
    847 }
    848 
    849 void UIMachineLogic::sltAdditionsStateChanged()
    850 {
    851     /* Get our guest: */
    852     CGuest guest = session().GetConsole().GetGuest();
    853 
    854     /* Variable flags: */
    855     bool fIsAdditionsActive = guest.GetAdditionsActive();
    856     bool fIsGuestSupportsGraphics = guest.GetSupportsGraphics();
    857     bool fIsGuestSupportsSeamless = guest.GetSupportsSeamless();
    858 
    859     /* Check if something had changed: */
    860     if (m_fIsAdditionsActive != fIsAdditionsActive ||
    861         m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics ||
    862         m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
    863     {
    864         /* Store new data: */
    865         m_fIsAdditionsActive = fIsAdditionsActive;
    866         m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
    867         m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
    868 
    869         /* Update additions state: */
    870         updateAdditionsState();
    871     }
    872 }
    873 
    874 void UIMachineLogic::sltMouseCapabilityChanged(bool fIsSupportsAbsolute, bool fIsSupportsRelative, bool fIsHostCursorNeeded)
    875 {
    876     /* Check if something is changed: */
    877     if (m_fIsMouseSupportsAbsolute != fIsSupportsAbsolute ||
    878         m_fIsMouseSupportsRelative != fIsSupportsRelative ||
    879         m_fIsHostCursorNeeded != fIsHostCursorNeeded)
    880     {
    881         /* Store new data: */
    882         m_fIsMouseSupportsAbsolute = fIsSupportsAbsolute;
    883         m_fIsMouseSupportsRelative = fIsSupportsRelative;
    884         m_fIsHostCursorNeeded = fIsHostCursorNeeded;
    885 
    886         /* Update mouse capability: */
    887         updateMouseCapability();
    888     }
    889 }
    890 
    891 void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error)
    892 {
    893     bool success = error.isNull();
    894 
    895     if (!success)
    896     {
    897         if (bIsAttached)
     696    pAction->setEnabled(fIsMouseSupportsAbsolute /* && fIsMouseSupportsRelative */ && !fIsMouseHostCursorNeeded);
     697    pAction->setChecked(fIsMouseHostCursorNeeded || pAction->isChecked());
     698}
     699
     700void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error)
     701{
     702    bool fSuccess = error.isNull();
     703
     704    if (!fSuccess)
     705    {
     706        if (fIsAttached)
    898707            vboxProblem().cannotAttachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
    899708        else
     
    902711}
    903712
    904 void UIMachineLogic::sltRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage)
    905 {
    906     vboxProblem().showRuntimeError(session().GetConsole(), bIsFatal, strErrorId, strMessage);
    907 }
    908 
    909 void UIMachineLogic::sltToggleGuestAutoresize(bool bEnabled)
     713void UIMachineLogic::sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage)
     714{
     715    vboxProblem().showRuntimeError(session().GetConsole(), fIsFatal, strErrorId, strMessage);
     716}
     717
     718void UIMachineLogic::sltToggleGuestAutoresize(bool fEnabled)
    910719{
    911720    /* Do not process if window or view is missing! */
     
    913722        return;
    914723
    915     machineWindowWrapper()->machineView()->setGuestAutoresizeEnabled(bEnabled);
     724    machineWindowWrapper()->machineView()->setGuestAutoresizeEnabled(fEnabled);
    916725}
    917726
     
    930739}
    931740
    932 void UIMachineLogic::sltToggleMouseIntegration(bool aOff)
     741void UIMachineLogic::sltToggleMouseIntegration(bool fOff)
    933742{
    934743    /* Do not process if window or view is missing! */
     
    937746
    938747    /* Disable/Enable mouse-integration for view: */
    939     machineWindowWrapper()->machineView()->setMouseIntegrationEnabled(!aOff);
     748    machineWindowWrapper()->machineView()->setMouseIntegrationEnabled(!fOff);
    940749}
    941750
     
    972781
    973782    /* Remember the paused state. */
    974     bool bWasPaused = machineState() == KMachineState_Paused;
    975     if (!bWasPaused)
     783    bool fWasPaused = uisession()->isPaused();
     784    if (!fWasPaused)
    976785    {
    977786        /* Suspend the VM and ignore the close event if failed to do so.
    978787         * pause() will show the error message to the user. */
    979         if (!pause())
     788        if (!uisession()->pause())
    980789            return;
    981790    }
     
    1012821
    1013822    /* Restore the running state if needed. */
    1014     if (!bWasPaused)
    1015         unpause();
     823    if (!fWasPaused)
     824        uisession()->unpause();
    1016825}
    1017826
     
    1023832
    1024833    // TODO: Call for singleton information dialog for this machine!
    1025 //    VBoxVMInformationDlg::createInformationDlg(session(), machineWindowWrapper()->machineWindow());
     834    //VBoxVMInformationDlg::createInformationDlg(session(), machineWindowWrapper()->machineWindow());
    1026835}
    1027836
     
    1037846}
    1038847
    1039 void UIMachineLogic::sltPause(bool aOn)
    1040 {
    1041     pause(aOn);
     848void UIMachineLogic::sltPause(bool fOn)
     849{
     850    uisession()->setPause(fOn);
    1042851}
    1043852
    1044853void UIMachineLogic::sltACPIShutdown()
    1045854{
     855    /* Get console: */
    1046856    CConsole console = session().GetConsole();
    1047857
     
    1144954            CMedium currentMedium = attachment.GetMedium();
    1145955            QString currentId = currentMedium.isNull() ? QString::null : currentMedium.GetId();
    1146             bool currentUsed = false;
     956            bool fCurrentUsed = false;
    1147957            foreach (CMedium medium, mediums)
    1148958            {
     
    1162972                if (!isMediumUsed)
    1163973                {
    1164                     if (!currentUsed && !currentMedium.isNull() && mediumsToBeShown == maxMediumsToBeShown - 1)
     974                    if (!fCurrentUsed && !currentMedium.isNull() && mediumsToBeShown == maxMediumsToBeShown - 1)
    1165975                        medium = currentMedium;
    1166976
    1167977                    if (medium.GetId() == currentId)
    1168                         currentUsed = true;
     978                        fCurrentUsed = true;
    1169979
    1170980                    QAction *mountMediumAction = new QAction(VBoxMedium(medium, mediumType).name(), pAttachmentMenu);
     
    12691079    /* New mount-target attributes: */
    12701080    QString newId = QString("");
    1271     bool selectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
     1081    bool fSelectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
    12721082
    12731083    /* Open Virtual Media Manager to select image id: */
    1274     if (selectWithMediaManager)
     1084    if (fSelectWithMediaManager)
    12751085    {
    12761086        /* Search for already used images: */
     
    12931103        newId = target.id;
    12941104
    1295     bool mount = !newId.isEmpty();
     1105    bool fMount = !newId.isEmpty();
    12961106
    12971107    /* Remount medium to the predefined port/device: */
    1298     bool wasMounted = false;
     1108    bool fWasMounted = false;
    12991109    machine.MountMedium(target.name, target.port, target.device, newId, false /* force */);
    13001110    if (machine.isOk())
    1301         wasMounted = true;
     1111        fWasMounted = true;
    13021112    else
    13031113    {
    13041114        /* Ask for force remounting: */
    1305         if (vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, true /* retry? */) == QIMessageBox::Ok)
     1115        if (vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, vboxGlobal().findMedium (fMount ? newId : currentId), fMount, true /* retry? */) == QIMessageBox::Ok)
    13061116        {
    13071117            /* Force remount medium to the predefined port/device: */
    13081118            machine.MountMedium(target.name, target.port, target.device, newId, true /* force */);
    13091119            if (machine.isOk())
    1310                 wasMounted = true;
     1120                fWasMounted = true;
    13111121            else
    1312                 vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, false /* retry? */);
     1122                vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, vboxGlobal().findMedium (fMount ? newId : currentId), fMount, false /* retry? */);
    13131123        }
    13141124    }
    13151125
    13161126    /* Save medium mounted at runtime */
    1317     if (wasMounted && !m_fIsIgnoringRutimeMediums)
     1127    if (fWasMounted && !uisession()->isIgnoreRuntimeMediumsChanging())
    13181128    {
    13191129        machine.SaveSettings();
     
    13381148
    13391149    /* Fill USB devices menu: */
    1340     bool bIsUSBListEmpty = devices.size() == 0;
    1341     if (bIsUSBListEmpty)
     1150    bool fIsUSBListEmpty = devices.size() == 0;
     1151    if (fIsUSBListEmpty)
    13421152    {
    13431153        /* Fill USB devices menu: */
     
    14231233}
    14241234
    1425 void UIMachineLogic::sltSwitchVrdp(bool aOn)
     1235void UIMachineLogic::sltSwitchVrdp(bool fOn)
    14261236{
    14271237    /* Enable VRDP server if possible: */
    14281238    CVRDPServer server = session().GetMachine().GetVRDPServer();
    14291239    AssertMsg(!server.isNull(), ("VRDP server should not be null!\n"));
    1430     server.SetEnabled(aOn);
     1240    server.SetEnabled(fOn);
    14311241}
    14321242
     
    15131323}
    15141324
    1515 void UIMachineLogic::sltLoggingToggled(bool bState)
    1516 {
    1517     NOREF(bState);
     1325void UIMachineLogic::sltLoggingToggled(bool fState)
     1326{
     1327    NOREF(fState);
    15181328    CConsole console = session().GetConsole();
    15191329    if (console.isOk())
     
    15211331        CMachineDebugger cdebugger = console.GetDebugger();
    15221332        if (console.isOk())
    1523             cdebugger.SetLogEnabled(bState);
    1524     }
    1525 }
    1526 #endif
    1527 
    1528 bool UIMachineLogic::pause(bool bOn)
    1529 {
    1530     if (isPaused() == bOn)
    1531         return true;
    1532 
    1533     CConsole console = session().GetConsole();
    1534 
    1535     if (bOn)
    1536         console.Pause();
    1537     else
    1538         console.Resume();
    1539 
    1540     bool ok = console.isOk();
    1541     if (!ok)
    1542     {
    1543         if (bOn)
    1544             vboxProblem().cannotPauseMachine(console);
    1545         else
    1546             vboxProblem().cannotResumeMachine(console);
    1547     }
    1548 
    1549     return ok;
    1550 }
     1333            cdebugger.SetLogEnabled(fState);
     1334    }
     1335}
     1336#endif
    15511337
    15521338void UIMachineLogic::installGuestAdditionsFrom(const QString &strSource)
     
    16021388    if (!strCntName.isNull())
    16031389    {
    1604         bool isMounted = false;
     1390        bool fIsMounted = false;
    16051391
    16061392        /* Mount medium to the predefined port/device */
    16071393        machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, false /* force */);
    16081394        if (machine.isOk())
    1609             isMounted = true;
     1395            fIsMounted = true;
    16101396        else
    16111397        {
     
    16171403                machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, true /* force */);
    16181404                if (machine.isOk())
    1619                     isMounted = true;
     1405                    fIsMounted = true;
    16201406                else
    16211407                    vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
    16221408                                                      true /* mount? */, false /* retry? */);
    16231409            }
    1624         }
    1625 
    1626         /* Save medium mounted at runtime */
    1627         if (isMounted && !m_fIsIgnoringRutimeMediums)
    1628         {
    1629             machine.SaveSettings();
    1630             if (!machine.isOk())
    1631                 vboxProblem().cannotSaveMachineSettings(machine);
    16321410        }
    16331411    }
     
    17361514}
    17371515# endif
    1738 bool UIMachineLogic::toggleFullscreenMode (bool aOn, bool aSeamless)
     1516bool UIMachineLogic::toggleFullscreenMode (bool fOn, bool fSeamless)
    17391517{
    17401518    /* Please note: For some platforms like the Mac, the calling order of the
     
    17431521
    17441522    QSize initialSize = size();
    1745     if (aSeamless || mConsole->isAutoresizeGuestActive())
    1746     {
    1747         QRect screen = aSeamless ?
     1523    if (fSeamless || mConsole->isAutoresizeGuestActive())
     1524    {
     1525        QRect screen = fSeamless ?
    17481526            QApplication::desktop()->availableGeometry (this) :
    17491527            QApplication::desktop()->screenGeometry (this);
     
    17581536                         * mSession.GetMachine().GetMonitorCount() /**< @todo fix assumption that all screens have same resolution */
    17591537                         + 4096 * 8; /* adapter info */
    1760         if (aOn && (availBits < usedBits))
    1761         {
    1762             if (aSeamless)
     1538        if (fOn && (availBits < usedBits))
     1539        {
     1540            if (fSeamless)
    17631541            {
    17641542                vboxProblem().cannotEnterSeamlessMode (
     
    17791557
    17801558    AssertReturn (mConsole, false);
    1781     AssertReturn ((mHiddenChildren.empty() == aOn), false);
    1782     AssertReturn ((aSeamless && mIsSeamless != aOn) ||
    1783                   (!aSeamless && mIsFullscreen != aOn), false);
    1784     if (aOn)
    1785         AssertReturn ((aSeamless && !mIsFullscreen) ||
    1786                       (!aSeamless && !mIsSeamless), false);
    1787 
    1788     if (aOn)
     1559    AssertReturn ((mHiddenChildren.empty() == fOn), false);
     1560    AssertReturn ((fSeamless && mIsSeamless != fOn) ||
     1561                  (!fSeamless && mIsFullscreen != fOn), false);
     1562    if (fOn)
     1563        AssertReturn ((fSeamless && !mIsFullscreen) ||
     1564                      (!fSeamless && !mIsSeamless), false);
     1565
     1566    if (fOn)
    17891567    {
    17901568        /* Take the toggle hot key from the menu item. Since
     
    17921570         * linked key without the 'Host+' part we are adding it here. */
    17931571        QString hotKey = QString ("Host+%1")
    1794             .arg (VBoxGlobal::extractKeyFromActionText (aSeamless ?
     1572            .arg (VBoxGlobal::extractKeyFromActionText (fSeamless ?
    17951573                  mVmSeamlessAction->text() : mVmFullscreenAction->text()));
    17961574
     
    17981576
    17991577        /* Show the info message. */
    1800         bool ok = aSeamless ?
     1578        bool ok = fSeamless ?
    18011579            vboxProblem().confirmGoingSeamless (hotKey) :
    18021580            vboxProblem().confirmGoingFullscreen (hotKey);
     
    18061584
    18071585#ifdef Q_WS_MAC
    1808     if (!aSeamless)
    1809     {
    1810     }
    1811 #endif
    1812 
    1813     if (aSeamless)
     1586    if (!fSeamless)
     1587    {
     1588    }
     1589#endif
     1590
     1591    if (fSeamless)
    18141592    {
    18151593        /* Activate the auto-resize feature required for the seamless mode. */
     
    18211599            mVmDisableMouseIntegrAction->setChecked (false);
    18221600
    1823         mVmAdjustWindowAction->setEnabled (!aOn);
    1824         mVmFullscreenAction->setEnabled (!aOn);
    1825         mVmAutoresizeGuestAction->setEnabled (!aOn);
    1826         mVmDisableMouseIntegrAction->setEnabled (!aOn);
    1827 
    1828         mConsole->console().GetDisplay().SetSeamlessMode (aOn);
    1829         mIsSeamless = aOn;
     1601        mVmAdjustWindowAction->setEnabled (!fOn);
     1602        mVmFullscreenAction->setEnabled (!fOn);
     1603        mVmAutoresizeGuestAction->setEnabled (!fOn);
     1604        mVmDisableMouseIntegrAction->setEnabled (!fOn);
     1605
     1606        mConsole->console().GetDisplay().SetSeamlessMode (fOn);
     1607        mIsSeamless = fOn;
    18301608    }
    18311609    else
    18321610    {
    1833         mIsFullscreen = aOn;
    1834         mVmAdjustWindowAction->setEnabled (!aOn);
    1835         mVmSeamlessAction->setEnabled (!aOn && m_fIsGuestSupportsSeamless && m_fIsGuestSupportsGraphics);
     1611        mIsFullscreen = fOn;
     1612        mVmAdjustWindowAction->setEnabled (!fOn);
     1613        mVmSeamlessAction->setEnabled (!fOn && m_fIsGuestSupportsSeamless && m_fIsGuestSupportsGraphics);
    18361614    }
    18371615
     
    18401618    /* Temporarily disable the mode-related action to make sure
    18411619     * user can not leave the mode before he enter it and inside out. */
    1842     aSeamless ? mVmSeamlessAction->setEnabled (false) :
     1620    fSeamless ? mVmSeamlessAction->setEnabled (false) :
    18431621                mVmFullscreenAction->setEnabled (false);
    18441622
     
    18461624    QSize consoleSize;
    18471625
    1848     if (aOn)
     1626    if (fOn)
    18491627    {
    18501628        consoleSize = mConsole->frameSize();
     
    18681646
    18691647        /* let the widget take the whole available desktop space */
    1870         QRect scrGeo = aSeamless ?
     1648        QRect scrGeo = fSeamless ?
    18711649            dtw->availableGeometry (this) : dtw->screenGeometry (this);
    18721650
     
    18741652         * we requested. So after all the resizing stuff set the clipping
    18751653         * mask and the spacing shifter to the corresponding values. */
    1876         if (aSeamless)
     1654        if (fSeamless)
    18771655            setViewInSeamlessMode (scrGeo);
    18781656
     
    19021680        palette.setColor (centralWidget()->backgroundRole(), Qt::black);
    19031681        centralWidget()->setPalette (palette);
    1904         centralWidget()->setAutoFillBackground (!aSeamless);
     1682        centralWidget()->setAutoFillBackground (!fSeamless);
    19051683        mConsoleStyle = mConsole->frameStyle();
    19061684        mConsole->setFrameStyle (QFrame::NoFrame);
     
    19231701
    19241702#ifdef Q_WS_MAC
    1925         if (aSeamless)
     1703        if (fSeamless)
    19261704        {
    19271705            /* Please note: All the stuff below has to be done before the
     
    19541732        mIsWaitingModeResize = true;
    19551733
    1956     if (!aOn)
     1734    if (!fOn)
    19571735    {
    19581736        /* Animation takes a bit long, the mini toolbar is still disappearing
     
    19631741
    19641742    /* Toggle qt full-screen mode */
    1965     switchToFullscreen (aOn, aSeamless);
    1966 
    1967     if (aOn)
    1968     {
    1969         mMiniToolBar->setSeamlessMode (aSeamless);
     1743    switchToFullscreen (fOn, fSeamless);
     1744
     1745    if (fOn)
     1746    {
     1747        mMiniToolBar->setSeamlessMode (fSeamless);
    19701748        mMiniToolBar->updateDisplay (true, true);
    19711749    }
    19721750
    19731751#ifdef Q_WS_MAC
    1974     if (aOn && aSeamless)
     1752    if (fOn && fSeamless)
    19751753    {
    19761754        /* Please note: All the stuff below has to be done after the window has
     
    20041782    return true;
    20051783}
    2006 void UIMachineLogic::switchToFullscreen (bool aOn, bool aSeamless)
     1784void UIMachineLogic::switchToFullscreen (bool fOn, bool fSeamless)
    20071785{
    20081786#ifdef Q_WS_MAC
     
    20121790    WindowGroupRef g = GetWindowGroup (::darwinToNativeWindow (this));
    20131791# endif  /* !QT_MAC_USE_COCOA */
    2014     if (aSeamless)
    2015         if (aOn)
     1792    if (fSeamless)
     1793        if (fOn)
    20161794        {
    20171795            /* Save for later restoring */
     
    20351813        /* Here we are going really fullscreen */
    20361814        setWindowState (windowState() ^ Qt::WindowFullScreen);
    2037         sltChangePresentationMode (VBoxChangePresentationModeEvent(aOn));
     1815        sltChangePresentationMode (VBoxChangePresentationModeEvent(fOn));
    20381816    }
    20391817
     
    20431821# endif /* !QT_MAC_USE_COCOA */
    20441822#else
    2045     NOREF (aOn);
    2046     NOREF (aSeamless);
     1823    NOREF (fOn);
     1824    NOREF (fSeamless);
    20471825    setWindowState (windowState() ^ Qt::WindowFullScreen);
    20481826#endif
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r26795 r26815  
    2424#define __UIMachineLogic_h__
    2525
     26/* Global includes */
     27#include <QObject>
     28
    2629/* Local includes */
    27 #include "COMDefs.h"
    2830#include "UIMachineDefs.h"
    2931#ifdef VBOX_WITH_DEBUGGER_GUI
     
    3537
    3638/* Local forwards */
     39class CSession;
     40class CMachine;
     41class CSnapshot;
     42class CUSBDevice;
     43class CVirtualBoxErrorInfo;
    3744class UISession;
    3845class UIActionsPool;
     
    5158                                  UIVisualStateType visualStateType);
    5259
    53     /* Public getters: */
     60    /* Main getters/setters: */
    5461    UISession* uisession() { return m_pSession; }
    5562    UIActionsPool* actionsPool() { return m_pActionsPool; }
    5663    UIVisualStateType visualStateType() const { return m_visualStateType; }
    5764    UIMachineWindow* machineWindowWrapper() { return m_pMachineWindowWrapper; }
    58     KMachineState machineState() const { return m_machineState; }
    59     bool isPaused() const { return machineState() == KMachineState_Paused ||
    60                                    machineState() == KMachineState_TeleportingPausedVM; }
     65
     66    /* Maintenance getters/setters: */
    6167    bool isPreventAutoClose() const { return m_fIsPreventAutoClose; }
    62 
    63     /* Public setters: */
    6468    void setPreventAutoClose(bool fIsPreventAutoClose) { m_fIsPreventAutoClose = fIsPreventAutoClose; }
    6569
     
    7377    virtual ~UIMachineLogic();
    7478
    75     /* Protected getters: */
     79    /* Protected wrappers: */
    7680    CSession& session();
    77     bool isFirstTimeStarted() const { return m_fIsFirstTimeStarted; }
    7881
    7982    /* Protected setters: */
    8083    void setMachineWindowWrapper(UIMachineWindow *pMachineWindowWrapper) { m_pMachineWindowWrapper = pMachineWindowWrapper; }
    81 
    82     /* Console related routines: */
    83     bool pause() { return pause(true); }
    84     bool unpause() { return pause(false); }
    8584
    8685    /* Prepare helpers: */
     
    8988    virtual void prepareActionConnections();
    9089    virtual void prepareRequiredFeatures();
    91     virtual void loadLogicSettings();
    9290
    9391    /* Cleanup helpers: */
    94     virtual void saveLogicSettings();
    95     virtual void cleanupRequiredFeatures() {}
    96     virtual void cleanupActionConnections() {}
    97     virtual void cleanupActionGroups() {}
    98     virtual void cleanupConsoleConnections() {}
    99 
    100     /* Update helpers: */
    101     virtual void updateMachineState();
    102     virtual void updateAdditionsState();
    103     virtual void updateMouseCapability();
     92    //virtual void cleanupRequiredFeatures() {}
     93    //virtual void cleanupActionConnections() {}
     94    //virtual void cleanupActionGroups() {}
     95    //virtual void cleanupConsoleConnections() {}
    10496
    10597protected slots:
    10698
    10799    /* Console callback handlers: */
    108     virtual void sltMachineStateChanged(KMachineState machineState);
     100    virtual void sltMachineStateChanged();
    109101    virtual void sltAdditionsStateChanged();
    110     virtual void sltMouseCapabilityChanged(bool fIsSupportsAbsolute, bool fIsSupportsRelative, bool fNeedsHostCursor);
    111     virtual void sltUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error);
    112     virtual void sltRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage);
     102    virtual void sltMouseCapabilityChanged();
     103    virtual void sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error);
     104    virtual void sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage);
    113105
    114106private slots:
    115107
    116108    /* "Machine" menu funtionality */
    117     void sltToggleGuestAutoresize(bool bEnabled);
     109    void sltToggleGuestAutoresize(bool fEnabled);
    118110    void sltAdjustWindow();
    119     void sltToggleMouseIntegration(bool bDisabled);
     111    void sltToggleMouseIntegration(bool fDisabled);
    120112    void sltTypeCAD();
    121113#ifdef Q_WS_X11
     
    125117    void sltShowInformationDialog();
    126118    void sltReset();
    127     void sltPause(bool aOn);
     119    void sltPause(bool fOn);
    128120    void sltACPIShutdown();
    129121    void sltClose();
     
    136128    void sltOpenNetworkAdaptersDialog();
    137129    void sltOpenSharedFoldersDialog();
    138     void sltSwitchVrdp(bool bOn);
     130    void sltSwitchVrdp(bool fOn);
    139131    void sltInstallGuestAdditions();
    140132
     
    149141
    150142    /* Utility functions: */
    151     bool pause(bool bPaused);
    152143    void installGuestAdditionsFrom(const QString &strSource);
    153144    static int searchMaxSnapshotIndex(const CMachine &machine,
     
    158149    UISession *m_pSession;
    159150    UIActionsPool *m_pActionsPool;
    160     KMachineState m_machineState;
    161151    UIVisualStateType m_visualStateType;
    162152    UIMachineWindow *m_pMachineWindowWrapper;
     
    165155    QActionGroup *m_pRunningOrPausedActions;
    166156
    167     bool m_fIsFirstTimeStarted : 1;
    168     bool m_fIsIgnoringRutimeMediums : 1;
    169     bool m_fIsAdditionsActive : 1;
    170     bool m_fIsGuestSupportsGraphics : 1;
    171     bool m_fIsGuestSupportsSeamless : 1;
    172     bool m_fIsMouseSupportsAbsolute : 1;
    173     bool m_fIsMouseSupportsRelative : 1;
    174     bool m_fIsHostCursorNeeded : 1;
    175157    bool m_fIsPreventAutoClose : 1;
    176158
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r26797 r26815  
    3030
    3131/* Local includes */
     32#include "COMDefs.h"
    3233#include "VBoxGlobal.h"
    3334#include "VBoxProblemReporter.h"
     
    7172# endif
    7273# include "XKeyboard.h"
    73 # ifndef VBOX_WITHOUT_XCURSOR
    74 #  include <X11/Xcursor/Xcursor.h>
    75 # endif
    7674#endif
    7775
     
    157155int UIMachineView::mouseState() const
    158156{
    159     return (m_bIsMouseCaptured ? UIMouseStateType_MouseCaptured : 0) |
    160            (m_fIsMouseSupportsAbsolute ? UIMouseStateType_MouseAbsolute : 0) |
    161            (m_bIsMouseIntegrated ? 0 : UIMouseStateType_MouseAbsoluteDisabled);
     157    return (uisession()->isMouseCaptured() ? UIMouseStateType_MouseCaptured : 0) |
     158           (uisession()->isMouseSupportsAbsolute() ? UIMouseStateType_MouseAbsolute : 0) |
     159           (uisession()->isMouseIntegrated() ? 0 : UIMouseStateType_MouseAbsoluteDisabled);
    162160}
    163161
    164162void UIMachineView::setMouseIntegrationEnabled(bool bEnabled)
    165163{
    166     if (m_bIsMouseIntegrated == bEnabled)
     164    if (uisession()->isMouseIntegrated() == bEnabled)
    167165        return;
    168166
    169     if (m_fIsMouseSupportsAbsolute)
     167    if (uisession()->isMouseSupportsAbsolute())
    170168        captureMouse(!bEnabled, false);
    171169
    172170    /* Hiding host cursor in case we are entering mouse integration
    173      * mode until it's shape is set to the guest cursor shape in
    174      * OnMousePointerShapeChange event handler.
    175      *
    176      * This is necessary to avoid double-cursor issues where both the
    177      * guest and the host cursors are displayed in one place, one above the
    178      * other.
    179      *
    180      * This is a workaround because the correct decision would be to notify
    181      * the Guest Additions about we are entering the mouse integration
    182      * mode. The GuestOS should hide it's cursor to allow using of
    183      * host cursor for the guest's manipulation.
    184      *
    185      * This notification is not always possible though, as not all guests
    186      * support switching to a hardware pointer on demand. */
     171     * mode until it's shape is set to the guest cursor shape. */
    187172    if (bEnabled)
    188173        viewport()->setCursor(QCursor(Qt::BlankCursor));
    189174
    190     m_bIsMouseIntegrated = bEnabled;
     175    uisession()->setMouseIntegrated(bEnabled);
    191176
    192177    emitMouseStateChanged();
     
    201186    : QAbstractScrollArea(pMachineWindow->machineWindow())
    202187    , m_pMachineWindow(pMachineWindow)
    203     , m_console(pMachineWindow->machineLogic()->uisession()->session().GetConsole())
    204188    , m_mode(renderMode)
    205189    , m_globalSettings(vboxGlobal().settings())
    206     , m_machineState(KMachineState_Null)
    207190    , m_pFrameBuffer(0)
    208191#if defined(Q_WS_WIN)
     
    210193#endif
    211194    , m_iLastMouseWheelDelta(0)
    212     , m_uNumLockAdaptionCnt(2)
    213     , m_uCapsLockAdaptionCnt(2)
    214195    , m_bIsAutoCaptureDisabled(false)
    215196    , m_bIsKeyboardCaptured(false)
    216     , m_bIsMouseCaptured(false)
    217     , m_fIsMouseSupportsAbsolute(false)
    218     , m_fIsMouseSupportsRelative(false)
    219     , m_bIsMouseIntegrated(true)
    220     , m_fIsHideHostPointer(true)
    221197    , m_bIsHostkeyPressed(false)
    222198    , m_bIsHostkeyAlone (false)
    223199    , m_bIsHostkeyInCapture(false)
    224     , m_bIsGuestSupportsGraphics(false)
    225200    , m_bIsMachineWindowResizeIgnored(true)
    226201    , m_bIsFrameBufferResizeIgnored(false)
    227     , m_bIsGuestResizeIgnored(false)
    228     , m_fNumLock(false)
    229     , m_fCapsLock(false)
    230     , m_fScrollLock(false)
    231202    , m_fPassCAD(false)
    232203#ifdef VBOX_WITH_VIDEOHWACCEL
     
    251222UIMachineView::~UIMachineView()
    252223{
     224}
     225
     226UISession* UIMachineView::uisession() const
     227{
     228    return machineWindowWrapper()->machineLogic()->uisession();
     229}
     230
     231CSession& UIMachineView::session()
     232{
     233    return uisession()->session();
    253234}
    254235
     
    385366void UIMachineView::prepareFrameBuffer()
    386367{
    387     CDisplay display = m_console.GetDisplay();
     368    CDisplay display = session().GetConsole().GetDisplay();
    388369    Assert(!display.isNull());
    389370    m_pFrameBuffer = NULL;
     
    527508    /* Overlay logo for the dock icon */
    528509    //mVirtualBoxLogo = ::darwinToCGImageRef("VirtualBox_cube_42px.png");
    529     QString osTypeId = m_console.GetGuest().GetOSTypeId();
     510    QString osTypeId = session().GetConsole().GetGuest().GetOSTypeId();
    530511
    531512    // TODO_NEW_CORE
     
    573554
    574555    /* Machine state-change updater: */
    575     connect(sender, SIGNAL(sigStateChange(KMachineState)), this, SLOT(sltMachineStateChanged(KMachineState)));
     556    connect(sender, SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
    576557
    577558    /* Guest additions state-change updater: */
    578559    connect(sender, SIGNAL(sigAdditionsStateChange()), this, SLOT(sltAdditionsStateChanged()));
    579560
    580     /* Keyboard LEDs state-change updater: */
    581     connect(sender, SIGNAL(sigKeyboardLedsChange(bool, bool, bool)), this, SLOT(sltKeyboardLedsChanged(bool, bool, bool)));
    582 
    583561    /* Mouse pointer shape state-change updater: */
    584     connect(sender, SIGNAL(sigMousePointerShapeChange(bool, bool, uint, uint, uint, uint, const uchar *)),
    585             this, SLOT(sltMousePointerShapeChanged(bool, bool, uint, uint, uint, uint, const uchar *)));
     562    connect(sender, SIGNAL(sigMousePointerShapeChange()), this, SLOT(sltMousePointerShapeChanged()));
    586563
    587564    /* Mouse capability state-change updater: */
    588     connect(sender, SIGNAL(sigMouseCapabilityChange(bool, bool, bool)), this, SLOT(sltMouseCapabilityChanged(bool, bool, bool)));
     565    connect(sender, SIGNAL(sigMouseCapabilityChange()), this, SLOT(sltMouseCapabilityChanged()));
    589566}
    590567
     
    617594    {
    618595        /* CAD settings: */
    619         QString passCAD = m_console.GetMachine().GetExtraData(VBoxDefs::GUI_PassCAD);
     596        QString passCAD = session().GetConsole().GetMachine().GetExtraData(VBoxDefs::GUI_PassCAD);
    620597        if (!passCAD.isEmpty() && ((passCAD != "false") || (passCAD != "no")))
    621598            m_fPassCAD = true;
    622599    }
    623600
    624 #if 0
    625     /* Dynamical property settings: */
    626     {
    627         /* Get loader: */
    628         UISession *loader = machineWindowWrapper()->machineLogic()->uisession();
    629 
    630         /* Load dynamical properties: */
    631         m_machineState = loader->property("MachineView/MachineState").value<KMachineState>();
    632         m_uNumLockAdaptionCnt = loader->property("MachineView/NumLockAdaptionCnt").toUInt();
    633         m_uCapsLockAdaptionCnt = loader->property("MachineView/CapsLockAdaptionCnt").toUInt();
    634         m_bIsAutoCaptureDisabled = loader->property("MachineView/IsAutoCaptureDisabled").toBool();
    635         m_bIsKeyboardCaptured = loader->property("MachineView/IsKeyboardCaptured").toBool();
    636         m_bIsMouseCaptured = loader->property("MachineView/IsMouseCaptured").toBool();
    637         m_fIsMouseSupportsAbsolute = loader->property("MachineView/IsMouseSupportsAbsolute").toBool();
    638         m_fIsMouseSupportsRelative = loader->property("MachineView/IsMouseSupportsRelative").toBool();
    639         m_bIsMouseIntegrated = loader->property("MachineView/IsMouseIntegrated").toBool();
    640         m_fIsHideHostPointer = loader->property("MachineView/IsHideHostPointer").toBool();
    641         m_bIsHostkeyInCapture = loader->property("MachineView/IsHostkeyInCapture").toBool();
    642         m_bIsGuestSupportsGraphics = loader->property("MachineView/IsGuestSupportsGraphics").toBool();
    643         m_fNumLock = loader->property("MachineView/IsNumLock").toBool();
    644         m_fCapsLock = loader->property("MachineView/IsCapsLock").toBool();
    645         m_fScrollLock = loader->property("MachineView/IsScrollLock").toBool();
    646 
    647         /* Update related things: */
    648         updateMachineState();
    649         updateAdditionsState();
    650         updateMousePointerShape();
    651         updateMouseCapability();
    652     }
    653 #endif
    654 }
    655 
    656 void UIMachineView::saveMachineViewSettings()
    657 {
    658 #if 0
    659     /* Dynamical property settings: */
    660     {
    661         /* Get saver: */
    662         UISession *saver = machineWindowWrapper()->machineLogic()->uisession();
    663 
    664         /* Save dynamical properties: */
    665         saver->setProperty("MachineView/MachineState", QVariant::fromValue(machineState()));
    666         saver->setProperty("MachineView/NumLockAdaptionCnt", m_uNumLockAdaptionCnt);
    667         saver->setProperty("MachineView/CapsLockAdaptionCnt", m_uCapsLockAdaptionCnt);
    668         saver->setProperty("MachineView/IsAutoCaptureDisabled", m_bIsAutoCaptureDisabled);
    669         saver->setProperty("MachineView/IsKeyboardCaptured", m_bIsKeyboardCaptured);
    670         saver->setProperty("MachineView/IsMouseCaptured", m_bIsMouseCaptured);
    671         saver->setProperty("MachineView/IsMouseSupportsAbsolute", m_fIsMouseSupportsAbsolute);
    672         saver->setProperty("MachineView/IsMouseSupportsRelative", m_fIsMouseSupportsRelative);
    673         saver->setProperty("MachineView/IsMouseIntegrated", m_bIsMouseIntegrated);
    674         saver->setProperty("MachineView/IsHideHostPointer", m_fIsHideHostPointer);
    675         saver->setProperty("MachineView/IsHostkeyInCapture", m_bIsHostkeyInCapture);
    676         saver->setProperty("MachineView/IsGuestSupportsGraphics", m_bIsGuestSupportsGraphics);
    677         saver->setProperty("MachineView/IsNumLock", m_fNumLock);
    678         saver->setProperty("MachineView/IsCapsLock", m_fCapsLock);
    679         saver->setProperty("MachineView/IsScrollLock", m_fScrollLock);
    680     }
     601#ifdef Q_WS_MAC
     602    QString strSettings = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
     603    /* Default to true if it is an empty value: */
     604    bool fIsDockIconEnabled = strSettings.isEmpty() || strSettings == "true";
     605    setDockIconEnabled(fIsDockIconEnabled);
     606    updateDockOverlay();
    681607#endif
    682608}
     
    717643    {
    718644        /* Detach framebuffer from Display: */
    719         CDisplay display = console().GetDisplay();
     645        CDisplay display = session().GetConsole().GetDisplay();
    720646        display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(NULL));
    721647        /* Release the reference: */
     
    725651}
    726652
    727 void UIMachineView::updateMachineState()
    728 {
    729     switch (machineState())
     653void UIMachineView::sltMachineStateChanged()
     654{
     655    /* Get machine state: */
     656    KMachineState state = uisession()->machineState();
     657    switch (state)
    730658    {
    731659        case KMachineState_Paused:
     
    733661        {
    734662            if (mode() != VBoxDefs::TimerMode &&  m_pFrameBuffer &&
    735                 (machineState() != KMachineState_TeleportingPausedVM || machineState() != KMachineState_Teleporting))
     663                (state != KMachineState_TeleportingPausedVM || state != KMachineState_Teleporting))
    736664            {
    737665                /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */
    738666                QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);
    739                 CDisplay dsp = m_console.GetDisplay();
     667                CDisplay dsp = session().GetConsole().GetDisplay();
    740668                dsp.TakeScreenShot(shot.bits(), shot.width(), shot.height());
    741669                /* TakeScreenShot() may fail if, e.g. the Paused notification was delivered
     
    759687        case KMachineState_Running:
    760688        {
    761             if (machineState() == KMachineState_Paused || machineState() == KMachineState_TeleportingPausedVM)
     689            if (state == KMachineState_Paused || state == KMachineState_TeleportingPausedVM)
    762690            {
    763691                if (mode() != VBoxDefs::TimerMode && m_pFrameBuffer)
     
    767695                    /* Ask for full guest display update (it will also update
    768696                     * the viewport through IFramebuffer::NotifyUpdate): */
    769                     CDisplay dsp = m_console.GetDisplay();
     697                    CDisplay dsp = session().GetConsole().GetDisplay();
    770698                    dsp.InvalidateAndUpdate();
    771699                }
     
    779707            break;
    780708    }
    781 }
    782 
    783 void UIMachineView::updateAdditionsState()
     709
     710#ifdef Q_WS_MAC
     711    /* Update Dock Overlay: */
     712    updateDockOverlay();
     713#endif /* Q_WS_MAC */
     714}
     715
     716void UIMachineView::sltAdditionsStateChanged()
    784717{
    785718    /* Check if we should restrict minimum size: */
     
    795728}
    796729
    797 void UIMachineView::updateMousePointerShape()
    798 {
    799     if (m_fIsMouseSupportsAbsolute)
     730void UIMachineView::sltMousePointerShapeChanged()
     731{
     732    if (uisession()->isMouseSupportsAbsolute())
    800733    {
    801734        /* Should we hide/show pointer? */
    802         if (m_fIsHideHostPointer)
     735        if (uisession()->isHidingHostPointer())
    803736            viewport()->setCursor(Qt::BlankCursor);
    804737        else
    805             viewport()->setCursor(m_lastCursor);
    806     }
    807 }
    808 
    809 void UIMachineView::updateMouseCapability()
     738            viewport()->setCursor(uisession()->cursor());
     739    }
     740}
     741
     742void UIMachineView::sltMouseCapabilityChanged()
    810743{
    811744    /* Correct the mouse capture state and reset the cursor to the default shape if necessary: */
    812     if (m_fIsMouseSupportsAbsolute)
    813     {
    814         CMouse mouse = m_console.GetMouse();
    815         mouse.PutMouseEventAbsolute(-1, -1, 0, 0 /* Horizontal wheel */, 0);
     745    if (uisession()->isMouseSupportsAbsolute())
     746    {
     747        CMouse mouse = session().GetConsole().GetMouse();
     748        mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0);
    816749        captureMouse(false, false);
    817750    }
     
    820753
    821754    /* Notify user about mouse integration state: */
    822     vboxProblem().remindAboutMouseIntegration(m_fIsMouseSupportsAbsolute);
    823 
    824     /* Notify all watchers: */
     755    vboxProblem().remindAboutMouseIntegration(uisession()->isMouseSupportsAbsolute());
     756
     757    /* Notify all listeners: */
    825758    emitMouseStateChanged();
    826 }
    827 
    828 void UIMachineView::sltMachineStateChanged(KMachineState state)
    829 {
    830     /* Check if something had changed: */
    831     if (m_machineState != state)
    832     {
    833         /* Set new data: */
    834         m_machineState = state;
    835 
    836         /* Update depending things: */
    837         updateMachineState();
    838     }
    839 }
    840 
    841 void UIMachineView::sltAdditionsStateChanged()
    842 {
    843     /* Get new values: */
    844     CGuest guest = console().GetGuest();
    845     bool bIsGuestSupportsGraphics = guest.GetSupportsGraphics();
    846 
    847     /* Check if something had changed: */
    848     if (m_bIsGuestSupportsGraphics != bIsGuestSupportsGraphics)
    849     {
    850         /* Get new data: */
    851         m_bIsGuestSupportsGraphics = bIsGuestSupportsGraphics;
    852 
    853         /* Update depending things: */
    854         updateAdditionsState();
    855     }
    856 }
    857 
    858 void UIMachineView::sltKeyboardLedsChanged(bool bNumLock, bool bCapsLock, bool bScrollLock)
    859 {
    860     /* Update num lock status: */
    861     if (m_fNumLock != bNumLock)
    862     {
    863         m_fNumLock = bNumLock;
    864         m_uNumLockAdaptionCnt = 2;
    865     }
    866 
    867     /* Update caps lock status: */
    868     if (m_fCapsLock != bCapsLock)
    869     {
    870         m_fCapsLock = bCapsLock;
    871         m_uCapsLockAdaptionCnt = 2;
    872     }
    873 
    874     /* Update scroll lock status: */
    875     if (m_fScrollLock != bScrollLock)
    876         m_fScrollLock = bScrollLock;
    877 }
    878 
    879 void UIMachineView::sltMousePointerShapeChanged(bool fIsVisible, bool fHasAlpha,
    880                                                 uint uXHot, uint uYHot, uint uWidth, uint uHeight,
    881                                                 const uchar *pShapeData)
    882 {
    883     /* Should we show cursor anyway? */
    884     m_fIsHideHostPointer = !fIsVisible;
    885 
    886     /* Should we cache shape data? */
    887     if (pShapeData)
    888         setPointerShape(pShapeData, fHasAlpha, uXHot, uYHot, uWidth, uHeight);
    889 
    890     /* Perform cursor update: */
    891     updateMousePointerShape();
    892 }
    893 
    894 void UIMachineView::sltMouseCapabilityChanged(bool fIsMouseSupportsAbsolute, bool fIsMouseSupportsRelative, bool /* fIsMouseNeedsHostCursor */)
    895 {
    896     /* Check if something had changed: */
    897     if (m_fIsMouseSupportsAbsolute != fIsMouseSupportsAbsolute || m_fIsMouseSupportsRelative != fIsMouseSupportsRelative)
    898     {
    899         /* Get new data: */
    900         m_fIsMouseSupportsAbsolute = fIsMouseSupportsAbsolute;
    901         m_fIsMouseSupportsRelative = fIsMouseSupportsRelative;
    902 
    903         /* Update depending things: */
    904         updateMouseCapability();
    905     }
    906759}
    907760
     
    952805        case QEvent::FocusIn:
    953806        {
    954             if (isRunning())
     807            if (uisession()->isRunning())
    955808                focusEvent(true);
    956809            break;
     
    958811        case QEvent::FocusOut:
    959812        {
    960             if (isRunning())
     813            if (uisession()->isRunning())
    961814                focusEvent(false);
    962815            else
     
    975828             * to be ignored at all, leaving previous framebuffer,
    976829             * machine view and machine window sizes preserved: */
    977             if (m_bIsGuestResizeIgnored)
     830            if (uisession()->isGuestResizeIgnored())
    978831                return true;
    979832
     
    991844             * Moreover the current cursor, which could be set by the guest, should be restored after resize: */
    992845            QCursor cursor;
    993             if (shouldHideHostPointer())
     846            if (uisession()->isHidingHostPointer())
    994847                cursor = QCursor(Qt::BlankCursor);
    995848            else
     
    1007860             * which was unset to default here will not be hidden in capture state. So it is necessary to perform
    1008861             * updateMouseClipping() for the guest resize event if the mouse cursor was captured: */
    1009             if (m_bIsMouseCaptured)
     862            if (uisession()->isMouseCaptured())
    1010863                updateMouseClipping();
    1011864
     
    1035888
    1036889            /* Report to the VM thread that we finished resizing */
    1037             m_console.GetDisplay().ResizeCompleted(0);
     890            session().GetConsole().GetDisplay().ResizeCompleted(0);
    1038891
    1039892            m_bIsMachineWindowResizeIgnored = oldIgnoreMainwndResize;
     
    1063916            viewport()->repaint(pPaintEvent->x() - contentsX(), pPaintEvent->y() - contentsY(),
    1064917                                pPaintEvent->width(), pPaintEvent->height());
    1065             /* m_console.GetDisplay().UpdateCompleted(); - the event was acked already */
     918            /* session().GetConsole().GetDisplay().UpdateCompleted(); - the event was acked already */
    1066919            return true;
    1067920        }
     
    1103956            {
    1104957                bool pressed = pEvent->type() == QEvent::KeyPress;
    1105                 CKeyboard keyboard = m_console.GetKeyboard();
     958                CKeyboard keyboard = session().GetConsole().GetKeyboard();
    1106959
    1107960                /* Whether the host key is Shift so that it will modify the hot key values?
     
    11941047                        Assert(0);
    11951048
    1196                     CKeyboard keyboard = m_console.GetKeyboard();
     1049                    CKeyboard keyboard = session().GetConsole().GetKeyboard();
    11971050                    keyboard.PutScancodes(combo);
    11981051                }
     
    12031056                    /* Activate the main menu */
    12041057                    if (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen())
    1205                         machineWindowWrapper()->popupMainMenu (m_bIsMouseCaptured);
     1058                        machineWindowWrapper()->popupMainMenu (uisession()->isMouseCaptured());
    12061059                    else
    12071060                    {
     
    12241077            {
    12251078                /* Show a possible warning on key release which seems to be more expected by the end user: */
    1226                 if (machineWindowWrapper()->machineLogic()->isPaused())
     1079                if (uisession()->isPaused())
    12271080                {
    12281081                    /* Iif the reminder is disabled we pass the event to Qt to enable normal
     
    13241177            case QEvent::Resize:
    13251178            {
    1326                 if (m_bIsMouseCaptured)
     1179                if (uisession()->isMouseCaptured())
    13271180                    updateMouseClipping();
    13281181#ifdef VBOX_WITH_VIDEOHWACCEL
     
    15331386                 * that's not possible because we cannot predict what other
    15341387                 * keys will be pressed next when one of C, A, D is held. */
    1535                 if (isRunning() && m_bIsKeyboardCaptured)
     1388                if (uisession()->isRunning() && m_bIsKeyboardCaptured)
    15361389                {
    15371390                    captureKbd (false);
    1538                     if (!(m_fIsMouseSupportsAbsolute && m_bIsMouseIntegrated))
     1391                    if (!(uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated()))
    15391392                        captureMouse (false);
    15401393                }
     
    15891442            {
    15901443                m_bIsHostkeyPressed = m_bIsHostkeyAlone = true;
    1591                 if (isRunning())
     1444                if (uisession()->isRunning())
    15921445                    saveKeyStates();
    15931446                emitSignal = true;
     
    16161469                if (m_bIsHostkeyAlone)
    16171470                {
    1618                     if (machineWindowWrapper()->machineLogic()->isPaused())
     1471                    if (uisession()->isPaused())
    16191472                    {
    16201473                        vboxProblem().remindAboutPausedVMInput();
    16211474                    }
    1622                     else if (isRunning())
     1475                    else if (uisession()->isRunning())
    16231476                    {
    16241477                        bool captured = m_bIsKeyboardCaptured;
     
    16441497                        {
    16451498                            captureKbd (!captured, false);
    1646                             if (!(m_fIsMouseSupportsAbsolute && m_bIsMouseIntegrated))
     1499                            if (!(uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated()))
    16471500                            {
    16481501#ifdef Q_WS_X11
     
    16581511                }
    16591512
    1660                 if (isRunning())
     1513                if (uisession()->isRunning())
    16611514                    sendChangedKeyStates();
    16621515
     
    17281581
    17291582    /* No more to do, if the host key is in action or the VM is paused: */
    1730     if (m_bIsHostkeyPressed || isHostKey || machineWindowWrapper()->machineLogic()->isPaused())
     1583    if (m_bIsHostkeyPressed || isHostKey || uisession()->isPaused())
    17311584    {
    17321585        /* Grab the key from Qt and from VM if it's a host key,
     
    17351588    }
    17361589
    1737     CKeyboard keyboard = m_console.GetKeyboard();
     1590    CKeyboard keyboard = session().GetConsole().GetKeyboard();
    17381591    Assert(!keyboard.isNull());
    17391592
     
    18031656        wheelHorizontal = aWheelDelta / 120;
    18041657
    1805     if (m_bIsMouseCaptured)
     1658    if (uisession()->isMouseCaptured())
    18061659    {
    18071660#ifdef Q_WS_WIN32
     
    18101663#endif
    18111664
    1812         CMouse mouse = m_console.GetMouse();
     1665        CMouse mouse = session().GetConsole().GetMouse();
    18131666        mouse.PutMouseEvent(aGlobalPos.x() - m_lastMousePos.x(),
    18141667                            aGlobalPos.y() - m_lastMousePos.y(),
     
    19031756        return true; /* stop further event handling */
    19041757    }
    1905     else /* !m_bIsMouseCaptured */
     1758    else /* !uisession()->isMouseCaptured() */
    19061759    {
    19071760#if 0 // TODO: Move that to fullscreen event-hjadler:
     
    19281781#endif
    19291782
    1930         if (m_fIsMouseSupportsAbsolute && m_bIsMouseIntegrated)
     1783        if (uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())
    19311784        {
    19321785            int cw = contentsWidth(), ch = contentsHeight();
     
    19531806            else if (cpnt.y() > ch) cpnt.setY (ch);
    19541807
    1955             CMouse mouse = m_console.GetMouse();
     1808            CMouse mouse = session().GetConsole().GetMouse();
    19561809            mouse.PutMouseEventAbsolute (cpnt.x(), cpnt.y(), wheelVertical,
    19571810                                         wheelHorizontal, state);
     
    19621815            if (hasFocus() && (aType == QEvent::MouseButtonRelease && aButtons == Qt::NoButton))
    19631816            {
    1964                 if (machineWindowWrapper()->machineLogic()->isPaused())
     1817                if (uisession()->isPaused())
    19651818                {
    19661819                    vboxProblem().remindAboutPausedVMInput();
    19671820                }
    1968                 else if (isRunning())
     1821                else if (uisession()->isRunning())
    19691822                {
    19701823                    /* Temporarily disable auto capture that will take place after this dialog is dismissed because
     
    20241877        /* Update the dock icon if we are in the running state */
    20251878            // TODO_NEW_CORE
    2026 //        if (isRunning())
     1879//        if (uisession()->isRunning())
    20271880//            updateDockIcon();
    20281881#endif
     
    23162169        case XFocusOut:
    23172170        case XFocusIn:
    2318             if (isRunning())
     2171            if (uisession()->isRunning())
    23192172                focusEvent(pEvent->type == XFocusIn);
    23202173            return false;
     
    25692422#endif
    25702423
    2571 void UIMachineView::fixModifierState(LONG *piCodes, uint *puCount)
     2424void UIMachineView::fixModifierState(int *piCodes, uint *puCount)
    25722425{
    25732426    /* Synchronize the views of the host and the guest to the modifier keys.
     
    25972450    XFreeModifiermap(map);
    25982451
    2599     if (m_uNumLockAdaptionCnt && (m_fNumLock ^ !!(uMask & uKeyMaskNum)))
    2600     {
    2601         -- m_uNumLockAdaptionCnt;
     2452    if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(uMask & uKeyMaskNum)))
     2453    {
     2454        uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1);
    26022455        piCodes[(*puCount)++] = 0x45;
    26032456        piCodes[(*puCount)++] = 0x45 | 0x80;
    26042457    }
    2605     if (m_uCapsLockAdaptionCnt && (m_fCapsLock ^ !!(uMask & uKeyMaskCaps)))
    2606     {
    2607         m_uCapsLockAdaptionCnt--;
     2458    if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(uMask & uKeyMaskCaps)))
     2459    {
     2460        uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1);
     2461        piCodes[(*puCount)++] = 0x3a;
     2462        piCodes[(*puCount)++] = 0x3a | 0x80;
     2463        /* Some keyboard layouts require shift to be pressed to break
     2464         * capslock.  For simplicity, only do this if shift is not
     2465         * already held down. */
     2466        if (uisession()->isCapsLock() && !(m_pressedKeys[0x2a] & IsKeyPressed))
     2467        {
     2468            piCodes[(*puCount)++] = 0x2a;
     2469            piCodes[(*puCount)++] = 0x2a | 0x80;
     2470        }
     2471    }
     2472
     2473#elif defined(Q_WS_WIN32)
     2474
     2475    if (uisession()->numLockAdaptionCnt() && (m_fNumLock ^ !!(GetKeyState(VK_NUMLOCK))))
     2476    {
     2477        uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1);
     2478        piCodes[(*puCount)++] = 0x45;
     2479        piCodes[(*puCount)++] = 0x45 | 0x80;
     2480    }
     2481    if (uisession()->capsLockAdaptionCnt() && (m_fCapsLock ^ !!(GetKeyState(VK_CAPITAL))))
     2482    {
     2483        uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1);
    26082484        piCodes[(*puCount)++] = 0x3a;
    26092485        piCodes[(*puCount)++] = 0x3a | 0x80;
     
    26182494    }
    26192495
    2620 #elif defined(Q_WS_WIN32)
    2621 
    2622     if (m_uNumLockAdaptionCnt && (m_fNumLock ^ !!(GetKeyState(VK_NUMLOCK))))
    2623     {
    2624         m_uNumLockAdaptionCnt--;
    2625         piCodes[(*puCount)++] = 0x45;
    2626         piCodes[(*puCount)++] = 0x45 | 0x80;
    2627     }
    2628     if (m_uCapsLockAdaptionCnt && (m_fCapsLock ^ !!(GetKeyState(VK_CAPITAL))))
    2629     {
    2630         m_uCapsLockAdaptionCnt--;
    2631         piCodes[(*puCount)++] = 0x3a;
    2632         piCodes[(*puCount)++] = 0x3a | 0x80;
    2633         /* Some keyboard layouts require shift to be pressed to break
    2634          * capslock.  For simplicity, only do this if shift is not
    2635          * already held down. */
    2636         if (m_fCapsLock && !(m_pressedKeys[0x2a] & IsKeyPressed))
    2637         {
    2638             piCodes[(*puCount)++] = 0x2a;
    2639             piCodes[(*puCount)++] = 0x2a | 0x80;
    2640         }
    2641     }
    2642 
    26432496#elif defined(Q_WS_MAC)
    26442497
    2645     /* if (m_uNumLockAdaptionCnt) ... - NumLock isn't implemented by Mac OS X so ignore it. */
    2646     if (m_uCapsLockAdaptionCnt && (m_fCapsLock ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
    2647     {
    2648         m_uCapsLockAdaptionCnt--;
     2498    /* if (uisession()->numLockAdaptionCnt()) ... - NumLock isn't implemented by Mac OS X so ignore it. */
     2499    if (uisession()->capsLockAdaptionCnt() && (m_fCapsLock ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
     2500    {
     2501        uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1);
    26492502        piCodes[(*puCount)++] = 0x3a;
    26502503        piCodes[(*puCount)++] = 0x3a | 0x80;
     
    27582611void UIMachineView::captureMouse(bool fCapture, bool fEmitSignal /* = true */)
    27592612{
    2760     if (m_bIsMouseCaptured == fCapture)
     2613    if (uisession()->isMouseCaptured() == fCapture)
    27612614        return;
    27622615
     
    27872640#endif
    27882641        /* Release mouse buttons: */
    2789         CMouse mouse = m_console.GetMouse();
     2642        CMouse mouse = session().GetConsole().GetMouse();
    27902643        mouse.PutMouseEvent (0, 0, 0, 0 /* Horizontal wheel */, 0);
    27912644    }
    27922645
    2793     m_bIsMouseCaptured = fCapture;
     2646    uisession()->setMouseCaptured(fCapture);
    27942647
    27952648    updateMouseClipping();
     
    28062659void UIMachineView::releaseAllPressedKeys(bool aReleaseHostKey /* = true */)
    28072660{
    2808     CKeyboard keyboard = m_console.GetKeyboard();
     2661    CKeyboard keyboard = session().GetConsole().GetKeyboard();
    28092662    bool fSentRESEND = false;
    28102663
     
    28562709{
    28572710    QVector <LONG> codes(2);
    2858     CKeyboard keyboard = m_console.GetKeyboard();
     2711    CKeyboard keyboard = session().GetConsole().GetKeyboard();
    28592712    for (uint i = 0; i < SIZEOF_ARRAY(m_pressedKeys); ++ i)
    28602713    {
     
    28812734void UIMachineView::updateMouseClipping()
    28822735{
    2883     if (m_bIsMouseCaptured)
     2736    if (uisession()->isMouseCaptured())
    28842737    {
    28852738        viewport()->setCursor(QCursor(Qt::BlankCursor));
     
    29002753        viewport()->unsetCursor();
    29012754    }
    2902 }
    2903 
    2904 void UIMachineView::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
    2905                                     uint uXHot, uint uYHot, uint uWidth, uint uHeight)
    2906 {
    2907     AssertMsg(pShapeData, ("Shape data must not be NULL!\n"));
    2908 
    2909     bool ok = false;
    2910 
    2911     const uchar *srcAndMaskPtr = pShapeData;
    2912     uint andMaskSize = (uWidth + 7) / 8 * uHeight;
    2913     const uchar *srcShapePtr = pShapeData + ((andMaskSize + 3) & ~3);
    2914     uint srcShapePtrScan = uWidth * 4;
    2915 
    2916 #if defined (Q_WS_WIN)
    2917 
    2918     BITMAPV5HEADER bi;
    2919     HBITMAP hBitmap;
    2920     void *lpBits;
    2921 
    2922     ::ZeroMemory(&bi, sizeof (BITMAPV5HEADER));
    2923     bi.bV5Size = sizeof(BITMAPV5HEADER);
    2924     bi.bV5Width = uWidth;
    2925     bi.bV5Height = - (LONG)uHeight;
    2926     bi.bV5Planes = 1;
    2927     bi.bV5BitCount = 32;
    2928     bi.bV5Compression = BI_BITFIELDS;
    2929     bi.bV5RedMask   = 0x00FF0000;
    2930     bi.bV5GreenMask = 0x0000FF00;
    2931     bi.bV5BlueMask  = 0x000000FF;
    2932     if (fHasAlpha)
    2933         bi.bV5AlphaMask = 0xFF000000;
    2934     else
    2935         bi.bV5AlphaMask = 0;
    2936 
    2937     HDC hdc = GetDC(NULL);
    2938 
    2939     /* Create the DIB section with an alpha channel: */
    2940     hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD) 0);
    2941 
    2942     ReleaseDC(NULL, hdc);
    2943 
    2944     HBITMAP hMonoBitmap = NULL;
    2945     if (fHasAlpha)
    2946     {
    2947         /* Create an empty mask bitmap: */
    2948         hMonoBitmap = CreateBitmap(uWidth, uHeight, 1, 1, NULL);
    2949     }
    2950     else
    2951     {
    2952         /* Word aligned AND mask. Will be allocated and created if necessary. */
    2953         uint8_t *pu8AndMaskWordAligned = NULL;
    2954 
    2955         /* Width in bytes of the original AND mask scan line. */
    2956         uint32_t cbAndMaskScan = (uWidth + 7) / 8;
    2957 
    2958         if (cbAndMaskScan & 1)
    2959         {
    2960             /* Original AND mask is not word aligned. */
    2961 
    2962             /* Allocate memory for aligned AND mask. */
    2963             pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * uHeight);
    2964 
    2965             Assert(pu8AndMaskWordAligned);
    2966 
    2967             if (pu8AndMaskWordAligned)
    2968             {
    2969                 /* According to MSDN the padding bits must be 0.
    2970                  * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask. */
    2971                 uint32_t u32PaddingBits = cbAndMaskScan * 8  - uWidth;
    2972                 Assert(u32PaddingBits < 8);
    2973                 uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
    2974 
    2975                 Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
    2976                       u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, uWidth, cbAndMaskScan));
    2977 
    2978                 uint8_t *src = (uint8_t *)srcAndMaskPtr;
    2979                 uint8_t *dst = pu8AndMaskWordAligned;
    2980 
    2981                 unsigned i;
    2982                 for (i = 0; i < uHeight; i++)
    2983                 {
    2984                     memcpy(dst, src, cbAndMaskScan);
    2985 
    2986                     dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
    2987 
    2988                     src += cbAndMaskScan;
    2989                     dst += cbAndMaskScan + 1;
    2990                 }
    2991             }
    2992         }
    2993 
    2994         /* Create the AND mask bitmap: */
    2995         hMonoBitmap = ::CreateBitmap(uWidth, uHeight, 1, 1,
    2996                                      pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
    2997 
    2998         if (pu8AndMaskWordAligned)
    2999         {
    3000             RTMemTmpFree(pu8AndMaskWordAligned);
    3001         }
    3002     }
    3003 
    3004     Assert(hBitmap);
    3005     Assert(hMonoBitmap);
    3006     if (hBitmap && hMonoBitmap)
    3007     {
    3008         DWORD *dstShapePtr = (DWORD *) lpBits;
    3009 
    3010         for (uint y = 0; y < uHeight; y ++)
    3011         {
    3012             memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
    3013             srcShapePtr += srcShapePtrScan;
    3014             dstShapePtr += uWidth;
    3015         }
    3016 
    3017         ICONINFO ii;
    3018         ii.fIcon = FALSE;
    3019         ii.xHotspot = uXHot;
    3020         ii.yHotspot = uYHot;
    3021         ii.hbmMask = hMonoBitmap;
    3022         ii.hbmColor = hBitmap;
    3023 
    3024         HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
    3025         Assert(hAlphaCursor);
    3026         if (hAlphaCursor)
    3027         {
    3028             viewport()->setCursor(QCursor(hAlphaCursor));
    3029             ok = true;
    3030             if (m_alphaCursor)
    3031                 DestroyIcon(m_alphaCursor);
    3032             m_alphaCursor = hAlphaCursor;
    3033         }
    3034     }
    3035 
    3036     if (hMonoBitmap)
    3037         DeleteObject(hMonoBitmap);
    3038     if (hBitmap)
    3039         DeleteObject(hBitmap);
    3040 
    3041 #elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
    3042 
    3043     XcursorImage *img = XcursorImageCreate(uWidth, uHeight);
    3044     Assert(img);
    3045     if (img)
    3046     {
    3047         img->xhot = uXHot;
    3048         img->yhot = uYHot;
    3049 
    3050         XcursorPixel *dstShapePtr = img->pixels;
    3051 
    3052         for (uint y = 0; y < uHeight; y ++)
    3053         {
    3054             memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
    3055 
    3056             if (!fHasAlpha)
    3057             {
    3058                 /* Convert AND mask to the alpha channel: */
    3059                 uchar byte = 0;
    3060                 for (uint x = 0; x < uWidth; x ++)
    3061                 {
    3062                     if (!(x % 8))
    3063                         byte = *(srcAndMaskPtr ++);
    3064                     else
    3065                         byte <<= 1;
    3066 
    3067                     if (byte & 0x80)
    3068                     {
    3069                         /* Linux doesn't support inverted pixels (XOR ops,
    3070                          * to be exact) in cursor shapes, so we detect such
    3071                          * pixels and always replace them with black ones to
    3072                          * make them visible at least over light colors */
    3073                         if (dstShapePtr [x] & 0x00FFFFFF)
    3074                             dstShapePtr [x] = 0xFF000000;
    3075                         else
    3076                             dstShapePtr [x] = 0x00000000;
    3077                     }
    3078                     else
    3079                         dstShapePtr [x] |= 0xFF000000;
    3080                 }
    3081             }
    3082 
    3083             srcShapePtr += srcShapePtrScan;
    3084             dstShapePtr += uWidth;
    3085         }
    3086 
    3087         Cursor cur = XcursorImageLoadCursor(QX11Info::display(), img);
    3088         Assert (cur);
    3089         if (cur)
    3090         {
    3091             viewport()->setCursor(QCursor(cur));
    3092             ok = true;
    3093         }
    3094 
    3095         XcursorImageDestroy(img);
    3096     }
    3097 
    3098 #elif defined(Q_WS_MAC)
    3099 
    3100     /* Create a ARGB image out of the shape data. */
    3101     QImage image  (uWidth, uHeight, QImage::Format_ARGB32);
    3102     const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
    3103     unsigned cbSrcMaskLine = RT_ALIGN (uWidth, 8) / 8;
    3104     for (unsigned int y = 0; y < uHeight; ++y)
    3105     {
    3106         for (unsigned int x = 0; x < uWidth; ++x)
    3107         {
    3108            unsigned int color = ((unsigned int*)srcShapePtr)[y*uWidth+x];
    3109            /* If the alpha channel isn't in the shape data, we have to
    3110             * create them from the and-mask. This is a bit field where 1
    3111             * represent transparency & 0 opaque respectively. */
    3112            if (!fHasAlpha)
    3113            {
    3114                if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
    3115                    color  |= 0xff000000;
    3116                else
    3117                {
    3118                    /* This isn't quite right, but it's the best we can do I think... */
    3119                    if (color & 0x00ffffff)
    3120                        color = 0xff000000;
    3121                    else
    3122                        color = 0x00000000;
    3123                }
    3124            }
    3125            image.setPixel (x, y, color);
    3126         }
    3127         /* Move one scanline forward. */
    3128         pbSrcMask += cbSrcMaskLine;
    3129     }
    3130     /* Set the new cursor: */
    3131     QCursor cursor(QPixmap::fromImage(image), uXHot, uYHot);
    3132     viewport()->setCursor(cursor);
    3133     ok = true;
    3134     NOREF(srcShapePtrScan);
    3135 
    3136 #else
    3137 
    3138 # warning "port me"
    3139 
    3140 #endif
    3141 
    3142     if (ok)
    3143         m_lastCursor = viewport()->cursor();
    3144     else
    3145         viewport()->unsetCursor();
    31462755}
    31472756
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r26798 r26815  
    2424#define ___UIMachineView_h___
    2525
     26/* Global includes */
     27#include <QAbstractScrollArea>
     28
     29/* Local includes */
     30#include "VBoxDefs.h"
     31#include "UIMachineDefs.h"
     32
     33#ifdef Q_WS_MAC
     34# include <CoreFoundation/CFBase.h>
     35#endif /* Q_WS_MAC */
     36
    2637/* Local forwards */
     38class CSession;
     39class UISession;
    2740class UIFrameBuffer;
    2841class UIMachineWindow;
    2942class VBoxGlobalSettings;
    30 
    31 /* Global includes */
    32 #include <QAbstractScrollArea>
    33 
    34 /* Local includes */
    35 #include "COMDefs.h"
    36 #include "UIMachineDefs.h"
    37 
    38 #ifdef Q_WS_MAC
    39 # include <CoreFoundation/CFBase.h>
    40 #endif /* Q_WS_MAC */
    41 
    42 /* Local forwards */
    4343#ifdef Q_WS_MAC
    4444class VBoxChangeDockIconUpdateEvent;
     
    6161                                 , UIVisualStateType visualStateType);
    6262
    63     /* Public virtual members: */
    64     virtual void normalizeGeometry(bool bAdjustPosition = false) = 0;
    65 
    6663    /* Public getters: */
    6764    int keyboardState() const;
     
    6966
    7067    /* Public setters: */
    71     void setIgnoreGuestResize(bool bIgnore) { m_bIsGuestResizeIgnored = bIgnore; }
    7268    virtual void setGuestAutoresizeEnabled(bool bEnabled) = 0;
    7369    virtual void setMouseIntegrationEnabled(bool bEnabled);
    7470    //void setMachineViewFinalized(bool fTrue = true) { m_bIsMachineWindowResizeIgnored = !fTrue; }
     71
     72    /* Public members: */
     73    virtual void normalizeGeometry(bool bAdjustPosition = false) = 0;
    7574
    7675#if defined(Q_WS_MAC)
     
    105104
    106105    /* Protected getters: */
    107     UIMachineWindow* machineWindowWrapper() { return m_pMachineWindow; }
    108     CConsole &console() { return m_console; }
    109 
    110     /* Protected getters: */
    111     KMachineState machineState() const { return m_machineState; }
     106    UISession* uisession() const;
     107    CSession& session();
     108    UIMachineWindow* machineWindowWrapper() const { return m_pMachineWindow; }
    112109    VBoxDefs::RenderMode mode() const { return m_mode; }
    113110    QSize sizeHint() const;
     
    119116    int visibleHeight() const;
    120117    QRect desktopGeometry() const;
    121     bool isGuestSupportsGraphics() const { return m_bIsGuestSupportsGraphics; }
    122118    const QPixmap& pauseShot() const { return m_pauseShot; }
    123     //bool isMouseAbsolute() const { return m_fIsMouseSupportsAbsolute; }
    124119
    125120    /* Protected members: */
     
    138133
    139134    /* Cleanup routines: */
    140     virtual void saveMachineViewSettings();
    141     virtual void cleanupConsoleConnections() {}
    142     virtual void cleanupFilters() {}
     135    //virtual void saveMachineViewSettings() {}
     136    //virtual void cleanupConsoleConnections() {}
     137    //virtual void cleanupFilters() {}
    143138    virtual void cleanupCommon();
    144139    virtual void cleanupFrameBuffer();
    145140
    146     /* Update routines: */
    147     virtual void updateMachineState();
    148     virtual void updateAdditionsState();
    149     virtual void updateMousePointerShape();
    150     virtual void updateMouseCapability();
    151 
    152141protected slots:
    153142
    154143    /* Console callback handlers: */
    155     virtual void sltMachineStateChanged(KMachineState state);
     144    virtual void sltMachineStateChanged();
    156145    virtual void sltAdditionsStateChanged();
    157     virtual void sltKeyboardLedsChanged(bool bNumLock, bool bCapsLock, bool bScrollLock);
    158     virtual void sltMousePointerShapeChanged(bool fIsVisible, bool fHasAlpha,
    159                                              uint uXHot, uint uYHot, uint uWidth, uint uHeight,
    160                                              const uchar *pShapeData);
    161     virtual void sltMouseCapabilityChanged(bool bIsSupportsAbsolute, bool bIsSupportsRelative, bool bNeedsHostCursor);
     146    virtual void sltMousePointerShapeChanged();
     147    virtual void sltMouseCapabilityChanged();
    162148
    163149    /* Initiate resize request to guest: */
     
    212198
    213199    /* Private helpers: */
    214     void fixModifierState(LONG *piCodes, uint *puCount);
     200    void fixModifierState(int *piCodes, uint *puCount);
    215201    QPoint viewportToContents(const QPoint &vp) const;
    216202    void updateSliders();
     
    227213    void sendChangedKeyStates();
    228214    void updateMouseClipping();
    229     void setPointerShape(const uchar *pShapeData, bool fHasAlpha,
    230                          uint uXHot, uint uYHot, uint uWidth, uint uHeight);
    231 
    232     /* Private getters: */
    233     bool isRunning() { return m_machineState == KMachineState_Running || m_machineState == KMachineState_Teleporting || m_machineState == KMachineState_LiveSnapshotting; }
    234     bool shouldHideHostPointer() const { return m_bIsMouseCaptured || (m_fIsMouseSupportsAbsolute && m_fIsHideHostPointer); }
    235215
    236216    static void dimImage(QImage &img);
     
    238218    /* Private members: */
    239219    UIMachineWindow *m_pMachineWindow;
    240     CConsole m_console;
    241220    VBoxDefs::RenderMode m_mode;
    242221    const VBoxGlobalSettings &m_globalSettings;
    243     KMachineState m_machineState;
    244222    UIFrameBuffer *m_pFrameBuffer;
    245223
    246     QCursor m_lastCursor;
    247 #if defined(Q_WS_WIN)
    248     HCURSOR m_alphaCursor;
    249 #endif
    250224    QPoint m_lastMousePos;
    251225    QPoint m_capturedMousePos;
     
    255229    uint8_t m_pressedKeysCopy[128];
    256230
    257     uint m_uNumLockAdaptionCnt;
    258     uint m_uCapsLockAdaptionCnt;
    259 
    260231    bool m_bIsAutoCaptureDisabled : 1;
    261232    bool m_bIsKeyboardCaptured : 1;
    262     bool m_bIsMouseCaptured : 1;
    263     bool m_fIsMouseSupportsAbsolute : 1;
    264     bool m_fIsMouseSupportsRelative : 1;
    265     bool m_bIsMouseIntegrated : 1;
    266     bool m_fIsHideHostPointer;
    267233    bool m_bIsHostkeyPressed : 1;
    268234    bool m_bIsHostkeyAlone : 1;
    269235    bool m_bIsHostkeyInCapture : 1;
    270     bool m_bIsGuestSupportsGraphics : 1;
    271236    bool m_bIsMachineWindowResizeIgnored : 1;
    272237    bool m_bIsFrameBufferResizeIgnored : 1;
    273     bool m_bIsGuestResizeIgnored : 1;
    274     bool m_fNumLock : 1;
    275     bool m_fCapsLock : 1;
    276     bool m_fScrollLock : 1;
    277238    bool m_fPassCAD;
    278239#ifdef VBOX_WITH_VIDEOHWACCEL
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r26800 r26815  
    2727
    2828/* Local includes */
     29#include "COMDefs.h"
    2930#include "VBoxGlobal.h"
    3031#include "VBoxProblemReporter.h"
     
    9899}
    99100
    100 CSession UIMachineWindow::session()
    101 {
    102     return m_pMachineLogic->uisession()->session();
     101UISession* UIMachineWindow::uisession()
     102{
     103    return machineLogic()->uisession();
     104}
     105
     106CSession& UIMachineWindow::session()
     107{
     108    return uisession()->session();
    103109}
    104110
     
    131137    }
    132138
    133     switch (machineLogic()->machineState())
     139    /* Get machine state: */
     140    KMachineState state = uisession()->machineState();
     141
     142    switch (state)
    134143    {
    135144        case KMachineState_PoweredOff:
     
    161170            bool success = true;
    162171
    163             bool wasPaused = machineLogic()->machineState() == KMachineState_Paused ||
    164                              machineLogic()->machineState() == KMachineState_Stuck ||
    165                              machineLogic()->machineState() == KMachineState_TeleportingPausedVM;
     172            bool wasPaused = uisession()->isPaused() || state == KMachineState_Stuck;
    166173            if (!wasPaused)
    167174            {
    168175                /* Suspend the VM and ignore the close event if failed to do so.
    169176                 * pause() will show the error message to the user. */
    170                 success = machineLogic()->pause();
     177                success = uisession()->pause();
    171178            }
    172179
     
    185192                    dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(machine.GetCurrentSnapshot().GetName()));
    186193
    187                 if (machineLogic()->machineState() != KMachineState_Stuck)
     194                if (state != KMachineState_Stuck)
    188195                {
    189196                    /* Read the last user's choice for the given VM */
     
    246253                    {
    247254                        /* Unpause the VM to let it grab the ACPI shutdown event */
    248                         machineLogic()->unpause();
     255                        uisession()->unpause();
    249256                        /* Prevent the subsequent unpause request */
    250257                        wasPaused = true;
     
    330337            machineLogic()->setPreventAutoClose(false);
    331338
    332             if (machineLogic()->machineState() == KMachineState_PoweredOff ||
    333                 machineLogic()->machineState() == KMachineState_Saved ||
    334                 machineLogic()->machineState() == KMachineState_Teleported ||
    335                 machineLogic()->machineState() == KMachineState_Aborted)
     339            if (state == KMachineState_PoweredOff ||
     340                state == KMachineState_Saved ||
     341                state == KMachineState_Teleported ||
     342                state == KMachineState_Aborted)
    336343            {
    337344                /* The machine has been stopped while showing the Close or the Pause
     
    344351                {
    345352                    /* Restore the running state if needed */
    346                     if (!wasPaused && machineLogic()->machineState() == KMachineState_Paused)
    347                         machineLogic()->unpause();
     353                    if (!wasPaused && state == KMachineState_Paused)
     354                        uisession()->unpause();
    348355                }
    349356            }
     
    393400{
    394401    /* Machine state-change updater: */
    395     QObject::connect(machineLogic()->uisession(), SIGNAL(sigStateChange(KMachineState)),
    396                      machineWindow(), SLOT(sltMachineStateChanged(KMachineState)));
     402    QObject::connect(uisession(), SIGNAL(sigMachineStateChange()), machineWindow(), SLOT(sltMachineStateChanged()));
    397403}
    398404
     
    460466#endif /* VBOX_WITH_DEBUGGER_GUI */
    461467
    462 void UIMachineWindow::loadWindowSettings()
    463 {
    464 #ifdef Q_WS_MAC
    465     QString testStr = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
    466     /* Default to true if it is an empty value */
    467     bool bIsDockIconEnabled = testStr.isEmpty() || testStr == "true";
    468     if (machineView())
    469     {
    470         machineView()->setDockIconEnabled(bIsDockIconEnabled);
    471         machineView()->updateDockOverlay();
    472     }
    473 #endif
    474 }
    475 
    476468void UIMachineWindow::updateAppearanceOf(int iElement)
    477469{
     
    480472    if (iElement & UIVisualElement_WindowCaption)
    481473    {
     474        /* Get machine state: */
     475        KMachineState state = uisession()->machineState();
     476        /* Prepare full name: */
    482477        QString strSnapshotName;
    483478        if (machine.GetSnapshotCount() > 0)
     
    487482        }
    488483        QString strMachineName = machine.GetName() + strSnapshotName;
    489         if (machineLogic()->machineState() != KMachineState_Null)
    490             strMachineName += " [" + vboxGlobal().toString(machineLogic()->machineState()) + "] - ";
     484        if (state != KMachineState_Null)
     485            strMachineName += " [" + vboxGlobal().toString(state) + "] - ";
    491486        strMachineName += m_strWindowTitlePrefix;
    492487        machineWindow()->setWindowTitle(strMachineName);
     
    497492}
    498493
    499 void UIMachineWindow::sltMachineStateChanged(KMachineState /* machineState */)
     494void UIMachineWindow::sltMachineStateChanged()
    500495{
    501496    updateAppearanceOf(UIVisualElement_WindowCaption);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h

    r26800 r26815  
    2525
    2626/* Local includes */
    27 #include "COMDefs.h"
    2827#include "UIMachineDefs.h"
    2928
     
    3332
    3433/* Local forwards */
     34class CSession;
     35class UISession;
    3536class UIMachineLogic;
    3637class UIMachineView;
     
    5859    virtual ~UIMachineWindow();
    5960
     61    /* Protected wrappers: */
     62    UISession* uisession();
     63    CSession& session();
     64
    6065    /* Protected getters: */
    61     CSession session();
    6266    const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; }
    6367
     
    7680    virtual void prepareMenuDebug();
    7781#endif
    78     virtual void loadWindowSettings();
     82    //virtual void loadWindowSettings() {}
    7983
    8084    /* Cleanup helpers: */
     
    9296
    9397    /* Protected slots: */
    94     void sltMachineStateChanged(KMachineState machineState);
     98    virtual void sltMachineStateChanged();
    9599
    96100    /* Protected variables: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r26795 r26815  
    2828/* Local includes */
    2929#include "UISession.h"
    30 
    3130#include "UIMachine.h"
     31#include "UIActionsPool.h"
    3232#include "UIMachineLogic.h"
    3333#include "UIMachineWindow.h"
    34 
    35 #include "VBoxUtils.h"
     34#include "VBoxProblemReporter.h"
     35
     36#ifdef Q_WS_X11
     37# include <QX11Info>
     38# ifndef VBOX_WITHOUT_XCURSOR
     39#  include <X11/Xcursor/Xcursor.h>
     40# endif
     41#endif
     42
     43#if defined (Q_WS_MAC)
     44# include "VBoxUtils.h"
     45#endif
    3646
    3747/* Guest mouse pointer shape change event: */
     
    513523UISession::UISession(UIMachine *pMachine, const CSession &session)
    514524    : QObject(pMachine)
     525    /* Base variables: */
    515526    , m_pMachine(pMachine)
    516527    , m_session(session)
    517528    , m_pCallback(new UIConsoleCallback(this))
    518529    , m_callback(CConsoleCallback(m_pCallback))
     530    /* Common varibles: */
     531    , m_machineState(KMachineState_Null)
     532    /* Common flags: */
     533    , m_fIsFirstTimeStarted(false)
     534    , m_fIsIgnoreRutimeMediumsChanging(false)
     535    /* Guest additions flags: */
     536    , m_fIsGuestAdditionsActive(false)
     537    , m_fIsGuestSupportsGraphics(false)
     538    , m_fIsGuestSupportsSeamless(false)
     539    /* Mouse flags: */
     540    , m_fNumLock(false)
     541    , m_fCapsLock(false)
     542    , m_fScrollLock(false)
     543    , m_uNumLockAdaptionCnt(2)
     544    , m_uCapsLockAdaptionCnt(2)
     545    /* Mouse flags: */
     546    , m_fIsMouseSupportsAbsolute(false)
     547    , m_fIsMouseSupportsRelative(false)
     548    , m_fIsMouseHostCursorNeeded(false)
     549    , m_fIsMouseCaptured(false)
     550    , m_fIsMouseIntegrated(true)
     551    , m_fIsHideHostPointer(true)
    519552{
    520553    /* Check CSession object */
    521     AssertMsg(!m_session.isNull(), ("CSession is not set!\n"));
     554    AssertMsg(!m_session.isNull(), ("CSession should not be NULL!\n"));
    522555
    523556    /* Register console callback: */
    524557    m_session.GetConsole().RegisterCallback(m_callback);
     558
     559    /* Load session settings: */
     560    loadSessionSettings();
    525561}
    526562
    527563UISession::~UISession()
    528564{
     565    /* Save session settings: */
     566    saveSessionSettings();
     567
    529568    /* Unregister console callback: */
    530569    m_session.GetConsole().UnregisterCallback(m_callback);
     
    533572}
    534573
     574bool UISession::setPause(bool fOn)
     575{
     576    if (isPaused() == fOn)
     577        return true;
     578
     579    CConsole console = session().GetConsole();
     580
     581    if (fOn)
     582        console.Pause();
     583    else
     584        console.Resume();
     585
     586    bool ok = console.isOk();
     587    if (!ok)
     588    {
     589        if (fOn)
     590            vboxProblem().cannotPauseMachine(console);
     591        else
     592            vboxProblem().cannotResumeMachine(console);
     593    }
     594
     595    return ok;
     596}
     597
    535598bool UISession::event(QEvent *pEvent)
    536599{
     
    539602        case UIConsoleEventType_MousePointerShapeChange:
    540603        {
     604            /* Convert to mouse shape change event: */
    541605            UIMousePointerShapeChangeEvent *pConsoleEvent = static_cast<UIMousePointerShapeChangeEvent*>(pEvent);
    542             emit sigMousePointerShapeChange(pConsoleEvent->isVisible(), pConsoleEvent->hasAlpha(),
    543                                             pConsoleEvent->xHot(), pConsoleEvent->yHot(),
    544                                             pConsoleEvent->width(), pConsoleEvent->height(),
    545                                             pConsoleEvent->shapeData());
     606
     607            /* Remember if we should show cursor: */
     608            m_fIsHideHostPointer = !pConsoleEvent->isVisible();
     609
     610            /* Cache shape dataif present: */
     611            if (pConsoleEvent->shapeData())
     612                setPointerShape(pConsoleEvent->shapeData(), pConsoleEvent->hasAlpha(),
     613                                pConsoleEvent->xHot(), pConsoleEvent->yHot(),
     614                                pConsoleEvent->width(), pConsoleEvent->height());
     615
     616            /* Notify listeners about mouse capability changed: */
     617            emit sigMousePointerShapeChange();
     618
     619            /* Accept event: */
     620            pEvent->accept();
    546621            return true;
    547622        }
     
    549624        case UIConsoleEventType_MouseCapabilityChange:
    550625        {
     626            /* Convert to mouse capability event: */
    551627            UIMouseCapabilityChangeEvent *pConsoleEvent = static_cast<UIMouseCapabilityChangeEvent*>(pEvent);
    552             emit sigMouseCapabilityChange(pConsoleEvent->supportsAbsolute(), pConsoleEvent->supportsRelative(), pConsoleEvent->needsHostCursor());
     628
     629            /* Check if something had changed: */
     630            if (m_fIsMouseSupportsAbsolute != pConsoleEvent->supportsAbsolute() ||
     631                m_fIsMouseSupportsRelative != pConsoleEvent->supportsRelative() ||
     632                m_fIsMouseHostCursorNeeded != pConsoleEvent->needsHostCursor())
     633            {
     634                /* Store new data: */
     635                m_fIsMouseSupportsAbsolute = pConsoleEvent->supportsAbsolute();
     636                m_fIsMouseSupportsRelative = pConsoleEvent->supportsRelative();
     637                m_fIsMouseHostCursorNeeded = pConsoleEvent->needsHostCursor();
     638
     639                /* Notify listeners about mouse capability changed: */
     640                emit sigMouseCapabilityChange();
     641            }
     642
     643            /* Accept event: */
     644            pEvent->accept();
    553645            return true;
    554646        }
     
    556648        case UIConsoleEventType_KeyboardLedsChange:
    557649        {
     650            /* Convert to keyboard LEDs change event: */
    558651            UIKeyboardLedsChangeEvent *pConsoleEvent = static_cast<UIKeyboardLedsChangeEvent*>(pEvent);
    559             emit sigKeyboardLedsChange(pConsoleEvent->numLock(), pConsoleEvent->capsLock(), pConsoleEvent->scrollLock());
     652
     653            /* Check if something had changed: */
     654            if (m_fNumLock != pConsoleEvent->numLock() ||
     655                m_fCapsLock != pConsoleEvent->capsLock() ||
     656                m_fScrollLock != pConsoleEvent->scrollLock())
     657            {
     658                /* Store new num lock data: */
     659                if (m_fNumLock != pConsoleEvent->numLock())
     660                {
     661                    m_fNumLock = pConsoleEvent->numLock();
     662                    m_uNumLockAdaptionCnt = 2;
     663                }
     664
     665                /* Store new caps lock data: */
     666                if (m_fCapsLock != pConsoleEvent->capsLock())
     667                {
     668                    m_fCapsLock = pConsoleEvent->capsLock();
     669                    m_uCapsLockAdaptionCnt = 2;
     670                }
     671
     672                /* Store new scroll lock data: */
     673                if (m_fScrollLock != pConsoleEvent->scrollLock())
     674                {
     675                    m_fScrollLock = pConsoleEvent->scrollLock();
     676                }
     677
     678                /* Notify listeners about mouse capability changed: */
     679                emit sigKeyboardLedsChange();
     680            }
     681
     682            /* Accept event: */
     683            pEvent->accept();
    560684            return true;
    561685        }
     
    563687        case UIConsoleEventType_StateChange:
    564688        {
     689            /* Convert to machine state event: */
    565690            UIStateChangeEvent *pConsoleEvent = static_cast<UIStateChangeEvent*>(pEvent);
    566             emit sigStateChange(pConsoleEvent->machineState());
     691
     692            /* Check if something had changed: */
     693            if (m_machineState != pConsoleEvent->machineState())
     694            {
     695                /* Store new data: */
     696                m_machineState = pConsoleEvent->machineState();
     697
     698                /* Notify listeners about machine state changed: */
     699                emit sigMachineStateChange();
     700            }
     701
     702            /* Accept event: */
     703            pEvent->accept();
    567704            return true;
    568705        }
     
    570707        case UIConsoleEventType_AdditionsStateChange:
    571708        {
    572             emit sigAdditionsStateChange();
     709            /* Get our guest: */
     710            CGuest guest = session().GetConsole().GetGuest();
     711
     712            /* Variable flags: */
     713            bool fIsGuestAdditionsActive = guest.GetAdditionsActive();
     714            bool fIsGuestSupportsGraphics = guest.GetSupportsGraphics();
     715            bool fIsGuestSupportsSeamless = guest.GetSupportsSeamless();
     716
     717            /* Check if something had changed: */
     718            if (m_fIsGuestAdditionsActive != fIsGuestAdditionsActive ||
     719                m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics ||
     720                m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
     721            {
     722                /* Store new data: */
     723                m_fIsGuestAdditionsActive = fIsGuestAdditionsActive;
     724                m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
     725                m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
     726
     727                /* Notify listeners about guest additions state changed: */
     728                emit sigAdditionsStateChange();
     729            }
     730
     731            /* Accept event: */
     732            pEvent->accept();
    573733            return true;
    574734        }
     
    679839}
    680840
     841void UISession::loadSessionSettings()
     842{
     843    /* Get machine: */
     844    CMachine machine = session().GetConsole().GetMachine();
     845
     846    /* Availability settings: */
     847    {
     848        /* USB Stuff: */
     849        CUSBController usbController = machine.GetUSBController();
     850        if (usbController.isNull())
     851        {
     852            /* Hide USB menu if controller is NULL: */
     853            uimachine()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->setVisible(false);
     854        }
     855        else
     856        {
     857            /* Enable/Disable USB menu depending on USB controller: */
     858            uimachine()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->setEnabled(usbController.GetEnabled());
     859        }
     860
     861        /* VRDP Stuff: */
     862        CVRDPServer vrdpServer = machine.GetVRDPServer();
     863        if (vrdpServer.isNull())
     864        {
     865            /* Hide VRDP Action: */
     866            uimachine()->actionsPool()->action(UIActionIndex_Toggle_VRDP)->setVisible(false);
     867        }
     868    }
     869
     870    /* Prepare some initial settings: */
     871    {
     872        /* Initialize CD/FD menus: */
     873        int iDevicesCountCD = 0;
     874        int iDevicesCountFD = 0;
     875        const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
     876        foreach (const CMediumAttachment &attachment, attachments)
     877        {
     878            if (attachment.GetType() == KDeviceType_DVD)
     879                ++ iDevicesCountCD;
     880            if (attachment.GetType() == KDeviceType_Floppy)
     881                ++ iDevicesCountFD;
     882        }
     883        QAction *pOpticalDevicesMenu = uimachine()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices);
     884        QAction *pFloppyDevicesMenu = uimachine()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices);
     885        pOpticalDevicesMenu->setData(iDevicesCountCD);
     886        pOpticalDevicesMenu->setVisible(iDevicesCountCD);
     887        pFloppyDevicesMenu->setData(iDevicesCountFD);
     888        pFloppyDevicesMenu->setVisible(iDevicesCountFD);
     889    }
     890
     891    /* Load extra-data settings: */
     892    {
     893        /* Temporary: */
     894        QString strSettings;
     895
     896        /* Is there shoul be First RUN Wizard? */
     897        strSettings = machine.GetExtraData(VBoxDefs::GUI_FirstRun);
     898        if (strSettings == "yes")
     899            m_fIsFirstTimeStarted = true;
     900
     901        /* Ignore mediums mounted at runtime? */
     902        strSettings = machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
     903        if (strSettings == "no")
     904            m_fIsIgnoreRutimeMediumsChanging = true;
     905
     906        /* Should guest autoresize? */
     907        strSettings = machine.GetExtraData(VBoxDefs::GUI_AutoresizeGuest);
     908        QAction *pGuestAutoresizeSwitch = uimachine()->actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize);
     909        pGuestAutoresizeSwitch->blockSignals(true);
     910        pGuestAutoresizeSwitch->setChecked(strSettings != "off");
     911        pGuestAutoresizeSwitch->blockSignals(false);
     912    }
     913}
     914
     915void UISession::saveSessionSettings()
     916{
     917    /* Get session machine: */
     918    CMachine machine = session().GetConsole().GetMachine();
     919
     920    /* Save extra-data settings: */
     921    {
     922        /* Disable First RUN Wizard for the since now: */
     923        machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
     924
     925        /* Remember if guest should autoresize: */
     926        machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
     927                             uimachine()->actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->isChecked() ?
     928                             QString() : "off");
     929
     930        // TODO: Move to fullscreen/seamless logic:
     931        //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
     932    }
     933}
     934
    681935qulonglong UISession::winId() const
    682936{
    683     return machine()->machineLogic()->machineWindowWrapper()->machineWindow()->winId();
     937    return uimachine()->machineLogic()->machineWindowWrapper()->machineWindow()->winId();
    684938}
    685939
     940void UISession::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
     941                                uint uXHot, uint uYHot, uint uWidth, uint uHeight)
     942{
     943    AssertMsg(pShapeData, ("Shape data must not be NULL!\n"));
     944
     945    const uchar *srcAndMaskPtr = pShapeData;
     946    uint andMaskSize = (uWidth + 7) / 8 * uHeight;
     947    const uchar *srcShapePtr = pShapeData + ((andMaskSize + 3) & ~3);
     948    uint srcShapePtrScan = uWidth * 4;
     949
     950#if defined (Q_WS_WIN)
     951
     952    BITMAPV5HEADER bi;
     953    HBITMAP hBitmap;
     954    void *lpBits;
     955
     956    ::ZeroMemory(&bi, sizeof (BITMAPV5HEADER));
     957    bi.bV5Size = sizeof(BITMAPV5HEADER);
     958    bi.bV5Width = uWidth;
     959    bi.bV5Height = - (LONG)uHeight;
     960    bi.bV5Planes = 1;
     961    bi.bV5BitCount = 32;
     962    bi.bV5Compression = BI_BITFIELDS;
     963    bi.bV5RedMask   = 0x00FF0000;
     964    bi.bV5GreenMask = 0x0000FF00;
     965    bi.bV5BlueMask  = 0x000000FF;
     966    if (fHasAlpha)
     967        bi.bV5AlphaMask = 0xFF000000;
     968    else
     969        bi.bV5AlphaMask = 0;
     970
     971    HDC hdc = GetDC(NULL);
     972
     973    /* Create the DIB section with an alpha channel: */
     974    hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD) 0);
     975
     976    ReleaseDC(NULL, hdc);
     977
     978    HBITMAP hMonoBitmap = NULL;
     979    if (fHasAlpha)
     980    {
     981        /* Create an empty mask bitmap: */
     982        hMonoBitmap = CreateBitmap(uWidth, uHeight, 1, 1, NULL);
     983    }
     984    else
     985    {
     986        /* Word aligned AND mask. Will be allocated and created if necessary. */
     987        uint8_t *pu8AndMaskWordAligned = NULL;
     988
     989        /* Width in bytes of the original AND mask scan line. */
     990        uint32_t cbAndMaskScan = (uWidth + 7) / 8;
     991
     992        if (cbAndMaskScan & 1)
     993        {
     994            /* Original AND mask is not word aligned. */
     995
     996            /* Allocate memory for aligned AND mask. */
     997            pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * uHeight);
     998
     999            Assert(pu8AndMaskWordAligned);
     1000
     1001            if (pu8AndMaskWordAligned)
     1002            {
     1003                /* According to MSDN the padding bits must be 0.
     1004                 * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask. */
     1005                uint32_t u32PaddingBits = cbAndMaskScan * 8  - uWidth;
     1006                Assert(u32PaddingBits < 8);
     1007                uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
     1008
     1009                Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
     1010                      u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, uWidth, cbAndMaskScan));
     1011
     1012                uint8_t *src = (uint8_t *)srcAndMaskPtr;
     1013                uint8_t *dst = pu8AndMaskWordAligned;
     1014
     1015                unsigned i;
     1016                for (i = 0; i < uHeight; i++)
     1017                {
     1018                    memcpy(dst, src, cbAndMaskScan);
     1019
     1020                    dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
     1021
     1022                    src += cbAndMaskScan;
     1023                    dst += cbAndMaskScan + 1;
     1024                }
     1025            }
     1026        }
     1027
     1028        /* Create the AND mask bitmap: */
     1029        hMonoBitmap = ::CreateBitmap(uWidth, uHeight, 1, 1,
     1030                                     pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
     1031
     1032        if (pu8AndMaskWordAligned)
     1033        {
     1034            RTMemTmpFree(pu8AndMaskWordAligned);
     1035        }
     1036    }
     1037
     1038    Assert(hBitmap);
     1039    Assert(hMonoBitmap);
     1040    if (hBitmap && hMonoBitmap)
     1041    {
     1042        DWORD *dstShapePtr = (DWORD *) lpBits;
     1043
     1044        for (uint y = 0; y < uHeight; y ++)
     1045        {
     1046            memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
     1047            srcShapePtr += srcShapePtrScan;
     1048            dstShapePtr += uWidth;
     1049        }
     1050
     1051        ICONINFO ii;
     1052        ii.fIcon = FALSE;
     1053        ii.xHotspot = uXHot;
     1054        ii.yHotspot = uYHot;
     1055        ii.hbmMask = hMonoBitmap;
     1056        ii.hbmColor = hBitmap;
     1057
     1058        HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
     1059        Assert(hAlphaCursor);
     1060        if (hAlphaCursor)
     1061        {
     1062            /* Set the new cursor: */
     1063            m_cursor = QCursor(hAlphaCursor);
     1064            if (m_alphaCursor)
     1065                DestroyIcon(m_alphaCursor);
     1066            m_alphaCursor = hAlphaCursor;
     1067        }
     1068    }
     1069
     1070    if (hMonoBitmap)
     1071        DeleteObject(hMonoBitmap);
     1072    if (hBitmap)
     1073        DeleteObject(hBitmap);
     1074
     1075#elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
     1076
     1077    XcursorImage *img = XcursorImageCreate(uWidth, uHeight);
     1078    Assert(img);
     1079    if (img)
     1080    {
     1081        img->xhot = uXHot;
     1082        img->yhot = uYHot;
     1083
     1084        XcursorPixel *dstShapePtr = img->pixels;
     1085
     1086        for (uint y = 0; y < uHeight; y ++)
     1087        {
     1088            memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
     1089
     1090            if (!fHasAlpha)
     1091            {
     1092                /* Convert AND mask to the alpha channel: */
     1093                uchar byte = 0;
     1094                for (uint x = 0; x < uWidth; x ++)
     1095                {
     1096                    if (!(x % 8))
     1097                        byte = *(srcAndMaskPtr ++);
     1098                    else
     1099                        byte <<= 1;
     1100
     1101                    if (byte & 0x80)
     1102                    {
     1103                        /* Linux doesn't support inverted pixels (XOR ops,
     1104                         * to be exact) in cursor shapes, so we detect such
     1105                         * pixels and always replace them with black ones to
     1106                         * make them visible at least over light colors */
     1107                        if (dstShapePtr [x] & 0x00FFFFFF)
     1108                            dstShapePtr [x] = 0xFF000000;
     1109                        else
     1110                            dstShapePtr [x] = 0x00000000;
     1111                    }
     1112                    else
     1113                        dstShapePtr [x] |= 0xFF000000;
     1114                }
     1115            }
     1116
     1117            srcShapePtr += srcShapePtrScan;
     1118            dstShapePtr += uWidth;
     1119        }
     1120
     1121        /* Set the new cursor: */
     1122        m_cursor = QCursor(XcursorImageLoadCursor(QX11Info::display(), img));
     1123
     1124        XcursorImageDestroy(img);
     1125    }
     1126
     1127#elif defined(Q_WS_MAC)
     1128
     1129    /* Create a ARGB image out of the shape data. */
     1130    QImage image  (uWidth, uHeight, QImage::Format_ARGB32);
     1131    const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
     1132    unsigned cbSrcMaskLine = RT_ALIGN (uWidth, 8) / 8;
     1133    for (unsigned int y = 0; y < uHeight; ++y)
     1134    {
     1135        for (unsigned int x = 0; x < uWidth; ++x)
     1136        {
     1137           unsigned int color = ((unsigned int*)srcShapePtr)[y*uWidth+x];
     1138           /* If the alpha channel isn't in the shape data, we have to
     1139            * create them from the and-mask. This is a bit field where 1
     1140            * represent transparency & 0 opaque respectively. */
     1141           if (!fHasAlpha)
     1142           {
     1143               if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
     1144                   color  |= 0xff000000;
     1145               else
     1146               {
     1147                   /* This isn't quite right, but it's the best we can do I think... */
     1148                   if (color & 0x00ffffff)
     1149                       color = 0xff000000;
     1150                   else
     1151                       color = 0x00000000;
     1152               }
     1153           }
     1154           image.setPixel (x, y, color);
     1155        }
     1156        /* Move one scanline forward. */
     1157        pbSrcMask += cbSrcMaskLine;
     1158    }
     1159
     1160    /* Set the new cursor: */
     1161    m_cursor = cursor(QPixmap::fromImage(image), uXHot, uYHot);
     1162    NOREF(srcShapePtrScan);
     1163
     1164#else
     1165
     1166# warning "port me"
     1167
     1168#endif
     1169}
     1170
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r26795 r26815  
    2626/* Global includes */
    2727#include <QObject>
     28#include <QCursor>
    2829
    2930/* Local includes */
     
    6970    virtual ~UISession();
    7071
    71     /* Public getters: */
     72    /* Common getters: */
    7273    CSession& session() { return m_session; }
     74    KMachineState machineState() const { return m_machineState; }
     75    bool isSaved() const { return machineState() == KMachineState_Saved; }
     76    bool isTurnedOff() const { return machineState() == KMachineState_PoweredOff ||
     77                                      machineState() == KMachineState_Saved ||
     78                                      machineState() == KMachineState_Teleported ||
     79                                      machineState() == KMachineState_Aborted; }
     80    bool isPaused() const { return machineState() == KMachineState_Paused ||
     81                                   machineState() == KMachineState_TeleportingPausedVM; }
     82    bool isRunning() const { return machineState() == KMachineState_Running ||
     83                                    machineState() == KMachineState_Teleporting ||
     84                                    machineState() == KMachineState_LiveSnapshotting; }
     85    bool isFirstTimeStarted() const { return m_fIsFirstTimeStarted; }
     86    bool isIgnoreRuntimeMediumsChanging() const { return m_fIsIgnoreRutimeMediumsChanging; }
     87    bool isGuestResizeIgnored() const { return m_fIsGuestResizeIgnored; }
     88    QCursor cursor() const { return m_cursor; }
     89
     90    /* Guest additions state getters: */
     91    bool isGuestAdditionsActive() const { return m_fIsGuestAdditionsActive; }
     92    bool isGuestSupportsGraphics() const { return m_fIsGuestSupportsGraphics; }
     93    bool isGuestSupportsSeamless() const { return m_fIsGuestSupportsSeamless; }
     94
     95    /* Keyboard getters: */
     96    bool isNumLock() const { return m_fNumLock; }
     97    bool isCapsLock() const { return m_fCapsLock; }
     98    bool isScrollLock() const { return m_fScrollLock; }
     99    uint numLockAdaptionCnt() const { return m_uNumLockAdaptionCnt; }
     100    uint capsLockAdaptionCnt() const { return m_uCapsLockAdaptionCnt; }
     101
     102    /* Mouse getters: */
     103    bool isMouseSupportsAbsolute() const { return m_fIsMouseSupportsAbsolute; }
     104    bool isMouseSupportsRelative() const { return m_fIsMouseSupportsRelative; }
     105    bool isMouseHostCursorNeeded() const { return m_fIsMouseHostCursorNeeded; }
     106    bool isMouseCaptured() const { return m_fIsMouseCaptured; }
     107    bool isMouseIntegrated() const { return m_fIsMouseIntegrated; }
     108    bool isHidingHostPointer() const { return m_fIsMouseCaptured || (m_fIsMouseSupportsAbsolute && m_fIsHideHostPointer); }
     109
     110    /* Common setters: */
     111    bool pause() { return setPause(true); }
     112    bool unpause() { return setPause(false); }
     113    bool setPause(bool fOn);
     114    void setGuestResizeIgnored(bool fIsGuestResizeIgnored) { m_fIsGuestResizeIgnored = fIsGuestResizeIgnored; }
     115
     116    /* Keyboard setters: */
     117    void setNumLockAdaptionCnt(uint uNumLockAdaptionCnt) { m_uNumLockAdaptionCnt = uNumLockAdaptionCnt; }
     118    void setCapsLockAdaptionCnt(uint uCapsLockAdaptionCnt) { m_uCapsLockAdaptionCnt = uCapsLockAdaptionCnt; }
     119
     120    /* Mouse setters: */
     121    void setMouseCaptured(bool fIsMouseCaptured) { m_fIsMouseCaptured = fIsMouseCaptured; }
     122    void setMouseIntegrated(bool fIsMouseIntegrated) { m_fIsMouseIntegrated = fIsMouseIntegrated; }
    73123
    74124signals:
    75125
    76     /* Console signals: */
    77     void sigMousePointerShapeChange(bool bIsVisible, bool bHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight, const uchar *pShapeData);
    78     void sigMouseCapabilityChange(bool bIsSupportsAbsolute, bool bIsSupportsRelative, bool bNeedsHostCursor);
    79     void sigKeyboardLedsChange(bool bNumLock, bool bCapsLock, bool bScrollLock);
    80     void sigStateChange(KMachineState machineState);
     126    /* Console callback signals: */
     127    void sigMousePointerShapeChange();
     128    void sigMouseCapabilityChange();
     129    void sigKeyboardLedsChange();
     130    void sigMachineStateChange();
    81131    void sigAdditionsStateChange();
    82132    void sigNetworkAdapterChange(const CNetworkAdapter &networkAdapter);
     
    96146
    97147    /* Private getters: */
    98     UIMachine* machine() const { return m_pMachine; }
     148    UIMachine* uimachine() const { return m_pMachine; }
    99149
    100150    /* Event handlers: */
    101151    bool event(QEvent *pEvent);
    102152
    103     /* Helper routines: */
     153    /* Prepare helpers: */
     154    void loadSessionSettings();
     155
     156    /* Cleanup helpers: */
     157    void saveSessionSettings();
     158
     159    /* Common helpers: */
    104160    qulonglong winId() const;
     161    void setPointerShape(const uchar *pShapeData, bool fHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight);
    105162
    106163    /* Private variables: */
     
    110167    const CConsoleCallback &m_callback;
    111168
     169    /* Common variables: */
     170    KMachineState m_machineState;
     171    QCursor m_cursor;
     172#if defined(Q_WS_WIN)
     173    HCURSOR m_alphaCursor;
     174#endif
     175
     176    /* Common flags: */
     177    bool m_fIsFirstTimeStarted : 1;
     178    bool m_fIsIgnoreRutimeMediumsChanging : 1;
     179    bool m_fIsGuestResizeIgnored : 1;
     180
     181    /* Guest additions flags: */
     182    bool m_fIsGuestAdditionsActive : 1;
     183    bool m_fIsGuestSupportsGraphics : 1;
     184    bool m_fIsGuestSupportsSeamless : 1;
     185
     186    /* Keyboard flags: */
     187    bool m_fNumLock : 1;
     188    bool m_fCapsLock : 1;
     189    bool m_fScrollLock : 1;
     190    uint m_uNumLockAdaptionCnt;
     191    uint m_uCapsLockAdaptionCnt;
     192
     193    /* Mouse flags: */
     194    bool m_fIsMouseSupportsAbsolute : 1;
     195    bool m_fIsMouseSupportsRelative : 1;
     196    bool m_fIsMouseHostCursorNeeded : 1;
     197    bool m_fIsMouseCaptured : 1;
     198    bool m_fIsMouseIntegrated : 1;
     199    bool m_fIsHideHostPointer : 1;
     200
    112201    /* Friend classes: */
    113202    friend class UIConsoleCallback;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp

    r26773 r26815  
    2727
    2828/* Local includes */
     29#include "COMDefs.h"
    2930#include "VBoxGlobal.h"
    3031#include "VBoxProblemReporter.h"
     
    5556    prepareRequiredFeatures();
    5657
    57     /* Load common logic settings: */
    58     loadLogicSettings();
    59 
    6058    /* Prepare normal machine window: */
    6159    prepareMachineWindow();
     60
     61    /* Initialization: */
     62    sltMachineStateChanged();
     63    sltAdditionsStateChanged();
     64    sltMouseCapabilityChanged();
    6265}
    6366
     
    6669    /* Cleanup normal machine window: */
    6770    cleanupMachineWindow();
    68 
    69     /* Save common logic settings: */
    70     saveLogicSettings();
    7171}
    7272
     
    9797void UIMachineLogicNormal::prepareActionConnections()
    9898{
    99     /* Base-class connections: */
     99    /* Base class connections: */
    100100    UIMachineLogic::prepareActionConnections();
    101101
     
    124124    setMachineWindowWrapper(UIMachineWindow::create(this, visualStateType()));
    125125
    126     bool bIsSaved = machineState() == KMachineState_Saved;
    127     bool bIsRunning = machineState() == KMachineState_Running ||
    128                       machineState() == KMachineState_Teleporting ||
    129                       machineState() == KMachineState_LiveSnapshotting;
    130     bool bIsRunningOrPaused = bIsRunning ||
    131                               machineState() == KMachineState_Paused;
    132 
    133126    /* If we are not started yet: */
    134     if (!bIsRunningOrPaused)
     127    if (!uisession()->isRunning() && !uisession()->isPaused())
    135128    {
    136129        /* Get current machine/console: */
     
    143136
    144137        /* Shows first run wizard if necessary: */
    145         if (isFirstTimeStarted())
     138        if (uisession()->isFirstTimeStarted())
    146139        {
    147140            UIFirstRunWzd wzd(machineWindowWrapper()->machineWindow(), machine);
     
    160153        }
    161154
    162         /* Disable auto closure because we want to have a chance to show the error dialog on startup failure: */
     155        /* Disable auto-closure because we want to have a chance to show the error dialog on startup failure: */
    163156        setPreventAutoClose(true);
    164157
    165158        /* Show "Starting/Restoring" progress dialog: */
    166         if (bIsSaved)
     159        if (uisession()->isSaved())
    167160            vboxProblem().showModalProgressDialog(progress, machine.GetName(), machineWindowWrapper()->machineWindow(), 0);
    168161        else
     
    180173        qApp->processEvents();
    181174
    182         /* Enable auto closure again: */
     175        /* Enable auto-closure again: */
    183176        setPreventAutoClose(false);
    184177
    185178        /* Check if we missed a really quick termination after successful startup, and process it if we did: */
    186         if (machineState() == KMachineState_PoweredOff || machineState() == KMachineState_Saved ||
    187             machineState() == KMachineState_Teleported || machineState() == KMachineState_Aborted)
     179        if (uisession()->isTurnedOff())
    188180        {
    189181            machineWindowWrapper()->machineWindow()->close();
     
    216208#ifdef VBOX_WITH_UPDATE_REQUEST
    217209        /* Check for updates if necessary: */
    218         vboxGlobal().showUpdateDialog(false /* aForce */);
     210        vboxGlobal().showUpdateDialog(false /* force request? */);
    219211#endif
    220212    }
     
    227219        return;
    228220
    229     /* Cleanup machine window: */
     221    /* Cleanup normal machine window: */
    230222    UIMachineWindow::destroy(machineWindowWrapper());
    231223    setMachineWindowWrapper(0);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp

    r26773 r26815  
    3030/* Local includes */
    3131#include "VBoxGlobal.h"
     32#include "UISession.h"
    3233#include "UIActionsPool.h"
    3334#include "UIMachineLogic.h"
     
    6263    /* Load machine view settings: */
    6364    loadMachineViewSettings();
     65
     66    /* Initialization: */
     67    sltMachineStateChanged();
     68    sltAdditionsStateChanged();
     69    sltMousePointerShapeChanged();
     70    sltMouseCapabilityChanged();
    6471}
    6572
     
    114121
    115122    /* Enable/Disable guest auto-resizing depending on advanced graphics availablability: */
    116     setGuestAutoresizeEnabled(isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled);
     123    setGuestAutoresizeEnabled(m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics());
    117124}
    118125
     
    134141        maybeRestrictMinimumSize();
    135142
    136         if (isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled)
     143        if (uisession()->isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled)
    137144            sltPerformGuestResize();
    138145    }
     
    195202    if (mode() == VBoxDefs::SDLMode)
    196203    {
    197         if (!isGuestSupportsGraphics() || !m_bIsGuestAutoresizeEnabled)
     204        if (!uisession()->isGuestSupportsGraphics() || !m_bIsGuestAutoresizeEnabled)
    198205            setMinimumSize(sizeHint());
    199206        else
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

    r26800 r26815  
    3131#include "VBoxGlobal.h"
    3232
    33 #include "VBoxVMInformationDlg.h"
    34 
    3533#include "UISession.h"
    3634#include "UIActionsPool.h"
     
    6866    prepareConnections();
    6967
     68    /* Retranslate normal window finally: */
     69    retranslateUi();
     70
     71    /* Prepare normal machine view: */
     72    prepareMachineView();
     73
    7074    /* Load normal window settings: */
    7175    loadWindowSettings();
    7276
    73     /* Retranslate normal window finally: */
    74     retranslateUi();
    75 
    76     /* Prepare normal machine view: */
    77     prepareMachineView();
    78 
    7977    /* Update all the elements: */
    8078    updateAppearanceOf(UIVisualElement_AllStuff);
     
    9391}
    9492
    95 void UIMachineWindowNormal::sltMachineStateChanged(KMachineState machineState)
    96 {
    97     UIMachineWindow::sltMachineStateChanged(machineState);
     93void UIMachineWindowNormal::sltMachineStateChanged()
     94{
     95    UIMachineWindow::sltMachineStateChanged();
    9896}
    9997
     
    477475void UIMachineWindowNormal::loadWindowSettings()
    478476{
    479     /* Load parent class settings: */
    480     UIMachineWindow::loadWindowSettings();
    481 
    482     /* Load this class settings: */
     477    /* Load normal window settings: */
    483478    CMachine machine = session().GetMachine();
    484479
    485     /* Extra-data settings */
     480    /* Load extra-data settings: */
    486481    {
    487482        QString strPositionSettings = machine.GetExtraData(VBoxDefs::GUI_LastWindowPosition);
     
    511506                machineView()->normalizeGeometry(true /* adjust position? */);
    512507
    513             /* Maximize if needed */
     508            /* Maximize if needed: */
    514509            if (max)
    515510                setWindowState(windowState() | Qt::WindowMaximized);
     
    528523    }
    529524
    530     /* Availability settings */
     525    /* Load availability settings: */
    531526    {
    532527        /* USB Stuff: */
     
    545540    }
    546541
    547     /* Global settings */
     542    /* Load global settings: */
    548543    {
    549544        VBoxGlobalSettings settings = vboxGlobal().settings();
     
    557552    CMachine machine = session().GetMachine();
    558553
    559     /* Extra-data settings */
     554    /* Save extra-data settings: */
    560555    {
    561556        QString strWindowPosition = QString("%1,%2,%3,%4")
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h

    r26800 r26815  
    3737
    3838/* Local forwards */
     39class CMediumAttachment;
    3940class UIIndicatorsPool;
    4041class QIStateIndicator;
     
    5354
    5455    /* Console callback handlers: */
    55     void sltMachineStateChanged(KMachineState machineState);
     56    void sltMachineStateChanged();
    5657    void sltMediumChange(const CMediumAttachment &attachment);
    5758    void sltUSBControllerChange();
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette