Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Porting to KDE(2) was done by |
| 11 | * |
| 12 | * (C) 2000 by Thomas Capricelli <orzel@freehackers.org> |
| 13 | * |
| 14 | * Please visit http://freehackers.org/kvim for other vim- or |
| 15 | * kde-related coding. |
| 16 | * |
| 17 | * $Id$ |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <assert.h> |
| 22 | #include <qpainter.h> |
| 23 | #include <qevent.h> |
| 24 | #include <qpushbutton.h> |
| 25 | #include <qscrollbar.h> |
| 26 | #include <qlayout.h> |
| 27 | #include <qclipboard.h> |
| 28 | #include <qdragobject.h> |
| 29 | #include <qstrlist.h> |
| 30 | #include <qmenubar.h> |
| 31 | #include <qtextcodec.h> |
| 32 | #if QT_VERSION>=300 |
| 33 | #include <qptrlist.h> |
| 34 | #include <ktip.h> |
| 35 | #endif |
| 36 | #include <kglobal.h> |
| 37 | #include <kconfig.h> |
| 38 | #include <kaboutapplication.h> |
| 39 | #include <dcopclient.h> |
| 40 | #include <kaboutkde.h> |
| 41 | #include <kbugreport.h> |
| 42 | #include <kurldrag.h> |
| 43 | #include <kmenubar.h> |
| 44 | #include <ktoolbar.h> |
| 45 | #include <kstandarddirs.h> |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 46 | #include "gui_kde_wid.h" |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 47 | #include <qxembed.h> |
| 48 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 49 | extern "C" |
| 50 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 51 | #include "version.h" |
| 52 | } |
| 53 | |
| 54 | // Pixmap for dialog |
| 55 | #ifdef FEAT_GUI_DIALOG |
| 56 | # include "../../pixmaps/alert.xpm" |
| 57 | # include "../../pixmaps/error.xpm" |
| 58 | # include "../../pixmaps/generic.xpm" |
| 59 | # include "../../pixmaps/info.xpm" |
| 60 | # include "../../pixmaps/quest.xpm" |
| 61 | #endif |
| 62 | |
| 63 | /** |
| 64 | * Keycodes recognized by vim. |
| 65 | */ |
| 66 | struct special_key {//{{{ |
| 67 | int qtkey; |
| 68 | char_u code0; |
| 69 | char_u code1; |
| 70 | } special_keys[] = |
| 71 | { |
| 72 | { Qt::Key_Up, 'k', 'u' }, |
| 73 | { Qt::Key_Down, 'k', 'd' }, |
| 74 | { Qt::Key_Left, 'k', 'l' }, |
| 75 | { Qt::Key_Right, 'k', 'r' }, |
| 76 | { Qt::Key_F1, 'k', '1' }, |
| 77 | { Qt::Key_F2, 'k', '2' }, |
| 78 | { Qt::Key_F3, 'k', '3' }, |
| 79 | { Qt::Key_F4, 'k', '4' }, |
| 80 | { Qt::Key_F5, 'k', '5' }, |
| 81 | { Qt::Key_F6, 'k', '6' }, |
| 82 | { Qt::Key_F7, 'k', '7' }, |
| 83 | { Qt::Key_F8, 'k', '8' }, |
| 84 | { Qt::Key_F9, 'k', '9' }, |
| 85 | { Qt::Key_F10, 'k', ';' }, |
| 86 | { Qt::Key_F11, 'F', '1' }, |
| 87 | { Qt::Key_F12, 'F', '2' }, |
| 88 | { Qt::Key_F13, 'F', '3' }, |
| 89 | { Qt::Key_F14, 'F', '4' }, |
| 90 | { Qt::Key_F15, 'F', '5' }, |
| 91 | { Qt::Key_F16, 'F', '6' }, |
| 92 | { Qt::Key_F17, 'F', '7' }, |
| 93 | { Qt::Key_F18, 'F', '8' }, |
| 94 | { Qt::Key_F19, 'F', '9' }, |
| 95 | { Qt::Key_F20, 'F', 'A' }, |
| 96 | { Qt::Key_F21, 'F', 'B' }, |
| 97 | { Qt::Key_F22, 'F', 'C' }, |
| 98 | { Qt::Key_F23, 'F', 'D' }, |
| 99 | { Qt::Key_F24, 'F', 'E' }, |
| 100 | { Qt::Key_F25, 'F', 'F' }, |
| 101 | { Qt::Key_F26, 'F', 'G' }, |
| 102 | { Qt::Key_F27, 'F', 'H' }, |
| 103 | { Qt::Key_F28, 'F', 'I' }, |
| 104 | { Qt::Key_F29, 'F', 'J' }, |
| 105 | { Qt::Key_F30, 'F', 'K' }, |
| 106 | { Qt::Key_F31, 'F', 'L' }, |
| 107 | { Qt::Key_F32, 'F', 'M' }, |
| 108 | { Qt::Key_F33, 'F', 'N' }, |
| 109 | { Qt::Key_F34, 'F', 'O' }, |
| 110 | { Qt::Key_F35, 'F', 'P' }, |
| 111 | { Qt::Key_Help, '%', '1' }, |
| 112 | // { Qt::Key_Undo, '&', '8' }, <= hmmm ? |
| 113 | { Qt::Key_BackSpace, 'k', 'b' }, |
| 114 | { Qt::Key_Insert, KS_EXTRA, KE_KINS }, |
| 115 | { Qt::Key_Delete, KS_EXTRA, KE_KDEL }, |
| 116 | { Qt::Key_Home, 'K', '1' }, |
| 117 | { Qt::Key_End, 'K', '4' }, |
| 118 | { Qt::Key_Prior, 'K', '3' }, |
| 119 | { Qt::Key_Next, 'K', '5' }, |
| 120 | { Qt::Key_Print, '%', '9' }, |
| 121 | |
| 122 | { Qt::Key_Plus, 'K', '6'}, |
| 123 | { Qt::Key_Minus, 'K', '7'}, |
| 124 | { Qt::Key_Slash, 'K', '8'}, |
| 125 | { Qt::Key_multiply, 'K', '9'}, |
| 126 | { Qt::Key_Enter, 'K', 'A'}, |
| 127 | { Qt::Key_Period, 'K', 'B'}, |
| 128 | |
| 129 | { Qt::Key_0, 'K', 'C'}, |
| 130 | { Qt::Key_1, 'K', 'D'}, |
| 131 | { Qt::Key_2, 'K', 'E'}, |
| 132 | { Qt::Key_3, 'K', 'F'}, |
| 133 | { Qt::Key_4, 'K', 'G'}, |
| 134 | { Qt::Key_5, 'K', 'H'}, |
| 135 | { Qt::Key_6, 'K', 'I'}, |
| 136 | { Qt::Key_7, 'K', 'J'}, |
| 137 | { Qt::Key_8, 'K', 'K'}, |
| 138 | { Qt::Key_9, 'K', 'L'}, |
| 139 | /* End of list marker: */ |
| 140 | { 0, 0, 0 } |
| 141 | };//}}} |
| 142 | |
| 143 | #ifdef FEAT_CLIENTSERVER |
| 144 | typedef int (*QX11EventFilter) (XEvent*); |
| 145 | extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter); |
| 146 | static QX11EventFilter oldFilter = 0; |
| 147 | static int kvim_x11_event_filter( XEvent* e); |
| 148 | #endif |
| 149 | void gui_keypress(QKeyEvent *e); |
| 150 | |
| 151 | /* |
| 152 | * Return OK if the key with the termcap name "name" is supported. |
| 153 | */ |
| 154 | int |
| 155 | gui_mch_haskey(char_u * name)//{{{ |
| 156 | { |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 157 | for (int i = 0; special_keys[i].qtkey != 0; i++) |
| 158 | if (name[0] == special_keys[i].code0 |
| 159 | && name[1] == special_keys[i].code1) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 160 | return OK; |
| 161 | return FAIL; |
| 162 | }//}}} |
| 163 | |
| 164 | /* |
| 165 | * custom Frame for drawing ... |
| 166 | */ |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 167 | void VimWidget::paintEvent(QPaintEvent *e)//{{{ |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 168 | { |
| 169 | QRect r = e->rect(); |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 170 | gui_redraw(r.x(), r.y(), r.width(), r.height()); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 171 | }//}}} |
| 172 | |
| 173 | void VimWidget::draw_string(int x, int y, QString s, int len, int flags)//{{{ |
| 174 | { |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 175 | gui.current_font->setBold(flags & DRAW_BOLD); |
| 176 | gui.current_font->setUnderline(flags & DRAW_UNDERL); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 177 | gui.current_font->setItalic(flags & DRAW_ITALIC); |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 178 | painter->setBackgroundMode(flags & DRAW_TRANSP ? Qt::TransparentMode : Qt::OpaqueMode); |
| 179 | painter->setFont(*(gui.current_font)); |
| 180 | painter->drawText(x, y, s, len); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 181 | }//}}} |
| 182 | |
| 183 | void VimWidget::mousePressEvent(QMouseEvent *event)//{{{ |
| 184 | { |
| 185 | int button=0; |
| 186 | int modifiers=0; |
| 187 | ButtonState state = event->state(); |
| 188 | ButtonState buttons = event->button(); |
| 189 | |
| 190 | //Look at button states |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 191 | if (buttons & QMouseEvent::LeftButton) |
| 192 | button |= MOUSE_LEFT; |
| 193 | if (buttons & QMouseEvent::RightButton) |
| 194 | button |= MOUSE_RIGHT; |
| 195 | if (buttons & QMouseEvent::MidButton) |
| 196 | button |= MOUSE_MIDDLE; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 197 | //Look for keyboard modifiers |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 198 | if (state & QMouseEvent::ShiftButton) |
| 199 | modifiers |= MOUSE_SHIFT; |
| 200 | if (state & QMouseEvent::ControlButton) |
| 201 | modifiers |= MOUSE_CTRL; |
| 202 | if (state & QMouseEvent::AltButton) |
| 203 | modifiers |= MOUSE_ALT; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 204 | gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers); |
| 205 | #if QT_VERSION>=300 |
| 206 | QByteArray params; |
| 207 | QDataStream stream(params, IO_WriteOnly); |
| 208 | stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; |
| 209 | kapp->dcopClient()->emitDCOPSignal("mousePEvent(QCString,int,int,int,int)", params); |
| 210 | #endif |
| 211 | event->accept(); |
| 212 | }//}}} |
| 213 | |
| 214 | #if defined(FEAT_SESSION) |
| 215 | void VimMainWindow::saveGlobalProperties (KConfig *conf) |
| 216 | { |
| 217 | //we write a mksession file to a file written in the user's ~/.kde/share/config/ |
| 218 | //the name of the file in saved in 'conf' |
| 219 | //when restoring app, we source this file |
| 220 | #if 0 //disabled for release |
| 221 | QString filename = KGlobal::dirs()->localkdedir() + KGlobal::dirs()->kde_default("config") + kapp->randomString(10); |
| 222 | QString cmd("mksession "); |
| 223 | cmd+=filename; |
| 224 | do_cmdline_cmd((char_u*)cmd.latin1()); |
| 225 | conf->writePathEntry("sessionfile", filename); |
| 226 | conf->sync(); |
| 227 | #endif |
| 228 | } |
| 229 | |
| 230 | void VimMainWindow::readGlobalProperties (KConfig *conf) |
| 231 | { |
| 232 | #if 0 |
| 233 | QString filename = conf->readPathEntry("sessionfile"); |
| 234 | if (filename.isNull()) return; |
| 235 | QString cmd("source "); |
| 236 | cmd+=filename; |
| 237 | do_cmdline_cmd((char_u*)cmd.latin1()); |
| 238 | #endif |
| 239 | } |
| 240 | #endif |
| 241 | |
| 242 | void VimMainWindow::wheelEvent (QWheelEvent *event)//{{{ |
| 243 | { |
| 244 | ButtonState state = event->state(); |
| 245 | int button=0; |
| 246 | int modifiers=0; |
| 247 | |
| 248 | if (event->delta()>0) |
| 249 | button|=MOUSE_4; |
| 250 | else button|=MOUSE_5; |
| 251 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 252 | if (state & ShiftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 253 | modifiers|=MOUSE_SHIFT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 254 | if (state & ControlButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 255 | modifiers|=MOUSE_CTRL; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 256 | if (state & AltButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 257 | modifiers|=MOUSE_ALT; |
| 258 | |
| 259 | gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers); |
| 260 | #if QT_VERSION>=300 |
| 261 | QByteArray params; |
| 262 | QDataStream stream(params, IO_WriteOnly); |
| 263 | stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; |
| 264 | kapp->dcopClient()->emitDCOPSignal("mouseWhlEvent(QCString, int, int,int,int)", params); |
| 265 | #endif |
| 266 | event->accept(); |
| 267 | }//}}} |
| 268 | |
| 269 | void VimWidget::mouseDoubleClickEvent(QMouseEvent *event)//{{{ |
| 270 | { |
| 271 | ButtonState state = event->state(); |
| 272 | ButtonState buttons = event->button(); |
| 273 | int modifiers=0; |
| 274 | int button=0; |
| 275 | |
| 276 | //Look at button states |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 277 | if (buttons & LeftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 278 | button|=MOUSE_LEFT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 279 | if (buttons & RightButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 280 | button|=MOUSE_RIGHT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 281 | if (buttons & MidButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 282 | button|=MOUSE_MIDDLE; |
| 283 | |
| 284 | //Look for keyboard modifiers |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 285 | if (state & ShiftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 286 | modifiers|=MOUSE_SHIFT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 287 | if (state & ControlButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 288 | modifiers|=MOUSE_CTRL; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 289 | if (state & AltButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 290 | modifiers|=MOUSE_ALT; |
| 291 | |
| 292 | gui_send_mouse_event(button,event->x(),event->y(),TRUE,modifiers); |
| 293 | #if QT_VERSION>=300 |
| 294 | QByteArray params; |
| 295 | QDataStream stream(params, IO_WriteOnly); |
| 296 | stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; |
| 297 | kapp->dcopClient()->emitDCOPSignal("mouseDblClickEvent(QCString, int, int,int,int)", params); |
| 298 | #endif |
| 299 | event->accept(); |
| 300 | }//}}} |
| 301 | |
| 302 | void VimWidget::mouseMoveEvent(QMouseEvent *event){//{{{ |
| 303 | ButtonState state = event->state(); |
| 304 | int modifiers=0; |
| 305 | int button=0; |
| 306 | |
| 307 | gui_mch_mousehide(FALSE); |
| 308 | |
| 309 | //Look at button states |
| 310 | //warning: we use state here, this is important ! |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 311 | if (state & QMouseEvent::LeftButton || state & QMouseEvent::RightButton || state & QMouseEvent::MidButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 312 | button|=MOUSE_DRAG; |
| 313 | |
| 314 | //Look for keyboard modifiers |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 315 | if (state & ShiftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 316 | modifiers|=MOUSE_SHIFT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 317 | if (state & ControlButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 318 | modifiers|=MOUSE_CTRL; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 319 | if (state & AltButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 320 | modifiers|=MOUSE_ALT; |
| 321 | if (button!=MOUSE_DRAG) |
| 322 | gui_mouse_moved(event->x(),event->y()); |
| 323 | else |
| 324 | gui_send_mouse_event(MOUSE_DRAG,event->x(),event->y(),FALSE,modifiers); |
| 325 | }//}}} |
| 326 | |
| 327 | void VimWidget::mouseReleaseEvent(QMouseEvent *event)//{{{ |
| 328 | { |
| 329 | ButtonState state = event->state(); |
| 330 | int modifiers=0; |
| 331 | |
| 332 | //Look for keyboard modifiers |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 333 | if (state & ShiftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 334 | modifiers|=MOUSE_SHIFT; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 335 | if (state & ControlButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 336 | modifiers|=MOUSE_CTRL; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 337 | if (state & AltButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 338 | modifiers|=MOUSE_ALT; |
| 339 | |
| 340 | gui_send_mouse_event(MOUSE_RELEASE,event->x(),event->y(),FALSE,modifiers); |
| 341 | event->accept(); |
| 342 | }//}}} |
| 343 | |
| 344 | /* |
| 345 | * The main widget (everything but toolbar/menubar) |
| 346 | */ |
| 347 | VimWidget::VimWidget( QWidget *parent, const char *name, WFlags f )//{{{ |
| 348 | :QWidget(parent, name, f) |
| 349 | ,DCOPObject("KVim") |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 350 | #ifdef FEAT_MZSCHEME |
| 351 | ,mzscheme_timer_id(-1) |
| 352 | #endif |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 353 | { |
| 354 | //to be able to show/hide the cursor when moving the mouse |
| 355 | setMouseTracking(true); |
| 356 | painter=new QPainter(this); |
| 357 | |
| 358 | setKeyCompression(true); |
| 359 | setFocusPolicy( QWidget::StrongFocus ); |
| 360 | setAcceptDrops(TRUE); // DND |
| 361 | blink_state = BLINK_NONE; |
| 362 | blink_on_time = 700; |
| 363 | blink_off_time = 400; |
| 364 | blink_wait_time = 250; |
| 365 | connect( &blink_timer, SIGNAL( timeout() ), SLOT( blink_cursor() )); |
| 366 | connect( &wait_timer, SIGNAL( timeout() ), SLOT ( wait_timeout() )); |
| 367 | }//}}} |
| 368 | |
| 369 | void VimWidget::execNormal(QString command)//{{{ |
| 370 | { |
| 371 | QString cmd("execute 'normal "); |
| 372 | cmd+=command; |
| 373 | cmd+="'"; |
| 374 | QCString unistring = vmw->codec->fromUnicode(cmd); |
| 375 | do_cmdline_cmd((char_u *)(const char*)unistring); |
| 376 | gui_update_screen(); |
| 377 | }//}}} |
| 378 | |
| 379 | void VimWidget::execInsert(QString command)//{{{ |
| 380 | { |
| 381 | QString cmd("execute 'normal i"); |
| 382 | cmd+=command; |
| 383 | cmd+="'"; |
| 384 | QCString unistring = vmw->codec->fromUnicode(cmd); |
| 385 | do_cmdline_cmd((char_u *)(const char*)unistring); |
| 386 | gui_update_screen(); |
| 387 | }//}}} |
| 388 | |
| 389 | void VimWidget::execRaw(QString command)//{{{ |
| 390 | { |
| 391 | QString cmd("execute '"); |
| 392 | cmd+=command; |
| 393 | cmd+="'"; |
| 394 | QCString unistring = vmw->codec->fromUnicode(cmd); |
| 395 | do_cmdline_cmd((char_u *)(const char*)unistring); |
| 396 | gui_update_screen(); |
| 397 | }//}}} |
| 398 | |
| 399 | void VimWidget::execCmd(QString command)//{{{ |
| 400 | { |
| 401 | QCString unistring = vmw->codec->fromUnicode(command); |
| 402 | do_cmdline_cmd((char_u *)(const char*)unistring); |
| 403 | gui_update_screen(); |
| 404 | }//}}} |
| 405 | |
| 406 | QString VimWidget::eval(QString expr)//{{{ |
| 407 | { |
| 408 | #ifdef FEAT_EVAL |
| 409 | QCString unistring = vmw->codec->fromUnicode(expr); |
| 410 | QString val((const char *)eval_to_string((char_u *)(const char*)unistring,NULL)); |
| 411 | return val; |
| 412 | #else |
| 413 | return QString::null; |
| 414 | #endif |
| 415 | }//}}} |
| 416 | |
| 417 | void VimWidget::wait(long wtime)//{{{ |
| 418 | { |
| 419 | if ( wait_timer.isActive() ) wait_timer.stop(); |
| 420 | wait_done = false; |
| 421 | wait_timer.start( wtime, true); |
| 422 | }//}}} |
| 423 | |
| 424 | void VimWidget::wait_timeout() //{{{ |
| 425 | { |
| 426 | wait_done = true; |
| 427 | }//}}} |
| 428 | |
| 429 | void VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{ |
| 430 | { |
| 431 | #if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO) |
| 432 | e->accept(QUriDrag::canDecode(e)); |
| 433 | #else |
| 434 | e->ignore(); |
| 435 | #endif |
| 436 | }//}}} |
| 437 | |
| 438 | void VimWidget::dropEvent (QDropEvent *e) // {{{ |
| 439 | { |
| 440 | #if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO) |
| 441 | QStrList urls; |
| 442 | |
| 443 | char_u **fnames; |
| 444 | int redo_dirs = FALSE; |
| 445 | int i; |
| 446 | int n; |
| 447 | int nfiles; |
| 448 | int url = FALSE; |
| 449 | |
| 450 | /* Count how many items there may be and normalize delimiters. */ |
| 451 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 452 | if (QUriDrag::decode(e, urls)) |
| 453 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 454 | n = urls.count(); |
| 455 | fnames = (char_u **)lalloc((n+1) * sizeof(char_u *), TRUE); |
| 456 | nfiles = 0; |
| 457 | #if QT_VERSION>=300 |
| 458 | QPtrListIterator<char> it(urls); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 459 | for (; it.current(); ++it ) |
| 460 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 461 | KURL u(*it); |
| 462 | #else |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 463 | for (i=0;i<urls.count();++i) |
| 464 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 465 | KURL u(urls.at(i)); |
| 466 | #endif |
| 467 | if ( !u.isLocalFile() ) |
| 468 | url = TRUE; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 469 | else |
| 470 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 471 | fnames[nfiles] = (char_u *)strdup((const char *)u.path()); |
| 472 | ++nfiles; |
| 473 | } |
| 474 | } |
| 475 | /* Real files (i.e. not http and not ftp) */ |
| 476 | if (url == FALSE) |
| 477 | { |
| 478 | if (nfiles == 1) |
| 479 | { |
| 480 | if (mch_isdir(fnames[0])) |
| 481 | { |
| 482 | /* Handle dropping a directory on Vim. */ |
| 483 | if (mch_chdir((char *)fnames[0]) == 0) |
| 484 | { |
| 485 | free(fnames[0]); |
| 486 | fnames[0] = NULL; |
| 487 | redo_dirs = TRUE; |
| 488 | } |
| 489 | } |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 490 | } |
| 491 | else |
| 492 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 493 | /* Ignore any directories */ |
| 494 | for (i = 0; i < nfiles; ++i) |
| 495 | { |
| 496 | if (mch_isdir(fnames[i])) |
| 497 | { |
| 498 | vim_free(fnames[i]); |
| 499 | fnames[i] = NULL; |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if (0) |
| 505 | { |
| 506 | /* Shift held down, change to first file's directory */ |
| 507 | if (fnames[0] != NULL && vim_chdirfile(fnames[0]) == OK) |
| 508 | redo_dirs = TRUE; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 509 | } |
| 510 | else |
| 511 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 512 | char_u dirname[MAXPATHL]; |
| 513 | char_u *s; |
| 514 | if (mch_dirname(dirname, MAXPATHL) == OK) |
| 515 | for (i = 0; i < nfiles; ++i) |
| 516 | if (fnames[i] != NULL) |
| 517 | { |
| 518 | s = shorten_fname(fnames[i], dirname); |
| 519 | if (s != NULL && (s = vim_strsave(s)) != NULL) |
| 520 | { |
| 521 | vim_free(fnames[i]); |
| 522 | fnames[i] = s; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /* Handle the drop, :edit or :split to get to the file */ |
| 529 | handle_drop(nfiles, fnames, FALSE); |
| 530 | |
| 531 | if (redo_dirs) |
| 532 | shorten_fnames(TRUE); |
| 533 | } |
| 534 | |
| 535 | /* Update the screen display */ |
| 536 | update_screen(NOT_VALID); |
| 537 | #ifdef FEAT_MENU |
| 538 | gui_update_menus(0); |
| 539 | #endif |
| 540 | setcursor(); |
| 541 | out_flush(); |
| 542 | gui_update_cursor(FALSE, FALSE); |
| 543 | gui_mch_flush(); |
| 544 | #endif |
| 545 | } // }}} |
| 546 | |
| 547 | void VimWidget::keyPressEvent( QKeyEvent *e ) // {{{ |
| 548 | { |
| 549 | gui_keypress(e); |
| 550 | } // }}} |
| 551 | |
| 552 | void gui_keypress(QKeyEvent *e) { // {{{ |
| 553 | int key = (int)e->key(); |
| 554 | int modifiers = 0,i; |
| 555 | uchar string[256],string2[256]; |
| 556 | uchar *s,*d; |
| 557 | Qt::ButtonState state = e->state(); |
| 558 | |
| 559 | QCString unistring = vmw->codec->fromUnicode(e->text()); |
| 560 | if (unistring.length()>0) |
| 561 | strncpy((char*)string, (const char*)unistring,unistring.length()); |
| 562 | string[unistring.length()] = 0; |
| 563 | int len=unistring.length(); |
| 564 | |
| 565 | // ignore certain keys |
| 566 | if (key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Meta |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 567 | || key == Qt::Key_CapsLock || key == Qt::Key_NumLock || key == Qt::Key_ScrollLock ) |
| 568 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 569 | e->ignore(); |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | #ifdef FEAT_MBYTE |
| 574 | if (input_conv.vc_type != CONV_NONE) |
| 575 | { |
| 576 | mch_memmove(string2, string, len); |
| 577 | len = convert_input(string2, len, sizeof(string2)); |
| 578 | s = string2; |
| 579 | } |
| 580 | else |
| 581 | #endif |
| 582 | s = string; |
| 583 | d = string; |
| 584 | for (i = 0; i < len; ++i) |
| 585 | { |
| 586 | *d++ = s[i]; |
| 587 | if (d[-1] == CSI && d + 2 < string + sizeof(string)) |
| 588 | { |
| 589 | /* Turn CSI into K_CSI. */ |
| 590 | *d++ = KS_EXTRA; |
| 591 | *d++ = (int)KE_CSI; |
| 592 | } |
| 593 | } |
| 594 | len = d - string; |
| 595 | |
| 596 | |
| 597 | // change shift-tab (backtab) into S_TAB |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 598 | if ( key == Qt::Key_BackTab && state & Qt::ShiftButton) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 599 | key = Qt::Key_Tab; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 600 | |
| 601 | // Change C-@ and C-2 in NUL ? Gtk does this |
| 602 | if ( (key == Qt::Key_2 || key == Qt::Key_At) |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 603 | && state & Qt::ControlButton ) |
| 604 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 605 | string[0] = NUL; |
| 606 | len = 1; |
| 607 | } |
| 608 | else if (len == 0 && (key == Qt::Key_Space || key == Qt::Key_Tab)) |
| 609 | { |
| 610 | /* When there are modifiers, these keys get zero length; we need the |
| 611 | * original key here to be able to add a modifier below. */ |
| 612 | string[0] = (key & 0xff); |
| 613 | len = 1; |
| 614 | } |
| 615 | /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character |
| 616 | * that already has the 8th bit set. |
| 617 | * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. */ |
| 618 | if (len == 1 |
| 619 | && (key != Qt::Key_BackSpace && key != Qt::Key_Delete) |
| 620 | && (string[0] & 0x80) == 0 |
| 621 | && (state & Qt::AltButton) |
| 622 | && !(key == Qt::Key_Tab && (state & Qt::ShiftButton))) |
| 623 | { |
| 624 | string[0] |= 0x80; |
| 625 | #ifdef FEAT_MBYTE |
| 626 | if (enc_utf8) // convert to utf-8 |
| 627 | { |
| 628 | string[1] = string[0] & 0xbf; |
| 629 | string[0] = ((unsigned)string[0] >> 6) + 0xc0; |
| 630 | if (string[1] == CSI) |
| 631 | { |
| 632 | string[2] = KS_EXTRA; |
| 633 | string[3] = (int)KE_CSI; |
| 634 | len = 4; |
| 635 | } |
| 636 | else |
| 637 | len = 2; |
| 638 | } |
| 639 | #endif |
| 640 | } |
| 641 | |
| 642 | /* Check for special keys, making sure BS and DEL are recognised. */ |
| 643 | if (len == 0 || key == Qt::Key_BackSpace || key == Qt::Key_Delete) |
| 644 | { |
| 645 | while (special_keys[i].qtkey != 0 && special_keys[i].qtkey != key ) i++; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 646 | if (special_keys[i].qtkey != 0) |
| 647 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 648 | string[0] = CSI; |
| 649 | string[1] = special_keys[i].code0; |
| 650 | string[2] = special_keys[i].code1; |
| 651 | len = -3; |
| 652 | } |
| 653 | /* |
| 654 | for (i = 0; special_keys[i].qtkey != 0 ; i++) |
| 655 | { |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 656 | if (special_keys[i].qtkey == key ) |
| 657 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 658 | string[0] = CSI; |
| 659 | string[1] = special_keys[i].code0; |
| 660 | string[2] = special_keys[i].code1; |
| 661 | len = -3; |
| 662 | break; |
| 663 | } |
| 664 | }*/ |
| 665 | } |
| 666 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 667 | if (len == 0) |
| 668 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 669 | //no need to dump that, that's a QT problem, we can't do anything |
| 670 | //dbf("Unrecognised Key : %X %s", key, e->text().latin1()); |
| 671 | e->ignore(); |
| 672 | return; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | /* Special keys (and a few others) may have modifiers */ |
| 677 | if (len == -3 || key == Qt::Key_Space || key == Qt::Key_Tab || |
| 678 | key == Qt::Key_Return || key == Qt::Key_Enter || |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 679 | key == Qt::Key_Escape) |
| 680 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 681 | |
| 682 | modifiers = 0; |
| 683 | if (state & Qt::ShiftButton) modifiers |= MOD_MASK_SHIFT; |
| 684 | if (state & Qt::ControlButton) modifiers |= MOD_MASK_CTRL; |
| 685 | if (state & Qt::AltButton) modifiers |= MOD_MASK_ALT; |
| 686 | |
| 687 | /* |
| 688 | * For some keys a shift modifier is translated into another key |
| 689 | * code. Do we need to handle the case where len != 1 and |
| 690 | * string[0] != CSI? |
| 691 | */ |
| 692 | if (len == -3) |
| 693 | key = TO_SPECIAL(string[1], string[2]); |
| 694 | else |
| 695 | key = string[0]; |
| 696 | |
| 697 | key = simplify_key(key, &modifiers); |
| 698 | if (key == CSI) key=K_CSI; |
| 699 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 700 | if (IS_SPECIAL(key)) |
| 701 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 702 | string[0] = CSI; |
| 703 | string[1] = K_SECOND(key); |
| 704 | string[2] = K_THIRD(key); |
| 705 | len = 3; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 706 | } |
| 707 | else |
| 708 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 709 | string[0] = key; |
| 710 | len = 1; |
| 711 | } |
| 712 | |
| 713 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 714 | if (modifiers!=0) |
| 715 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 716 | uchar string2[10]; |
| 717 | string2[0] = CSI; |
| 718 | string2[1] = KS_MODIFIER; |
| 719 | string2[2] = modifiers; |
| 720 | add_to_input_buf(string2, 3); |
| 721 | } |
| 722 | |
| 723 | } /* special keys */ |
| 724 | |
| 725 | if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) |
| 726 | || (string[0] == intr_char && intr_char != Ctrl_C))) |
| 727 | { |
| 728 | trash_input_buf(); |
| 729 | got_int = TRUE; |
| 730 | } |
| 731 | |
| 732 | add_to_input_buf(string, len); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 733 | if (p_mh) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 734 | gui_mch_mousehide(TRUE); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 735 | |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 736 | //DCOP Embedding stuff |
| 737 | //if we are here then the user has type something in the window, thus we can easily imagine that : |
| 738 | // 1 - text has changed (emit textChanged()) |
| 739 | // 2 - characters were interactively inserted (emit charactersInteractivelyInserted()) |
| 740 | // 3 - cursor position has changed ( emit cursorPositionChanged() ) |
| 741 | // 4 - selection has changed ? dunno yet //XXX |
| 742 | // 5 - undo changed too ? (each character typed in makes the undo changes anyway) |
| 743 | // conclusion : this makes a lot of things to send to the vim kpart, maybe too much |
| 744 | // for now i'll just send : keyboardEvent to the kpart with the event string as parameter, |
| 745 | // with current current position |
| 746 | // i'll do the same for mouseEvents |
| 747 | #if QT_VERSION>=300 |
| 748 | QByteArray params; |
| 749 | QDataStream stream(params, IO_WriteOnly); |
| 750 | stream << kapp->dcopClient()->appId() << unistring << gui.row << gui.col; |
| 751 | kapp->dcopClient()->emitDCOPSignal("keyboardEvent(QCString, QCString,int,int)", params); |
| 752 | #endif |
| 753 | e->ignore(); |
| 754 | } // }}} |
| 755 | |
| 756 | #ifdef FEAT_CLIENTSERVER |
| 757 | void VimWidget::serverActivate(WId id) //{{{ |
| 758 | { |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 759 | if (serverName == NULL && serverDelayedStartName != NULL) |
| 760 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 761 | commWindow = id; |
| 762 | (void)serverRegisterName(qt_xdisplay(), serverDelayedStartName); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 763 | } |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 764 | else |
| 765 | serverChangeRegisteredWindow( qt_xdisplay(), id); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 766 | }//}}} |
| 767 | #endif |
| 768 | |
| 769 | #ifdef FEAT_XIM |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 770 | void VimWidget::imStartEvent(QIMEvent *e) |
| 771 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 772 | e->accept(); |
| 773 | } |
| 774 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 775 | void VimWidget::imEndEvent(QIMEvent *e) |
| 776 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 777 | uchar string[256]; |
| 778 | |
| 779 | QCString unistring = vmw->codec->fromUnicode(e->text()); |
| 780 | if (unistring.length()>0) |
| 781 | strncpy((char*)string, (const char*)unistring,unistring.length()); |
| 782 | string[unistring.length()] = 0; |
| 783 | int len=unistring.length(); |
| 784 | |
| 785 | add_to_input_buf(string, len); |
| 786 | e->accept(); |
| 787 | } |
| 788 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 789 | void VimWidget::imComposeEvent(QIMEvent *e) |
| 790 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 791 | //i should do something here, displaying the text somewhere ... (status area ?) |
| 792 | e->accept(); |
| 793 | } |
| 794 | #endif |
| 795 | |
| 796 | |
| 797 | void VimMainWindow::lock() |
| 798 | { |
| 799 | locked=true; |
| 800 | } |
| 801 | |
| 802 | void VimMainWindow::unlock() |
| 803 | { |
| 804 | locked=false; |
| 805 | } |
| 806 | |
| 807 | bool VimMainWindow::isLocked() |
| 808 | { |
| 809 | return locked; |
| 810 | } |
| 811 | |
| 812 | // ->resize VimWidget if not locked |
| 813 | // |
| 814 | void VimMainWindow::resizeEvent ( QResizeEvent *e ) //{{{ |
| 815 | { |
| 816 | if ( vmw->isLocked() ) return; |
| 817 | //remove toolbar and menubar height |
| 818 | int height = e->size().height(); |
| 819 | int width = e->size().width(); |
| 820 | |
| 821 | if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() |
| 822 | #if QT_VERSION>=300 |
| 823 | && !vmw->menuBar()->isTopLevelMenu() |
| 824 | #endif |
| 825 | ) |
| 826 | height -= vmw->menuBar()->height(); |
| 827 | #ifdef FEAT_TOOLBAR |
| 828 | if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && |
| 829 | (vmw->toolBar()->barPos()==KToolBar::Top || |
| 830 | vmw->toolBar()->barPos()==KToolBar::Bottom)) |
| 831 | height -= vmw->toolBar()->height(); |
| 832 | |
| 833 | if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && |
| 834 | (vmw->toolBar()->barPos()==KToolBar::Left || |
| 835 | vmw->toolBar()->barPos()==KToolBar::Right)) |
| 836 | width -= vmw->toolBar()->width(); |
| 837 | #endif |
| 838 | height = ( ((int)(height/gui.char_height))*gui.char_height ); |
| 839 | if (!vmw->isLocked()) gui_resize_shell(width,height); |
| 840 | }//}}} |
| 841 | |
| 842 | void VimWidget::focusInEvent( QFocusEvent * fe ) // {{{ |
| 843 | { |
| 844 | gui_focus_change(true); |
| 845 | |
| 846 | if (blink_state == BLINK_NONE) |
| 847 | gui_mch_start_blink(); |
| 848 | } // }}} |
| 849 | |
| 850 | void VimWidget::focusOutEvent( QFocusEvent * fe )//{{{ |
| 851 | { |
| 852 | gui_focus_change(false); |
| 853 | |
| 854 | if (blink_state != BLINK_NONE) |
| 855 | gui_mch_stop_blink(); |
| 856 | }//}}} |
| 857 | |
| 858 | void VimWidget::set_blink_time( long wait, long on, long off)//{{{ |
| 859 | { |
| 860 | blink_wait_time = wait; |
| 861 | blink_on_time = on; |
| 862 | blink_off_time = off; |
| 863 | }//}}} |
| 864 | |
| 865 | void VimWidget::start_cursor_blinking()//{{{ |
| 866 | { |
| 867 | if (blink_timer.isActive()) blink_timer.stop(); |
| 868 | |
| 869 | /* Only switch blinking on if none of the times is zero */ |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 870 | if (blink_wait_time && blink_on_time && blink_off_time && gui.in_focus) |
| 871 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 872 | blink_state = BLINK_ON; |
| 873 | gui_update_cursor(TRUE, FALSE); |
| 874 | // The first blink appears after wait_time |
| 875 | blink_timer.start( blink_wait_time, true); |
| 876 | } |
| 877 | }//}}} |
| 878 | |
| 879 | void VimWidget::blink_cursor()//{{{ |
| 880 | { |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 881 | if (blink_state == BLINK_ON) |
| 882 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 883 | // set cursor off |
| 884 | gui_undraw_cursor(); |
| 885 | blink_state = BLINK_OFF; |
| 886 | blink_timer.start( blink_off_time, true); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 887 | } |
| 888 | else |
| 889 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 890 | // set cursor on |
| 891 | gui_update_cursor(TRUE, FALSE); |
| 892 | blink_state = BLINK_ON; |
| 893 | blink_timer.start( blink_on_time, true); |
| 894 | } |
| 895 | }//}}} |
| 896 | |
| 897 | void VimWidget::stop_cursor_blinking()//{{{ |
| 898 | { |
| 899 | if (blink_timer.isActive()) blink_timer.stop(); |
| 900 | |
| 901 | if (blink_state == BLINK_OFF) |
| 902 | gui_update_cursor(TRUE, FALSE); |
| 903 | |
| 904 | blink_state = BLINK_NONE; |
| 905 | }//}}} |
| 906 | |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 907 | #ifdef FEAT_MZSCHEME |
| 908 | void VimWidget::timerEvent( QTimerEvent * evnt)//{{{ |
| 909 | { |
| 910 | if (evnt->timerId() == mzscheme_timer_id) |
| 911 | timer_proc(); |
| 912 | }//}}} |
| 913 | |
| 914 | void VimWidget::enable_mzscheme_threads()//{{{ |
| 915 | { |
| 916 | mzscheme_timer_id = startTimer(p_mzq); |
| 917 | }//}}} |
| 918 | |
| 919 | void VimWidget::disable_mzscheme_threads()//{{{ |
| 920 | { |
| 921 | killTimer(mzscheme_timer_id); |
| 922 | }//}}} |
| 923 | #endif |
| 924 | |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 925 | void VimWidget::flash()//{{{ |
| 926 | { |
| 927 | QPainter p(this); |
| 928 | |
| 929 | p.setRasterOp(Qt::XorROP); |
| 930 | p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF)); |
| 931 | p.flush(); |
| 932 | //FIXME: Make this a little smarter. Maybe add a timer or something |
| 933 | usleep(19000); |
| 934 | p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF)); |
| 935 | p.flush(); |
| 936 | p.end(); |
| 937 | }//}}} |
| 938 | |
| 939 | |
| 940 | /* |
| 941 | * The main Window |
| 942 | */ |
| 943 | VimMainWindow::VimMainWindow ( const char *name , WFlags f)//{{{ |
| 944 | :KMainWindow(0L, name,f) |
| 945 | { |
| 946 | #ifdef FEAT_CLIENTSERVER |
| 947 | oldFilter = qt_set_x11_event_filter( kvim_x11_event_filter ); |
| 948 | #endif |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 949 | if (echo_wid_arg== 1) |
| 950 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 951 | fprintf(stderr, "WID: %ld\n", (long)winId()); |
| 952 | fflush(stderr); |
| 953 | } |
| 954 | |
| 955 | w = new VimWidget(this, "main vim widget"); |
| 956 | gui.w = w; |
| 957 | setFocusProxy(w); |
| 958 | w->setFocus(); |
| 959 | have_tearoff=0; |
| 960 | |
| 961 | finddlg=new KEdFind (this,0,false); |
| 962 | repldlg=new KEdReplace (this,0,false); |
| 963 | QObject::connect( finddlg, SIGNAL(search()), this, SLOT(slotSearch()) ); |
| 964 | QObject::connect( repldlg, SIGNAL(find()), this, SLOT(slotFind()) ); |
| 965 | QObject::connect( repldlg, SIGNAL(replace()), this, SLOT(slotReplace()) ); |
| 966 | QObject::connect( repldlg, SIGNAL(replaceAll()), this, SLOT(slotReplaceAll()) ); |
| 967 | |
| 968 | #ifdef FEAT_TOOLBAR |
| 969 | connect(toolBar(), SIGNAL(clicked(int)), this, SLOT(menu_activated(int))); |
| 970 | #endif |
| 971 | #ifdef FEAT_CLIENTSERVER |
| 972 | w->serverActivate(winId()); |
| 973 | |
| 974 | if (serverName!=NULL) |
| 975 | kapp->dcopClient()->registerAs(QCString((const char*)serverName),false); |
| 976 | else if (serverDelayedStartName!=NULL) |
| 977 | kapp->dcopClient()->registerAs(QCString((const char*)serverDelayedStartName),false); |
| 978 | else if (argServerName!=NULL) |
| 979 | kapp->dcopClient()->registerAs(argServerName->utf8(),false); |
| 980 | #else |
| 981 | if (argServerName!=NULL) |
| 982 | kapp->dcopClient()->registerAs(argServerName->utf8(),false); |
| 983 | #endif |
| 984 | QXEmbed::initialize(); |
| 985 | |
| 986 | }//{{{ |
| 987 | |
| 988 | bool VimMainWindow::queryClose()//{{{ |
| 989 | { |
| 990 | gui_shell_closed(); |
| 991 | return true; |
| 992 | }//}}} |
| 993 | |
| 994 | bool VimMainWindow::queryExit()//{{{ |
| 995 | { |
| 996 | return true; |
| 997 | }//}}} |
| 998 | |
| 999 | void VimMainWindow::menu_activated(int dx)//{{{ |
| 1000 | { |
| 1001 | #ifdef FEAT_MENU |
| 1002 | if (!dx) { // tearoff |
| 1003 | return; |
| 1004 | } |
| 1005 | gui_mch_set_foreground(); |
| 1006 | gui_menu_cb((VimMenu *) dx); |
| 1007 | #endif |
| 1008 | }//}}} |
| 1009 | |
| 1010 | |
| 1011 | void VimMainWindow::clipboard_selection_update(){//{{{ |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1012 | if (kapp->clipboard()->ownsSelection()) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1013 | clip_own_selection(&clip_star); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1014 | else |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1015 | clip_lose_selection(&clip_star); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1016 | }//}}} |
| 1017 | |
| 1018 | void VimMainWindow::clipboard_data_update(){//{{{ |
| 1019 | #if QT_VERSION>=300 |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1020 | if (kapp->clipboard()->ownsClipboard()) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1021 | clip_own_selection(&clip_plus); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1022 | else |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1023 | clip_lose_selection(&clip_plus); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1024 | #else |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1025 | if (kapp->clipboard()->ownsSelection()) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1026 | clip_own_selection(&clip_star); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1027 | else |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1028 | clip_lose_selection(&clip_star); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1029 | #endif |
| 1030 | }//}}} |
| 1031 | |
| 1032 | void VimMainWindow::slotSearch()//{{{ |
| 1033 | { |
| 1034 | QString find_text; |
| 1035 | bool direction_down = TRUE; |
| 1036 | bool casesensitive = TRUE; |
| 1037 | int flags = FRD_FINDNEXT; |
| 1038 | |
| 1039 | find_text = finddlg->getText(); |
| 1040 | direction_down = !(finddlg->get_direction()); |
| 1041 | casesensitive = finddlg->case_sensitive(); |
| 1042 | // if (casesensitive) find_text = "\\C" + find_text; |
| 1043 | // else find_text = "\\c" + find_text; |
| 1044 | if (casesensitive) flags|=FRD_MATCH_CASE; |
| 1045 | QCString unistring = vmw->codec->fromUnicode(find_text); |
| 1046 | gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down); |
| 1047 | }//}}} |
| 1048 | |
| 1049 | void VimMainWindow::slotFind()//{{{ |
| 1050 | { |
| 1051 | QString find_text; |
| 1052 | bool direction_down=TRUE; |
| 1053 | bool casesensitive = TRUE; |
| 1054 | int flags = FRD_R_FINDNEXT; |
| 1055 | |
| 1056 | find_text=repldlg->getText(); |
| 1057 | direction_down = !(repldlg->get_direction()); |
| 1058 | casesensitive = repldlg->case_sensitive(); |
| 1059 | // if (casesensitive) find_text = "\\C" + find_text; |
| 1060 | // else find_text = "\\c" + find_text; |
| 1061 | if (casesensitive) flags|=FRD_MATCH_CASE; |
| 1062 | |
| 1063 | QCString unistring = vmw->codec->fromUnicode(find_text); |
| 1064 | gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down); |
| 1065 | }//}}} |
| 1066 | |
| 1067 | void VimMainWindow::slotReplace()//{{{ |
| 1068 | { |
| 1069 | QString find_text; |
| 1070 | QString repl_text; |
| 1071 | bool direction_down=TRUE; |
| 1072 | bool casesensitive = TRUE; |
| 1073 | int flags = FRD_REPLACE; |
| 1074 | |
| 1075 | find_text=repldlg->getText(); |
| 1076 | repl_text=repldlg->getReplaceText(); |
| 1077 | direction_down = !(repldlg->get_direction()); |
| 1078 | //if (casesensitive) find_text = "\\C" + find_text; |
| 1079 | //else find_text = "\\c" + find_text; |
| 1080 | if (casesensitive) flags|=FRD_MATCH_CASE; |
| 1081 | |
| 1082 | QCString unistring = vmw->codec->fromUnicode(find_text); |
| 1083 | QCString unistring2 = vmw->codec->fromUnicode(repl_text); |
| 1084 | gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down); |
| 1085 | }//}}} |
| 1086 | |
| 1087 | void VimMainWindow::slotReplaceAll()//{{{ |
| 1088 | { |
| 1089 | QString find_text; |
| 1090 | QString repl_text; |
| 1091 | bool direction_down=TRUE; |
| 1092 | bool casesensitive = TRUE; |
| 1093 | int flags = FRD_REPLACEALL; |
| 1094 | |
| 1095 | find_text=repldlg->getText(); |
| 1096 | repl_text=repldlg->getReplaceText(); |
| 1097 | direction_down = !(repldlg->get_direction()); |
| 1098 | casesensitive = repldlg->case_sensitive(); |
| 1099 | // if (casesensitive) find_text = "\\C" + find_text; |
| 1100 | // else find_text = "\\c" + find_text; |
| 1101 | if (casesensitive) flags|=FRD_MATCH_CASE; |
| 1102 | QCString unistring = vmw->codec->fromUnicode(find_text); |
| 1103 | QCString unistring2 = vmw->codec->fromUnicode(repl_text); |
| 1104 | gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down); |
| 1105 | }//}}} |
| 1106 | |
| 1107 | void VimMainWindow::showAboutKDE() |
| 1108 | { |
| 1109 | KAboutKDE *kde = new KAboutKDE(this); |
| 1110 | kde->show(); |
| 1111 | } |
| 1112 | |
| 1113 | void VimMainWindow::showAboutApplication()//{{{ |
| 1114 | { |
| 1115 | KAboutData *aboutData = new KAboutData ( |
| 1116 | "kvim" |
| 1117 | , I18N_NOOP("KVim") |
| 1118 | , VIM_VERSION_SHORT |
| 1119 | , I18N_NOOP("Vim in a KDE interface") |
| 1120 | , 0 |
| 1121 | , "(c) Vim Team, \":help credits\" for more infos.\nType \":help iccf\" to see how you can help the children in Uganda" |
| 1122 | , 0l |
| 1123 | , "http://freehackers.org/kvim" |
| 1124 | , "kvim-dev@freenux.org" |
| 1125 | ); |
| 1126 | |
| 1127 | aboutData->addAuthor("Bram Moolenaar", |
| 1128 | I18N_NOOP("Main vim author"), |
| 1129 | "Bram@vim.org", |
| 1130 | "http://www.vim.org/"); |
| 1131 | aboutData->addAuthor("Thomas Capricelli", |
| 1132 | I18N_NOOP("KDE porting"), |
| 1133 | "orzel@freehackers.org", |
| 1134 | "http://orzel.freehackers.org"); |
| 1135 | aboutData->addAuthor("Philippe Fremy", |
| 1136 | I18N_NOOP("KDE porting"), |
| 1137 | "pfremy@chez.com", |
| 1138 | "http://www.freehackers.org/kvim"); |
| 1139 | aboutData->addAuthor("Mark Westcott", |
| 1140 | I18N_NOOP("Qtopia porting, maintainer of the Qtopia part"), |
| 1141 | "mark@houseoffish.org", |
| 1142 | "http://houseoffish.org"); |
| 1143 | aboutData->addAuthor("Mickael Marchand", |
| 1144 | I18N_NOOP("KDE porting, maintainer"), |
| 1145 | "marchand@kde.org", |
| 1146 | "http://freenux.org"); |
| 1147 | aboutData->addAuthor("Many other people", |
| 1148 | I18N_NOOP("type :help credits for more infos") |
| 1149 | ); |
| 1150 | aboutData->addCredit("Vince Negri", |
| 1151 | I18N_NOOP("Antialiasing support, Color fixes"), |
| 1152 | "vnegri@asl-electronics.co.uk"); |
| 1153 | aboutData->addCredit("Malte Starostik", |
| 1154 | I18N_NOOP("Patch for performance improvement"), |
| 1155 | "malte@kde.org"); |
| 1156 | aboutData->addCredit("Mark Stosberg", |
| 1157 | I18N_NOOP("Provided a FreeBSD box to debug KVim on BSD"), |
| 1158 | "mark@summersault.com" |
| 1159 | ); |
| 1160 | aboutData->addCredit("Henrik Skott", |
| 1161 | I18N_NOOP("Font patch when KDE not configured"), |
| 1162 | "henrik.skott@hem.utfors.se" |
| 1163 | ); |
| 1164 | aboutData->addCredit("Kailash Sethuraman", |
| 1165 | I18N_NOOP("NetBSD configure/compilation fixes") |
| 1166 | ); |
| 1167 | aboutData->setLicenseText( |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 1168 | "KVim as an extension of Vim follows Vim license.\n\ |
| 1169 | You can read it with \":help license\"\n\ |
| 1170 | Or read the file $VIMRUNTIME/doc/uganda.txt."); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1171 | |
| 1172 | KAboutApplication *about = new KAboutApplication(aboutData); |
| 1173 | about->show(); |
| 1174 | }//}}} |
| 1175 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1176 | void VimMainWindow::showTipOfTheDay() |
| 1177 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1178 | #if QT_VERSION>=300 |
| 1179 | KTipDialog::showTip (vmw,QString::null,true); |
| 1180 | #endif |
| 1181 | } |
| 1182 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1183 | void VimMainWindow::buffersToolbar() |
| 1184 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1185 | |
| 1186 | } |
| 1187 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1188 | void VimMainWindow::showBugReport() |
| 1189 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1190 | KBugReport *bug= new KBugReport(this,true); |
| 1191 | bug->show(); |
| 1192 | } |
| 1193 | /* |
| 1194 | * Vim Dialog |
| 1195 | * |
| 1196 | * Returns: |
| 1197 | * 0: Cancel |
| 1198 | * 1- : nb of the pressed button |
| 1199 | */ |
| 1200 | |
| 1201 | VimDialog::VimDialog (int type, /* type of dialog *///{{{ |
| 1202 | char_u * title, /* title of dialog */ |
| 1203 | char_u * message, /* message text */ |
| 1204 | char_u * buttons, /* names of buttons */ |
| 1205 | int def_but, /* default button */ |
| 1206 | char_u *textfield ) /* input field */ |
| 1207 | :QDialog(vmw, "vim generic dialog", true), // true is for "modal" |
| 1208 | mapper(this, "dialog signal mapper") |
| 1209 | { |
| 1210 | /* |
| 1211 | * Create Icon |
| 1212 | */ |
| 1213 | char ** icon_data; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1214 | switch (type) |
| 1215 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1216 | case VIM_GENERIC: |
| 1217 | icon_data = generic_xpm; |
| 1218 | break; |
| 1219 | case VIM_ERROR: |
| 1220 | icon_data = error_xpm; |
| 1221 | break; |
| 1222 | case VIM_WARNING: |
| 1223 | icon_data = alert_xpm; |
| 1224 | break; |
| 1225 | case VIM_INFO: |
| 1226 | icon_data = info_xpm; |
| 1227 | break; |
| 1228 | case VIM_QUESTION: |
| 1229 | icon_data = quest_xpm; |
| 1230 | break; |
| 1231 | default: |
| 1232 | icon_data = generic_xpm; |
| 1233 | }; |
| 1234 | QLabel * icon = new QLabel( this ); |
| 1235 | icon->setPixmap( QPixmap( (const char **) icon_data ) ); |
| 1236 | icon->setFixedSize( icon->sizeHint() ); |
| 1237 | |
| 1238 | QLabel * text = new QLabel( (const char *)message, this ); |
| 1239 | text->setAlignment( AlignHCenter | AlignVCenter | ExpandTabs ); |
| 1240 | |
| 1241 | QStringList buttonText = QStringList::split( DLG_BUTTON_SEP, (char *) buttons); |
| 1242 | int butNb = buttonText.count(); |
| 1243 | |
| 1244 | /* |
| 1245 | * Layout |
| 1246 | */ |
| 1247 | |
| 1248 | QVBoxLayout * vly = new QVBoxLayout( this, 5, 5 ); |
| 1249 | QHBoxLayout * hly1 = new QHBoxLayout( vly, 5); |
| 1250 | hly1->addWidget( icon ); |
| 1251 | hly1->addWidget( text ); |
| 1252 | QHBoxLayout * hly3 = new QHBoxLayout ( vly , 5); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1253 | if (textfield!=NULL) |
| 1254 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1255 | entry = new QLineEdit((const char *)textfield,this); |
| 1256 | entry->setText((const char *)textfield); |
| 1257 | hly3->addWidget( entry ); |
| 1258 | ret=textfield; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1259 | } |
| 1260 | else |
| 1261 | entry=NULL; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1262 | |
| 1263 | QHBoxLayout * hly2 = new QHBoxLayout( vly, 15); |
| 1264 | QString s; |
| 1265 | QPushButton * pushButton = 0L; |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1266 | for (int i=0; i<butNb; i++) |
| 1267 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1268 | s = buttonText[i]; |
| 1269 | pushButton = new QPushButton(s, this ); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1270 | if (s.find('&') != -1) |
| 1271 | pushButton->setAccel(s.at(s.find('&')+1).latin1()); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1272 | |
| 1273 | hly2->addWidget( pushButton ); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1274 | if (i == def_but-1) |
| 1275 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1276 | pushButton->setDefault( true ); |
| 1277 | pushButton->setAutoDefault( true ); |
| 1278 | setResult( i+1 ); |
| 1279 | } |
| 1280 | connect(pushButton, SIGNAL(clicked()), &mapper, SLOT(map())); |
| 1281 | mapper.setMapping(pushButton, i+1); |
| 1282 | } |
| 1283 | connect( &mapper, SIGNAL(mapped(int)), this, SLOT(done(int))); |
| 1284 | |
| 1285 | setCaption((const char *) title); |
| 1286 | |
| 1287 | vly->activate(); |
| 1288 | }//}}} |
| 1289 | |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1290 | void VimDialog::done(int r) |
| 1291 | { |
| 1292 | if (entry!=NULL) |
| 1293 | { |
| 1294 | if (r) |
| 1295 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1296 | QCString unistring=vmw->codec->fromUnicode(entry->text()); |
| 1297 | STRCPY(ret,(const char*)unistring); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1298 | } |
| 1299 | else |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1300 | *ret=NUL; |
| 1301 | } |
| 1302 | QDialog::done(r); |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | * ScrollBar pool handling |
| 1307 | */ |
| 1308 | SBPool::SBPool(void)//{{{ |
| 1309 | :mapper(this, "SBPool signal mapper") |
| 1310 | { |
| 1311 | connect(&mapper, SIGNAL(mapped(int)), this, SLOT(sbUsed(int))); |
| 1312 | }//}}} |
| 1313 | |
| 1314 | |
| 1315 | void SBPool::create(GuiScrollbar * sb, int orient)//{{{ |
| 1316 | { |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1317 | switch(orient) |
| 1318 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1319 | case SBAR_HORIZ: |
| 1320 | sb->w = new QScrollBar(QScrollBar::Horizontal, vmw); |
| 1321 | break; |
| 1322 | case SBAR_VERT: |
| 1323 | sb->w = new QScrollBar(QScrollBar::Vertical, vmw); |
| 1324 | break; |
| 1325 | default: |
| 1326 | sb->w = 0; |
| 1327 | return; |
| 1328 | } |
| 1329 | |
| 1330 | connect(sb->w, SIGNAL(valueChanged(int)), &mapper, SLOT(map())); |
| 1331 | mapper.setMapping(sb->w, (int)sb); |
| 1332 | }//}}} |
| 1333 | |
| 1334 | |
| 1335 | void SBPool::sbUsed(int who)//{{{ |
| 1336 | { |
| 1337 | GuiScrollbar *sb = (GuiScrollbar*)who; |
| 1338 | gui_drag_scrollbar( sb, sb->w->value(), FALSE); |
| 1339 | }//}}} |
| 1340 | |
| 1341 | |
| 1342 | void SBPool::destroy(GuiScrollbar * sb)//{{{ |
| 1343 | { |
| 1344 | if (!sb->w) return; |
| 1345 | |
| 1346 | delete sb->w; |
| 1347 | sb->w = 0; |
| 1348 | }//}}} |
| 1349 | |
| 1350 | #ifdef FEAT_CLIENTSERVER |
| 1351 | static int kvim_x11_event_filter( XEvent* e)//{{{ |
| 1352 | { |
| 1353 | if (e->xproperty.type == PropertyNotify |
| 1354 | && e->xproperty.atom == commProperty |
| 1355 | && e->xproperty.window == commWindow |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1356 | && e->xproperty.state == PropertyNewValue) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1357 | serverEventProc(qt_xdisplay(), e); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1358 | |
| 1359 | if (oldFilter) return oldFilter( e ); |
| 1360 | return FALSE; |
| 1361 | }//}}} |
| 1362 | #endif |
| 1363 | |
| 1364 | //add some QT 3 fonts usefull functions |
| 1365 | #if QT_VERSION<300 |
| 1366 | QString KVimUtils::toString(QFont *f) |
| 1367 | { |
| 1368 | QStringList l; |
| 1369 | l.append(f->family()); |
| 1370 | l.append(QString::number(f->pointSize())); |
| 1371 | l.append(QString::number(f->pixelSize())); |
| 1372 | l.append(QString::number((int)f->styleHint())); |
| 1373 | l.append(QString::number(f->weight())); |
| 1374 | l.append(QString::number((int)f->italic())); |
| 1375 | l.append(QString::number((int)f->underline())); |
| 1376 | l.append(QString::number((int)f->strikeOut())); |
| 1377 | l.append(QString::number((int)f->fixedPitch())); |
| 1378 | l.append(QString::number((int)f->rawMode())); |
| 1379 | return l.join(","); |
| 1380 | } |
| 1381 | |
| 1382 | bool KVimUtils::fromString(QFont *f, QString descrip) |
| 1383 | { |
| 1384 | QStringList l(QStringList::split(',', descrip)); |
| 1385 | |
| 1386 | int count = l.count(); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1387 | if (count != 10 && count != 9) |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1388 | return FALSE; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1389 | |
| 1390 | f->setFamily(l[0]); |
| 1391 | f->setPointSize(l[1].toInt()); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 1392 | if ( count == 9 ) |
| 1393 | { |
| 1394 | f->setStyleHint((QFont::StyleHint) l[2].toInt()); |
| 1395 | f->setWeight(l[3].toInt()); |
| 1396 | f->setItalic(l[4].toInt()); |
| 1397 | f->setUnderline(l[5].toInt()); |
| 1398 | f->setStrikeOut(l[6].toInt()); |
| 1399 | f->setFixedPitch(l[7].toInt()); |
| 1400 | f->setRawMode(l[8].toInt()); |
| 1401 | } |
| 1402 | else |
| 1403 | { |
| 1404 | f->setPixelSize(l[2].toInt()); |
| 1405 | f->setStyleHint((QFont::StyleHint) l[3].toInt()); |
| 1406 | f->setWeight(l[4].toInt()); |
| 1407 | f->setItalic(l[5].toInt()); |
| 1408 | f->setUnderline(l[6].toInt()); |
| 1409 | f->setStrikeOut(l[7].toInt()); |
| 1410 | f->setFixedPitch(l[8].toInt()); |
| 1411 | f->setRawMode(l[9].toInt()); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1412 | } |
| 1413 | return TRUE; |
| 1414 | } |
| 1415 | #endif |
| 1416 | |
| 1417 | QString KVimUtils::convertEncodingName(QString name) |
| 1418 | { |
| 1419 | if (name.startsWith("ucs") || name.startsWith("utf-16")) return QString("utf16"); |
| 1420 | if (name=="cp950") return QString("Big5"); |
| 1421 | return QString(); |
| 1422 | } |