annotate libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @ 16617:3a17dd5964e3

use average width for character size in GUI terminal for Windows * QWinTErminalImpl.cpp (QConsolePrivate::updateConsoleSize): Use QFontMetrics::averageCharWidth instead of maxWidth.
author John W. Eaton <jwe@octave.org>
date Mon, 06 May 2013 00:56:09 -0400
parents dae674adf045
children 13728d41fb6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1 /*
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
2
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 Copyright (C) 2011 Michael Goffioul.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
5 This file is part of QConsole.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
6
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
7 Foobar is free software: you can redistribute it and/or modify
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 (at your option) any later version.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
12 QConsole is distributed in the hope that it will be useful,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
15 GNU General Public License for more details.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
18 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
19
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
20 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
22 #include <QApplication>
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
23 #include <QClipboard>
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
24 #include <QColor>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
25 #include <QFont>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
26 #include <QHBoxLayout>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
27 #include <QPaintEvent>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
28 #include <QPainter>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
29 #include <QResizeEvent>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
30 #include <QScrollBar>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
31 #include <QtDebug>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
32 #include <QThread>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
33 #include <QTimer>
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
34 #include <QToolTip>
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
35 #include <QCursor>
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
36 #include <QMessageBox>
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
37
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
38 #include <fcntl.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
39 #include <io.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
40 #include <stdio.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
41 #include <stdarg.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
42 #define WIN32_LEAN_AND_MEAN
15665
4ee03200951e Applied patch for compiling with mingw.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15662
diff changeset
43 #define _WIN32_WINNT 0x0500
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
44 #include <windows.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
45 #include <cstring>
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
46 #include <limits>
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
47
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
48 #include "QWinTerminalImpl.h"
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
49 #include "QTerminalColors.h"
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
50
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
51 // Uncomment to log activity to LOGFILENAME
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
52 // #define DEBUG_QCONSOLE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
53 #define LOGFILENAME "QConsole.log"
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
54 // Uncomment to create hidden console window
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
55 #define HIDDEN_CONSOLE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
56
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
57 #ifdef _MSC_VER
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
58 # pragma warning(disable : 4996)
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
59 #endif
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
60
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
61 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
62
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
63 class QConsoleView : public QWidget
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
64 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
65 public:
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
66 QConsoleView (QWinTerminalImpl* parent = 0) : QWidget (parent), q (parent) { }
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
67 ~QConsoleView (void) { }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
68
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
69 protected:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
70 void paintEvent (QPaintEvent* event) { q->viewPaintEvent (this, event); }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
71 void resizeEvent (QResizeEvent* event) { q->viewResizeEvent (this, event); }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
72
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
73 private:
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
74 QWinTerminalImpl* q;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
75 };
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
76
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
77 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
78
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
79 class QConsoleThread : public QThread
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
80 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
81 public:
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
82 QConsoleThread (QWinTerminalImpl* console) : QThread (console), q (console) { }
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
83
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
84 protected:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
85 void run (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
86 { q->start (); }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
87
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
88 private:
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
89 QWinTerminalImpl* q;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
90 };
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
91
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
92 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
93
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
94 class QConsolePrivate
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
95 {
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
96 friend class QWinTerminalImpl;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
97
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
98 public:
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
99
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
100 enum KeyboardCursorType
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
101 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
102 BlockCursor,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
103 UnderlineCursor,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
104 IBeamCursor
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
105 };
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
106
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
107 QConsolePrivate (QWinTerminalImpl* parent, const QString& cmd = QString ());
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
108 ~QConsolePrivate (void);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
109
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
110 void updateConsoleSize (bool sync = false);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
111 void syncConsoleParameters (void);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
112 void grabConsoleBuffer (CHAR_INFO* buf = 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
113 void updateScrollBar (void);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
114 void setScrollValue (int value);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
115 void updateConsoleView (bool grab = true);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
116 void monitorConsole (void);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
117 void startCommand (void);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
118 void sendConsoleText (const QString& s);
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
119 QRect cursorRect (void);
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
120
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
121 void log (const char* fmt, ...);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
122
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
123 void closeStandardIO (int fd, DWORD stdHandleId, const char* name);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
124 void setupStandardIO (DWORD stdHandleId, int fd, const char* name,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
125 const char* devName);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
126
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
127 QPoint posToCell (const QPoint& pt);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
128 QString getSelection (void);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
129 void updateSelection (void);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
130 void clearSelection (void);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
131
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
132 private:
15658
eaa7da75d202 Added QTerminalInteface class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15653
diff changeset
133 QWinTerminalImpl* q;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
134
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
135 private:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
136 QFont m_font;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
137 QColor m_backgroundColor;
16474
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
138 QColor m_foregroundColor;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
139 QString m_command;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
140 QConsoleColors m_colors;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
141 bool m_inWheelEvent;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
142 QString m_title;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
143
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
144 QSize m_charSize;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
145 QSize m_bufferSize;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
146 QRect m_consoleRect;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
147 QPoint m_cursorPos;
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
148 bool m_cursorBlinking;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
149 bool m_hasBlinkingCursor;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
150 QTimer *m_blinkCursorTimer;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
151 KeyboardCursorType m_cursorType;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
152
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
153 QPoint m_beginSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
154 QPoint m_endSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
155
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
156 HANDLE m_stdOut;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
157 HWND m_consoleWindow;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
158 CHAR_INFO* m_buffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
159 CHAR_INFO* m_tmpBuffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
160 HANDLE m_process;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
161
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
162 QConsoleView* m_consoleView;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
163 QScrollBar* m_scrollBar;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
164 QTimer* m_consoleWatcher;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
165 QConsoleThread *m_consoleThread;
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
166
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
167 // The delay in milliseconds between redrawing blinking text.
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
168 static const int BLINK_DELAY = 500;
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
169 };
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
170
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
171 static void maybeSwapPoints (QPoint& begin, QPoint& end)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
172 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
173 if (end.y () < begin.y ()
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
174 || (end.y () == begin.y () && end.x () < begin.x ()))
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
175 qSwap (begin, end);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
176 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
177
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
178 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
179
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
180 QConsolePrivate::QConsolePrivate (QWinTerminalImpl* parent, const QString& cmd)
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
181 : q (parent), m_command (cmd), m_hasBlinkingCursor (true),
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
182 m_cursorType (BlockCursor), m_beginSelection (0, 0),
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
183 m_endSelection (0, 0), m_process (NULL), m_inWheelEvent (false)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
184 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
185 log (NULL);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
186
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
187 // Possibly detach from any existing console
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
188 log ("Detaching from existing console (if any)...\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
189 FreeConsole ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
190 log ("Closing standard IO...\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
191 closeStandardIO (0, STD_INPUT_HANDLE, "STDIN");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
192 closeStandardIO (1, STD_OUTPUT_HANDLE, "STDOUT");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
193 closeStandardIO (2, STD_ERROR_HANDLE, "STDERR");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
194
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
195 #ifdef HIDDEN_CONSOLE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
196 HWINSTA hOrigSta, hNewSta;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
197
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
198 // Create new (hidden) console
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
199 hOrigSta = GetProcessWindowStation ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
200 hNewSta = CreateWindowStation (NULL, 0, GENERIC_ALL, NULL);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
201 log ("Current Windows station: %p.\nNew Windows station: %p.\n", hOrigSta,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
202 hNewSta);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
203 if (! SetProcessWindowStation (hNewSta))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
204 log ("Failed to switch to new Windows station.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
205 #endif
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
206 if (! AllocConsole ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
207 log ("Failed to create new console.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
208 #ifdef HIDDEN_CONSOLE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
209 if (! SetProcessWindowStation (hOrigSta))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
210 log ("Failed to restore original Windows station.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
211 if (! CloseWindowStation (hNewSta))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
212 log ("Failed to close new Windows station.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
213 #endif
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
214
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
215 log ("New (hidden) console created.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
216
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
217 setupStandardIO (STD_INPUT_HANDLE, 0, "STDIN", "CONIN$");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
218 setupStandardIO (STD_OUTPUT_HANDLE, 1, "STDOUT", "CONOUT$");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
219 setupStandardIO (STD_ERROR_HANDLE, 2, "STDERR", "CONOUT$");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
220
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
221 log ("Standard input/output/error set up.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
222
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
223 *stdin = *(fdopen (0, "rb"));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
224 *stdout = *(fdopen (1, "wb"));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
225 *stderr = *(fdopen (2, "wb"));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
226
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
227 log ("POSIX standard streams created.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
228
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
229 setvbuf (stdin, NULL, _IONBF, 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
230 setvbuf (stdout, NULL, _IONBF, 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
231 setvbuf (stderr, NULL, _IONBF, 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
232
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
233 log ("POSIX standard stream buffers adjusted.\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
234
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
235 HANDLE hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
236
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
237 log ("Console allocated: hStdOut: %p\n", hStdOut);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
238
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
239 m_stdOut = hStdOut;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
240 m_consoleWindow = GetConsoleWindow ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
241
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
242 // In case the console window hasn't been created hidden...
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
243 ShowWindow (m_consoleWindow, SW_HIDE);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
244
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
245 CONSOLE_SCREEN_BUFFER_INFO sbi;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
246
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
247 GetConsoleScreenBufferInfo (hStdOut, &sbi);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
248 m_bufferSize = QSize (sbi.dwSize.X, qMax (sbi.dwSize.Y, (SHORT)500));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
249 m_consoleRect = QRect (sbi.srWindow.Left, sbi.srWindow.Top,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
250 sbi.srWindow.Right - sbi.srWindow.Left + 1,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
251 sbi.srWindow.Bottom - sbi.srWindow.Top + 1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
252 m_cursorPos = QPoint (sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
253
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
254 log ("Initial console parameters:\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
255 log (" buffer size: %d x %d\n", m_bufferSize.width (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
256 m_bufferSize.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
257 log (" window: (%d, %d) -> (%d, %d) [%d x %d]\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
258 m_consoleRect.left (), m_consoleRect.top (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
259 m_consoleRect.right (), m_consoleRect.bottom (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
260 m_consoleRect.width (), m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
261
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
262 wchar_t titleBuf[260];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
263 GetConsoleTitleW (titleBuf, sizeof (titleBuf));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
264 q->setWindowTitle (QString::fromWCharArray (titleBuf));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
265
16474
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
266 m_backgroundColor = Qt::white;
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
267 m_foregroundColor = Qt::black;
16513
44f3a9f6e791 fix windows terminal widget colors
John W. Eaton <jwe@octave.org>
parents: 16474
diff changeset
268 SetConsoleTextAttribute (m_stdOut, 0xF0);
16474
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
269
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
270 m_font.setFamily ("Lucida Console");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
271 m_font.setPointSize (9);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
272 m_font.setStyleHint (QFont::TypeWriter);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
273
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
274 m_buffer = m_tmpBuffer = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
275
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
276 m_consoleView = new QConsoleView (parent);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
277 m_scrollBar = new QScrollBar (Qt::Vertical, parent);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
278
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
279 QHBoxLayout* l = new QHBoxLayout (parent);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
280 l->setContentsMargins (0, 0, 0, 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
281 l->setSpacing (0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
282 l->addWidget (m_consoleView, 1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
283 l->addWidget (m_scrollBar, 0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
284
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
285 m_consoleView->setPalette (QPalette (m_backgroundColor));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
286 m_consoleView->setAutoFillBackground (true);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
287 m_consoleView->setFont (m_font);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
288 parent->setFocusPolicy (Qt::StrongFocus);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
289 parent->winId ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
290
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
291 updateScrollBar ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
292
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
293 m_consoleWatcher = new QTimer (parent);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
294 m_consoleWatcher->setInterval (10);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
295 m_consoleWatcher->setSingleShot (false);
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
296
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
297 m_blinkCursorTimer = new QTimer (parent);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
298 QObject::connect (m_blinkCursorTimer, SIGNAL (timeout()),
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
299 q, SLOT (blinkCursorEvent ()));
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
300
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
301 QObject::connect (m_scrollBar, SIGNAL (valueChanged (int)),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
302 q, SLOT (scrollValueChanged (int)));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
303 QObject::connect (m_consoleWatcher, SIGNAL (timeout (void)),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
304 q, SLOT (monitorConsole (void)));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
305
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
306 m_consoleWatcher->start ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
307
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
308 if (m_command.isEmpty ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
309 m_consoleThread = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
310 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
311 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
312 m_consoleThread = new QConsoleThread (q);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
313 QObject::connect (m_consoleThread, SIGNAL (finished (void)),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
314 q, SIGNAL (terminated (void)));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
315 m_consoleThread->start ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
316 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
317 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
318
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
319 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
320
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
321 QConsolePrivate::~QConsolePrivate (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
322 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
323 if (m_consoleThread && m_consoleThread->isRunning () && m_process)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
324 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
325 TerminateProcess (m_process, (UINT)-1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
326 m_consoleThread->wait ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
327 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
328 if (m_buffer)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
329 delete [] m_buffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
330 if (m_tmpBuffer)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
331 delete [] m_tmpBuffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
332 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
333
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
334 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
335
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
336 void QConsolePrivate::setupStandardIO (DWORD stdHandleId, int targetFd,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
337 const char* name, const char* devName)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
338 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
339 log ("Opening %s...\n", devName);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
340
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
341 int fd = open (devName, _O_RDWR | _O_BINARY);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
342
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
343 if (fd != -1)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
344 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
345 if (fd != targetFd)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
346 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
347 log ("Opened %s is not at target file descriptor %d, "
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
348 "duplicating...\n", name, targetFd);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
349 if (dup2 (fd, targetFd) == -1)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
350 log ("Failed to duplicate file descriptor: errno=%d.\n", errno);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
351 if (close (fd) == -1)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
352 log ("Failed to close original file descriptor: errno=%d.\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
353 errno);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
354 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
355 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
356 log ("%s opened and assigned to file descriptor %d.\n", devName, fd);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
357 if (! SetStdHandle (stdHandleId, (HANDLE) _get_osfhandle (targetFd)))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
358 log ("Failed to re-assign %s: error=%08x.\n", name, GetLastError ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
359 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
360 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
361 log ("Failed to open %s: errno=%d.\n", devName, errno);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
362 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
363
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
364 QPoint QConsolePrivate::posToCell (const QPoint& p)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
365 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
366 return QPoint (m_consoleRect.left () + p.x () / m_charSize.width (),
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
367 m_consoleRect.top () + p.y () / m_charSize.height ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
368 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
369
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
370 QString QConsolePrivate::getSelection (void)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
371 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
372 QString selection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
373
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
374 QPoint begin = m_beginSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
375 QPoint end = m_endSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
376
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
377 maybeSwapPoints (begin, end);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
378
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
379 if (m_beginSelection != m_endSelection)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
380 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
381 CHAR_INFO* buf;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
382 COORD bufSize, bufCoord;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
383 SMALL_RECT bufRect;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
384 int nr;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
385
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
386 nr = m_endSelection.y () - m_beginSelection.y () + 1;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
387 buf = new CHAR_INFO[m_bufferSize.width () * nr];
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
388 bufSize.X = m_bufferSize.width ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
389 bufSize.Y = nr;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
390 bufCoord.X = 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
391 bufCoord.Y = 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
392
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
393 bufRect.Left = 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
394 bufRect.Right = m_bufferSize.width ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
395 bufRect.Top = m_beginSelection.y ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
396 bufRect.Bottom = m_endSelection.y ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
397
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
398 if (ReadConsoleOutput (m_stdOut, buf, bufSize, bufCoord, &bufRect))
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
399 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
400 int start = m_beginSelection.x ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
401 int end = (nr - 1) * m_bufferSize.width () + m_endSelection.x ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
402 int lastNonSpace = -1;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
403
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
404 for (int i = start; i <= end; i++)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
405 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
406 if (i && (i % m_bufferSize.width ()) == 0)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
407 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
408 if (lastNonSpace >= 0)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
409 selection.truncate (lastNonSpace);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
410 selection.append ('\n');
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
411 lastNonSpace = selection.length ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
412 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
413
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
414 QChar c (buf[i].Char.UnicodeChar);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
415
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
416 selection.append (c);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
417 if (! c.isSpace ())
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
418 lastNonSpace = selection.length ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
419 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
420
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
421 if (lastNonSpace >= 0)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
422 selection.truncate (lastNonSpace);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
423 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
424 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
425
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
426 return selection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
427 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
428
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
429 void QConsolePrivate::updateSelection (void)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
430 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
431 QPoint begin = m_beginSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
432 QPoint end = m_endSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
433
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
434 maybeSwapPoints (begin, end);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
435
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
436 begin.rx () = 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
437 end.rx () = m_consoleRect.width ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
438
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
439 m_consoleView->update ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
440 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
441
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
442 void QConsolePrivate::clearSelection (void)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
443 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
444 m_beginSelection = m_endSelection = QPoint ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
445
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
446 m_consoleView->update ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
447 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
448
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
449 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
450
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
451 void QConsolePrivate::closeStandardIO (int fd, DWORD stdHandleId,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
452 const char* name)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
453 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
454 if (close (fd) == -1)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
455 log ("Failed to close file descriptor %d: errno=%d.\n", fd, errno);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
456 if (! CloseHandle (GetStdHandle (stdHandleId)))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
457 log ("Failed to close Win32 %s: error=%08x.\n", name, GetLastError ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
458 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
459
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
460 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
461
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
462 void QConsolePrivate::log (const char* fmt, ...)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
463 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
464 #ifdef DEBUG_QCONSOLE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
465 if (fmt)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
466 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
467 va_list l;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
468 FILE* flog = fopen (LOGFILENAME, "ab");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
469
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
470 va_start (l, fmt);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
471 vfprintf (flog, fmt, l);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
472 va_end (l);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
473 fclose (flog);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
474 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
475 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
476 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
477 // Special case to re-initialize the log file
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
478 FILE* flog = fopen (LOGFILENAME, "w");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
479 fclose (flog);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
480 }
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
481 #else
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
482 Q_UNUSED (fmt);
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
483 #endif
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
484 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
485
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
486 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
487
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
488 void QConsolePrivate::updateConsoleSize (bool sync)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
489 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
490 QFontMetrics fm (m_font);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
491 QSize winSize = m_consoleView->size ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
492
16617
3a17dd5964e3 use average width for character size in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16612
diff changeset
493 m_charSize.rwidth () = fm.averageCharWidth ();
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
494 m_charSize.rheight () = fm.lineSpacing ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
495
16617
3a17dd5964e3 use average width for character size in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16612
diff changeset
496 m_consoleRect.setWidth (winSize.width () / fm.averageCharWidth ());
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
497 m_consoleRect.setHeight (winSize.height () / fm.lineSpacing ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
498
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
499 m_bufferSize.rwidth () = m_consoleRect.width ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
500 m_bufferSize.rheight () = qMax (m_bufferSize.height (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
501 m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
502
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
503 m_consoleRect.moveLeft (0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
504 if (m_consoleRect.bottom () >= m_bufferSize.height ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
505 m_consoleRect.moveTop (m_bufferSize.height () - m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
506
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
507 log ("Console resized:\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
508 log (" widget size: %d x %d\n", winSize.width (), winSize.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
509 log (" buffer size: %d x %d\n", m_bufferSize.width (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
510 m_bufferSize.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
511 log (" window: (%d, %d) -> (%d, %d) [%d x %d]\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
512 m_consoleRect.left (), m_consoleRect.top (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
513 m_consoleRect.right (), m_consoleRect.bottom (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
514 m_consoleRect.width (), m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
515
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
516 if (sync)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
517 syncConsoleParameters ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
518
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
519 updateScrollBar ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
520 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
521
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
522 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
523
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
524 void QConsolePrivate::syncConsoleParameters (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
525 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
526 CONSOLE_SCREEN_BUFFER_INFO sbi;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
527 HANDLE hStdOut = m_stdOut;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
528
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
529 GetConsoleScreenBufferInfo (hStdOut, &sbi);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
530
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
531 COORD bs;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
532 SMALL_RECT sr;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
533
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
534 bs.X = sbi.dwSize.X;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
535 bs.Y = m_bufferSize.height ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
536 sr.Left = sbi.srWindow.Left;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
537 sr.Right = sbi.srWindow.Right;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
538 sr.Top = m_consoleRect.top ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
539 sr.Bottom = m_consoleRect.bottom ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
540
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
541 if (bs.Y > sbi.dwSize.Y)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
542 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
543 SetConsoleScreenBufferSize (hStdOut, bs);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
544 SetConsoleWindowInfo (hStdOut, TRUE, &sr);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
545 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
546 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
547 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
548 SetConsoleWindowInfo (hStdOut, TRUE, &sr);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
549 SetConsoleScreenBufferSize (hStdOut, bs);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
550 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
551
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
552 bs.X = m_bufferSize.width ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
553 sr.Left = m_consoleRect.left ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
554 sr.Right = m_consoleRect.right ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
555
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
556 if (bs.X > sbi.dwSize.X)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
557 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
558 SetConsoleScreenBufferSize (hStdOut, bs);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
559 SetConsoleWindowInfo (hStdOut, TRUE, &sr);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
560 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
561 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
562 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
563 SetConsoleWindowInfo (hStdOut, TRUE, &sr);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
564 SetConsoleScreenBufferSize (hStdOut, bs);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
565 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
566
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
567 log ("Sync'ing console parameters:\n");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
568 log (" buffer size: %d x %d\n", bs.X, bs.Y);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
569 log (" window: (%d, %d) -> (%d, %d)\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
570 sr.Left, sr.Top, sr.Right, sr.Bottom);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
571
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
572 if (m_buffer)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
573 delete [] m_buffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
574 if (m_tmpBuffer)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
575 delete [] m_tmpBuffer;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
576
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
577 int bufSize = m_consoleRect.width () * m_consoleRect.height ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
578
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
579 m_buffer = new CHAR_INFO[bufSize];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
580 m_tmpBuffer = new CHAR_INFO[bufSize];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
581 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
582
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
583 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
584
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
585 void QConsolePrivate::grabConsoleBuffer (CHAR_INFO* buf)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
586 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
587 COORD bs, bc;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
588 SMALL_RECT r;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
589
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
590 bs.X = m_consoleRect.width ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
591 bs.Y = m_consoleRect.height ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
592 bc.X = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
593 bc.Y = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
594
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
595 r.Left = m_consoleRect.left ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
596 r.Top = m_consoleRect.top ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
597 r.Right = m_consoleRect.right ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
598 r.Bottom = m_consoleRect.bottom ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
599
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
600 if (! ReadConsoleOutput (m_stdOut, (buf ? buf : m_buffer), bs, bc, &r))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
601 qCritical ("cannot read console output");
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
602 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
603
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
604 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
605
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
606 void QConsolePrivate::updateScrollBar (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
607 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
608 m_scrollBar->setMinimum (0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
609 if (m_bufferSize.height () > m_consoleRect.height ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
610 m_scrollBar->setMaximum (m_bufferSize.height () - m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
611 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
612 m_scrollBar->setMaximum (0);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
613 m_scrollBar->setSingleStep (1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
614 m_scrollBar->setPageStep (m_consoleRect.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
615 m_scrollBar->setValue (m_consoleRect.top ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
616
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
617 log ("Scrollbar parameters updated: %d/%d/%d/%d\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
618 m_scrollBar->minimum (), m_scrollBar->maximum (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
619 m_scrollBar->singleStep (), m_scrollBar->pageStep ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
620 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
621
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
622 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
623
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
624 void QConsolePrivate::setScrollValue (int value)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
625 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
626 if (value == m_consoleRect.top ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
627 return;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
628
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
629 SMALL_RECT r;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
630 HANDLE hStdOut = m_stdOut;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
631
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
632 if (value + m_consoleRect.height () > m_bufferSize.height ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
633 value = m_bufferSize.height () - m_consoleRect.height ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
634
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
635 r.Left = m_consoleRect.left ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
636 r.Top = value;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
637 r.Right = m_consoleRect.right ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
638 r.Bottom = value + m_consoleRect.height () - 1;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
639
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
640 log ("Scrolling window: (%d, %d) -> (%d, %d) [%d x %d]\n",
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
641 r.Left, r.Top, r.Right, r.Bottom,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
642 r.Right - r.Left + 1, r.Bottom - r.Top + 1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
643
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
644 if (SetConsoleWindowInfo (hStdOut, TRUE, &r))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
645 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
646 m_consoleRect.moveTop (value);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
647 updateConsoleView ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
648 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
649 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
650
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
651 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
652
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
653 void QConsolePrivate::updateConsoleView (bool grab)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
654 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
655 if (grab)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
656 grabConsoleBuffer ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
657 m_consoleView->update ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
658 m_consoleWatcher->start ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
659 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
660
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
661 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
662
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
663 void QConsolePrivate::monitorConsole (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
664 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
665 CONSOLE_SCREEN_BUFFER_INFO sbi;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
666 HANDLE hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
667
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
668 static wchar_t titleBuf[260];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
669
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
670 GetConsoleTitleW (titleBuf, sizeof (titleBuf));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
671 QString title = QString::fromWCharArray (titleBuf);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
672
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
673 if (title != m_title)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
674 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
675 q->setWindowTitle (title);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
676 emit q->titleChanged (title);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
677 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
678
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
679 if (GetConsoleScreenBufferInfo (hStdOut, &sbi))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
680 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
681 if (m_bufferSize.width () != sbi.dwSize.X
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
682 || m_bufferSize.height () != sbi.dwSize.Y)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
683 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
684 // Buffer size changed
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
685 m_bufferSize.rwidth () = sbi.dwSize.X;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
686 m_bufferSize.rheight () = sbi.dwSize.Y;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
687 updateScrollBar ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
688 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
689
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
690 if (m_cursorPos.x () != sbi.dwCursorPosition.X
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
691 || m_cursorPos.y () != sbi.dwCursorPosition.Y)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
692 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
693 // Cursor position changed
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
694 m_consoleView->update
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
695 ((m_cursorPos.x () - sbi.srWindow.Left) * m_charSize.width (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
696 (m_cursorPos.y () - sbi.srWindow.Top) * m_charSize.height (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
697 m_charSize.width (), m_charSize.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
698 m_cursorPos.rx () = sbi.dwCursorPosition.X;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
699 m_cursorPos.ry () = sbi.dwCursorPosition.Y;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
700 m_consoleView->update
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
701 ((m_cursorPos.x () - sbi.srWindow.Left) * m_charSize.width (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
702 (m_cursorPos.y () - sbi.srWindow.Top) * m_charSize.height (),
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
703 m_charSize.width (), m_charSize.height ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
704 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
705
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
706 if (m_consoleRect.left () != sbi.srWindow.Left
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
707 || m_consoleRect.right () != sbi.srWindow.Right
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
708 || m_consoleRect.top () != sbi.srWindow.Top
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
709 || m_consoleRect.bottom () != sbi.srWindow.Bottom)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
710 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
711 // Console window changed
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
712 m_consoleRect = QRect (sbi.srWindow.Left, sbi.srWindow.Top,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
713 sbi.srWindow.Right - sbi.srWindow.Left + 1,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
714 sbi.srWindow.Bottom - sbi.srWindow.Top + 1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
715 updateScrollBar ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
716 updateConsoleView ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
717 return;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
718 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
719
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
720 if (m_tmpBuffer && m_buffer)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
721 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
722 grabConsoleBuffer (m_tmpBuffer);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
723 if (memcmp (m_tmpBuffer, m_buffer,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
724 sizeof (CHAR_INFO) * m_consoleRect.width () *
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
725 m_consoleRect.height ()))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
726 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
727 // FIXME: compute the area to update based on the
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
728 // difference between the 2 buffers.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
729 qSwap (m_buffer, m_tmpBuffer);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
730 updateConsoleView (false);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
731 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
732 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
733 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
734 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
735
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
736 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
737
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
738 void QConsolePrivate::startCommand (void)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
739 {
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
740 QString cmd = m_command;
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
741
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
742 if (cmd.isEmpty ())
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
743 cmd = qgetenv ("COMSPEC").constData ();
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
744
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
745 if (! cmd.isEmpty ())
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
746 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
747 STARTUPINFO si;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
748 PROCESS_INFORMATION pi;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
749
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
750 ZeroMemory (&si, sizeof (si));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
751 si.cb = sizeof (si);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
752 ZeroMemory (&pi, sizeof (pi));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
753
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
754 if (CreateProcessW (NULL,
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
755 (LPWSTR)cmd.unicode (),
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
756 NULL,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
757 NULL,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
758 TRUE,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
759 0,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
760 NULL,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
761 NULL,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
762 &si,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
763 &pi))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
764 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
765 CloseHandle (pi.hThread);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
766 m_process = pi.hProcess;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
767 WaitForSingleObject (m_process, INFINITE);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
768 CloseHandle (m_process);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
769 m_process = NULL;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
770 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
771 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
772 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
773
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
774 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
775
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
776 void QConsolePrivate::sendConsoleText (const QString& s)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
777 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
778 // Send the string in chunks of 512 characters. Each character is
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
779 // translated into an equivalent keypress event.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
780
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
781 #define TEXT_CHUNK_SIZE 512
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
782
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
783 int len = s.length ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
784 INPUT_RECORD events[TEXT_CHUNK_SIZE];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
785 DWORD nEvents = 0, written;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
786 HANDLE hStdIn = GetStdHandle (STD_INPUT_HANDLE);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
787
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
788 ZeroMemory (events, sizeof (events));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
789
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
790 for (int i = 0; i < len; i++)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
791 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
792 QChar c = s.at (i);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
793
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
794 if (c == L'\r' || c == L'\n')
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
795 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
796 if (c == L'\r' && i < (len - 1) && s.at (i+1) == L'\n')
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
797 i++;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
798 if (nEvents)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
799 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
800 WriteConsoleInput (hStdIn, events, nEvents, &written);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
801 nEvents = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
802 ZeroMemory (events, sizeof (events));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
803 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
804 PostMessage (m_consoleWindow, WM_KEYDOWN, VK_RETURN, 0x001C0001);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
805 PostMessage (m_consoleWindow, WM_KEYDOWN, VK_RETURN, 0xC01C0001);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
806 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
807 else
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
808 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
809 events[nEvents].EventType = KEY_EVENT;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
810 events[nEvents].Event.KeyEvent.bKeyDown = TRUE;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
811 events[nEvents].Event.KeyEvent.wRepeatCount = 1;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
812 events[nEvents].Event.KeyEvent.wVirtualKeyCode =
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
813 LOBYTE (VkKeyScan (c.unicode ()));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
814 events[nEvents].Event.KeyEvent.wVirtualScanCode = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
815 events[nEvents].Event.KeyEvent.uChar.UnicodeChar = c.unicode ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
816 events[nEvents].Event.KeyEvent.dwControlKeyState = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
817 nEvents++;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
818 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
819
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
820 if (nEvents == TEXT_CHUNK_SIZE
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
821 || (nEvents > 0 && i == (len - 1)))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
822 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
823 WriteConsoleInput (hStdIn, events, nEvents, &written);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
824 nEvents = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
825 ZeroMemory (events, sizeof (events));
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
826 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
827 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
828 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
829
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
830 QRect
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
831 QConsolePrivate::cursorRect (void)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
832 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
833 int cw = m_charSize.width ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
834 int ch = m_charSize.height ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
835
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
836 return QRect ((m_cursorPos.x () - m_consoleRect.x ()) * cw,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
837 (m_cursorPos.y () - m_consoleRect.y ()) * ch,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
838 cw, ch);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
839 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
840
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
841 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
842
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
843 QWinTerminalImpl::QWinTerminalImpl (QWidget* parent)
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
844 : QTerminalInterface (parent), d (new QConsolePrivate (this))
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
845 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
846 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
847
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
848 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
849
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
850 QWinTerminalImpl::QWinTerminalImpl (const QString& cmd, QWidget* parent)
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
851 : QTerminalInterface (parent), d (new QConsolePrivate (this, cmd))
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
852 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
853 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
854
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
855 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
856
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
857 QWinTerminalImpl::~QWinTerminalImpl (void)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
858 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
859 delete d;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
860 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
861
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
862 void QWinTerminalImpl::mouseMoveEvent (QMouseEvent *event)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
863 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
864 d->m_endSelection = d->posToCell (event->pos ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
865
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
866 updateSelection ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
867 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
868
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
869 void QWinTerminalImpl::mousePressEvent (QMouseEvent *event)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
870 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
871 if (event->button () == Qt::LeftButton)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
872 d->m_beginSelection = d->posToCell (event->pos ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
873 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
874
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
875 void QWinTerminalImpl::mouseReleaseEvent (QMouseEvent *event)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
876 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
877 if (event->button () == Qt::LeftButton)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
878 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
879 d->m_endSelection = d->posToCell (event->pos ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
880
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
881 updateSelection ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
882 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
883 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
884
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
885 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
886
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
887 void QWinTerminalImpl::viewResizeEvent (QConsoleView*, QResizeEvent*)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
888 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
889 d->updateConsoleSize (true);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
890 d->grabConsoleBuffer ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
891 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
892
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
893 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
894
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
895 void QWinTerminalImpl::viewPaintEvent (QConsoleView* w, QPaintEvent* event)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
896 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
897 QPainter p (w);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
898 int cw = d->m_charSize.width (), ch = d->m_charSize.height ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
899 int ascent, stride, cx1, cy1, cx2, cy2, x, y;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
900 WORD attr = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
901 QString s;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
902 bool hasChar = false;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
903
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
904 QRect updateRect = event->rect ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
905
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
906 cx1 = updateRect.left () / cw;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
907 cy1 = updateRect.top () / ch;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
908 cx2 = qMin (d->m_consoleRect.width () - 1, updateRect.right () / cw);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
909 cy2 = qMin (d->m_consoleRect.height () - 1, updateRect.bottom () / ch);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
910
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
911 if (cx1 > d->m_consoleRect.width () - 1
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
912 || cy1 > d->m_consoleRect.height () - 1)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
913 return;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
914
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
915 p.setFont (d->m_font);
16474
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
916 p.setPen (d->m_foregroundColor);
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
917
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
918 ascent = p.fontMetrics ().ascent ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
919 stride = d->m_consoleRect.width ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
920
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
921 s.reserve (cx2 - cx1 + 1);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
922 y = ascent + cy1 * ch;;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
923
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
924 QPoint begin = d->m_beginSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
925 QPoint end = d->m_endSelection;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
926
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
927 bool haveSelection = (begin != end);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
928
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
929 if (haveSelection)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
930 maybeSwapPoints (begin, end);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
931
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
932 if (haveSelection)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
933 d->log ("cy1: %d, cy2: %d, begin.y: %d, end.y: %d\n",
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
934 cy1, cy2, begin.y (), end.y ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
935
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
936 int scrollOffset = d->m_consoleRect.top ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
937
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
938 begin.ry () -= scrollOffset;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
939 end.ry () -= scrollOffset;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
940
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
941 for (int j = cy1; j <= cy2; j++, y += ch)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
942 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
943 // Reset string buffer and starting X coordinate
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
944 s.clear ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
945 hasChar = false;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
946 x = cx1 * cw;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
947
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
948 int charsThisLine = 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
949
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
950 for (int i = cx1; i <= cx2; i++)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
951 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
952 CHAR_INFO* ci = &(d->m_buffer[stride*j+i]);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
953
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
954 if ((ci->Attributes & 0x00ff) != attr)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
955 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
956 // Character attributes changed
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
957 if (! s.isEmpty ())
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
958 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
959 // String buffer not empty -> draw it
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
960 if (hasChar || (attr & 0x00f0))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
961 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
962 if (attr & 0x00f0)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
963 p.fillRect (x, y-ascent, s.length () * cw, ch,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
964 p.brush ());
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
965 p.drawText (x, y, s);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
966 }
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
967 int len = s.length ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
968 charsThisLine += len;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
969 x += (len * cw);
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
970 s.clear ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
971 hasChar = false;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
972 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
973 // Update current pen and store current attributes
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
974 // FIXME: what about background?
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
975 attr = (ci->Attributes & 0x00ff);
16474
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
976 p.setPen (d->m_colors[attr & 0x000f]);
720fd1ca04ec another attempt to fix windows command window colors
John W. Eaton <jwe@octave.org>
parents: 16405
diff changeset
977 p.setBrush (d->m_colors[(attr >> 4) & 0x000f]);
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
978 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
979
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
980 // Append current character to the string buffer
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
981 s.append (ci->Char.UnicodeChar);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
982 if (ci->Char.UnicodeChar != L' ')
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
983 hasChar = true;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
984 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
985
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
986 if (! s.isEmpty () && (hasChar || (attr & 0x00f0)))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
987 {
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
988 int len = s.length ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
989 charsThisLine += len;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
990
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
991 // Line end reached, but string buffer not empty -> draw it
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
992 // No need to update s or x, they will be reset on the next
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
993 // for-loop iteration
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
994
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
995 if (attr & 0x00f0)
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
996 p.fillRect (x, y-ascent, len * cw, ch, p.brush ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
997
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
998 p.drawText (x, y, s);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
999 }
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1000
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1001 if (haveSelection && j >= begin.y () && j <= end.y ())
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1002 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1003 int selectionBegin = j == begin.y () ? begin.x (): 0;
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1004
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1005 int len = ((j == end.y () && end.x () < charsThisLine)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1006 ? end.x () - selectionBegin + 1
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1007 : stride - selectionBegin);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1008
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1009 QColor selectionColor = d->m_colors[7];
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1010
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1011 p.save ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1012
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1013 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1014
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1015 p.fillRect (selectionBegin * cw, y-ascent, len * cw, ch,
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1016 selectionColor);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1017
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1018 p.restore ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1019 }
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1020 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1021
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1022 if (! d->m_cursorBlinking)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1023 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1024 QColor cursorColor = d->m_colors[7];
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1025 QRect cursorRect = d->cursorRect ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1026
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1027 p.setPen (d->m_foregroundColor);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1028
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1029 if (d->m_cursorType == QConsolePrivate::BlockCursor)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1030 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1031 if (hasFocus ())
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1032 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1033 p.setCompositionMode (QPainter::RasterOp_SourceXorDestination);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1034
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1035 p.fillRect (cursorRect, cursorColor);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1036 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1037 else
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1038 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1039 // draw the cursor outline, adjusting the area so that
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1040 // it is draw entirely inside 'rect'
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1041
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1042 int penWidth = qMax (1, p.pen().width());
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1043
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1044 p.setBrush (Qt::NoBrush);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1045
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1046 p.drawRect (cursorRect.adjusted (penWidth/2, penWidth/2,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1047 - penWidth/2 - penWidth%2,
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1048 - penWidth/2 - penWidth%2));
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1049 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1050 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1051 else if (d->m_cursorType == QConsolePrivate::UnderlineCursor)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1052 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1053 p.drawLine (cursorRect.left (), cursorRect.bottom (),
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1054 cursorRect.right (), cursorRect.bottom ());
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1055 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1056 else if (d->m_cursorType == QConsolePrivate::IBeamCursor)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1057 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1058 p.drawLine (cursorRect.left (), cursorRect.top (),
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1059 cursorRect.left (), cursorRect.bottom ());
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1060 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1061 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1062 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1063
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1064 void QWinTerminalImpl::blinkCursorEvent (void)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1065 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1066 if (d->m_hasBlinkingCursor)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1067 d->m_cursorBlinking = ! d->m_cursorBlinking;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1068 else
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1069 d->m_cursorBlinking = false;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1070
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1071 d->m_consoleView->update (d->cursorRect ());
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1072 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1073
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1074 void QWinTerminalImpl::setBlinkingCursor (bool blink)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1075 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1076 d->m_hasBlinkingCursor = blink;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1077
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1078 setBlinkingCursorState (blink);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1079 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1080
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1081 void QWinTerminalImpl::setBlinkingCursorState (bool blink)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1082 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1083 if (blink && ! d->m_blinkCursorTimer->isActive ())
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1084 d->m_blinkCursorTimer->start (d->BLINK_DELAY);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1085
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1086 if (! blink && d->m_blinkCursorTimer->isActive ())
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1087 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1088 d->m_blinkCursorTimer->stop ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1089
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1090 if (d->m_cursorBlinking)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1091 blinkCursorEvent ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1092 }
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1093 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1094
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1095 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1096
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1097 void QWinTerminalImpl::wheelEvent (QWheelEvent* event)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1098 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1099 if (! d->m_inWheelEvent)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1100 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1101 // Forward to the scrollbar (avoid recursion)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1102 d->m_inWheelEvent = true;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1103 QApplication::sendEvent (d->m_scrollBar, event);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1104 d->m_inWheelEvent = false;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1105 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1106 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1107
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1108 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1109
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1110 bool QWinTerminalImpl::winEvent (MSG* msg, long* result)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1111 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1112 switch (msg->message)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1113 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1114 case WM_KEYDOWN:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1115 case WM_KEYUP:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1116 //case WM_CHAR:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1117 // Forward Win32 message to the console window
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1118 PostMessage (d->m_consoleWindow,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1119 msg->message,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1120 msg->wParam,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1121 msg->lParam);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1122 result = 0;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1123 return true;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1124 default:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1125 return false;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1126 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1127 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1128
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1129 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1130
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1131 void QWinTerminalImpl::scrollValueChanged (int value)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1132 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1133 d->setScrollValue (value);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1134 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1135
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1136 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1137
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1138 void QWinTerminalImpl::monitorConsole (void)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1139 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1140 d->monitorConsole ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1141 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1142
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1143 void QWinTerminalImpl::updateSelection (void)
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1144 {
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1145 d->updateSelection ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1146 }
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1147
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1148 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1149
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1150 void QWinTerminalImpl::focusInEvent (QFocusEvent* event)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1151 {
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1152 setBlinkingCursorState (true);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1153
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1154 QWidget::focusInEvent (event);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1155 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1156
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1157 void QWinTerminalImpl::focusOutEvent (QFocusEvent* event)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1158 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1159 // Force the cursor to be redrawn.
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1160 d->m_cursorBlinking = true;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1161
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1162 setBlinkingCursorState (false);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1163
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1164 QWidget::focusOutEvent (event);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1165 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1166
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1167 void QWinTerminalImpl::keyPressEvent (QKeyEvent* event)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1168 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1169 if (d->m_hasBlinkingCursor)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1170 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1171 d->m_blinkCursorTimer->start (d->BLINK_DELAY);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1172
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1173 if (d->m_cursorBlinking)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1174 blinkCursorEvent ();
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1175 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1176
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1177 QWidget::keyPressEvent (event);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1178 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1179
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1180 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1181
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1182 void QWinTerminalImpl::start (void)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1183 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1184 d->startCommand ();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1185 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1186
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1187 //////////////////////////////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1188
15660
a6df0e2a082a Corrections for windows code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15658
diff changeset
1189 void QWinTerminalImpl::sendText (const QString& s)
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1190 {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1191 d->sendConsoleText (s);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1192 }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1193
16608
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1194 void QWinTerminalImpl::setCursorType (CursorType type, bool blinking)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1195 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1196 switch (type)
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1197 {
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1198 case UnderlineCursor:
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1199 d->m_cursorType = QConsolePrivate::UnderlineCursor;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1200 break;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1201
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1202 case BlockCursor:
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1203 d->m_cursorType = QConsolePrivate::BlockCursor;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1204 break;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1205
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1206 case IBeamCursor:
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1207 d->m_cursorType = QConsolePrivate::IBeamCursor;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1208 break;
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1209 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1210
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1211 setBlinkingCursor (blinking);
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1212 }
739d7eb97b85 make blinking cursor and different cursor styles for Windows GUI terminal
John W. Eaton <jwe@octave.org>
parents: 16513
diff changeset
1213
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1214 //////////////////////////////////////////////////////////////////////////////
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1215
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1216 void QWinTerminalImpl::setTerminalFont (const QFont& f)
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1217 {
15666
20299b92a64e Added patch that allows for changing the terminal font.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15665
diff changeset
1218 d->m_font = f;
20299b92a64e Added patch that allows for changing the terminal font.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15665
diff changeset
1219 d->m_consoleView->setFont (f);
20299b92a64e Added patch that allows for changing the terminal font.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 15665
diff changeset
1220 d->updateConsoleSize (true);
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1221 }
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1222
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1223 //////////////////////////////////////////////////////////////////////////////
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1224
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1225 void QWinTerminalImpl::setSize (int columns, int lines)
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1226 {
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1227 Q_UNUSED (columns);
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1228 Q_UNUSED (lines);
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1229 }
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1230
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1231 //////////////////////////////////////////////////////////////////////////////
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1232
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1233 void QWinTerminalImpl::copyClipboard (void)
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1234 {
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1235 QClipboard *clipboard = QApplication::clipboard ();
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1236
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1237 clipboard->setText (d->getSelection ());
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1238
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1239 d->clearSelection ();
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1240 }
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1241
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1242 //////////////////////////////////////////////////////////////////////////////
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1243
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1244 void QWinTerminalImpl::pasteClipboard (void)
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1245 {
16612
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1246 QString text = QApplication::clipboard()->text (QClipboard::Clipboard);
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1247
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1248 if (! text.isEmpty ())
dae674adf045 handle text selection in GUI terminal for Windows
John W. Eaton <jwe@octave.org>
parents: 16608
diff changeset
1249 sendText (text);
15662
5758e0013246 Enable compilation on Win32-native platform.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15660
diff changeset
1250 }