VirtualBox

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

Last change on this file since 49142 was 49142, checked in by vboxsync, 11 years ago

Debugger/VBoxDbgConsole: Customized context-menu to toggle colors/fonts.

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