VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgConsole.h@ 72492

Last change on this file since 72492 was 72197, checked in by vboxsync, 7 years ago

VBoxDbg: Console font size menu. Don't call setExtraData during construction in response to defaults or getExtraData values.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: VBoxDbgConsole.h 72197 2018-05-11 22:11:22Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI - Console.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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#ifndef ___Debugger_VBoxDbgConsole_h
19#define ___Debugger_VBoxDbgConsole_h
20
21#include "VBoxDbgBase.h"
22
23#include <QTextEdit>
24#include <QComboBox>
25#include <QTimer>
26#include <QEvent>
27#include <QActionGroup>
28
29#include <iprt/critsect.h>
30#include <iprt/semaphore.h>
31#include <iprt/thread.h>
32
33// VirtualBox COM interfaces declarations (generated header)
34#ifdef VBOX_WITH_XPCOM
35# include <VirtualBox_XPCOM.h>
36#else
37# include <VirtualBox.h>
38#endif
39
40
41class VBoxDbgConsoleOutput : public QTextEdit
42{
43 Q_OBJECT
44
45public:
46 /**
47 * Constructor.
48 *
49 * @param pParent Parent Widget.
50 * @param pVirtualBox VirtualBox object for storing extra data.
51 * @param pszName Widget name.
52 */
53 VBoxDbgConsoleOutput(QWidget *pParent = NULL, IVirtualBox *pVirtualBox = NULL, const char *pszName = NULL);
54
55 /**
56 * Destructor
57 */
58 virtual ~VBoxDbgConsoleOutput();
59
60 /**
61 * Appends text.
62 * This differs from QTextEdit::append() in that it won't start on a new paragraph
63 * unless the previous char was a newline ('\n').
64 *
65 * @param rStr The text string to append.
66 * @param fClearSelection Whether to clear selected text before appending.
67 * If @c false the selection and window position
68 * are preserved.
69 */
70 virtual void appendText(const QString &rStr, bool fClearSelection);
71
72 /** The action to switch to black-on-white color scheme. */
73 QAction *m_pBlackOnWhiteAction;
74 /** The action to switch to green-on-black color scheme. */
75 QAction *m_pGreenOnBlackAction;
76
77 /** The action to switch to Courier font. */
78 QAction *m_pCourierFontAction;
79 /** The action to switch to Monospace font. */
80 QAction *m_pMonospaceFontAction;
81
82protected:
83 typedef enum { kGreenOnBlack, kBlackOnWhite } VBoxDbgConsoleColor;
84 typedef enum { kFontType_Monospace, kFontType_Courier } VBoxDbgConsoleFontType;
85
86 /**
87 * Context menu event.
88 * This adds custom menu items for the output view.
89 *
90 * @param pEvent Pointer to the event.
91 */
92 virtual void contextMenuEvent(QContextMenuEvent *pEvent);
93
94 /**
95 * Sets the color scheme.
96 *
97 * @param enmScheme The new color scheme.
98 * @param fSaveIt Whether to save it.
99 */
100 void setColorScheme(VBoxDbgConsoleColor enmScheme, bool fSaveIt);
101
102 /**
103 * Sets the font type / family.
104 *
105 * @param enmFontType The font type.
106 * @param fSaveIt Whether to save it.
107 */
108 void setFontType(VBoxDbgConsoleFontType enmFontType, bool fSaveIt);
109
110 /**
111 * Sets the font size.
112 *
113 * @param uFontSize The new font size in points.
114 * @param fSaveIt Whether to save it.
115 */
116 void setFontSize(uint32_t uFontSize, bool fSaveIt);
117
118
119 /** The current line (paragraph) number. */
120 unsigned m_uCurLine;
121 /** The position in the current line. */
122 unsigned m_uCurPos;
123 /** The handle to the GUI thread. */
124 RTNATIVETHREAD m_hGUIThread;
125 /** The current color scheme (foreground on background). */
126 VBoxDbgConsoleColor m_enmColorScheme;
127 /** The IVirtualBox object */
128 IVirtualBox *m_pVirtualBox;
129
130 /** Array of font size actions 6..22pt. */
131 QAction *m_apFontSizeActions[22 - 6 + 1];
132 /** Action group for m_apFontSizeActions. */
133 QActionGroup *m_pActionFontSizeGroup;
134
135 /** The minimum font size. */
136 static const uint32_t s_uMinFontSize;
137
138private slots:
139 /**
140 * Selects color scheme
141 */
142 void sltSelectColorScheme();
143
144 /**
145 * Selects font type.
146 */
147 void sltSelectFontType();
148
149 /**
150 * Selects font size.
151 */
152 void sltSelectFontSize();
153};
154
155
156/**
157 * The Debugger Console Input widget.
158 *
159 * This is a combobox which only responds to \<return\>.
160 */
161class VBoxDbgConsoleInput : public QComboBox
162{
163 Q_OBJECT
164
165public:
166 /**
167 * Constructor.
168 *
169 * @param pParent Parent Widget.
170 * @param pszName Widget name.
171 */
172 VBoxDbgConsoleInput(QWidget *pParent = NULL, const char *pszName = NULL);
173
174 /**
175 * Destructor
176 */
177 virtual ~VBoxDbgConsoleInput();
178
179 /**
180 * We overload this method to get signaled upon returnPressed().
181 *
182 * See QComboBox::setLineEdit for full description.
183 * @param pEdit The new line edit widget.
184 * @remark This won't be called during the constructor.
185 */
186 virtual void setLineEdit(QLineEdit *pEdit);
187
188signals:
189 /**
190 * New command submitted.
191 */
192 void commandSubmitted(const QString &rCommand);
193
194private slots:
195 /**
196 * Returned was pressed.
197 *
198 * Will emit commandSubmitted().
199 */
200 void returnPressed();
201
202protected:
203 /** The handle to the GUI thread. */
204 RTNATIVETHREAD m_hGUIThread;
205};
206
207
208/**
209 * The Debugger Console.
210 */
211class VBoxDbgConsole : public VBoxDbgBaseWindow
212{
213 Q_OBJECT
214
215public:
216 /**
217 * Constructor.
218 *
219 * @param a_pDbgGui Pointer to the debugger gui object.
220 * @param a_pParent Parent Widget.
221 * @param a_pVirtualBox VirtualBox object for storing extra data.
222 */
223 VBoxDbgConsole(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent = NULL, IVirtualBox *a_pVirtualBox = NULL);
224
225 /**
226 * Destructor
227 */
228 virtual ~VBoxDbgConsole();
229
230protected slots:
231 /**
232 * Handler called when a command is submitted.
233 * (Enter or return pressed in the combo box.)
234 *
235 * @param rCommand The submitted command.
236 */
237 void commandSubmitted(const QString &rCommand);
238
239 /**
240 * Updates the output with what's currently in the output buffer.
241 * This is called by a timer or a User event posted by the debugger thread.
242 */
243 void updateOutput();
244
245 /**
246 * Changes the focus to the input field.
247 */
248 void actFocusToInput();
249
250 /**
251 * Changes the focus to the output viewer widget.
252 */
253 void actFocusToOutput();
254
255protected:
256 /**
257 * Override the closeEvent so we can choose delete the window when
258 * it is closed.
259 *
260 * @param a_pCloseEvt The close event.
261 */
262 virtual void closeEvent(QCloseEvent *a_pCloseEvt);
263
264 /**
265 * Lock the object.
266 */
267 void lock();
268
269 /**
270 * Unlocks the object.
271 */
272 void unlock();
273
274protected:
275 /** @name Debug Console Backend.
276 * @{
277 */
278
279
280 /**
281 * Checks if there is input.
282 *
283 * @returns true if there is input ready.
284 * @returns false if there not input ready.
285 * @param pBack Pointer to VBoxDbgConsole::m_Back.
286 * @param cMillies Number of milliseconds to wait on input data.
287 */
288 static DECLCALLBACK(bool) backInput(PDBGCBACK pBack, uint32_t cMillies);
289
290 /**
291 * Read input.
292 *
293 * @returns VBox status code.
294 * @param pBack Pointer to VBoxDbgConsole::m_Back.
295 * @param pvBuf Where to put the bytes we read.
296 * @param cbBuf Maximum nymber of bytes to read.
297 * @param pcbRead Where to store the number of bytes actually read.
298 * If NULL the entire buffer must be filled for a
299 * successful return.
300 */
301 static DECLCALLBACK(int) backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
302
303 /**
304 * Write (output).
305 *
306 * @returns VBox status code.
307 * @param pBack Pointer to VBoxDbgConsole::m_Back.
308 * @param pvBuf What to write.
309 * @param cbBuf Number of bytes to write.
310 * @param pcbWritten Where to store the number of bytes actually written.
311 * If NULL the entire buffer must be successfully written.
312 */
313 static DECLCALLBACK(int) backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
314
315 /**
316 * @copydoc FNDBGCBACKSETREADY
317 */
318 static DECLCALLBACK(void) backSetReady(PDBGCBACK pBack, bool fReady);
319
320 /**
321 * The Debugger Console Thread
322 *
323 * @returns VBox status code (ignored).
324 * @param Thread The thread handle.
325 * @param pvUser Pointer to the VBoxDbgConsole object.s
326 */
327 static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
328
329 /** @} */
330
331protected:
332 /**
333 * Processes GUI command posted by the console thread.
334 *
335 * Qt3 isn't thread safe on any platform, meaning there is no locking, so, as
336 * a result we have to be very careful. All operations on objects which we share
337 * with the main thread has to be posted to it so it can perform it.
338 */
339 bool event(QEvent *pEvent);
340
341 /**
342 * For implementing keyboard shortcuts.
343 *
344 * @param pEvent The key event.
345 */
346 void keyReleaseEvent(QKeyEvent *pEvent);
347
348protected:
349 /** The output widget. */
350 VBoxDbgConsoleOutput *m_pOutput;
351 /** The input widget. */
352 VBoxDbgConsoleInput *m_pInput;
353 /** A hack to restore focus to the combobox after a command execution. */
354 bool m_fInputRestoreFocus;
355 /** The input buffer. */
356 char *m_pszInputBuf;
357 /** The amount of input in the buffer. */
358 size_t m_cbInputBuf;
359 /** The allocated size of the buffer. */
360 size_t m_cbInputBufAlloc;
361
362 /** The output buffer. */
363 char *m_pszOutputBuf;
364 /** The amount of output in the buffer. */
365 size_t m_cbOutputBuf;
366 /** The allocated size of the buffer. */
367 size_t m_cbOutputBufAlloc;
368 /** The timer object used to process output in a delayed fashion. */
369 QTimer *m_pTimer;
370 /** Set when an output update is pending. */
371 bool volatile m_fUpdatePending;
372
373 /** The debugger console thread. */
374 RTTHREAD m_Thread;
375 /** The event semaphore used to signal the debug console thread about input. */
376 RTSEMEVENT m_EventSem;
377 /** The critical section used to lock the object. */
378 RTCRITSECT m_Lock;
379 /** When set the thread will cause the debug console thread to terminate. */
380 bool volatile m_fTerminate;
381 /** Has the thread terminated?
382 * Used to do the right thing in closeEvent; the console is dead if the
383 * thread has terminated. */
384 bool volatile m_fThreadTerminated;
385
386 /** The debug console backend structure.
387 * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
388 struct VBoxDbgConsoleBack
389 {
390 DBGCBACK Core;
391 VBoxDbgConsole *pSelf;
392 } m_Back;
393
394 /**
395 * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
396 * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
397 */
398# define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
399
400 /** Change focus to the input field. */
401 QAction *m_pFocusToInput;
402 /** Change focus to the output viewer widget. */
403 QAction *m_pFocusToOutput;
404};
405
406
407/**
408 * Simple event class for push certain operations over
409 * onto the GUI thread.
410 */
411class VBoxDbgConsoleEvent : public QEvent
412{
413public:
414 typedef enum { kUpdate, kInputEnable, kTerminatedUser, kTerminatedOther } VBoxDbgConsoleEventType;
415 enum { kEventNumber = QEvent::User + 42 };
416
417 VBoxDbgConsoleEvent(VBoxDbgConsoleEventType enmCommand)
418 : QEvent((QEvent::Type)kEventNumber), m_enmCommand(enmCommand)
419 {
420 }
421
422 VBoxDbgConsoleEventType command() const
423 {
424 return m_enmCommand;
425 }
426
427private:
428 VBoxDbgConsoleEventType m_enmCommand;
429};
430
431
432#endif
433
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