Changeset 1121 in vbox
- Timestamp:
- Feb 28, 2007 6:39:26 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 19018
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMListBox.h
r1068 r1121 116 116 void setMachine (const CMachine &aM); 117 117 118 QUuid id() const { return mId; }119 120 118 void recache(); 121 119 … … 125 123 int width (const QListBox *) const; 126 124 125 QUuid id() const { return mId; } 127 126 bool accessible() const { return mAccessible; } 128 127 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(); 129 135 130 136 protected: … … 150 156 CEnums::SessionState mSessionState; 151 157 QString mOSType; 158 ULONG mSnapshotCount; 159 160 ULONG mPid; 161 WId mWinId; 152 162 }; 153 163 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp
r1068 r1121 640 640 AssertMsg (item, ("Item must be always selected here")); 641 641 642 CMachine machine = item->machine();643 AssertMsg (machine.GetState() < CEnums::Running,644 ("Machine must be PoweredOff/Saved/Aborted"));645 646 642 #if defined (VBOX_GUI_SEPARATE_VM_PROCESS) 647 643 648 644 AssertMsg (!vboxGlobal().isVMConsoleProcess(), 649 645 ("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")); 650 656 651 657 QUuid id = item->id(); … … 668 674 if (!vbox.isOk()) 669 675 { 670 vboxProblem().cannotOpenSession (vbox, machine);676 vboxProblem().cannotOpenSession (vbox, item->machine()); 671 677 return; 672 678 } 673 679 674 680 /* show the "VM spawning" progress dialog */ 675 vboxProblem().showModalProgressDialog (progress, machine.GetName(), this);681 vboxProblem().showModalProgressDialog (progress, item->name(), this); 676 682 677 683 if (progress.GetResultCode() != 0) 678 vboxProblem().cannotOpenSession (vbox, machine, progress);684 vboxProblem().cannotOpenSession (vbox, item->machine(), progress); 679 685 680 686 session.Close(); … … 682 688 #else // !VBOX_GUI_SEPARATE_VM_PROCESS 683 689 684 if (!vboxGlobal().startMachine ( machine.GetId()))690 if (!vboxGlobal().startMachine (id)) 685 691 return; 686 692 … … 847 853 vmDeleteAction->setStatusTip (tr ("Delete the selected virtual machine")); 848 854 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() */ 853 856 854 857 vmDiscardAction->setMenuText (tr ("D&iscard")); … … 919 922 if (aRefreshSnapshots) 920 923 { 921 /* update snapshots tab name */924 /* update the snapshots tab name */ 922 925 QString shotName = tr ("&Snapshots"); 923 ULONG shotCount = m.GetSnapshotCount();926 ULONG shotCount = item->snapshotCount(); 924 927 if (shotCount) 925 928 shotName += QString (" (%1)").arg (shotCount); … … 929 932 } 930 933 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; 933 936 bool modifyEnabled = !running && state != CEnums::Saved; 934 937 … … 940 943 vmConfigAction->setEnabled (modifyEnabled); 941 944 vmDeleteAction->setEnabled (modifyEnabled); 942 vmStartAction->setEnabled (!running);943 945 vmDiscardAction->setEnabled (state == CEnums::Saved && !running); 944 946 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 */ 945 970 vmRefreshAction->setEnabled (false); 946 971 } -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMListBox.cpp
r1072 r1121 36 36 37 37 //////////////////////////////////////////////////////////////////////////////// 38 // Helpers 39 //////////////////////////////////////////////////////////////////////////////// 40 41 #if defined (Q_WS_WIN32) 42 43 struct EnumWindowsProcData 44 { 45 ULONG pid; 46 WId wid; 47 }; 48 49 BOOL 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 */ 106 static 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 //////////////////////////////////////////////////////////////////////////////// 38 127 // VBoxVMListBoxItem class 39 128 //////////////////////////////////////////////////////////////////////////////// … … 261 350 mSessionState = mMachine.GetSessionState(); 262 351 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 } 263 364 } 264 365 else … … 277 378 mLastStateChange = QDateTime::currentDateTime(); 278 379 mOSType = QString::null; 380 mSnapshotCount = 0; 381 382 mPid = (ULONG) ~0; 383 mWinId = (WId) ~0; 279 384 } 280 385 … … 389 494 } 390 495 496 /** 497 * Tries to switch to the main window of the VM process. 498 * 499 * @return true if successfully switched and false otherwise. 500 */ 501 bool 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 391 553 // protected members 392 554 ////////////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.