VirtualBox

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

Last change on this file since 65521 was 65521, checked in by vboxsync, 8 years ago

Debugger: make font + color scheme setting persistent

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