blob: 21d4a041d718ccff89286291bcc4f75d8dc8c9e1 [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 }
238 KCmdLineArgs::init(gui_argc, gui_argv, "kvim",
239 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/*
843 * Use the blank mouse pointer or not.
844 *
845 * hide: TRUE = use blank ptr, FALSE = use parent ptr
846 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000847 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000848gui_mch_mousehide(int hide)//{{{
849{
Bram Moolenaar81695252004-12-29 20:58:21 +0000850 if (hide == gui.pointer_hidden)
851 return;
852 //#ifdef FEAT_MOUSESHAPE
853 // if (!hide) mch_set_mouse_shape(last_shape);
854 //#else
Bram Moolenaar843ee412004-06-30 16:16:41 +0000855# if (QT_VERSION<300)
Bram Moolenaar81695252004-12-29 20:58:21 +0000856 gui.w->setCursor((hide)?BlankCursor:ArrowCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000857# else
Bram Moolenaar81695252004-12-29 20:58:21 +0000858 gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000859# endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000860 //#endif
861 gui.pointer_hidden = hide;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000862}//}}}
863
Bram Moolenaar81695252004-12-29 20:58:21 +0000864 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000865gui_mch_update_codec()
866{
867#ifdef FEAT_MBYTE
Bram Moolenaar81695252004-12-29 20:58:21 +0000868 if (!gui.in_use)
869 return;
870 vmw->codec = QTextCodec::codecForName((const char *)p_enc);
871 if (vmw->codec == NULL)
872 vmw->codec = QTextCodec::codecForName(
873 KVimUtils::convertEncodingName(QString((const char*)p_enc)));
874 if (vmw->codec == NULL)
875 vmw->codec = QTextCodec::codecForLocale();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000876#else
Bram Moolenaar81695252004-12-29 20:58:21 +0000877 vmw->codec = QTextCodec::codecForLocale();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000878#endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000879 if (vmw->codec == NULL)
880 vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback
Bram Moolenaar843ee412004-06-30 16:16:41 +0000881}
882
Bram Moolenaar81695252004-12-29 20:58:21 +0000883 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000884gui_mch_draw_string(int row, int col, char_u * s, int len, int flags)//{{{
885{
Bram Moolenaar81695252004-12-29 20:58:21 +0000886 QString text = vmw->codec->toUnicode((const char *)s, len);
887 gui.w->draw_string(TEXT_X(col), TEXT_Y(row), text, text.length(), flags);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000888}//}}}
889
890#if defined(FEAT_TITLE) || defined(PROTO)
891/*
892 * Return the text window-id and display. Only required for X-based GUI's
893 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000894 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000895gui_get_x11_windis(Window * win, Display ** dis)//{{{
896{
Bram Moolenaar81695252004-12-29 20:58:21 +0000897 *win = /*vmw*/gui.w->winId();
898 *dis = qt_xdisplay();
899 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000900}//}}}
901#endif
902
Bram Moolenaar81695252004-12-29 20:58:21 +0000903 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000904gui_mch_beep()//{{{
905{
Bram Moolenaar81695252004-12-29 20:58:21 +0000906 kapp->beep();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000907}//}}}
908
Bram Moolenaar81695252004-12-29 20:58:21 +0000909 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000910gui_mch_flash(int msec)//{{{
911{
Bram Moolenaar81695252004-12-29 20:58:21 +0000912 gui.w->flash();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000913}//}}}
914
915/*
916 * Invert a rectangle from row r, column c, for nr rows and nc columns.
917 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000918 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000919gui_mch_invert_rectangle(int r, int c, int nr, int nc)//{{{
920{
Bram Moolenaar81695252004-12-29 20:58:21 +0000921 bitBlt(gui.w,
922 FILL_X(c), FILL_Y(r),
923 gui.w,
924 FILL_X(c), FILL_Y(r),
925 (nc) * gui.char_width,
926 (nr) * gui.char_height,
927 Qt::NotROP, // raster Operation
928 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +0000929}//}}}
930
931/*
932 * Iconify the GUI window.
933 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000934 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000935gui_mch_iconify()//{{{
936{
Bram Moolenaar81695252004-12-29 20:58:21 +0000937 vmw->showMinimized();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000938}//}}}
939
940/*
941 * Draw a cursor without focus.
942 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000943 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000944gui_mch_draw_hollow_cursor(guicolor_T color)//{{{
945{
Bram Moolenaar81695252004-12-29 20:58:21 +0000946 QPainter p(gui.w);
947 p.setPen(color);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000948
Bram Moolenaar81695252004-12-29 20:58:21 +0000949 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1,
950 gui.char_height - 1);
951 p.end();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000952}//}}}
953
954/*
955 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
956 * color "color".
957 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000958 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000959gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{
960{
Bram Moolenaar81695252004-12-29 20:58:21 +0000961 QPainter p(gui.w);
962 p.setPen(color);
963 p.fillRect(
964 FILL_X(gui.col),
965 FILL_Y(gui.row) + gui.char_height - h + 1,
966 w, h - 2, QColor( color, color));
967 p.drawRect(FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h
968 + (int)p_linespace / 2,
969 w, h - (int)p_linespace);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000970}//}}}
971
972
973/*
974 * Catch up with any queued X11 events. This may put keyboard input into the
975 * input buffer, call resize call-backs, trigger timers etc. If there is
976 * nothing in the X11 event queue (& no timers pending), then we return
977 * immediately.
978 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000979 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000980gui_mch_update()//{{{
981{
Bram Moolenaar81695252004-12-29 20:58:21 +0000982 kapp->processEvents();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000983}//}}}
984
985
986/*
987 * GUI input routine called by gui_wait_for_chars(). Waits for a character
988 * from the keyboard.
989 * wtime == -1 Wait forever.
990 * wtime == 0 This should never happen.
991 * wtime > 0 Wait wtime milliseconds for a character.
992 * Returns OK if a character was found to be available within the given time,
993 * or FAIL otherwise.
994 */
Bram Moolenaar81695252004-12-29 20:58:21 +0000995 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000996gui_mch_wait_for_chars(long wtime)//{{{
997{
Bram Moolenaar81695252004-12-29 20:58:21 +0000998 // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug
999 if (wtime > 0)
1000 {
1001 gui.w->wait(wtime);
1002 while (vim_is_input_buf_empty() && !gui.w->wait_done)
1003 kapp->processOneEvent();
1004 return vim_is_input_buf_empty() ? FAIL : OK;
1005 }
1006 else
1007 while (vim_is_input_buf_empty())
1008 kapp->processOneEvent();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001009
Bram Moolenaar81695252004-12-29 20:58:21 +00001010 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001011}//}}}
1012
1013
1014/****************************************************************************
1015 * Output drawing routines.
1016 ****************************************************************************/
1017
1018
1019/* Flush any output to the screen */
Bram Moolenaar81695252004-12-29 20:58:21 +00001020 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001021gui_mch_flush()//{{{
1022{
Bram Moolenaar81695252004-12-29 20:58:21 +00001023 kapp->flushX();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001024}//}}}
1025
1026/*
1027 * Clear a rectangular region of the screen from text pos (row1, col1) to
1028 * (row2, col2) inclusive.
1029 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001030 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001031gui_mch_clear_block(int row1, int col1, int row2, int col2)//{{{
1032{
Bram Moolenaar81695252004-12-29 20:58:21 +00001033 gui.w->erase(FILL_X(col1), FILL_Y(row1),
1034 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1),
1035 (row2 - row1 + 1) * gui.char_height);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001036}//}}}
1037
Bram Moolenaar81695252004-12-29 20:58:21 +00001038 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001039gui_mch_clear_all(void)//{{{
1040{
Bram Moolenaar81695252004-12-29 20:58:21 +00001041 gui.w->erase();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001042}//}}}
1043
1044
1045/*
1046 * Delete the given number of lines from the given row, scrolling up any
1047 * text further down within the scroll region.
1048 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001049 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001050gui_mch_delete_lines(int row, int num_lines)//{{{
1051{
Bram Moolenaar81695252004-12-29 20:58:21 +00001052 if (num_lines <= 0)
1053 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001054
Bram Moolenaar81695252004-12-29 20:58:21 +00001055 if (row + num_lines > gui.scroll_region_bot)
1056 {
1057 /* Scrolled out of region, just blank the lines out */
1058 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
1059 gui.scroll_region_right);
1060 }
1061 else
1062 {
1063 bitBlt(gui.w,
1064 FILL_X(gui.scroll_region_left), FILL_Y(row),
1065 gui.w,
1066 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
1067 gui.char_width * (gui.scroll_region_right
1068 - gui.scroll_region_left + 1) + 1,
1069 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
1070 Qt::CopyROP, // raster Operation
1071 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +00001072
Bram Moolenaar81695252004-12-29 20:58:21 +00001073 /* Update gui.cursor_row if the cursor scrolled or copied over */
1074 if (gui.cursor_row >= row)
1075 {
1076 if (gui.cursor_row < row + num_lines)
1077 gui.cursor_is_valid = FALSE;
1078 else if (gui.cursor_row <= gui.scroll_region_bot)
1079 gui.cursor_row -= num_lines;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001080 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001081
1082 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
1083 gui.scroll_region_left,
1084 gui.scroll_region_bot, gui.scroll_region_right);
1085 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001086}//}}}
1087
1088/*
1089 * Insert the given number of lines before the given row, scrolling down any
1090 * following text within the scroll region.
1091 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001092 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001093gui_mch_insert_lines(int row, int num_lines)//{{{
1094{
Bram Moolenaar81695252004-12-29 20:58:21 +00001095 if (num_lines <= 0)
1096 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001097
Bram Moolenaar81695252004-12-29 20:58:21 +00001098 if (row + num_lines > gui.scroll_region_bot)
1099 {
1100 /* Scrolled out of region, just blank the lines out */
1101 gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot,
1102 gui.scroll_region_right - 1);
1103 }
1104 else
1105 {
1106 bitBlt(gui.w,
1107 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines),
1108 gui.w,
1109 FILL_X(gui.scroll_region_left), FILL_Y(row),
1110 gui.char_width * ( gui.scroll_region_right
1111 - gui.scroll_region_left + 1 ) + 1,
1112 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1),
1113 Qt::CopyROP, // raster Operation
1114 true); // ignoreMask
Bram Moolenaar843ee412004-06-30 16:16:41 +00001115
Bram Moolenaar81695252004-12-29 20:58:21 +00001116 /* Update gui.cursor_row if the cursor scrolled or copied over */
1117 if (gui.cursor_row >= gui.row)
1118 {
1119 if (gui.cursor_row <= gui.scroll_region_bot - num_lines)
1120 gui.cursor_row += num_lines;
1121 else if (gui.cursor_row <= gui.scroll_region_bot)
1122 gui.cursor_is_valid = FALSE;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001123 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001124
1125 gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1,
1126 gui.scroll_region_right);
1127 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001128}//}}}
1129
1130/*
1131 * X Selection stuff, for cutting and pasting text to other windows.
1132 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001133 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001134clip_mch_request_selection(VimClipboard *cbd)//{{{
1135{
1136#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001137 if (cbd == &clip_star)
1138 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001139#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001140 QString selection = kapp->clipboard()->text();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001141
Bram Moolenaar81695252004-12-29 20:58:21 +00001142 QCString unistring = vmw->codec->fromUnicode(selection);
1143 clip_yank_selection(MCHAR, (char_u *)(const char*)unistring,
1144 (long)unistring.length(), cbd);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001145#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001146 if (cbd == &clip_star)
1147 kapp->clipboard()->setSelectionMode(false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001148#endif
1149}//}}}
1150
Bram Moolenaar81695252004-12-29 20:58:21 +00001151 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001152clip_mch_lose_selection(VimClipboard *cbd)//{{{
1153{
Bram Moolenaar81695252004-12-29 20:58:21 +00001154 // Don't need to do anything here
1155 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001156}//}}}
1157
1158/*
1159 * Check whatever we allready own the selection.
1160 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001161 int
Bram Moolenaar843ee412004-06-30 16:16:41 +00001162clip_mch_own_selection(VimClipboard *cbd)//{{{
1163{
Bram Moolenaar81695252004-12-29 20:58:21 +00001164 if (kapp->clipboard()->ownsSelection())
1165 return OK;
1166 else
1167 {
Bram Moolenaar843ee412004-06-30 16:16:41 +00001168#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001169 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001170#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001171 return OK;
1172 }
Bram Moolenaar843ee412004-06-30 16:16:41 +00001173}//}}}
1174
1175/*
1176 * Send the current selection to the clipboard.
1177 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001178 void
1179clip_mch_set_selection(VimClipboard *cbd)//{{{
1180{
1181 char_u *data;
1182 long_u length;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001183
Bram Moolenaar81695252004-12-29 20:58:21 +00001184 clip_get_selection(cbd);
1185 if (clip_convert_selection(&data, &length, cbd) < 0)
1186 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001187
Bram Moolenaar81695252004-12-29 20:58:21 +00001188 QString selection((const char *)data);
1189 // We must turncate the string because it is not
1190 // null terminated
1191 selection.truncate((uint) length);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001192
1193#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001194 if (cbd == &clip_star)
1195 kapp->clipboard()->setSelectionMode(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001196#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001197 kapp->clipboard()->setText(selection);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001198#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001199 kapp->clipboard()->setSelectionMode(false);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001200#endif
1201}//}}}
1202
1203
1204#if defined(FEAT_MENU) || defined(PROTO)
1205/*
1206 * Make a menu item appear either active or not active (grey or not grey).
1207 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001208 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001209gui_mch_menu_grey(vimmenu_T * menu, int grey)//{{{
1210{
Bram Moolenaar81695252004-12-29 20:58:21 +00001211 if (!menu || !menu->parent || !menu->parent->widget)
1212 return;
Bram Moolenaar12805862005-01-05 22:16:17 +00001213 menu->parent->widget->setItemEnabled((long)menu, !grey);
Bram Moolenaar81695252004-12-29 20:58:21 +00001214 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001215}//}}}
1216
1217/*
1218 * Make menu item hidden or not hidden.
1219 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001220 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001221gui_mch_menu_hidden(vimmenu_T * menu, int hidden)//{{{
1222{
Bram Moolenaar81695252004-12-29 20:58:21 +00001223 // FIXME: cannot be fixed AFAIK
1224 // it's hard to remove an item in a QPopupMenu
1225 gui_mch_menu_grey(menu, hidden);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001226}//}}}
1227
1228/*
1229 * This is called after setting all the menus to grey/hidden or not.
1230 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001231 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001232gui_mch_draw_menubar()//{{{
1233{
Bram Moolenaar81695252004-12-29 20:58:21 +00001234 // nothing to do under kde
Bram Moolenaar843ee412004-06-30 16:16:41 +00001235}//}}}
1236#endif
1237
1238/*
1239 * Scrollbar stuff.
1240 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001241 void
1242gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001243{
Bram Moolenaar81695252004-12-29 20:58:21 +00001244 if (!sb->w)
1245 return;
1246 int width = gui.w->width();
1247 int height = gui.w->height();
1248 int neww = vmw->width();
1249 int newh = vmw->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001250
Bram Moolenaar81695252004-12-29 20:58:21 +00001251 if (gui.which_scrollbars[SBAR_LEFT])
1252 width += gui.scrollbar_width;
1253 if (gui.which_scrollbars[SBAR_RIGHT])
1254 width += gui.scrollbar_width;
1255 if (gui.which_scrollbars[SBAR_BOTTOM])
1256 height += gui.scrollbar_height;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001257
Bram Moolenaar81695252004-12-29 20:58:21 +00001258 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001259#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001260 && !vmw->menuBar()->isTopLevelMenu()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001261#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001262 )
1263 height += vmw->menuBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001264#ifdef FEAT_TOOLBAR
Bram Moolenaar81695252004-12-29 20:58:21 +00001265 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1266 && (vmw->toolBar()->barPos() == KToolBar::Top
1267 || vmw->toolBar()->barPos() == KToolBar::Bottom))
1268 height += vmw->toolBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001269
Bram Moolenaar81695252004-12-29 20:58:21 +00001270 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
1271 && (vmw->toolBar()->barPos() == KToolBar::Left
1272 || vmw->toolBar()->barPos() == KToolBar::Right))
1273 width += vmw->toolBar()->width();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001274#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001275 if (abs(vmw->width() - width) > 5
1276 && (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT))
1277 neww = width;
1278 if (abs(vmw->height() - height) > 5 && (sb->type == SBAR_BOTTOM))
1279 newh = height;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001280
Bram Moolenaar81695252004-12-29 20:58:21 +00001281 if (flag)
1282 sb->w->show();
1283 else
1284 sb->w->hide();
1285 gui_mch_update();
1286 vmw->lock();
1287 vmw->resize(neww, newh);
1288 vmw->unlock();
1289 gui_mch_update();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001290}//}}}
1291
1292/*
1293 * Return the RGB value of a pixel as "#RRGGBB".
1294 */
Bram Moolenaar81695252004-12-29 20:58:21 +00001295 long_u
Bram Moolenaar843ee412004-06-30 16:16:41 +00001296gui_mch_get_rgb(guicolor_T pixel)//{{{
1297{
Bram Moolenaar81695252004-12-29 20:58:21 +00001298 // QColor c(pixel, pixel);
1299 // return (c.red() << 16) + ((c.green() << 8)) + (c.blue());
1300 return pixel;
1301 // funny no ? it looks like with Qt we can always use directly the rgb
1302 // value (i hope i don't break colors again ;p)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001303}//}}}
1304
1305/*
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001306 * Get current mouse coordinates in text window.
Bram Moolenaar843ee412004-06-30 16:16:41 +00001307 */
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001308 void
1309gui_mch_getmouse(int *x, int *y)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +00001310{
Bram Moolenaar9588a0f2005-01-08 21:45:39 +00001311 *x = vmw->mapFromGlobal(QCursor::pos()).x();
1312 *y = vmw->mapFromGlobal(QCursor::pos()).y();
Bram Moolenaar843ee412004-06-30 16:16:41 +00001313}//}}}
1314
Bram Moolenaar81695252004-12-29 20:58:21 +00001315 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001316gui_mch_setmouse(int x, int y)//{{{
1317{
Bram Moolenaar81695252004-12-29 20:58:21 +00001318 QCursor::setPos(vmw->mapToGlobal(QPoint(x, y)));
Bram Moolenaar843ee412004-06-30 16:16:41 +00001319}//}}}
1320
1321#if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1322#if QT_VERSION>=300
1323static int mshape_ids[] = {//{{{
1324 Qt::ArrowCursor, /* arrow */
1325 Qt::BlankCursor, /* blank */
1326 Qt::IbeamCursor, /* beam */
1327 Qt::SizeVerCursor, /* updown */
1328 Qt::SplitHCursor, /* udsizing */
1329 Qt::SizeHorCursor, /* leftright */
1330 Qt::SizeHorCursor, /* lrsizing */
Bram Moolenaar81695252004-12-29 20:58:21 +00001331 Qt::WaitCursor, /* busy */
1332 Qt::ForbiddenCursor, /* no */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001333 Qt::CrossCursor, /* crosshair */
Bram Moolenaar81695252004-12-29 20:58:21 +00001334 Qt::PointingHandCursor, /* hand1 */
1335 Qt::PointingHandCursor, /* hand2 */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001336 Qt::ArrowCursor, /* pencil */
Bram Moolenaar81695252004-12-29 20:58:21 +00001337 Qt::WhatsThisCursor, /* question */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001338 Qt::ArrowCursor, /* right-arrow */
1339 Qt::UpArrowCursor, /* up-arrow */
Bram Moolenaar81695252004-12-29 20:58:21 +00001340 Qt::ArrowCursor /* last one */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001341};//}}}
1342#else
1343static int mshape_ids[] = {//{{{
1344 ArrowCursor, /* arrow */
1345 BlankCursor, /* blank */
1346 IbeamCursor, /* beam */
1347 SizeVerCursor, /* updown */
1348 SplitHCursor, /* udsizing */
1349 SizeHorCursor, /* leftright */
1350 SizeHorCursor, /* lrsizing */
Bram Moolenaar81695252004-12-29 20:58:21 +00001351 WaitCursor, /* busy */
1352 ForbiddenCursor, /* no */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001353 CrossCursor, /* crosshair */
Bram Moolenaar81695252004-12-29 20:58:21 +00001354 PointingHandCursor, /* hand1 */
1355 PointingHandCursor, /* hand2 */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001356 ArrowCursor, /* pencil */
1357 ArrowCursor, /* question */
1358 ArrowCursor, /* right-arrow */
1359 UpArrowCursor, /* up-arrow */
Bram Moolenaar81695252004-12-29 20:58:21 +00001360 ArrowCursor /* last one */
Bram Moolenaar843ee412004-06-30 16:16:41 +00001361};//}}}
1362#endif
1363
Bram Moolenaar81695252004-12-29 20:58:21 +00001364 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001365mch_set_mouse_shape (int shape)//{{{
1366{
Bram Moolenaar81695252004-12-29 20:58:21 +00001367 int id;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001368
Bram Moolenaar81695252004-12-29 20:58:21 +00001369 if (shape == MSHAPE_HIDE || gui.pointer_hidden)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001370#if QT_VERSION>=300
Bram Moolenaar81695252004-12-29 20:58:21 +00001371 gui.w->setCursor(Qt::BlankCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001372#else
Bram Moolenaar81695252004-12-29 20:58:21 +00001373 gui.w->setCursor(BlankCursor);
Bram Moolenaar843ee412004-06-30 16:16:41 +00001374#endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001375 else
1376 {
1377 if (shape >= MSHAPE_NUMBERED)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001378 {
Bram Moolenaar81695252004-12-29 20:58:21 +00001379 id = shape - MSHAPE_NUMBERED;
1380 /* if (id >= GDK_NUM_GLYPHS)
1381 id = GDK_LEFT_PTR;
1382 else
1383 id &= ~1;*/ /* they are always even (why?) */
1384 id &= -1;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001385 }
Bram Moolenaar81695252004-12-29 20:58:21 +00001386 else
1387 id = mshape_ids[shape];
1388
1389 gui.w->setCursor(id);
1390 }
1391 if (shape != MSHAPE_HIDE)
1392 last_shape = shape;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001393}//}}}
1394#endif
1395
Bram Moolenaar81695252004-12-29 20:58:21 +00001396 int
Bram Moolenaar843ee412004-06-30 16:16:41 +00001397gui_mch_adjust_charsize ()//{{{
1398{
Bram Moolenaar81695252004-12-29 20:58:21 +00001399 QFont f(*(gui.current_font));
1400 QFontMetrics fm(f);
1401 gui.char_height = fm.height() + p_linespace;
1402 //gui.char_height = fm.ascent() + fm.descent() + p_linespace;
1403 gui.char_ascent = fm.ascent() + p_linespace / 2;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001404
Bram Moolenaar81695252004-12-29 20:58:21 +00001405 return OK;
Bram Moolenaar843ee412004-06-30 16:16:41 +00001406}//}}}
1407
Bram Moolenaar81695252004-12-29 20:58:21 +00001408 void
Bram Moolenaar843ee412004-06-30 16:16:41 +00001409gui_mch_set_foreground ()//{{{
1410{
Bram Moolenaar81695252004-12-29 20:58:21 +00001411 KWin::setActiveWindow(vmw->winId());
Bram Moolenaar843ee412004-06-30 16:16:41 +00001412}//}}}