Mercurial > vim
comparison src/gui_kde.cc @ 11:4424b47a0797
updated for version 7.0003
author | vimboss |
---|---|
date | Wed, 30 Jun 2004 16:16:41 +0000 |
parents | |
children | 4ac1dce8dd5e |
comparison
equal
deleted
inserted
replaced
10:4e2284e71352 | 11:4424b47a0797 |
---|---|
1 /* vi:set ts=8 sts=0 sw=8: | |
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 #include <assert.h> | |
21 #include <errno.h> | |
22 #include <string.h> | |
23 #include <kmenubar.h> | |
24 #include <kfiledialog.h> | |
25 #include <kiconloader.h> | |
26 | |
27 #include <qscrollbar.h> | |
28 #include <qcursor.h> | |
29 #include <qmessagebox.h> | |
30 #include <qiconset.h> | |
31 #include <qtextcodec.h> | |
32 #include "gui_kde_widget.h" | |
33 | |
34 extern "C" { | |
35 #include "vim.h" | |
36 } | |
37 | |
38 #undef dbf | |
39 #undef db | |
40 #undef mputs | |
41 | |
42 #if 1 | |
43 #define dbf( format, args... ) { printf( "%s" " : " format "\n" , __FUNCTION__ , ## args ); fflush(stdout); } | |
44 #define db() { printf( "%s\n", __FUNCTION__ );fflush(stdout); } | |
45 #else | |
46 #define dbf(format, args... ) | |
47 #define db() | |
48 #endif | |
49 | |
50 | |
51 #ifdef FEAT_TOOLBAR | |
52 #ifndef FEAT_KDETOOLBAR | |
53 /* | |
54 * Icons used by the toolbar code. | |
55 *///{{{ | |
56 #include "../pixmaps/tb_new.xpm" | |
57 #include "../pixmaps/tb_open.xpm" | |
58 #include "../pixmaps/tb_close.xpm" | |
59 #include "../pixmaps/tb_save.xpm" | |
60 #include "../pixmaps/tb_print.xpm" | |
61 #include "../pixmaps/tb_cut.xpm" | |
62 #include "../pixmaps/tb_copy.xpm" | |
63 #include "../pixmaps/tb_paste.xpm" | |
64 #include "../pixmaps/tb_find.xpm" | |
65 #include "../pixmaps/tb_find_next.xpm" | |
66 #include "../pixmaps/tb_find_prev.xpm" | |
67 #include "../pixmaps/tb_find_help.xpm" | |
68 #include "../pixmaps/tb_exit.xpm" | |
69 #include "../pixmaps/tb_undo.xpm" | |
70 #include "../pixmaps/tb_redo.xpm" | |
71 #include "../pixmaps/tb_help.xpm" | |
72 #include "../pixmaps/tb_macro.xpm" | |
73 #include "../pixmaps/tb_make.xpm" | |
74 #include "../pixmaps/tb_save_all.xpm" | |
75 #include "../pixmaps/tb_jump.xpm" | |
76 #include "../pixmaps/tb_ctags.xpm" | |
77 #include "../pixmaps/tb_load_session.xpm" | |
78 #include "../pixmaps/tb_save_session.xpm" | |
79 #include "../pixmaps/tb_new_session.xpm" | |
80 #include "../pixmaps/tb_blank.xpm" | |
81 #include "../pixmaps/tb_maximize.xpm" | |
82 #include "../pixmaps/tb_split.xpm" | |
83 #include "../pixmaps/tb_minimize.xpm" | |
84 #include "../pixmaps/tb_shell.xpm" | |
85 #include "../pixmaps/tb_replace.xpm" | |
86 #include "../pixmaps/tb_vsplit.xpm" | |
87 #include "../pixmaps/tb_maxwidth.xpm" | |
88 #include "../pixmaps/tb_minwidth.xpm" | |
89 //}}} | |
90 /* | |
91 * These are the pixmaps used for the default buttons. | |
92 * Order must exactly match toolbar_names[] in menu.c! | |
93 *///{{{ | |
94 static char **(built_in_pixmaps[]) = | |
95 { | |
96 tb_new_xpm, | |
97 tb_open_xpm, | |
98 tb_save_xpm, | |
99 tb_undo_xpm, | |
100 tb_redo_xpm, | |
101 tb_cut_xpm, | |
102 tb_copy_xpm, | |
103 tb_paste_xpm, | |
104 tb_print_xpm, | |
105 tb_help_xpm, | |
106 tb_find_xpm, | |
107 tb_save_all_xpm, | |
108 tb_save_session_xpm, | |
109 tb_new_session_xpm, | |
110 tb_load_session_xpm, | |
111 tb_macro_xpm, | |
112 tb_replace_xpm, | |
113 tb_close_xpm, | |
114 tb_maximize_xpm, | |
115 tb_minimize_xpm, | |
116 tb_split_xpm, | |
117 tb_shell_xpm, | |
118 tb_find_prev_xpm, | |
119 tb_find_next_xpm, | |
120 tb_find_help_xpm, | |
121 tb_make_xpm, | |
122 tb_jump_xpm, | |
123 tb_ctags_xpm, | |
124 tb_vsplit_xpm, | |
125 tb_maxwidth_xpm, | |
126 tb_minwidth_xpm, | |
127 tb_exit_xpm | |
128 };//}}} | |
129 #else | |
130 const char *kdeicons[] = { | |
131 "filenew", | |
132 "fileopen", | |
133 "filesave", | |
134 "undo", | |
135 "redo", | |
136 "editcut", | |
137 "editcopy", | |
138 "editpaste", | |
139 "fileprint", | |
140 "contents2", | |
141 "filefind", | |
142 "save_all", | |
143 "fileexport", | |
144 "filenew", | |
145 "fileimport", | |
146 "run", | |
147 "edit", | |
148 "fileclose", | |
149 "", | |
150 "", | |
151 "split", | |
152 "openterm", | |
153 "previous", | |
154 "next", | |
155 "help", | |
156 "make", | |
157 "goto", | |
158 "run", | |
159 "vsplit", | |
160 "maxwidth", | |
161 "minwidth", | |
162 "quit" | |
163 }; | |
164 #endif | |
165 /* | |
166 * creates a blank pixmap using tb_blank | |
167 */ | |
168 QPixmap | |
169 pixmap_create_from_xpm(char **xpm)//{{{ | |
170 { | |
171 return(QPixmap((const char **)xpm)); | |
172 }//}}} | |
173 | |
174 /* | |
175 * creates a pixmap by using a built-in number | |
176 */ | |
177 QPixmap | |
178 pixmap_create_by_num(int pixmap_num)//{{{ | |
179 { | |
180 #ifdef FEAT_KDETOOLBAR | |
181 if (pixmap_num >= 0 && (unsigned)pixmap_num < (sizeof(kdeicons) | |
182 / sizeof(kdeicons[0])) - 1) { | |
183 | |
184 KIconLoader *il = kapp->iconLoader(); //new KIconLoader(); | |
185 QString icon; | |
186 icon=QString(kdeicons[pixmap_num]); | |
187 return il->loadIcon(icon,KIcon::MainToolbar); | |
188 } | |
189 return QPixmap(); | |
190 #else | |
191 if (pixmap_num >= 0 && (unsigned)pixmap_num < (sizeof(built_in_pixmaps) | |
192 / sizeof(built_in_pixmaps[0])) - 1) | |
193 return pixmap_create_from_xpm(built_in_pixmaps[pixmap_num]); | |
194 else return QPixmap(); | |
195 #endif | |
196 }//}}} | |
197 | |
198 /* | |
199 * Creates a pixmap by using the pixmap "name" found in 'runtimepath'/bitmaps/ | |
200 */ | |
201 QPixmap | |
202 pixmap_create_by_dir(char_u *name)//{{{ | |
203 { | |
204 char_u full_pathname[MAXPATHL + 1]; | |
205 | |
206 if (gui_find_bitmap(name, full_pathname, "xpm") == OK) { | |
207 return QPixmap((const char *)full_pathname); | |
208 } | |
209 else return QPixmap(); | |
210 }//}}} | |
211 | |
212 | |
213 QPixmap | |
214 pixmap_create_from_file(char_u *file) | |
215 { | |
216 return QPixmap((const char*)file); | |
217 } | |
218 #endif | |
219 | |
220 void | |
221 gui_mch_add_menu(vimmenu_T * menu, int idx)//{{{ | |
222 { | |
223 #ifdef FEAT_MENU | |
224 QPopupMenu *me; | |
225 vimmenu_T *parent = menu->parent; | |
226 | |
227 if (menu_is_popup(menu->name)) { | |
228 menu->widget = new QPopupMenu(vmw , (const char *) menu->name); | |
229 QObject::connect( menu->widget, SIGNAL(activated(int)), vmw, SLOT(menu_activated(int)) ); | |
230 return; | |
231 } | |
232 | |
233 if (!menu_is_menubar(menu->name)) | |
234 return; | |
235 | |
236 if (parent) { | |
237 idx++; // for tearoffs to be first in menus | |
238 me = new QPopupMenu(parent->widget, (const char *) menu->name); | |
239 parent->widget->insertItem( QString((const char *)menu->name), me, (int)me, idx); | |
240 } else { | |
241 me = new QPopupMenu(vmw->menuBar() , (const char *) menu->name); | |
242 vmw->menuBar()->insertItem( QString((const char *)menu->name), me , (int) me, idx); | |
243 } | |
244 | |
245 me->setCaption((const char*)( menu->dname )); | |
246 if (vmw->have_tearoff) me->insertTearOffHandle(0,0); | |
247 QObject::connect( me, SIGNAL(activated(int)), vmw, SLOT(menu_activated(int)) ); | |
248 menu->widget = me; | |
249 #endif | |
250 }//}}} | |
251 | |
252 | |
253 void | |
254 gui_mch_add_menu_item(vimmenu_T * menu, int idx)//{{{ | |
255 { | |
256 #ifdef FEAT_MENU | |
257 vimmenu_T *parent = menu->parent; | |
258 #ifdef FEAT_TOOLBAR | |
259 if (menu_is_toolbar(parent->name)) { | |
260 QPixmap pix; | |
261 if ( menu_is_separator(menu->name) ) | |
262 { | |
263 vmw->toolBar()->insertSeparator(); | |
264 return; | |
265 } | |
266 if (menu->iconfile != NULL) { | |
267 pix = pixmap_create_from_file(menu->iconfile); | |
268 } | |
269 if (!menu->icon_builtin) { | |
270 pix = pixmap_create_by_dir(menu->name); | |
271 } | |
272 if (pix.isNull() && menu->iconidx >= 0) { | |
273 pix = pixmap_create_by_num(menu->iconidx); | |
274 } | |
275 #ifndef FEAT_KDETOOLBAR | |
276 if (pix.isNull()) { | |
277 pix = pixmap_create_from_xpm(tb_blank_xpm); | |
278 } | |
279 #endif | |
280 if (pix.isNull()) return; // failed | |
281 vmw->toolBar()->insertButton ( | |
282 pix, | |
283 (int) menu , // id | |
284 true, | |
285 (char *) (menu->strings[MENU_INDEX_TIP]) , // tooltip or text | |
286 idx | |
287 ); | |
288 menu->parent=parent; | |
289 return; | |
290 } | |
291 #endif // FEAT_TOOLBAR | |
292 | |
293 idx++; | |
294 if ( menu_is_separator(menu->name) ) { | |
295 parent->widget->insertSeparator(); | |
296 return; | |
297 } | |
298 parent->widget->insertItem(QString((const char *)menu->name), (int)menu, idx ); | |
299 #endif | |
300 }//}}} | |
301 | |
302 | |
303 void | |
304 gui_mch_set_text_area_pos(int x, int y, int w, int h)//{{{ | |
305 { | |
306 int X = 0; | |
307 int Y = 0; | |
308 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() | |
309 #if QT_VERSION>=300 | |
310 && !vmw->menuBar()->isTopLevelMenu() | |
311 #endif | |
312 ) | |
313 Y += vmw->menuBar()->height(); | |
314 #ifdef FEAT_TOOLBAR | |
315 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && | |
316 vmw->toolBar()->barPos()==KToolBar::Top) | |
317 Y += vmw->toolBar()->height(); | |
318 | |
319 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && | |
320 vmw->toolBar()->barPos()==KToolBar::Left) | |
321 X += vmw->toolBar()->width(); | |
322 #endif // FEAT_TOOLBAR | |
323 | |
324 gui.w->setGeometry(x+X,y+Y,w,h); | |
325 }//}}} | |
326 | |
327 | |
328 #if defined(FEAT_MENU) || defined(PROTO) | |
329 /* | |
330 * Enable or disable mnemonics for the toplevel menus. | |
331 */ | |
332 void | |
333 gui_gtk_set_mnemonics(int enable)//{{{ // TO BE REMOVED | |
334 { | |
335 }//}}} | |
336 | |
337 void | |
338 toggle_tearoffs(vimmenu_T *menu, int enable)//{{{ | |
339 { | |
340 while (menu != NULL) { | |
341 if (!menu_is_popup(menu->name)) { | |
342 if (menu->widget != 0) { | |
343 if (enable) menu->widget->insertTearOffHandle(0,0); | |
344 else menu->widget->removeItem(0); | |
345 } | |
346 toggle_tearoffs(menu->children, enable); | |
347 } | |
348 menu = menu->next; | |
349 } | |
350 }//}}} | |
351 | |
352 void | |
353 gui_mch_toggle_tearoffs(int enable)//{{{ | |
354 { | |
355 vmw->have_tearoff=enable; | |
356 toggle_tearoffs(root_menu, enable); | |
357 }//}}} | |
358 #endif | |
359 | |
360 | |
361 #if defined(FEAT_MENU) || defined(PROTO) | |
362 /* | |
363 * Destroy the machine specific menu widget. | |
364 */ | |
365 void | |
366 gui_mch_destroy_menu(vimmenu_T * menu)//{{{ | |
367 { | |
368 #ifdef FEAT_TOOLBAR | |
369 if (menu->parent && menu_is_toolbar(menu->parent->name)) { | |
370 vmw->toolBar()->removeItem( (int) menu ); | |
371 return; | |
372 } | |
373 #endif | |
374 if(menu->parent){ | |
375 menu->parent->widget->removeItem((int)menu ); | |
376 } | |
377 if (menu->widget){ | |
378 delete menu->widget; | |
379 } | |
380 menu->widget = 0; | |
381 }//}}} | |
382 #endif /* FEAT_MENU */ | |
383 | |
384 | |
385 /* | |
386 * Scrollbar stuff. | |
387 */ | |
388 | |
389 void | |
390 gui_mch_set_scrollbar_thumb(scrollbar_T * sb, long val, long size, long max)//{{{ | |
391 { | |
392 if (!sb->w) return; | |
393 | |
394 sb->w->setRange(0, max+1-size); | |
395 sb->w->setValue(val); | |
396 | |
397 sb->w->setLineStep(1); | |
398 sb->w->setPageStep(size); | |
399 }//}}} | |
400 | |
401 void | |
402 gui_mch_set_scrollbar_pos(scrollbar_T * sb, int x, int y, int w, int h)//{{{ | |
403 { | |
404 if (!sb->w) return; | |
405 //we add the menubar and toolbar height/width | |
406 int X = 0; | |
407 int Y = 0; | |
408 | |
409 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() | |
410 #if QT_VERSION>=300 | |
411 && !vmw->menuBar()->isTopLevelMenu() | |
412 #endif | |
413 ) | |
414 Y += vmw->menuBar()->height(); | |
415 #ifdef FEAT_TOOLBAR | |
416 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && | |
417 vmw->toolBar()->barPos()==KToolBar::Top) | |
418 Y += vmw->toolBar()->height(); | |
419 | |
420 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && | |
421 vmw->toolBar()->barPos()==KToolBar::Left) | |
422 X += vmw->toolBar()->width(); | |
423 #endif //FEAT_TOOLBAR | |
424 if (sb->w->orientation() == Qt::Vertical) { | |
425 bool leftscroll=gui.which_scrollbars[SBAR_LEFT]; | |
426 bool rightscroll=gui.which_scrollbars[SBAR_RIGHT]; | |
427 if (x<20) leftscroll=true; | |
428 else rightscroll=true; | |
429 if (x<20) sb->w->setGeometry(X,y+Y,w,h); | |
430 else sb->w->setGeometry(vmw->width()-w-1+X, y+Y,w,h); | |
431 } else { | |
432 sb->w->setGeometry(x+X,y+Y,w,h); | |
433 } | |
434 }//}}} | |
435 | |
436 /* SBAR_VERT or SBAR_HORIZ */ | |
437 void | |
438 gui_mch_create_scrollbar(scrollbar_T * sb, int orient)//{{{ | |
439 { | |
440 sbpool->create(sb,orient); | |
441 if (orient==SBAR_VERT) | |
442 gui.scrollbar_width = sb->w->sizeHint().width(); | |
443 else | |
444 gui.scrollbar_height = sb->w->sizeHint().height(); | |
445 }//}}} | |
446 | |
447 void | |
448 gui_mch_destroy_scrollbar(scrollbar_T * sb)//{{{ | |
449 { | |
450 sbpool->destroy(sb); | |
451 }//}}} | |
452 | |
453 #if defined(FEAT_BROWSE) || defined(PROTO) | |
454 /* | |
455 * Implementation of the file selector related stuff | |
456 */ | |
457 | |
458 /* | |
459 * Put up a file requester. | |
460 * Returns the selected name in allocated memory, or NULL for Cancel. | |
461 * saving, select file to write | |
462 * title title for the window | |
463 * dflt default name | |
464 * ext not used (extension added) | |
465 * initdir initial directory, NULL for current dir | |
466 * filter not used (file name filter) | |
467 */ | |
468 /*ARGSUSED*/ | |
469 char_u * | |
470 gui_mch_browse(int saving,//{{{ | |
471 char_u * title, | |
472 char_u * dflt, | |
473 char_u * ext, | |
474 char_u * initdir, | |
475 char_u * filter) | |
476 { | |
477 char * filt_glob; | |
478 if (filter != (char_u *) 0x0 ) { | |
479 filter = vim_strsave(filter); | |
480 strtok((char *) filter, "("); | |
481 filt_glob = strtok(0L, ")"); | |
482 } else | |
483 filt_glob = (char *) filter; | |
484 | |
485 gui_mch_mousehide(FALSE); | |
486 | |
487 QString s; | |
488 if (! saving) | |
489 s = KFileDialog::getOpenFileName( (char *) initdir, (char *) filt_glob, vmw, (char *) title ); | |
490 else | |
491 s = KFileDialog::getSaveFileName( ); | |
492 | |
493 if (filter) | |
494 vim_free(filter); | |
495 | |
496 if (s.isNull()) | |
497 return NULL; | |
498 QCString unistring = vmw->codec->fromUnicode(s); | |
499 char_u * s2 = (char_u *)(const char*)unistring; | |
500 if (s2) | |
501 s2 = vim_strsave( s2 ); | |
502 | |
503 return s2; | |
504 }//}}} | |
505 | |
506 #endif /* FEAT_BROWSE */ | |
507 | |
508 #ifdef FEAT_GUI_DIALOG | |
509 | |
510 /* ARGSUSED */ | |
511 int | |
512 gui_mch_dialog(int type, /* type of dialog *///{{{ | |
513 char_u * title, /* title of dialog */ | |
514 char_u * message, /* message text */ | |
515 char_u * buttons, /* names of buttons */ | |
516 int def_but, /* default button */ | |
517 char_u *textfield) | |
518 { | |
519 gui_mch_mousehide(FALSE); | |
520 VimDialog vd(type, title, message, buttons, def_but,textfield); | |
521 int ret = vd.exec(); | |
522 return ret; | |
523 }//}}} | |
524 | |
525 | |
526 #endif /* FEAT_GUI_DIALOG */ | |
527 | |
528 #if defined(FEAT_MENU) || defined(PROTO) | |
529 void | |
530 gui_mch_show_popupmenu(vimmenu_T * menu)//{{{ | |
531 { | |
532 menu->widget->popup(QCursor::pos()); | |
533 }//}}} | |
534 | |
535 void | |
536 gui_make_popup (char_u *pathname) {//{{{ | |
537 vimmenu_T *menu = gui_find_menu(pathname); | |
538 | |
539 if (menu != NULL) { | |
540 menu->widget->popup(QCursor::pos()); | |
541 } | |
542 }//}}} | |
543 #endif | |
544 | |
545 | |
546 | |
547 /* Find and Replace implementations */ | |
548 void | |
549 gui_mch_find_dialog(exarg_T * eap)//{{{ | |
550 { | |
551 // char_u* entry_text; | |
552 //int exact_word=FALSE; | |
553 // entry_text = get_find_dialog_text(eap->arg,&exact_word); | |
554 | |
555 vmw->finddlg->setCaseSensitive(true); | |
556 | |
557 /* if(entry_text!=NULL) { | |
558 vmw->finddlg->setText(QString((char*)entry_text)); | |
559 // exact match should go there, hopefully KDE old KEdFind/KEdReplace will be replaced in KDE 4 as pple wanted KDE 3's Find/Replace to be kept | |
560 }*/ // Don't use it, KDE keeps old search in memory and vim give \\Csearch, which is difficult to handle | |
561 // vim_free(entry_text); | |
562 | |
563 vmw->finddlg->show(); | |
564 }//}}} | |
565 | |
566 void | |
567 gui_mch_replace_dialog(exarg_T * eap)//{{{ | |
568 { | |
569 // char_u* entry_text; | |
570 //int exact_word=FALSE; | |
571 | |
572 // entry_text = get_find_dialog_text(eap->arg,&exact_word); | |
573 | |
574 /* if(entry_text!=NULL) { | |
575 vmw->repldlg->setText(QString((char*)entry_text)); | |
576 // exact match should go there, hopefully KDE old KEdFind/KEdReplace will be replaced in KDE 4 as pple wanted KDE 3's Find/Replace to be kept | |
577 }*/ | |
578 //vim_free(entry_text); | |
579 | |
580 vmw->repldlg->show(); | |
581 }//}}} | |
582 | |
583 void | |
584 ex_helpfind(exarg_T *eap)//{{{ | |
585 { | |
586 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp"); | |
587 }//}}} |