Mercurial > hg > octave-avbm
changeset 13882:b09321ab8464 gui
[Win32] Implement sendText capability in Win32 terminal widget.
* src/terminal/win32/QConsole.h (QConsole::sendText): New method.
* src/terminal/win32/QConsole.cpp (QConsole::sendText): Likewise.
(QConsolePrivate::sendConsoleText): Likewise, used in QConsole::sendText.
* src/WinTerminalView.cpp (WinTerminalView::sendText): Use it.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 17 Nov 2011 23:04:02 +0000 |
parents | e3066c972c6a |
children | 22e16fd68b8a |
files | gui/src/WinTerminalView.cpp gui/src/terminal/win32/QConsole.cpp gui/src/terminal/win32/QConsole.h |
diffstat | 3 files changed, 68 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
old mode 100644 new mode 100755 --- a/gui/src/WinTerminalView.cpp +++ b/gui/src/WinTerminalView.cpp @@ -26,7 +26,7 @@ { } -void WinTerminalView::sendText (const QString& /*txt*/) +void WinTerminalView::sendText (const QString& txt) { - // FIXME: implement this. + QConsole::sendText (txt); }
old mode 100644 new mode 100755 --- a/gui/src/terminal/win32/QConsole.cpp +++ b/gui/src/terminal/win32/QConsole.cpp @@ -97,6 +97,7 @@ void updateConsoleView (bool grab = true); void monitorConsole (void); void startCommand (void); + void sendConsoleText (const QString& s); void log (const char* fmt, ...); @@ -629,6 +630,62 @@ ////////////////////////////////////////////////////////////////////////////// +void QConsolePrivate::sendConsoleText (const QString& s) +{ + // Send the string in chunks of 512 characters. Each character is + // translated into an equivalent keypress event. + +#define TEXT_CHUNK_SIZE 512 + + int len = s.length (); + INPUT_RECORD events[TEXT_CHUNK_SIZE]; + DWORD nEvents = 0, written; + HANDLE hStdIn = GetStdHandle (STD_INPUT_HANDLE); + + ZeroMemory (events, sizeof (events)); + + for (int i = 0; i < len; i++) + { + QChar c = s.at (i); + + if (c == L'\r' || c == L'\n') + { + if (c == L'\r' && i < (len - 1) && s.at (i+1) == L'\n') + i++; + if (nEvents) + { + WriteConsoleInput (hStdIn, events, nEvents, &written); + nEvents = 0; + ZeroMemory (events, sizeof (events)); + } + PostMessage (m_consoleWindow, WM_KEYDOWN, VK_RETURN, 0x001C0001); + PostMessage (m_consoleWindow, WM_KEYDOWN, VK_RETURN, 0xC01C0001); + } + else + { + events[nEvents].EventType = KEY_EVENT; + events[nEvents].Event.KeyEvent.bKeyDown = TRUE; + events[nEvents].Event.KeyEvent.wRepeatCount = 1; + events[nEvents].Event.KeyEvent.wVirtualKeyCode = + LOBYTE (VkKeyScan (c.unicode ())); + events[nEvents].Event.KeyEvent.wVirtualScanCode = 0; + events[nEvents].Event.KeyEvent.uChar.UnicodeChar = c.unicode (); + events[nEvents].Event.KeyEvent.dwControlKeyState = 0; + nEvents++; + } + + if (nEvents == TEXT_CHUNK_SIZE + || (nEvents > 0 && i == (len - 1))) + { + WriteConsoleInput (hStdIn, events, nEvents, &written); + nEvents = 0; + ZeroMemory (events, sizeof (events)); + } + } +} + +////////////////////////////////////////////////////////////////////////////// + QConsole::QConsole (QWidget* parent) : d (new QConsolePrivate (this)) { @@ -807,3 +864,10 @@ { d->startCommand (); } + +////////////////////////////////////////////////////////////////////////////// + +void QConsole::sendText (const QString& s) +{ + d->sendConsoleText (s); +}
old mode 100644 new mode 100755 --- a/gui/src/terminal/win32/QConsole.h +++ b/gui/src/terminal/win32/QConsole.h @@ -48,6 +48,8 @@ QConsole (const QString& cmd, QWidget* parent = 0); ~QConsole (void); + void sendText (const QString& s); + signals: void terminated (void); void titleChanged (const QString&);