blob: 52d1c9eadc0bee23435db61b5a877dc44f9703cd [file] [log] [blame]
Bram Moolenaar843ee412004-06-30 16:16:41 +00001/* 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 Moolenaar5eb86f92004-07-26 12:53:41 +000046#include "gui_kde_wid.h"
Bram Moolenaar843ee412004-06-30 16:16:41 +000047#include <qxembed.h>
48
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000049extern "C"
50{
Bram Moolenaar843ee412004-06-30 16:16:41 +000051#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 */
66struct special_key {//{{{
67 int qtkey;
68 char_u code0;
69 char_u code1;
70} special_keys[] =
71{
Bram Moolenaar81695252004-12-29 20:58:21 +000072 {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'},
Bram Moolenaar843ee412004-06-30 16:16:41 +0000121
Bram Moolenaar81695252004-12-29 20:58:21 +0000122 {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'},
Bram Moolenaar843ee412004-06-30 16:16:41 +0000128
Bram Moolenaar81695252004-12-29 20:58:21 +0000129 {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
Bram Moolenaar843ee412004-06-30 16:16:41 +0000140 /* End of list marker: */
Bram Moolenaar81695252004-12-29 20:58:21 +0000141 {0, 0, 0}
Bram Moolenaar843ee412004-06-30 16:16:41 +0000142};//}}}
143
144#ifdef FEAT_CLIENTSERVER
Bram Moolenaar81695252004-12-29 20:58:21 +0000145typedef int (*QX11EventFilter)(XEvent*);
146extern QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter);
147static QX11EventFilter oldFilter = 0;
148static int kvim_x11_event_filter(XEvent* e);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000149#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000150void gui_keypress(QKeyEvent *e);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000151
152/*
153 * Return OK if the key with the termcap name "name" is supported.
154 */
155 int
156gui_mch_haskey(char_u * name)//{{{
157{
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000158 for (int i = 0; special_keys[i].qtkey != 0; i++)
159 if (name[0] == special_keys[i].code0
160 && name[1] == special_keys[i].code1)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000161 return OK;
162 return FAIL;
163}//}}}
164
165/*
166 * custom Frame for drawing ...
167 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000168 void
169VimWidget::paintEvent(QPaintEvent *e)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000170{
171 QRect r = e->rect();
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000172 gui_redraw(r.x(), r.y(), r.width(), r.height());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000173}//}}}
174
Bram Moolenaar81695252004-12-29 20:58:21 +0000175 void
176VimWidget::draw_string(int x, int y, QString s, int len, int flags)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000177{
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000178 gui.current_font->setBold(flags & DRAW_BOLD);
179 gui.current_font->setUnderline(flags & DRAW_UNDERL);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000180 gui.current_font->setItalic(flags & DRAW_ITALIC);
Bram Moolenaar81695252004-12-29 20:58:21 +0000181 painter->setBackgroundMode(flags & DRAW_TRANSP
182 ? Qt::TransparentMode : Qt::OpaqueMode);
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000183 painter->setFont(*(gui.current_font));
184 painter->drawText(x, y, s, len);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000185}//}}}
186
Bram Moolenaar81695252004-12-29 20:58:21 +0000187 void
188VimWidget::mousePressEvent(QMouseEvent *event)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000189{
Bram Moolenaar81695252004-12-29 20:58:21 +0000190 int button = 0;
191 int modifiers = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000192 ButtonState state = event->state();
193 ButtonState buttons = event->button();
194
195 //Look at button states
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000196 if (buttons & QMouseEvent::LeftButton)
197 button |= MOUSE_LEFT;
198 if (buttons & QMouseEvent::RightButton)
199 button |= MOUSE_RIGHT;
200 if (buttons & QMouseEvent::MidButton)
201 button |= MOUSE_MIDDLE;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000202 //Look for keyboard modifiers
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000203 if (state & QMouseEvent::ShiftButton)
204 modifiers |= MOUSE_SHIFT;
205 if (state & QMouseEvent::ControlButton)
206 modifiers |= MOUSE_CTRL;
207 if (state & QMouseEvent::AltButton)
208 modifiers |= MOUSE_ALT;
Bram Moolenaar81695252004-12-29 20:58:21 +0000209 gui_send_mouse_event(button, event->x(), event->y(), FALSE, modifiers);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000210#if QT_VERSION>=300
211 QByteArray params;
212 QDataStream stream(params, IO_WriteOnly);
Bram Moolenaar81695252004-12-29 20:58:21 +0000213 stream << kapp->dcopClient()->appId() << button << modifiers
214 << gui.row << gui.col;
215 kapp->dcopClient()->emitDCOPSignal(
216 "mousePEvent(QCString, int, int, int, int)", params);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000217#endif
218 event->accept();
219}//}}}
220
221#if defined(FEAT_SESSION)
Bram Moolenaar81695252004-12-29 20:58:21 +0000222 void
223VimMainWindow::saveGlobalProperties(KConfig *conf)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000224{
225 //we write a mksession file to a file written in the user's ~/.kde/share/config/
226 //the name of the file in saved in 'conf'
227 //when restoring app, we source this file
228#if 0 //disabled for release
229 QString filename = KGlobal::dirs()->localkdedir() + KGlobal::dirs()->kde_default("config") + kapp->randomString(10);
230 QString cmd("mksession ");
231 cmd+=filename;
232 do_cmdline_cmd((char_u*)cmd.latin1());
233 conf->writePathEntry("sessionfile", filename);
234 conf->sync();
235#endif
236}
237
Bram Moolenaar81695252004-12-29 20:58:21 +0000238 void
239VimMainWindow::readGlobalProperties (KConfig *conf)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000240{
241#if 0
242 QString filename = conf->readPathEntry("sessionfile");
243 if (filename.isNull()) return;
244 QString cmd("source ");
245 cmd+=filename;
246 do_cmdline_cmd((char_u*)cmd.latin1());
247#endif
248}
249#endif
250
Bram Moolenaar81695252004-12-29 20:58:21 +0000251 void
252VimMainWindow::wheelEvent (QWheelEvent *event)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000253{
254 ButtonState state = event->state();
Bram Moolenaar81695252004-12-29 20:58:21 +0000255 int button = 0;
256 int modifiers = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000257
Bram Moolenaar81695252004-12-29 20:58:21 +0000258 if (event->delta() > 0)
259 button |= MOUSE_4;
260 else button |= MOUSE_5;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000261
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000262 if (state & ShiftButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000263 modifiers |= MOUSE_SHIFT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000264 if (state & ControlButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000265 modifiers |= MOUSE_CTRL;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000266 if (state & AltButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000267 modifiers |= MOUSE_ALT;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000268
Bram Moolenaar81695252004-12-29 20:58:21 +0000269 gui_send_mouse_event(button, event->x(), event->y(), FALSE, modifiers);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000270#if QT_VERSION>=300
271 QByteArray params;
272 QDataStream stream(params, IO_WriteOnly);
Bram Moolenaar81695252004-12-29 20:58:21 +0000273 stream << kapp->dcopClient()->appId() << button << modifiers
274 << gui.row << gui.col;
275 kapp->dcopClient()->emitDCOPSignal(
276 "mouseWhlEvent(QCString, int, int, int, int)", params);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000277#endif
278 event->accept();
279}//}}}
280
Bram Moolenaar81695252004-12-29 20:58:21 +0000281 void
282VimWidget::mouseDoubleClickEvent(QMouseEvent *event)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000283{
284 ButtonState state = event->state();
285 ButtonState buttons = event->button();
Bram Moolenaar81695252004-12-29 20:58:21 +0000286 int modifiers = 0;
287 int button = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000288
289 //Look at button states
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000290 if (buttons & LeftButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000291 button |= MOUSE_LEFT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000292 if (buttons & RightButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000293 button |= MOUSE_RIGHT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000294 if (buttons & MidButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000295 button |= MOUSE_MIDDLE;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000296
297 //Look for keyboard modifiers
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000298 if (state & ShiftButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000299 modifiers |= MOUSE_SHIFT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000300 if (state & ControlButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000301 modifiers |= MOUSE_CTRL;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000302 if (state & AltButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000303 modifiers |= MOUSE_ALT;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000304
Bram Moolenaar81695252004-12-29 20:58:21 +0000305 gui_send_mouse_event(button, event->x(), event->y(), TRUE, modifiers);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000306#if QT_VERSION>=300
307 QByteArray params;
308 QDataStream stream(params, IO_WriteOnly);
Bram Moolenaar81695252004-12-29 20:58:21 +0000309 stream << kapp->dcopClient()->appId() << button << modifiers
310 << gui.row << gui.col;
311 kapp->dcopClient()->emitDCOPSignal(
312 "mouseDblClickEvent(QCString, int, int, int, int)", params);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000313#endif
314 event->accept();
315}//}}}
316
Bram Moolenaar81695252004-12-29 20:58:21 +0000317 void
318VimWidget::mouseMoveEvent(QMouseEvent *event)//{{{
319{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000320 ButtonState state = event->state();
Bram Moolenaar81695252004-12-29 20:58:21 +0000321 int modifiers = 0;
322 int button = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000323
324 gui_mch_mousehide(FALSE);
325
326 //Look at button states
327 //warning: we use state here, this is important !
Bram Moolenaar81695252004-12-29 20:58:21 +0000328 if (state & QMouseEvent::LeftButton
329 || state & QMouseEvent::RightButton
330 || state & QMouseEvent::MidButton)
331 button |= MOUSE_DRAG;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000332
333 //Look for keyboard modifiers
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000334 if (state & ShiftButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000335 modifiers |= MOUSE_SHIFT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000336 if (state & ControlButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000337 modifiers |= MOUSE_CTRL;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000338 if (state & AltButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000339 modifiers |= MOUSE_ALT;
340 if (button != MOUSE_DRAG)
341 gui_mouse_moved(event->x(), event->y());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000342 else
Bram Moolenaar81695252004-12-29 20:58:21 +0000343 gui_send_mouse_event(MOUSE_DRAG, event->x(), event->y(),
344 FALSE, modifiers);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000345}//}}}
346
Bram Moolenaar81695252004-12-29 20:58:21 +0000347 void
348VimWidget::mouseReleaseEvent(QMouseEvent *event)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000349{
350 ButtonState state = event->state();
Bram Moolenaar81695252004-12-29 20:58:21 +0000351 int modifiers = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000352
353 //Look for keyboard modifiers
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000354 if (state & ShiftButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000355 modifiers |= MOUSE_SHIFT;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000356 if (state & ControlButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000357 modifiers |= MOUSE_CTRL;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000358 if (state & AltButton)
Bram Moolenaar81695252004-12-29 20:58:21 +0000359 modifiers |= MOUSE_ALT;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000360
Bram Moolenaar81695252004-12-29 20:58:21 +0000361 gui_send_mouse_event(MOUSE_RELEASE, event->x(), event->y(),
362 FALSE, modifiers);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000363 event->accept();
364}//}}}
365
366/*
367 * The main widget (everything but toolbar/menubar)
368 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000369VimWidget::VimWidget(QWidget *parent, const char *name, WFlags f)//{{{
370 :QWidget(parent, name, f)
371 , DCOPObject("KVim")
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000372#ifdef FEAT_MZSCHEME
Bram Moolenaar81695252004-12-29 20:58:21 +0000373 , mzscheme_timer_id(-1)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000374#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +0000375{
376 //to be able to show/hide the cursor when moving the mouse
377 setMouseTracking(true);
Bram Moolenaar81695252004-12-29 20:58:21 +0000378 painter = new QPainter(this);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000379
380 setKeyCompression(true);
Bram Moolenaar81695252004-12-29 20:58:21 +0000381 setFocusPolicy(QWidget::StrongFocus);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000382 setAcceptDrops(TRUE); // DND
383 blink_state = BLINK_NONE;
384 blink_on_time = 700;
385 blink_off_time = 400;
386 blink_wait_time = 250;
Bram Moolenaar81695252004-12-29 20:58:21 +0000387 connect( &blink_timer, SIGNAL(timeout()), SLOT(blink_cursor()));
388 connect( &wait_timer, SIGNAL(timeout()), SLOT(wait_timeout()));
389 setInputMethodEnabled(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000390}//}}}
391
Bram Moolenaar81695252004-12-29 20:58:21 +0000392 void
393VimWidget::execNormal(QString command)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000394{
395 QString cmd("execute 'normal ");
Bram Moolenaar81695252004-12-29 20:58:21 +0000396 cmd += command;
397 cmd += "'";
Bram Moolenaar843ee412004-06-30 16:16:41 +0000398 QCString unistring = vmw->codec->fromUnicode(cmd);
399 do_cmdline_cmd((char_u *)(const char*)unistring);
400 gui_update_screen();
401}//}}}
402
Bram Moolenaar81695252004-12-29 20:58:21 +0000403 void
404VimWidget::execInsert(QString command)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000405{
406 QString cmd("execute 'normal i");
Bram Moolenaar81695252004-12-29 20:58:21 +0000407 cmd += command;
408 cmd += "'";
Bram Moolenaar843ee412004-06-30 16:16:41 +0000409 QCString unistring = vmw->codec->fromUnicode(cmd);
410 do_cmdline_cmd((char_u *)(const char*)unistring);
411 gui_update_screen();
412}//}}}
413
Bram Moolenaar81695252004-12-29 20:58:21 +0000414 void
415VimWidget::execRaw(QString command)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000416{
417 QString cmd("execute '");
Bram Moolenaar81695252004-12-29 20:58:21 +0000418 cmd += command;
419 cmd += "'";
Bram Moolenaar843ee412004-06-30 16:16:41 +0000420 QCString unistring = vmw->codec->fromUnicode(cmd);
421 do_cmdline_cmd((char_u *)(const char*)unistring);
422 gui_update_screen();
423}//}}}
424
Bram Moolenaar81695252004-12-29 20:58:21 +0000425 void
426VimWidget::execCmd(QString command)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000427{
428 QCString unistring = vmw->codec->fromUnicode(command);
429 do_cmdline_cmd((char_u *)(const char*)unistring);
430 gui_update_screen();
431}//}}}
432
Bram Moolenaar81695252004-12-29 20:58:21 +0000433 QString
434VimWidget::eval(QString expr)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000435{
436#ifdef FEAT_EVAL
437 QCString unistring = vmw->codec->fromUnicode(expr);
Bram Moolenaar81695252004-12-29 20:58:21 +0000438 QString val((const char *)eval_to_string(
439 (char_u *)(const char*)unistring, NULL));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000440 return val;
441#else
442 return QString::null;
443#endif
444}//}}}
445
Bram Moolenaar81695252004-12-29 20:58:21 +0000446 void
447VimWidget::wait(long wtime)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000448{
Bram Moolenaar81695252004-12-29 20:58:21 +0000449 if (wait_timer.isActive())
450 wait_timer.stop();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000451 wait_done = false;
452 wait_timer.start( wtime, true);
453}//}}}
454
Bram Moolenaar81695252004-12-29 20:58:21 +0000455 void
456VimWidget::wait_timeout() //{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000457{
458 wait_done = true;
459}//}}}
460
Bram Moolenaar81695252004-12-29 20:58:21 +0000461 void
462VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000463{
464#if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO)
465 e->accept(QUriDrag::canDecode(e));
466#else
467 e->ignore();
468#endif
469}//}}}
470
Bram Moolenaar81695252004-12-29 20:58:21 +0000471 void
472VimWidget::dropEvent(QDropEvent *e) // {{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000473{
474#if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO)
Bram Moolenaar81695252004-12-29 20:58:21 +0000475 QStrList urls;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000476
477 char_u **fnames;
478 int redo_dirs = FALSE;
479 int i;
480 int n;
481 int nfiles;
482 int url = FALSE;
483
484 /* Count how many items there may be and normalize delimiters. */
485
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000486 if (QUriDrag::decode(e, urls))
487 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000488 n = urls.count();
Bram Moolenaar81695252004-12-29 20:58:21 +0000489 fnames = (char_u **)lalloc((n+1) * sizeof(char_u *), TRUE);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000490 nfiles = 0;
491#if QT_VERSION>=300
492 QPtrListIterator<char> it(urls);
Bram Moolenaar81695252004-12-29 20:58:21 +0000493 for (; it.current(); ++it)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000494 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000495 KURL u(*it);
496#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000497 for (i = 0; i < urls.count(); ++i)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000498 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000499 KURL u(urls.at(i));
500#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000501 if (!u.isLocalFile())
Bram Moolenaar843ee412004-06-30 16:16:41 +0000502 url = TRUE;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000503 else
504 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000505 fnames[nfiles] = (char_u *)strdup((const char *)u.path());
506 ++nfiles;
507 }
508 }
509 /* Real files (i.e. not http and not ftp) */
510 if (url == FALSE)
511 {
512 if (nfiles == 1)
513 {
514 if (mch_isdir(fnames[0]))
515 {
516 /* Handle dropping a directory on Vim. */
517 if (mch_chdir((char *)fnames[0]) == 0)
518 {
519 free(fnames[0]);
520 fnames[0] = NULL;
521 redo_dirs = TRUE;
522 }
523 }
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000524 }
525 else
526 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000527 /* Ignore any directories */
528 for (i = 0; i < nfiles; ++i)
529 {
530 if (mch_isdir(fnames[i]))
531 {
532 vim_free(fnames[i]);
533 fnames[i] = NULL;
534 }
535 }
536 }
537
538 if (0)
539 {
540 /* Shift held down, change to first file's directory */
541 if (fnames[0] != NULL && vim_chdirfile(fnames[0]) == OK)
542 redo_dirs = TRUE;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000543 }
544 else
545 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000546 char_u dirname[MAXPATHL];
547 char_u *s;
Bram Moolenaar81695252004-12-29 20:58:21 +0000548
Bram Moolenaar843ee412004-06-30 16:16:41 +0000549 if (mch_dirname(dirname, MAXPATHL) == OK)
550 for (i = 0; i < nfiles; ++i)
551 if (fnames[i] != NULL)
552 {
553 s = shorten_fname(fnames[i], dirname);
554 if (s != NULL && (s = vim_strsave(s)) != NULL)
555 {
556 vim_free(fnames[i]);
557 fnames[i] = s;
558 }
559 }
560 }
561 }
562
563 /* Handle the drop, :edit or :split to get to the file */
564 handle_drop(nfiles, fnames, FALSE);
565
566 if (redo_dirs)
567 shorten_fnames(TRUE);
568 }
569
570 /* Update the screen display */
571 update_screen(NOT_VALID);
572#ifdef FEAT_MENU
573 gui_update_menus(0);
574#endif
575 setcursor();
576 out_flush();
577 gui_update_cursor(FALSE, FALSE);
578 gui_mch_flush();
579#endif
580} // }}}
581
Bram Moolenaar81695252004-12-29 20:58:21 +0000582 void
583VimWidget::keyPressEvent(QKeyEvent *e) // {{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000584{
585 gui_keypress(e);
586} // }}}
587
Bram Moolenaar81695252004-12-29 20:58:21 +0000588 void
589gui_keypress(QKeyEvent *e) // {{{
590{
591 int key = (int)e->key();
592 int modifiers = 0, i;
593 uchar string[256], string2[256];
594 uchar *s, *d;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000595 Qt::ButtonState state = e->state();
596
597 QCString unistring = vmw->codec->fromUnicode(e->text());
Bram Moolenaar81695252004-12-29 20:58:21 +0000598 if (unistring.length() > 0)
599 strncpy((char*)string, (const char*)unistring, unistring.length());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000600 string[unistring.length()] = 0;
Bram Moolenaar81695252004-12-29 20:58:21 +0000601 int len = unistring.length();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000602
603 // ignore certain keys
Bram Moolenaar81695252004-12-29 20:58:21 +0000604 if (key == Qt::Key_Shift
605 || key == Qt::Key_Alt
606 || key == Qt::Key_Control
607 || key == Qt::Key_Meta
608 || key == Qt::Key_CapsLock
609 || key == Qt::Key_NumLock
610 || key == Qt::Key_ScrollLock)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000611 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000612 e->ignore();
613 return;
614 }
615
616#ifdef FEAT_MBYTE
617 if (input_conv.vc_type != CONV_NONE)
618 {
619 mch_memmove(string2, string, len);
620 len = convert_input(string2, len, sizeof(string2));
621 s = string2;
622 }
623 else
624#endif
625 s = string;
626 d = string;
627 for (i = 0; i < len; ++i)
628 {
629 *d++ = s[i];
630 if (d[-1] == CSI && d + 2 < string + sizeof(string))
631 {
632 /* Turn CSI into K_CSI. */
633 *d++ = KS_EXTRA;
634 *d++ = (int)KE_CSI;
635 }
636 }
637 len = d - string;
638
639
640 // change shift-tab (backtab) into S_TAB
Bram Moolenaar81695252004-12-29 20:58:21 +0000641 if (key == Qt::Key_BackTab && state & Qt::ShiftButton)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000642 key = Qt::Key_Tab;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000643
644 // Change C-@ and C-2 in NUL ? Gtk does this
Bram Moolenaar81695252004-12-29 20:58:21 +0000645 if ((key == Qt::Key_2 || key == Qt::Key_At) && state & Qt::ControlButton)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000646 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000647 string[0] = NUL;
648 len = 1;
649 }
650 else if (len == 0 && (key == Qt::Key_Space || key == Qt::Key_Tab))
651 {
652 /* When there are modifiers, these keys get zero length; we need the
653 * original key here to be able to add a modifier below. */
654 string[0] = (key & 0xff);
655 len = 1;
656 }
657 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character
658 * that already has the 8th bit set.
659 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. */
660 if (len == 1
661 && (key != Qt::Key_BackSpace && key != Qt::Key_Delete)
662 && (string[0] & 0x80) == 0
663 && (state & Qt::AltButton)
664 && !(key == Qt::Key_Tab && (state & Qt::ShiftButton)))
665 {
666 string[0] |= 0x80;
667#ifdef FEAT_MBYTE
668 if (enc_utf8) // convert to utf-8
669 {
670 string[1] = string[0] & 0xbf;
671 string[0] = ((unsigned)string[0] >> 6) + 0xc0;
672 if (string[1] == CSI)
673 {
674 string[2] = KS_EXTRA;
675 string[3] = (int)KE_CSI;
676 len = 4;
677 }
678 else
679 len = 2;
680 }
681#endif
682 }
683
684 /* Check for special keys, making sure BS and DEL are recognised. */
685 if (len == 0 || key == Qt::Key_BackSpace || key == Qt::Key_Delete)
686 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000687 while (special_keys[i].qtkey != 0 && special_keys[i].qtkey != key)
688 i++;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000689 if (special_keys[i].qtkey != 0)
690 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000691 string[0] = CSI;
692 string[1] = special_keys[i].code0;
693 string[2] = special_keys[i].code1;
694 len = -3;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000695 }
696/*
697 for (i = 0; special_keys[i].qtkey != 0 ; i++)
698 {
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000699 if (special_keys[i].qtkey == key )
700 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000701 string[0] = CSI;
702 string[1] = special_keys[i].code0;
703 string[2] = special_keys[i].code1;
704 len = -3;
705 break;
706 }
707 }*/
708 }
709
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000710 if (len == 0)
711 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000712 //no need to dump that, that's a QT problem, we can't do anything
713 //dbf("Unrecognised Key : %X %s", key, e->text().latin1());
714 e->ignore();
715 return;
716 }
717
718
719 /* Special keys (and a few others) may have modifiers */
Bram Moolenaar81695252004-12-29 20:58:21 +0000720 if (len == -3
721 || key == Qt::Key_Space
722 || key == Qt::Key_Tab
723 || key == Qt::Key_Return
724 || key == Qt::Key_Enter
725 || key == Qt::Key_Escape)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000726 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000727 modifiers = 0;
Bram Moolenaar81695252004-12-29 20:58:21 +0000728 if (state & Qt::ShiftButton)
729 modifiers |= MOD_MASK_SHIFT;
730 if (state & Qt::ControlButton)
731 modifiers |= MOD_MASK_CTRL;
732 if (state & Qt::AltButton)
733 modifiers |= MOD_MASK_ALT;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000734
735 /*
736 * For some keys a shift modifier is translated into another key
737 * code. Do we need to handle the case where len != 1 and
738 * string[0] != CSI?
739 */
740 if (len == -3)
741 key = TO_SPECIAL(string[1], string[2]);
742 else
743 key = string[0];
744
745 key = simplify_key(key, &modifiers);
Bram Moolenaar81695252004-12-29 20:58:21 +0000746 if (key == CSI)
747 key = K_CSI;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000748
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000749 if (IS_SPECIAL(key))
750 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000751 string[0] = CSI;
752 string[1] = K_SECOND(key);
753 string[2] = K_THIRD(key);
754 len = 3;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000755 }
756 else
757 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000758 string[0] = key;
759 len = 1;
760 }
761
Bram Moolenaar81695252004-12-29 20:58:21 +0000762 if (modifiers != 0)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000763 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000764 uchar string2[10];
765 string2[0] = CSI;
766 string2[1] = KS_MODIFIER;
767 string2[2] = modifiers;
768 add_to_input_buf(string2, 3);
769 }
770
771 } /* special keys */
772
773 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts)
Bram Moolenaar81695252004-12-29 20:58:21 +0000774 || (string[0] == intr_char && intr_char != Ctrl_C)))
Bram Moolenaar843ee412004-06-30 16:16:41 +0000775 {
776 trash_input_buf();
777 got_int = TRUE;
778 }
779
780 add_to_input_buf(string, len);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000781 if (p_mh)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000782 gui_mch_mousehide(TRUE);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000783
Bram Moolenaar843ee412004-06-30 16:16:41 +0000784 //DCOP Embedding stuff
785 //if we are here then the user has type something in the window, thus we can easily imagine that :
786 // 1 - text has changed (emit textChanged())
787 // 2 - characters were interactively inserted (emit charactersInteractivelyInserted())
788 // 3 - cursor position has changed ( emit cursorPositionChanged() )
789 // 4 - selection has changed ? dunno yet //XXX
790 // 5 - undo changed too ? (each character typed in makes the undo changes anyway)
791 // conclusion : this makes a lot of things to send to the vim kpart, maybe too much
792 // for now i'll just send : keyboardEvent to the kpart with the event string as parameter,
793 // with current current position
794 // i'll do the same for mouseEvents
795#if QT_VERSION>=300
796 QByteArray params;
797 QDataStream stream(params, IO_WriteOnly);
798 stream << kapp->dcopClient()->appId() << unistring << gui.row << gui.col;
Bram Moolenaar81695252004-12-29 20:58:21 +0000799 kapp->dcopClient()->emitDCOPSignal(
800 "keyboardEvent(QCString, QCString, int, int)", params);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000801#endif
802 e->ignore();
803} // }}}
804
805#ifdef FEAT_CLIENTSERVER
Bram Moolenaar81695252004-12-29 20:58:21 +0000806 void
807VimWidget::serverActivate(WId id) //{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000808{
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000809 if (serverName == NULL && serverDelayedStartName != NULL)
810 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000811 commWindow = id;
812 (void)serverRegisterName(qt_xdisplay(), serverDelayedStartName);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000813 }
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000814 else
815 serverChangeRegisteredWindow( qt_xdisplay(), id);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000816}//}}}
817#endif
818
819#ifdef FEAT_XIM
Bram Moolenaar81695252004-12-29 20:58:21 +0000820
821static int preedit_buf_len = 0;
822static int im_preedit_cursor = 0;
823static int im_preedit_trailing = 0;
824
825 static void
826im_delete_preedit(void)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000827{
Bram Moolenaar81695252004-12-29 20:58:21 +0000828 char_u bskey[] = {CSI, 'k', 'b'};
829 char_u delkey[] = {CSI, 'k', 'D'};
830
831 if (State & NORMAL)
832 {
833 im_preedit_cursor = 0;
834 return;
835 }
836 for (; im_preedit_cursor > 0; --im_preedit_cursor)
837 add_to_input_buf(bskey, (int)sizeof(bskey));
838
839 for (; im_preedit_trailing > 0; --im_preedit_trailing)
840 add_to_input_buf(delkey, (int)sizeof(delkey));
841}
842
843 void
844im_set_position(int row, int col)
845{
846 vmw->w->setMicroFocusHint(
847 TEXT_X(gui.col),
848 TEXT_Y(gui.row), 0, 0, TRUE, &vmw->w->font());
849}
850
851 int
852im_is_preediting()
853{
854 return (preedit_start_col != MAXCOL);
855}
856
857 int
858im_get_feedback_attr(int col)
859{
860 if (draw_feedback != NULL && col < preedit_buf_len)
861 {
862 if (draw_feedback[col] & XIMReverse)
863 return HL_INVERSE;
864 else if (draw_feedback[col] & XIMUnderline)
865 return HL_UNDERLINE;
866 else
867 return hl_attr(HLF_V);
868 }
869
870 return -1;
871}
872
873 void
874VimWidget::imStartEvent(QIMEvent *e)
875{
876 if (State & CMDLINE)
877 preedit_start_col = cmdline_getvcol_cursor();
878 else if (curwin != NULL)
879 getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL);
880 xic = (XIC)!NULL;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000881 e->accept();
882}
883
Bram Moolenaar81695252004-12-29 20:58:21 +0000884 void
885VimWidget::imEndEvent(QIMEvent *e)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000886{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000887 uchar string[256];
888
Bram Moolenaar81695252004-12-29 20:58:21 +0000889 im_delete_preedit();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000890
Bram Moolenaar81695252004-12-29 20:58:21 +0000891 QCString unistring = vmw->codec->fromUnicode(e->text());
892 if (unistring.length() > 0)
893 strncpy((char*)string, (const char*)unistring, unistring.length());
894 string[unistring.length()] = 0;
895 int len = unistring.length();
896
897 add_to_input_buf_csi(string, len);
898 im_preedit_cursor = 0;
899 im_preedit_trailing = 0;
900 preedit_start_col = MAXCOL;
901 preedit_buf_len = 0;
902 if (draw_feedback)
903 {
904 free(draw_feedback);
905 draw_feedback = NULL;
906 }
907 xic = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000908 e->accept();
909}
910
Bram Moolenaar81695252004-12-29 20:58:21 +0000911 void
912VimWidget::imComposeEvent(QIMEvent *e)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000913{
Bram Moolenaar81695252004-12-29 20:58:21 +0000914 uchar string[256];
915 char_u backkey[] = {CSI, 'k', 'l'};
916
917 im_delete_preedit();
918
919 if (State & NORMAL)
920 {
921 im_preedit_cursor = 0;
922 return;
923 }
924
925 QCString unistring = vmw->codec->fromUnicode(e->text());
926 if (unistring.length() > 0)
927 strncpy((char*)string, (const char*)unistring,unistring.length());
928 string[unistring.length()] = 0;
929 int len = unistring.length();
930 add_to_input_buf_csi(string, len);
931
932 preedit_buf_len = e->text().length();
933 if (draw_feedback == NULL)
934 draw_feedback = (char *)alloc(preedit_buf_len);
935 else
936 draw_feedback = (char *)realloc(draw_feedback, preedit_buf_len);
937 preedit_end_col = preedit_start_col;
938
939 char_u *p = string;
940 for (int n = 0; n < preedit_buf_len; n++)
941 {
942 if (n < e->cursorPos() || n >= e->cursorPos() + e->selectionLength())
943 draw_feedback[n] = XIMUnderline;
944 else
945 draw_feedback[n] = XIMReverse;
946 preedit_end_col += (*mb_ptr2cells)(p);
947 p += (*mb_ptr2len_check)(p);
948 }
949 im_preedit_cursor = e->cursorPos();
950 im_preedit_trailing = preedit_buf_len - im_preedit_cursor;
951
952# ifdef FEAT_RIGHTLEFT
953 if ((State & CMDLINE) == 0 && curwin != NULL && curwin->w_p_rl)
954 backkey[2] = 'r';
955# endif
956 for (int n = 0; n < im_preedit_trailing; n++)
957 add_to_input_buf(backkey, (int)sizeof(backkey));
958
Bram Moolenaar843ee412004-06-30 16:16:41 +0000959 e->accept();
960}
961#endif
962
963
Bram Moolenaar81695252004-12-29 20:58:21 +0000964 void
965VimMainWindow::lock()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000966{
Bram Moolenaar81695252004-12-29 20:58:21 +0000967 locked = true;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000968}
969
Bram Moolenaar81695252004-12-29 20:58:21 +0000970 void
971VimMainWindow::unlock()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000972{
Bram Moolenaar81695252004-12-29 20:58:21 +0000973 locked = false;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000974}
975
Bram Moolenaar81695252004-12-29 20:58:21 +0000976 bool
977VimMainWindow::isLocked()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000978{
979 return locked;
980}
981
982// ->resize VimWidget if not locked
983//
Bram Moolenaar81695252004-12-29 20:58:21 +0000984 void
985VimMainWindow::resizeEvent(QResizeEvent *e) //{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000986{
Bram Moolenaar81695252004-12-29 20:58:21 +0000987 if (vmw->isLocked())
988 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000989 //remove toolbar and menubar height
990 int height = e->size().height();
991 int width = e->size().width();
992
993 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
994#if QT_VERSION>=300
995 && !vmw->menuBar()->isTopLevelMenu()
996#endif
997 )
998 height -= vmw->menuBar()->height();
999#ifdef FEAT_TOOLBAR
Bram Moolenaar81695252004-12-29 20:58:21 +00001000 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1001 && (vmw->toolBar()->barPos() == KToolBar::Top
1002 || vmw->toolBar()->barPos() == KToolBar::Bottom))
Bram Moolenaar843ee412004-06-30 16:16:41 +00001003 height -= vmw->toolBar()->height();
1004
Bram Moolenaar81695252004-12-29 20:58:21 +00001005 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1006 && (vmw->toolBar()->barPos() == KToolBar::Left
1007 || vmw->toolBar()->barPos() == KToolBar::Right))
Bram Moolenaar843ee412004-06-30 16:16:41 +00001008 width -= vmw->toolBar()->width();
1009#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001010 height = ((int)(height/gui.char_height))*gui.char_height;
1011 if (!vmw->isLocked())
1012 gui_resize_shell(width, height);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001013}//}}}
1014
Bram Moolenaar81695252004-12-29 20:58:21 +00001015 void
1016VimWidget::focusInEvent(QFocusEvent *fe) // {{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001017{
1018 gui_focus_change(true);
1019
1020 if (blink_state == BLINK_NONE)
1021 gui_mch_start_blink();
1022} // }}}
1023
Bram Moolenaar81695252004-12-29 20:58:21 +00001024 void
1025VimWidget::focusOutEvent(QFocusEvent *fe)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001026{
1027 gui_focus_change(false);
1028
1029 if (blink_state != BLINK_NONE)
1030 gui_mch_stop_blink();
1031}//}}}
1032
Bram Moolenaar81695252004-12-29 20:58:21 +00001033 void
1034VimWidget::set_blink_time(long wait, long on, long off)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001035{
1036 blink_wait_time = wait;
1037 blink_on_time = on;
1038 blink_off_time = off;
1039}//}}}
1040
Bram Moolenaar81695252004-12-29 20:58:21 +00001041 void
1042VimWidget::start_cursor_blinking()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001043{
Bram Moolenaar81695252004-12-29 20:58:21 +00001044 if (blink_timer.isActive())
1045 blink_timer.stop();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001046
1047 /* Only switch blinking on if none of the times is zero */
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001048 if (blink_wait_time && blink_on_time && blink_off_time && gui.in_focus)
1049 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001050 blink_state = BLINK_ON;
1051 gui_update_cursor(TRUE, FALSE);
1052 // The first blink appears after wait_time
1053 blink_timer.start( blink_wait_time, true);
1054 }
1055}//}}}
1056
Bram Moolenaar81695252004-12-29 20:58:21 +00001057 void
1058VimWidget::blink_cursor()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001059{
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001060 if (blink_state == BLINK_ON)
1061 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001062 // set cursor off
1063 gui_undraw_cursor();
1064 blink_state = BLINK_OFF;
1065 blink_timer.start( blink_off_time, true);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001066 }
1067 else
1068 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001069 // set cursor on
1070 gui_update_cursor(TRUE, FALSE);
1071 blink_state = BLINK_ON;
1072 blink_timer.start( blink_on_time, true);
1073 }
1074}//}}}
1075
Bram Moolenaar81695252004-12-29 20:58:21 +00001076 void
1077VimWidget::stop_cursor_blinking()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001078{
Bram Moolenaar81695252004-12-29 20:58:21 +00001079 if (blink_timer.isActive())
1080 blink_timer.stop();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001081
1082 if (blink_state == BLINK_OFF)
1083 gui_update_cursor(TRUE, FALSE);
1084
1085 blink_state = BLINK_NONE;
1086}//}}}
1087
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00001088#ifdef FEAT_MZSCHEME
Bram Moolenaar81695252004-12-29 20:58:21 +00001089 void
1090VimWidget::timerEvent(QTimerEvent * evnt)//{{{
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00001091{
1092 if (evnt->timerId() == mzscheme_timer_id)
1093 timer_proc();
1094}//}}}
1095
Bram Moolenaar81695252004-12-29 20:58:21 +00001096 void
1097VimWidget::enable_mzscheme_threads()//{{{
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00001098{
1099 mzscheme_timer_id = startTimer(p_mzq);
1100}//}}}
1101
Bram Moolenaar81695252004-12-29 20:58:21 +00001102 void
1103VimWidget::disable_mzscheme_threads()//{{{
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00001104{
1105 killTimer(mzscheme_timer_id);
1106}//}}}
1107#endif
1108
Bram Moolenaar81695252004-12-29 20:58:21 +00001109 void
1110VimWidget::flash()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001111{
1112 QPainter p(this);
1113
1114 p.setRasterOp(Qt::XorROP);
Bram Moolenaar81695252004-12-29 20:58:21 +00001115 p.fillRect(geometry(), QColor(0xFF, 0xFF, 0xFF));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001116 p.flush();
1117 //FIXME: Make this a little smarter. Maybe add a timer or something
1118 usleep(19000);
Bram Moolenaar81695252004-12-29 20:58:21 +00001119 p.fillRect(geometry(), QColor(0xFF, 0xFF, 0xFF));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001120 p.flush();
1121 p.end();
1122}//}}}
1123
1124
1125/*
1126 * The main Window
1127 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001128VimMainWindow::VimMainWindow(const char *name , WFlags f)//{{{
1129 :KMainWindow(0L, name, f)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001130{
1131#ifdef FEAT_CLIENTSERVER
Bram Moolenaar81695252004-12-29 20:58:21 +00001132 oldFilter = qt_set_x11_event_filter(kvim_x11_event_filter);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001133#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001134 if (echo_wid_arg == 1)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001135 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001136 fprintf(stderr, "WID: %ld\n", (long)winId());
1137 fflush(stderr);
1138 }
1139
1140 w = new VimWidget(this, "main vim widget");
1141 gui.w = w;
1142 setFocusProxy(w);
1143 w->setFocus();
Bram Moolenaar81695252004-12-29 20:58:21 +00001144 have_tearoff = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001145
Bram Moolenaar81695252004-12-29 20:58:21 +00001146 finddlg = new KEdFind(this, 0, false);
1147 repldlg = new KEdReplace(this, 0, false);
1148 QObject::connect(finddlg, SIGNAL(search()), this, SLOT(slotSearch()));
1149 QObject::connect(repldlg, SIGNAL(find()), this, SLOT(slotFind()));
1150 QObject::connect(repldlg, SIGNAL(replace()), this, SLOT(slotReplace()));
1151 QObject::connect(repldlg, SIGNAL(replaceAll()), this,
1152 SLOT(slotReplaceAll()));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001153
1154#ifdef FEAT_TOOLBAR
1155 connect(toolBar(), SIGNAL(clicked(int)), this, SLOT(menu_activated(int)));
1156#endif
1157#ifdef FEAT_CLIENTSERVER
1158 w->serverActivate(winId());
1159
Bram Moolenaar81695252004-12-29 20:58:21 +00001160 if (serverName != NULL)
1161 kapp->dcopClient()->registerAs(QCString((const char*)serverName),
1162 false);
1163 else if (serverDelayedStartName != NULL)
1164 kapp->dcopClient()->registerAs(
1165 QCString((const char*)serverDelayedStartName), false);
1166 else if (argServerName != NULL)
1167 kapp->dcopClient()->registerAs(argServerName->utf8(), false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001168#else
Bram Moolenaar81695252004-12-29 20:58:21 +00001169 if (argServerName != NULL)
1170 kapp->dcopClient()->registerAs(argServerName->utf8(), false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001171#endif
1172 QXEmbed::initialize();
1173
1174}//{{{
1175
Bram Moolenaar81695252004-12-29 20:58:21 +00001176 bool
1177VimMainWindow::queryClose()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001178{
1179 gui_shell_closed();
1180 return true;
1181}//}}}
1182
Bram Moolenaar81695252004-12-29 20:58:21 +00001183 bool
1184VimMainWindow::queryExit()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001185{
1186 return true;
1187}//}}}
1188
Bram Moolenaar81695252004-12-29 20:58:21 +00001189 void
1190VimMainWindow::menu_activated(int dx)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001191{
1192#ifdef FEAT_MENU
Bram Moolenaar81695252004-12-29 20:58:21 +00001193 if (!dx) // tearoff
Bram Moolenaar843ee412004-06-30 16:16:41 +00001194 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001195 gui_mch_set_foreground();
Bram Moolenaar81695252004-12-29 20:58:21 +00001196 gui_menu_cb((VimMenu *)dx);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001197#endif
1198}//}}}
1199
1200
Bram Moolenaar81695252004-12-29 20:58:21 +00001201 void
1202VimMainWindow::clipboard_selection_update()//{{{
1203{
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001204 if (kapp->clipboard()->ownsSelection())
Bram Moolenaar843ee412004-06-30 16:16:41 +00001205 clip_own_selection(&clip_star);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001206 else
Bram Moolenaar843ee412004-06-30 16:16:41 +00001207 clip_lose_selection(&clip_star);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001208}//}}}
1209
Bram Moolenaar81695252004-12-29 20:58:21 +00001210 void
1211VimMainWindow::clipboard_data_update()//{{{
1212{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001213#if QT_VERSION>=300
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001214 if (kapp->clipboard()->ownsClipboard())
Bram Moolenaar843ee412004-06-30 16:16:41 +00001215 clip_own_selection(&clip_plus);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001216 else
Bram Moolenaar843ee412004-06-30 16:16:41 +00001217 clip_lose_selection(&clip_plus);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001218#else
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001219 if (kapp->clipboard()->ownsSelection())
Bram Moolenaar843ee412004-06-30 16:16:41 +00001220 clip_own_selection(&clip_star);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001221 else
Bram Moolenaar843ee412004-06-30 16:16:41 +00001222 clip_lose_selection(&clip_star);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001223#endif
1224}//}}}
1225
Bram Moolenaar81695252004-12-29 20:58:21 +00001226 void
1227VimMainWindow::slotSearch()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001228{
1229 QString find_text;
1230 bool direction_down = TRUE;
1231 bool casesensitive = TRUE;
1232 int flags = FRD_FINDNEXT;
1233
1234 find_text = finddlg->getText();
1235 direction_down = !(finddlg->get_direction());
1236 casesensitive = finddlg->case_sensitive();
1237 // if (casesensitive) find_text = "\\C" + find_text;
1238 // else find_text = "\\c" + find_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001239 if (casesensitive)
1240 flags |= FRD_MATCH_CASE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001241 QCString unistring = vmw->codec->fromUnicode(find_text);
Bram Moolenaar81695252004-12-29 20:58:21 +00001242 gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,
1243 (int)direction_down);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001244}//}}}
1245
Bram Moolenaar81695252004-12-29 20:58:21 +00001246 void
1247VimMainWindow::slotFind()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001248{
1249 QString find_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001250 bool direction_down = TRUE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001251 bool casesensitive = TRUE;
1252 int flags = FRD_R_FINDNEXT;
1253
Bram Moolenaar81695252004-12-29 20:58:21 +00001254 find_text = repldlg->getText();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001255 direction_down = !(repldlg->get_direction());
1256 casesensitive = repldlg->case_sensitive();
1257 // if (casesensitive) find_text = "\\C" + find_text;
1258 // else find_text = "\\c" + find_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001259 if (casesensitive) flags |= FRD_MATCH_CASE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001260
1261 QCString unistring = vmw->codec->fromUnicode(find_text);
Bram Moolenaar81695252004-12-29 20:58:21 +00001262 gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,
1263 (int)direction_down);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001264}//}}}
1265
Bram Moolenaar81695252004-12-29 20:58:21 +00001266 void
1267VimMainWindow::slotReplace()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001268{
1269 QString find_text;
1270 QString repl_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001271 bool direction_down = TRUE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001272 bool casesensitive = TRUE;
1273 int flags = FRD_REPLACE;
1274
Bram Moolenaar81695252004-12-29 20:58:21 +00001275 find_text = repldlg->getText();
1276 repl_text = repldlg->getReplaceText();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001277 direction_down = !(repldlg->get_direction());
1278 //if (casesensitive) find_text = "\\C" + find_text;
1279 //else find_text = "\\c" + find_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001280 if (casesensitive) flags |= FRD_MATCH_CASE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001281
1282 QCString unistring = vmw->codec->fromUnicode(find_text);
1283 QCString unistring2 = vmw->codec->fromUnicode(repl_text);
Bram Moolenaar81695252004-12-29 20:58:21 +00001284 gui_do_findrepl(flags, (char_u *)(const char *)unistring,
1285 (char_u *)(const char*)unistring2, (int)direction_down);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001286}//}}}
1287
Bram Moolenaar81695252004-12-29 20:58:21 +00001288 void
1289VimMainWindow::slotReplaceAll()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001290{
1291 QString find_text;
1292 QString repl_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001293 bool direction_down = TRUE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001294 bool casesensitive = TRUE;
1295 int flags = FRD_REPLACEALL;
1296
Bram Moolenaar81695252004-12-29 20:58:21 +00001297 find_text = repldlg->getText();
1298 repl_text = repldlg->getReplaceText();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001299 direction_down = !(repldlg->get_direction());
1300 casesensitive = repldlg->case_sensitive();
1301 // if (casesensitive) find_text = "\\C" + find_text;
1302 // else find_text = "\\c" + find_text;
Bram Moolenaar81695252004-12-29 20:58:21 +00001303 if (casesensitive)
1304 flags |= FRD_MATCH_CASE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001305 QCString unistring = vmw->codec->fromUnicode(find_text);
1306 QCString unistring2 = vmw->codec->fromUnicode(repl_text);
Bram Moolenaar81695252004-12-29 20:58:21 +00001307 gui_do_findrepl(flags, (char_u *)(const char *)unistring,
1308 (char_u *)(const char*)unistring2, (int)direction_down);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001309}//}}}
1310
Bram Moolenaar81695252004-12-29 20:58:21 +00001311 void
1312VimMainWindow::showAboutKDE()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001313{
1314 KAboutKDE *kde = new KAboutKDE(this);
1315 kde->show();
1316}
1317
Bram Moolenaar81695252004-12-29 20:58:21 +00001318 void
1319VimMainWindow::showAboutApplication()//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001320{
Bram Moolenaar81695252004-12-29 20:58:21 +00001321 KAboutData *aboutData = new KAboutData(
Bram Moolenaar843ee412004-06-30 16:16:41 +00001322 "kvim"
1323 , I18N_NOOP("KVim")
1324 , VIM_VERSION_SHORT
1325 , I18N_NOOP("Vim in a KDE interface")
1326 , 0
1327 , "(c) Vim Team, \":help credits\" for more infos.\nType \":help iccf\" to see how you can help the children in Uganda"
1328 , 0l
1329 , "http://freehackers.org/kvim"
1330 , "kvim-dev@freenux.org"
1331 );
1332
1333 aboutData->addAuthor("Bram Moolenaar",
1334 I18N_NOOP("Main vim author"),
1335 "Bram@vim.org",
1336 "http://www.vim.org/");
1337 aboutData->addAuthor("Thomas Capricelli",
1338 I18N_NOOP("KDE porting"),
1339 "orzel@freehackers.org",
1340 "http://orzel.freehackers.org");
1341 aboutData->addAuthor("Philippe Fremy",
1342 I18N_NOOP("KDE porting"),
1343 "pfremy@chez.com",
1344 "http://www.freehackers.org/kvim");
1345 aboutData->addAuthor("Mark Westcott",
1346 I18N_NOOP("Qtopia porting, maintainer of the Qtopia part"),
1347 "mark@houseoffish.org",
1348 "http://houseoffish.org");
1349 aboutData->addAuthor("Mickael Marchand",
1350 I18N_NOOP("KDE porting, maintainer"),
1351 "marchand@kde.org",
1352 "http://freenux.org");
1353 aboutData->addAuthor("Many other people",
1354 I18N_NOOP("type :help credits for more infos")
1355 );
1356 aboutData->addCredit("Vince Negri",
1357 I18N_NOOP("Antialiasing support, Color fixes"),
1358 "vnegri@asl-electronics.co.uk");
1359 aboutData->addCredit("Malte Starostik",
1360 I18N_NOOP("Patch for performance improvement"),
1361 "malte@kde.org");
1362 aboutData->addCredit("Mark Stosberg",
1363 I18N_NOOP("Provided a FreeBSD box to debug KVim on BSD"),
1364 "mark@summersault.com"
1365 );
1366 aboutData->addCredit("Henrik Skott",
1367 I18N_NOOP("Font patch when KDE not configured"),
1368 "henrik.skott@hem.utfors.se"
1369 );
1370 aboutData->addCredit("Kailash Sethuraman",
1371 I18N_NOOP("NetBSD configure/compilation fixes")
1372 );
1373 aboutData->setLicenseText(
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001374"KVim as an extension of Vim follows Vim license.\n\
1375You can read it with \":help license\"\n\
1376Or read the file $VIMRUNTIME/doc/uganda.txt.");
Bram Moolenaar843ee412004-06-30 16:16:41 +00001377
1378 KAboutApplication *about = new KAboutApplication(aboutData);
1379 about->show();
1380}//}}}
1381
Bram Moolenaar81695252004-12-29 20:58:21 +00001382 void
1383VimMainWindow::showTipOfTheDay()
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001384{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001385#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001386 KTipDialog::showTip(vmw, QString::null, true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001387#endif
1388}
1389
Bram Moolenaar81695252004-12-29 20:58:21 +00001390 void
1391VimMainWindow::buffersToolbar()
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001392{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001393
1394}
1395
Bram Moolenaar81695252004-12-29 20:58:21 +00001396 void
1397VimMainWindow::showBugReport()
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001398{
Bram Moolenaar81695252004-12-29 20:58:21 +00001399 KBugReport *bug= new KBugReport(this, true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001400 bug->show();
1401}
Bram Moolenaar81695252004-12-29 20:58:21 +00001402
Bram Moolenaar843ee412004-06-30 16:16:41 +00001403/*
1404 * Vim Dialog
1405 *
1406 * Returns:
1407 * 0: Cancel
1408 * 1- : nb of the pressed button
1409 */
1410
Bram Moolenaar81695252004-12-29 20:58:21 +00001411VimDialog::VimDialog(int type, /* type of dialog *///{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001412 char_u * title, /* title of dialog */
1413 char_u * message, /* message text */
1414 char_u * buttons, /* names of buttons */
1415 int def_but, /* default button */
Bram Moolenaar81695252004-12-29 20:58:21 +00001416 char_u *textfield) /* input field */
1417 :QDialog(vmw, "vim generic dialog", true), // true is for "modal"
Bram Moolenaar843ee412004-06-30 16:16:41 +00001418 mapper(this, "dialog signal mapper")
1419{
1420 /*
1421 * Create Icon
1422 */
1423 char ** icon_data;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001424 switch (type)
1425 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001426 case VIM_GENERIC:
1427 icon_data = generic_xpm;
1428 break;
1429 case VIM_ERROR:
1430 icon_data = error_xpm;
1431 break;
1432 case VIM_WARNING:
1433 icon_data = alert_xpm;
1434 break;
1435 case VIM_INFO:
1436 icon_data = info_xpm;
1437 break;
1438 case VIM_QUESTION:
1439 icon_data = quest_xpm;
1440 break;
1441 default:
1442 icon_data = generic_xpm;
1443 };
Bram Moolenaar81695252004-12-29 20:58:21 +00001444 QLabel * icon = new QLabel(this);
1445 icon->setPixmap(QPixmap((const char **) icon_data));
1446 icon->setFixedSize(icon->sizeHint());
Bram Moolenaar843ee412004-06-30 16:16:41 +00001447
Bram Moolenaar81695252004-12-29 20:58:21 +00001448 QLabel * text = new QLabel(QSTR(message), this);
1449 text->setAlignment(AlignHCenter | AlignVCenter | ExpandTabs);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001450
Bram Moolenaar81695252004-12-29 20:58:21 +00001451 QStringList buttonText = QStringList::split(DLG_BUTTON_SEP, QSTR(buttons));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001452 int butNb = buttonText.count();
1453
1454 /*
1455 * Layout
1456 */
1457
Bram Moolenaar81695252004-12-29 20:58:21 +00001458 QVBoxLayout * vly = new QVBoxLayout(this, 5, 5);
1459 QHBoxLayout * hly1 = new QHBoxLayout(vly, 5);
1460 hly1->addWidget(icon);
1461 hly1->addWidget(text);
1462 QHBoxLayout * hly3 = new QHBoxLayout(vly , 5);
1463 if (textfield != NULL)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001464 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001465 entry = new QLineEdit(QSTR(textfield), this);
1466 entry->setText(QSTR(textfield));
1467 hly3->addWidget(entry);
1468 ret = textfield;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001469 }
1470 else
Bram Moolenaar81695252004-12-29 20:58:21 +00001471 entry = NULL;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001472
Bram Moolenaar81695252004-12-29 20:58:21 +00001473 QHBoxLayout * hly2 = new QHBoxLayout(vly, 15);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001474 QString s;
1475 QPushButton * pushButton = 0L;
Bram Moolenaar81695252004-12-29 20:58:21 +00001476 for (int i = 0; i<butNb; i++)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001477 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001478 s = buttonText[i];
Bram Moolenaar81695252004-12-29 20:58:21 +00001479 pushButton = new QPushButton(s, this);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001480 if (s.find('&') != -1)
Bram Moolenaar81695252004-12-29 20:58:21 +00001481 pushButton->setAccel(s.at(s.find('&') + 1).latin1());
Bram Moolenaar843ee412004-06-30 16:16:41 +00001482
Bram Moolenaar81695252004-12-29 20:58:21 +00001483 hly2->addWidget(pushButton);
1484 if (i == def_but - 1)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001485 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001486 pushButton->setDefault(true);
1487 pushButton->setAutoDefault(true);
1488 setResult(i + 1);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001489 }
1490 connect(pushButton, SIGNAL(clicked()), &mapper, SLOT(map()));
Bram Moolenaar81695252004-12-29 20:58:21 +00001491 mapper.setMapping(pushButton, i + 1);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001492 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001493 connect(&mapper, SIGNAL(mapped(int)), this, SLOT(done(int)));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001494
Bram Moolenaar81695252004-12-29 20:58:21 +00001495 setCaption(QSTR(title));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001496
1497 vly->activate();
1498}//}}}
1499
Bram Moolenaar81695252004-12-29 20:58:21 +00001500 void
1501VimDialog::done(int r)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001502{
Bram Moolenaar81695252004-12-29 20:58:21 +00001503 if (entry != NULL)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001504 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001505 if (r)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001506 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001507 QCString unistring = vmw->codec->fromUnicode(entry->text());
1508 STRCPY(ret, (const char*)unistring);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001509 }
1510 else
Bram Moolenaar81695252004-12-29 20:58:21 +00001511 *ret = NUL;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001512 }
1513 QDialog::done(r);
1514}
1515
1516/*
1517 * ScrollBar pool handling
1518 */
1519SBPool::SBPool(void)//{{{
1520 :mapper(this, "SBPool signal mapper")
1521{
1522 connect(&mapper, SIGNAL(mapped(int)), this, SLOT(sbUsed(int)));
1523}//}}}
1524
1525
Bram Moolenaar81695252004-12-29 20:58:21 +00001526 void
1527SBPool::create(GuiScrollbar * sb, int orient)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001528{
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001529 switch(orient)
1530 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001531 case SBAR_HORIZ:
1532 sb->w = new QScrollBar(QScrollBar::Horizontal, vmw);
1533 break;
1534 case SBAR_VERT:
1535 sb->w = new QScrollBar(QScrollBar::Vertical, vmw);
1536 break;
1537 default:
1538 sb->w = 0;
1539 return;
1540 }
1541
1542 connect(sb->w, SIGNAL(valueChanged(int)), &mapper, SLOT(map()));
1543 mapper.setMapping(sb->w, (int)sb);
1544}//}}}
1545
1546
Bram Moolenaar81695252004-12-29 20:58:21 +00001547 void
1548SBPool::sbUsed(int who)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001549{
1550 GuiScrollbar *sb = (GuiScrollbar*)who;
Bram Moolenaar81695252004-12-29 20:58:21 +00001551 gui_drag_scrollbar(sb, sb->w->value(), FALSE);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001552}//}}}
1553
1554
Bram Moolenaar81695252004-12-29 20:58:21 +00001555 void
1556SBPool::destroy(GuiScrollbar *sb)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001557{
Bram Moolenaar81695252004-12-29 20:58:21 +00001558 if (!sb->w)
1559 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001560
1561 delete sb->w;
1562 sb->w = 0;
1563}//}}}
1564
1565#ifdef FEAT_CLIENTSERVER
Bram Moolenaar81695252004-12-29 20:58:21 +00001566 static int
1567kvim_x11_event_filter(XEvent* e)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001568{
1569 if (e->xproperty.type == PropertyNotify
1570 && e->xproperty.atom == commProperty
1571 && e->xproperty.window == commWindow
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001572 && e->xproperty.state == PropertyNewValue)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001573 serverEventProc(qt_xdisplay(), e);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001574
Bram Moolenaar81695252004-12-29 20:58:21 +00001575 if (oldFilter)
1576 return oldFilter( e );
Bram Moolenaar843ee412004-06-30 16:16:41 +00001577 return FALSE;
1578}//}}}
1579#endif
1580
1581//add some QT 3 fonts usefull functions
1582#if QT_VERSION<300
Bram Moolenaar81695252004-12-29 20:58:21 +00001583 QString
1584KVimUtils::toString(QFont *f)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001585{
1586 QStringList l;
1587 l.append(f->family());
1588 l.append(QString::number(f->pointSize()));
1589 l.append(QString::number(f->pixelSize()));
1590 l.append(QString::number((int)f->styleHint()));
1591 l.append(QString::number(f->weight()));
1592 l.append(QString::number((int)f->italic()));
1593 l.append(QString::number((int)f->underline()));
1594 l.append(QString::number((int)f->strikeOut()));
1595 l.append(QString::number((int)f->fixedPitch()));
1596 l.append(QString::number((int)f->rawMode()));
1597 return l.join(",");
1598}
1599
Bram Moolenaar81695252004-12-29 20:58:21 +00001600 bool
1601KVimUtils::fromString(QFont *f, QString descrip)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001602{
1603 QStringList l(QStringList::split(',', descrip));
1604
1605 int count = l.count();
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001606 if (count != 10 && count != 9)
Bram Moolenaar81695252004-12-29 20:58:21 +00001607 return FALSE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001608
1609 f->setFamily(l[0]);
1610 f->setPointSize(l[1].toInt());
Bram Moolenaar81695252004-12-29 20:58:21 +00001611 if (count == 9)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +00001612 {
1613 f->setStyleHint((QFont::StyleHint) l[2].toInt());
1614 f->setWeight(l[3].toInt());
1615 f->setItalic(l[4].toInt());
1616 f->setUnderline(l[5].toInt());
1617 f->setStrikeOut(l[6].toInt());
1618 f->setFixedPitch(l[7].toInt());
1619 f->setRawMode(l[8].toInt());
1620 }
1621 else
1622 {
1623 f->setPixelSize(l[2].toInt());
1624 f->setStyleHint((QFont::StyleHint) l[3].toInt());
1625 f->setWeight(l[4].toInt());
1626 f->setItalic(l[5].toInt());
1627 f->setUnderline(l[6].toInt());
1628 f->setStrikeOut(l[7].toInt());
1629 f->setFixedPitch(l[8].toInt());
1630 f->setRawMode(l[9].toInt());
Bram Moolenaar843ee412004-06-30 16:16:41 +00001631 }
1632 return TRUE;
1633}
1634#endif
1635
Bram Moolenaar81695252004-12-29 20:58:21 +00001636 QString
1637KVimUtils::convertEncodingName(QString name)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001638{
Bram Moolenaar81695252004-12-29 20:58:21 +00001639 if (name.startsWith("ucs") || name.startsWith("utf-16"))
1640 return QString("utf16");
1641 if (name == "cp950")
1642 return QString("Big5");
Bram Moolenaar843ee412004-06-30 16:16:41 +00001643 return QString();
1644}