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
|
|
703 /*
|
37
|
704 * Return the name of font "font" in allocated memory.
|
|
705 * Don't know how to get the actual name, thus use the provided name.
|
|
706 */
|
|
707 char_u *
|
42
|
708 gui_mch_get_fontname(GuiFont font, char_u *name)//{{{
|
37
|
709 {
|
|
710 if (name == NULL)
|
|
711 return NULL;
|
|
712 return vim_strsave(name);
|
42
|
713 }//}}}
|
37
|
714
|
|
715 /*
|
11
|
716 * Set the current text font.
|
|
717 * Since we create all GC on demand, we use just gui.current_font to
|
|
718 * indicate the desired current font.
|
|
719 */
|
42
|
720 void
|
11
|
721 gui_mch_set_font(GuiFont font)//{{{
|
|
722 {
|
42
|
723 gui.current_font = font;
|
|
724 gui.w->painter->setFont(*(gui.current_font));
|
11
|
725 }//}}}
|
|
726
|
|
727 /*
|
|
728 * If a font is not going to be used, free its structure.
|
|
729 */
|
42
|
730 void
|
11
|
731 gui_mch_free_font(GuiFont font)//{{{
|
|
732 {
|
|
733 if (font)
|
|
734 delete font; // this is a QFont , we can delete it :)
|
|
735 }//}}}
|
|
736
|
42
|
737 GuiFontset
|
|
738 gui_mch_get_fontset(char_u *name, int report_error, int fixed_width)
|
11
|
739 {
|
42
|
740 return (GuiFontset)gui_mch_get_font(name, report_error);
|
11
|
741 }
|
|
742
|
42
|
743 void
|
|
744 gui_mch_set_fontset(GuiFontset fontset)
|
11
|
745 {
|
|
746 gui_mch_set_font((GuiFont)fontset);
|
|
747 }
|
|
748
|
42
|
749 void
|
|
750 gui_mch_free_fontset(GuiFontset fontset)
|
11
|
751 {
|
|
752 if (fontset)
|
|
753 delete fontset;
|
|
754 }
|
|
755
|
42
|
756 void
|
|
757 gui_mch_settitle(char_u *title, char_u *icon)//{{{
|
11
|
758 {
|
42
|
759 if (!gui.in_use) /* can't do this when GUI not running */
|
|
760 return;
|
|
761 vmw->setPlainCaption((const char *)title);
|
|
762 QPixmap p((const char *)icon);
|
|
763 vmw->setIcon(p); //FIXME
|
11
|
764 }//}}}
|
|
765
|
|
766 /*
|
|
767 * Return the Pixel value (color) for the given color name. This routine was
|
|
768 * pretty much taken from example code in the Silicon Graphics OSF/Motif
|
|
769 * Programmer's Guide.
|
|
770 * Return -1 for error.
|
|
771 */
|
42
|
772 guicolor_T
|
11
|
773 gui_mch_get_color(char_u * name)//{{{
|
|
774 {
|
42
|
775 int i;
|
|
776 static char *(vimnames[][2]) =
|
|
777 {
|
|
778 /* A number of colors that some X11 systems don't have */
|
|
779 {"LightRed", "#FFA0A0"},
|
|
780 {"LightGreen", "#80FF80"},
|
|
781 {"LightMagenta", "#FFA0FF"},
|
|
782 {"DarkCyan", "#008080"},
|
|
783 {"DarkBlue", "#0000C0"},
|
|
784 {"DarkRed", "#C00000"},
|
|
785 {"DarkMagenta", "#C000C0"},
|
|
786 {"DarkGrey", "#C0C0C0"},
|
|
787 {NULL, NULL}
|
|
788 };
|
11
|
789
|
42
|
790 if (!gui.in_use) /* can't do this when GUI not running */
|
|
791 return (guicolor_T)(-1);
|
|
792
|
|
793 QColor _color((const char *)name);
|
11
|
794
|
42
|
795 if (_color.isValid())
|
|
796 {
|
|
797 // return (_color.red() << 16) + ((_color.green() << 8))
|
|
798 // + (_color.blue());
|
|
799 return _color.rgb();
|
|
800 // return (guicolor_T) _color.pixel();
|
|
801 }
|
11
|
802
|
42
|
803 /* add a few builtin names */
|
|
804 for (i = 0;; ++i)
|
|
805 {
|
|
806 if (vimnames[i][0] == NULL)
|
|
807 return (guicolor_T)(-1);
|
|
808 if (STRICMP(name, vimnames[i][0]) == 0)
|
|
809 {
|
|
810 name = (char_u *) vimnames[i][1];
|
|
811 return gui_mch_get_color(name);
|
11
|
812 }
|
42
|
813 }
|
11
|
814
|
42
|
815 return (guicolor_T)(-1); // dead code, should not be reached..
|
11
|
816 }//}}}
|
|
817
|
|
818 /*
|
|
819 * Set the current text foreground color.
|
|
820 */
|
42
|
821 void
|
11
|
822 gui_mch_set_fg_color(guicolor_T color)//{{{
|
|
823 {
|
42
|
824 QColor rgb;
|
|
825 rgb.setRgb(color);
|
|
826 gui.w->painter->setPen(rgb);
|
11
|
827 }//}}}
|
|
828
|
|
829 /*
|
|
830 * Set the current text background color.
|
|
831 */
|
42
|
832 void
|
11
|
833 gui_mch_set_bg_color(guicolor_T color)//{{{
|
|
834 {
|
42
|
835 QColor rgb;
|
|
836 rgb.setRgb(color);
|
|
837 gui.w->painter->setBackgroundColor(rgb);
|
11
|
838 }//}}}
|
|
839
|
|
840 /*
|
|
841 * Use the blank mouse pointer or not.
|
|
842 *
|
|
843 * hide: TRUE = use blank ptr, FALSE = use parent ptr
|
|
844 */
|
42
|
845 void
|
11
|
846 gui_mch_mousehide(int hide)//{{{
|
|
847 {
|
42
|
848 if (hide == gui.pointer_hidden)
|
|
849 return;
|
|
850 //#ifdef FEAT_MOUSESHAPE
|
|
851 // if (!hide) mch_set_mouse_shape(last_shape);
|
|
852 //#else
|
11
|
853 # if (QT_VERSION<300)
|
42
|
854 gui.w->setCursor((hide)?BlankCursor:ArrowCursor);
|
11
|
855 # else
|
42
|
856 gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor);
|
11
|
857 # endif
|
42
|
858 //#endif
|
|
859 gui.pointer_hidden = hide;
|
11
|
860 }//}}}
|
|
861
|
42
|
862 void
|
11
|
863 gui_mch_update_codec()
|
|
864 {
|
|
865 #ifdef FEAT_MBYTE
|
42
|
866 if (!gui.in_use)
|
|
867 return;
|
|
868 vmw->codec = QTextCodec::codecForName((const char *)p_enc);
|
|
869 if (vmw->codec == NULL)
|
|
870 vmw->codec = QTextCodec::codecForName(
|
|
871 KVimUtils::convertEncodingName(QString((const char*)p_enc)));
|
|
872 if (vmw->codec == NULL)
|
|
873 vmw->codec = QTextCodec::codecForLocale();
|
11
|
874 #else
|
42
|
875 vmw->codec = QTextCodec::codecForLocale();
|
11
|
876 #endif
|
42
|
877 if (vmw->codec == NULL)
|
|
878 vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback
|
11
|
879 }
|
|
880
|
42
|
881 void
|
11
|
882 gui_mch_draw_string(int row, int col, char_u * s, int len, int flags)//{{{
|
|
883 {
|
42
|
884 QString text = vmw->codec->toUnicode((const char *)s, len);
|
|
885 gui.w->draw_string(TEXT_X(col), TEXT_Y(row), text, text.length(), flags);
|
11
|
886 }//}}}
|
|
887
|
|
888 #if defined(FEAT_TITLE) || defined(PROTO)
|
|
889 /*
|
|
890 * Return the text window-id and display. Only required for X-based GUI's
|
|
891 */
|
42
|
892 int
|
11
|
893 gui_get_x11_windis(Window * win, Display ** dis)//{{{
|
|
894 {
|
42
|
895 *win = /*vmw*/gui.w->winId();
|
|
896 *dis = qt_xdisplay();
|
|
897 return OK;
|
11
|
898 }//}}}
|
|
899 #endif
|
|
900
|
42
|
901 void
|
11
|
902 gui_mch_beep()//{{{
|
|
903 {
|
42
|
904 kapp->beep();
|
11
|
905 }//}}}
|
|
906
|
42
|
907 void
|
11
|
908 gui_mch_flash(int msec)//{{{
|
|
909 {
|
42
|
910 gui.w->flash();
|
11
|
911 }//}}}
|
|
912
|
|
913 /*
|
|
914 * Invert a rectangle from row r, column c, for nr rows and nc columns.
|
|
915 */
|
42
|
916 void
|
11
|
917 gui_mch_invert_rectangle(int r, int c, int nr, int nc)//{{{
|
|
918 {
|
42
|
919 bitBlt(gui.w,
|
|
920 FILL_X(c), FILL_Y(r),
|
|
921 gui.w,
|
|
922 FILL_X(c), FILL_Y(r),
|
|
923 (nc) * gui.char_width,
|
|
924 (nr) * gui.char_height,
|
|
925 Qt::NotROP, // raster Operation
|
|
926 true); // ignoreMask
|
11
|
927 }//}}}
|
|
928
|
|
929 /*
|
|
930 * Iconify the GUI window.
|
|
931 */
|
42
|
932 void
|
11
|
933 gui_mch_iconify()//{{{
|
|
934 {
|
42
|
935 vmw->showMinimized();
|
11
|
936 }//}}}
|
|
937
|
|
938 /*
|
|
939 * Draw a cursor without focus.
|
|
940 */
|
42
|
941 void
|
11
|
942 gui_mch_draw_hollow_cursor(guicolor_T color)//{{{
|
|
943 {
|
42
|
944 QPainter p(gui.w);
|
|
945 p.setPen(color);
|
11
|
946
|
42
|
947 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1,
|
|
948 gui.char_height - 1);
|
|
949 p.end();
|
11
|
950 }//}}}
|
|
951
|
|
952 /*
|
|
953 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
|
|
954 * color "color".
|
|
955 */
|
42
|
956 void
|
11
|
957 gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{
|
|
958 {
|
42
|
959 QPainter p(gui.w);
|
|
960 p.setPen(color);
|
|
961 p.fillRect(
|
|
962 FILL_X(gui.col),
|
|
963 FILL_Y(gui.row) + gui.char_height - h + 1,
|
|
964 w, h - 2, QColor( color, color));
|
|
965 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h
|
|
966 + (int)p_linespace / 2,
|
|
967 w, h - (int)p_linespace);
|
11
|
968 }//}}}
|
|
969
|
|
970
|
|
971 /*
|
|
972 * Catch up with any queued X11 events. This may put keyboard input into the
|
|
973 * input buffer, call resize call-backs, trigger timers etc. If there is
|
|
974 * nothing in the X11 event queue (& no timers pending), then we return
|
|
975 * immediately.
|
|
976 */
|
42
|
977 void
|
11
|
978 gui_mch_update()//{{{
|
|
979 {
|
42
|
980 kapp->processEvents();
|
11
|
981 }//}}}
|
|
982
|
|
983
|
|
984 /*
|
|
985 * GUI input routine called by gui_wait_for_chars(). Waits for a character
|
|
986 * from the keyboard.
|
|
987 * wtime == -1 Wait forever.
|
|
988 * wtime == 0 This should never happen.
|
|
989 * wtime > 0 Wait wtime milliseconds for a character.
|
|
990 * Returns OK if a character was found to be available within the given time,
|
|
991 * or FAIL otherwise.
|
|
992 */
|
42
|
993 int
|
11
|
994 gui_mch_wait_for_chars(long wtime)//{{{
|
|
995 {
|
42
|
996 // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug
|
|
997 if (wtime > 0)
|
|
998 {
|
|
999 gui.w->wait(wtime);
|
|
1000 while (vim_is_input_buf_empty() && !gui.w->wait_done)
|
|
1001 kapp->processOneEvent();
|
|
1002 return vim_is_input_buf_empty() ? FAIL : OK;
|
|
1003 }
|
|
1004 else
|
|
1005 while (vim_is_input_buf_empty())
|
|
1006 kapp->processOneEvent();
|
11
|
1007
|
42
|
1008 return OK;
|
11
|
1009 }//}}}
|
|
1010
|
|
1011
|
|
1012 /****************************************************************************
|
|
1013 * Output drawing routines.
|
|
1014 ****************************************************************************/
|
|
1015
|
|
1016
|
|
1017 /* Flush any output to the screen */
|
42
|
1018 void
|
11
|
1019 gui_mch_flush()//{{{
|
|
1020 {
|
42
|
1021 kapp->flushX();
|
11
|
1022 }//}}}
|
|
1023
|
|
1024 /*
|
|
1025 * Clear a rectangular region of the screen from text pos (row1, col1) to
|
|
1026 * (row2, col2) inclusive.
|
|
1027 */
|
42
|
1028 void
|
11
|
1029 gui_mch_clear_block(int row1, int col1, int row2, int col2)//{{{
|
|
1030 {
|
42
|
1031 gui.w->erase(FILL_X(col1), FILL_Y(row1),
|
|
1032 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1),
|
|
1033 (row2 - row1 + 1) * gui.char_height);
|
11
|
1034 }//}}}
|
|
1035
|
42
|
1036 void
|
11
|
1037 gui_mch_clear_all(void)//{{{
|
|
1038 {
|
42
|
1039 gui.w->erase();
|
11
|
1040 }//}}}
|
|
1041
|
|
1042
|
|
1043 /*
|
|
1044 * Delete the given number of lines from the given row, scrolling up any
|
|
1045 * text further down within the scroll region.
|
|
1046 */
|
42
|
1047 void
|
11
|
1048 gui_mch_delete_lines(int row, int num_lines)//{{{
|
|
1049 {
|
42
|
1050 if (num_lines <= 0)
|
|
1051 return;
|
11
|
1052
|
42
|
1053 if (row + num_lines > gui.scroll_region_bot)
|
|
1054 {
|
|
1055 /* Scrolled out of region, just blank the lines out */
|
|
1056 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
|
|
1057 gui.scroll_region_right);
|
|
1058 }
|
|
1059 else
|
|
1060 {
|
|
1061 bitBlt(gui.w,
|
|
1062 FILL_X(gui.scroll_region_left), FILL_Y(row),
|
|
1063 gui.w,
|
|
1064 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
|
|
1065 gui.char_width * (gui.scroll_region_right
|
|
1066 - gui.scroll_region_left + 1) + 1,
|
|
1067 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
1068 Qt::CopyROP, // raster Operation
|
|
1069 true); // ignoreMask
|
11
|
1070
|
42
|
1071 /* Update gui.cursor_row if the cursor scrolled or copied over */
|
|
1072 if (gui.cursor_row >= row)
|
|
1073 {
|
|
1074 if (gui.cursor_row < row + num_lines)
|
|
1075 gui.cursor_is_valid = FALSE;
|
|
1076 else if (gui.cursor_row <= gui.scroll_region_bot)
|
|
1077 gui.cursor_row -= num_lines;
|
|
1078 }
|
11
|
1079
|
42
|
1080 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
|
|
1081 gui.scroll_region_left,
|
|
1082 gui.scroll_region_bot, gui.scroll_region_right);
|
|
1083 }
|
11
|
1084 }//}}}
|
|
1085
|
|
1086 /*
|
|
1087 * Insert the given number of lines before the given row, scrolling down any
|
|
1088 * following text within the scroll region.
|
|
1089 */
|
42
|
1090 void
|
11
|
1091 gui_mch_insert_lines(int row, int num_lines)//{{{
|
|
1092 {
|
42
|
1093 if (num_lines <= 0)
|
|
1094 return;
|
11
|
1095
|
42
|
1096 if (row + num_lines > gui.scroll_region_bot)
|
|
1097 {
|
|
1098 /* Scrolled out of region, just blank the lines out */
|
|
1099 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
|
|
1100 gui.scroll_region_right - 1);
|
|
1101 }
|
|
1102 else
|
|
1103 {
|
|
1104 bitBlt(gui.w,
|
|
1105 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
|
|
1106 gui.w,
|
|
1107 FILL_X(gui.scroll_region_left), FILL_Y(row),
|
|
1108 gui.char_width * ( gui.scroll_region_right
|
|
1109 - gui.scroll_region_left + 1 ) + 1,
|
|
1110 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
|
|
1111 Qt::CopyROP, // raster Operation
|
|
1112 true); // ignoreMask
|
11
|
1113
|
42
|
1114 /* Update gui.cursor_row if the cursor scrolled or copied over */
|
|
1115 if (gui.cursor_row >= gui.row)
|
|
1116 {
|
|
1117 if (gui.cursor_row <= gui.scroll_region_bot - num_lines)
|
|
1118 gui.cursor_row += num_lines;
|
|
1119 else if (gui.cursor_row <= gui.scroll_region_bot)
|
|
1120 gui.cursor_is_valid = FALSE;
|
|
1121 }
|
11
|
1122
|
42
|
1123 gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1,
|
|
1124 gui.scroll_region_right);
|
|
1125 }
|
11
|
1126 }//}}}
|
|
1127
|
|
1128 /*
|
|
1129 * X Selection stuff, for cutting and pasting text to other windows.
|
|
1130 */
|
42
|
1131 void
|
11
|
1132 clip_mch_request_selection(VimClipboard *cbd)//{{{
|
|
1133 {
|
|
1134 #if QT_VERSION>=300
|
42
|
1135 if (cbd == &clip_star)
|
|
1136 kapp->clipboard()->setSelectionMode(true);
|
11
|
1137 #endif
|
42
|
1138 QString selection = kapp->clipboard()->text();
|
11
|
1139
|
42
|
1140 QCString unistring = vmw->codec->fromUnicode(selection);
|
|
1141 clip_yank_selection(MCHAR, (char_u *)(const char*)unistring,
|
|
1142 (long)unistring.length(), cbd);
|
11
|
1143 #if QT_VERSION>=300
|
42
|
1144 if (cbd == &clip_star)
|
|
1145 kapp->clipboard()->setSelectionMode(false);
|
11
|
1146 #endif
|
|
1147 }//}}}
|
|
1148
|
42
|
1149 void
|
11
|
1150 clip_mch_lose_selection(VimClipboard *cbd)//{{{
|
|
1151 {
|
42
|
1152 // Don't need to do anything here
|
|
1153 gui_mch_update();
|
11
|
1154 }//}}}
|
|
1155
|
|
1156 /*
|
|
1157 * Check whatever we allready own the selection.
|
|
1158 */
|
42
|
1159 int
|
11
|
1160 clip_mch_own_selection(VimClipboard *cbd)//{{{
|
|
1161 {
|
42
|
1162 if (kapp->clipboard()->ownsSelection())
|
|
1163 return OK;
|
|
1164 else
|
|
1165 {
|
11
|
1166 #if QT_VERSION>=300
|
42
|
1167 kapp->clipboard()->setSelectionMode(true);
|
11
|
1168 #endif
|
42
|
1169 return OK;
|
|
1170 }
|
11
|
1171 }//}}}
|
|
1172
|
|
1173 /*
|
|
1174 * Send the current selection to the clipboard.
|
|
1175 */
|
42
|
1176 void
|
|
1177 clip_mch_set_selection(VimClipboard *cbd)//{{{
|
|
1178 {
|
|
1179 char_u *data;
|
|
1180 long_u length;
|
11
|
1181
|
42
|
1182 clip_get_selection(cbd);
|
|
1183 if (clip_convert_selection(&data, &length, cbd) < 0)
|
|
1184 return;
|
11
|
1185
|
42
|
1186 QString selection((const char *)data);
|
|
1187 // We must turncate the string because it is not
|
|
1188 // null terminated
|
|
1189 selection.truncate((uint) length);
|
11
|
1190
|
|
1191 #if QT_VERSION>=300
|
42
|
1192 if (cbd == &clip_star)
|
|
1193 kapp->clipboard()->setSelectionMode(true);
|
11
|
1194 #endif
|
42
|
1195 kapp->clipboard()->setText(selection);
|
11
|
1196 #if QT_VERSION>=300
|
42
|
1197 kapp->clipboard()->setSelectionMode(false);
|
11
|
1198 #endif
|
|
1199 }//}}}
|
|
1200
|
|
1201
|
|
1202 #if defined(FEAT_MENU) || defined(PROTO)
|
|
1203 /*
|
|
1204 * Make a menu item appear either active or not active (grey or not grey).
|
|
1205 */
|
42
|
1206 void
|
11
|
1207 gui_mch_menu_grey(vimmenu_T * menu, int grey)//{{{
|
|
1208 {
|
42
|
1209 if (!menu || !menu->parent || !menu->parent->widget)
|
|
1210 return;
|
|
1211 menu->parent->widget->setItemEnabled((int)menu, !grey);
|
|
1212 gui_mch_update();
|
11
|
1213 }//}}}
|
|
1214
|
|
1215 /*
|
|
1216 * Make menu item hidden or not hidden.
|
|
1217 */
|
42
|
1218 void
|
11
|
1219 gui_mch_menu_hidden(vimmenu_T * menu, int hidden)//{{{
|
|
1220 {
|
42
|
1221 // FIXME: cannot be fixed AFAIK
|
|
1222 // it's hard to remove an item in a QPopupMenu
|
|
1223 gui_mch_menu_grey(menu, hidden);
|
11
|
1224 }//}}}
|
|
1225
|
|
1226 /*
|
|
1227 * This is called after setting all the menus to grey/hidden or not.
|
|
1228 */
|
42
|
1229 void
|
11
|
1230 gui_mch_draw_menubar()//{{{
|
|
1231 {
|
42
|
1232 // nothing to do under kde
|
11
|
1233 }//}}}
|
|
1234 #endif
|
|
1235
|
|
1236 /*
|
|
1237 * Scrollbar stuff.
|
|
1238 */
|
42
|
1239 void
|
|
1240 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)//{{{
|
11
|
1241 {
|
42
|
1242 if (!sb->w)
|
|
1243 return;
|
|
1244 int width = gui.w->width();
|
|
1245 int height = gui.w->height();
|
|
1246 int neww = vmw->width();
|
|
1247 int newh = vmw->height();
|
11
|
1248
|
42
|
1249 if (gui.which_scrollbars[SBAR_LEFT])
|
|
1250 width += gui.scrollbar_width;
|
|
1251 if (gui.which_scrollbars[SBAR_RIGHT])
|
|
1252 width += gui.scrollbar_width;
|
|
1253 if (gui.which_scrollbars[SBAR_BOTTOM])
|
|
1254 height += gui.scrollbar_height;
|
23
|
1255
|
42
|
1256 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
|
11
|
1257 #if QT_VERSION>=300
|
42
|
1258 && !vmw->menuBar()->isTopLevelMenu()
|
11
|
1259 #endif
|
42
|
1260 )
|
|
1261 height += vmw->menuBar()->height();
|
11
|
1262 #ifdef FEAT_TOOLBAR
|
42
|
1263 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
1264 && (vmw->toolBar()->barPos() == KToolBar::Top
|
|
1265 || vmw->toolBar()->barPos() == KToolBar::Bottom))
|
|
1266 height += vmw->toolBar()->height();
|
11
|
1267
|
42
|
1268 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
|
|
1269 && (vmw->toolBar()->barPos() == KToolBar::Left
|
|
1270 || vmw->toolBar()->barPos() == KToolBar::Right))
|
|
1271 width += vmw->toolBar()->width();
|
11
|
1272 #endif
|
42
|
1273 if (abs(vmw->width() - width) > 5
|
|
1274 && (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT))
|
|
1275 neww = width;
|
|
1276 if (abs(vmw->height() - height) > 5 && (sb->type == SBAR_BOTTOM))
|
|
1277 newh = height;
|
11
|
1278
|
42
|
1279 if (flag)
|
|
1280 sb->w->show();
|
|
1281 else
|
|
1282 sb->w->hide();
|
|
1283 gui_mch_update();
|
|
1284 vmw->lock();
|
|
1285 vmw->resize(neww, newh);
|
|
1286 vmw->unlock();
|
|
1287 gui_mch_update();
|
11
|
1288 }//}}}
|
|
1289
|
|
1290 /*
|
|
1291 * Return the RGB value of a pixel as "#RRGGBB".
|
|
1292 */
|
42
|
1293 long_u
|
11
|
1294 gui_mch_get_rgb(guicolor_T pixel)//{{{
|
|
1295 {
|
42
|
1296 // QColor c(pixel, pixel);
|
|
1297 // return (c.red() << 16) + ((c.green() << 8)) + (c.blue());
|
|
1298 return pixel;
|
|
1299 // funny no ? it looks like with Qt we can always use directly the rgb
|
|
1300 // value (i hope i don't break colors again ;p)
|
11
|
1301 }//}}}
|
|
1302
|
|
1303 /*
|
|
1304 * Get current y mouse coordinate in text window.
|
|
1305 * Return -1 when unknown.
|
|
1306 */
|
42
|
1307 int
|
11
|
1308 gui_mch_get_mouse_x(void)//{{{
|
|
1309 {
|
42
|
1310 return vmw->mapFromGlobal(QCursor::pos()).x();
|
11
|
1311 }//}}}
|
|
1312
|
42
|
1313 int
|
11
|
1314 gui_mch_get_mouse_y(void)//{{{
|
|
1315 {
|
42
|
1316 return vmw->mapFromGlobal(QCursor::pos()).y();
|
11
|
1317 }//}}}
|
|
1318
|
42
|
1319 void
|
11
|
1320 gui_mch_setmouse(int x, int y)//{{{
|
|
1321 {
|
42
|
1322 QCursor::setPos(vmw->mapToGlobal(QPoint(x, y)));
|
11
|
1323 }//}}}
|
|
1324
|
|
1325 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
|
|
1326 #if QT_VERSION>=300
|
|
1327 static int mshape_ids[] = {//{{{
|
|
1328 Qt::ArrowCursor, /* arrow */
|
|
1329 Qt::BlankCursor, /* blank */
|
|
1330 Qt::IbeamCursor, /* beam */
|
|
1331 Qt::SizeVerCursor, /* updown */
|
|
1332 Qt::SplitHCursor, /* udsizing */
|
|
1333 Qt::SizeHorCursor, /* leftright */
|
|
1334 Qt::SizeHorCursor, /* lrsizing */
|
42
|
1335 Qt::WaitCursor, /* busy */
|
|
1336 Qt::ForbiddenCursor, /* no */
|
11
|
1337 Qt::CrossCursor, /* crosshair */
|
42
|
1338 Qt::PointingHandCursor, /* hand1 */
|
|
1339 Qt::PointingHandCursor, /* hand2 */
|
11
|
1340 Qt::ArrowCursor, /* pencil */
|
42
|
1341 Qt::WhatsThisCursor, /* question */
|
11
|
1342 Qt::ArrowCursor, /* right-arrow */
|
|
1343 Qt::UpArrowCursor, /* up-arrow */
|
42
|
1344 Qt::ArrowCursor /* last one */
|
11
|
1345 };//}}}
|
|
1346 #else
|
|
1347 static int mshape_ids[] = {//{{{
|
|
1348 ArrowCursor, /* arrow */
|
|
1349 BlankCursor, /* blank */
|
|
1350 IbeamCursor, /* beam */
|
|
1351 SizeVerCursor, /* updown */
|
|
1352 SplitHCursor, /* udsizing */
|
|
1353 SizeHorCursor, /* leftright */
|
|
1354 SizeHorCursor, /* lrsizing */
|
42
|
1355 WaitCursor, /* busy */
|
|
1356 ForbiddenCursor, /* no */
|
11
|
1357 CrossCursor, /* crosshair */
|
42
|
1358 PointingHandCursor, /* hand1 */
|
|
1359 PointingHandCursor, /* hand2 */
|
11
|
1360 ArrowCursor, /* pencil */
|
|
1361 ArrowCursor, /* question */
|
|
1362 ArrowCursor, /* right-arrow */
|
|
1363 UpArrowCursor, /* up-arrow */
|
42
|
1364 ArrowCursor /* last one */
|
11
|
1365 };//}}}
|
|
1366 #endif
|
|
1367
|
42
|
1368 void
|
11
|
1369 mch_set_mouse_shape (int shape)//{{{
|
|
1370 {
|
42
|
1371 int id;
|
11
|
1372
|
42
|
1373 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
|
11
|
1374 #if QT_VERSION>=300
|
42
|
1375 gui.w->setCursor(Qt::BlankCursor);
|
11
|
1376 #else
|
42
|
1377 gui.w->setCursor(BlankCursor);
|
11
|
1378 #endif
|
42
|
1379 else
|
|
1380 {
|
|
1381 if (shape >= MSHAPE_NUMBERED)
|
11
|
1382 {
|
42
|
1383 id = shape - MSHAPE_NUMBERED;
|
|
1384 /* if (id >= GDK_NUM_GLYPHS)
|
|
1385 id = GDK_LEFT_PTR;
|
|
1386 else
|
|
1387 id &= ~1;*/ /* they are always even (why?) */
|
|
1388 id &= -1;
|
|
1389 }
|
|
1390 else
|
|
1391 id = mshape_ids[shape];
|
11
|
1392
|
42
|
1393 gui.w->setCursor(id);
|
|
1394 }
|
|
1395 if (shape != MSHAPE_HIDE)
|
|
1396 last_shape = shape;
|
11
|
1397 }//}}}
|
|
1398 #endif
|
|
1399
|
42
|
1400 int
|
11
|
1401 gui_mch_adjust_charsize ()//{{{
|
|
1402 {
|
42
|
1403 QFont f(*(gui.current_font));
|
|
1404 QFontMetrics fm(f);
|
|
1405 gui.char_height = fm.height() + p_linespace;
|
|
1406 //gui.char_height = fm.ascent() + fm.descent() + p_linespace;
|
|
1407 gui.char_ascent = fm.ascent() + p_linespace / 2;
|
11
|
1408
|
42
|
1409 return OK;
|
11
|
1410 }//}}}
|
|
1411
|
42
|
1412 void
|
11
|
1413 gui_mch_set_foreground ()//{{{
|
|
1414 {
|
42
|
1415 KWin::setActiveWindow(vmw->winId());
|
11
|
1416 }//}}}
|