1 | /* $Id: VBoxDbgGui.cpp 12462 2008-09-15 13:22:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Debugger GUI - The Manager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | #define VBOX_COM_NO_ATL
|
---|
24 | #include <VBox/com/defs.h>
|
---|
25 | #include <VBox/vm.h>
|
---|
26 | #include <VBox/err.h>
|
---|
27 |
|
---|
28 | #include "VBoxDbgGui.h"
|
---|
29 | #ifdef VBOXDBG_USE_QT4
|
---|
30 | # include <QDesktopWidget>
|
---|
31 | # include <QApplication>
|
---|
32 | #else
|
---|
33 | # include <qdesktopwidget.h>
|
---|
34 | # include <qapplication.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 |
|
---|
38 | VBoxDbgGui::VBoxDbgGui() :
|
---|
39 | m_pDbgStats(NULL), m_pDbgConsole(NULL), m_pSession(NULL), m_pConsole(NULL),
|
---|
40 | m_pMachineDebugger(NULL), m_pMachine(NULL), m_pVM(NULL), m_x(0), m_y(0), m_cx(0), m_cy(0),
|
---|
41 | m_xDesktop(0), m_yDesktop(0), m_cxDesktop(0), m_cyDesktop(0)
|
---|
42 | {
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | int VBoxDbgGui::init(PVM pVM)
|
---|
48 | {
|
---|
49 | /*
|
---|
50 | * Set the VM handle and update the desktop size.
|
---|
51 | */
|
---|
52 | m_pVM = pVM;
|
---|
53 | updateDesktopSize();
|
---|
54 |
|
---|
55 | return VINF_SUCCESS;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | int VBoxDbgGui::init(ISession *pSession)
|
---|
60 | {
|
---|
61 | int rc = VERR_GENERAL_FAILURE;
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * Query the Virtual Box interfaces.
|
---|
65 | */
|
---|
66 | m_pSession = pSession;
|
---|
67 | m_pSession->AddRef();
|
---|
68 |
|
---|
69 | HRESULT hrc = m_pSession->COMGETTER(Machine)(&m_pMachine);
|
---|
70 | if (SUCCEEDED(hrc))
|
---|
71 | {
|
---|
72 | hrc = m_pSession->COMGETTER(Console)(&m_pConsole);
|
---|
73 | if (SUCCEEDED(hrc))
|
---|
74 | {
|
---|
75 | hrc = m_pConsole->COMGETTER(Debugger)(&m_pMachineDebugger);
|
---|
76 | if (SUCCEEDED(hrc))
|
---|
77 | {
|
---|
78 | /*
|
---|
79 | * Get the VM handle.
|
---|
80 | */
|
---|
81 | ULONG64 ullVM;
|
---|
82 | hrc = m_pMachineDebugger->COMGETTER(VM)(&ullVM);
|
---|
83 | if (SUCCEEDED(hrc))
|
---|
84 | {
|
---|
85 | rc = init((PVM)(uintptr_t)ullVM);
|
---|
86 | if (RT_SUCCESS(rc))
|
---|
87 | return rc;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* damn, failure! */
|
---|
91 | m_pMachineDebugger->Release();
|
---|
92 | }
|
---|
93 | m_pConsole->Release();
|
---|
94 | }
|
---|
95 | m_pMachine->Release();
|
---|
96 | }
|
---|
97 |
|
---|
98 | return rc;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | VBoxDbgGui::~VBoxDbgGui()
|
---|
103 | {
|
---|
104 |
|
---|
105 | #ifndef VBOXDBG_USE_QT4
|
---|
106 | if (m_pDbgStats)
|
---|
107 | {
|
---|
108 | delete m_pDbgStats;
|
---|
109 | m_pDbgStats = NULL;
|
---|
110 | }
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | if (m_pDbgConsole)
|
---|
114 | {
|
---|
115 | delete m_pDbgConsole;
|
---|
116 | m_pDbgConsole = NULL;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (m_pMachineDebugger)
|
---|
120 | {
|
---|
121 | m_pMachineDebugger->Release();
|
---|
122 | m_pMachineDebugger = NULL;
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (m_pConsole)
|
---|
126 | {
|
---|
127 | m_pConsole->Release();
|
---|
128 | m_pConsole = NULL;
|
---|
129 | }
|
---|
130 |
|
---|
131 | if (m_pMachine)
|
---|
132 | {
|
---|
133 | m_pMachine->Release();
|
---|
134 | m_pMachine = NULL;
|
---|
135 | }
|
---|
136 |
|
---|
137 | if (m_pSession)
|
---|
138 | {
|
---|
139 | m_pSession->Release();
|
---|
140 | m_pSession = NULL;
|
---|
141 | }
|
---|
142 |
|
---|
143 | m_pVM = NULL;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | int VBoxDbgGui::showStatistics()
|
---|
148 | {
|
---|
149 | if (!m_pDbgStats)
|
---|
150 | {
|
---|
151 | #ifdef VBOXDBG_USE_QT4
|
---|
152 | m_pDbgStats = new VBoxDbgStats(m_pVM, "*x*"); /// @todo the QTreeWidget/QTreeView sucks big time. it freezes the app for 30+ seconds. Need to write a new item model I fear. 'ing crap!!!
|
---|
153 | #else
|
---|
154 | m_pDbgStats = new VBoxDbgStats(m_pVM);
|
---|
155 | #endif
|
---|
156 | connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
|
---|
157 | repositionStatistics();
|
---|
158 | }
|
---|
159 | m_pDbgStats->show();
|
---|
160 | return VINF_SUCCESS;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void VBoxDbgGui::repositionStatistics(bool fResize/* = true*/)
|
---|
164 | {
|
---|
165 | if (m_pDbgStats)
|
---|
166 | {
|
---|
167 | /* Move it to the right side of the VBox console. */
|
---|
168 | m_pDbgStats->move(m_x + m_cx, m_y);
|
---|
169 | if (fResize)
|
---|
170 | /* Resize it to cover all the space to the left side of the desktop. */
|
---|
171 | resizeWidget(m_pDbgStats, m_cxDesktop - m_cx - m_x + m_xDesktop, m_cyDesktop - m_y + m_yDesktop);
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | int VBoxDbgGui::showConsole()
|
---|
177 | {
|
---|
178 | if (!m_pDbgConsole)
|
---|
179 | {
|
---|
180 | m_pDbgConsole = new VBoxDbgConsole(m_pVM);
|
---|
181 | connect(m_pDbgConsole, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
|
---|
182 | repositionConsole();
|
---|
183 | }
|
---|
184 | m_pDbgConsole->show();
|
---|
185 | return VINF_SUCCESS;
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | void VBoxDbgGui::repositionConsole(bool fResize/* = true*/)
|
---|
190 | {
|
---|
191 | if (m_pDbgConsole)
|
---|
192 | {
|
---|
193 | /* Move it to the bottom of the VBox console. */
|
---|
194 | m_pDbgConsole->move(m_x, m_y + m_cy);
|
---|
195 | if (fResize)
|
---|
196 | /* Resize it to cover the space down to the bottom of the desktop. */
|
---|
197 | resizeWidget(m_pDbgConsole, RT_MAX(m_cx, 32), m_cyDesktop - m_cy - m_y + m_yDesktop);
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | void VBoxDbgGui::updateDesktopSize()
|
---|
203 | {
|
---|
204 | QRect Rct(0, 0, 1600, 1200);
|
---|
205 | QDesktopWidget *pDesktop = QApplication::desktop();
|
---|
206 | if (pDesktop)
|
---|
207 | Rct = pDesktop->availableGeometry(QPoint(m_x, m_y));
|
---|
208 | m_xDesktop = Rct.x();
|
---|
209 | m_yDesktop = Rct.y();
|
---|
210 | m_cxDesktop = Rct.width();
|
---|
211 | m_cyDesktop = Rct.height();
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | void VBoxDbgGui::adjustRelativePos(int x, int y, unsigned cx, unsigned cy)
|
---|
216 | {
|
---|
217 | const bool fResize = cx != m_cx || cy != m_cy;
|
---|
218 | const bool fMoved = x != m_x || y != m_y;
|
---|
219 |
|
---|
220 | m_x = x;
|
---|
221 | m_y = y;
|
---|
222 | m_cx = cx;
|
---|
223 | m_cy = cy;
|
---|
224 |
|
---|
225 | if (fMoved)
|
---|
226 | updateDesktopSize();
|
---|
227 | repositionConsole(fResize);
|
---|
228 | repositionStatistics(fResize);
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | /*static*/ void VBoxDbgGui::resizeWidget(QWidget *pWidget, unsigned cx, unsigned cy)
|
---|
233 | {
|
---|
234 | QSize FrameSize = pWidget->frameSize();
|
---|
235 | QSize WidgetSize = pWidget->size();
|
---|
236 | pWidget->resize(cx - (FrameSize.width() - WidgetSize.width()),
|
---|
237 | cy - (FrameSize.height() - WidgetSize.height()));
|
---|
238 | }
|
---|
239 |
|
---|
240 | void VBoxDbgGui::notifyChildDestroyed(QObject *pObj)
|
---|
241 | {
|
---|
242 | if (m_pDbgStats == pObj)
|
---|
243 | m_pDbgStats = NULL;
|
---|
244 | else if (m_pDbgConsole == pObj)
|
---|
245 | m_pDbgConsole = NULL;
|
---|
246 | }
|
---|
247 |
|
---|