11
|
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 <qscrollbar.h>
|
|
22 #include <qcstring.h>
|
|
23 #include <qdatetime.h>
|
|
24 #include <qcursor.h>
|
|
25 #include <qfontmetrics.h>
|
|
26 #include <qpaintdevice.h>
|
|
27 #include <qclipboard.h>
|
|
28 #include <qregexp.h>
|
|
29 #include <kaboutkde.h>
|
|
30 #include <kiconloader.h>
|
|
31 #include <kfontdialog.h>
|
|
32 #include <kmessagebox.h>
|
|
33 #include <dcopclient.h>
|
|
34 #include <kwin.h>
|
|
35 #include <kmenubar.h>
|
|
36 #include <kconfig.h>
|
|
37 #if (QT_VERSION>=300)
|
|
38 #include <qnamespace.h>
|
|
39 #include <ktip.h>
|
|
40 #endif
|
|
41 #include <qpopupmenu.h>
|
|
42 #include <qpainter.h>
|
|
43 #include <qtextcodec.h>
|
|
44 #include <qfontmetrics.h>
|
|
45 #include <qfont.h>
|
|
46
|
|
47
|
20
|
48 #include "gui_kde_wid.h"
|
11
|
49
|
|
50
|
|
51 extern "C" {
|
|
52 #include "vim.h"
|
|
53 #include "version.h"
|
|
54 }
|
|
55
|
|
56 #include <stdio.h>
|
|
57
|
|
58 /*
|
|
59 * global variable for KDE, we can't put them in Gui, cause there are C++ types
|
|
60 */
|
42
|
61 VimMainWindow *vmw = 0;
|
|
62 SBPool *sbpool = 0;
|
|
63 QString *argServerName = 0;
|
11
|
64
|
|
65 #ifdef FEAT_MOUSESHAPE
|
|
66 /* The last set mouse pointer shape is remembered, to be used when it goes
|
|
67 * from hidden to not hidden. */
|
|
68 static int last_shape = 0;
|
|
69 #endif
|
|
70
|
|
71 /*
|
|
72 * Arguments handled by KDE internally.
|
|
73 */
|
|
74
|
|
75 #if QT_VERSION>=300
|
42
|
76 static int tip = 0; // 1 no dialog, 0 use it if enabled in conf,
|
|
77 // 2 force the tip
|
11
|
78 #endif
|
42
|
79 static int reverse = 0; // 0 bg : white, 1 : bg : black
|
|
80 QString *startfont;
|
|
81 QSize *startsize;
|
|
82 static int gui_argc = 0;
|
|
83 static char **gui_argv = NULL;
|
11
|
84
|
|
85 /*
|
|
86 * Parse the GUI related command-line arguments. Any arguments used are
|
|
87 * deleted from argv, and *argc is decremented accordingly. This is called
|
|
88 * when vim is started, whether or not the GUI has been started.
|
|
89 */
|
42
|
90 void
|
11
|
91 gui_mch_prepare(int *argc, char **argv)// {{{
|
|
92 {
|
42
|
93 // copy args for KDE/Qt
|
|
94 gui_argc = 0;
|
11
|
95
|
42
|
96 // this one is not really good as all options are not for KDE/Qt ...
|
|
97 gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE);
|
|
98 if (gui_argv == NULL)
|
|
99 return;
|
|
100 gui_argv[gui_argc++] = argv[0];
|
|
101
|
|
102 int found = 0;
|
|
103 for (int i = 1; i < *argc ; i++)
|
|
104 {
|
|
105 if (found != 2)
|
|
106 found = 0;
|
|
107 else
|
11
|
108 {
|
42
|
109 found = 0;
|
|
110 // remove from the list of argv
|
|
111 if (--*argc > i)
|
|
112 {
|
|
113 mch_memmove(&argv[i], &argv[i + 1],
|
|
114 (*argc - i) * sizeof(char *));
|
|
115 }
|
|
116 i--;
|
|
117 continue;
|
|
118 }
|
23
|
119
|
42
|
120 if (strcmp(argv[i], "--servername") == 0)
|
|
121 {
|
|
122 argServerName = new QString(argv[i+1]); // to get the serverName now
|
|
123 }
|
11
|
124 #if QT_VERSION>+300
|
42
|
125 if (strcmp(argv[i], "-tip") == 0 )
|
|
126 {
|
|
127 tip = 2;
|
|
128 found = 1;
|
|
129 }
|
|
130 if (strcmp(argv[i], "-notip") == 0 )
|
|
131 {
|
|
132 tip = 1;
|
|
133 found = 1;
|
|
134 }
|
11
|
135 #endif
|
42
|
136 if (strcmp(argv[i], "-black") == 0 )
|
|
137 {
|
|
138 reverse = 1;
|
|
139 found = 1;
|
|
140 }
|
|
141 /* replaced by -black */
|
|
142 /* if (strcmp(argv[i], "-rv") == 0 )
|
|
143 * {
|
|
144 reverse = 1;
|
|
145 found = 1;
|
|
146 }*/
|
|
147 if (strcmp(argv[i], "-font") == 0 || strcmp(argv[i], "-fn") == 0)
|
|
148 {
|
|
149 startfont = new QString(argv[i+1]);
|
|
150 found = 2;
|
|
151 }
|
|
152 if (strcmp(argv[i], "-geometry") == 0 || strcmp(argv[i], "-geom") == 0)
|
|
153 {
|
|
154 found = 2;
|
|
155 QString text(argv[i + 1]);
|
|
156 QStringList list = QStringList::split(QChar('x'), text);
|
|
157 startsize = new QSize(list[0].toInt(), list[1].toInt());
|
|
158 }
|
|
159 if (strcmp(argv[i], "-display") == 0) //XXX: this does not work,
|
|
160 // too many -display options in main.c !
|
|
161 // ask Bram ...
|
|
162 {
|
|
163 gui_argv[gui_argc++] = strdup("--display");
|
|
164 gui_argv[gui_argc++] = argv[i+1];
|
|
165 found = 0;
|
|
166 }
|
|
167 if (strcmp(argv[i], "--display") == 0 )
|
|
168 {
|
|
169 gui_argv[gui_argc++] = argv[i];
|
|
170 gui_argv[gui_argc++] = argv[i+1];
|
|
171 found = 2;
|
|
172 }
|
|
173 //KDE/Qt options with no args
|
|
174 if (strcmp(argv[i], "--help-kde") == 0
|
|
175 || strcmp(argv[i], "--help-qt") == 0
|
|
176 || strcmp(argv[i], "--help-all") == 0
|
|
177 || strcmp(argv[i], "--reverse") == 0
|
|
178 || strcmp(argv[i], "--author") == 0
|
|
179 // || strcmp(argv[i], "--version") == 0 //disabled we need these for kcmvim
|
|
180 // || strcmp(argv[i], "-v") == 0
|
|
181 || strcmp(argv[i], "--license") == 0
|
|
182 || strcmp(argv[i], "--cmap") == 0
|
|
183 || strcmp(argv[i], "--nograb") == 0
|
|
184 || strcmp(argv[i], "--dograb") == 0
|
|
185 || strcmp(argv[i], "--sync") == 0
|
|
186 || strcmp(argv[i], "--noxim") == 0
|
|
187 || strcmp(argv[i], "--nocrashhandler") == 0
|
|
188 || strcmp(argv[i], "--waitforwm") == 0
|
|
189 )
|
|
190 {
|
|
191 gui_argv[gui_argc++] = argv[i];
|
|
192 found = 1;
|
|
193 }
|
|
194 //this outputs KDE and Vim versions :)
|
|
195 if (strcmp(argv[i], "--version") == 0
|
|
196 || strcmp(argv[i], "-v") == 0)
|
|
197 {
|
|
198 gui_argv[gui_argc++] = argv[i];
|
|
199 }
|
23
|
200
|
11
|
201
|
42
|
202 // KDE/Qt options with one arg
|
|
203 if (strcmp(argv[i], "--session") == 0
|
|
204 || strcmp(argv[i], "--ncols") == 0
|
|
205 || strcmp(argv[i], "--bg") == 0
|
|
206 || strcmp(argv[i], "--background") == 0
|
|
207 || strcmp(argv[i], "--fg") == 0
|
|
208 || strcmp(argv[i], "--foreground") == 0
|
|
209 || strcmp(argv[i], "--btn") == 0
|
|
210 || strcmp(argv[i], "--name") == 0
|
|
211 || strcmp(argv[i], "--title") == 0
|
|
212 || strcmp(argv[i], "--inputstyle") == 0
|
|
213 || strcmp(argv[i], "--im") == 0
|
|
214 || strcmp(argv[i], "--caption") == 0
|
|
215 || strcmp(argv[i], "--icon") == 0
|
|
216 || strcmp(argv[i], "--miniicon") == 0
|
|
217 || strcmp(argv[i], "--config") == 0
|
|
218 || strcmp(argv[i], "--dcopserver") == 0
|
|
219 || strcmp(argv[i], "--style") == 0
|
|
220 || strcmp(argv[i], "--geometry") == 0
|
|
221 || strcmp(argv[i], "--smkey") == 0
|
|
222 || strcmp(argv[i], "-smkey") == 0
|
|
223 || strcmp(argv[i], "-session") == 0
|
|
224 )
|
|
225 {
|
|
226 gui_argv[gui_argc++] = argv[i];
|
|
227 gui_argv[gui_argc++] = argv[i + 1];
|
|
228 found = 2;
|
|
229 }
|
23
|
230
|
42
|
231 // remove from the list of argv
|
|
232 if (found >= 1 && --*argc > i)
|
|
233 {
|
|
234 mch_memmove(&argv[i], &argv[i + 1], (*argc - i) * sizeof(char *));
|
|
235 i--;
|
11
|
236 }
|
42
|
237 }
|
|
238 KCmdLineArgs::init(gui_argc, gui_argv, "kvim",
|
|
239 I18N_NOOP("Vim inside KDE"), VIM_VERSION_SHORT);
|
11
|
240 }// }}}
|
|
241
|
|
242 /****************************************************************************
|
|
243 * Focus handlers:
|
|
244 */
|
|
245
|
|
246 /*
|
|
247 * Initialises time intervals for the cursor blinking
|
|
248 */
|
42
|
249 void
|
11
|
250 gui_mch_set_blinking(long waittime, long on, long off)//{{{
|
|
251 {
|
42
|
252 gui.w->set_blink_time(waittime, on, off);
|
11
|
253 }//}}}
|
|
254
|
|
255 /*
|
|
256 * Stop the cursor blinking. Show the cursor if it wasn't shown.
|
|
257 */
|
42
|
258 void
|
11
|
259 gui_mch_stop_blink()//{{{
|
|
260 {
|
42
|
261 gui.w->stop_cursor_blinking();
|
11
|
262 }//}}}
|
|
263
|
|
264 /*
|
|
265 * Start the cursor blinking. If it was already blinking, this restarts the
|
|
266 * waiting time and shows the cursor.
|
|
267 */
|
42
|
268 void
|
11
|
269 gui_mch_start_blink()//{{{
|
|
270 {
|
42
|
271 gui.w->start_cursor_blinking();
|
11
|
272 }//}}}
|
|
273
|
16
|
274 #ifdef FEAT_MZSCHEME
|
42
|
275 void
|
16
|
276 mzscheme_kde_start_timer()//{{{
|
|
277 {
|
42
|
278 gui.w->enable_mzscheme_threads();
|
16
|
279 }//}}}
|
42
|
280 void
|
16
|
281 mzscheme_kde_stop_timer()//{{{
|
|
282 {
|
42
|
283 gui.w->disable_mzscheme_threads();
|
16
|
284 }//}}}
|
|
285 #endif
|
|
286
|
11
|
287 /*
|
|
288 * Check if the GUI can be started. Called before gvimrc is sourced.
|
|
289 * Return OK or FAIL.
|
|
290 */
|
42
|
291 int
|
11
|
292 gui_mch_init_check(void)//{{{
|
|
293 {
|
42
|
294 gui.dpy = qt_xdisplay();
|
|
295 return OK;
|
11
|
296 }//}}}
|
|
297
|
|
298 /*
|
|
299 * Initialise the X GUI. Create all the windows, set up all the call-backs etc.
|
|
300 * Returns OK for success, FAIL when the GUI can't be started.
|
|
301 */
|
42
|
302 int
|
11
|
303 gui_mch_init()//{{{
|
|
304 {
|
42
|
305 (void) new KApplication();
|
|
306 KApplication::kApplication()->dcopClient()->registerAs(
|
|
307 KApplication::kApplication()->name(), false);
|
|
308 // dbf("%s %s", KGlobal::locale()->language().latin1(), KLocale::defaultLanguage().latin1());
|
11
|
309
|
42
|
310 vmw = new VimMainWindow("KVim", 0);
|
|
311 vmw->setFrameBorderWidth(0);
|
|
312 kapp->setMainWidget(vmw);
|
|
313 kapp->setTopWidget(vmw);
|
11
|
314
|
42
|
315 sbpool = new SBPool;
|
11
|
316
|
|
317 #if QT_VERSION>=300
|
42
|
318 vmw->connect(kapp->clipboard(), SIGNAL(selectionChanged()),
|
|
319 vmw, SLOT(clipboard_selection_update()));
|
11
|
320 #endif
|
42
|
321 vmw->connect(kapp->clipboard(), SIGNAL(dataChanged()),
|
|
322 vmw, SLOT(clipboard_data_update()));
|
|
323 clip_lose_selection(&clip_plus);
|
|
324 clip_lose_selection(&clip_star);
|
11
|
325
|
42
|
326 gui.in_focus = FALSE; // will be updated
|
|
327
|
|
328 if (reverse)
|
|
329 {
|
|
330 gui.def_norm_pixel = gui_get_color((char_u *)"White");
|
|
331 gui.def_back_pixel = gui_get_color((char_u *)"Black");
|
11
|
332 #if QT_VERSION>=300
|
42
|
333 gui.w->setEraseColor(QColor(Qt::black));
|
11
|
334 #else
|
42
|
335 gui.w->setBackgroundColor(QColor(Qt::black));
|
11
|
336 #endif
|
42
|
337 }
|
|
338 else
|
|
339 {
|
|
340 gui.def_norm_pixel = gui_get_color((char_u *)"Black");
|
|
341 gui.def_back_pixel = gui_get_color((char_u *)"White");
|
11
|
342 #if QT_VERSION>=300
|
42
|
343 gui.w->setEraseColor(QColor(Qt::white));
|
11
|
344 #else
|
42
|
345 gui.w->setBackgroundColor(QColor(Qt::white));
|
11
|
346 #endif
|
42
|
347 }
|
11
|
348
|
42
|
349 gui.norm_pixel = gui.def_norm_pixel;
|
|
350 gui.back_pixel = gui.def_back_pixel;
|
11
|
351
|
42
|
352 gui.border_width = 1;
|
|
353 gui.border_offset = 1;//gui.border_width;
|
|
354 gui.scrollbar_width = SB_DEFAULT_WIDTH;
|
|
355 gui.scrollbar_height = SB_DEFAULT_WIDTH;
|
11
|
356
|
42
|
357 //gui.menu_height = vmw->menuBar()->height()+1;
|
|
358 //gui.toolbar_height = vmw->toolBar()->height();
|
11
|
359
|
42
|
360 return OK;
|
11
|
361 }//}}}
|
|
362
|
|
363
|
|
364 /*
|
|
365 * Called when the foreground or background color has been changed.
|
|
366 */
|
42
|
367 void
|
11
|
368 gui_mch_new_colors()//{{{
|
|
369 {
|
42
|
370 QColor rgb;
|
|
371 rgb.setRgb(gui.back_pixel);
|
11
|
372 #if QT_VERSION>=300
|
42
|
373 gui.w->setEraseColor(rgb);
|
11
|
374 #else
|
42
|
375 gui.w->setBackgroundColor(rgb);
|
11
|
376 #endif
|
|
377 }//}}}
|
|
378
|
|
379 /*
|
|
380 * Open the GUI window which was created by a call to gui_mch_init().
|
|
381 */
|
42
|
382 int
|
11
|
383 gui_mch_open()//{{{
|
|
384 {
|
42
|
385 gui.dpy = qt_xdisplay();
|
|
386 set_normal_colors();
|
11
|
387
|
42
|
388 /* Check that none of the colors are the same as the background color */
|
|
389 gui_check_colors();
|
11
|
390
|
42
|
391 /* Get the colors for the highlight groups (gui_check_colors() might have
|
|
392 * changed them).
|
|
393 */
|
|
394 highlight_gui_started(); /* re-init colors and fonts */
|
11
|
395 #ifdef FEAT_MENU
|
42
|
396 vmw->w->menu = new QPopupMenu(vmw);
|
11
|
397
|
|
398 #if QT_VERSION>=300
|
42
|
399 vmw->w->menu->insertItem(SmallIcon("ktip"), i18n("&Tip of the day..."),
|
|
400 vmw, SLOT(showTipOfTheDay()));
|
|
401 vmw->w->menu->insertSeparator();
|
11
|
402 #endif
|
42
|
403 if (vmw->have_tearoff)
|
|
404 vmw->w->menu->insertTearOffHandle(0, 0);
|
|
405 vmw->w->menu->insertItem(i18n("&Report Bug ..."),
|
|
406 vmw, SLOT(showBugReport()));
|
|
407 vmw->w->menu->insertSeparator();
|
|
408 vmw->w->menu->insertItem(SmallIcon("kvim"), i18n("&About KVim..."),
|
|
409 vmw, SLOT(showAboutApplication()));
|
|
410 vmw->w->menu->insertItem(SmallIcon("about_kde"), i18n("About &KDE..."),
|
|
411 vmw, SLOT(showAboutKDE()));
|
|
412 vmw->menuBar()->insertItem("&KVim", vmw->w->menu);
|
11
|
413 #endif
|
42
|
414 if (startfont != NULL)
|
|
415 gui_mch_init_font((char_u*)startfont->latin1(), FALSE);
|
23
|
416
|
42
|
417 if (startsize != NULL)
|
|
418 vmw->resize(startsize->width(), startsize->height());
|
11
|
419
|
42
|
420 gui_mch_update_codec();
|
11
|
421
|
42
|
422 if (kapp->isRestored())
|
|
423 if (KMainWindow::canBeRestored(1))
|
|
424 vmw->restore(1);
|
23
|
425
|
42
|
426 vmw->show();
|
11
|
427 #if QT_VERSION>=300
|
42
|
428 if (tip == 2)
|
|
429 KTipDialog::showTip(vmw, QString::null, true);
|
|
430 else if (tip == 0)
|
|
431 KTipDialog::showTip(vmw);
|
11
|
432 #endif
|
|
433
|
42
|
434 return OK;
|
11
|
435 }//}}}
|
|
436
|
42
|
437 void
|
11
|
438 gui_mch_exit(int rc)//{{{
|
|
439 {
|
42
|
440 kapp->quit();
|
11
|
441 }//}}}
|
|
442
|
|
443 /*
|
|
444 * Get the position of the top left corner of the window.
|
|
445 */
|
42
|
446 int
|
11
|
447 gui_mch_get_winpos(int *x, int *y)//{{{
|
|
448 {
|
42
|
449 *x = vmw->x();
|
|
450 *y = vmw->y();
|
|
451 return OK;
|
11
|
452 }//}}}
|
|
453
|
|
454 /*
|
|
455 * Set the position of the top left corner of the window to the given
|
|
456 * coordinates.
|
|
457 */
|
42
|
458 void
|
11
|
459 gui_mch_set_winpos(int x, int y)//{{{
|
|
460 {
|
42
|
461 vmw->move(x, y);
|
11
|
462 }//}}}
|
|
463
|
|
464 /*
|
|
465 * Set the windows size.
|
|
466 * ->resize VimWidget
|
|
467 * ->resize vmw (block any events generated from here)
|
|
468 */
|
42
|
469 void
|
11
|
470 gui_mch_set_shellsize(int width, int height,//{{{
|
|
471 int min_width, int min_height,
|
|
472 int base_width, int base_height)
|
|
473 {
|
42
|
474 //resize VimWidget
|
|
475 vmw->w->resize(width, height);
|
11
|
476
|
42
|
477 //resize vmw
|
|
478 int vheight, vwidth;
|
|
479 vheight = height;
|
|
480 vwidth = width;
|
11
|
481
|
42
|
482 if (gui.which_scrollbars[SBAR_LEFT])
|
|
483 vwidth += gui.scrollbar_width;
|
|
484 if (gui.which_scrollbars[SBAR_RIGHT])
|
|
485 vwidth += gui.scrollbar_width;
|
|
486 if (gui.which_scrollbars[SBAR_BOTTOM])
|
|
487 vheight += gui.scrollbar_height;
|
11
|
488
|
42
|
489 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
|
11
|
490 #if QT_VERSION>=300
|
42
|
491 && !vmw->menuBar()->isTopLevelMenu()
|
11
|
492 #endif
|
42
|
493 )
|
|
494 vheight += vmw->menuBar()->height();
|
11
|
495 #ifdef FEAT_TOOLBAR
|
42
|
496 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
497 && (vmw->toolBar()->barPos() == KToolBar::Top
|
|
498 || vmw->toolBar()->barPos() == KToolBar::Bottom))
|
|
499 vheight += vmw->toolBar()->height();
|
11
|
500
|
42
|
501 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
502 && (vmw->toolBar()->barPos() == KToolBar::Left
|
|
503 || vmw->toolBar()->barPos() == KToolBar::Right))
|
|
504 vwidth += vmw->toolBar()->width();
|
11
|
505 #endif
|
42
|
506 vmw->lock();
|
|
507 vmw->resize(vwidth, vheight);
|
|
508 gui_mch_update();
|
|
509 //size should be nearly perfect, update baseSize and sizeIncrement
|
|
510 vmw->setBaseSize(base_width, vmw->menuBar()->height() + 1
|
|
511 + vmw->toolBar()->height() + gui.char_height * 2);
|
|
512 vmw->setSizeIncrement((( int )(gui.char_width / 2) * 2), gui.char_height);
|
|
513 vmw->unlock();
|
11
|
514 }//}}}
|
|
515
|
|
516
|
|
517 /*
|
|
518 * The screen size is used to make sure the initial window doesn't get bigger
|
|
519 * then the screen. This subtracts some room for menubar, toolbar and window
|
|
520 * decorations.
|
|
521 */
|
42
|
522 void
|
11
|
523 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)//{{{
|
|
524 {
|
42
|
525 *screen_w = kapp->desktop()->width();
|
|
526 *screen_h = kapp->desktop()->height();
|
11
|
527 }//}}}
|
|
528
|
|
529 #if defined(FEAT_MENU) || defined(PROTO)
|
42
|
530 void
|
11
|
531 gui_mch_enable_menu(int showit)//{{{
|
|
532 {
|
42
|
533 if (showit)
|
|
534 vmw->menuBar()->show();
|
|
535 else
|
|
536 vmw->menuBar()->hide();
|
|
537 vmw->resize(vmw->width(), vmw->height());
|
11
|
538 }//}}}
|
|
539 #endif
|
|
540
|
|
541
|
|
542 #if defined(FEAT_TOOLBAR) || defined(PROTO)
|
42
|
543 void
|
11
|
544 gui_mch_show_toolbar(int showit)//{{{
|
|
545 {
|
42
|
546 if (showit)
|
|
547 vmw->toolBar()->show();
|
|
548 else
|
|
549 vmw->toolBar()->hide();
|
|
550 vmw->resize(vmw->width(), vmw->height());
|
11
|
551 }//}}}
|
|
552 #endif
|
|
553
|
|
554 /*
|
|
555 * Put up a font dialog and return the selected font name in allocated memory.
|
|
556 * "oldval" is the previous value.
|
|
557 * Return NULL when cancelled.
|
|
558 */
|
|
559
|
42
|
560 char_u *
|
|
561 gui_mch_font_dialog(char_u *oldval)//{{{
|
11
|
562 {
|
42
|
563 QFont myFont(vmw->w->font());
|
|
564 if (gui.fontname)
|
|
565 gui.fontname = NULL;
|
|
566
|
|
567 int result = KFontDialog::getFont(myFont, true);
|
|
568 if (result != KFontDialog::Accepted)
|
|
569 return NULL;
|
|
570
|
|
571 // myFont.setFixedPitch(true);
|
11
|
572 #if QT_VERSION>=300
|
42
|
573 QString n = myFont.toString();
|
11
|
574 #else
|
42
|
575 QString n = KVimUtils::toString(&myFont);
|
11
|
576 #endif
|
42
|
577 n.replace(QRegExp(","), "/");
|
|
578 gui.fontname = (char_u *)strdup((const char *)n);
|
|
579 n.replace(QRegExp(" "), "\\ ");
|
|
580 n = QString("To set this font as your default font for KVim, edit your ~/.gvimrc file and add the following lines : \nif has(\"gui_kde\")\nset guifont=")+n+QString("\nendif");// \n OR \n use the control center of KDE and choose the correct fixed font");
|
11
|
581
|
42
|
582 //display a message box which explains how to save your font settings
|
|
583 KMessageBox::information(vmw, n, "Font Selection", "kvimselectfont");
|
11
|
584
|
42
|
585 return vim_strsave(gui.fontname);
|
11
|
586 }//}}}
|
|
587
|
|
588 /*
|
|
589 * Initialise vim to use the font with the given name.
|
|
590 * Return FAIL if the font could not be loaded, OK otherwise.
|
|
591 */
|
42
|
592 int
|
11
|
593 gui_mch_init_font(char_u * font_name, int fontset)//{{{
|
|
594 {
|
42
|
595 QString fontname;
|
|
596 GuiFont font = NULL;
|
23
|
597
|
42
|
598 if (font_name == NULL)
|
|
599 {
|
11
|
600 #if 0
|
|
601 #if QT_VERSION>=300
|
42
|
602 KConfig *base = KGlobal::config();
|
11
|
603 #else
|
42
|
604 KConfigBase *base = KGlobal::config();
|
11
|
605 #endif
|
42
|
606 base->setGroup("General");
|
|
607 if (!base->hasKey("fixed"))
|
|
608 {
|
|
609 KMessageBox::error(KApplication::kApplication()->mainWidget(),"Cannot load default fixed font\n\nConfigure fonts in KDE Control Center.\n(Just click 'Choose...', 'OK' and then 'Apply')");
|
|
610 return FAIL;
|
|
611 }
|
11
|
612 #if QT_VERSION>=300
|
42
|
613 QString f = base->readEntry("fixed");
|
11
|
614 #else
|
42
|
615 QFont ft = base->readFontEntry("fixed", NULL);
|
|
616 QString f = KVimUtils::toString(&ft);
|
11
|
617 #endif
|
42
|
618 font_name = (char_u*)strdup(f.latin1()); //latin1 ?
|
11
|
619 #else
|
42
|
620 font_name = (char_u*)strdup("misc-fixed/10/-1/5/50/0/0/0/1/0");
|
11
|
621 #endif
|
42
|
622 }
|
|
623 fontname = (const char *)font_name;
|
|
624 /* fontname.replace(QRegExp("/"), ",");
|
11
|
625 font = new QFont();
|
|
626 font->fromString( fontname );
|
42
|
627 */
|
37
|
628 #ifdef FEAT_XFONTSET
|
42
|
629 if (fontset)
|
|
630 font = gui_mch_get_fontset(font_name, TRUE, TRUE);
|
|
631 if (font == NULL)
|
37
|
632 #endif
|
42
|
633 font = gui_mch_get_font(font_name, FALSE);
|
37
|
634
|
42
|
635 if (font == NULL)
|
|
636 return FAIL;
|
|
637 if (fontname.contains('*') && fontname.contains('-'))
|
|
638 return FAIL;
|
37
|
639
|
42
|
640 gui_mch_free_font(gui.norm_font);
|
11
|
641 #ifdef FEAT_XFONTSET
|
42
|
642 gui_mch_free_fontset(gui.fontset);
|
|
643 gui.fontset = NOFONTSET;
|
|
644 if (fontset)
|
|
645 {
|
|
646 gui.fontset = font;
|
|
647 gui.norm_font = NOFONT;
|
|
648 }
|
|
649 else
|
11
|
650 #endif
|
42
|
651 gui.norm_font = font;
|
11
|
652
|
42
|
653 /* Compute the width of the character cell. Some fonts include
|
|
654 * double-width characters. Use the width of ASCII characters to find
|
|
655 * out if this is so. */
|
|
656 QFontMetrics f(*font);
|
|
657 int width_max = 0;
|
|
658 for (char c = 32; c < 127; c++)
|
|
659 if (width_max < f.width((QChar)c))
|
|
660 width_max = f.width((QChar)c);
|
|
661 if (width_max <= f.maxWidth() / 2)
|
|
662 width_max = f.maxWidth() / 2;
|
|
663 gui.char_width = width_max;
|
|
664 gui.char_height = f.height() + p_linespace;
|
|
665 gui.char_ascent = f.ascent() + p_linespace;
|
23
|
666
|
42
|
667 //check values, just to make sure and avoid a crash
|
|
668 if (gui.char_width <= 0)
|
|
669 gui.char_width = 8;
|
|
670 if (gui.char_height <= 0)
|
|
671 gui.char_height = 1;
|
11
|
672
|
42
|
673 hl_set_font_name(font_name);
|
11
|
674
|
42
|
675 vmw->w->setFont(*font);
|
|
676
|
|
677 return OK;
|
11
|
678 }//}}}
|
|
679
|
42
|
680 GuiFont
|
11
|
681 gui_mch_get_font(char_u * name, int report_error)//{{{
|
|
682 {
|
42
|
683 QString fontname((const char *)name);
|
|
684 if (!gui.in_use || name == NULL)
|
|
685 return NOFONT;
|
|
686 if (fontname.contains('*') && fontname.contains('-'))
|
|
687 return NOFONT; // XFLD names not allowed anymore
|
|
688 QFont *myFont = new QFont();
|
|
689 fontname.replace(QRegExp("/"), ",");
|
|
690 // myFont->setRawMode(TRUE);
|
11
|
691
|
|
692 #if QT_VERSION>=300
|
42
|
693 myFont->fromString(fontname);
|
11
|
694 #else
|
42
|
695 KVimUtils::fromString(myFont, fontname);
|
11
|
696 #endif
|
42
|
697 myFont->setFixedPitch(true);
|
|
698 if (!myFont->fixedPitch())
|
|
699 dbf("Non fixed-width font");
|
|
700 return (GuiFont) myFont;
|
11
|
701 }//}}}
|
|
702
|
44
|
703 #if defined(FEAT_EVAL) || defined(PROTO)
|
11
|
704 /*
|
37
|
705 * Return the name of font "font" in allocated memory.
|
|
706 * Don't know how to get the actual name, thus use the provided name.
|
|
707 */
|
|
708 char_u *
|
42
|
709 gui_mch_get_fontname(GuiFont font, char_u *name)//{{{
|
37
|
710 {
|
|
711 if (name == NULL)
|
|
712 return NULL;
|
|
713 return vim_strsave(name);
|
42
|
714 }//}}}
|
44
|
715 #endif
|
37
|
716
|
|
717 /*
|
11
|
718 * Set the current text font.
|
|
719 * Since we create all GC on demand, we use just gui.current_font to
|
|
720 * indicate the desired current font.
|
|
721 */
|
42
|
722 void
|
11
|
723 gui_mch_set_font(GuiFont font)//{{{
|
|
724 {
|
42
|
725 gui.current_font = font;
|
|
726 gui.w->painter->setFont(*(gui.current_font));
|
11
|
727 }//}}}
|
|
728
|
|
729 /*
|
|
730 * If a font is not going to be used, free its structure.
|
|
731 */
|
42
|
732 void
|
11
|
733 gui_mch_free_font(GuiFont font)//{{{
|
|
734 {
|
|
735 if (font)
|
|
736 delete font; // this is a QFont , we can delete it :)
|
|
737 }//}}}
|
|
738
|
42
|
739 GuiFontset
|
|
740 gui_mch_get_fontset(char_u *name, int report_error, int fixed_width)
|
11
|
741 {
|
42
|
742 return (GuiFontset)gui_mch_get_font(name, report_error);
|
11
|
743 }
|
|
744
|
42
|
745 void
|
|
746 gui_mch_set_fontset(GuiFontset fontset)
|
11
|
747 {
|
|
748 gui_mch_set_font((GuiFont)fontset);
|
|
749 }
|
|
750
|
42
|
751 void
|
|
752 gui_mch_free_fontset(GuiFontset fontset)
|
11
|
753 {
|
|
754 if (fontset)
|
|
755 delete fontset;
|
|
756 }
|
|
757
|
42
|
758 void
|
|
759 gui_mch_settitle(char_u *title, char_u *icon)//{{{
|
11
|
760 {
|
42
|
761 if (!gui.in_use) /* can't do this when GUI not running */
|
|
762 return;
|
|
763 vmw->setPlainCaption((const char *)title);
|
|
764 QPixmap p((const char *)icon);
|
|
765 vmw->setIcon(p); //FIXME
|
11
|
766 }//}}}
|
|
767
|
|
768 /*
|
|
769 * Return the Pixel value (color) for the given color name. This routine was
|
|
770 * pretty much taken from example code in the Silicon Graphics OSF/Motif
|
|
771 * Programmer's Guide.
|
|
772 * Return -1 for error.
|
|
773 */
|
42
|
774 guicolor_T
|
11
|
775 gui_mch_get_color(char_u * name)//{{{
|
|
776 {
|
42
|
777 int i;
|
|
778 static char *(vimnames[][2]) =
|
|
779 {
|
|
780 /* A number of colors that some X11 systems don't have */
|
|
781 {"LightRed", "#FFA0A0"},
|
|
782 {"LightGreen", "#80FF80"},
|
|
783 {"LightMagenta", "#FFA0FF"},
|
|
784 {"DarkCyan", "#008080"},
|
|
785 {"DarkBlue", "#0000C0"},
|
|
786 {"DarkRed", "#C00000"},
|
|
787 {"DarkMagenta", "#C000C0"},
|
|
788 {"DarkGrey", "#C0C0C0"},
|
|
789 {NULL, NULL}
|
|
790 };
|
11
|
791
|
42
|
792 if (!gui.in_use) /* can't do this when GUI not running */
|
|
793 return (guicolor_T)(-1);
|
|
794
|
|
795 QColor _color((const char *)name);
|
11
|
796
|
42
|
797 if (_color.isValid())
|
|
798 {
|
|
799 // return (_color.red() << 16) + ((_color.green() << 8))
|
|
800 // + (_color.blue());
|
|
801 return _color.rgb();
|
|
802 // return (guicolor_T) _color.pixel();
|
|
803 }
|
11
|
804
|
42
|
805 /* add a few builtin names */
|
|
806 for (i = 0;; ++i)
|
|
807 {
|
|
808 if (vimnames[i][0] == NULL)
|
|
809 return (guicolor_T)(-1);
|
|
810 if (STRICMP(name, vimnames[i][0]) == 0)
|
|
811 {
|
|
812 name = (char_u *) vimnames[i][1];
|
|
813 return gui_mch_get_color(name);
|
11
|
814 }
|
42
|
815 }
|
11
|
816
|
42
|
817 return (guicolor_T)(-1); // dead code, should not be reached..
|
11
|
818 }//}}}
|
|
819
|
|
820 /*
|
|
821 * Set the current text foreground color.
|
|
822 */
|
42
|
823 void
|
11
|
824 gui_mch_set_fg_color(guicolor_T color)//{{{
|
|
825 {
|
42
|
826 QColor rgb;
|
|
827 rgb.setRgb(color);
|
|
828 gui.w->painter->setPen(rgb);
|
11
|
829 }//}}}
|
|
830
|
|
831 /*
|
|
832 * Set the current text background color.
|
|
833 */
|
42
|
834 void
|
11
|
835 gui_mch_set_bg_color(guicolor_T color)//{{{
|
|
836 {
|
42
|
837 QColor rgb;
|
|
838 rgb.setRgb(color);
|
|
839 gui.w->painter->setBackgroundColor(rgb);
|
11
|
840 }//}}}
|
|
841
|
|
842 /*
|
|
843 * Use the blank mouse pointer or not.
|
|
844 *
|
|
845 * hide: TRUE = use blank ptr, FALSE = use parent ptr
|
|
846 */
|
42
|
847 void
|
11
|
848 gui_mch_mousehide(int hide)//{{{
|
|
849 {
|
42
|
850 if (hide == gui.pointer_hidden)
|
|
851 return;
|
|
852 //#ifdef FEAT_MOUSESHAPE
|
|
853 // if (!hide) mch_set_mouse_shape(last_shape);
|
|
854 //#else
|
11
|
855 # if (QT_VERSION<300)
|
42
|
856 gui.w->setCursor((hide)?BlankCursor:ArrowCursor);
|
11
|
857 # else
|
42
|
858 gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor);
|
11
|
859 # endif
|
42
|
860 //#endif
|
|
861 gui.pointer_hidden = hide;
|
11
|
862 }//}}}
|
|
863
|
42
|
864 void
|
11
|
865 gui_mch_update_codec()
|
|
866 {
|
|
867 #ifdef FEAT_MBYTE
|
42
|
868 if (!gui.in_use)
|
|
869 return;
|
|
870 vmw->codec = QTextCodec::codecForName((const char *)p_enc);
|
|
871 if (vmw->codec == NULL)
|
|
872 vmw->codec = QTextCodec::codecForName(
|
|
873 KVimUtils::convertEncodingName(QString((const char*)p_enc)));
|
|
874 if (vmw->codec == NULL)
|
|
875 vmw->codec = QTextCodec::codecForLocale();
|
11
|
876 #else
|
42
|
877 vmw->codec = QTextCodec::codecForLocale();
|
11
|
878 #endif
|
42
|
879 if (vmw->codec == NULL)
|
|
880 vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback
|
11
|
881 }
|
|
882
|
42
|
883 void
|
11
|
884 gui_mch_draw_string(int row, int col, char_u * s, int len, int flags)//{{{
|
|
885 {
|
42
|
886 QString text = vmw->codec->toUnicode((const char *)s, len);
|
|
887 gui.w->draw_string(TEXT_X(col), TEXT_Y(row), text, text.length(), flags);
|
11
|
888 }//}}}
|
|
889
|
|
890 #if defined(FEAT_TITLE) || defined(PROTO)
|
|
891 /*
|
|
892 * Return the text window-id and display. Only required for X-based GUI's
|
|
893 */
|
42
|
894 int
|
11
|
895 gui_get_x11_windis(Window * win, Display ** dis)//{{{
|
|
896 {
|
42
|
897 *win = /*vmw*/gui.w->winId();
|
|
898 *dis = qt_xdisplay();
|
|
899 return OK;
|
11
|
900 }//}}}
|
|
901 #endif
|
|
902
|
42
|
903 void
|
11
|
904 gui_mch_beep()//{{{
|
|
905 {
|
42
|
906 kapp->beep();
|
11
|
907 }//}}}
|
|
908
|
42
|
909 void
|
11
|
910 gui_mch_flash(int msec)//{{{
|
|
911 {
|
42
|
912 gui.w->flash();
|
11
|
913 }//}}}
|
|
914
|
|
915 /*
|
|
916 * Invert a rectangle from row r, column c, for nr rows and nc columns.
|
|
917 */
|
42
|
918 void
|
11
|
919 gui_mch_invert_rectangle(int r, int c, int nr, int nc)//{{{
|
|
920 {
|
42
|
921 bitBlt(gui.w,
|
|
922 FILL_X(c), FILL_Y(r),
|
|
923 gui.w,
|
|
924 FILL_X(c), FILL_Y(r),
|
|
925 (nc) * gui.char_width,
|
|
926 (nr) * gui.char_height,
|
|
927 Qt::NotROP, // raster Operation
|
|
928 true); // ignoreMask
|
11
|
929 }//}}}
|
|
930
|
|
931 /*
|
|
932 * Iconify the GUI window.
|
|
933 */
|
42
|
934 void
|
11
|
935 gui_mch_iconify()//{{{
|
|
936 {
|
42
|
937 vmw->showMinimized();
|
11
|
938 }//}}}
|
|
939
|
|
940 /*
|
|
941 * Draw a cursor without focus.
|
|
942 */
|
42
|
943 void
|
11
|
944 gui_mch_draw_hollow_cursor(guicolor_T color)//{{{
|
|
945 {
|
42
|
946 QPainter p(gui.w);
|
|
947 p.setPen(color);
|
11
|
948
|
42
|
949 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1,
|
|
950 gui.char_height - 1);
|
|
951 p.end();
|
11
|
952 }//}}}
|
|
953
|
|
954 /*
|
|
955 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
|
|
956 * color "color".
|
|
957 */
|
42
|
958 void
|
11
|
959 gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{
|
|
960 {
|
42
|
961 QPainter p(gui.w);
|
|
962 p.setPen(color);
|
|
963 p.fillRect(
|
|
964 FILL_X(gui.col),
|
|
965 FILL_Y(gui.row) + gui.char_height - h + 1,
|
|
966 w, h - 2, QColor( color, color));
|
|
967 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h
|
|
968 + (int)p_linespace / 2,
|
|
969 w, h - (int)p_linespace);
|
11
|
970 }//}}}
|
|
971
|
|
972
|
|
973 /*
|
|
974 * Catch up with any queued X11 events. This may put keyboard input into the
|
|
975 * input buffer, call resize call-backs, trigger timers etc. If there is
|
|
976 * nothing in the X11 event queue (& no timers pending), then we return
|
|
977 * immediately.
|
|
978 */
|
42
|
979 void
|
11
|
980 gui_mch_update()//{{{
|
|
981 {
|
42
|
982 kapp->processEvents();
|
11
|
983 }//}}}
|
|
984
|
|
985
|
|
986 /*
|
|
987 * GUI input routine called by gui_wait_for_chars(). Waits for a character
|
|
988 * from the keyboard.
|
|
989 * wtime == -1 Wait forever.
|
|
990 * wtime == 0 This should never happen.
|
|
991 * wtime > 0 Wait wtime milliseconds for a character.
|
|
992 * Returns OK if a character was found to be available within the given time,
|
|
993 * or FAIL otherwise.
|
|
994 */
|
42
|
995 int
|
11
|
996 gui_mch_wait_for_chars(long wtime)//{{{
|
|
997 {
|
42
|
998 // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug
|
|
999 if (wtime > 0)
|
|
1000 {
|
|
1001 gui.w->wait(wtime);
|
|
1002 while (vim_is_input_buf_empty() && !gui.w->wait_done)
|
|
1003 kapp->processOneEvent();
|
|
1004 return vim_is_input_buf_empty() ? FAIL : OK;
|
|
1005 }
|
|
1006 else
|
|
1007 while (vim_is_input_buf_empty())
|
|
1008 kapp->processOneEvent();
|
11
|
1009
|
42
|
1010 return OK;
|
11
|
1011 }//}}}
|
|
1012
|
|
1013
|
|
1014 /****************************************************************************
|
|
1015 * Output drawing routines.
|
|
1016 ****************************************************************************/
|
|
1017
|
|
1018
|
|
1019 /* Flush any output to the screen */
|
42
|
1020 void
|
11
|
1021 gui_mch_flush()//{{{
|
|
1022 {
|
42
|
1023 kapp->flushX();
|
11
|
1024 }//}}}
|
|
1025
|
|
1026 /*
|
|
1027 * Clear a rectangular region of the screen from text pos (row1, col1) to
|
|
1028 * (row2, col2) inclusive.
|
|
1029 */
|
42
|
1030 void
|
11
|
1031 gui_mch_clear_block(int row1, int col1, int row2, int col2)//{{{
|
|
1032 {
|
42
|
1033 gui.w->erase(FILL_X(col1), FILL_Y(row1),
|
|
1034 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1),
|
|
1035 (row2 - row1 + 1) * gui.char_height);
|
11
|
1036 }//}}}
|
|
1037
|
42
|
1038 void
|
11
|
1039 gui_mch_clear_all(void)//{{{
|
|
1040 {
|
42
|
1041 gui.w->erase();
|
11
|
1042 }//}}}
|
|
1043
|
|
1044
|
|
1045 /*
|
|
1046 * Delete the given number of lines from the given row, scrolling up any
|
|
1047 * text further down within the scroll region.
|
|
1048 */
|
42
|
1049 void
|
11
|
1050 gui_mch_delete_lines(int row, int num_lines)//{{{
|
|
1051 {
|
42
|
1052 if (num_lines <= 0)
|
|
1053 return;
|
11
|
1054
|
42
|
1055 if (row + num_lines > gui.scroll_region_bot)
|
|
1056 {
|
|
1057 /* Scrolled out of region, just blank the lines out */
|
|
1058 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
|
|
1059 gui.scroll_region_right);
|
|
1060 }
|
|
1061 else
|
|
1062 {
|
|
1063 bitBlt(gui.w,
|
|
1064 FILL_X(gui.scroll_region_left), FILL_Y(row),
|
|
1065 gui.w,
|
|
1066 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
|
|
1067 gui.char_width * (gui.scroll_region_right
|
|
1068 - gui.scroll_region_left + 1) + 1,
|
|
1069 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
1070 Qt::CopyROP, // raster Operation
|
|
1071 true); // ignoreMask
|
11
|
1072
|
42
|
1073 /* Update gui.cursor_row if the cursor scrolled or copied over */
|
|
1074 if (gui.cursor_row >= row)
|
|
1075 {
|
|
1076 if (gui.cursor_row < row + num_lines)
|
|
1077 gui.cursor_is_valid = FALSE;
|
|
1078 else if (gui.cursor_row <= gui.scroll_region_bot)
|
|
1079 gui.cursor_row -= num_lines;
|
|
1080 }
|
11
|
1081
|
42
|
1082 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
|
|
1083 gui.scroll_region_left,
|
|
1084 gui.scroll_region_bot, gui.scroll_region_right);
|
|
1085 }
|
11
|
1086 }//}}}
|
|
1087
|
|
1088 /*
|
|
1089 * Insert the given number of lines before the given row, scrolling down any
|
|
1090 * following text within the scroll region.
|
|
1091 */
|
42
|
1092 void
|
11
|
1093 gui_mch_insert_lines(int row, int num_lines)//{{{
|
|
1094 {
|
42
|
1095 if (num_lines <= 0)
|
|
1096 return;
|
11
|
1097
|
42
|
1098 if (row + num_lines > gui.scroll_region_bot)
|
|
1099 {
|
|
1100 /* Scrolled out of region, just blank the lines out */
|
|
1101 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
|
|
1102 gui.scroll_region_right - 1);
|
|
1103 }
|
|
1104 else
|
|
1105 {
|
|
1106 bitBlt(gui.w,
|
|
1107 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
|
|
1108 gui.w,
|
|
1109 FILL_X(gui.scroll_region_left), FILL_Y(row),
|
|
1110 gui.char_width * ( gui.scroll_region_right
|
|
1111 - gui.scroll_region_left + 1 ) + 1,
|
|
1112 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
1113 Qt::CopyROP, // raster Operation
|
|
1114 true); // ignoreMask
|
11
|
1115
|
42
|
1116 /* Update gui.cursor_row if the cursor scrolled or copied over */
|
|
1117 if (gui.cursor_row >= gui.row)
|
|
1118 {
|
|
1119 if (gui.cursor_row <= gui.scroll_region_bot - num_lines)
|
|
1120 gui.cursor_row += num_lines;
|
|
1121 else if (gui.cursor_row <= gui.scroll_region_bot)
|
|
1122 gui.cursor_is_valid = FALSE;
|
|
1123 }
|
11
|
1124
|
42
|
1125 gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1,
|
|
1126 gui.scroll_region_right);
|
|
1127 }
|
11
|
1128 }//}}}
|
|
1129
|
|
1130 /*
|
|
1131 * X Selection stuff, for cutting and pasting text to other windows.
|
|
1132 */
|
42
|
1133 void
|
11
|
1134 clip_mch_request_selection(VimClipboard *cbd)//{{{
|
|
1135 {
|
|
1136 #if QT_VERSION>=300
|
42
|
1137 if (cbd == &clip_star)
|
|
1138 kapp->clipboard()->setSelectionMode(true);
|
11
|
1139 #endif
|
42
|
1140 QString selection = kapp->clipboard()->text();
|
11
|
1141
|
42
|
1142 QCString unistring = vmw->codec->fromUnicode(selection);
|
|
1143 clip_yank_selection(MCHAR, (char_u *)(const char*)unistring,
|
|
1144 (long)unistring.length(), cbd);
|
11
|
1145 #if QT_VERSION>=300
|
42
|
1146 if (cbd == &clip_star)
|
|
1147 kapp->clipboard()->setSelectionMode(false);
|
11
|
1148 #endif
|
|
1149 }//}}}
|
|
1150
|
42
|
1151 void
|
11
|
1152 clip_mch_lose_selection(VimClipboard *cbd)//{{{
|
|
1153 {
|
42
|
1154 // Don't need to do anything here
|
|
1155 gui_mch_update();
|
11
|
1156 }//}}}
|
|
1157
|
|
1158 /*
|
|
1159 * Check whatever we allready own the selection.
|
|
1160 */
|
42
|
1161 int
|
11
|
1162 clip_mch_own_selection(VimClipboard *cbd)//{{{
|
|
1163 {
|
42
|
1164 if (kapp->clipboard()->ownsSelection())
|
|
1165 return OK;
|
|
1166 else
|
|
1167 {
|
11
|
1168 #if QT_VERSION>=300
|
42
|
1169 kapp->clipboard()->setSelectionMode(true);
|
11
|
1170 #endif
|
42
|
1171 return OK;
|
|
1172 }
|
11
|
1173 }//}}}
|
|
1174
|
|
1175 /*
|
|
1176 * Send the current selection to the clipboard.
|
|
1177 */
|
42
|
1178 void
|
|
1179 clip_mch_set_selection(VimClipboard *cbd)//{{{
|
|
1180 {
|
|
1181 char_u *data;
|
|
1182 long_u length;
|
11
|
1183
|
42
|
1184 clip_get_selection(cbd);
|
|
1185 if (clip_convert_selection(&data, &length, cbd) < 0)
|
|
1186 return;
|
11
|
1187
|
42
|
1188 QString selection((const char *)data);
|
|
1189 // We must turncate the string because it is not
|
|
1190 // null terminated
|
|
1191 selection.truncate((uint) length);
|
11
|
1192
|
|
1193 #if QT_VERSION>=300
|
42
|
1194 if (cbd == &clip_star)
|
|
1195 kapp->clipboard()->setSelectionMode(true);
|
11
|
1196 #endif
|
42
|
1197 kapp->clipboard()->setText(selection);
|
11
|
1198 #if QT_VERSION>=300
|
42
|
1199 kapp->clipboard()->setSelectionMode(false);
|
11
|
1200 #endif
|
|
1201 }//}}}
|
|
1202
|
|
1203
|
|
1204 #if defined(FEAT_MENU) || defined(PROTO)
|
|
1205 /*
|
|
1206 * Make a menu item appear either active or not active (grey or not grey).
|
|
1207 */
|
42
|
1208 void
|
11
|
1209 gui_mch_menu_grey(vimmenu_T * menu, int grey)//{{{
|
|
1210 {
|
42
|
1211 if (!menu || !menu->parent || !menu->parent->widget)
|
|
1212 return;
|
75
|
1213 menu->parent->widget->setItemEnabled((long)menu, !grey);
|
42
|
1214 gui_mch_update();
|
11
|
1215 }//}}}
|
|
1216
|
|
1217 /*
|
|
1218 * Make menu item hidden or not hidden.
|
|
1219 */
|
42
|
1220 void
|
11
|
1221 gui_mch_menu_hidden(vimmenu_T * menu, int hidden)//{{{
|
|
1222 {
|
42
|
1223 // FIXME: cannot be fixed AFAIK
|
|
1224 // it's hard to remove an item in a QPopupMenu
|
|
1225 gui_mch_menu_grey(menu, hidden);
|
11
|
1226 }//}}}
|
|
1227
|
|
1228 /*
|
|
1229 * This is called after setting all the menus to grey/hidden or not.
|
|
1230 */
|
42
|
1231 void
|
11
|
1232 gui_mch_draw_menubar()//{{{
|
|
1233 {
|
42
|
1234 // nothing to do under kde
|
11
|
1235 }//}}}
|
|
1236 #endif
|
|
1237
|
|
1238 /*
|
|
1239 * Scrollbar stuff.
|
|
1240 */
|
42
|
1241 void
|
|
1242 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)//{{{
|
11
|
1243 {
|
42
|
1244 if (!sb->w)
|
|
1245 return;
|
|
1246 int width = gui.w->width();
|
|
1247 int height = gui.w->height();
|
|
1248 int neww = vmw->width();
|
|
1249 int newh = vmw->height();
|
11
|
1250
|
42
|
1251 if (gui.which_scrollbars[SBAR_LEFT])
|
|
1252 width += gui.scrollbar_width;
|
|
1253 if (gui.which_scrollbars[SBAR_RIGHT])
|
|
1254 width += gui.scrollbar_width;
|
|
1255 if (gui.which_scrollbars[SBAR_BOTTOM])
|
|
1256 height += gui.scrollbar_height;
|
23
|
1257
|
42
|
1258 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
|
11
|
1259 #if QT_VERSION>=300
|
42
|
1260 && !vmw->menuBar()->isTopLevelMenu()
|
11
|
1261 #endif
|
42
|
1262 )
|
|
1263 height += vmw->menuBar()->height();
|
11
|
1264 #ifdef FEAT_TOOLBAR
|
42
|
1265 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
1266 && (vmw->toolBar()->barPos() == KToolBar::Top
|
|
1267 || vmw->toolBar()->barPos() == KToolBar::Bottom))
|
|
1268 height += vmw->toolBar()->height();
|
11
|
1269
|
42
|
1270 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
1271 && (vmw->toolBar()->barPos() == KToolBar::Left
|
|
1272 || vmw->toolBar()->barPos() == KToolBar::Right))
|
|
1273 width += vmw->toolBar()->width();
|
11
|
1274 #endif
|
42
|
1275 if (abs(vmw->width() - width) > 5
|
|
1276 && (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT))
|
|
1277 neww = width;
|
|
1278 if (abs(vmw->height() - height) > 5 && (sb->type == SBAR_BOTTOM))
|
|
1279 newh = height;
|
11
|
1280
|
42
|
1281 if (flag)
|
|
1282 sb->w->show();
|
|
1283 else
|
|
1284 sb->w->hide();
|
|
1285 gui_mch_update();
|
|
1286 vmw->lock();
|
|
1287 vmw->resize(neww, newh);
|
|
1288 vmw->unlock();
|
|
1289 gui_mch_update();
|
11
|
1290 }//}}}
|
|
1291
|
|
1292 /*
|
|
1293 * Return the RGB value of a pixel as "#RRGGBB".
|
|
1294 */
|
42
|
1295 long_u
|
11
|
1296 gui_mch_get_rgb(guicolor_T pixel)//{{{
|
|
1297 {
|
42
|
1298 // QColor c(pixel, pixel);
|
|
1299 // return (c.red() << 16) + ((c.green() << 8)) + (c.blue());
|
|
1300 return pixel;
|
|
1301 // funny no ? it looks like with Qt we can always use directly the rgb
|
|
1302 // value (i hope i don't break colors again ;p)
|
11
|
1303 }//}}}
|
|
1304
|
|
1305 /*
|
87
|
1306 * Get current mouse coordinates in text window.
|
11
|
1307 */
|
87
|
1308 void
|
|
1309 gui_mch_getmouse(int *x, int *y)//{{{
|
11
|
1310 {
|
87
|
1311 *x = vmw->mapFromGlobal(QCursor::pos()).x();
|
|
1312 *y = vmw->mapFromGlobal(QCursor::pos()).y();
|
11
|
1313 }//}}}
|
|
1314
|
42
|
1315 void
|
11
|
1316 gui_mch_setmouse(int x, int y)//{{{
|
|
1317 {
|
42
|
1318 QCursor::setPos(vmw->mapToGlobal(QPoint(x, y)));
|
11
|
1319 }//}}}
|
|
1320
|
|
1321 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
|
|
1322 #if QT_VERSION>=300
|
|
1323 static int mshape_ids[] = {//{{{
|
|
1324 Qt::ArrowCursor, /* arrow */
|
|
1325 Qt::BlankCursor, /* blank */
|
|
1326 Qt::IbeamCursor, /* beam */
|
|
1327 Qt::SizeVerCursor, /* updown */
|
|
1328 Qt::SplitHCursor, /* udsizing */
|
|
1329 Qt::SizeHorCursor, /* leftright */
|
|
1330 Qt::SizeHorCursor, /* lrsizing */
|
42
|
1331 Qt::WaitCursor, /* busy */
|
|
1332 Qt::ForbiddenCursor, /* no */
|
11
|
1333 Qt::CrossCursor, /* crosshair */
|
42
|
1334 Qt::PointingHandCursor, /* hand1 */
|
|
1335 Qt::PointingHandCursor, /* hand2 */
|
11
|
1336 Qt::ArrowCursor, /* pencil */
|
42
|
1337 Qt::WhatsThisCursor, /* question */
|
11
|
1338 Qt::ArrowCursor, /* right-arrow */
|
|
1339 Qt::UpArrowCursor, /* up-arrow */
|
42
|
1340 Qt::ArrowCursor /* last one */
|
11
|
1341 };//}}}
|
|
1342 #else
|
|
1343 static int mshape_ids[] = {//{{{
|
|
1344 ArrowCursor, /* arrow */
|
|
1345 BlankCursor, /* blank */
|
|
1346 IbeamCursor, /* beam */
|
|
1347 SizeVerCursor, /* updown */
|
|
1348 SplitHCursor, /* udsizing */
|
|
1349 SizeHorCursor, /* leftright */
|
|
1350 SizeHorCursor, /* lrsizing */
|
42
|
1351 WaitCursor, /* busy */
|
|
1352 ForbiddenCursor, /* no */
|
11
|
1353 CrossCursor, /* crosshair */
|
42
|
1354 PointingHandCursor, /* hand1 */
|
|
1355 PointingHandCursor, /* hand2 */
|
11
|
1356 ArrowCursor, /* pencil */
|
|
1357 ArrowCursor, /* question */
|
|
1358 ArrowCursor, /* right-arrow */
|
|
1359 UpArrowCursor, /* up-arrow */
|
42
|
1360 ArrowCursor /* last one */
|
11
|
1361 };//}}}
|
|
1362 #endif
|
|
1363
|
42
|
1364 void
|
11
|
1365 mch_set_mouse_shape (int shape)//{{{
|
|
1366 {
|
42
|
1367 int id;
|
11
|
1368
|
42
|
1369 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
|
11
|
1370 #if QT_VERSION>=300
|
42
|
1371 gui.w->setCursor(Qt::BlankCursor);
|
11
|
1372 #else
|
42
|
1373 gui.w->setCursor(BlankCursor);
|
11
|
1374 #endif
|
42
|
1375 else
|
|
1376 {
|
|
1377 if (shape >= MSHAPE_NUMBERED)
|
11
|
1378 {
|
42
|
1379 id = shape - MSHAPE_NUMBERED;
|
|
1380 /* if (id >= GDK_NUM_GLYPHS)
|
|
1381 id = GDK_LEFT_PTR;
|
|
1382 else
|
|
1383 id &= ~1;*/ /* they are always even (why?) */
|
|
1384 id &= -1;
|
|
1385 }
|
|
1386 else
|
|
1387 id = mshape_ids[shape];
|
11
|
1388
|
42
|
1389 gui.w->setCursor(id);
|
|
1390 }
|
|
1391 if (shape != MSHAPE_HIDE)
|
|
1392 last_shape = shape;
|
11
|
1393 }//}}}
|
|
1394 #endif
|
|
1395
|
42
|
1396 int
|
11
|
1397 gui_mch_adjust_charsize ()//{{{
|
|
1398 {
|
42
|
1399 QFont f(*(gui.current_font));
|
|
1400 QFontMetrics fm(f);
|
|
1401 gui.char_height = fm.height() + p_linespace;
|
|
1402 //gui.char_height = fm.ascent() + fm.descent() + p_linespace;
|
|
1403 gui.char_ascent = fm.ascent() + p_linespace / 2;
|
11
|
1404
|
42
|
1405 return OK;
|
11
|
1406 }//}}}
|
|
1407
|
42
|
1408 void
|
11
|
1409 gui_mch_set_foreground ()//{{{
|
|
1410 {
|
42
|
1411 KWin::setActiveWindow(vmw->winId());
|
11
|
1412 }//}}}
|