author | ibotty <ibotty> | 2002-10-09 17:40:35 (UTC) |
---|---|---|
committer | ibotty <ibotty> | 2002-10-09 17:40:35 (UTC) |
commit | c80818d8388c07c1606a70306aea0c9a1e17ea3c (patch) (side-by-side diff) | |
tree | c010af190b398b698299a42ce06217c950d6525d | |
parent | e0b4cca74ec611583c38901a83c448592e8ebec6 (diff) | |
download | opie-c80818d8388c07c1606a70306aea0c9a1e17ea3c.zip opie-c80818d8388c07c1606a70306aea0c9a1e17ea3c.tar.gz opie-c80818d8388c07c1606a70306aea0c9a1e17ea3c.tar.bz2 |
updated emulationLayer to use WidgetLayer (not Widget, which is b0rked)
default.cpp is broken, because there is still no new widget (coming
soon...)
-rw-r--r-- | noncore/apps/opie-console/common.h | 10 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_layer.cpp | 34 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_layer.h | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/screen.cpp | 16 | ||||
-rw-r--r-- | noncore/apps/opie-console/screen.h | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/vt102emulation.cpp | 18 | ||||
-rw-r--r-- | noncore/apps/opie-console/vt102emulation.h | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 11 |
8 files changed, 57 insertions, 44 deletions
diff --git a/noncore/apps/opie-console/common.h b/noncore/apps/opie-console/common.h index 979c2bd..a621ff5 100644 --- a/noncore/apps/opie-console/common.h +++ b/noncore/apps/opie-console/common.h @@ -1,56 +1,56 @@ /* -------------------------------------------------------------------------- */ /* */ -/* [TECommon.h] Common Definitions */ +/* [Common.h] Common Definitions */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ /* */ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ -/*! \file TECommon.h +/*! \file Common.h \brief Definitions shared between TEScreen and TEWidget. */ -#ifndef TECOMMON_H -#define TECOMMON_H +#ifndef COMMON_H +#define COMMON_H #include <qcolor.h> #ifndef BOOL typedef bool BOOL; #endif #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #ifndef UINT8 typedef unsigned char UINT8; #endif #ifndef UINT16 typedef unsigned short UINT16; #endif // Attributed Character Representations /////////////////////////////// // Colors #define BASE_COLORS (2+8) #define INTENSITIES 2 #define TABLE_COLORS (INTENSITIES*BASE_COLORS) #define DEFAULT_FORE_COLOR 0 @@ -82,33 +82,33 @@ public: UINT8 r; // rendition public: friend BOOL operator == (Character a, Character b); friend BOOL operator != (Character a, Character b); }; inline BOOL operator == (Character a, Character b) { return a.c == b.c && a.f == b.f && a.b == b.b && a.r == b.r; } inline BOOL operator != (Character a, Character b) { return a.c != b.c || a.f != b.f || a.b != b.b || a.r != b.r; } /*! */ struct ColorEntry { ColorEntry(QColor c, bool tr, bool b) : color(c), transparent(tr), bold(b) {} ColorEntry() : transparent(false), bold(false) {} // default constructors void operator=(const ColorEntry& rhs) { color = rhs.color; transparent = rhs.transparent; bold = rhs.bold; } QColor color; bool transparent; // if used on bg bool bold; // if used on fg }; -#endif // TECOMMON_H +#endif // COMMON_H diff --git a/noncore/apps/opie-console/emulation_layer.cpp b/noncore/apps/opie-console/emulation_layer.cpp index 6c420e0..5baf05c 100644 --- a/noncore/apps/opie-console/emulation_layer.cpp +++ b/noncore/apps/opie-console/emulation_layer.cpp @@ -47,110 +47,110 @@ in slowing down the overall performance of emulations. Displaying individual characters using X11 creates a lot of overhead. Second, by using the following refreshing method, the screen operations can be completely separated from the displaying. This greatly simplifies the programmer's task of coding and maintaining the screen operations, since one need not worry about differential modifications on the display affecting the operation of concern. We use a refreshing algorithm here that has been adoped from rxvt/kvt. By this, refreshing is driven by a timer, which is (re)started whenever a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'. As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger refresh. This rule suits both bulk display operation as done by curses as well as individual characters typed. (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). Additionally, we trigger refreshing by newlines comming in to make visual snapshots of lists as produced by `cat', `ls' and likely programs, thereby producing the illusion of a permanent and immediate display operation. As a sort of catch-all needed for cases where none of the above conditions catch, the screen refresh is also triggered by a count of incoming bulks (`bulk_incnt'). */ /* FIXME - evtl. the bulk operations could be made more transparent. */ #include "emulation_layer.h" -#include "widget.h" +#include "widget_layer.h" #include "screen.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <qkeycode.h> /* ------------------------------------------------------------------------- */ /* */ /* EmulationLayer */ /* */ /* ------------------------------------------------------------------------- */ #define CNTL(c) ((c)-'@') /*! */ -EmulationLayer::EmulationLayer(Widget* gui) +EmulationLayer::EmulationLayer( WidgetLayer* gui ) : decoder((QTextDecoder*)NULL) { this->gui = gui; - screen[0] = new Screen(gui->Lines(),gui->Columns()); - screen[1] = new Screen(gui->Lines(),gui->Columns()); + screen[0] = new Screen(gui->lines(),gui->columns()); + screen[1] = new Screen(gui->lines(),gui->columns()); scr = screen[0]; bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter connected = FALSE; QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) ); - QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)), + QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), this,SLOT(onImageSizeChange(int,int))); QObject::connect(gui,SIGNAL(changedHistoryCursor(int)), - this,SLOT(onHistoryCursorChange(int))); - QObject::connect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)), + this,SLOT( historyCursorChange( int ) ) ); + QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), this,SLOT(onKeyPress(QKeyEvent*))); - QObject::connect(gui,SIGNAL(beginSelectionSignal(const int,const int)), + QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), this,SLOT(onSelectionBegin(const int,const int)) ); - QObject::connect(gui,SIGNAL(extendSelectionSignal(const int,const int)), + QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), this,SLOT(onSelectionExtend(const int,const int)) ); - QObject::connect(gui,SIGNAL(endSelectionSignal(const BOOL)), - this,SLOT(setSelection(const BOOL)) ); - QObject::connect(gui,SIGNAL(clearSelectionSignal()), + QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), + this,SLOT( setSelection( const bool ) ) ); + QObject::connect(gui,SIGNAL( selectionCleared() ), this,SLOT(clearSelection()) ); } /*! */ EmulationLayer::~EmulationLayer() { delete screen[0]; delete screen[1]; bulk_timer.stop(); } /*! change between primary and alternate screen */ void EmulationLayer::setScreen(int n) { scr = screen[n&1]; } void EmulationLayer::setHistory(bool on) { screen[0]->setScroll(on); if (!connected) return; showBulk(); } bool EmulationLayer::history() { return screen[0]->hasScroll(); } @@ -168,65 +168,65 @@ void EmulationLayer::setKeytrans(int no) { keytrans = KeyTrans::find(no); } void EmulationLayer::setKeytrans(const char * no) { keytrans = KeyTrans::find(no); } // Interpreting Codes --------------------------------------------------------- /* This section deals with decoding the incoming character stream. Decoding means here, that the stream is first seperated into `tokens' which are then mapped to a `meaning' provided as operations by the `Screen' class. */ /*! */ void EmulationLayer::onRcvChar(int c) // process application unicode input to terminal // this is a trivial scanner { c &= 0xff; switch (c) { case '\b' : scr->BackSpace(); break; case '\t' : scr->Tabulate(); break; case '\n' : scr->NewLine(); break; case '\r' : scr->Return(); break; - case 0x07 : gui->Bell(); break; + case 0x07 : gui->bell(); break; default : scr->ShowCharacter(c); break; }; } /* ------------------------------------------------------------------------- */ /* */ /* Keyboard Handling */ /* */ /* ------------------------------------------------------------------------- */ /*! */ void EmulationLayer::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); if (!ev->text().isEmpty()) { // A block of text // Note that the text is proper unicode. // We should do a conversion here, but since this // routine will never be used, we simply emit plain ascii. sendString( ev->text().ascii() ); //,ev->text().length()); } else if (ev->ascii()>0) { QByteArray c = QByteArray( 1 ); c.at( 0 ) = ev->ascii(); // ibot: qbytearray is emited not char* emit sndBlock( (QByteArray) c ); } @@ -274,93 +274,93 @@ void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { if (!t.isNull()) gui->setSelection(t); } void EmulationLayer::clearSelection() { if (!connected) return; scr->clearSelection(); showBulk(); } // Refreshing -------------------------------------------------------------- -- #define BULK_TIMEOUT 20 /*! called when \n comes in. Evtl. triggers showBulk at endBulk */ void EmulationLayer::bulkNewline() { bulk_nlcnt += 1; bulk_incnt = 0; // reset bulk counter since `nl' rule applies } /*! */ void EmulationLayer::showBulk() { bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter if (connected) { - Character* image = scr->getCookedImage(); // get the image + QArray<Character> image = scr->getCookedImage(); // get the image gui->setImage(image, scr->getLines(), scr->getColumns()); // actual refresh - free(image); + delete image; //FIXME: check that we do not trigger other draw event here. gui->setScroll(scr->getHistCursor(),scr->getHistLines()); } } void EmulationLayer::bulkStart() { if (bulk_timer.isActive()) bulk_timer.stop(); } void EmulationLayer::bulkEnd() { - if ( bulk_nlcnt > gui->Lines() || bulk_incnt > 20 ) + if ( bulk_nlcnt > gui->lines() || bulk_incnt > 20 ) showBulk(); // resets bulk_??cnt to 0, too. else bulk_timer.start(BULK_TIMEOUT,TRUE); } void EmulationLayer::setConnect(bool c) { connected = c; if ( connected) { - onImageSizeChange(gui->Lines(), gui->Columns()); + onImageSizeChange(gui->lines(), gui->columns()); showBulk(); } else { scr->clearSelection(); } } // --------------------------------------------------------------------------- /*! triggered by image size change of the Widget `gui'. This event is simply propagated to the attached screens and to the related serial line. */ void EmulationLayer::onImageSizeChange(int lines, int columns) { if (!connected) return; screen[0]->resizeImage(lines,columns); screen[1]->resizeImage(lines,columns); showBulk(); emit ImageSizeChanged(lines,columns); // propagate event to serial line } void EmulationLayer::onHistoryCursorChange(int cursor) { if (!connected) return; scr->setHistCursor(cursor); showBulk(); } diff --git a/noncore/apps/opie-console/emulation_layer.h b/noncore/apps/opie-console/emulation_layer.h index 5781acc..91a4856 100644 --- a/noncore/apps/opie-console/emulation_layer.h +++ b/noncore/apps/opie-console/emulation_layer.h @@ -9,133 +9,133 @@ /* This file is part of Konsole - an X terminal for KDE */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* */ /* made to a layer between io_layer and widget */ /* */ /* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ /* */ /* -------------------------------------------------------------------------- */ #ifndef EMULATION_LAYER_H #define EMULATION_LAYER_H #include "widget_layer.h" #include "screen.h" #include <qtimer.h> #include <stdio.h> #include <qtextcodec.h> #include "keytrans.h" class EmulationLayer : public QObject { Q_OBJECT public: - EmulationLayer(Widget* gui); + EmulationLayer( WidgetLayer* gui ); ~EmulationLayer(); public: virtual void setHistory(bool on); virtual bool history(); public slots: // signals incoming from Widget virtual void onImageSizeChange(int lines, int columns); virtual void onHistoryCursorChange(int cursor); virtual void onKeyPress(QKeyEvent*); virtual void clearSelection(); virtual void onSelectionBegin(const int x, const int y); virtual void onSelectionExtend(const int x, const int y); - virtual void setSelection(const BOOL preserve_line_breaks); + virtual void setSelection(const bool preserve_line_breaks); public slots: // signals incoming from data source /** * to be called, when new data arrives */ void onRcvBlock(const QByteArray&); signals: /** * will send data, encoded to suit emulation */ void sndBlock(const QByteArray&); void ImageSizeChanged(int lines, int columns); void changeColumns(int columns); void changeTitle(int arg, const char* str); public: /** * process single char (decode) */ virtual void onRcvChar(int); virtual void setMode (int) = 0; virtual void resetMode(int) = 0; /** * @deprecated use qbytearray instead */ virtual void sendString(const char*) = 0; /** * sends a string to IOLayer * encodes to suit emulation before */ virtual void sendString(const QByteArray&) = 0; virtual void setConnect(bool r); void setColumns(int columns); void setKeytrans(int no); void setKeytrans(const char * no); protected: - Widget* gui; + WidgetLayer* gui; Screen* scr; // referes to one `screen' Screen* screen[2]; // 0 = primary, 1 = alternate void setScreen(int n); // set `scr' to `screen[n]' bool connected; // communicate with widget void setCodec(int c); // codec number, 0 = locale, 1=utf8 QTextCodec* codec; QTextCodec* localeCodec; QTextDecoder* decoder; KeyTrans* keytrans; // refreshing related material. // this is localized in the class. private slots: // triggered by timer void showBulk(); private: void bulkNewline(); void bulkStart(); void bulkEnd(); private: QTimer bulk_timer; int bulk_nlcnt; // bulk newline counter char* SelectedText; int bulk_incnt; // bulk counter diff --git a/noncore/apps/opie-console/screen.cpp b/noncore/apps/opie-console/screen.cpp index 8ebc47d..a796ba1 100644 --- a/noncore/apps/opie-console/screen.cpp +++ b/noncore/apps/opie-console/screen.cpp @@ -39,79 +39,79 @@ it is a little more complex bejond this. See the header file of the class. \sa TEWidget \sa VT102Emulation */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> // #include <kdebug.h> #include <assert.h> #include <string.h> #include <ctype.h> #include "screen.h" #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) //FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. //FIXME: see if we can get this from terminfo. #define BS_CLEARS FALSE #define loc(X,Y) ((Y)*columns+(X)) /*! creates a `Screen' of `lines' lines and `columns' columns. */ Screen::Screen(int lines, int columns) { this->lines = lines; this->columns = columns; - image = (Character*) malloc(lines*columns*sizeof(Character)); + image = QArray<Character>( lines*columns ); tabstops = NULL; initTabStops(); histCursor = 0; clearSelection(); reset(); } /*! Destructor */ Screen::~Screen() { - free(image); + delete image; if (tabstops) free(tabstops); } /* ------------------------------------------------------------------------- */ /* */ /* Normalized Screen Operations */ /* */ /* ------------------------------------------------------------------------- */ // Cursor Setting -------------------------------------------------------------- /*! \section Cursor The `cursor' is a location within the screen that is implicitely used in many operations. The operations within this section allow to manipulate the cursor explicitly and to obtain it's value. The position of the cursor is guarantied to be between (including) 0 and `columns-1' and `lines-1'. */ /*! Move the cursor up. The cursor will not be moved beyond the top margin. */ void Screen::cursorUp(int n) //=CUU { if (n == 0) n = 1; // Default int stop = cuY < tmargin ? 0 : tmargin; @@ -365,89 +365,89 @@ void Screen::restoreCursor() effectiveRendition(); } /* ------------------------------------------------------------------------- */ /* */ /* Screen Operations */ /* */ /* ------------------------------------------------------------------------- */ /*! Assing a new size to the screen. The topmost left position is maintained, while lower lines or right hand side columns might be removed or filled with spaces to fit the new size. The region setting is reset to the whole screen and the tab positions reinitialized. */ void Screen::resizeImage(int new_lines, int new_columns) { if (cuY > new_lines-1) { // attempt to preserve focus and lines bmargin = lines-1; //FIXME: margin lost for (int i = 0; i < cuY-(new_lines-1); i++) { addHistLine(); scrollUp(0,1); } } // make new image - Character* newimg = (Character*) malloc(new_lines*new_columns*sizeof(Character)); + QArray<Character> newimg = QArray<Character>( new_lines * new_columns ); clearSelection(); // clear new image for (int y = 0; y < new_lines; y++) for (int x = 0; x < new_columns; x++) { newimg[y*new_columns+x].c = ' '; newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; newimg[y*new_columns+x].r = DEFAULT_RENDITION; } int cpy_lines = QMIN(new_lines, lines); int cpy_columns = QMIN(new_columns,columns); // copy to new image for (int y = 0; y < cpy_lines; y++) for (int x = 0; x < cpy_columns; x++) { newimg[y*new_columns+x].c = image[loc(x,y)].c; newimg[y*new_columns+x].f = image[loc(x,y)].f; newimg[y*new_columns+x].b = image[loc(x,y)].b; newimg[y*new_columns+x].r = image[loc(x,y)].r; } - free(image); + delete image; image = newimg; lines = new_lines; columns = new_columns; cuX = QMIN(cuX,columns-1); cuY = QMIN(cuY,lines-1); // FIXME: try to keep values, evtl. tmargin=0; bmargin=lines-1; initTabStops(); clearSelection(); } /* Clarifying rendition here and in TEWidget. currently, TEWidget's color table is 0 1 2 .. 9 10 .. 17 dft_fg, dft_bg, dim 0..7, intensive 0..7 cu_fg, cu_bg contain values 0..8; - 0 = default color - 1..8 = ansi specified color re_fg, re_bg contain values 0..17 due to the TEWidget's color table rendition attributes are attr widget screen -------------- ------ ------ RE_UNDERLINE XX XX affects foreground only @@ -475,108 +475,110 @@ void Screen::effectiveRendition() // calculate rendition { ef_re = cu_re & (RE_UNDERLINE | RE_BLINK); if (cu_re & RE_REVERSE) { ef_fg = cu_bg; ef_bg = cu_fg; } else { ef_fg = cu_fg; ef_bg = cu_bg; } if (cu_re & RE_BOLD) { if (ef_fg < BASE_COLORS) ef_fg += BASE_COLORS; else ef_fg -= BASE_COLORS; } } /*! returns the image. Get the size of the image by \sa getLines and \sa getColumns. NOTE that the image returned by this function must later be freed. */ -Character* Screen::getCookedImage() +QArray<Character> Screen::getCookedImage() { int x,y; Character* merged = (Character*) malloc(lines*columns*sizeof(Character)); Character dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) { int len = QMIN(columns,hist.getLineLen(y+histCursor)); int yp = y*columns; int yq = (y+histCursor)*columns; hist.getCells(y+histCursor,0,len,merged+yp); for (x = len; x < columns; x++) merged[yp+x] = dft; for (x = 0; x < columns; x++) { int p=x + yp; int q=x + yq; if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) reverseRendition(&merged[p]); // for selection } } if (lines >= hist.getLines()-histCursor) { for (y = (hist.getLines()-histCursor); y < lines ; y++) { int yp = y*columns; int yq = (y+histCursor)*columns; int yr = (y-hist.getLines()+histCursor)*columns; for (x = 0; x < columns; x++) { int p = x + yp; int q = x + yq; int r = x + yr; merged[p] = image[r]; if ( q >= sel_TL && q <= sel_BR ) reverseRendition(&merged[p]); // for selection } } } // evtl. inverse display if (getMode(MODE_Screen)) { int i,n = lines*columns; for (i = 0; i < n; i++) reverseRendition(&merged[i]); // for reverse display } if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); - return merged; + QArray<Character> res( sizeof( merged ) / sizeof( Character ) ); + res.assign( merged, sizeof( merged ) / sizeof( Character ) ); + return res; } /*! */ void Screen::reset() { setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke setMode(MODE_Cursor); // cursor visible resetMode(MODE_Screen); // screen not inverse resetMode(MODE_NewLine); tmargin=0; bmargin=lines-1; setDefaultRendition(); saveCursor(); clear(); } /*! Clear the entire screen and home the cursor. */ void Screen::clear() { clearEntireScreen(); home(); } @@ -1130,65 +1132,65 @@ cases: FIXME: * this suppresses \n for command output that is sized to the exact column width of the screen. 2) eol%columns == 0 --> blank line. insert a \n unconditionally. Do it either you would because you are in preserve_line_break mode, or because it's an ASCII paragraph delimiter, so even when not preserving line_breaks, you want to preserve paragraph breaks. 3) else --> partially filled line insert a \n in preserve line break mode, else a space The space prevents concatenation of the last word of one line with the first of the next. */ void Screen::addHistLine() { assert(hasScroll() || histCursor == 0); // add to hist buffer // we have to take care about scrolling, too... if (hasScroll()) { Character dft; int end = columns-1; while (end >= 0 && image[end] == dft) end -= 1; - hist.addCells(image,end+1); + hist.addCells(image.data(), end+1); hist.addLine(); // adjust history cursor histCursor += (hist.getLines()-1 == histCursor); } if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround } void Screen::setHistCursor(int cursor) { histCursor = cursor; //FIXME:rangecheck } int Screen::getHistCursor() { return histCursor; } int Screen::getHistLines() { return hist.getLines(); } void Screen::setScroll(bool on) { histCursor = 0; clearSelection(); hist.setScroll(on); } bool Screen::hasScroll() diff --git a/noncore/apps/opie-console/screen.h b/noncore/apps/opie-console/screen.h index cd7422a..38b84ab 100644 --- a/noncore/apps/opie-console/screen.h +++ b/noncore/apps/opie-console/screen.h @@ -107,122 +107,122 @@ public: // these are all `Screen' operations void helpAlign (); // // ------------------------------------- // void setRendition (int rendition); void resetRendition(int rendition); void setForeColor (int fgcolor); void setBackColor (int bgcolor); // void setDefaultRendition(); void setForeColorToDefault(); void setBackColorToDefault(); // // ------------------------------------- // BOOL getMode (int n); // // only for report cursor position // int getCursorX(); int getCursorY(); // // ------------------------------------- // void clear(); void home(); void reset(); // void ShowCharacter(unsigned short c); // void resizeImage(int new_lines, int new_columns); // - Character* getCookedImage(); + QArray<Character> getCookedImage(); /*! return the number of lines. */ int getLines() { return lines; } /*! return the number of columns. */ int getColumns() { return columns; } /*! set the position of the history cursor. */ void setHistCursor(int cursor); /*! return the position of the history cursor. */ int getHistCursor(); int getHistLines (); void setScroll(bool on); bool hasScroll(); // // Selection // void setSelBeginXY(const int x, const int y); void setSelExtentXY(const int x, const int y); void clearSelection(); QString getSelText(const BOOL preserve_line_breaks); void checkSelection(int from, int to); private: // helper void clearImage(int loca, int loce, char c); void moveImage(int dst, int loca, int loce); void scrollUp(int from, int i); void scrollDown(int from, int i); void addHistLine(); void initTabStops(); void effectiveRendition(); void reverseRendition(Character* p); private: /* The state of the screen is more complex as one would expect first. The screem does really do part of the emulation providing state informations in form of modes, margins, tabulators, cursor etc. Even more unexpected are variables to save and restore parts of the state. */ // screen image ---------------- int lines; int columns; - Character *image; // [lines][columns] + QArray<Character> image; // [lines][columns] // history buffer --------------- int histCursor; // display position relative to start of the history buffer HistoryScroll hist; // cursor location int cuX; int cuY; // cursor color and rendition info UINT8 cu_fg; // foreground UINT8 cu_bg; // background UINT8 cu_re; // rendition // margins ---------------- int tmargin; // top margin int bmargin; // bottom margin // states ---------------- ScreenParm currParm; // ---------------------------- bool* tabstops; // selection ------------------- diff --git a/noncore/apps/opie-console/vt102emulation.cpp b/noncore/apps/opie-console/vt102emulation.cpp index 2220f4e..7eecef3 100644 --- a/noncore/apps/opie-console/vt102emulation.cpp +++ b/noncore/apps/opie-console/vt102emulation.cpp @@ -36,65 +36,65 @@ /* VT102 Terminal Emulation This class puts together the screens, the pty and the widget to a complete terminal emulation. Beside combining it's componentes, it handles the emulations's protocol. This module consists of the following sections: - Constructor/Destructor - Incoming Bytes Event pipeline - Outgoing Bytes - Mouse Events - Keyboard Events - Modes and Charset State - Diagnostics */ /* ------------------------------------------------------------------------- */ /* */ /* Constructor / Destructor */ /* */ /* ------------------------------------------------------------------------- */ /* Nothing really intesting happens here. */ /*! */ -Vt102Emulation::Vt102Emulation(Widget* gui) : EmulationLayer(gui) +Vt102Emulation::Vt102Emulation(WidgetLayer* gui) : EmulationLayer(gui) { QObject::connect(gui,SIGNAL(mouseSignal(int,int,int)), this,SLOT(onMouse(int,int,int))); initTokenizer(); reset(); } /*! */ Vt102Emulation::~Vt102Emulation() { } /*! */ void Vt102Emulation::reset() { resetToken(); resetModes(); resetCharset(0); screen[0]->reset(); resetCharset(1); screen[0]->reset(); setCodec(0); setKeytrans("linux.keytab"); } /* ------------------------------------------------------------------------- */ /* */ /* Processing the incoming byte stream */ /* */ /* ------------------------------------------------------------------------- */ @@ -320,65 +320,65 @@ void Vt102Emulation::XtermHack() the current screen, or of the emulation class itself. The token to be interpreteted comes in as a machine word possibly accompanied by two parameters. Likewise, the operations assigned to, come with up to two arguments. One could consider to make up a proper table from the function below. The technical reference manual provides more informations about this mapping. */ void Vt102Emulation::tau( int token, int p, int q ) { //scan_buffer_report(); //if (token == TY_CHR___()) printf("%c",p); else //printf("tau(%d,%d,%d, %d,%d)\n",(token>>0)&0xff,(token>>8)&0xff,(token>>16)&0xffff,p,q); switch (token) { case TY_CHR___( ) : scr->ShowCharacter (p ); break; //UTF16 // 127 DEL : ignored on input case TY_CTL___('@' ) : /* NUL: ignored */ break; case TY_CTL___('A' ) : /* SOH: ignored */ break; case TY_CTL___('B' ) : /* STX: ignored */ break; case TY_CTL___('C' ) : /* ETX: ignored */ break; case TY_CTL___('D' ) : /* EOT: ignored */ break; case TY_CTL___('E' ) : reportAnswerBack ( ); break; //VT100 case TY_CTL___('F' ) : /* ACK: ignored */ break; - case TY_CTL___('G' ) : gui->Bell ( ); break; //VT100 + case TY_CTL___('G' ) : gui->bell ( ); break; //VT100 case TY_CTL___('H' ) : scr->BackSpace ( ); break; //VT100 case TY_CTL___('I' ) : scr->Tabulate ( ); break; //VT100 case TY_CTL___('J' ) : scr->NewLine ( ); break; //VT100 case TY_CTL___('K' ) : scr->NewLine ( ); break; //VT100 case TY_CTL___('L' ) : scr->NewLine ( ); break; //VT100 case TY_CTL___('M' ) : scr->Return ( ); break; //VT100 case TY_CTL___('N' ) : useCharset ( 1); break; //VT100 case TY_CTL___('O' ) : useCharset ( 0); break; //VT100 case TY_CTL___('P' ) : /* DLE: ignored */ break; case TY_CTL___('Q' ) : /* DC1: XON continue */ break; //VT100 case TY_CTL___('R' ) : /* DC2: ignored */ break; case TY_CTL___('S' ) : /* DC3: XOFF halt */ break; //VT100 case TY_CTL___('T' ) : /* DC4: ignored */ break; case TY_CTL___('U' ) : /* NAK: ignored */ break; case TY_CTL___('V' ) : /* SYN: ignored */ break; case TY_CTL___('W' ) : /* ETB: ignored */ break; case TY_CTL___('X' ) : scr->ShowCharacter ( 0x2592); break; //VT100 case TY_CTL___('Y' ) : /* EM : ignored */ break; case TY_CTL___('Z' ) : scr->ShowCharacter ( 0x2592); break; //VT100 case TY_CTL___('[' ) : /* ESC: cannot be seen here. */ break; case TY_CTL___('\\' ) : /* FS : ignored */ break; case TY_CTL___(']' ) : /* GS : ignored */ break; case TY_CTL___('^' ) : /* RS : ignored */ break; case TY_CTL___('_' ) : /* US : ignored */ break; case TY_ESC___('D' ) : scr->index ( ); break; //VT100 case TY_ESC___('E' ) : scr->NextLine ( ); break; //VT100 case TY_ESC___('H' ) : scr->changeTabStop (TRUE ); break; //VT100 case TY_ESC___('M' ) : scr->reverseIndex ( ); break; //VT100 case TY_ESC___('Z' ) : reportTerminalType ( ); break; @@ -708,69 +708,69 @@ void Vt102Emulation::onMouse( int cb, int cx, int cy ) #define encodeMode(M,B) BITS(B,getMode(M)) #define encodeStat(M,B) BITS(B,((ev->state() & (M)) == (M))) /* Keyboard event handling has been simplified somewhat by pushing the complications towards a configuration file [see KeyTrans class]. */ void Vt102Emulation::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys //printf("State/Key: 0x%04x 0x%04x (%d,%d)\n",ev->state(),ev->key(),ev->text().length(),ev->text().length()?ev->text().ascii()[0]:0); // revert to non-history when typing if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); // lookup in keyboard translation table ... int cmd; const char* txt; int len; if (keytrans->findEntry(ev->key(), encodeMode(MODE_NewLine , BITS_NewLine ) + // OLD, encodeMode(MODE_Ansi , BITS_Ansi ) + // OBSOLETE, encodeMode(MODE_AppCuKeys, BITS_AppCuKeys ) + // VT100 stuff encodeStat(ControlButton , BITS_Control ) + encodeStat(ShiftButton , BITS_Shift ) + encodeStat(AltButton , BITS_Alt ), &cmd, &txt, &len )) //printf("cmd: %d, %s, %d\n",cmd,txt,len); { switch(cmd) // ... and execute if found. { - case CMD_emitSelection : gui->emitSelection(); return; - case CMD_scrollPageUp : gui->doScroll(-gui->Lines()/2); return; - case CMD_scrollPageDown : gui->doScroll(+gui->Lines()/2); return; - case CMD_scrollLineUp : gui->doScroll(-1 ); return; - case CMD_scrollLineDown : gui->doScroll(+1 ); return; + case CMD_emitSelection : gui->insertSelection(); return; + case CMD_scrollPageUp : gui->scroll(-gui->lines()/2); return; + case CMD_scrollPageDown : gui->scroll(+gui->lines()/2); return; + case CMD_scrollLineUp : gui->scroll(-1 ); return; + case CMD_scrollLineDown : gui->scroll(+1 ); return; case CMD_send : sendString( txt ); return; case CMD_prevSession : emit prevSession(); return; case CMD_nextSession : emit nextSession(); return; } } // fall back handling if (!ev->text().isEmpty()) { if (ev->state() & AltButton) sendString("\033"); // ESC, this is the ALT prefix /// very hacky if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='A')) sendString("\01"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='B')) sendString("\02"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='C')) sendString("\03"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='D')) sendString("\04"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='E')) sendString("\05"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='F')) sendString("\06"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='G')) sendString("\07"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='H')) sendString("\010"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='I')) sendString("\011"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='J')) sendString("\012"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='K')) sendString("\013"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='L')) sendString("\014"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='M')) sendString("\015"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='N')) sendString("\016"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='O')) sendString("\017"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='P')) sendString("\020"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='Q')) sendString("\021"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='R')) sendString("\022"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='S')) sendString("\023"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='T')) sendString("\024"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='U')) sendString("\025"); else if ((ev->state() & ControlButton) && (ev->text().upper().ascii()[0]=='V')) sendString("\026"); @@ -895,84 +895,84 @@ void Vt102Emulation::restoreCursor() /* */ /* ------------------------------------------------------------------------- */ /* Some of the emulations state is either added to the state of the screens. This causes some scoping problems, since different emulations choose to located the mode either to the current screen or to both. For strange reasons, the extend of the rendition attributes ranges over all screens and not over the actual screen. We decided on the precise precise extend, somehow. */ // "Mode" related part of the state. These are all booleans. void Vt102Emulation::resetModes() { resetMode(MODE_Mouse1000); saveMode(MODE_Mouse1000); resetMode(MODE_AppScreen); saveMode(MODE_AppScreen); // here come obsolete modes resetMode(MODE_AppCuKeys); saveMode(MODE_AppCuKeys); resetMode(MODE_NewLine ); setMode(MODE_Ansi ); } void Vt102Emulation::setMode(int m) { currParm.mode[m] = TRUE; switch (m) { - case MODE_Mouse1000 : gui->setMouseMarks(FALSE); + case MODE_Mouse1000 : //gui->setMouseMarks(FALSE); break; case MODE_AppScreen : screen[1]->clearSelection(); screen[1]->clearEntireScreen(); setScreen(1); break; } if (m < MODES_SCREEN || m == MODE_NewLine) { screen[0]->setMode(m); screen[1]->setMode(m); } } void Vt102Emulation::resetMode(int m) { currParm.mode[m] = FALSE; switch (m) { - case MODE_Mouse1000 : gui->setMouseMarks(TRUE); + case MODE_Mouse1000 : //gui->setMouseMarks(TRUE); break; case MODE_AppScreen : screen[0]->clearSelection(); setScreen(0); break; } if (m < MODES_SCREEN || m == MODE_NewLine) { screen[0]->resetMode(m); screen[1]->resetMode(m); } } void Vt102Emulation::saveMode(int m) { saveParm.mode[m] = currParm.mode[m]; } void Vt102Emulation::restoreMode(int m) { if(saveParm.mode[m]) setMode(m); else resetMode(m); } BOOL Vt102Emulation::getMode(int m) { return currParm.mode[m]; } void Vt102Emulation::setConnect(bool c) { EmulationLayer::setConnect(c); if (c) { // refresh mouse mode diff --git a/noncore/apps/opie-console/vt102emulation.h b/noncore/apps/opie-console/vt102emulation.h index a3d0ae6..de4a62f 100644 --- a/noncore/apps/opie-console/vt102emulation.h +++ b/noncore/apps/opie-console/vt102emulation.h @@ -31,65 +31,65 @@ #include <stdio.h> // #define MODE_AppScreen (MODES_SCREEN+0) #define MODE_AppCuKeys (MODES_SCREEN+1) #define MODE_AppKeyPad (MODES_SCREEN+2) #define MODE_Mouse1000 (MODES_SCREEN+3) #define MODE_Ansi (MODES_SCREEN+4) #define MODE_total (MODES_SCREEN+5) struct DECpar { BOOL mode[MODE_total]; }; struct CharCodes { // coding info char charset[4]; // int cu_cs; // actual charset. bool graphic; // Some VT100 tricks bool pound ; // Some VT100 tricks bool sa_graphic; // saved graphic bool sa_pound; // saved pound }; class Vt102Emulation: public EmulationLayer { Q_OBJECT public: - Vt102Emulation(Widget* gui); + Vt102Emulation(WidgetLayer* gui); ~Vt102Emulation(); public slots: // signals incoming from Widget void onKeyPress(QKeyEvent*); void onMouse(int cb, int cx, int cy); signals: void changeTitle(int,const QString&); void prevSession(); void nextSession(); public: void reset(); /** * receive a char from IOLayer */ void onRcvChar(int cc); /** * sends a list of bytes to the IOLayer */ void sendString(const QByteArray&); /** * @deprecated use QByteArray instead * see sendString() above */ void sendString(const char *); diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h index 6e2e61e..5bd2ef9 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h @@ -77,64 +77,75 @@ public: */ int columns() { return m_columns; } /** * insert current selection (currently this is only the clipboard) */ void insertSelection(); /** * insert text * @param QString text, the text to be inserted */ void insertText( QString text ); /** * set selection (clipboard) to text * @param const QString &text, the text to be selected */ void setSelection( const QString &text ); /** * paste content of clipboard */ void pasteClipboard(); /** * reload configuration */ virtual void reloadConfig() = 0; + /** + * sets the scrollbar (if implemented by successor of this class) + */ + virtual void setScroll( int cursor, int slines ); + + /** + * scrolls (if implemented, by successor of this class) + * @param int value, how much the widget should scroll up (positive value) or down (negative value) + */ + virtual void scroll( int value ); + signals: /** * key was pressed */ void keyPressed( QKeyEvent *e ); /** * whenever Mouse selects something * @param int button, the button that us pressed : * 0 left Button * 3 Button released * @param int x, x position * @param int y, y position * * // numbering due to layout in old TEWidget */ void mousePressed( int button, int x, int y ); /** * size of image changed * @param int lines, line count of new size * @param int columns, column count of new size */ void imageSizeChanged( int lines, int columns ); /** * cursor in history changed * @param int value, value of history cursor */ void historyCursorChanged( int value ); |