tools/*: remove bcc and as86 as they are no longer required to compile the system...
[virtualbox.git] / src / VBox / Debugger / VBoxDbgBase.cpp
blob5fd846bd2ac8d80c2195923770260e9d0b1a98e4
1 /* $Id$ */
2 /** @file
3 * VBox Debugger GUI - Base classes.
4 */
6 /*
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 /*******************************************************************************
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"
29 #include <QApplication>
30 #include <QWidgetList>
34 VBoxDbgBase::VBoxDbgBase(VBoxDbgGui *a_pDbgGui)
35 : m_pDbgGui(a_pDbgGui), m_pVM(NULL), m_hGUIThread(RTThreadNativeSelf())
38 * Register
40 PVM pVM = a_pDbgGui->getVMHandle();
41 if (pVM)
43 m_pVM = pVM;
44 int rc = VMR3AtStateRegister(pVM, atStateChange, this);
45 AssertRC(rc);
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);
57 if (pVM)
59 int rc = VMR3AtStateDeregister(pVM, atStateChange, this);
60 AssertRC(rc);
65 int
66 VBoxDbgBase::stamReset(const QString &rPat)
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;
78 int
79 VBoxDbgBase::stamEnum(const QString &rPat, PFNSTAMR3ENUM pfnEnum, void *pvUser)
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;
91 int
92 VBoxDbgBase::dbgcCreate(PDBGCBACK pBack, unsigned fFlags)
94 PVM pVM = m_pVM;
95 if ( pVM
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;
106 switch (enmState)
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;
114 case VMSTATE_DESTROYING:
115 pThis->sigDestroying();
116 break;
118 default:
119 break;
124 void
125 VBoxDbgBase::sigDestroying()
130 void
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()
165 void
166 VBoxDbgBaseWindow::vShow()
168 show();
169 /** @todo this ain't working right. HELP! */
170 setWindowState(windowState() & ~Qt::WindowMinimized);
171 //activateWindow();
172 //setFocus();
173 vPolishSizeAndPos();
177 void
178 VBoxDbgBaseWindow::vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize)
180 if (a_fResize)
182 m_cx = a_cx;
183 m_cy = a_cy;
185 QSize BorderSize = frameSize() - size();
186 if (BorderSize == QSize(0,0))
187 BorderSize = vGuessBorderSizes();
189 resize(a_cx - BorderSize.width(), a_cy - BorderSize.height());
192 m_x = a_x;
193 m_y = a_y;
194 move(a_x, a_y);
198 bool
199 VBoxDbgBaseWindow::event(QEvent *a_pEvt)
201 bool fRc = QWidget::event(a_pEvt);
202 vPolishSizeAndPos();
203 return fRc;
207 void
208 VBoxDbgBaseWindow::vPolishSizeAndPos()
210 /* Ignore if already done or no size set. */
211 if ( m_fPolished
212 || (m_x == INT_MAX && m_y == INT_MAX))
213 return;
215 QSize BorderSize = frameSize() - size();
216 if (BorderSize != QSize(0,0))
217 m_fPolished = true;
219 vReposition(m_x, m_y, m_cx, m_cy, m_cx || m_cy);
223 QSize
224 VBoxDbgBaseWindow::vGuessBorderSizes()
226 #ifdef Q_WS_X11 /* (from the qt gui) */
227 /* only once. */
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())
242 int framew, frameh;
243 QWidget *current = it.next();
244 if (!current->isVisible())
245 continue;
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)
256 m_cxBorder = extraw;
257 m_cyBorder = extrah;
260 #endif /* X11 */
261 return QSize(m_cxBorder, m_cyBorder);