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