author | llornkcor <llornkcor> | 2002-11-01 12:56:21 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-01 12:56:21 (UTC) |
commit | 287f8a39e757e87a840fbffce258ee03c6b62161 (patch) (side-by-side diff) | |
tree | f62a4f36857aeb6f3f270ddadf92010639b6ce94 | |
parent | 14bd24ba233e370b44ec23cab2733289a3387ca7 (diff) | |
download | opie-287f8a39e757e87a840fbffce258ee03c6b62161.zip opie-287f8a39e757e87a840fbffce258ee03c6b62161.tar.gz opie-287f8a39e757e87a840fbffce258ee03c6b62161.tar.bz2 |
remove some commented code
-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 60 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/TEWidget.cpp | 63 |
2 files changed, 3 insertions, 120 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 50807d3..a6cf6a1 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp @@ -1,1278 +1,1220 @@ /* -------------------------------------------------------------------------- */ /* */ /* [TEScreen.C] Screen Data Type */ /* */ /* -------------------------------------------------------------------------- */ /* */ /* 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> */ /* */ /* -------------------------------------------------------------------------- */ // enhancements added by L.J. Potter <ljp@llornkcor.com> /*! \file */ /*! \class TEScreen \brief The image manipulated by the emulation. This class implements the operations of the terminal emulation framework. It is a complete passive device, driven by the emulation decoder (TEmuVT102). By this it forms in fact an ADT, that defines operations on a rectangular image. It does neither know how to display its image nor about escape sequences. It is further independent of the underlying toolkit. By this, one can even use this module for an ordinary text surface. Since the operations are called by a specific emulation decoder, one may collect their different operations here. The state manipulated by the operations is mainly kept in `image', though 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 <qpe/config.h> #include "TEScreen.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 `TEScreen' of `lines' lines and `columns' columns. */ TEScreen::TEScreen(int lines, int columns) { this->lines = lines; this->columns = columns; // qDebug("Columns %d", columns); image = (ca*) malloc(lines*columns*sizeof(ca)); tabstops = NULL; initTabStops(); histCursor = 0; horzCursor = 0; clearSelection(); reset(); } /*! Destructor */ TEScreen::~TEScreen() { free(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 TEScreen::cursorUp(int n) //=CUU { if (n == 0) n = 1; // Default int stop = cuY < tmargin ? 0 : tmargin; cuX = QMIN(columns-1,cuX); // nowrap! cuY = QMAX(stop,cuY-n); } /*! Move the cursor down. The cursor will not be moved beyond the bottom margin. */ void TEScreen::cursorDown(int n) //=CUD { if (n == 0) n = 1; // Default int stop = cuY > bmargin ? lines-1 : bmargin; cuX = QMIN(columns-1,cuX); // nowrap! cuY = QMIN(stop,cuY+n); } /*! Move the cursor left. The cursor will not move beyond the first column. */ void TEScreen::cursorLeft(int n) //=CUB { if (n == 0) n = 1; // Default cuX = QMIN(columns-1,cuX); // nowrap! cuX = QMAX(0,cuX-n); } /*! Move the cursor left. The cursor will not move beyond the rightmost column. */ void TEScreen::cursorRight(int n) //=CUF { if (n == 0) n = 1; // Default cuX = QMIN(columns-1,cuX+n); } /*! Set top and bottom margin. */ void TEScreen::setMargins(int top, int bot) //=STBM { if (top == 0) top = 1; // Default if (bot == 0) bot = lines; // Default top = top - 1; // Adjust to internal lineno bot = bot - 1; // Adjust to internal lineno if ( !( 0 <= top && top < bot && bot < lines ) ) { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", __FILE__,__LINE__,top,bot); return; // Default error action: ignore } tmargin = top; bmargin = bot; cuX = 0; cuY = getMode(MODE_Origin) ? top : 0; } /*! Move the cursor down one line. If cursor is on bottom margin, the region between the actual top and bottom margin is scrolled up instead. */ void TEScreen::index() //=IND { if (cuY == bmargin) { if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history scrollUp(tmargin,1); } else if (cuY < lines-1) cuY += 1; } /*! Move the cursor up one line. If cursor is on the top margin, the region between the actual top and bottom margin is scrolled down instead. */ void TEScreen::reverseIndex() //=RI { if (cuY == tmargin) scrollDown(tmargin,1); else if (cuY > 0) cuY -= 1; } /*! Move the cursor to the begin of the next line. If cursor is on bottom margin, the region between the actual top and bottom margin is scrolled up. */ void TEScreen::NextLine() //=NEL { Return(); index(); } // Line Editing ---------------------------------------------------------------- /*! \section inserting / deleting characters */ /*! erase `n' characters starting from (including) the cursor position. The line is filled in from the right with spaces. */ void TEScreen::eraseChars(int n) { if (n == 0) n = 1; // Default int p = QMAX(0,QMIN(cuX+n-1,columns-1)); clearImage(loc(cuX,cuY),loc(p,cuY),' '); } /*! delete `n' characters starting from (including) the cursor position. The line is filled in from the right with spaces. */ void TEScreen::deleteChars(int n) { if (n == 0) n = 1; // Default int p = QMAX(0,QMIN(cuX+n,columns-1)); moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); } /*! insert `n' spaces at the cursor position. The cursor is not moved by the operation. */ void TEScreen::insertChars(int n) { if (n == 0) n = 1; // Default int p = QMAX(0,QMIN(columns-1-n,columns-1)); int q = QMAX(0,QMIN(cuX+n,columns-1)); moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); } /*! delete `n' lines starting from (including) the cursor position. The cursor is not moved by the operation. */ void TEScreen::deleteLines(int n) { if (n == 0) n = 1; // Default scrollUp(cuY,n); } /*! insert `n' lines at the cursor position. The cursor is not moved by the operation. */ void TEScreen::insertLines(int n) { if (n == 0) n = 1; // Default scrollDown(cuY,n); } // Mode Operations ----------------------------------------------------------- /*! Set a specific mode. */ void TEScreen::setMode(int m) { currParm.mode[m] = TRUE; switch(m) { case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home } } /*! Reset a specific mode. */ void TEScreen::resetMode(int m) { currParm.mode[m] = FALSE; switch(m) { case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home } } /*! Save a specific mode. */ void TEScreen::saveMode(int m) { saveParm.mode[m] = currParm.mode[m]; } /*! Restore a specific mode. */ void TEScreen::restoreMode(int m) { currParm.mode[m] = saveParm.mode[m]; } //NOTE: this is a helper function /*! Return the setting a specific mode. */ BOOL TEScreen::getMode(int m) { return currParm.mode[m]; } /*! Save the cursor position and the rendition attribute settings. */ void TEScreen::saveCursor() { sa_cuX = cuX; sa_cuY = cuY; sa_cu_re = cu_re; sa_cu_fg = cu_fg; sa_cu_bg = cu_bg; } /*! Restore the cursor position and the rendition attribute settings. */ void TEScreen::restoreCursor() { cuX = QMIN(sa_cuX,columns-1); cuY = QMIN(sa_cuY,lines-1); cu_re = sa_cu_re; cu_fg = sa_cu_fg; cu_bg = sa_cu_bg; 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 TEScreen::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(horzCursor,1); } } // make new image ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca)); 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); 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 RE_BLINK XX XX affects foreground only RE_BOLD XX XX affects foreground only RE_REVERSE -- XX RE_TRANSPARENT XX -- affects background only RE_INTENSIVE XX -- affects foreground only Note that RE_BOLD is used in both widget and screen rendition. Since xterm/vt102 is to poor to distinguish between bold (which is a font attribute) and intensive (which is a color attribute), we translate this and RE_BOLD in falls eventually appart into RE_BOLD and RE_INTENSIVE. */ void TEScreen::reverseRendition(ca* p) { UINT8 f = p->f; UINT8 b = p->b; p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT; } void TEScreen::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. */ ca* TEScreen::getCookedImage() { int x,y; ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); ca 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; - - /* - int x, y, z; - - ca* merged = (ca*)malloc( lines * columns * sizeof( ca)); - - ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); - -// qDebug("hist lines %d, historyCursor %d, minus %d ,lines %d, columns %d", -// hist.getLines(), histCursor, hist.getLines() - histCursor , lines, columns); - 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; -// qDebug("horzCursor %d, columns %d, len %d", horzCursor, columns, len); -// qDebug("lineno %d, colno %d, count %d\n", y + histCursor, (horzCursor / 2), len ); - qDebug("Y %d", y); - hist.getCells( y + histCursor, (horzCursor / 2), 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 z = horzCursor; - int yp = y * columns; - int yq = ( y + histCursor) * columns; - int yr = ( y - hist.getLines() + histCursor) * columns; -// qDebug("y %d, yp %d, yq %d, columns %d, z cursor %d", y, yp, yq, columns, z); - for (x = 0; x < columns; x++) { - int p = x + yp; int q = x + yq; int r = (x + (horzCursor/2) ) + 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; - */ - + } /*! */ void TEScreen::reset() { Config cfg("Konsole"); cfg.setGroup("ScrollBar"); if( !cfg.readBoolEntry("HorzScroll",0) ) 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 TEScreen::clear() { clearEntireScreen(); home(); } /*! Moves the cursor left one column. */ void TEScreen::BackSpace() { cuX = QMAX(0,cuX-1); if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; } /*! */ void TEScreen::Tabulate() { // note that TAB is a format effector (does not write ' '); cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); } void TEScreen::clearTabStops() { for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; } void TEScreen::changeTabStop(bool set) { if (cuX >= columns) return; tabstops[cuX] = set; } void TEScreen::initTabStops() { if (tabstops) free(tabstops); tabstops = (bool*)malloc(columns*sizeof(bool)); // Arrg! The 1st tabstop has to be one longer than the other. // i.e. the kids start counting from 0 instead of 1. // Other programs might behave correctly. Be aware. for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); } /*! This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) depending on the NewLine Mode (LNM). This mode also affects the key sequence returned for newline ([CR]LF). */ void TEScreen::NewLine() { if (getMode(MODE_NewLine)) Return(); index(); } /*! put `c' literally onto the screen at the current cursor position. VT100 uses the convention to produce an automatic newline (am) with the *first* character that would fall onto the next line (xenl). */ void TEScreen::checkSelection(int from, int to) { if (sel_begin == -1) return; int scr_TL = loc(0, hist.getLines()); //Clear entire selection if it overlaps region [from, to] if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) { clearSelection(); } } void TEScreen::ShowCharacter(unsigned short c) { // Note that VT100 does wrapping BEFORE putting the character. // This has impact on the assumption of valid cursor positions. // We indicate the fact that a newline has to be triggered by // putting the cursor one right to the last column of the screen. if (cuX >= columns) { if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; // comment out for no wrap } if (getMode(MODE_Insert)) insertChars(1); int i = loc( cuX, cuY); checkSelection(i, i); // check if selection is still valid. image[i].c = c; image[i].f = ef_fg; image[i].b = ef_bg; image[i].r = ef_re; cuX += 1; } // Region commands ------------------------------------------------------------- /*! scroll up `n' lines within current region. The `n' new lines are cleared. \sa setRegion \sa scrollDown */ void TEScreen::scrollUp(int from, int n) { if (n <= 0 || from + n > bmargin) return; //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); } /*! scroll down `n' lines within current region. The `n' new lines are cleared. \sa setRegion \sa scrollUp */ void TEScreen::scrollDown(int from, int n) { //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. if (n <= 0) return; if (from > bmargin) return; if (from + n > bmargin) n = bmargin - from; moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); clearImage(loc(0,from),loc(columns-1,from+n-1),' '); } /*! position the cursor to a specific line and column. */ void TEScreen::setCursorYX(int y, int x) { setCursorY(y); setCursorX(x); } /*! Set the cursor to x-th line. */ void TEScreen::setCursorX(int x) { if (x == 0) x = 1; // Default x -= 1; // Adjust cuX = QMAX(0,QMIN(columns-1, x)); } /*! Set the cursor to y-th line. */ void TEScreen::setCursorY(int y) { if (y == 0) y = 1; // Default y -= 1; // Adjust cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); } /*! set cursor to the `left upper' corner of the screen (1,1). */ void TEScreen::home() { cuX = 0; cuY = 0; } /*! set cursor to the begin of the current line. */ void TEScreen::Return() { cuX = 0; } /*! returns the current cursor columns. */ int TEScreen::getCursorX() { return cuX; } /*! returns the current cursor line. */ int TEScreen::getCursorY() { return cuY; } // Erasing --------------------------------------------------------------------- /*! \section Erasing This group of operations erase parts of the screen contents by filling it with spaces colored due to the current rendition settings. Althought the cursor position is involved in most of these operations, it is never modified by them. */ /*! fill screen between (including) `loca' and `loce' with spaces. This is an internal helper functions. The parameter types are internal addresses of within the screen image and make use of the way how the screen matrix is mapped to the image vector. */ void TEScreen::clearImage(int loca, int loce, char c) { int i; int scr_TL=loc(0,hist.getLines()); //FIXME: check positions //Clear entire selection if it overlaps region to be moved... if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) { clearSelection(); } for (i = loca; i <= loce; i++) { image[i].c = c; image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. } } /*! move image between (including) `loca' and `loce' to 'dst'. This is an internal helper functions. The parameter types are internal addresses of within the screen image and make use of the way how the screen matrix is mapped to the image vector. */ void TEScreen::moveImage(int dst, int loca, int loce) { //FIXME: check positions if (loce < loca) { // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; return; } memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); } /*! clear from (including) current cursor position to end of screen. */ void TEScreen::clearToEndOfScreen() { clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); } /*! clear from begin of screen to (including) current cursor position. */ void TEScreen::clearToBeginOfScreen() { clearImage(loc(0,0),loc(cuX,cuY),' '); } /*! clear the entire screen. */ void TEScreen::clearEntireScreen() { clearImage(loc(0,0),loc(columns-1,lines-1),' '); } /*! fill screen with 'E' This is to aid screen alignment */ void TEScreen::helpAlign() { clearImage(loc(0,0),loc(columns-1,lines-1),'E'); } /*! clear from (including) current cursor position to end of current cursor line. */ void TEScreen::clearToEndOfLine() { clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); } /*! clear from begin of current cursor line to (including) current cursor position. */ void TEScreen::clearToBeginOfLine() { clearImage(loc(0,cuY),loc(cuX,cuY),' '); } /*! clears entire current cursor line */ void TEScreen::clearEntireLine() { clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); } // Rendition ------------------------------------------------------------------ /*! set rendition mode */ void TEScreen::setRendition(int re) { cu_re |= re; effectiveRendition(); } /*! reset rendition mode */ void TEScreen::resetRendition(int re) { cu_re &= ~re; effectiveRendition(); } /*! */ void TEScreen::setDefaultRendition() { setForeColorToDefault(); setBackColorToDefault(); cu_re = DEFAULT_RENDITION; effectiveRendition(); } /*! */ void TEScreen::setForeColor(int fgcolor) { cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); effectiveRendition(); } /*! */ void TEScreen::setBackColor(int bgcolor) { cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); effectiveRendition(); } /*! */ void TEScreen::setBackColorToDefault() { cu_bg = DEFAULT_BACK_COLOR; effectiveRendition(); } /*! */ void TEScreen::setForeColorToDefault() { cu_fg = DEFAULT_FORE_COLOR; effectiveRendition(); } /* ------------------------------------------------------------------------- */ /* */ /* Marking & Selection */ /* */ /* ------------------------------------------------------------------------- */ void TEScreen::clearSelection() { sel_BR = -1; sel_TL = -1; sel_begin = -1; } void TEScreen::setSelBeginXY(const int x, const int y) { sel_begin = loc(x,y+histCursor) ; sel_BR = sel_begin; sel_TL = sel_begin; } void TEScreen::setSelExtentXY(const int x, const int y) { if (sel_begin == -1) return; int l = loc(x,y + histCursor); if (l < sel_begin) { sel_TL = l; sel_BR = sel_begin; } else { /* FIXME, HACK to correct for x too far to the right... */ if (( x == columns )|| (x == 0)) l--; sel_TL = sel_begin; sel_BR = l; } } QString TEScreen::getSelText(const BOOL preserve_line_breaks) { if (sel_begin == -1) return QString::null; // Selection got clear while selecting. int *m; // buffer to fill. int s, d; // source index, dest. index. int hist_BR = loc(0, hist.getLines()); int hY = sel_TL / columns; int hX = sel_TL % columns; int eol; // end of line s = sel_TL; // tracks copy in source. // allocate buffer for maximum // possible size... d = (sel_BR - sel_TL) / columns + 1; m = new int[d * (columns + 1) + 2]; d = 0; while (s <= sel_BR) { if (s < hist_BR) { // get lines from hist.history // buffer. eol = hist.getLineLen(hY); if ((hY == (sel_BR / columns)) && (eol >= (sel_BR % columns))) { eol = sel_BR % columns + 1; } while (hX < eol) { m[d++] = hist.getCell(hY, hX++).c; s++; } if (s <= sel_BR) { // The line break handling // It's different from the screen // image case! if (eol % columns == 0) { // That's either a completely filled // line or an empty line if (eol == 0) { m[d++] = '\n'; } else { // We have a full line. // FIXME: How can we handle newlines // at this position?! } } else if ((eol + 1) % columns == 0) { // FIXME: We don't know if this was a // space at the last position or a // short line!! m[d++] = ' '; } else { // We have a short line here. Put a // newline or a space into the // buffer. m[d++] = preserve_line_breaks ? '\n' : ' '; } } hY++; hX = 0; s = hY * columns; } else { // or from screen image. eol = (s / columns + 1) * columns - 1; if (eol < sel_BR) { while ((eol > s) && isspace(image[eol - hist_BR].c)) { eol--; } } else { eol = sel_BR; } while (s <= eol) { m[d++] = image[s++ - hist_BR].c; } if (eol < sel_BR) { // eol processing see below ... if ((eol + 1) % columns == 0) { if (image[eol - hist_BR].c == ' ') { m[d++] = ' '; } } else { m[d++] = ((preserve_line_breaks || ((eol % columns) == 0)) ? '\n' : ' '); } } s = (eol / columns + 1) * columns; } } QChar* qc = new QChar[d]; for (int i = 0; i < d; i++) { qc[i] = m[i]; } QString res(qc, d); delete m; delete qc; return res; } /* above ... end of line processing for selection -- psilva cases: 1) (eol+1)%columns == 0 --> the whole line is filled. If the last char is a space, insert (preserve) space. otherwise leave the text alone, so that words that are broken by linewrap are preserved. 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 TEScreen::addHistLine() { assert(hasScroll() || histCursor == 0); // add to hist buffer // we have to take care about scrolling, too... if (hasScroll()){ ca dft; int end = columns - 1; while (end >= 0 && image[end] == dft) end -= 1; hist.addCells( image, end + 1); hist.addLine(); // adjust history cursor histCursor += ( hist.getLines() - 1 == histCursor); } if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround } void TEScreen::setHistCursor(int cursor) { histCursor = cursor; //FIXME:rangecheck } void TEScreen::setHorzCursor(int cursor) { horzCursor = cursor; } int TEScreen::getHistCursor() { return histCursor; } int TEScreen::getHorzCursor() { return horzCursor; } int TEScreen::getHistLines() { return hist.getLines(); } void TEScreen::setScroll(bool on) { histCursor = 0; clearSelection(); hist.setScroll(on); } bool TEScreen::hasScroll() { return hist.hasScroll(); } diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp index 60021f4..d6ee6e8 100644 --- a/core/apps/embeddedkonsole/TEWidget.cpp +++ b/core/apps/embeddedkonsole/TEWidget.cpp @@ -290,1117 +290,1058 @@ TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) this, SLOT(onClearSelection()) ); #endif scrollbar = new QScrollBar(this); scrollbar->setCursor( arrowCursor ); connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); hScrollbar = new QScrollBar(this); hScrollbar->setCursor( arrowCursor ); hScrollbar->setOrientation(QScrollBar::Horizontal); hScrollbar->setMaximumHeight(16); connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); Config cfg("Konsole"); cfg.setGroup("ScrollBar"); switch( cfg.readNumEntry("Position",2)){ case 0: scrollLoc = SCRNONE; break; case 1: scrollLoc = SCRLEFT; break; case 2: scrollLoc = SCRRIGHT; break; }; useHorzScroll=cfg.readBoolEntry("HorzScroll",0); blinkT = new QTimer(this); connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); // blinking = FALSE; blinking = TRUE; resizing = FALSE; actSel = 0; image = 0; lines = 1; columns = 1; font_w = 1; font_h = 1; font_a = 1; word_selection_mode = FALSE; hposition = 0; vcolumns = 0; setMouseMarks(TRUE); setVTFont( QFont("fixed") ); setColorTable(base_color_table); // init color table qApp->installEventFilter( this ); //FIXME: see below // KCursor::setAutoHideCursor( this, true ); // Init DnD //////////////////////////////////////////////////////////////// currentSession = NULL; // setAcceptDrops(true); // attempt // m_drop = new QPopupMenu(this); // m_drop->insertItem( QString("Paste"), 0); // m_drop->insertItem( QString("cd"), 1); // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); // we need focus so that the auto-hide cursor feature works setFocus(); setFocusPolicy( WheelFocus ); } //FIXME: make proper destructor // Here's a start (David) TEWidget::~TEWidget() { qApp->removeEventFilter( this ); if (image) free(image); } /* ------------------------------------------------------------------------- */ /* */ /* Display Operations */ /* */ /* ------------------------------------------------------------------------- */ /*! attributed string draw primitive */ void TEWidget::drawAttrStr(QPainter &paint, QRect rect, QString& str, ca attr, BOOL pm, BOOL clear) { if (pm && color_table[attr.b].transparent) { paint.setBackgroundMode( TransparentMode ); if (clear) erase(rect); } else { if (blinking) paint.fillRect(rect, color_table[attr.b].color); else { paint.setBackgroundMode( OpaqueMode ); paint.setBackgroundColor( color_table[attr.b].color ); } } if (color_table[attr.f].bold) paint.setPen(QColor( 0x8F, 0x00, 0x00 )); else paint.setPen(color_table[attr.f].color); paint.drawText(rect.x(),rect.y()+font_a, str); if (attr.r & RE_UNDERLINE) paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); } /*! The image can only be set completely. The size of the new image may or may not match the size of the widget. */ void TEWidget::setImage(const ca* const newimg, int lines, int columns) { int y,x,len; const QPixmap* pm = backgroundPixmap(); QPainter paint; setUpdatesEnabled(FALSE); paint.begin( this ); HCNT("setImage"); QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); hasBlinker = FALSE; int cf = -1; // undefined int cb = -1; // undefined int cr = -1; // undefined int lins = QMIN(this->lines, QMAX(0,lines )); int cols = QMIN(this->columns,QMAX(0,columns)); QChar *disstrU = new QChar[cols]; for (y = 0; y < lins; y++) { const ca* lcl = &image[y*this->columns]; const ca* const ext = &newimg[y*columns]; if (!resizing) // not while resizing, we're expecting a paintEvent for (x = 0; x < cols; x++) { hasBlinker |= (ext[x].r & RE_BLINK); if (ext[x] != lcl[x]) { cr = ext[x].r; cb = ext[x].b; if (ext[x].f != cf) cf = ext[x].f; int lln = cols - x; disstrU[0] = fontMap(ext[x+0].c); for (len = 1; len < lln; len++) { if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || ext[x+len] == lcl[x+len] ) break; disstrU[len] = fontMap(ext[x+len].c); } QString unistr(disstrU,len); drawAttrStr(paint, QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), unistr, ext[x], pm != NULL, true); x += len - 1; } } // finally, make `image' become `newimg'. memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); } drawFrame( &paint ); paint.end(); setUpdatesEnabled(TRUE); if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } delete [] disstrU; } // paint Event //////////////////////////////////////////////////// /*! The difference of this routine vs. the `setImage' is, that the drawing does not include a difference analysis between the old and the new image. Instead, the internal image is used and the painting bound by the PaintEvent box. */ void TEWidget::paintEvent( QPaintEvent* pe ) { //{ static int cnt = 0; printf("paint %d\n",cnt++); } const QPixmap* pm = backgroundPixmap(); QPainter paint; setUpdatesEnabled(FALSE); paint.begin( this ); paint.setBackgroundMode( TransparentMode ); HCNT("paintEvent"); // Note that the actual widget size can be slightly larger // that the image (the size is truncated towards the smaller // number of characters in `resizeEvent'. The paint rectangle // can thus be larger than the image, but less then the size // of one character. QRect rect = pe->rect().intersect(contentsRect()); QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); /* printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, rect.left(), rect.right(), rect.top(), rect.bottom()); */ // if (pm != NULL && color_table[image->b].transparent) // erase(rect); // BL: I have no idea why we need this, and it breaks the refresh. QChar *disstrU = new QChar[columns]; for (int y = luy; y <= rly; y++) for (int x = lux; x <= rlx; x++) { int len = 1; disstrU[0] = fontMap(image[loc(x,y)].c); int cf = image[loc(x,y)].f; int cb = image[loc(x,y)].b; int cr = image[loc(x,y)].r; while (x+len <= rlx && image[loc(x+len,y)].f == cf && image[loc(x+len,y)].b == cb && image[loc(x+len,y)].r == cr ) { disstrU[len] = fontMap(image[loc(x+len,y)].c); len += 1; } QString unistr(disstrU,len); drawAttrStr(paint, QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), unistr, image[loc(x,y)], pm != NULL, false); x += len - 1; } delete [] disstrU; drawFrame( &paint ); paint.end(); setUpdatesEnabled(TRUE); } void TEWidget::blinkEvent() { blinking = !blinking; repaint(FALSE); } /* ------------------------------------------------------------------------- */ /* */ /* Resizing */ /* */ /* ------------------------------------------------------------------------- */ void TEWidget::resizeEvent(QResizeEvent* ev) { // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); //printf("curren: %d,%d\n",width(),height()); HCNT("resizeEvent"); // see comment in `paintEvent' concerning the rounding. //FIXME: could make a routine here; check width(),height() assert(ev->size().width() == width()); assert(ev->size().height() == height()); propagateSize(); } void TEWidget::propagateSize() { ca* oldimg = image; int oldlin = lines; int oldcol = columns; makeImage(); // we copy the old image to reduce flicker int lins = QMIN(oldlin,lines); int cols = QMIN(oldcol,columns); if (oldimg) { for (int lin = 0; lin < lins; lin++) memcpy((void*)&image[columns*lin], (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); free(oldimg); //FIXME: try new,delete } else clearImage(); //NOTE: control flows from the back through the chest right into the eye. // `emu' will call back via `setImage'. resizing = TRUE; emit changedImageSizeSignal(lines, columns); // expose resizeEvent resizing = FALSE; } /* ------------------------------------------------------------------------- */ /* */ /* Scrollbar */ /* */ /* ------------------------------------------------------------------------- */ void TEWidget::scrollChanged(int) { emit changedHistoryCursor(scrollbar->value()); //expose } void TEWidget::hScrollChanged(int loc) { hposition = loc; propagateSize(); update(); // emit changedHorzCursor( hScrollbar->value()); //expose } void TEWidget::setScroll(int cursor, int slines) { disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); scrollbar->setRange(0,slines); scrollbar->setSteps(1,lines); scrollbar->setValue(cursor); connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); } void TEWidget::setScrollbarLocation(int loc) { if (scrollLoc == loc) return; // quickly scrollLoc = loc; propagateSize(); update(); } /* ------------------------------------------------------------------------- */ /* */ /* Mouse */ /* */ /* ------------------------------------------------------------------------- */ /*! Three different operations can be performed using the mouse, and the routines in this section serve all of them: 1) The press/release events are exposed to the application 2) Marking (press and move left button) and Pasting (press middle button) 3) The right mouse button is used from the configuration menu NOTE: During the marking process we attempt to keep the cursor within the bounds of the text as being displayed by setting the mouse position whenever the mouse has left the text area. Two reasons to do so: 1) QT does not allow the `grabMouse' to confine-to the TEWidget. Thus a `XGrapPointer' would have to be used instead. 2) Even if so, this would not help too much, since the text area of the TEWidget is normally not identical with it's bounds. The disadvantage of the current handling is, that the mouse can visibly leave the bounds of the widget and is then moved back. Because of the current construction, and the reasons mentioned above, we cannot do better without changing the overall construction. */ /*! */ void TEWidget::mousePressEvent(QMouseEvent* ev) { //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); if ( !contentsRect().contains(ev->pos()) ) return; QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); word_selection_mode = FALSE; //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); if ( ev->button() == LeftButton) { QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; if (mouse_marks || (ev->state() & ShiftButton)) { emit clearSelectionSignal(); iPntSel = pntSel = pos; actSel = 1; // left mouse button pressed but nothing selected yet. grabMouse( /*crossCursor*/ ); // handle with care! } else { emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button } } if ( ev->button() == MidButton ) { emitSelection(); } if ( ev->button() == RightButton ) // Configure { emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); } } void TEWidget::mouseMoveEvent(QMouseEvent* ev) { // for auto-hiding the cursor, we need mouseTracking if (ev->state() == NoButton ) return; if (actSel == 0) return; // don't extend selection while pasting if (ev->state() & MidButton) return; //if ( !contentsRect().contains(ev->pos()) ) return; QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); int scroll = scrollbar->value(); // int hScroll = hScrollbar->value(); // we're in the process of moving the mouse with the left button pressed // the mouse cursor will kept catched within the bounds of the text in // this widget. // Adjust position within text area bounds. See FIXME above. QPoint pos = ev->pos(); if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); // check if we produce a mouse move event by this if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); if ( pos.y() == tLy+bY+lines*font_h-1 ) { scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward } if ( pos.y() == tLy+bY ) { scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback } QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); QPoint ohere; bool swapping = FALSE; if ( word_selection_mode ) { // Extend to word boundaries int i; int selClass; bool left_not_right = ( here.y() < iPntSel.y() || here.y() == iPntSel.y() && here.x() < iPntSel.x() ); bool old_left_not_right = ( pntSel.y() < iPntSel.y() || pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); swapping = left_not_right != old_left_not_right; // Find left (left_not_right ? from here : from start) QPoint left = left_not_right ? here : iPntSel; i = loc(left.x(),left.y()); selClass = charClass(image[i].c); while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) { i--; left.rx()--; } // Find left (left_not_right ? from start : from here) QPoint right = left_not_right ? iPntSel : here; i = loc(right.x(),right.y()); selClass = charClass(image[i].c); while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) { i++; right.rx()++; } // Pick which is start (ohere) and which is extension (here) if ( left_not_right ) { here = left; ohere = right; } else { here = right; ohere = left; } } if (here == pntSel && scroll == scrollbar->value()) return; // not moved if ( word_selection_mode ) { if ( actSel < 2 || swapping ) { emit beginSelectionSignal( ohere.x(), ohere.y() ); } } else if ( actSel < 2 ) { emit beginSelectionSignal( pntSel.x(), pntSel.y() ); } actSel = 2; // within selection pntSel = here; emit extendSelectionSignal( here.x(), here.y() ); } void TEWidget::mouseReleaseEvent(QMouseEvent* ev) { //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); if ( ev->button() == LeftButton) { if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); preserve_line_breaks = TRUE; actSel = 0; //FIXME: emits a release event even if the mouse is // outside the range. The procedure used in `mouseMoveEvent' // applies here, too. QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); if (!mouse_marks && !(ev->state() & ShiftButton)) emit mouseSignal( 3, // release (ev->x()-tLx-blX)/font_w + 1, (ev->y()-tLy-bY)/font_h + 1 ); releaseMouse(); } } void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) { if ( ev->button() != LeftButton) return; QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); // pass on double click as two clicks. if (!mouse_marks && !(ev->state() & ShiftButton)) { emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button return; } emit clearSelectionSignal(); QPoint bgnSel = pos; QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); int i = loc(bgnSel.x(),bgnSel.y()); iPntSel = bgnSel; word_selection_mode = TRUE; // find word boundaries... int selClass = charClass(image[i].c); { // set the start... int x = bgnSel.x(); while ( x > 0 && charClass(image[i-1].c) == selClass ) { i--; x--; } bgnSel.setX(x); emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); // set the end... i = loc( endSel.x(), endSel.y() ); x = endSel.x(); while( x < columns-1 && charClass(image[i+1].c) == selClass ) { i++; x++ ; } endSel.setX(x); actSel = 2; // within selection emit extendSelectionSignal( endSel.x(), endSel.y() ); emit endSelectionSignal(preserve_line_breaks); preserve_line_breaks = TRUE; } } void TEWidget::focusInEvent( QFocusEvent * ) { // do nothing, to prevent repainting } void TEWidget::focusOutEvent( QFocusEvent * ) { // do nothing, to prevent repainting } bool TEWidget::focusNextPrevChild( bool next ) { if (next) return false; // This disables changing the active part in konqueror // when pressing Tab return QFrame::focusNextPrevChild( next ); } int TEWidget::charClass(char ch) const { // This might seem like overkill, but imagine if ch was a Unicode // character (Qt 2.0 QChar) - it might then be sensible to separate // the different language ranges, etc. if ( isspace(ch) ) return ' '; static const char *word_characters = ":@-./_~"; if ( isalnum(ch) || strchr(word_characters, ch) ) return 'a'; // Everything else is weird return 1; } void TEWidget::setMouseMarks(bool on) { mouse_marks = on; setCursor( mouse_marks ? ibeamCursor : arrowCursor ); } /* ------------------------------------------------------------------------- */ /* */ /* Clipboard */ /* */ /* ------------------------------------------------------------------------- */ #undef KeyPress void TEWidget::emitSelection() // Paste Clipboard by simulating keypress events { #ifndef QT_NO_CLIPBOARD QString text = QApplication::clipboard()->text(); if ( ! text.isNull() ) { text.replace(QRegExp("\n"), "\r"); QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); emit keyPressedSignal(&e); // expose as a big fat keypress event emit clearSelectionSignal(); } #endif } void TEWidget::emitText(QString text) { QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); emit keyPressedSignal(&e); // expose as a big fat keypress event } void TEWidget::pasteClipboard( ) { emitSelection(); } void TEWidget::setSelection(const QString& t) { #ifndef QT_NO_CLIPBOARD // Disconnect signal while WE set the clipboard QObject *cb = QApplication::clipboard(); QObject::disconnect( cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); QApplication::clipboard()->setText(t); QObject::connect( cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); #endif } void TEWidget::onClearSelection() { emit clearSelectionSignal(); } /* ------------------------------------------------------------------------- */ /* */ /* Keyboard */ /* */ /* ------------------------------------------------------------------------- */ //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' // due to a bug in `QT' or the ignorance of the author to prevent // repaint events being emitted to the screen whenever one leaves // or reenters the screen to/from another application. // // Troll says one needs to change focusInEvent() and focusOutEvent(), // which would also let you have an in-focus cursor and an out-focus // cursor like xterm does. // for the auto-hide cursor feature, I added empty focusInEvent() and // focusOutEvent() so that update() isn't called. // For auto-hide, we need to get keypress-events, but we only get them when // we have focus. void TEWidget::doScroll(int lines) { scrollbar->setValue(scrollbar->value()+lines); } void TEWidget::doHScroll(int lines) { hScrollbar->setValue( hScrollbar->value()+lines); } bool TEWidget::eventFilter( QObject *obj, QEvent *e ) { if ( (e->type() == QEvent::Accel || e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { static_cast<QKeyEvent *>( e )->ignore(); return true; } if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) return FALSE; // not us if ( e->type() == QEvent::Wheel) { QApplication::sendEvent(scrollbar, e); } #ifdef FAKE_CTRL_AND_ALT static bool control = FALSE; static bool alt = FALSE; // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); bool dele=FALSE; if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent* ke = (QKeyEvent*)e; bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); switch (ke->key()) { case Key_F9: // let this be "Control" control = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); dele=TRUE; break; case Key_F13: // let this be "Alt" alt = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); dele=TRUE; break; default: if ( control ) { int a = toupper(ke->ascii())-64; if ( a >= 0 && a < ' ' ) { e = new QKeyEvent(e->type(), ke->key(), a, ke->state()|ControlButton, QChar(a,0)); dele=TRUE; } } if ( alt ) { e = new QKeyEvent(e->type(), ke->key(), ke->ascii(), ke->state()|AltButton, ke->text()); dele=TRUE; } } } #endif if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; actSel=0; // Key stroke implies a screen update, so TEWidget won't // know where the current selection is. -// qDebug("key pressed is 0x%x, state %d",ke->key(), ke->state()); +// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker -// qDebug("key pressed 2 is 0x%x",ke->key()); +// qDebug("key pressed 2 is 0x%x", ke->key()); emitText("\\"); // expose } else if( ke->state() == ControlButton && ke->key() == Key_V) { pasteClipboard(); } else emit keyPressedSignal(ke); // expose ke->accept(); #ifdef FAKE_CTRL_AND_ALT if ( dele ) delete e; #endif return true; // stop the event } if ( e->type() == QEvent::Enter ) { QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } if ( e->type() == QEvent::Leave ) { QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } return QFrame::eventFilter( obj, e ); } /* ------------------------------------------------------------------------- */ /* */ /* Frame */ /* */ /* ------------------------------------------------------------------------- */ void TEWidget::frameChanged() { propagateSize(); update(); } /* ------------------------------------------------------------------------- */ /* */ /* Sound */ /* */ /* ------------------------------------------------------------------------- */ void TEWidget::Bell() { //#ifdef QT_QWS_CUSTOM //# ifndef QT_NO_COP QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); //# endif //#else //# ifndef QT_NO_SOUND // QSound::play(Resource::findSound("alarm")); //# endif //#endif // QApplication::beep(); } /* ------------------------------------------------------------------------- */ /* */ /* Auxiluary */ /* */ /* ------------------------------------------------------------------------- */ void TEWidget::clearImage() // initialize the image // for internal use only { for (int y = 0; y < lines; y++) for (int x = 0; x < columns; x++) { image[loc(x,y)].c = 0xff; //' '; image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; } } // Create Image /////////////////////////////////////////////////////// void TEWidget::calcGeometry() { int showhscrollbar = 1; int hwidth = 0; int dcolumns; Config cfg("Konsole"); cfg.setGroup("ScrollBar"); useHorzScroll=cfg.readBoolEntry("HorzScroll",0); if(vcolumns == 0) showhscrollbar = 0; if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); scrollbar->resize(QApplication::style().scrollBarExtent().width(), contentsRect().height() - hwidth); switch(scrollLoc) { case SCRNONE : columns = ( contentsRect().width() - 2 * rimX ) / font_w; dcolumns = columns; if(vcolumns) columns = vcolumns; blX = (contentsRect().width() - (columns*font_w) ) / 2; if(showhscrollbar) blX = -hposition * font_w; brX = blX; scrollbar->hide(); break; case SCRLEFT : columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; dcolumns = columns; if(vcolumns) columns = vcolumns; brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; if(showhscrollbar) brX = -hposition * font_w; blX = brX + scrollbar->width(); scrollbar->move(contentsRect().topLeft()); scrollbar->show(); break; case SCRRIGHT: columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; dcolumns = columns; if(vcolumns) columns = vcolumns; blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; if(showhscrollbar) blX = -hposition * font_w; brX = blX; scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); scrollbar->show(); break; } //FIXME: support 'rounding' styles lines = ( contentsRect().height() - 2 * rimY ) / font_h; bY = (contentsRect().height() - (lines *font_h)) / 2; if(showhscrollbar == 1) { hScrollbar->resize(contentsRect().width() - hwidth, hwidth); hScrollbar->setRange(0, vcolumns - dcolumns); QPoint p = contentsRect().bottomLeft(); hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); hScrollbar->show(); } else hScrollbar->hide(); if(showhscrollbar == 1) { lines = lines - (hwidth / font_h) - 1; if(lines < 1) lines = 1; } - - /*//FIXME: set rimX == rimY == 0 when running in full screen mode. - Config cfg("Konsole"); - cfg.setGroup("ScrollBar"); - useHorzScroll=cfg.readBoolEntry("HorzScroll",0); - - scrollbar->resize( QApplication::style().scrollBarExtent().width(), - contentsRect().height()); - qDebug("font_w %d", font_w); - switch(scrollLoc) - { - case SCRNONE : - columns = ( contentsRect().width() - 2 * rimX ) / font_w; - blX = (contentsRect().width() - (columns*font_w) ) / 2; - brX = blX; - scrollbar->hide(); - break; - case SCRLEFT : - columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; - if(useHorzScroll) columns = columns * (font_w/2); - brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; - blX = brX + scrollbar->width(); - scrollbar->move(contentsRect().topLeft()); - scrollbar->show(); - break; - case SCRRIGHT: - columns = ( contentsRect().width() - 2 * rimX - scrollbar->width() ) / font_w; - if(useHorzScroll) columns = columns * (font_w/2); - blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; - if(useHorzScroll) { - brX = blX =2; - } else { - brX=blX; - } - scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0) ); - scrollbar->show(); - break; - } - - if( !scrollbar->isHidden()) - hScrollbar->resize( contentsRect().width()-SCRWIDTH, QApplication::style() - .scrollBarExtent().height()); - else - hScrollbar->resize( contentsRect().width(), QApplication::style() - .scrollBarExtent().height()); - - hScrollbar->move( 0, contentsRect().height() - SCRWIDTH); - - - if(useHorzScroll) { - hScrollbar->show(); - lines = ( (contentsRect().height() - SCRWIDTH) - 2 * rimY ) / font_h; - bY = ((contentsRect().height() - SCRWIDTH) - (lines *font_h)) / 2; - } else { - hScrollbar->hide(); - lines = (contentsRect().height() - 2 * rimY ) / font_h; - bY = (contentsRect().height() - (lines *font_h)) / 2; - } - */ //FIXME: support 'rounding' styles } void TEWidget::makeImage() //FIXME: rename 'calcGeometry? { calcGeometry(); image = (ca*) malloc(lines*columns*sizeof(ca)); clearImage(); } // calculate the needed size QSize TEWidget::calcSize(int cols, int lins) const { int frw = width() - contentsRect().width(); int frh = height() - contentsRect().height(); int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); } QSize TEWidget::sizeHint() const { return size(); } void TEWidget::styleChange(QStyle &) { propagateSize(); } #ifndef QT_NO_DRAGANDDROP /* --------------------------------------------------------------------- */ /* */ /* Drag & Drop */ /* */ /* --------------------------------------------------------------------- */ void TEWidget::dragEnterEvent(QDragEnterEvent* e) { e->accept(QTextDrag::canDecode(e) || QUriDrag::canDecode(e)); } void TEWidget::dropEvent(QDropEvent* event) { // The current behaviour when url(s) are dropped is // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd // * in all other cases, just paste // (for non-local ones, or for a list of URLs, 'cd' is nonsense) QStrList strlist; int file_count = 0; dropText = ""; bool bPopup = true; if(QUriDrag::decode(event, strlist)) { if (strlist.count()) { for(const char* p = strlist.first(); p; p = strlist.next()) { if(file_count++ > 0) { dropText += " "; bPopup = false; // more than one file, don't popup } /* KURL url(p); if (url.isLocalFile()) { dropText += url.path(); // local URL : remove protocol } else { dropText += url.prettyURL(); bPopup = false; // a non-local file, don't popup } */ } if (bPopup) // m_drop->popup(pos() + event->pos()); m_drop->popup(mapToGlobal(event->pos())); else { if (currentSession) { currentSession->getEmulation()->sendString(dropText.local8Bit()); } // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; } } } else if(QTextDrag::decode(event, dropText)) { // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; if (currentSession) { currentSession->getEmulation()->sendString(dropText.local8Bit()); } // Paste it } } #endif void TEWidget::drop_menu_activated(int item) { #ifndef QT_NO_DRAGANDDROP switch (item) { case 0: // paste currentSession->getEmulation()->sendString(dropText.local8Bit()); // KWM::activate((Window)this->winId()); break; case 1: // cd ... currentSession->getEmulation()->sendString("cd "); struct stat statbuf; if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) { if ( !S_ISDIR(statbuf.st_mode) ) { /* KURL url; url.setPath( dropText ); dropText = url.directory( true, false ); // remove filename */ } } dropText.replace(QRegExp(" "), "\\ "); // escape spaces currentSession->getEmulation()->sendString(dropText.local8Bit()); currentSession->getEmulation()->sendString("\n"); // KWM::activate((Window)this->winId()); break; } #endif } void TEWidget::setWrapAt(int columns) { vcolumns = columns; propagateSize(); update(); } |