blob: 21969c586182df9ea97a2338c33633ee96d0c990 [file] [log] [blame]
Bram Moolenaar843ee412004-06-30 16:16:41 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
10 * Porting to KDE(2) was done by
11 *
12 * (C) 2000 by Thomas Capricelli <orzel@freehackers.org>
13 *
14 * Please visit http://freehackers.org/kvim for other vim- or
15 * kde-related coding.
16 *
17 * $Id$
18 *
19 */
20
21#include <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
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000048#include "gui_kde_wid.h"
Bram Moolenaar843ee412004-06-30 16:16:41 +000049
50
51extern "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 */
Bram Moolenaar81695252004-12-29 20:58:21 +000061VimMainWindow *vmw = 0;
62SBPool *sbpool = 0;
63QString *argServerName = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +000064
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. */
68static int last_shape = 0;
69#endif
70
71/*
72 * Arguments handled by KDE internally.
73 */
74
75#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +000076static int tip = 0; // 1 no dialog, 0 use it if enabled in conf,
77 // 2 force the tip
Bram Moolenaar843ee412004-06-30 16:16:41 +000078#endif
Bram Moolenaar81695252004-12-29 20:58:21 +000079static int reverse = 0; // 0 bg : white, 1 : bg : black
80QString *startfont;
81QSize *startsize;
82static int gui_argc = 0;
83static char **gui_argv = NULL;
Bram Moolenaar843ee412004-06-30 16:16:41 +000084
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 */
Bram Moolenaar81695252004-12-29 20:58:21 +000090 void
Bram Moolenaar843ee412004-06-30 16:16:41 +000091gui_mch_prepare(int *argc, char **argv)// {{{
92{
Bram Moolenaar81695252004-12-29 20:58:21 +000093 // copy args for KDE/Qt
94 gui_argc = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +000095
Bram Moolenaar81695252004-12-29 20:58:21 +000096 // 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
Bram Moolenaar843ee412004-06-30 16:16:41 +0000108 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000109 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;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000118 }
Bram Moolenaar81695252004-12-29 20:58:21 +0000119
120 if (strcmp(argv[i], "--servername") == 0)
121 {
122 argServerName = new QString(argv[i+1]); // to get the serverName now
123 }
124#if QT_VERSION>+300
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 }
135#endif
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 }
200
201
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 }
230
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--;
236 }
237 }
Bram Moolenaar495de9c2005-01-25 22:03:25 +0000238 KCmdLineArgs::init(gui_argc, gui_argv, argv[0], I18N_NOOP("KVim"),
Bram Moolenaar81695252004-12-29 20:58:21 +0000239 I18N_NOOP("Vim inside KDE"), VIM_VERSION_SHORT);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000240}// }}}
241
242/****************************************************************************
243 * Focus handlers:
244 */
245
246/*
247 * Initialises time intervals for the cursor blinking
248 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000249 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000250gui_mch_set_blinking(long waittime, long on, long off)//{{{
251{
Bram Moolenaar81695252004-12-29 20:58:21 +0000252 gui.w->set_blink_time(waittime, on, off);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000253}//}}}
254
255/*
256 * Stop the cursor blinking. Show the cursor if it wasn't shown.
257 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000258 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000259gui_mch_stop_blink()//{{{
260{
Bram Moolenaar81695252004-12-29 20:58:21 +0000261 gui.w->stop_cursor_blinking();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000262}//}}}
263
264/*
265 * Start the cursor blinking. If it was already blinking, this restarts the
266 * waiting time and shows the cursor.
267 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000268 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000269gui_mch_start_blink()//{{{
270{
Bram Moolenaar81695252004-12-29 20:58:21 +0000271 gui.w->start_cursor_blinking();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000272}//}}}
273
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000274#ifdef FEAT_MZSCHEME
Bram Moolenaar81695252004-12-29 20:58:21 +0000275 void
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000276mzscheme_kde_start_timer()//{{{
277{
Bram Moolenaar81695252004-12-29 20:58:21 +0000278 gui.w->enable_mzscheme_threads();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000279}//}}}
Bram Moolenaar81695252004-12-29 20:58:21 +0000280 void
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000281mzscheme_kde_stop_timer()//{{{
282{
Bram Moolenaar81695252004-12-29 20:58:21 +0000283 gui.w->disable_mzscheme_threads();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000284}//}}}
285#endif
286
Bram Moolenaar843ee412004-06-30 16:16:41 +0000287/*
288 * Check if the GUI can be started. Called before gvimrc is sourced.
289 * Return OK or FAIL.
290 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000291 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000292gui_mch_init_check(void)//{{{
293{
Bram Moolenaar81695252004-12-29 20:58:21 +0000294 gui.dpy = qt_xdisplay();
295 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000296}//}}}
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 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000302 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000303gui_mch_init()//{{{
304{
Bram Moolenaar81695252004-12-29 20:58:21 +0000305 (void) new KApplication();
306 KApplication::kApplication()->dcopClient()->registerAs(
307 KApplication::kApplication()->name(), false);
308 // dbf("%s %s", KGlobal::locale()->language().latin1(), KLocale::defaultLanguage().latin1());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000309
Bram Moolenaar81695252004-12-29 20:58:21 +0000310 vmw = new VimMainWindow("KVim", 0);
311 vmw->setFrameBorderWidth(0);
312 kapp->setMainWidget(vmw);
313 kapp->setTopWidget(vmw);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000314
Bram Moolenaar81695252004-12-29 20:58:21 +0000315 sbpool = new SBPool;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000316
317#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000318 vmw->connect(kapp->clipboard(), SIGNAL(selectionChanged()),
319 vmw, SLOT(clipboard_selection_update()));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000320#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000321 vmw->connect(kapp->clipboard(), SIGNAL(dataChanged()),
322 vmw, SLOT(clipboard_data_update()));
323 clip_lose_selection(&clip_plus);
324 clip_lose_selection(&clip_star);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000325
Bram Moolenaar81695252004-12-29 20:58:21 +0000326 gui.in_focus = FALSE; // will be updated
Bram Moolenaar843ee412004-06-30 16:16:41 +0000327
Bram Moolenaar81695252004-12-29 20:58:21 +0000328 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");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000332#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000333 gui.w->setEraseColor(QColor(Qt::black));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000334#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000335 gui.w->setBackgroundColor(QColor(Qt::black));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000336#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000337 }
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");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000342#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000343 gui.w->setEraseColor(QColor(Qt::white));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000344#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000345 gui.w->setBackgroundColor(QColor(Qt::white));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000346#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000347 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000348
Bram Moolenaar81695252004-12-29 20:58:21 +0000349 gui.norm_pixel = gui.def_norm_pixel;
350 gui.back_pixel = gui.def_back_pixel;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000351
Bram Moolenaar81695252004-12-29 20:58:21 +0000352 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;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000356
Bram Moolenaar81695252004-12-29 20:58:21 +0000357 //gui.menu_height = vmw->menuBar()->height()+1;
358 //gui.toolbar_height = vmw->toolBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000359
Bram Moolenaar81695252004-12-29 20:58:21 +0000360 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000361}//}}}
362
363
364/*
365 * Called when the foreground or background color has been changed.
366 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000367 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000368gui_mch_new_colors()//{{{
369{
Bram Moolenaar81695252004-12-29 20:58:21 +0000370 QColor rgb;
371 rgb.setRgb(gui.back_pixel);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000372#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000373 gui.w->setEraseColor(rgb);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000374#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000375 gui.w->setBackgroundColor(rgb);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000376#endif
377}//}}}
378
379/*
380 * Open the GUI window which was created by a call to gui_mch_init().
381 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000382 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000383gui_mch_open()//{{{
384{
Bram Moolenaar81695252004-12-29 20:58:21 +0000385 gui.dpy = qt_xdisplay();
386 set_normal_colors();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000387
Bram Moolenaar81695252004-12-29 20:58:21 +0000388 /* Check that none of the colors are the same as the background color */
389 gui_check_colors();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000390
Bram Moolenaar81695252004-12-29 20:58:21 +0000391 /* 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 */
Bram Moolenaar843ee412004-06-30 16:16:41 +0000395#ifdef FEAT_MENU
Bram Moolenaar81695252004-12-29 20:58:21 +0000396 vmw->w->menu = new QPopupMenu(vmw);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000397
398#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000399 vmw->w->menu->insertItem(SmallIcon("ktip"), i18n("&Tip of the day..."),
400 vmw, SLOT(showTipOfTheDay()));
401 vmw->w->menu->insertSeparator();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000402#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000403 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);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000413#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000414 if (startfont != NULL)
415 gui_mch_init_font((char_u*)startfont->latin1(), FALSE);
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000416
Bram Moolenaar81695252004-12-29 20:58:21 +0000417 if (startsize != NULL)
418 vmw->resize(startsize->width(), startsize->height());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000419
Bram Moolenaar81695252004-12-29 20:58:21 +0000420 gui_mch_update_codec();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000421
Bram Moolenaar81695252004-12-29 20:58:21 +0000422 if (kapp->isRestored())
423 if (KMainWindow::canBeRestored(1))
424 vmw->restore(1);
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000425
Bram Moolenaar81695252004-12-29 20:58:21 +0000426 vmw->show();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000427#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000428 if (tip == 2)
429 KTipDialog::showTip(vmw, QString::null, true);
430 else if (tip == 0)
431 KTipDialog::showTip(vmw);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000432#endif
433
Bram Moolenaar81695252004-12-29 20:58:21 +0000434 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000435}//}}}
436
Bram Moolenaar81695252004-12-29 20:58:21 +0000437 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000438gui_mch_exit(int rc)//{{{
439{
Bram Moolenaar81695252004-12-29 20:58:21 +0000440 kapp->quit();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000441}//}}}
442
443/*
444 * Get the position of the top left corner of the window.
445 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000446 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000447gui_mch_get_winpos(int *x, int *y)//{{{
448{
Bram Moolenaar81695252004-12-29 20:58:21 +0000449 *x = vmw->x();
450 *y = vmw->y();
451 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000452}//}}}
453
454/*
455 * Set the position of the top left corner of the window to the given
456 * coordinates.
457 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000458 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000459gui_mch_set_winpos(int x, int y)//{{{
460{
Bram Moolenaar81695252004-12-29 20:58:21 +0000461 vmw->move(x, y);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000462}//}}}
463
464/*
465 * Set the windows size.
466 * ->resize VimWidget
467 * ->resize vmw (block any events generated from here)
468 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000469 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000470gui_mch_set_shellsize(int width, int height,//{{{
471 int min_width, int min_height,
472 int base_width, int base_height)
473{
Bram Moolenaar81695252004-12-29 20:58:21 +0000474 //resize VimWidget
475 vmw->w->resize(width, height);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000476
Bram Moolenaar81695252004-12-29 20:58:21 +0000477 //resize vmw
478 int vheight, vwidth;
479 vheight = height;
480 vwidth = width;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000481
Bram Moolenaar81695252004-12-29 20:58:21 +0000482 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;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000488
Bram Moolenaar81695252004-12-29 20:58:21 +0000489 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000490#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000491 && !vmw->menuBar()->isTopLevelMenu()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000492#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000493 )
494 vheight += vmw->menuBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000495#ifdef FEAT_TOOLBAR
Bram Moolenaar81695252004-12-29 20:58:21 +0000496 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
497 && (vmw->toolBar()->barPos() == KToolBar::Top
498 || vmw->toolBar()->barPos() == KToolBar::Bottom))
499 vheight += vmw->toolBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000500
Bram Moolenaar81695252004-12-29 20:58:21 +0000501 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
502 && (vmw->toolBar()->barPos() == KToolBar::Left
503 || vmw->toolBar()->barPos() == KToolBar::Right))
504 vwidth += vmw->toolBar()->width();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000505#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000506 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();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000514}//}}}
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 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000522 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000523gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)//{{{
524{
Bram Moolenaar81695252004-12-29 20:58:21 +0000525 *screen_w = kapp->desktop()->width();
526 *screen_h = kapp->desktop()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000527}//}}}
528
529#if defined(FEAT_MENU) || defined(PROTO)
Bram Moolenaar81695252004-12-29 20:58:21 +0000530 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000531gui_mch_enable_menu(int showit)//{{{
532{
Bram Moolenaar81695252004-12-29 20:58:21 +0000533 if (showit)
534 vmw->menuBar()->show();
535 else
536 vmw->menuBar()->hide();
537 vmw->resize(vmw->width(), vmw->height());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000538}//}}}
539#endif
540
541
542#if defined(FEAT_TOOLBAR) || defined(PROTO)
Bram Moolenaar81695252004-12-29 20:58:21 +0000543 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000544gui_mch_show_toolbar(int showit)//{{{
545{
Bram Moolenaar81695252004-12-29 20:58:21 +0000546 if (showit)
547 vmw->toolBar()->show();
548 else
549 vmw->toolBar()->hide();
550 vmw->resize(vmw->width(), vmw->height());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000551}//}}}
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
Bram Moolenaar81695252004-12-29 20:58:21 +0000560 char_u *
561gui_mch_font_dialog(char_u *oldval)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000562{
Bram Moolenaar81695252004-12-29 20:58:21 +0000563 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);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000572#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000573 QString n = myFont.toString();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000574#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000575 QString n = KVimUtils::toString(&myFont);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000576#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000577 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");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000581
Bram Moolenaar81695252004-12-29 20:58:21 +0000582 //display a message box which explains how to save your font settings
583 KMessageBox::information(vmw, n, "Font Selection", "kvimselectfont");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000584
Bram Moolenaar81695252004-12-29 20:58:21 +0000585 return vim_strsave(gui.fontname);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000586}//}}}
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 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000592 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000593gui_mch_init_font(char_u * font_name, int fontset)//{{{
594{
Bram Moolenaar81695252004-12-29 20:58:21 +0000595 QString fontname;
596 GuiFont font = NULL;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000597
Bram Moolenaar81695252004-12-29 20:58:21 +0000598 if (font_name == NULL)
599 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000600#if 0
601#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000602 KConfig *base = KGlobal::config();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000603#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000604 KConfigBase *base = KGlobal::config();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000605#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000606 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;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000611 }
Bram Moolenaar81695252004-12-29 20:58:21 +0000612#if QT_VERSION>=300
613 QString f = base->readEntry("fixed");
614#else
615 QFont ft = base->readFontEntry("fixed", NULL);
616 QString f = KVimUtils::toString(&ft);
617#endif
618 font_name = (char_u*)strdup(f.latin1()); //latin1 ?
619#else
620 font_name = (char_u*)strdup("misc-fixed/10/-1/5/50/0/0/0/1/0");
621#endif
622 }
623 fontname = (const char *)font_name;
624 /* fontname.replace(QRegExp("/"), ",");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000625 font = new QFont();
626 font->fromString( fontname );
Bram Moolenaar81695252004-12-29 20:58:21 +0000627 */
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000628#ifdef FEAT_XFONTSET
Bram Moolenaar81695252004-12-29 20:58:21 +0000629 if (fontset)
630 font = gui_mch_get_fontset(font_name, TRUE, TRUE);
631 if (font == NULL)
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000632#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000633 font = gui_mch_get_font(font_name, FALSE);
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000634
Bram Moolenaar81695252004-12-29 20:58:21 +0000635 if (font == NULL)
636 return FAIL;
637 if (fontname.contains('*') && fontname.contains('-'))
638 return FAIL;
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000639
Bram Moolenaar81695252004-12-29 20:58:21 +0000640 gui_mch_free_font(gui.norm_font);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000641#ifdef FEAT_XFONTSET
Bram Moolenaar81695252004-12-29 20:58:21 +0000642 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
Bram Moolenaar843ee412004-06-30 16:16:41 +0000650#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000651 gui.norm_font = font;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000652
Bram Moolenaar81695252004-12-29 20:58:21 +0000653 /* 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;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000666
Bram Moolenaar81695252004-12-29 20:58:21 +0000667 //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;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000672
Bram Moolenaar81695252004-12-29 20:58:21 +0000673 hl_set_font_name(font_name);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000674
Bram Moolenaar81695252004-12-29 20:58:21 +0000675 vmw->w->setFont(*font);
676
677 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000678}//}}}
679
Bram Moolenaar81695252004-12-29 20:58:21 +0000680 GuiFont
Bram Moolenaar843ee412004-06-30 16:16:41 +0000681gui_mch_get_font(char_u * name, int report_error)//{{{
682{
Bram Moolenaar81695252004-12-29 20:58:21 +0000683 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);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000691
692#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +0000693 myFont->fromString(fontname);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000694#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000695 KVimUtils::fromString(myFont, fontname);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000696#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000697 myFont->setFixedPitch(true);
698 if (!myFont->fixedPitch())
699 dbf("Non fixed-width font");
700 return (GuiFont) myFont;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000701}//}}}
702
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000703#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000704/*
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000705 * 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 *
Bram Moolenaar81695252004-12-29 20:58:21 +0000709gui_mch_get_fontname(GuiFont font, char_u *name)//{{{
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000710{
711 if (name == NULL)
712 return NULL;
713 return vim_strsave(name);
Bram Moolenaar81695252004-12-29 20:58:21 +0000714}//}}}
Bram Moolenaardfccaf02004-12-31 20:56:11 +0000715#endif
Bram Moolenaard8b0cf12004-12-12 11:33:30 +0000716
717/*
Bram Moolenaar843ee412004-06-30 16:16:41 +0000718 * 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 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000722 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000723gui_mch_set_font(GuiFont font)//{{{
724{
Bram Moolenaar81695252004-12-29 20:58:21 +0000725 gui.current_font = font;
726 gui.w->painter->setFont(*(gui.current_font));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000727}//}}}
728
729/*
730 * If a font is not going to be used, free its structure.
731 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000732 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000733gui_mch_free_font(GuiFont font)//{{{
734{
735 if (font)
736 delete font; // this is a QFont , we can delete it :)
737}//}}}
738
Bram Moolenaar81695252004-12-29 20:58:21 +0000739 GuiFontset
740gui_mch_get_fontset(char_u *name, int report_error, int fixed_width)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000741{
Bram Moolenaar81695252004-12-29 20:58:21 +0000742 return (GuiFontset)gui_mch_get_font(name, report_error);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000743}
744
Bram Moolenaar81695252004-12-29 20:58:21 +0000745 void
746gui_mch_set_fontset(GuiFontset fontset)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000747{
748 gui_mch_set_font((GuiFont)fontset);
749}
750
Bram Moolenaar81695252004-12-29 20:58:21 +0000751 void
752gui_mch_free_fontset(GuiFontset fontset)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000753{
754 if (fontset)
755 delete fontset;
756}
757
Bram Moolenaar81695252004-12-29 20:58:21 +0000758 void
759gui_mch_settitle(char_u *title, char_u *icon)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000760{
Bram Moolenaar81695252004-12-29 20:58:21 +0000761 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
Bram Moolenaar843ee412004-06-30 16:16:41 +0000766}//}}}
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 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000774 guicolor_T
Bram Moolenaar843ee412004-06-30 16:16:41 +0000775gui_mch_get_color(char_u * name)//{{{
776{
Bram Moolenaar81695252004-12-29 20:58:21 +0000777 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 };
791
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);
796
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 }
804
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)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000811 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000812 name = (char_u *) vimnames[i][1];
813 return gui_mch_get_color(name);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000814 }
Bram Moolenaar81695252004-12-29 20:58:21 +0000815 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000816
Bram Moolenaar81695252004-12-29 20:58:21 +0000817 return (guicolor_T)(-1); // dead code, should not be reached..
Bram Moolenaar843ee412004-06-30 16:16:41 +0000818}//}}}
819
820/*
821 * Set the current text foreground color.
822 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000823 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000824gui_mch_set_fg_color(guicolor_T color)//{{{
825{
Bram Moolenaar81695252004-12-29 20:58:21 +0000826 QColor rgb;
827 rgb.setRgb(color);
828 gui.w->painter->setPen(rgb);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000829}//}}}
830
831/*
832 * Set the current text background color.
833 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000834 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000835gui_mch_set_bg_color(guicolor_T color)//{{{
836{
Bram Moolenaar81695252004-12-29 20:58:21 +0000837 QColor rgb;
838 rgb.setRgb(color);
839 gui.w->painter->setBackgroundColor(rgb);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000840}//}}}
841
842/*
Bram Moolenaare2cc9702005-03-15 22:43:58 +0000843 * Set the current text special color.
844 */
845 void
846gui_mch_set_sp_color(guicolor_T color)//{{{
847{
848 /* TODO */
849}//}}}
850
851/*
Bram Moolenaar843ee412004-06-30 16:16:41 +0000852 * Use the blank mouse pointer or not.
853 *
854 * hide: TRUE = use blank ptr, FALSE = use parent ptr
855 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000856 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000857gui_mch_mousehide(int hide)//{{{
858{
Bram Moolenaar81695252004-12-29 20:58:21 +0000859 if (hide == gui.pointer_hidden)
860 return;
861 //#ifdef FEAT_MOUSESHAPE
862 // if (!hide) mch_set_mouse_shape(last_shape);
863 //#else
Bram Moolenaar843ee412004-06-30 16:16:41 +0000864# if (QT_VERSION<300)
Bram Moolenaar81695252004-12-29 20:58:21 +0000865 gui.w->setCursor((hide)?BlankCursor:ArrowCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000866# else
Bram Moolenaar81695252004-12-29 20:58:21 +0000867 gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000868# endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000869 //#endif
870 gui.pointer_hidden = hide;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000871}//}}}
872
Bram Moolenaar81695252004-12-29 20:58:21 +0000873 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000874gui_mch_update_codec()
875{
876#ifdef FEAT_MBYTE
Bram Moolenaar81695252004-12-29 20:58:21 +0000877 if (!gui.in_use)
878 return;
879 vmw->codec = QTextCodec::codecForName((const char *)p_enc);
880 if (vmw->codec == NULL)
881 vmw->codec = QTextCodec::codecForName(
882 KVimUtils::convertEncodingName(QString((const char*)p_enc)));
883 if (vmw->codec == NULL)
884 vmw->codec = QTextCodec::codecForLocale();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000885#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000886 vmw->codec = QTextCodec::codecForLocale();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000887#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000888 if (vmw->codec == NULL)
889 vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback
Bram Moolenaar843ee412004-06-30 16:16:41 +0000890}
891
Bram Moolenaar81695252004-12-29 20:58:21 +0000892 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000893gui_mch_draw_string(int row, int col, char_u * s, int len, int flags)//{{{
894{
Bram Moolenaar81695252004-12-29 20:58:21 +0000895 QString text = vmw->codec->toUnicode((const char *)s, len);
896 gui.w->draw_string(TEXT_X(col), TEXT_Y(row), text, text.length(), flags);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000897}//}}}
898
899#if defined(FEAT_TITLE) || defined(PROTO)
900/*
901 * Return the text window-id and display. Only required for X-based GUI's
902 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000903 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000904gui_get_x11_windis(Window * win, Display ** dis)//{{{
905{
Bram Moolenaar81695252004-12-29 20:58:21 +0000906 *win = /*vmw*/gui.w->winId();
907 *dis = qt_xdisplay();
908 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000909}//}}}
910#endif
911
Bram Moolenaar81695252004-12-29 20:58:21 +0000912 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000913gui_mch_beep()//{{{
914{
Bram Moolenaar81695252004-12-29 20:58:21 +0000915 kapp->beep();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000916}//}}}
917
Bram Moolenaar81695252004-12-29 20:58:21 +0000918 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000919gui_mch_flash(int msec)//{{{
920{
Bram Moolenaar81695252004-12-29 20:58:21 +0000921 gui.w->flash();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000922}//}}}
923
924/*
925 * Invert a rectangle from row r, column c, for nr rows and nc columns.
926 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000927 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000928gui_mch_invert_rectangle(int r, int c, int nr, int nc)//{{{
929{
Bram Moolenaar81695252004-12-29 20:58:21 +0000930 bitBlt(gui.w,
931 FILL_X(c), FILL_Y(r),
932 gui.w,
933 FILL_X(c), FILL_Y(r),
934 (nc) * gui.char_width,
935 (nr) * gui.char_height,
936 Qt::NotROP, // raster Operation
937 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +0000938}//}}}
939
940/*
941 * Iconify the GUI window.
942 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000943 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000944gui_mch_iconify()//{{{
945{
Bram Moolenaar81695252004-12-29 20:58:21 +0000946 vmw->showMinimized();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000947}//}}}
948
949/*
950 * Draw a cursor without focus.
951 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000952 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000953gui_mch_draw_hollow_cursor(guicolor_T color)//{{{
954{
Bram Moolenaar81695252004-12-29 20:58:21 +0000955 QPainter p(gui.w);
956 p.setPen(color);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000957
Bram Moolenaar81695252004-12-29 20:58:21 +0000958 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1,
959 gui.char_height - 1);
960 p.end();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000961}//}}}
962
963/*
964 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
965 * color "color".
966 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000967 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000968gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{
969{
Bram Moolenaar81695252004-12-29 20:58:21 +0000970 QPainter p(gui.w);
971 p.setPen(color);
972 p.fillRect(
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000973#ifdef FEAT_RIGHTLEFT
974 /* vertical line should be on the right of current point */
975 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w :
976#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000977 FILL_X(gui.col),
978 FILL_Y(gui.row) + gui.char_height - h + 1,
979 w, h - 2, QColor( color, color));
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000980 p.drawRect(
981#ifdef FEAT_RIGHTLEFT
982 /* vertical line should be on the right of current point */
983 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w :
984#endif
985 FILL_X(gui.col),
986 FILL_Y(gui.row) + gui.char_height - h
Bram Moolenaar81695252004-12-29 20:58:21 +0000987 + (int)p_linespace / 2,
988 w, h - (int)p_linespace);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000989}//}}}
990
991
992/*
993 * Catch up with any queued X11 events. This may put keyboard input into the
994 * input buffer, call resize call-backs, trigger timers etc. If there is
995 * nothing in the X11 event queue (& no timers pending), then we return
996 * immediately.
997 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000998 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000999gui_mch_update()//{{{
1000{
Bram Moolenaar81695252004-12-29 20:58:21 +00001001 kapp->processEvents();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001002}//}}}
1003
1004
1005/*
1006 * GUI input routine called by gui_wait_for_chars(). Waits for a character
1007 * from the keyboard.
1008 * wtime == -1 Wait forever.
1009 * wtime == 0 This should never happen.
1010 * wtime > 0 Wait wtime milliseconds for a character.
1011 * Returns OK if a character was found to be available within the given time,
1012 * or FAIL otherwise.
1013 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001014 int
Bram Moolenaar843ee412004-06-30 16:16:41 +00001015gui_mch_wait_for_chars(long wtime)//{{{
1016{
Bram Moolenaar81695252004-12-29 20:58:21 +00001017 // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug
1018 if (wtime > 0)
1019 {
1020 gui.w->wait(wtime);
1021 while (vim_is_input_buf_empty() && !gui.w->wait_done)
1022 kapp->processOneEvent();
1023 return vim_is_input_buf_empty() ? FAIL : OK;
1024 }
1025 else
1026 while (vim_is_input_buf_empty())
1027 kapp->processOneEvent();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001028
Bram Moolenaar81695252004-12-29 20:58:21 +00001029 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001030}//}}}
1031
1032
1033/****************************************************************************
1034 * Output drawing routines.
1035 ****************************************************************************/
1036
1037
1038/* Flush any output to the screen */
Bram Moolenaar81695252004-12-29 20:58:21 +00001039 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001040gui_mch_flush()//{{{
1041{
Bram Moolenaar81695252004-12-29 20:58:21 +00001042 kapp->flushX();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001043}//}}}
1044
1045/*
1046 * Clear a rectangular region of the screen from text pos (row1, col1) to
1047 * (row2, col2) inclusive.
1048 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001049 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001050gui_mch_clear_block(int row1, int col1, int row2, int col2)//{{{
1051{
Bram Moolenaar81695252004-12-29 20:58:21 +00001052 gui.w->erase(FILL_X(col1), FILL_Y(row1),
1053 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1),
1054 (row2 - row1 + 1) * gui.char_height);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001055}//}}}
1056
Bram Moolenaar81695252004-12-29 20:58:21 +00001057 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001058gui_mch_clear_all(void)//{{{
1059{
Bram Moolenaar81695252004-12-29 20:58:21 +00001060 gui.w->erase();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001061}//}}}
1062
1063
1064/*
1065 * Delete the given number of lines from the given row, scrolling up any
1066 * text further down within the scroll region.
1067 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001068 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001069gui_mch_delete_lines(int row, int num_lines)//{{{
1070{
Bram Moolenaar81695252004-12-29 20:58:21 +00001071 if (num_lines <= 0)
1072 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001073
Bram Moolenaar81695252004-12-29 20:58:21 +00001074 if (row + num_lines > gui.scroll_region_bot)
1075 {
1076 /* Scrolled out of region, just blank the lines out */
1077 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
1078 gui.scroll_region_right);
1079 }
1080 else
1081 {
1082 bitBlt(gui.w,
1083 FILL_X(gui.scroll_region_left), FILL_Y(row),
1084 gui.w,
1085 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
1086 gui.char_width * (gui.scroll_region_right
1087 - gui.scroll_region_left + 1) + 1,
1088 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
1089 Qt::CopyROP, // raster Operation
1090 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +00001091
Bram Moolenaar81695252004-12-29 20:58:21 +00001092 /* Update gui.cursor_row if the cursor scrolled or copied over */
1093 if (gui.cursor_row >= row)
1094 {
1095 if (gui.cursor_row < row + num_lines)
1096 gui.cursor_is_valid = FALSE;
1097 else if (gui.cursor_row <= gui.scroll_region_bot)
1098 gui.cursor_row -= num_lines;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001099 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001100
1101 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
1102 gui.scroll_region_left,
1103 gui.scroll_region_bot, gui.scroll_region_right);
1104 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001105}//}}}
1106
1107/*
1108 * Insert the given number of lines before the given row, scrolling down any
1109 * following text within the scroll region.
1110 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001111 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001112gui_mch_insert_lines(int row, int num_lines)//{{{
1113{
Bram Moolenaar81695252004-12-29 20:58:21 +00001114 if (num_lines <= 0)
1115 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001116
Bram Moolenaar81695252004-12-29 20:58:21 +00001117 if (row + num_lines > gui.scroll_region_bot)
1118 {
1119 /* Scrolled out of region, just blank the lines out */
1120 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
1121 gui.scroll_region_right - 1);
1122 }
1123 else
1124 {
1125 bitBlt(gui.w,
1126 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
1127 gui.w,
1128 FILL_X(gui.scroll_region_left), FILL_Y(row),
1129 gui.char_width * ( gui.scroll_region_right
1130 - gui.scroll_region_left + 1 ) + 1,
1131 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
1132 Qt::CopyROP, // raster Operation
1133 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +00001134
Bram Moolenaar81695252004-12-29 20:58:21 +00001135 /* Update gui.cursor_row if the cursor scrolled or copied over */
1136 if (gui.cursor_row >= gui.row)
1137 {
1138 if (gui.cursor_row <= gui.scroll_region_bot - num_lines)
1139 gui.cursor_row += num_lines;
1140 else if (gui.cursor_row <= gui.scroll_region_bot)
1141 gui.cursor_is_valid = FALSE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001142 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001143
1144 gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1,
1145 gui.scroll_region_right);
1146 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001147}//}}}
1148
1149/*
1150 * X Selection stuff, for cutting and pasting text to other windows.
1151 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001152 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001153clip_mch_request_selection(VimClipboard *cbd)//{{{
1154{
1155#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001156 if (cbd == &clip_star)
1157 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001158#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001159 QString selection = kapp->clipboard()->text();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001160
Bram Moolenaar81695252004-12-29 20:58:21 +00001161 QCString unistring = vmw->codec->fromUnicode(selection);
1162 clip_yank_selection(MCHAR, (char_u *)(const char*)unistring,
1163 (long)unistring.length(), cbd);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001164#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001165 if (cbd == &clip_star)
1166 kapp->clipboard()->setSelectionMode(false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001167#endif
1168}//}}}
1169
Bram Moolenaar81695252004-12-29 20:58:21 +00001170 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001171clip_mch_lose_selection(VimClipboard *cbd)//{{{
1172{
Bram Moolenaar81695252004-12-29 20:58:21 +00001173 // Don't need to do anything here
1174 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001175}//}}}
1176
1177/*
1178 * Check whatever we allready own the selection.
1179 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001180 int
Bram Moolenaar843ee412004-06-30 16:16:41 +00001181clip_mch_own_selection(VimClipboard *cbd)//{{{
1182{
Bram Moolenaar81695252004-12-29 20:58:21 +00001183 if (kapp->clipboard()->ownsSelection())
1184 return OK;
1185 else
1186 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001187#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001188 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001189#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001190 return OK;
1191 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001192}//}}}
1193
1194/*
1195 * Send the current selection to the clipboard.
1196 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001197 void
1198clip_mch_set_selection(VimClipboard *cbd)//{{{
1199{
1200 char_u *data;
1201 long_u length;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001202
Bram Moolenaar81695252004-12-29 20:58:21 +00001203 clip_get_selection(cbd);
1204 if (clip_convert_selection(&data, &length, cbd) < 0)
1205 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001206
Bram Moolenaar81695252004-12-29 20:58:21 +00001207 QString selection((const char *)data);
1208 // We must turncate the string because it is not
1209 // null terminated
1210 selection.truncate((uint) length);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001211
1212#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001213 if (cbd == &clip_star)
1214 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001215#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001216 kapp->clipboard()->setText(selection);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001217#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001218 kapp->clipboard()->setSelectionMode(false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001219#endif
1220}//}}}
1221
1222
1223#if defined(FEAT_MENU) || defined(PROTO)
1224/*
1225 * Make a menu item appear either active or not active (grey or not grey).
1226 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001227 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001228gui_mch_menu_grey(vimmenu_T * menu, int grey)//{{{
1229{
Bram Moolenaar81695252004-12-29 20:58:21 +00001230 if (!menu || !menu->parent || !menu->parent->widget)
1231 return;
Bram Moolenaar12805862005-01-05 22:16:17 +00001232 menu->parent->widget->setItemEnabled((long)menu, !grey);
Bram Moolenaar81695252004-12-29 20:58:21 +00001233 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001234}//}}}
1235
1236/*
1237 * Make menu item hidden or not hidden.
1238 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001239 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001240gui_mch_menu_hidden(vimmenu_T * menu, int hidden)//{{{
1241{
Bram Moolenaar81695252004-12-29 20:58:21 +00001242 // FIXME: cannot be fixed AFAIK
1243 // it's hard to remove an item in a QPopupMenu
1244 gui_mch_menu_grey(menu, hidden);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001245}//}}}
1246
1247/*
1248 * This is called after setting all the menus to grey/hidden or not.
1249 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001250 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001251gui_mch_draw_menubar()//{{{
1252{
Bram Moolenaar81695252004-12-29 20:58:21 +00001253 // nothing to do under kde
Bram Moolenaar843ee412004-06-30 16:16:41 +00001254}//}}}
1255#endif
1256
1257/*
1258 * Scrollbar stuff.
1259 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001260 void
1261gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001262{
Bram Moolenaar81695252004-12-29 20:58:21 +00001263 if (!sb->w)
1264 return;
1265 int width = gui.w->width();
1266 int height = gui.w->height();
1267 int neww = vmw->width();
1268 int newh = vmw->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001269
Bram Moolenaar81695252004-12-29 20:58:21 +00001270 if (gui.which_scrollbars[SBAR_LEFT])
1271 width += gui.scrollbar_width;
1272 if (gui.which_scrollbars[SBAR_RIGHT])
1273 width += gui.scrollbar_width;
1274 if (gui.which_scrollbars[SBAR_BOTTOM])
1275 height += gui.scrollbar_height;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001276
Bram Moolenaar81695252004-12-29 20:58:21 +00001277 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001278#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001279 && !vmw->menuBar()->isTopLevelMenu()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001280#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001281 )
1282 height += vmw->menuBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001283#ifdef FEAT_TOOLBAR
Bram Moolenaar81695252004-12-29 20:58:21 +00001284 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1285 && (vmw->toolBar()->barPos() == KToolBar::Top
1286 || vmw->toolBar()->barPos() == KToolBar::Bottom))
1287 height += vmw->toolBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001288
Bram Moolenaar81695252004-12-29 20:58:21 +00001289 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1290 && (vmw->toolBar()->barPos() == KToolBar::Left
1291 || vmw->toolBar()->barPos() == KToolBar::Right))
1292 width += vmw->toolBar()->width();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001293#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001294 if (abs(vmw->width() - width) > 5
1295 && (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT))
1296 neww = width;
1297 if (abs(vmw->height() - height) > 5 && (sb->type == SBAR_BOTTOM))
1298 newh = height;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001299
Bram Moolenaar81695252004-12-29 20:58:21 +00001300 if (flag)
1301 sb->w->show();
1302 else
1303 sb->w->hide();
1304 gui_mch_update();
1305 vmw->lock();
1306 vmw->resize(neww, newh);
1307 vmw->unlock();
1308 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001309}//}}}
1310
1311/*
1312 * Return the RGB value of a pixel as "#RRGGBB".
1313 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001314 long_u
Bram Moolenaar843ee412004-06-30 16:16:41 +00001315gui_mch_get_rgb(guicolor_T pixel)//{{{
1316{
Bram Moolenaar81695252004-12-29 20:58:21 +00001317 // QColor c(pixel, pixel);
1318 // return (c.red() << 16) + ((c.green() << 8)) + (c.blue());
1319 return pixel;
1320 // funny no ? it looks like with Qt we can always use directly the rgb
1321 // value (i hope i don't break colors again ;p)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001322}//}}}
1323
1324/*
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001325 * Get current mouse coordinates in text window.
Bram Moolenaar843ee412004-06-30 16:16:41 +00001326 */
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001327 void
1328gui_mch_getmouse(int *x, int *y)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001329{
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001330 *x = vmw->mapFromGlobal(QCursor::pos()).x();
1331 *y = vmw->mapFromGlobal(QCursor::pos()).y();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001332}//}}}
1333
Bram Moolenaar81695252004-12-29 20:58:21 +00001334 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001335gui_mch_setmouse(int x, int y)//{{{
1336{
Bram Moolenaar81695252004-12-29 20:58:21 +00001337 QCursor::setPos(vmw->mapToGlobal(QPoint(x, y)));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001338}//}}}
1339
1340#if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1341#if QT_VERSION>=300
1342static int mshape_ids[] = {//{{{
1343 Qt::ArrowCursor, /* arrow */
1344 Qt::BlankCursor, /* blank */
1345 Qt::IbeamCursor, /* beam */
1346 Qt::SizeVerCursor, /* updown */
1347 Qt::SplitHCursor, /* udsizing */
1348 Qt::SizeHorCursor, /* leftright */
1349 Qt::SizeHorCursor, /* lrsizing */
Bram Moolenaar81695252004-12-29 20:58:21 +00001350 Qt::WaitCursor, /* busy */
1351 Qt::ForbiddenCursor, /* no */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001352 Qt::CrossCursor, /* crosshair */
Bram Moolenaar81695252004-12-29 20:58:21 +00001353 Qt::PointingHandCursor, /* hand1 */
1354 Qt::PointingHandCursor, /* hand2 */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001355 Qt::ArrowCursor, /* pencil */
Bram Moolenaar81695252004-12-29 20:58:21 +00001356 Qt::WhatsThisCursor, /* question */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001357 Qt::ArrowCursor, /* right-arrow */
1358 Qt::UpArrowCursor, /* up-arrow */
Bram Moolenaar81695252004-12-29 20:58:21 +00001359 Qt::ArrowCursor /* last one */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001360};//}}}
1361#else
1362static int mshape_ids[] = {//{{{
1363 ArrowCursor, /* arrow */
1364 BlankCursor, /* blank */
1365 IbeamCursor, /* beam */
1366 SizeVerCursor, /* updown */
1367 SplitHCursor, /* udsizing */
1368 SizeHorCursor, /* leftright */
1369 SizeHorCursor, /* lrsizing */
Bram Moolenaar81695252004-12-29 20:58:21 +00001370 WaitCursor, /* busy */
1371 ForbiddenCursor, /* no */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001372 CrossCursor, /* crosshair */
Bram Moolenaar81695252004-12-29 20:58:21 +00001373 PointingHandCursor, /* hand1 */
1374 PointingHandCursor, /* hand2 */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001375 ArrowCursor, /* pencil */
1376 ArrowCursor, /* question */
1377 ArrowCursor, /* right-arrow */
1378 UpArrowCursor, /* up-arrow */
Bram Moolenaar81695252004-12-29 20:58:21 +00001379 ArrowCursor /* last one */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001380};//}}}
1381#endif
1382
Bram Moolenaar81695252004-12-29 20:58:21 +00001383 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001384mch_set_mouse_shape (int shape)//{{{
1385{
Bram Moolenaar81695252004-12-29 20:58:21 +00001386 int id;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001387
Bram Moolenaar81695252004-12-29 20:58:21 +00001388 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001389#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001390 gui.w->setCursor(Qt::BlankCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001391#else
Bram Moolenaar81695252004-12-29 20:58:21 +00001392 gui.w->setCursor(BlankCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001393#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001394 else
1395 {
1396 if (shape >= MSHAPE_NUMBERED)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001397 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001398 id = shape - MSHAPE_NUMBERED;
1399 /* if (id >= GDK_NUM_GLYPHS)
1400 id = GDK_LEFT_PTR;
1401 else
1402 id &= ~1;*/ /* they are always even (why?) */
1403 id &= -1;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001404 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001405 else
1406 id = mshape_ids[shape];
1407
1408 gui.w->setCursor(id);
1409 }
1410 if (shape != MSHAPE_HIDE)
1411 last_shape = shape;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001412}//}}}
1413#endif
1414
Bram Moolenaar81695252004-12-29 20:58:21 +00001415 int
Bram Moolenaar843ee412004-06-30 16:16:41 +00001416gui_mch_adjust_charsize ()//{{{
1417{
Bram Moolenaar81695252004-12-29 20:58:21 +00001418 QFont f(*(gui.current_font));
1419 QFontMetrics fm(f);
1420 gui.char_height = fm.height() + p_linespace;
1421 //gui.char_height = fm.ascent() + fm.descent() + p_linespace;
1422 gui.char_ascent = fm.ascent() + p_linespace / 2;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001423
Bram Moolenaar81695252004-12-29 20:58:21 +00001424 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001425}//}}}
1426
Bram Moolenaar81695252004-12-29 20:58:21 +00001427 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001428gui_mch_set_foreground ()//{{{
1429{
Bram Moolenaar495de9c2005-01-25 22:03:25 +00001430 KWin::activateWindow(vmw->winId());
Bram Moolenaar843ee412004-06-30 16:16:41 +00001431}//}}}