VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgGui.cpp@ 12884

Last change on this file since 12884 was 12884, checked in by vboxsync, 17 years ago

Debugger: parenting, menu, destroy on close

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxDbgGui.cpp 12884 2008-10-01 23:48:04Z 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.215389.xyz. 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* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_DBGG
26#define VBOX_COM_NO_ATL
27#include <VBox/com/defs.h>
28#include <VBox/vm.h>
29#include <VBox/err.h>
30
31#include "VBoxDbgGui.h"
32#ifdef VBOXDBG_USE_QT4
33# include <QDesktopWidget>
34# include <QApplication>
35#else
36# include <qdesktopwidget.h>
37# include <qapplication.h>
38#endif
39
40
41
42
43VBoxDbgGui::VBoxDbgGui() :
44 m_pDbgStats(NULL), m_pDbgConsole(NULL), m_pSession(NULL), m_pConsole(NULL),
45 m_pMachineDebugger(NULL), m_pMachine(NULL), m_pVM(NULL),
46 m_pParent(NULL), m_pMenu(NULL),
47 m_x(0), m_y(0), m_cx(0), m_cy(0), m_xDesktop(0), m_yDesktop(0), m_cxDesktop(0), m_cyDesktop(0)
48{
49
50}
51
52
53int VBoxDbgGui::init(PVM pVM)
54{
55 /*
56 * Set the VM handle and update the desktop size.
57 */
58 m_pVM = pVM;
59 updateDesktopSize();
60
61 return VINF_SUCCESS;
62}
63
64
65int VBoxDbgGui::init(ISession *pSession)
66{
67 int rc = VERR_GENERAL_FAILURE;
68
69 /*
70 * Query the Virtual Box interfaces.
71 */
72 m_pSession = pSession;
73 m_pSession->AddRef();
74
75 HRESULT hrc = m_pSession->COMGETTER(Machine)(&m_pMachine);
76 if (SUCCEEDED(hrc))
77 {
78 hrc = m_pSession->COMGETTER(Console)(&m_pConsole);
79 if (SUCCEEDED(hrc))
80 {
81 hrc = m_pConsole->COMGETTER(Debugger)(&m_pMachineDebugger);
82 if (SUCCEEDED(hrc))
83 {
84 /*
85 * Get the VM handle.
86 */
87 ULONG64 ullVM;
88 hrc = m_pMachineDebugger->COMGETTER(VM)(&ullVM);
89 if (SUCCEEDED(hrc))
90 {
91 rc = init((PVM)(uintptr_t)ullVM);
92 if (RT_SUCCESS(rc))
93 return rc;
94 }
95
96 /* damn, failure! */
97 m_pMachineDebugger->Release();
98 }
99 m_pConsole->Release();
100 }
101 m_pMachine->Release();
102 }
103
104 return rc;
105}
106
107
108VBoxDbgGui::~VBoxDbgGui()
109{
110 if (m_pDbgStats)
111 {
112 delete m_pDbgStats;
113 m_pDbgStats = NULL;
114 }
115
116 if (m_pDbgConsole)
117 {
118 delete m_pDbgConsole;
119 m_pDbgConsole = NULL;
120 }
121
122 if (m_pMachineDebugger)
123 {
124 m_pMachineDebugger->Release();
125 m_pMachineDebugger = NULL;
126 }
127
128 if (m_pConsole)
129 {
130 m_pConsole->Release();
131 m_pConsole = NULL;
132 }
133
134 if (m_pMachine)
135 {
136 m_pMachine->Release();
137 m_pMachine = NULL;
138 }
139
140 if (m_pSession)
141 {
142 m_pSession->Release();
143 m_pSession = NULL;
144 }
145
146 m_pVM = NULL;
147}
148
149void
150VBoxDbgGui::setParent(QWidget *pParent)
151{
152 m_pParent = pParent;
153}
154
155
156void
157#ifdef VBOXDBG_USE_QT4
158VBoxDbgGui::setMenu(QMenu *pMenu)
159#else
160VBoxDbgGui::setMenu(QPopupMenu *pMenu)
161#endif
162{
163 m_pMenu = pMenu;
164}
165
166
167int
168VBoxDbgGui::showStatistics()
169{
170 if (!m_pDbgStats)
171 {
172 m_pDbgStats = new VBoxDbgStats(m_pVM, "*", 0, m_pParent);
173 connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
174 repositionStatistics();
175 }
176
177 m_pDbgStats->show();
178#ifdef VBOXDBG_USE_QT4 /** @todo this isn't working right. */
179 m_pDbgStats->setWindowState(m_pDbgStats->windowState() & ~Qt::WindowMinimized);
180 //m_pDbgStats->activateWindow();
181 //m_pDbgStats->setFocus();
182#endif
183
184 return VINF_SUCCESS;
185}
186
187
188void
189VBoxDbgGui::repositionStatistics(bool fResize/* = true*/)
190{
191 if (m_pDbgStats)
192 {
193 /* Move it to the right side of the VBox console. */
194 m_pDbgStats->move(m_x + m_cx, m_y);
195 if (fResize)
196 /* Resize it to cover all the space to the left side of the desktop. */
197 resizeWidget(m_pDbgStats, m_cxDesktop - m_cx - m_x + m_xDesktop, m_cyDesktop - m_y + m_yDesktop);
198 }
199}
200
201
202int
203VBoxDbgGui::showConsole()
204{
205 if (!m_pDbgConsole)
206 {
207 m_pDbgConsole = new VBoxDbgConsole(m_pVM, m_pParent);
208 connect(m_pDbgConsole, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
209 repositionConsole();
210 }
211
212 m_pDbgConsole->show();
213#ifdef VBOXDBG_USE_QT4 /** @todo this ain't working right. */
214 m_pDbgConsole->setWindowState(m_pDbgConsole->windowState() & ~Qt::WindowMinimized);
215 //m_pDbgConsole->activateWindow();
216 //m_pDbgConsole->setFocus();
217#endif
218
219 return VINF_SUCCESS;
220}
221
222
223void
224VBoxDbgGui::repositionConsole(bool fResize/* = true*/)
225{
226 if (m_pDbgConsole)
227 {
228 /* Move it to the bottom of the VBox console. */
229 m_pDbgConsole->move(m_x, m_y + m_cy);
230 if (fResize)
231 /* Resize it to cover the space down to the bottom of the desktop. */
232 resizeWidget(m_pDbgConsole, RT_MAX(m_cx, 32), m_cyDesktop - m_cy - m_y + m_yDesktop);
233 }
234}
235
236
237void
238VBoxDbgGui::updateDesktopSize()
239{
240 QRect Rct(0, 0, 1600, 1200);
241 QDesktopWidget *pDesktop = QApplication::desktop();
242 if (pDesktop)
243 Rct = pDesktop->availableGeometry(QPoint(m_x, m_y));
244 m_xDesktop = Rct.x();
245 m_yDesktop = Rct.y();
246 m_cxDesktop = Rct.width();
247 m_cyDesktop = Rct.height();
248}
249
250
251void
252VBoxDbgGui::adjustRelativePos(int x, int y, unsigned cx, unsigned cy)
253{
254 const bool fResize = cx != m_cx || cy != m_cy;
255 const bool fMoved = x != m_x || y != m_y;
256
257 m_x = x;
258 m_y = y;
259 m_cx = cx;
260 m_cy = cy;
261
262 if (fMoved)
263 updateDesktopSize();
264 repositionConsole(fResize);
265 repositionStatistics(fResize);
266}
267
268
269/*static*/ void
270VBoxDbgGui::resizeWidget(QWidget *pWidget, unsigned cx, unsigned cy)
271{
272 QSize FrameSize = pWidget->frameSize();
273 QSize WidgetSize = pWidget->size();
274 pWidget->resize(cx - (FrameSize.width() - WidgetSize.width()),
275 cy - (FrameSize.height() - WidgetSize.height()));
276}
277
278void
279VBoxDbgGui::notifyChildDestroyed(QObject *pObj)
280{
281 if (m_pDbgStats == pObj)
282 m_pDbgStats = NULL;
283 else if (m_pDbgConsole == pObj)
284 m_pDbgConsole = NULL;
285}
286
Note: See TracBrowser for help on using the repository browser.

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