summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEHistory.cpp29
-rw-r--r--core/apps/embeddedkonsole/TEScreen.cpp415
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp169
-rw-r--r--core/apps/embeddedkonsole/TEWidget.h15
-rw-r--r--core/apps/embeddedkonsole/TEmulation.cpp43
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp34
6 files changed, 491 insertions, 214 deletions
diff --git a/core/apps/embeddedkonsole/TEHistory.cpp b/core/apps/embeddedkonsole/TEHistory.cpp
index 317ce57..db9d10c 100644
--- a/core/apps/embeddedkonsole/TEHistory.cpp
+++ b/core/apps/embeddedkonsole/TEHistory.cpp
@@ -1,64 +1,64 @@
/* -------------------------------------------------------------------------- */
/* */
/* [TEHistory.C] History Buffer */
/* */
/* -------------------------------------------------------------------------- */
/* */
/* 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> */
-/* */
+/* */
/* -------------------------------------------------------------------------- */
#include "TEHistory.h"
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#define HERE printf("%s(%d): here\n",__FILE__,__LINE__)
/*
An arbitrary long scroll.
One can modify the scroll only by adding either cells
or newlines, but access it randomly.
The model is that of an arbitrary wide typewriter scroll
in that the scroll is a serie of lines and each line is
a serie of cells with no overwriting permitted.
The implementation provides arbitrary length and numbers
of cells and line/column indexed read access to the scroll
at constant costs.
FIXME: some complain about the history buffer comsuming the
memory of their machines. This problem is critical
since the history does not behave gracefully in cases
where the memory is used up completely.
I put in a workaround that should handle it problem
now gracefully. I'm not satisfied with the solution.
FIXME: Terminating the history is not properly indicated
in the menu. We should throw a signal.
FIXME: There is noticable decrease in speed, also. Perhaps,
there whole feature needs to be revisited therefore.
Disadvantage of a more elaborated, say block-oriented
scheme with wrap around would be it's complexity.
*/
//FIXME: tempory replacement for tmpfile
// this is here one for debugging purpose.
//#define tmpfile xTmpFile
@@ -72,141 +72,148 @@ FILE* xTmpFile()
// History Buffer ///////////////////////////////////////////
/*
A Row(X) data type which allows adding elements to the end.
*/
HistoryBuffer::HistoryBuffer()
{
ion = -1;
length = 0;
}
HistoryBuffer::~HistoryBuffer()
{
setScroll(FALSE);
}
void HistoryBuffer::setScroll(bool on)
{
if (on == hasScroll()) return;
if (on)
{
assert( ion < 0 );
assert( length == 0);
FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); return; }
ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n");
fclose(tmp);
}
else
{
assert( ion >= 0 );
close(ion);
ion = -1;
length = 0;
}
}
bool HistoryBuffer::hasScroll()
{
return ion >= 0;
}
void HistoryBuffer::add(const unsigned char* bytes, int len)
{ int rc;
assert(hasScroll());
- rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; }
- rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; }
+ rc = lseek( ion, length, SEEK_SET);
+ if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; }
+ rc = write( ion, bytes, len);
+ if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; }
length += rc;
}
-void HistoryBuffer::get(unsigned char* bytes, int len, int loc)
-{ int rc;
+void HistoryBuffer::get(unsigned char* bytes, int len, int loc) {
+ int rc;
assert(hasScroll());
+// qDebug("history get len %d, loc %d, length %d", len, loc, length);
if (loc < 0 || len < 0 || loc + len > length)
- fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
- rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; }
- rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; }
+ fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
+
+ rc = lseek( ion, loc, SEEK_SET);
+ if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; }
+ rc = read( ion, bytes, len);
+ if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; }
}
int HistoryBuffer::len()
{
return length;
}
// History Scroll //////////////////////////////////////
/*
The history scroll makes a Row(Row(Cell)) from
two history buffers. The index buffer contains
start of line positions which refere to the cells
buffer.
Note that index[0] addresses the second line
(line #1), while the first line (line #0) starts
at 0 in cells.
*/
HistoryScroll::HistoryScroll()
{
}
HistoryScroll::~HistoryScroll()
{
}
void HistoryScroll::setScroll(bool on)
{
index.setScroll(on);
cells.setScroll(on);
}
bool HistoryScroll::hasScroll()
{
return index.hasScroll() && cells.hasScroll();
}
int HistoryScroll::getLines()
{
if (!hasScroll()) return 0;
return index.len() / sizeof(int);
}
int HistoryScroll::getLineLen(int lineno)
{
if (!hasScroll()) return 0;
return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca);
}
int HistoryScroll::startOfLine(int lineno)
{
if (lineno <= 0) return 0;
if (!hasScroll()) return 0;
if (lineno <= getLines())
{ int res;
index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int));
return res;
}
return cells.len();
}
void HistoryScroll::getCells(int lineno, int colno, int count, ca res[])
{
assert(hasScroll());
- cells.get((unsigned char*)res,count*sizeof(ca),startOfLine(lineno)+colno*sizeof(ca));
+//get(unsigned char* bytes, int len, int loc)
+ cells.get( (unsigned char*)res, count * sizeof(ca), startOfLine( lineno) + colno * sizeof(ca) );
}
void HistoryScroll::addCells(ca text[], int count)
{
if (!hasScroll()) return;
cells.add((unsigned char*)text,count*sizeof(ca));
}
void HistoryScroll::addLine()
{
if (!hasScroll()) return;
int locn = cells.len();
index.add((unsigned char*)&locn,sizeof(int));
}
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp
index a3d115d..50807d3 100644
--- a/core/apps/embeddedkonsole/TEScreen.cpp
+++ b/core/apps/embeddedkonsole/TEScreen.cpp
@@ -1,122 +1,126 @@
/* -------------------------------------------------------------------------- */
/* */
/* [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))
+#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);
}
/*!
@@ -338,270 +342,331 @@ void TEScreen::restoreMode(int 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(0,1);
+ 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));
+ // 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);
+ clearSelection();
- // FIXME: try to keep values, evtl.
- tmargin=0;
- bmargin=lines-1;
- initTabStops();
- 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;
+{
+ 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)
@@ -613,144 +678,150 @@ void TEScreen::changeTabStop(bool 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;
+ 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);
+ 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;
+ 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),' ');
+
+ 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 (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));
+
+ 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;
}
@@ -826,97 +897,97 @@ void TEScreen::clearToEndOfScreen()
}
/*! 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),' ');
+ 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)
@@ -943,255 +1014,265 @@ void TEScreen::setForeColorToDefault()
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 *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
+ int eol; // end of line
- s = sel_TL; // tracks copy in source.
+ s = sel_TL; // tracks copy in source.
- // allocate buffer for maximum
- // possible size...
+ // 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;
- }
+ { // 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;
+ { // 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.
+ * 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
+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;
+ if (hasScroll()){
+ ca dft;
- int end = columns-1;
+ int end = columns - 1;
while (end >= 0 && image[end] == dft)
end -= 1;
- hist.addCells(image,end+1);
+ hist.addCells( image, end + 1);
hist.addLine();
// adjust history cursor
- histCursor += (hist.getLines()-1 == histCursor);
+ 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 b1ad008..c10c7a8 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -7,96 +7,103 @@
/* 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> */
/* */
/* -------------------------------------------------------------------------- */
/*! \class TEWidget
\brief Visible screen contents
This class is responsible to map the `image' of a terminal emulation to the
display. All the dependency of the emulation to a specific GUI or toolkit is
localized here. Further, this widget has no knowledge about being part of an
emulation, it simply work within the terminal emulation framework by exposing
size and key events and by being ordered to show a new image.
<ul>
<li> The internal image has the size of the widget (evtl. rounded up)
<li> The external image used in setImage can have any size.
<li> (internally) the external image is simply copied to the internal
when a setImage happens. During a resizeEvent no painting is done
a paintEvent is expected to follow anyway.
</ul>
\sa TEScreen \sa Emulation
*/
/* FIXME:
- 'image' may also be used uninitialized (it isn't in fact) in resizeEvent
- 'font_a' not used in mouse events
- add destructor
*/
/* TODO
- evtl. be sensitive to `paletteChange' while using default colors.
- set different 'rounding' styles? I.e. have a mode to show clipped chars?
*/
// #include "config.h"
#include "TEWidget.h"
#include "session.h"
#include <qpe/config.h>
+#include <qpe/resource.h>
+#include <qpe/sound.h>
+
+#ifdef QWS
+#include <qpe/qcopenvelope_qws.h>
+#endif
+
#include <qcursor.h>
#include <qregexp.h>
#include <qpainter.h>
#include <qclipboard.h>
#include <qstyle.h>
#include <qfile.h>
#include <qdragobject.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
#include <assert.h>
// #include "TEWidget.moc"
//#include <kapp.h>
//#include <kcursor.h>
//#include <kurl.h>
//#include <kdebug.h>
//#include <klocale.h>
#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
#define loc(X,Y) ((Y)*columns+(X))
//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
#define rimX 0 // left/right rim width
#define rimY 0 // top/bottom rim high
#define SCRWIDTH 16 // width of the scrollbar
#define yMouseScroll 1
// scroll increment used when dragging selection at top/bottom of window.
/* ------------------------------------------------------------------------- */
/* */
/* Colors */
/* */
/* ------------------------------------------------------------------------- */
//FIXME: the default color table is in session.C now.
// We need a way to get rid of this one, here.
static const ColorEntry base_color_table[TABLE_COLORS] =
@@ -242,223 +249,230 @@ void TEWidget::fontChange(const QFont &)
//printf("font_h: %d\n",font_h);
//printf("font_w: %d\n",font_w);
//printf("font_a: %d\n",font_a);
//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
//printf("rawname: %s\n",font().rawName().ascii());
fontMap =
#if QT_VERSION < 300
strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
? vt100extended
:
#endif
identicalMap;
propagateSize();
update();
}
void TEWidget::setVTFont(const QFont& f)
{
QFrame::setFont(f);
}
QFont TEWidget::getVTFont() {
return font();
}
void TEWidget::setFont(const QFont &)
{
// ignore font change request if not coming from konsole itself
}
/* ------------------------------------------------------------------------- */
/* */
/* Constructor / Destructor */
/* */
/* ------------------------------------------------------------------------- */
TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
{
#ifndef QT_NO_CLIPBOARD
cb = QApplication::clipboard();
QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
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;
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];
-
-//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
- for (y = 0; y < lins; y++)
- {
+ 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 )
@@ -543,101 +557,108 @@ 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)
-{
+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.
*/
/*!
@@ -652,96 +673,97 @@ void TEWidget::mousePressEvent(QMouseEvent* ev)
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;
@@ -928,96 +950,100 @@ 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;
}
}
}
@@ -1033,153 +1059,258 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
if( ke->state() == ShiftButton && ke->key() == Key_Tab) {
//lets hardcode this sucker
// 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()
{
- QApplication::beep();
+//#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()
{
- //FIXME: set rimX == rimY == 0 when running in full screen mode.
+ 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;
- scrollbar->resize(QApplication::style().scrollBarExtent().width(),
+ 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;
- blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
- brX = blX;
- scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
+ 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
- lines = ( contentsRect().height() - 2 * rimY ) / font_h;
- bY = (contentsRect().height() - (lines *font_h)) / 2;
}
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
@@ -1221,48 +1352,56 @@ void TEWidget::dropEvent(QDropEvent* event)
}
// 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();
+}
+
+
diff --git a/core/apps/embeddedkonsole/TEWidget.h b/core/apps/embeddedkonsole/TEWidget.h
index 40e1aea..a480d45 100644
--- a/core/apps/embeddedkonsole/TEWidget.h
+++ b/core/apps/embeddedkonsole/TEWidget.h
@@ -15,188 +15,197 @@
/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
/* */
/* -------------------------------------------------------------------------- */
#ifndef TE_WIDGET_H
#define TE_WIDGET_H
#include <qwidget.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qcolor.h>
#include <qkeycode.h>
#include <qscrollbar.h>
#include <qpopupmenu.h>
#include "TECommon.h"
extern unsigned short vt100_graphics[32];
class TESession;
// class Konsole;
class TEWidget : public QFrame
// a widget representing attributed text
{ Q_OBJECT
// friend class Konsole;
public:
TEWidget(QWidget *parent=0, const char *name=0);
virtual ~TEWidget();
public:
QColor getDefaultBackColor();
const ColorEntry* getColorTable() const;
const ColorEntry* getdefaultColorTable() const;
void setColorTable(const ColorEntry table[]);
void setScrollbarLocation(int loc);
enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 };
void setScroll(int cursor, int lines);
void doScroll(int lines);
+ void doHScroll(int lines);
+
+
void emitSelection();
+ void setWrapAt(int columns);
public:
void setImage(const ca* const newimg, int lines, int columns);
int Lines() { return lines; }
int Columns() { return columns; }
void calcGeometry();
void propagateSize();
QSize calcSize(int cols, int lins) const;
QSize sizeHint() const;
public:
+ bool useHorzScroll;
void Bell();
void emitText(QString text);
void pasteClipboard();
signals:
void keyPressedSignal(QKeyEvent *e);
void mouseSignal(int cb, int cx, int cy);
void changedImageSizeSignal(int lines, int columns);
void changedHistoryCursor(int value);
+ void changedHorzCursor(int value);
void configureRequest( TEWidget*, int state, int x, int y );
void clearSelectionSignal();
void beginSelectionSignal( const int x, const int y );
void extendSelectionSignal( const int x, const int y );
void endSelectionSignal(const BOOL preserve_line_breaks);
protected:
-
virtual void styleChange( QStyle& );
bool eventFilter( QObject *, QEvent * );
void drawAttrStr(QPainter &paint, QRect rect,
QString& str, ca attr, BOOL pm, BOOL clear);
void paintEvent( QPaintEvent * );
void resizeEvent(QResizeEvent*);
void fontChange(const QFont &font);
void frameChanged();
void mouseDoubleClickEvent(QMouseEvent* ev);
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
void mouseMoveEvent( QMouseEvent* );
void focusInEvent( QFocusEvent * );
void focusOutEvent( QFocusEvent * );
bool focusNextPrevChild( bool next );
#ifndef QT_NO_DRAGANDDROP
// Dnd
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
#endif
virtual int charClass(char) const;
void clearImage();
public:
const QPixmap *backgroundPixmap();
void setSelection(const QString &t);
virtual void setFont(const QFont &);
void setVTFont(const QFont &);
QFont getVTFont();
void setMouseMarks(bool on);
public slots:
void onClearSelection();
protected slots:
void scrollChanged(int value);
+ void hScrollChanged(int value);
void blinkEvent();
private:
QChar (*fontMap)(QChar); // possible vt100 font extention
bool fixed_font; // has fixed pitch
int font_h; // height
int font_w; // width
int font_a; // ascend
int blX; // actual offset (left)
int brX; // actual offset (right)
int bY; // actual offset
int lines;
int columns;
ca *image; // [lines][columns]
ColorEntry color_table[TABLE_COLORS];
BOOL resizing;
bool mouse_marks;
void makeImage();
QPoint iPntSel; // initial selection point
QPoint pntSel; // current selection point
int actSel; // selection state
BOOL word_selection_mode;
BOOL preserve_line_breaks;
QClipboard* cb;
- QScrollBar* scrollbar;
- int scrollLoc;
+ QScrollBar* scrollbar, *hScrollbar;
+
+ int scrollLoc, hScrollLoc;
+ int hposition, vcolumns;
+
//#define SCRNONE 0
//#define SCRLEFT 1
//#define SCRRIGHT 2
BOOL blinking; // hide text in paintEvent
BOOL hasBlinker; // has characters to blink
QTimer* blinkT; // active when hasBlinker
QPopupMenu* m_drop;
QString dropText;
public:
// current session in this widget
TESession *currentSession;
private slots:
void drop_menu_activated(int item);
};
#endif // TE_WIDGET_H
diff --git a/core/apps/embeddedkonsole/TEmulation.cpp b/core/apps/embeddedkonsole/TEmulation.cpp
index 6f3ad32..c19f2a1 100644
--- a/core/apps/embeddedkonsole/TEmulation.cpp
+++ b/core/apps/embeddedkonsole/TEmulation.cpp
@@ -1,167 +1,177 @@
/* -------------------------------------------------------------------------- */
/* */
/* [TEmulation.cpp] Terminal Emulation Decoder */
/* */
/* -------------------------------------------------------------------------- */
/* */
/* 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> */
-/* */
+/* */
/* -------------------------------------------------------------------------- */
/*! \class TEmulation
\brief Mediator between TEWidget and TEScreen.
This class is responsible to scan the escapes sequences of the terminal
emulation and to map it to their corresponding semantic complements.
Thus this module knows mainly about decoding escapes sequences and
is a stateless device w.r.t. the semantics.
It is also responsible to refresh the TEWidget by certain rules.
\sa TEWidget \sa TEScreen
\par A note on refreshing
Although the modifications to the current screen image could immediately
be propagated via `TEWidget' to the graphical surface, we have chosen
another way here.
The reason for doing so is twofold.
First, experiments show that directly displaying the operation results
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 "TEmulation.h"
#include "TEWidget.h"
#include "TEScreen.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <qkeycode.h>
/* ------------------------------------------------------------------------- */
/* */
/* TEmulation */
/* */
/* ------------------------------------------------------------------------- */
#define CNTL(c) ((c)-'@')
/*!
*/
TEmulation::TEmulation(TEWidget* gui)
: decoder((QTextDecoder*)NULL)
{
this->gui = gui;
screen[0] = new TEScreen(gui->Lines(),gui->Columns());
screen[1] = new TEScreen(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)),
this,SLOT(onImageSizeChange(int,int)));
+
QObject::connect(gui,SIGNAL(changedHistoryCursor(int)),
this,SLOT(onHistoryCursorChange(int)));
+
+ QObject::connect(gui,SIGNAL(changedHorzCursor(int)),
+ this,SLOT(onHorzCursorChange(int)));
+
QObject::connect(gui,SIGNAL(keyPressedSignal(QKeyEvent*)),
this,SLOT(onKeyPress(QKeyEvent*)));
+
QObject::connect(gui,SIGNAL(beginSelectionSignal(const int,const int)),
- this,SLOT(onSelectionBegin(const int,const int)) );
+ this,SLOT(onSelectionBegin(const int,const int)) );
+
QObject::connect(gui,SIGNAL(extendSelectionSignal(const int,const int)),
- this,SLOT(onSelectionExtend(const int,const int)) );
+ this,SLOT(onSelectionExtend(const int,const int)) );
+
QObject::connect(gui,SIGNAL(endSelectionSignal(const BOOL)),
- this,SLOT(setSelection(const BOOL)) );
+ this,SLOT(setSelection(const BOOL)) );
+
QObject::connect(gui,SIGNAL(clearSelectionSignal()),
- this,SLOT(clearSelection()) );
+ this,SLOT(clearSelection()) );
}
/*!
*/
TEmulation::~TEmulation()
{
delete screen[0];
delete screen[1];
bulk_timer.stop();
}
/*! change between primary and alternate screen
*/
void TEmulation::setScreen(int n)
{
scr = screen[n&1];
}
void TEmulation::setHistory(bool on)
{
screen[0]->setScroll(on);
if (!connected) return;
showBulk();
}
bool TEmulation::history()
{
return screen[0]->hasScroll();
}
void TEmulation::setCodec(int c)
{
//FIXME: check whether we have to free codec
codec = c ? QTextCodec::codecForName("utf8")
: QTextCodec::codecForLocale();
if (decoder) delete decoder;
decoder = codec->makeDecoder();
}
void TEmulation::setKeytrans(int no)
{
keytrans = KeyTrans::find(no);
}
void TEmulation::setKeytrans(const char * no)
{
@@ -254,110 +264,115 @@ void TEmulation::onSelectionBegin(const int x, const int y) {
}
void TEmulation::onSelectionExtend(const int x, const int y) {
if (!connected) return;
scr->setSelExtentXY(x,y);
showBulk();
}
void TEmulation::setSelection(const BOOL preserve_line_breaks) {
if (!connected) return;
QString t = scr->getSelText(preserve_line_breaks);
if (!t.isNull()) gui->setSelection(t);
}
void TEmulation::clearSelection() {
if (!connected) return;
scr->clearSelection();
showBulk();
}
// Refreshing -------------------------------------------------------------- --
#define BULK_TIMEOUT 20
/*!
called when \n comes in. Evtl. triggers showBulk at endBulk
*/
void TEmulation::bulkNewline()
{
bulk_nlcnt += 1;
bulk_incnt = 0; // reset bulk counter since `nl' rule applies
}
/*!
*/
void TEmulation::showBulk()
{
bulk_nlcnt = 0; // reset bulk newline counter
bulk_incnt = 0; // reset bulk counter
if (connected)
{
ca* image = scr->getCookedImage(); // get the image
gui->setImage(image,
scr->getLines(),
scr->getColumns()); // actual refresh
free(image);
- //FIXME: check that we do not trigger other draw event here.
+
+ //FIXME: check that we do not trigger other draw event here.
gui->setScroll(scr->getHistCursor(),scr->getHistLines());
+
}
}
void TEmulation::bulkStart()
{
if (bulk_timer.isActive()) bulk_timer.stop();
}
void TEmulation::bulkEnd()
{
if ( bulk_nlcnt > gui->Lines() || bulk_incnt > 20 )
showBulk(); // resets bulk_??cnt to 0, too.
else
bulk_timer.start(BULK_TIMEOUT,TRUE);
}
void TEmulation::setConnect(bool c)
{
connected = c;
if ( connected)
{
onImageSizeChange(gui->Lines(), gui->Columns());
showBulk();
}
else
{
scr->clearSelection();
}
}
// ---------------------------------------------------------------------------
/*! triggered by image size change of the TEWidget `gui'.
This event is simply propagated to the attached screens
and to the related serial line.
*/
-void TEmulation::onImageSizeChange(int lines, int columns)
-{
+void TEmulation::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 TEmulation::onHistoryCursorChange(int cursor)
-{
+void TEmulation::onHistoryCursorChange(int cursor) {
if (!connected) return;
scr->setHistCursor(cursor);
showBulk();
}
-void TEmulation::setColumns(int columns)
-{
+void TEmulation::onHorzCursorChange(int cursor) {
+ if (!connected) return;
+ scr->setHorzCursor(cursor);
+ showBulk();
+}
+
+void TEmulation::setColumns(int columns) {
//FIXME: this goes strange ways.
// Can we put this straight or explain it at least?
emit changeColumns(columns);
}
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index a8ddc99..3c87ad4 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -313,111 +313,123 @@ void Konsole::init(const char* _pgm, QStrList & _args)
a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar );
a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar );
a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar );
a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar );
/*
a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar );
a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar );
*/
secondToolBar = new QPEToolBar( this );
secondToolBar->setHorizontalStretchable( TRUE );
commonCombo = new QComboBox( secondToolBar );
commonCombo->setMaximumWidth(236);
editCommandListMenu->insertItem( tr( "Quick Edit" ) );
if( listHidden) {
secondToolBar->hide();
editCommandListMenu->setItemEnabled(-23 ,FALSE);
}
editCommandListMenu->insertItem(tr( "Edit" ) );
cfg.setGroup("Commands");
commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
initCommandList();
// for (int i = 0; commonCmds[i] != NULL; i++) {
// commonCombo->insertItem( commonCmds[i], i );
// tmp = cfg.readEntry( QString::number(i),"");
// if(tmp != "")
// commonCombo->changeItem( tmp,i );
// }
connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
scrollMenu->insertItem(tr( "None" ));
scrollMenu->insertItem(tr( "Left" ));
scrollMenu->insertItem(tr( "Right" ));
+ scrollMenu->insertSeparator(4);
+ scrollMenu->insertItem(tr( "Horizontal" ));
+
configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
-
+//scrollMenuSelected(-29);
+// cfg.setGroup("ScrollBar");
+// if(cfg.readBoolEntry("HorzScroll",0)) {
+// if(cfg.readNumEntry("Position",2) == 0)
+// te->setScrollbarLocation(1);
+// else
+// te->setScrollbarLocation(0);
+// te->setScrollbarLocation( cfg.readNumEntry("Position",2));
+// te->setWrapAt(120);
+// }
// create applications /////////////////////////////////////////////////////
setCentralWidget(tab);
// load keymaps ////////////////////////////////////////////////////////////
KeyTrans::loadAll();
for (int i = 0; i < KeyTrans::count(); i++)
{ KeyTrans* s = KeyTrans::find(i);
assert( s );
}
se_pgm = _pgm;
se_args = _args;
-
+ se_args.prepend("--login");
parseCommandLine();
// read and apply default values ///////////////////////////////////////////
resize(321, 321); // Dummy.
QSize currentSize = size();
if (currentSize != size())
defaultSize = size();
}
void Konsole::show()
{
if ( !nsessions ) {
newSession();
}
QMainWindow::show();
}
void Konsole::initSession(const char*, QStrList &)
{
QMainWindow::show();
}
Konsole::~Konsole()
{
while (nsessions > 0) {
doneSession(getTe()->currentSession, 0);
}
Config cfg("Konsole");
cfg.setGroup("Konsole");
cfg.writeEntry("FontID", cfont);
}
void Konsole::fontChanged(int f)
{
VTFont* font = fonts.at(f);
if (font != 0) {
for(uint i = 0; i < fonts.count(); i++) {
fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
}
cfont = f;
TEWidget* te = getTe();
if (te != 0) {
te->setVTFont(font->getFont());
}
}
}
@@ -463,140 +475,143 @@ void Konsole::hitTab()
void Konsole::hitPaste()
{
TEWidget* te = getTe();
if (te != 0) {
te->pasteClipboard();
}
}
void Konsole::hitUp()
{
TEWidget* te = getTe();
if (te != 0) {
QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
QApplication::sendEvent( te, &ke );
}
}
void Konsole::hitDown()
{
TEWidget* te = getTe();
if (te != 0) {
QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
QApplication::sendEvent( te, &ke );
}
}
/**
This function calculates the size of the external widget
needed for the internal widget to be
*/
QSize Konsole::calcSize(int columns, int lines) {
TEWidget* te = getTe();
if (te != 0) {
QSize size = te->calcSize(columns, lines);
return size;
} else {
QSize size;
return size;
}
}
/**
sets application window to a size based on columns X lines of the te
guest widget. Call with (0,0) for setting default size.
*/
void Konsole::setColLin(int columns, int lines)
{
+ qDebug("konsole::setColLin:: Columns %d", columns);
+
if ((columns==0) || (lines==0))
{
if (defaultSize.isEmpty()) // not in config file : set default value
{
defaultSize = calcSize(80,24);
// notifySize(24,80); // set menu items (strange arg order !)
}
resize(defaultSize);
} else {
resize(calcSize(columns, lines));
// notifySize(lines,columns); // set menu items (strange arg order !)
}
}
/*
void Konsole::setFont(int fontno)
{
QFont f;
if (fontno == 0)
f = defaultFont = QFont( "Helvetica", 12 );
else
if (fonts[fontno][0] == '-')
f.setRawName( fonts[fontno] );
else
{
f.setFamily(fonts[fontno]);
f.setRawMode( TRUE );
}
if ( !f.exactMatch() && fontno != 0)
{
QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
QMessageBox(this, msg);
return;
}
if (se) se->setFontNo(fontno);
te->setVTFont(f);
n_font = fontno;
}
*/
// --| color selection |-------------------------------------------------------
void Konsole::changeColumns(int columns)
{
+ qDebug("change columns");
TEWidget* te = getTe();
if (te != 0) {
setColLin(columns,te->Lines());
te->update();
}
}
//FIXME: If a child dies during session swap,
// this routine might be called before
// session swap is completed.
void Konsole::doneSession(TESession*, int )
{
TEWidget *te = getTe();
if (te != 0) {
te->currentSession->setConnect(FALSE);
tab->removeTab(te);
delete te->currentSession;
delete te;
nsessions--;
}
if (nsessions == 0) {
close();
}
}
void Konsole::newSession() {
if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory?
TEWidget* te = new TEWidget(tab);
// te->setBackgroundMode(PaletteBase); //we want transparent!!
te->setVTFont(fonts.at(cfont)->getFont());
tab->addTab(te);
TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
te->currentSession = se;
connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) );
se->run();
se->setConnect(TRUE);
se->setHistory(b_scroll);
tab->setCurrentPage(nsessions);
nsessions++;
setColor();
}
}
TEWidget* Konsole::getTe() {
if (nsessions) {
return (TEWidget *) tab->currentPage();
@@ -755,114 +770,125 @@ void Konsole::colorMenuSelected(int iD)
update();
}
void Konsole::configMenuSelected(int iD)
{
// QString temp;
// qDebug( temp.sprintf("configmenu %d",iD));
TEWidget* te = getTe();
Config cfg("Konsole");
cfg.setGroup("Menubar");
if( iD == -4) {
cfg.setGroup("Tabs");
QString tmp=cfg.readEntry("Position","Bottom");
if(tmp=="Top") {
tab->setTabPosition(QTabWidget::Bottom);
configMenu->changeItem( iD,"Tabs on Top");
cfg.writeEntry("Position","Bottom");
} else {
tab->setTabPosition(QTabWidget::Top);
configMenu->changeItem( iD,"Tabs on Bottom");
cfg.writeEntry("Position","Top");
}
}
}
void Konsole::changeCommand(const QString &text, int c)
{
Config cfg("Konsole");
cfg.setGroup("Commands");
if(commonCmds[c] != text) {
cfg.writeEntry(QString::number(c),text);
commonCombo->clearEdit();
commonCombo->setCurrentItem(c);
}
}
void Konsole::setColor()
{
Config cfg("Konsole");
cfg.setGroup("Colors");
int scheme = cfg.readNumEntry("Schema",1);
if(scheme != 1) colorMenuSelected( -scheme);
}
void Konsole::scrollMenuSelected(int index)
{
-// QString temp;
-// qDebug( temp.sprintf("scrollbar menu %d",index));
+ qDebug( "scrollbar menu %d",index);
TEWidget* te = getTe();
Config cfg("Konsole");
cfg.setGroup("ScrollBar");
switch( index){
case -25:
te->setScrollbarLocation(0);
cfg.writeEntry("Position",0);
break;
case -26:
te->setScrollbarLocation(1);
cfg.writeEntry("Position",1);
break;
case -27:
te->setScrollbarLocation(2);
cfg.writeEntry("Position",2);
break;
+ case -29: {
+ bool b=cfg.readBoolEntry("HorzScroll",0);
+ cfg.writeEntry("HorzScroll", !b );
+ cfg.write();
+ if(cfg.readNumEntry("Position",2) == 0)
+ te->setScrollbarLocation(1);
+ else
+ te->setScrollbarLocation(0);
+ te->setScrollbarLocation( cfg.readNumEntry("Position",2));
+ te->setWrapAt(120);
+ }
+ break;
};
}
void Konsole::editCommandListMenuSelected(int iD)
{
// QString temp;
// qDebug( temp.sprintf("edit command list %d",iD));
TEWidget* te = getTe();
Config cfg("Konsole");
cfg.setGroup("Menubar");
if( iD == -3) {
if(!secondToolBar->isHidden()) {
secondToolBar->hide();
configMenu->changeItem( iD,tr( "Show Command List" ));
cfg.writeEntry("Hidden","TRUE");
configMenu->setItemEnabled(-23 ,FALSE);
} else {
secondToolBar->show();
configMenu->changeItem( iD,tr( "Hide Command List" ));
cfg.writeEntry("Hidden","FALSE");
configMenu->setItemEnabled(-23 ,TRUE);
if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") {
configMenu->setItemChecked(-23,TRUE);
commonCombo->setEditable( TRUE );
} else {
configMenu->setItemChecked(-23,FALSE);
commonCombo->setEditable( FALSE );
}
}
}
if( iD == -23) {
cfg.setGroup("Commands");
// qDebug("enableCommandEdit");
if( !configMenu->isItemChecked(iD) ) {
commonCombo->setEditable( TRUE );
configMenu->setItemChecked(iD,TRUE);
commonCombo->setCurrentItem(0);
cfg.writeEntry("EditEnabled","TRUE");
} else {
commonCombo->setEditable( FALSE );
configMenu->setItemChecked(iD,FALSE);
cfg.writeEntry("EditEnabled","FALSE");
commonCombo->setFocusPolicy(QWidget::NoFocus);
te->setFocus();
}
}