summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-02-17 00:56:19 (UTC)
committer llornkcor <llornkcor>2003-02-17 00:56:19 (UTC)
commit0c50793d0ef839e90b9b2dea5001c3170971fc06 (patch) (unidiff)
tree7cb670b64059524eab1130212ba1c43ebed66720
parent4d0e8ffd8518fe24ed94cfcf92eeff666b014094 (diff)
downloadopie-0c50793d0ef839e90b9b2dea5001c3170971fc06.zip
opie-0c50793d0ef839e90b9b2dea5001c3170971fc06.tar.gz
opie-0c50793d0ef839e90b9b2dea5001c3170971fc06.tar.bz2
fixes bug 671 - clipboard copy causes new line
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index 23720cd..a989e10 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -838,328 +838,332 @@ void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
838 if (!mouse_marks && !(ev->state() & ShiftButton)) 838 if (!mouse_marks && !(ev->state() & ShiftButton))
839 { 839 {
840 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 840 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
841 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 841 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
842 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 842 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
843 return; 843 return;
844 } 844 }
845 845
846 846
847 emit clearSelectionSignal(); 847 emit clearSelectionSignal();
848 QPoint bgnSel = pos; 848 QPoint bgnSel = pos;
849 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 849 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
850 int i = loc(bgnSel.x(),bgnSel.y()); 850 int i = loc(bgnSel.x(),bgnSel.y());
851 iPntSel = bgnSel; 851 iPntSel = bgnSel;
852 852
853 word_selection_mode = TRUE; 853 word_selection_mode = TRUE;
854 854
855 // find word boundaries... 855 // find word boundaries...
856 int selClass = charClass(image[i].c); 856 int selClass = charClass(image[i].c);
857 { 857 {
858 // set the start... 858 // set the start...
859 int x = bgnSel.x(); 859 int x = bgnSel.x();
860 while ( x > 0 && charClass(image[i-1].c) == selClass ) 860 while ( x > 0 && charClass(image[i-1].c) == selClass )
861 { i--; x--; } 861 { i--; x--; }
862 bgnSel.setX(x); 862 bgnSel.setX(x);
863 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 863 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
864 864
865 // set the end... 865 // set the end...
866 i = loc( endSel.x(), endSel.y() ); 866 i = loc( endSel.x(), endSel.y() );
867 x = endSel.x(); 867 x = endSel.x();
868 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 868 while( x < columns-1 && charClass(image[i+1].c) == selClass )
869 { i++; x++ ; } 869 { i++; x++ ; }
870 endSel.setX(x); 870 endSel.setX(x);
871 actSel = 2; // within selection 871 actSel = 2; // within selection
872 emit extendSelectionSignal( endSel.x(), endSel.y() ); 872 emit extendSelectionSignal( endSel.x(), endSel.y() );
873 emit endSelectionSignal(preserve_line_breaks); 873 emit endSelectionSignal(preserve_line_breaks);
874 preserve_line_breaks = TRUE; 874 preserve_line_breaks = TRUE;
875 } 875 }
876} 876}
877 877
878void TEWidget::focusInEvent( QFocusEvent * ) 878void TEWidget::focusInEvent( QFocusEvent * )
879{ 879{
880 880
881 // do nothing, to prevent repainting 881 // do nothing, to prevent repainting
882} 882}
883 883
884 884
885void TEWidget::focusOutEvent( QFocusEvent * ) 885void TEWidget::focusOutEvent( QFocusEvent * )
886{ 886{
887 // do nothing, to prevent repainting 887 // do nothing, to prevent repainting
888} 888}
889 889
890bool TEWidget::focusNextPrevChild( bool next ) 890bool TEWidget::focusNextPrevChild( bool next )
891{ 891{
892 if (next) 892 if (next)
893 return false; // This disables changing the active part in konqueror 893 return false; // This disables changing the active part in konqueror
894 // when pressing Tab 894 // when pressing Tab
895 return QFrame::focusNextPrevChild( next ); 895 return QFrame::focusNextPrevChild( next );
896} 896}
897 897
898 898
899int TEWidget::charClass(char ch) const 899int TEWidget::charClass(char ch) const
900{ 900{
901 // This might seem like overkill, but imagine if ch was a Unicode 901 // This might seem like overkill, but imagine if ch was a Unicode
902 // character (Qt 2.0 QChar) - it might then be sensible to separate 902 // character (Qt 2.0 QChar) - it might then be sensible to separate
903 // the different language ranges, etc. 903 // the different language ranges, etc.
904 904
905 if ( isspace(ch) ) return ' '; 905 if ( isspace(ch) ) return ' ';
906 906
907 static const char *word_characters = ":@-./_~"; 907 static const char *word_characters = ":@-./_~";
908 if ( isalnum(ch) || strchr(word_characters, ch) ) 908 if ( isalnum(ch) || strchr(word_characters, ch) )
909 return 'a'; 909 return 'a';
910 910
911 // Everything else is weird 911 // Everything else is weird
912 return 1; 912 return 1;
913} 913}
914 914
915void TEWidget::setMouseMarks(bool on) 915void TEWidget::setMouseMarks(bool on)
916{ 916{
917 mouse_marks = on; 917 mouse_marks = on;
918 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 918 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
919} 919}
920 920
921/* ------------------------------------------------------------------------- */ 921/* ------------------------------------------------------------------------- */
922/* */ 922/* */
923/* Clipboard */ 923/* Clipboard */
924/* */ 924/* */
925/* ------------------------------------------------------------------------- */ 925/* ------------------------------------------------------------------------- */
926 926
927#undef KeyPress 927#undef KeyPress
928 928
929void TEWidget::emitSelection() 929void TEWidget::emitSelection()
930// Paste Clipboard by simulating keypress events 930// Paste Clipboard by simulating keypress events
931{ 931{
932#ifndef QT_NO_CLIPBOARD 932#ifndef QT_NO_CLIPBOARD
933 QString text = QApplication::clipboard()->text(); 933 QString text = QApplication::clipboard()->text();
934 if ( ! text.isNull() ) 934 //qDebug(text);
935 if ( ! text.isNull())
935 { 936 {
936 text.replace(QRegExp("\n"), "\r"); 937 text.replace(QRegExp("\n"), "\r");
937 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 938 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
938 emit keyPressedSignal(&e); // expose as a big fat keypress event 939 emit keyPressedSignal(&e); // expose as a big fat keypress event
939 emit clearSelectionSignal(); 940 emit clearSelectionSignal();
940 } 941 }
941#endif 942#endif
942} 943}
943 944
944void TEWidget::emitText(QString text) 945void TEWidget::emitText(QString text)
945{ 946{
946 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 947 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
947 emit keyPressedSignal(&e); // expose as a big fat keypress event 948 emit keyPressedSignal(&e); // expose as a big fat keypress event
948} 949}
949 950
950void TEWidget::pasteClipboard( ) 951void TEWidget::pasteClipboard( )
951{ 952{
952 emitSelection(); 953 emitSelection();
953} 954}
954 955
955void TEWidget::setSelection(const QString& t) 956void TEWidget::setSelection(const QString& t)
956{ 957{
957#ifndef QT_NO_CLIPBOARD 958#ifndef QT_NO_CLIPBOARD
958 // Disconnect signal while WE set the clipboard 959 // Disconnect signal while WE set the clipboard
959 QObject *cb = QApplication::clipboard(); 960 QObject *cb = QApplication::clipboard();
960 QObject::disconnect( cb, SIGNAL(dataChanged()), 961 QObject::disconnect( cb, SIGNAL(dataChanged()),
961 this, SLOT(onClearSelection()) ); 962 this, SLOT(onClearSelection()) );
962 963
963 QApplication::clipboard()->setText(t); 964 QApplication::clipboard()->setText(t);
964 965
965 QObject::connect( cb, SIGNAL(dataChanged()), 966 QObject::connect( cb, SIGNAL(dataChanged()),
966 this, SLOT(onClearSelection()) ); 967 this, SLOT(onClearSelection()) );
967#endif 968#endif
968} 969}
969 970
970void TEWidget::onClearSelection() 971void TEWidget::onClearSelection()
971{ 972{
972 emit clearSelectionSignal(); 973 emit clearSelectionSignal();
973} 974}
974 975
975/* ------------------------------------------------------------------------- */ 976/* ------------------------------------------------------------------------- */
976/* */ 977/* */
977/* Keyboard */ 978/* Keyboard */
978/* */ 979/* */
979/* ------------------------------------------------------------------------- */ 980/* ------------------------------------------------------------------------- */
980 981
981//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 982//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
982// due to a bug in `QT' or the ignorance of the author to prevent 983// due to a bug in `QT' or the ignorance of the author to prevent
983// repaint events being emitted to the screen whenever one leaves 984// repaint events being emitted to the screen whenever one leaves
984// or reenters the screen to/from another application. 985// or reenters the screen to/from another application.
985// 986//
986// Troll says one needs to change focusInEvent() and focusOutEvent(), 987// Troll says one needs to change focusInEvent() and focusOutEvent(),
987// which would also let you have an in-focus cursor and an out-focus 988// which would also let you have an in-focus cursor and an out-focus
988// cursor like xterm does. 989// cursor like xterm does.
989 990
990// for the auto-hide cursor feature, I added empty focusInEvent() and 991// for the auto-hide cursor feature, I added empty focusInEvent() and
991// focusOutEvent() so that update() isn't called. 992// focusOutEvent() so that update() isn't called.
992// For auto-hide, we need to get keypress-events, but we only get them when 993// For auto-hide, we need to get keypress-events, but we only get them when
993// we have focus. 994// we have focus.
994 995
995void TEWidget::doScroll(int lines) 996void TEWidget::doScroll(int lines)
996{ 997{
997 scrollbar->setValue(scrollbar->value()+lines); 998 scrollbar->setValue(scrollbar->value()+lines);
998} 999}
999 1000
1000void TEWidget::doHScroll(int lines) { 1001void TEWidget::doHScroll(int lines) {
1001 hScrollbar->setValue( hScrollbar->value()+lines); 1002 hScrollbar->setValue( hScrollbar->value()+lines);
1002} 1003}
1003 1004
1004bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1005bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1005{ 1006{
1006 if ( (e->type() == QEvent::Accel || 1007 if ( (e->type() == QEvent::Accel ||
1007 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1008 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1008 static_cast<QKeyEvent *>( e )->ignore(); 1009 static_cast<QKeyEvent *>( e )->ignore();
1009 return true; 1010 return true;
1010 } 1011 }
1011 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1012 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1012 return FALSE; // not us 1013 return FALSE; // not us
1013 if ( e->type() == QEvent::Wheel) { 1014 if ( e->type() == QEvent::Wheel) {
1014 QApplication::sendEvent(scrollbar, e); 1015 QApplication::sendEvent(scrollbar, e);
1015 } 1016 }
1016 1017
1017#ifdef FAKE_CTRL_AND_ALT 1018#ifdef FAKE_CTRL_AND_ALT
1018 static bool control = FALSE; 1019 static bool control = FALSE;
1019 static bool alt = FALSE; 1020 static bool alt = FALSE;
1020// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1021// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
1021 bool dele=FALSE; 1022 bool dele=FALSE;
1022 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1023 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1023 QKeyEvent* ke = (QKeyEvent*)e; 1024 QKeyEvent* ke = (QKeyEvent*)e;
1024 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1025 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1025 switch (ke->key()) { 1026 switch (ke->key()) {
1026 case Key_F9: // let this be "Control" 1027 case Key_F9: // let this be "Control"
1027 control = keydown; 1028 control = keydown;
1028 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1029 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1029 dele=TRUE; 1030 dele=TRUE;
1030 break; 1031 break;
1031 case Key_F13: // let this be "Alt" 1032 case Key_F13: // let this be "Alt"
1032 alt = keydown; 1033 alt = keydown;
1033 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1034 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1034 dele=TRUE; 1035 dele=TRUE;
1035 break; 1036 break;
1036 default: 1037 default:
1037 if ( control ) { 1038 if ( control ) {
1038 int a = toupper(ke->ascii())-64; 1039 int a = toupper(ke->ascii())-64;
1039 if ( a >= 0 && a < ' ' ) { 1040 if ( a >= 0 && a < ' ' ) {
1040 e = new QKeyEvent(e->type(), ke->key(), 1041 e = new QKeyEvent(e->type(), ke->key(),
1041 a, ke->state()|ControlButton, QChar(a,0)); 1042 a, ke->state()|ControlButton, QChar(a,0));
1042 dele=TRUE; 1043 dele=TRUE;
1043 } 1044 }
1044 } 1045 }
1045 if ( alt ) { 1046 if ( alt ) {
1046 e = new QKeyEvent(e->type(), ke->key(), 1047 e = new QKeyEvent(e->type(), ke->key(),
1047 ke->ascii(), ke->state()|AltButton, ke->text()); 1048 ke->ascii(), ke->state()|AltButton, ke->text());
1048 dele=TRUE; 1049 dele=TRUE;
1049 } 1050 }
1050 } 1051 }
1051 } 1052 }
1052#endif 1053#endif
1053 1054
1054 if ( e->type() == QEvent::KeyPress ) { 1055 if ( e->type() == QEvent::KeyPress ) {
1055 QKeyEvent* ke = (QKeyEvent*)e; 1056 QKeyEvent* ke = (QKeyEvent*)e;
1056 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1057 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1057 // know where the current selection is. 1058 // know where the current selection is.
1058 1059
1059// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); 1060// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state());
1060 1061
1061 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { 1062 if( ke->state() == ShiftButton && ke->key() == Key_Tab) {
1062 //lets hardcode this sucker 1063 //lets hardcode this sucker
1063 1064
1064// qDebug("key pressed 2 is 0x%x", ke->key()); 1065// qDebug("key pressed 2 is 0x%x", ke->key());
1065 emitText("\\"); // expose 1066 emitText("\\"); // expose
1066 } 1067 }
1067 else if( ke->state() == ControlButton && ke->key() == Key_V) { 1068 else if( ke->state() == ControlButton && ke->key() == Key_V) {
1068 pasteClipboard(); 1069 pasteClipboard();
1069 } 1070 }
1071 else if( ke->state() == ControlButton && ke->key() == Key_C) {
1072// pasteClipboard();
1073 }
1070 else 1074 else
1071 emit keyPressedSignal(ke); // expose 1075 emit keyPressedSignal(ke); // expose
1072 ke->accept(); 1076 ke->accept();
1073#ifdef FAKE_CTRL_AND_ALT 1077#ifdef FAKE_CTRL_AND_ALT
1074 if ( dele ) delete e; 1078 if ( dele ) delete e;
1075#endif 1079#endif
1076 return true; // stop the event 1080 return true; // stop the event
1077 } 1081 }
1078 if ( e->type() == QEvent::Enter ) { 1082 if ( e->type() == QEvent::Enter ) {
1079 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1083 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1080 this, SLOT(onClearSelection()) ); 1084 this, SLOT(onClearSelection()) );
1081 } 1085 }
1082 if ( e->type() == QEvent::Leave ) { 1086 if ( e->type() == QEvent::Leave ) {
1083 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1087 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1084 this, SLOT(onClearSelection()) ); 1088 this, SLOT(onClearSelection()) );
1085 } 1089 }
1086 return QFrame::eventFilter( obj, e ); 1090 return QFrame::eventFilter( obj, e );
1087} 1091}
1088 1092
1089/* ------------------------------------------------------------------------- */ 1093/* ------------------------------------------------------------------------- */
1090/* */ 1094/* */
1091/* Frame */ 1095/* Frame */
1092/* */ 1096/* */
1093/* ------------------------------------------------------------------------- */ 1097/* ------------------------------------------------------------------------- */
1094 1098
1095void TEWidget::frameChanged() 1099void TEWidget::frameChanged()
1096{ 1100{
1097 propagateSize(); 1101 propagateSize();
1098 update(); 1102 update();
1099} 1103}
1100 1104
1101/* ------------------------------------------------------------------------- */ 1105/* ------------------------------------------------------------------------- */
1102/* */ 1106/* */
1103/* Sound */ 1107/* Sound */
1104/* */ 1108/* */
1105/* ------------------------------------------------------------------------- */ 1109/* ------------------------------------------------------------------------- */
1106 1110
1107void TEWidget::Bell() 1111void TEWidget::Bell()
1108{ 1112{
1109//#ifdef QT_QWS_SHARP 1113//#ifdef QT_QWS_SHARP
1110//# ifndef QT_NO_COP 1114//# ifndef QT_NO_COP
1111 if(useBeep) 1115 if(useBeep)
1112 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 1116 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
1113 1117
1114//# endif 1118//# endif
1115//#else 1119//#else
1116//# ifndef QT_NO_SOUND 1120//# ifndef QT_NO_SOUND
1117// QSound::play(Resource::findSound("alarm")); 1121// QSound::play(Resource::findSound("alarm"));
1118//# endif 1122//# endif
1119//#endif 1123//#endif
1120 1124
1121// QApplication::beep(); 1125// QApplication::beep();
1122} 1126}
1123 1127
1124/* ------------------------------------------------------------------------- */ 1128/* ------------------------------------------------------------------------- */
1125/* */ 1129/* */
1126/* Auxiluary */ 1130/* Auxiluary */
1127/* */ 1131/* */
1128/* ------------------------------------------------------------------------- */ 1132/* ------------------------------------------------------------------------- */
1129 1133
1130void TEWidget::clearImage() 1134void TEWidget::clearImage()
1131// initialize the image 1135// initialize the image
1132// for internal use only 1136// for internal use only
1133{ 1137{
1134 for (int y = 0; y < lines; y++) 1138 for (int y = 0; y < lines; y++)
1135 for (int x = 0; x < columns; x++) 1139 for (int x = 0; x < columns; x++)
1136 { 1140 {
1137 image[loc(x,y)].c = 0xff; //' '; 1141 image[loc(x,y)].c = 0xff; //' ';
1138 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1142 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1139 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1143 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1140 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1144 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1141 } 1145 }
1142} 1146}
1143 1147
1144// Create Image /////////////////////////////////////////////////////// 1148// Create Image ///////////////////////////////////////////////////////
1145 1149
1146void TEWidget::calcGeometry() 1150void TEWidget::calcGeometry()
1147{ 1151{
1148 int showhscrollbar = 1; 1152 int showhscrollbar = 1;
1149 int hwidth = 0; 1153 int hwidth = 0;
1150 int dcolumns; 1154 int dcolumns;
1151 Config cfg("Konsole"); 1155 Config cfg("Konsole");
1152 cfg.setGroup("ScrollBar"); 1156 cfg.setGroup("ScrollBar");
1153 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 1157 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
1154 1158
1155 if(vcolumns == 0) showhscrollbar = 0; 1159 if(vcolumns == 0) showhscrollbar = 0;
1156 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1160 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1157 1161
1158 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1162 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1159 contentsRect().height() - hwidth); 1163 contentsRect().height() - hwidth);
1160 1164
1161 switch(scrollLoc) { 1165 switch(scrollLoc) {
1162 case SCRNONE : 1166 case SCRNONE :
1163 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1167 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1164 dcolumns = columns; 1168 dcolumns = columns;
1165 if(vcolumns) columns = vcolumns; 1169 if(vcolumns) columns = vcolumns;