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
), m_fPolished(false),
154 m_x(INT_MAX
), m_y(INT_MAX
), m_cx(0), m_cy(0)
159 VBoxDbgBaseWindow::~VBoxDbgBaseWindow()
166 VBoxDbgBaseWindow::vShow()
169 /** @todo this ain't working right. HELP! */
170 setWindowState(windowState() & ~Qt::WindowMinimized
);
178 VBoxDbgBaseWindow::vReposition(int a_x
, int a_y
, unsigned a_cx
, unsigned a_cy
, bool a_fResize
)
185 QSize BorderSize
= frameSize() - size();
186 if (BorderSize
== QSize(0,0))
187 BorderSize
= vGuessBorderSizes();
189 resize(a_cx
- BorderSize
.width(), a_cy
- BorderSize
.height());
199 VBoxDbgBaseWindow::event(QEvent
*a_pEvt
)
201 bool fRc
= QWidget::event(a_pEvt
);
208 VBoxDbgBaseWindow::vPolishSizeAndPos()
210 /* Ignore if already done or no size set. */
212 || (m_x
== INT_MAX
&& m_y
== INT_MAX
))
215 QSize BorderSize
= frameSize() - size();
216 if (BorderSize
!= QSize(0,0))
219 vReposition(m_x
, m_y
, m_cx
, m_cy
, m_cx
|| m_cy
);
224 VBoxDbgBaseWindow::vGuessBorderSizes()
226 #ifdef Q_WS_X11 /* (from the qt gui) */
228 if (!m_cxBorder
&& !m_cyBorder
)
231 /* On X11, there is no way to determine frame geometry (including WM
232 * decorations) before the widget is shown for the first time. Stupidly
233 * enumerate other top level widgets to find the thickest frame. The code
234 * is based on the idea taken from QDialog::adjustPositionInternal(). */
236 int extraw
= 0, extrah
= 0;
238 QWidgetList list
= QApplication::topLevelWidgets();
239 QListIterator
<QWidget
*> it (list
);
240 while ((extraw
== 0 || extrah
== 0) && it
.hasNext())
243 QWidget
*current
= it
.next();
244 if (!current
->isVisible())
247 framew
= current
->frameGeometry().width() - current
->width();
248 frameh
= current
->frameGeometry().height() - current
->height();
250 extraw
= qMax (extraw
, framew
);
251 extrah
= qMax (extrah
, frameh
);
254 if (extraw
|| extrah
)
261 return QSize(m_cxBorder
, m_cyBorder
);