blob: 4b88e98d49c9cb657fa1573b2eb9be2a486ad431 [file] [log] [blame]
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00001/* vi:set ts=8 sts=4 sw=4:
Bram Moolenaar843ee412004-06-30 16:16:41 +00002 *
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
Bram Moolenaar582fd852005-03-28 20:58:01 +000015 * kde-related coding. (URL currently doesn't work...)
Bram Moolenaar843ee412004-06-30 16:16:41 +000016 *
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>
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000032#include "gui_kde_wid.h"
Bram Moolenaar843ee412004-06-30 16:16:41 +000033
34extern "C" {
35#include "vim.h"
36}
37
38#undef dbf
39#undef db
40#undef mputs
41
42#if 1
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000043#define dbf(format, args...) { printf("%s" " : " format "\n" , __FUNCTION__ , ## args ); fflush(stdout); }
44#define db() { printf("%s\n", __FUNCTION__ );fflush(stdout); }
Bram Moolenaar843ee412004-06-30 16:16:41 +000045#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 *///{{{
94static 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
130const 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 */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000168 QPixmap
Bram Moolenaar843ee412004-06-30 16:16:41 +0000169pixmap_create_from_xpm(char **xpm)//{{{
170{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000171 return (QPixmap((const char **)xpm));
Bram Moolenaar843ee412004-06-30 16:16:41 +0000172}//}}}
173
174/*
175 * creates a pixmap by using a built-in number
176 */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000177 QPixmap
Bram Moolenaar843ee412004-06-30 16:16:41 +0000178pixmap_create_by_num(int pixmap_num)//{{{
179{
180#ifdef FEAT_KDETOOLBAR
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000181 if (pixmap_num >= 0 && (unsigned)pixmap_num < (sizeof(kdeicons)
182 / sizeof(kdeicons[0])) - 1)
183 {
Bram Moolenaar843ee412004-06-30 16:16:41 +0000184
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000185 KIconLoader *il = kapp->iconLoader(); //new KIconLoader();
186 QString icon;
187 icon = QString(kdeicons[pixmap_num]);
188 return il->loadIcon(icon, KIcon::MainToolbar);
189 }
190 return QPixmap();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000191#else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000192 if (pixmap_num >= 0 && (unsigned)pixmap_num < (sizeof(built_in_pixmaps)
193 / sizeof(built_in_pixmaps[0])) - 1)
194 return pixmap_create_from_xpm(built_in_pixmaps[pixmap_num]);
195 else
196 return QPixmap();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000197#endif
198}//}}}
199
200/*
201 * Creates a pixmap by using the pixmap "name" found in 'runtimepath'/bitmaps/
202 */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000203 QPixmap
Bram Moolenaar843ee412004-06-30 16:16:41 +0000204pixmap_create_by_dir(char_u *name)//{{{
205{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000206 char_u full_pathname[MAXPATHL + 1];
Bram Moolenaar843ee412004-06-30 16:16:41 +0000207
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000208 if (gui_find_bitmap(name, full_pathname, "xpm") == OK)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000209 return QPixmap((const char *)full_pathname);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000210 else
211 return QPixmap();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000212}//}}}
213
214
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000215 QPixmap
Bram Moolenaar843ee412004-06-30 16:16:41 +0000216pixmap_create_from_file(char_u *file)
217{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000218 return QPixmap((const char *)file);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000219}
220#endif
221
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000222 void
Bram Moolenaar81695252004-12-29 20:58:21 +0000223gui_mch_add_menu(vimmenu_T *menu, int idx)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000224{
225#ifdef FEAT_MENU
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000226 QPopupMenu *me;
227 vimmenu_T *parent = menu->parent;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000228
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000229 if (menu_is_popup(menu->name))
230 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000231 menu->widget = new QPopupMenu(vmw , QSTR(menu->name));
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000232 QObject::connect(menu->widget, SIGNAL(activated(int)), vmw,
233 SLOT(menu_activated(int)));
234 return;
235 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000236
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000237 if (!menu_is_menubar(menu->name))
238 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000239
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000240 if (parent)
241 {
242 idx++; // for tearoffs to be first in menus
Bram Moolenaar81695252004-12-29 20:58:21 +0000243 me = new QPopupMenu(parent->widget, QSTR(menu->name));
Bram Moolenaar12805862005-01-05 22:16:17 +0000244 parent->widget->insertItem(QSTR(menu->name), me, (long)me, idx);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000245 }
246 else
247 {
Bram Moolenaar81695252004-12-29 20:58:21 +0000248 me = new QPopupMenu(vmw->menuBar(), QSTR(menu->name));
Bram Moolenaar12805862005-01-05 22:16:17 +0000249 vmw->menuBar()->insertItem(QSTR(menu->name), me, (long)me, idx);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000250 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000251
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000252 me->setCaption((const char *)(menu->dname));
253 if (vmw->have_tearoff)
254 me->insertTearOffHandle(0, 0);
255 QObject::connect(me, SIGNAL(activated(int)), vmw,
256 SLOT(menu_activated(int)));
257 menu->widget = me;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000258#endif
259}//}}}
260
261
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000262 void
Bram Moolenaar81695252004-12-29 20:58:21 +0000263gui_mch_add_menu_item(vimmenu_T *menu, int idx)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000264{
265#ifdef FEAT_MENU
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000266 vimmenu_T *parent = menu->parent;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000267#ifdef FEAT_TOOLBAR
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000268 if (menu_is_toolbar(parent->name))
269 {
270 QPixmap pix;
271
272 if (menu_is_separator(menu->name))
273 {
274 vmw->toolBar()->insertSeparator();
275 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000276 }
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000277 if (menu->iconfile != NULL)
278 {
279 pix = pixmap_create_from_file(menu->iconfile);
280 }
281 if (!menu->icon_builtin)
282 {
283 pix = pixmap_create_by_dir(menu->name);
284 }
285 if (pix.isNull() && menu->iconidx >= 0)
286 {
287 pix = pixmap_create_by_num(menu->iconidx);
288 }
289#ifndef FEAT_KDETOOLBAR
290 if (pix.isNull())
291 {
292 pix = pixmap_create_from_xpm(tb_blank_xpm);
293 }
294#endif
295 if (pix.isNull())
296 return; // failed
297 vmw->toolBar()->insertButton(
298 pix,
Bram Moolenaar12805862005-01-05 22:16:17 +0000299 (long)menu, // id
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000300 true,
Bram Moolenaar81695252004-12-29 20:58:21 +0000301 QSTR(menu->strings[MENU_INDEX_TIP]), // tooltip or text
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000302 idx);
303 menu->parent=parent;
304 return;
305 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000306#endif // FEAT_TOOLBAR
307
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000308 idx++;
309 if (menu_is_separator(menu->name))
310 {
311 parent->widget->insertSeparator();
312 return;
313 }
Bram Moolenaar12805862005-01-05 22:16:17 +0000314 parent->widget->insertItem(QSTR(menu->name), (long)menu, idx);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000315#endif
316}//}}}
317
318
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000319 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000320gui_mch_set_text_area_pos(int x, int y, int w, int h)//{{{
321{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000322 int X = 0;
323 int Y = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000324
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000325 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
326#if QT_VERSION>=300
327 && !vmw->menuBar()->isTopLevelMenu()
328#endif
329 )
330 Y += vmw->menuBar()->height();
331#ifdef FEAT_TOOLBAR
332 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
333 && vmw->toolBar()->barPos()==KToolBar::Top)
334 Y += vmw->toolBar()->height();
335
336 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
337 && vmw->toolBar()->barPos()==KToolBar::Left)
338 X += vmw->toolBar()->width();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000339#endif // FEAT_TOOLBAR
340
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000341 gui.w->setGeometry(x + X, y + Y, w, h);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000342}//}}}
343
344
345#if defined(FEAT_MENU) || defined(PROTO)
346/*
347 * Enable or disable mnemonics for the toplevel menus.
348 */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000349 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000350gui_gtk_set_mnemonics(int enable)//{{{ // TO BE REMOVED
351{
352}//}}}
353
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000354 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000355toggle_tearoffs(vimmenu_T *menu, int enable)//{{{
356{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000357 while (menu != NULL)
358 {
359 if (!menu_is_popup(menu->name))
360 {
361 if (menu->widget != 0)
362 {
363 if (enable)
364 menu->widget->insertTearOffHandle(0,0);
365 else
366 menu->widget->removeItem(0);
367 }
368 toggle_tearoffs(menu->children, enable);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000369 }
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000370 menu = menu->next;
371 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000372}//}}}
373
374 void
375gui_mch_toggle_tearoffs(int enable)//{{{
376{
Bram Moolenaar81695252004-12-29 20:58:21 +0000377 vmw->have_tearoff=enable;
378 toggle_tearoffs(root_menu, enable);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000379}//}}}
380#endif
381
382
383#if defined(FEAT_MENU) || defined(PROTO)
384/*
385 * Destroy the machine specific menu widget.
386 */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000387 void
Bram Moolenaar81695252004-12-29 20:58:21 +0000388gui_mch_destroy_menu(vimmenu_T *menu)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000389{
390#ifdef FEAT_TOOLBAR
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000391 if (menu->parent && menu_is_toolbar(menu->parent->name))
392 {
Bram Moolenaar12805862005-01-05 22:16:17 +0000393 vmw->toolBar()->removeItem((long)menu);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000394 return;
395 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000396#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000397 if (menu->parent)
Bram Moolenaar12805862005-01-05 22:16:17 +0000398 menu->parent->widget->removeItem((long)menu);
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000399 if (menu->widget)
400 delete menu->widget;
401 menu->widget = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000402}//}}}
403#endif /* FEAT_MENU */
404
405
406/*
407 * Scrollbar stuff.
408 */
409
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000410 void
411gui_mch_set_scrollbar_thumb(scrollbar_T *sb, long val, long size, long max)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000412{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000413 if (!sb->w)
414 return;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000415
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000416 sb->w->setRange(0, max + 1 - size);
417 sb->w->setValue(val);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000418
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000419 sb->w->setLineStep(1);
420 sb->w->setPageStep(size);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000421}//}}}
422
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000423 void
424gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000425{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000426 if (!sb->w)
427 return;
Bram Moolenaar81695252004-12-29 20:58:21 +0000428
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000429 //we add the menubar and toolbar height/width
430 int X = 0;
431 int Y = 0;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000432
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000433 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000434#if QT_VERSION>=300
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000435 && !vmw->menuBar()->isTopLevelMenu()
Bram Moolenaar843ee412004-06-30 16:16:41 +0000436#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000437 )
438 Y += vmw->menuBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000439#ifdef FEAT_TOOLBAR
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000440 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
441 && vmw->toolBar()->barPos()==KToolBar::Top)
442 Y += vmw->toolBar()->height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000443
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000444 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled()
445 && vmw->toolBar()->barPos()==KToolBar::Left)
446 X += vmw->toolBar()->width();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000447#endif //FEAT_TOOLBAR
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000448 if (sb->w->orientation() == Qt::Vertical)
449 {
450 bool leftscroll=gui.which_scrollbars[SBAR_LEFT];
451 bool rightscroll=gui.which_scrollbars[SBAR_RIGHT];
452
453 if (x < 20)
454 leftscroll = true;
455 else
456 rightscroll = true;
457 if (x < 20)
458 sb->w->setGeometry(X, y+Y, w, h);
459 else
460 sb->w->setGeometry(vmw->width() - w - 1 + X, y + Y, w, h);
461 }
462 else
463 {
464 sb->w->setGeometry(x + X, y + Y, w, h);
465 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000466}//}}}
467
468/* SBAR_VERT or SBAR_HORIZ */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000469 void
470gui_mch_create_scrollbar(scrollbar_T *sb, int orient)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000471{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000472 sbpool->create(sb,orient);
473 if (orient == SBAR_VERT)
474 gui.scrollbar_width = sb->w->sizeHint().width();
475 else
476 gui.scrollbar_height = sb->w->sizeHint().height();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000477}//}}}
478
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000479 void
Bram Moolenaar81695252004-12-29 20:58:21 +0000480gui_mch_destroy_scrollbar(scrollbar_T *sb)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000481{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000482 sbpool->destroy(sb);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000483}//}}}
484
485#if defined(FEAT_BROWSE) || defined(PROTO)
486/*
487 * Implementation of the file selector related stuff
488 */
489
490/*
Bram Moolenaardef9e822004-12-31 20:58:58 +0000491 * Convert the Vim-style filter specification 's' to the KDE-style
492 * filter specification.
493 * Vim-style: {label}\t{pattern1};{pattern2}\n
494 * KDE-style: {pattern1} {pattern2}|{label}\n
495 *
496 * The newly constructed filter is returned in allocated memory and
497 * must be freed by the calling program.
498 */
499 static char *
500convert_filter(char_u *s)
501{
502 char *res;
503 unsigned i;
504 unsigned pattern_len;
505 char *filter_label;
506 char *filter_pattern;
507
508 // The conversion generates a string of equal length to the original
509 // pattern, so allocate enough memory to hold the original string.
510 res = new char[STRLEN(s) + 1];
511 s = vim_strsave(s);
512 if (res != NULL && s != NULL)
513 {
514 // Make sure the first byte is a NUL so that strcat()
515 // will append at the beginning of the string.
516 res[0] = '\0';
517 filter_label = strtok((char *) s, "\t");
518 while (filter_label != NULL)
519 {
520 filter_pattern = strtok( 0L, "\n");
521 if (filter_pattern != NULL)
522 {
523 pattern_len = (unsigned) STRLEN(filter_pattern);
524 for (i = 0; i < pattern_len; ++i)
525 if (filter_pattern[i] == ';')
526 filter_pattern[i] = ' ';
527
528 strcat(res, filter_pattern);
529 strcat(res, "|");
530 strcat(res, filter_label);
531 strcat(res, "\n");
532 }
533 filter_label = strtok(0L, "\t");
534 }
535 }
536 if (s)
537 vim_free(s);
538 return res;
539}
540
541/*
Bram Moolenaar843ee412004-06-30 16:16:41 +0000542 * Put up a file requester.
543 * Returns the selected name in allocated memory, or NULL for Cancel.
544 * saving, select file to write
545 * title title for the window
546 * dflt default name
547 * ext not used (extension added)
548 * initdir initial directory, NULL for current dir
549 * filter not used (file name filter)
550 */
551/*ARGSUSED*/
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000552 char_u *
Bram Moolenaar843ee412004-06-30 16:16:41 +0000553gui_mch_browse(int saving,//{{{
Bram Moolenaar81695252004-12-29 20:58:21 +0000554 char_u *title,
555 char_u *dflt,
556 char_u *ext,
557 char_u *initdir,
558 char_u *filter)
Bram Moolenaar843ee412004-06-30 16:16:41 +0000559{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000560 char *filt_glob;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000561
Bram Moolenaardef9e822004-12-31 20:58:58 +0000562 filt_glob = convert_filter(filter);
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000563
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000564 gui_mch_mousehide(FALSE);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000565
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000566 QString s;
567 if (!saving)
Bram Moolenaar81695252004-12-29 20:58:21 +0000568 s = KFileDialog::getOpenFileName(QSTR(initdir), QSTR(filt_glob),
569 vmw, QSTR(title));
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000570 else
571 s = KFileDialog::getSaveFileName();
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000572
Bram Moolenaardef9e822004-12-31 20:58:58 +0000573 if (filt_glob)
574 delete filt_glob;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000575
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000576 if (s.isNull())
577 return NULL;
578 QCString unistring = vmw->codec->fromUnicode(s);
579 char_u *s2 = (char_u *)(const char *)unistring;
580 if (s2)
581 s2 = vim_strsave(s2);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000582
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000583 return s2;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000584}//}}}
585
586#endif /* FEAT_BROWSE */
587
588#ifdef FEAT_GUI_DIALOG
589
590/* ARGSUSED */
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000591 int
Bram Moolenaar843ee412004-06-30 16:16:41 +0000592gui_mch_dialog(int type, /* type of dialog *///{{{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000593 char_u *title, /* title of dialog */
594 char_u *message, /* message text */
595 char_u *buttons, /* names of buttons */
Bram Moolenaar81695252004-12-29 20:58:21 +0000596 int def_but, /* default button */
Bram Moolenaar843ee412004-06-30 16:16:41 +0000597 char_u *textfield)
598{
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000599 gui_mch_mousehide(FALSE);
600 VimDialog vd(type, title, message, buttons, def_but,textfield);
601 int ret = vd.exec();
602 return ret;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000603}//}}}
604
605
606#endif /* FEAT_GUI_DIALOG */
607
608#if defined(FEAT_MENU) || defined(PROTO)
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000609 void
Bram Moolenaar81695252004-12-29 20:58:21 +0000610gui_mch_show_popupmenu(vimmenu_T *menu)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000611{
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000612 menu->widget->popup(QCursor::pos());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000613}//}}}
614
Bram Moolenaar97409f12005-07-08 22:17:29 +0000615/* TODO: use mouse_pos */
Bram Moolenaar843ee412004-06-30 16:16:41 +0000616void
Bram Moolenaar97409f12005-07-08 22:17:29 +0000617gui_make_popup (char_u *pathname, int mouse_pos)//{{{
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000618{
619 vimmenu_T *menu = gui_find_menu(pathname);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000620
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000621 if (menu != NULL)
622 menu->widget->popup(QCursor::pos());
Bram Moolenaar843ee412004-06-30 16:16:41 +0000623}//}}}
624#endif
625
626
627
628/* Find and Replace implementations */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000629 void
630gui_mch_find_dialog(exarg_T *eap)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000631{
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000632 // char_u* entry_text;
633 //int exact_word=FALSE;
634 // entry_text = get_find_dialog_text(eap->arg,&exact_word);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000635
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000636 vmw->finddlg->setCaseSensitive(true);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000637
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000638 /* if (entry_text!=NULL)
639 * {
640 vmw->finddlg->setText(QString((char *)entry_text));
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000641 // 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
642 }*/ // Don't use it, KDE keeps old search in memory and vim give \\Csearch, which is difficult to handle
643 // vim_free(entry_text);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000644
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +0000645 vmw->finddlg->show();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000646}//}}}
647
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000648 void
649gui_mch_replace_dialog(exarg_T *eap)//{{{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000650{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000651 // char_u* entry_text;
652 //int exact_word=FALSE;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000653
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000654 // entry_text = get_find_dialog_text(eap->arg,&exact_word);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000655
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000656 /* if (entry_text!=NULL)
657 * {
658 vmw->repldlg->setText(QString((char *)entry_text));
659 // 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
660 }*/
661 //vim_free(entry_text);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000662
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000663 vmw->repldlg->show();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000664}//}}}
665
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000666 void
Bram Moolenaar843ee412004-06-30 16:16:41 +0000667ex_helpfind(exarg_T *eap)//{{{
668{
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000669 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp");
Bram Moolenaar843ee412004-06-30 16:16:41 +0000670}//}}}