VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgBase.cpp@ 44342

Last change on this file since 44342 was 44342, checked in by vboxsync, 12 years ago

build fix

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

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