1
/* $Id: VBoxDbgBase.cpp 31530 2010-08-10 12:24:45Z vboxsync $ */
3
* VBox Debugger GUI - Base classes.
7
* Copyright (C) 2006-2010 Oracle Corporation
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.
18
/*******************************************************************************
20
*******************************************************************************/
21
#define LOG_GROUP LOG_GROUP_DBGG
24
#include <iprt/assert.h>
26
#include "VBoxDbgBase.h"
27
#include "VBoxDbgGui.h"
29
#include <QApplication>
30
#include <QWidgetList>
34
VBoxDbgBase::VBoxDbgBase(VBoxDbgGui *a_pDbgGui)
35
: m_pDbgGui(a_pDbgGui), m_pVM(NULL), m_hGUIThread(RTThreadNativeSelf())
40
PVM pVM = a_pDbgGui->getVMHandle();
44
int rc = VMR3AtStateRegister(pVM, atStateChange, this);
50
VBoxDbgBase::~VBoxDbgBase()
53
* If the VM is still around.
55
/** @todo need to do some locking here? */
56
PVM pVM = ASMAtomicXchgPtrT(&m_pVM, NULL, PVM);
59
int rc = VMR3AtStateDeregister(pVM, atStateChange, this);
66
VBoxDbgBase::stamReset(const QString &rPat)
68
QByteArray Utf8Array = rPat.toUtf8();
69
const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
72
&& VMR3GetState(pVM) < VMSTATE_DESTROYING)
73
return STAMR3Reset(pVM, pszPat);
74
return VERR_INVALID_HANDLE;
79
VBoxDbgBase::stamEnum(const QString &rPat, PFNSTAMR3ENUM pfnEnum, void *pvUser)
81
QByteArray Utf8Array = rPat.toUtf8();
82
const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
85
&& VMR3GetState(pVM) < VMSTATE_DESTROYING)
86
return STAMR3Enum(pVM, pszPat, pfnEnum, pvUser);
87
return VERR_INVALID_HANDLE;
92
VBoxDbgBase::dbgcCreate(PDBGCBACK pBack, unsigned fFlags)
96
&& VMR3GetState(pVM) < VMSTATE_DESTROYING)
97
return DBGCCreate(pVM, pBack, fFlags);
98
return VERR_INVALID_HANDLE;
102
/*static*/ DECLCALLBACK(void)
103
VBoxDbgBase::atStateChange(PVM pVM, VMSTATE enmState, VMSTATE /*enmOldState*/, void *pvUser)
105
VBoxDbgBase *pThis = (VBoxDbgBase *)pvUser;
108
case VMSTATE_TERMINATED:
109
/** @todo need to do some locking here? */
110
if (ASMAtomicCmpXchgPtr(&pThis->m_pVM, NULL, pVM))
111
pThis->sigTerminated();
114
case VMSTATE_DESTROYING:
115
pThis->sigDestroying();
125
VBoxDbgBase::sigDestroying()
131
VBoxDbgBase::sigTerminated()
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
148
unsigned VBoxDbgBaseWindow::m_cxBorder = 0;
149
unsigned VBoxDbgBaseWindow::m_cyBorder = 0;
152
VBoxDbgBaseWindow::VBoxDbgBaseWindow(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent)
153
: QWidget(a_pParent, Qt::Window), VBoxDbgBase(a_pDbgGui),
159
m_x(INT_MAX), m_y(INT_MAX), m_cx(0), m_cy(0)
164
VBoxDbgBaseWindow::~VBoxDbgBaseWindow()
171
VBoxDbgBaseWindow::vShow()
174
/** @todo this ain't working right. HELP! */
175
setWindowState(windowState() & ~Qt::WindowMinimized);
183
VBoxDbgBaseWindow::vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize)
190
QSize BorderSize = frameSize() - size();
191
if (BorderSize == QSize(0,0))
192
BorderSize = vGuessBorderSizes();
194
resize(a_cx - BorderSize.width(), a_cy - BorderSize.height());
204
VBoxDbgBaseWindow::event(QEvent *a_pEvt)
206
bool fRc = QWidget::event(a_pEvt);
213
VBoxDbgBaseWindow::vPolishSizeAndPos()
215
/* Ignore if already done or no size set. */
217
|| (m_x == INT_MAX && m_y == INT_MAX))
220
QSize BorderSize = frameSize() - size();
221
if (BorderSize != QSize(0,0))
224
vReposition(m_x, m_y, m_cx, m_cy, m_cx || m_cy);
229
VBoxDbgBaseWindow::vGuessBorderSizes()
231
#ifdef Q_WS_X11 /* (from the qt gui) */
233
if (!m_cxBorder && !m_cyBorder)
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(). */
241
int extraw = 0, extrah = 0;
243
QWidgetList list = QApplication::topLevelWidgets();
244
QListIterator<QWidget*> it (list);
245
while ((extraw == 0 || extrah == 0) && it.hasNext())
248
QWidget *current = it.next();
249
if (!current->isVisible())
252
framew = current->frameGeometry().width() - current->width();
253
frameh = current->frameGeometry().height() - current->height();
255
extraw = qMax (extraw, framew);
256
extrah = qMax (extrah, frameh);
259
if (extraw || extrah)
266
return QSize(m_cxBorder, m_cyBorder);