1 | /* $Id: VBoxDbgBase.cpp 31530 2010-08-10 12:24:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Debugger GUI - Base classes.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
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 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_DBGG
|
---|
22 | #include <VBox/err.h>
|
---|
23 | #include <iprt/asm.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <limits.h>
|
---|
26 | #include "VBoxDbgBase.h"
|
---|
27 | #include "VBoxDbgGui.h"
|
---|
28 |
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QWidgetList>
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | VBoxDbgBase::VBoxDbgBase(VBoxDbgGui *a_pDbgGui)
|
---|
35 | : m_pDbgGui(a_pDbgGui), m_pVM(NULL), m_hGUIThread(RTThreadNativeSelf())
|
---|
36 | {
|
---|
37 | /*
|
---|
38 | * Register
|
---|
39 | */
|
---|
40 | PVM pVM = a_pDbgGui->getVMHandle();
|
---|
41 | if (pVM)
|
---|
42 | {
|
---|
43 | m_pVM = pVM;
|
---|
44 | int rc = VMR3AtStateRegister(pVM, atStateChange, this);
|
---|
45 | AssertRC(rc);
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | VBoxDbgBase::~VBoxDbgBase()
|
---|
51 | {
|
---|
52 | /*
|
---|
53 | * If the VM is still around.
|
---|
54 | */
|
---|
55 | /** @todo need to do some locking here? */
|
---|
56 | PVM pVM = ASMAtomicXchgPtrT(&m_pVM, NULL, PVM);
|
---|
57 | if (pVM)
|
---|
58 | {
|
---|
59 | int rc = VMR3AtStateDeregister(pVM, atStateChange, this);
|
---|
60 | AssertRC(rc);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | int
|
---|
66 | VBoxDbgBase::stamReset(const QString &rPat)
|
---|
67 | {
|
---|
68 | QByteArray Utf8Array = rPat.toUtf8();
|
---|
69 | const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
|
---|
70 | PVM pVM = m_pVM;
|
---|
71 | if ( pVM
|
---|
72 | && VMR3GetState(pVM) < VMSTATE_DESTROYING)
|
---|
73 | return STAMR3Reset(pVM, pszPat);
|
---|
74 | return VERR_INVALID_HANDLE;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | int
|
---|
79 | VBoxDbgBase::stamEnum(const QString &rPat, PFNSTAMR3ENUM pfnEnum, void *pvUser)
|
---|
80 | {
|
---|
81 | QByteArray Utf8Array = rPat.toUtf8();
|
---|
82 | const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
|
---|
83 | PVM pVM = m_pVM;
|
---|
84 | if ( pVM
|
---|
85 | && VMR3GetState(pVM) < VMSTATE_DESTROYING)
|
---|
86 | return STAMR3Enum(pVM, pszPat, pfnEnum, pvUser);
|
---|
87 | return VERR_INVALID_HANDLE;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | int
|
---|
92 | VBoxDbgBase::dbgcCreate(PDBGCBACK pBack, unsigned fFlags)
|
---|
93 | {
|
---|
94 | PVM pVM = m_pVM;
|
---|
95 | if ( pVM
|
---|
96 | && VMR3GetState(pVM) < VMSTATE_DESTROYING)
|
---|
97 | return DBGCCreate(pVM, pBack, fFlags);
|
---|
98 | return VERR_INVALID_HANDLE;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /*static*/ DECLCALLBACK(void)
|
---|
103 | VBoxDbgBase::atStateChange(PVM pVM, VMSTATE enmState, VMSTATE /*enmOldState*/, void *pvUser)
|
---|
104 | {
|
---|
105 | VBoxDbgBase *pThis = (VBoxDbgBase *)pvUser;
|
---|
106 | switch (enmState)
|
---|
107 | {
|
---|
108 | case VMSTATE_TERMINATED:
|
---|
109 | /** @todo need to do some locking here? */
|
---|
110 | if (ASMAtomicCmpXchgPtr(&pThis->m_pVM, NULL, pVM))
|
---|
111 | pThis->sigTerminated();
|
---|
112 | break;
|
---|
113 |
|
---|
114 | case VMSTATE_DESTROYING:
|
---|
115 | pThis->sigDestroying();
|
---|
116 | break;
|
---|
117 |
|
---|
118 | default:
|
---|
119 | break;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | void
|
---|
125 | VBoxDbgBase::sigDestroying()
|
---|
126 | {
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | void
|
---|
131 | VBoxDbgBase::sigTerminated()
|
---|
132 | {
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 | //
|
---|
139 | //
|
---|
140 | //
|
---|
141 | // V B o x D b g B a s e W i n d o w
|
---|
142 | // V B o x D b g B a s e W i n d o w
|
---|
143 | // V B o x D b g B a s e W i n d o w
|
---|
144 | //
|
---|
145 | //
|
---|
146 | //
|
---|
147 |
|
---|
148 | unsigned VBoxDbgBaseWindow::m_cxBorder = 0;
|
---|
149 | unsigned VBoxDbgBaseWindow::m_cyBorder = 0;
|
---|
150 |
|
---|
151 |
|
---|
152 | VBoxDbgBaseWindow::VBoxDbgBaseWindow(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent)
|
---|
153 | : QWidget(a_pParent, Qt::Window), VBoxDbgBase(a_pDbgGui),
|
---|
154 | #ifdef Q_WS_X11
|
---|
155 | m_fPolished(false),
|
---|
156 | #else
|
---|
157 | m_fPolished(true),
|
---|
158 | #endif
|
---|
159 | m_x(INT_MAX), m_y(INT_MAX), m_cx(0), m_cy(0)
|
---|
160 | {
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | VBoxDbgBaseWindow::~VBoxDbgBaseWindow()
|
---|
165 | {
|
---|
166 |
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | void
|
---|
171 | VBoxDbgBaseWindow::vShow()
|
---|
172 | {
|
---|
173 | show();
|
---|
174 | /** @todo this ain't working right. HELP! */
|
---|
175 | setWindowState(windowState() & ~Qt::WindowMinimized);
|
---|
176 | //activateWindow();
|
---|
177 | //setFocus();
|
---|
178 | vPolishSizeAndPos();
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | void
|
---|
183 | VBoxDbgBaseWindow::vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize)
|
---|
184 | {
|
---|
185 | if (a_fResize)
|
---|
186 | {
|
---|
187 | m_cx = a_cx;
|
---|
188 | m_cy = a_cy;
|
---|
189 |
|
---|
190 | QSize BorderSize = frameSize() - size();
|
---|
191 | if (BorderSize == QSize(0,0))
|
---|
192 | BorderSize = vGuessBorderSizes();
|
---|
193 |
|
---|
194 | resize(a_cx - BorderSize.width(), a_cy - BorderSize.height());
|
---|
195 | }
|
---|
196 |
|
---|
197 | m_x = a_x;
|
---|
198 | m_y = a_y;
|
---|
199 | move(a_x, a_y);
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | bool
|
---|
204 | VBoxDbgBaseWindow::event(QEvent *a_pEvt)
|
---|
205 | {
|
---|
206 | bool fRc = QWidget::event(a_pEvt);
|
---|
207 | vPolishSizeAndPos();
|
---|
208 | return fRc;
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | void
|
---|
213 | VBoxDbgBaseWindow::vPolishSizeAndPos()
|
---|
214 | {
|
---|
215 | /* Ignore if already done or no size set. */
|
---|
216 | if ( m_fPolished
|
---|
217 | || (m_x == INT_MAX && m_y == INT_MAX))
|
---|
218 | return;
|
---|
219 |
|
---|
220 | QSize BorderSize = frameSize() - size();
|
---|
221 | if (BorderSize != QSize(0,0))
|
---|
222 | m_fPolished = true;
|
---|
223 |
|
---|
224 | vReposition(m_x, m_y, m_cx, m_cy, m_cx || m_cy);
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | QSize
|
---|
229 | VBoxDbgBaseWindow::vGuessBorderSizes()
|
---|
230 | {
|
---|
231 | #ifdef Q_WS_X11 /* (from the qt gui) */
|
---|
232 | /* only once. */
|
---|
233 | if (!m_cxBorder && !m_cyBorder)
|
---|
234 | {
|
---|
235 |
|
---|
236 | /* On X11, there is no way to determine frame geometry (including WM
|
---|
237 | * decorations) before the widget is shown for the first time. Stupidly
|
---|
238 | * enumerate other top level widgets to find the thickest frame. The code
|
---|
239 | * is based on the idea taken from QDialog::adjustPositionInternal(). */
|
---|
240 |
|
---|
241 | int extraw = 0, extrah = 0;
|
---|
242 |
|
---|
243 | QWidgetList list = QApplication::topLevelWidgets();
|
---|
244 | QListIterator<QWidget*> it (list);
|
---|
245 | while ((extraw == 0 || extrah == 0) && it.hasNext())
|
---|
246 | {
|
---|
247 | int framew, frameh;
|
---|
248 | QWidget *current = it.next();
|
---|
249 | if (!current->isVisible())
|
---|
250 | continue;
|
---|
251 |
|
---|
252 | framew = current->frameGeometry().width() - current->width();
|
---|
253 | frameh = current->frameGeometry().height() - current->height();
|
---|
254 |
|
---|
255 | extraw = qMax (extraw, framew);
|
---|
256 | extrah = qMax (extrah, frameh);
|
---|
257 | }
|
---|
258 |
|
---|
259 | if (extraw || extrah)
|
---|
260 | {
|
---|
261 | m_cxBorder = extraw;
|
---|
262 | m_cyBorder = extrah;
|
---|
263 | }
|
---|
264 | }
|
---|
265 | #endif /* X11 */
|
---|
266 | return QSize(m_cxBorder, m_cyBorder);
|
---|
267 | }
|
---|
268 |
|
---|