author | llornkcor <llornkcor> | 2004-04-25 13:05:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-04-25 13:05:00 (UTC) |
commit | 4e4586dc20a0a8befe808d7c89ee2fb3222c63b6 (patch) (unidiff) | |
tree | 3d67622f58160d0df8e69f75129be1ef6cdb9d03 /library | |
parent | 6182b509bdb16dd4d1e95b9a570219ef6c15ed21 (diff) | |
download | opie-4e4586dc20a0a8befe808d7c89ee2fb3222c63b6.zip opie-4e4586dc20a0a8befe808d7c89ee2fb3222c63b6.tar.gz opie-4e4586dc20a0a8befe808d7c89ee2fb3222c63b6.tar.bz2 |
escape close
-rw-r--r-- | library/qpeapplication.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index d0e9613..040b2fe 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -999,262 +999,264 @@ QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) | |||
999 | 999 | ||
1000 | /*! | 1000 | /*! |
1001 | \enum QPEApplication::InputMethodHint | 1001 | \enum QPEApplication::InputMethodHint |
1002 | 1002 | ||
1003 | \value Normal the application sometimes needs text input (the default). | 1003 | \value Normal the application sometimes needs text input (the default). |
1004 | \value AlwaysOff the application never needs text input. | 1004 | \value AlwaysOff the application never needs text input. |
1005 | \value AlwaysOn the application always needs text input. | 1005 | \value AlwaysOn the application always needs text input. |
1006 | */ | 1006 | */ |
1007 | 1007 | ||
1008 | /*! | 1008 | /*! |
1009 | Hints to the system that widget \a w has use for text input methods | 1009 | Hints to the system that widget \a w has use for text input methods |
1010 | as specified by \a mode. | 1010 | as specified by \a mode. |
1011 | 1011 | ||
1012 | \sa inputMethodHint() InputMethodHint | 1012 | \sa inputMethodHint() InputMethodHint |
1013 | */ | 1013 | */ |
1014 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) | 1014 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) |
1015 | { | 1015 | { |
1016 | createInputMethodDict(); | 1016 | createInputMethodDict(); |
1017 | if ( mode == Normal ) { | 1017 | if ( mode == Normal ) { |
1018 | inputMethodDict->remove | 1018 | inputMethodDict->remove |
1019 | ( w ); | 1019 | ( w ); |
1020 | } | 1020 | } |
1021 | else { | 1021 | else { |
1022 | inputMethodDict->insert( w, ( void* ) mode ); | 1022 | inputMethodDict->insert( w, ( void* ) mode ); |
1023 | } | 1023 | } |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | class HackDialog : public QDialog | 1026 | class HackDialog : public QDialog |
1027 | { | 1027 | { |
1028 | public: | 1028 | public: |
1029 | void acceptIt() | 1029 | void acceptIt() |
1030 | { | 1030 | { |
1031 | accept(); | 1031 | accept(); |
1032 | } | 1032 | } |
1033 | void rejectIt() | 1033 | void rejectIt() |
1034 | { | 1034 | { |
1035 | reject(); | 1035 | reject(); |
1036 | } | 1036 | } |
1037 | }; | 1037 | }; |
1038 | 1038 | ||
1039 | 1039 | ||
1040 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) | 1040 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) |
1041 | { | 1041 | { |
1042 | // specialised actions for certain widgets. May want to | 1042 | // specialised actions for certain widgets. May want to |
1043 | // add more stuff here. | 1043 | // add more stuff here. |
1044 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) | 1044 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) |
1045 | && activePopupWidget() ->parentWidget() | 1045 | && activePopupWidget() ->parentWidget() |
1046 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) | 1046 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) |
1047 | key = Qt::Key_Return; | 1047 | key = Qt::Key_Return; |
1048 | 1048 | ||
1049 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) | 1049 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) |
1050 | key = Qt::Key_Return; | 1050 | key = Qt::Key_Return; |
1051 | 1051 | ||
1052 | #ifdef QWS | 1052 | #ifdef QWS |
1053 | 1053 | ||
1054 | ke->simpleData.keycode = key; | 1054 | ke->simpleData.keycode = key; |
1055 | #endif | 1055 | #endif |
1056 | } | 1056 | } |
1057 | 1057 | ||
1058 | 1058 | ||
1059 | /*! | 1059 | /*! |
1060 | \internal | 1060 | \internal |
1061 | */ | 1061 | */ |
1062 | 1062 | ||
1063 | #ifdef QWS | 1063 | #ifdef QWS |
1064 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) | 1064 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) |
1065 | { | 1065 | { |
1066 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { | 1066 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { |
1067 | if ( qApp->type() != QApplication::GuiServer ) { | 1067 | if ( qApp->type() != QApplication::GuiServer ) { |
1068 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); | 1068 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); |
1069 | e << d->appName; | 1069 | e << d->appName; |
1070 | } | 1070 | } |
1071 | d->notbusysent = TRUE; | 1071 | d->notbusysent = TRUE; |
1072 | } | 1072 | } |
1073 | if ( type() == GuiServer ) { | 1073 | if ( type() == GuiServer ) { |
1074 | switch ( e->type ) { | 1074 | switch ( e->type ) { |
1075 | case QWSEvent::Mouse: | 1075 | case QWSEvent::Mouse: |
1076 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) | 1076 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) |
1077 | emit clientMoused(); | 1077 | emit clientMoused(); |
1078 | break; | 1078 | break; |
1079 | default: | 1079 | default: |
1080 | break; | 1080 | break; |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | if ( e->type == QWSEvent::Key ) { | 1083 | if ( e->type == QWSEvent::Key ) { |
1084 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; | 1084 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; |
1085 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { | 1085 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { |
1086 | // Use special "OK" key to press "OK" on top level widgets | 1086 | // Use special "OK" key to press "OK" on top level widgets |
1087 | QWidget * active = activeWindow(); | 1087 | QWidget * active = activeWindow(); |
1088 | QWidget *popup = 0; | 1088 | QWidget *popup = 0; |
1089 | if ( active && active->isPopup() ) { | 1089 | if ( active && active->isPopup() ) { |
1090 | popup = active; | 1090 | popup = active; |
1091 | active = active->parentWidget(); | 1091 | active = active->parentWidget(); |
1092 | } | 1092 | } |
1093 | if ( active && ( int ) active->winId() == ke->simpleData.window && | 1093 | if ( active && ( int ) active->winId() == ke->simpleData.window && |
1094 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 1094 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
1095 | if ( ke->simpleData.is_press ) { | 1095 | if ( ke->simpleData.is_press ) { |
1096 | if ( popup ) | 1096 | if ( popup ) |
1097 | popup->close(); | 1097 | popup->close(); |
1098 | if ( active->inherits( "QDialog" ) ) { | 1098 | if ( active->inherits( "QDialog" ) ) { |
1099 | HackDialog * d = ( HackDialog * ) active; | 1099 | HackDialog * d = ( HackDialog * ) active; |
1100 | d->acceptIt(); | 1100 | d->acceptIt(); |
1101 | return TRUE; | 1101 | return TRUE; |
1102 | } | 1102 | } |
1103 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { | 1103 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { |
1104 | QSignal s; | 1104 | QSignal s; |
1105 | s.connect( active, SLOT( accept() ) ); | 1105 | s.connect( active, SLOT( accept() ) ); |
1106 | s.activate(); | 1106 | s.activate(); |
1107 | } | 1107 | } |
1108 | else { | 1108 | else { |
1109 | // do the same as with the select key: Map to the default action of the widget: | 1109 | // do the same as with the select key: Map to the default action of the widget: |
1110 | mapToDefaultAction( ke, Qt::Key_Return ); | 1110 | mapToDefaultAction( ke, Qt::Key_Return ); |
1111 | } | 1111 | } |
1112 | } | 1112 | } |
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { | 1115 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { |
1116 | // Use special "select" key to do whatever default action a widget has | 1116 | // Use special "select" key to do whatever default action a widget has |
1117 | mapToDefaultAction( ke, Qt::Key_Space ); | 1117 | mapToDefaultAction( ke, Qt::Key_Space ); |
1118 | } | 1118 | } |
1119 | else if ( ke->simpleData.keycode == Qt::Key_Escape && | 1119 | else if ( ke->simpleData.keycode == Qt::Key_Escape && |
1120 | ke->simpleData.is_press ) { | 1120 | ke->simpleData.is_press ) { |
1121 | // Escape key closes app if focus on toplevel | 1121 | // Escape key closes app if focus on toplevel |
1122 | QWidget * active = activeWindow(); | 1122 | QWidget * active = activeWindow(); |
1123 | if ( active && active->testWFlags( WType_TopLevel ) && | 1123 | if ( active && active->testWFlags( WType_TopLevel ) && |
1124 | ( int ) active->winId() == ke->simpleData.window && | 1124 | ( int ) active->winId() == ke->simpleData.window && |
1125 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 1125 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
1126 | if ( active->inherits( "QDialog" ) ) { | 1126 | if ( active->inherits( "QDialog" ) ) { |
1127 | qDebug("dialog hack"); | ||
1128 | HackDialog * d = ( HackDialog * ) active; | 1127 | HackDialog * d = ( HackDialog * ) active; |
1129 | d->rejectIt(); | 1128 | d->rejectIt(); |
1130 | return TRUE; | 1129 | return TRUE; |
1130 | } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { | ||
1131 | active->close(); | ||
1131 | } | 1132 | } |
1132 | } | 1133 | } |
1134 | |||
1133 | } | 1135 | } |
1134 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { | 1136 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { |
1135 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) | 1137 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) |
1136 | // but we cannot access libopie function within libqpe :( | 1138 | // but we cannot access libopie function within libqpe :( |
1137 | 1139 | ||
1138 | QWidget * active = activeWindow ( ); | 1140 | QWidget * active = activeWindow ( ); |
1139 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { | 1141 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { |
1140 | if ( d-> kbgrabbed ) { // we grabbed the keyboard | 1142 | if ( d-> kbgrabbed ) { // we grabbed the keyboard |
1141 | QChar ch ( ke-> simpleData.unicode ); | 1143 | QChar ch ( ke-> simpleData.unicode ); |
1142 | QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, | 1144 | QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, |
1143 | ke-> simpleData.keycode, | 1145 | ke-> simpleData.keycode, |
1144 | ch. latin1 ( ), | 1146 | ch. latin1 ( ), |
1145 | ke-> simpleData.modifiers, | 1147 | ke-> simpleData.modifiers, |
1146 | QString ( ch ), | 1148 | QString ( ch ), |
1147 | ke-> simpleData.is_auto_repeat, 1 ); | 1149 | ke-> simpleData.is_auto_repeat, 1 ); |
1148 | 1150 | ||
1149 | QObject *which = QWidget::keyboardGrabber ( ); | 1151 | QObject *which = QWidget::keyboardGrabber ( ); |
1150 | if ( !which ) | 1152 | if ( !which ) |
1151 | which = QApplication::focusWidget ( ); | 1153 | which = QApplication::focusWidget ( ); |
1152 | if ( !which ) | 1154 | if ( !which ) |
1153 | which = QApplication::activeWindow ( ); | 1155 | which = QApplication::activeWindow ( ); |
1154 | if ( !which ) | 1156 | if ( !which ) |
1155 | which = qApp; | 1157 | which = qApp; |
1156 | 1158 | ||
1157 | QApplication::sendEvent ( which, &qke ); | 1159 | QApplication::sendEvent ( which, &qke ); |
1158 | } | 1160 | } |
1159 | else { // we didn't grab the keyboard, so send the event to the launcher | 1161 | else { // we didn't grab the keyboard, so send the event to the launcher |
1160 | QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); | 1162 | QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); |
1161 | e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); | 1163 | e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); |
1162 | } | 1164 | } |
1163 | } | 1165 | } |
1164 | return true; | 1166 | return true; |
1165 | } | 1167 | } |
1166 | } | 1168 | } |
1167 | if ( e->type == QWSEvent::Focus ) { | 1169 | if ( e->type == QWSEvent::Focus ) { |
1168 | QWSFocusEvent * fe = ( QWSFocusEvent* ) e; | 1170 | QWSFocusEvent * fe = ( QWSFocusEvent* ) e; |
1169 | if ( !fe->simpleData.get_focus ) { | 1171 | if ( !fe->simpleData.get_focus ) { |
1170 | QWidget * active = activeWindow(); | 1172 | QWidget * active = activeWindow(); |
1171 | while ( active && active->isPopup() ) { | 1173 | while ( active && active->isPopup() ) { |
1172 | active->close(); | 1174 | active->close(); |
1173 | active = activeWindow(); | 1175 | active = activeWindow(); |
1174 | } | 1176 | } |
1175 | } | 1177 | } |
1176 | else { | 1178 | else { |
1177 | // make sure our modal widget is ALWAYS on top | 1179 | // make sure our modal widget is ALWAYS on top |
1178 | QWidget *topm = activeModalWidget(); | 1180 | QWidget *topm = activeModalWidget(); |
1179 | if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { | 1181 | if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { |
1180 | topm->raise(); | 1182 | topm->raise(); |
1181 | } | 1183 | } |
1182 | } | 1184 | } |
1183 | if ( fe->simpleData.get_focus && inputMethodDict ) { | 1185 | if ( fe->simpleData.get_focus && inputMethodDict ) { |
1184 | InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); | 1186 | InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); |
1185 | if ( m == AlwaysOff ) | 1187 | if ( m == AlwaysOff ) |
1186 | Global::hideInputMethod(); | 1188 | Global::hideInputMethod(); |
1187 | if ( m == AlwaysOn ) | 1189 | if ( m == AlwaysOn ) |
1188 | Global::showInputMethod(); | 1190 | Global::showInputMethod(); |
1189 | } | 1191 | } |
1190 | } | 1192 | } |
1191 | 1193 | ||
1192 | 1194 | ||
1193 | return QApplication::qwsEventFilter( e ); | 1195 | return QApplication::qwsEventFilter( e ); |
1194 | } | 1196 | } |
1195 | #endif | 1197 | #endif |
1196 | 1198 | ||
1197 | /*! | 1199 | /*! |
1198 | Destroys the QPEApplication. | 1200 | Destroys the QPEApplication. |
1199 | */ | 1201 | */ |
1200 | QPEApplication::~QPEApplication() | 1202 | QPEApplication::~QPEApplication() |
1201 | { | 1203 | { |
1202 | ungrabKeyboard(); | 1204 | ungrabKeyboard(); |
1203 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 1205 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
1204 | // Need to delete QCopChannels early, since the display will | 1206 | // Need to delete QCopChannels early, since the display will |
1205 | // be gone by the time we get to ~QObject(). | 1207 | // be gone by the time we get to ~QObject(). |
1206 | delete sysChannel; | 1208 | delete sysChannel; |
1207 | delete pidChannel; | 1209 | delete pidChannel; |
1208 | #endif | 1210 | #endif |
1209 | 1211 | ||
1210 | delete d; | 1212 | delete d; |
1211 | } | 1213 | } |
1212 | 1214 | ||
1213 | /*! | 1215 | /*! |
1214 | Returns <tt>$OPIEDIR/</tt>. | 1216 | Returns <tt>$OPIEDIR/</tt>. |
1215 | */ | 1217 | */ |
1216 | QString QPEApplication::qpeDir() | 1218 | QString QPEApplication::qpeDir() |
1217 | { | 1219 | { |
1218 | const char * base = getenv( "OPIEDIR" ); | 1220 | const char * base = getenv( "OPIEDIR" ); |
1219 | if ( base ) | 1221 | if ( base ) |
1220 | return QString( base ) + "/"; | 1222 | return QString( base ) + "/"; |
1221 | 1223 | ||
1222 | return QString( "../" ); | 1224 | return QString( "../" ); |
1223 | } | 1225 | } |
1224 | 1226 | ||
1225 | /*! | 1227 | /*! |
1226 | Returns the user's current Document directory. There is a trailing "/". | 1228 | Returns the user's current Document directory. There is a trailing "/". |
1227 | .. well, it does now,, and there's no trailing '/' | 1229 | .. well, it does now,, and there's no trailing '/' |
1228 | */ | 1230 | */ |
1229 | QString QPEApplication::documentDir() | 1231 | QString QPEApplication::documentDir() |
1230 | { | 1232 | { |
1231 | const char* base = getenv( "HOME"); | 1233 | const char* base = getenv( "HOME"); |
1232 | if ( base ) | 1234 | if ( base ) |
1233 | return QString( base ) + "/Documents"; | 1235 | return QString( base ) + "/Documents"; |
1234 | 1236 | ||
1235 | return QString( "../Documents" ); | 1237 | return QString( "../Documents" ); |
1236 | } | 1238 | } |
1237 | 1239 | ||
1238 | static int deforient = -1; | 1240 | static int deforient = -1; |
1239 | 1241 | ||
1240 | /*! | 1242 | /*! |
1241 | \internal | 1243 | \internal |
1242 | */ | 1244 | */ |
1243 | int QPEApplication::defaultRotation() | 1245 | int QPEApplication::defaultRotation() |
1244 | { | 1246 | { |
1245 | if ( deforient < 0 ) { | 1247 | if ( deforient < 0 ) { |
1246 | QString d = getenv( "QWS_DISPLAY" ); | 1248 | QString d = getenv( "QWS_DISPLAY" ); |
1247 | if ( d.contains( "Rot90" ) ) { | 1249 | if ( d.contains( "Rot90" ) ) { |
1248 | deforient = 90; | 1250 | deforient = 90; |
1249 | } | 1251 | } |
1250 | else if ( d.contains( "Rot180" ) ) { | 1252 | else if ( d.contains( "Rot180" ) ) { |
1251 | deforient = 180; | 1253 | deforient = 180; |
1252 | } | 1254 | } |
1253 | else if ( d.contains( "Rot270" ) ) { | 1255 | else if ( d.contains( "Rot270" ) ) { |
1254 | deforient = 270; | 1256 | deforient = 270; |
1255 | } | 1257 | } |
1256 | else { | 1258 | else { |
1257 | deforient = 0; | 1259 | deforient = 0; |
1258 | } | 1260 | } |
1259 | } | 1261 | } |
1260 | return deforient; | 1262 | return deforient; |