VirtualBox

Changeset 1121 in vbox


Ignore:
Timestamp:
Feb 28, 2007 6:39:26 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19018
Message:

FE/Qt: Doubleclicking a VM in the Selector window will switch to an existing VM window if the VM is already running and there is a visual representation.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMListBox.h

    r1068 r1121  
    116116    void setMachine (const CMachine &aM);
    117117
    118     QUuid id() const { return mId; }
    119 
    120118    void recache();
    121119
     
    125123    int width (const QListBox *) const;
    126124
     125    QUuid id() const { return mId; }
    127126    bool accessible() const { return mAccessible; }
    128127    const CVirtualBoxErrorInfo &accessError() const { return mAccessError; }
     128    QString name() const { return mName; }
     129    CEnums::MachineState state() const { return mState; }
     130    CEnums::SessionState sessionState() const { return mSessionState; }
     131    ULONG snapshotCount() const { return mSnapshotCount; }
     132
     133    bool canSwitchTo() const { return mWinId != (WId) ~0; }
     134    bool switchTo();
    129135
    130136protected:
     
    150156    CEnums::SessionState mSessionState;
    151157    QString mOSType;
     158    ULONG mSnapshotCount;
     159
     160    ULONG mPid;
     161    WId mWinId;
    152162};
    153163
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp

    r1068 r1121  
    640640    AssertMsg (item, ("Item must be always selected here"));
    641641
    642     CMachine machine = item->machine();
    643     AssertMsg (machine.GetState() < CEnums::Running,
    644                ("Machine must be PoweredOff/Saved/Aborted"));
    645 
    646642#if defined (VBOX_GUI_SEPARATE_VM_PROCESS)
    647643
    648644    AssertMsg (!vboxGlobal().isVMConsoleProcess(),
    649645               ("Must NOT be a VM console process"));
     646
     647    /* just switch to the VM window if it already exists */
     648    if (item->canSwitchTo())
     649    {
     650        item->switchTo();
     651        return;
     652    }
     653
     654    AssertMsg (item->state() < CEnums::Running,
     655               ("Machine must be PoweredOff/Saved/Aborted"));
    650656
    651657    QUuid id = item->id();
     
    668674    if (!vbox.isOk())
    669675    {
    670         vboxProblem().cannotOpenSession (vbox, machine);
     676        vboxProblem().cannotOpenSession (vbox, item->machine());
    671677        return;
    672678    }
    673679
    674680    /* show the "VM spawning" progress dialog */
    675     vboxProblem().showModalProgressDialog (progress, machine.GetName(), this);
     681    vboxProblem().showModalProgressDialog (progress, item->name(), this);
    676682
    677683    if (progress.GetResultCode() != 0)
    678         vboxProblem().cannotOpenSession (vbox, machine, progress);
     684        vboxProblem().cannotOpenSession (vbox, item->machine(), progress);
    679685
    680686    session.Close();
     
    682688#else // !VBOX_GUI_SEPARATE_VM_PROCESS
    683689
    684     if (!vboxGlobal().startMachine (machine.GetId()))
     690    if (!vboxGlobal().startMachine (id))
    685691        return;
    686692
     
    847853    vmDeleteAction->setStatusTip (tr ("Delete the selected virtual machine"));
    848854
    849     vmStartAction->setMenuText (tr ("S&tart"));
    850     vmStartAction->setText (tr ("Start"));
    851     vmStartAction->setAccel (QString::null);
    852     vmStartAction->setStatusTip (tr ("Start the selected virtual machine"));
     855    /* Note: vmStartAction text is set up in vmListBoxCurrentChanged() */
    853856
    854857    vmDiscardAction->setMenuText (tr ("D&iscard"));
     
    919922        if (aRefreshSnapshots)
    920923        {
    921             /* update snapshots tab name */
     924            /* update the snapshots tab name */
    922925            QString shotName = tr ("&Snapshots");
    923             ULONG shotCount = m.GetSnapshotCount();
     926            ULONG shotCount = item->snapshotCount();
    924927            if (shotCount)
    925928                shotName += QString (" (%1)").arg (shotCount);
     
    929932        }
    930933
    931         CEnums::MachineState state = m.GetState();
    932         bool running = m.GetSessionState() != CEnums::SessionClosed;
     934        CEnums::MachineState state = item->state();
     935        bool running = item->sessionState() != CEnums::SessionClosed;
    933936        bool modifyEnabled = !running && state != CEnums::Saved;
    934937
     
    940943        vmConfigAction->setEnabled (modifyEnabled);
    941944        vmDeleteAction->setEnabled (modifyEnabled);
    942         vmStartAction->setEnabled (!running);
    943945        vmDiscardAction->setEnabled (state == CEnums::Saved && !running);
    944946
     947        /* change the Start button text accordingly */
     948        if (state >= CEnums::Running)
     949        {
     950            vmStartAction->setMenuText (tr ("S&how"));
     951            vmStartAction->setText (tr ("Show"));
     952            vmStartAction->setAccel (QString::null);
     953            vmStartAction->setStatusTip (
     954                tr ("Switch to the window of the selected virtual machine"));
     955
     956            vmStartAction->setEnabled (item->canSwitchTo());
     957        }
     958        else
     959        {
     960            vmStartAction->setMenuText (tr ("S&tart"));
     961            vmStartAction->setText (tr ("Start"));
     962            vmStartAction->setAccel (QString::null);
     963            vmStartAction->setStatusTip (
     964                tr ("Start the selected virtual machine"));
     965
     966            vmStartAction->setEnabled (!running);
     967        }
     968
     969        /* disable Refresh for accessible machines */
    945970        vmRefreshAction->setEnabled (false);
    946971    }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMListBox.cpp

    r1072 r1121  
    3636
    3737////////////////////////////////////////////////////////////////////////////////
     38// Helpers
     39////////////////////////////////////////////////////////////////////////////////
     40
     41#if defined (Q_WS_WIN32)
     42
     43struct EnumWindowsProcData
     44{
     45    ULONG pid;
     46    WId wid;
     47};
     48
     49BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
     50{
     51    EnumWindowsProcData *d = (EnumWindowsProcData *) lParam;
     52
     53    DWORD pid = 0;
     54    GetWindowThreadProcessId (hwnd, &pid);
     55
     56    if (d->pid == pid)
     57    {
     58        WINDOWINFO info;
     59        if (!GetWindowInfo (hwnd, &info))
     60            return TRUE;
     61
     62#if 0
     63        LogFlowFunc (("pid=%d, wid=%08X\n", pid, hwnd));
     64        LogFlowFunc (("  parent=%08X\n", GetParent (hwnd)));
     65        LogFlowFunc (("  owner=%08X\n", GetWindow (hwnd, GW_OWNER)));
     66        TCHAR buf [256];
     67        LogFlowFunc (("  rcWindow=%d,%d;%d,%d\n",
     68                      info.rcWindow.left, info.rcWindow.top,
     69                      info.rcWindow.right, info.rcWindow.bottom));
     70        LogFlowFunc (("  dwStyle=%08X\n", info.dwStyle));
     71        LogFlowFunc (("  dwExStyle=%08X\n", info.dwExStyle));
     72        GetClassName (hwnd, buf, 256);
     73        LogFlowFunc (("  class=%ls\n", buf));
     74        GetWindowText (hwnd, buf, 256);
     75        LogFlowFunc (("  text=%ls\n", buf));
     76#endif
     77
     78        /* we are interested in unowned top-level windows only */
     79        if (!(info.dwStyle & (WS_CHILD | WS_POPUP)) &&
     80            info.rcWindow.left < info.rcWindow.right &&
     81            info.rcWindow.top < info.rcWindow.bottom &&
     82            GetParent (hwnd) == NULL &&
     83            GetWindow (hwnd, GW_OWNER) == NULL)
     84        {
     85            d->wid = hwnd;
     86            /* if visible, stop the search immediately */
     87            if (info.dwStyle & WS_VISIBLE)
     88                return FALSE;
     89            /* otherwise, give other top-level windows a chance
     90             * (the last one wins) */
     91        }
     92    }
     93
     94    return TRUE;
     95}
     96
     97#endif
     98
     99/**
     100 * Searches for a main window of the given process.
     101 *
     102 * @param aPid process ID to search for
     103 *
     104 * @return window ID on success or <tt>(WId) ~0</tt> otherwise.
     105 */
     106static WId FindWindowIdFromPid (ULONG aPid)
     107{
     108#if defined (Q_WS_WIN32)
     109
     110    EnumWindowsProcData d = { aPid, (WId) ~0 };
     111    EnumWindows (EnumWindowsProc, (LPARAM) &d);
     112    LogFlowFunc (("SELECTED wid=%08X\n", d.wid));
     113    return d.wid;
     114
     115#elif defined (Q_WS_X11)
     116
     117    return (WId) ~0;
     118
     119#else
     120
     121    return (WId) ~0;
     122
     123#endif
     124}
     125
     126////////////////////////////////////////////////////////////////////////////////
    38127// VBoxVMListBoxItem class
    39128////////////////////////////////////////////////////////////////////////////////
     
    261350        mSessionState = mMachine.GetSessionState();
    262351        mOSType = mMachine.GetOSType().GetId();
     352        mSnapshotCount = mMachine.GetSnapshotCount();
     353
     354        if (mState >= CEnums::Running)
     355        {
     356            mPid = mMachine.GetSessionPid();
     357            mWinId = FindWindowIdFromPid (mPid);
     358        }
     359        else
     360        {
     361            mPid = (ULONG) ~0;
     362            mWinId = (WId) ~0;
     363        }
    263364    }
    264365    else
     
    277378        mLastStateChange = QDateTime::currentDateTime();
    278379        mOSType = QString::null;
     380        mSnapshotCount = 0;
     381
     382        mPid = (ULONG) ~0;
     383        mWinId = (WId) ~0;
    279384    }
    280385
     
    389494}
    390495
     496/**
     497 * Tries to switch to the main window of the VM process.
     498 *
     499 * @return true if successfully switched and false otherwise.
     500 */
     501bool VBoxVMListBoxItem::switchTo()
     502{
     503    if (!canSwitchTo())
     504        return false;
     505
     506#if defined (Q_WS_WIN32)
     507
     508    HWND hwnd = mWinId;
     509
     510    /* if there are ownees (modal and modeless dialogs, etc), find the
     511     * topmost one */
     512    HWND hwndAbove = NULL;
     513    do
     514    {
     515        hwndAbove = GetNextWindow (hwnd, GW_HWNDPREV);
     516        HWND hwndOwner;
     517        if (hwndAbove != NULL &&
     518            ((hwndOwner = GetWindow (hwndAbove, GW_OWNER)) == hwnd ||
     519             hwndOwner  == hwndAbove))
     520            hwnd = hwndAbove;
     521        else
     522            break;
     523    }
     524    while (1);
     525
     526    /* first, check that the primary window is visible */
     527    if (IsIconic (mWinId))
     528        ShowWindow (mWinId, SW_RESTORE);
     529    else if (!IsWindowVisible (mWinId))
     530        ShowWindow (mWinId, SW_SHOW);
     531
     532#if 0
     533    LogFlowFunc (("mWinId=%08X hwnd=%08X\n", mWinId, hwnd));
     534#endif
     535
     536    /* then, activate the topmost in the group */
     537    AllowSetForegroundWindow (mPid);
     538    SetForegroundWindow (hwnd);
     539
     540    return true;
     541
     542#elif defined (Q_WS_X11)
     543
     544    return false;
     545
     546#else
     547
     548    return false;
     549
     550#endif
     551}
     552
    391553// protected members
    392554////////////////////////////////////////////////////////////////////////////////
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