diff options
author | Bram Moolenaar <Bram@vim.org> | 2004-12-29 20:58:21 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2004-12-29 20:58:21 +0000 |
commit | 81695250ef1bbc02016078044ac268129a33f333 (patch) | |
tree | c31ec7182b5b06ffeb5a14b79701127eaa5c0dc8 /src | |
parent | 86b68359978c933419279e599d0a8cf536095d77 (diff) | |
download | vim-git-81695250ef1bbc02016078044ac268129a33f333.tar.gz |
updated for version 7.0026
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/buffer.c | 47 | ||||
-rw-r--r-- | src/charset.c | 4 | ||||
-rw-r--r-- | src/configure.in | 4 | ||||
-rw-r--r-- | src/ex_docmd.c | 27 | ||||
-rw-r--r-- | src/ex_getln.c | 3 | ||||
-rw-r--r-- | src/feature.h | 5 | ||||
-rw-r--r-- | src/globals.h | 1 | ||||
-rw-r--r-- | src/gui.c | 10 | ||||
-rw-r--r-- | src/gui_kde.cc | 49 | ||||
-rw-r--r-- | src/gui_kde_wid.cc | 886 | ||||
-rw-r--r-- | src/gui_kde_wid.h | 85 | ||||
-rw-r--r-- | src/gui_kde_x11.cc | 1471 | ||||
-rw-r--r-- | src/mbyte.c | 10 | ||||
-rw-r--r-- | src/os_unix.c | 9 | ||||
-rw-r--r-- | src/proto/buffer.pro | 3 | ||||
-rw-r--r-- | src/proto/gui_kde_x11.pro | 1 | ||||
-rw-r--r-- | src/quickfix.c | 213 | ||||
-rw-r--r-- | src/screen.c | 4 | ||||
-rw-r--r-- | src/version.h | 4 | ||||
-rw-r--r-- | src/vim.h | 1 |
21 files changed, 1682 insertions, 1157 deletions
diff --git a/src/Makefile b/src/Makefile index 4a676c240..9b21a2e76 100644 --- a/src/Makefile +++ b/src/Makefile @@ -335,6 +335,8 @@ CClink = $(CC) # automatically be used if it is found. If you have GNOME, but do not want to # use it (e.g., want a GTK-only version), then use --enable-gui=gtk. # +# KDE doesn't fully work, unfortunately. See the todo list. +# # If the selected GUI isn't found, the GUI is disabled automatically #CONF_OPT_GUI = --enable-gui=gtk #CONF_OPT_GUI = --enable-gui=gtk --disable-gtktest diff --git a/src/buffer.c b/src/buffer.c index 1ed7a0055..bb58685de 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1641,6 +1641,8 @@ buflist_new(ffname, sfname, lnum, flags) #endif buf->b_u_synced = TRUE; buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; + if (flags & BLN_DUMMY) + buf->b_flags |= BF_DUMMY; buf_clear_file(buf); clrallmarks(buf); /* clear marks */ fmarks_check_names(buf); /* check file marks for this file */ @@ -1874,9 +1876,40 @@ buflist_getfpos() } } +#if defined(FEAT_QUICKFIX) || defined(FEAT_EVAL) || defined(PROTO) +/* + * Find file in buffer list by name (it has to be for the current window). + * Returns NULL if not found. + */ + buf_T * +buflist_findname_exp(fname) + char_u *fname; +{ + char_u *ffname; + buf_T *buf = NULL; + + /* First make the name into a full path name */ + ffname = FullName_save(fname, +#ifdef UNIX + TRUE /* force expansion, get rid of symbolic links */ +#else + FALSE +#endif + ); + if (ffname != NULL) + { + buf = buflist_findname(ffname); + vim_free(ffname); + } + return buf; +} +#endif + /* * Find file in buffer list by name (it has to be for the current window). * "ffname" must have a full path. + * Skips dummy buffers. + * Returns NULL if not found. */ buf_T * buflist_findname(ffname) @@ -1893,6 +1926,7 @@ buflist_findname(ffname) /* * Same as buflist_findname(), but pass the stat structure to avoid getting it * twice for the same file. + * Returns NULL if not found. */ static buf_T * buflist_findname_stat(ffname, stp) @@ -1903,7 +1937,7 @@ buflist_findname_stat(ffname, stp) buf_T *buf; for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (!otherfile_buf(buf, ffname + if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname #ifdef UNIX , stp #endif @@ -2457,9 +2491,9 @@ buflist_name_nr(fnum, fname, lnum) setfname(buf, ffname, sfname, message) buf_T *buf; char_u *ffname, *sfname; - int message; + int message; /* give message when buffer already exists */ { - buf_T *obuf; + buf_T *obuf = NULL; #ifdef UNIX struct stat st; #endif @@ -2489,9 +2523,12 @@ setfname(buf, ffname, sfname, message) #ifdef UNIX if (mch_stat((char *)ffname, &st) < 0) st.st_dev = (dev_T)-1; - obuf = buflist_findname_stat(ffname, &st); +#endif + if (!(buf->b_flags & BF_DUMMY)) +#ifdef UNIX + obuf = buflist_findname_stat(ffname, &st); #else - obuf = buflist_findname(ffname); + obuf = buflist_findname(ffname); #endif if (obuf != NULL && obuf != buf) { diff --git a/src/charset.c b/src/charset.c index 0a46306fc..7d01980bd 100644 --- a/src/charset.c +++ b/src/charset.c @@ -820,8 +820,8 @@ win_linetabsize(wp, p, len) } /* - * return TRUE if 'c' is a normal identifier character - * letters and characters from 'isident' option. + * Return TRUE if 'c' is a normal identifier character: + * Letters and characters from the 'isident' option. */ int vim_isIDc(c) diff --git a/src/configure.in b/src/configure.in index f2fdcd1d8..16bbf1328 100644 --- a/src/configure.in +++ b/src/configure.in @@ -2153,6 +2153,10 @@ if test "x$GUITYPE:$enable_fontset" = "xGTK:yes" -a "0$gtk_major_version" -ge 2; AC_MSG_RESULT(GTK+ 2 GUI selected; fontset has been disabled) enable_fontset="no" fi +if test "x$GUITYPE:$enable_fontset" = "xKDE:yes"; then + AC_MSG_RESULT(KDE GUI selected; fontset has been disabled) + enable_fontset="no" +fi dnl There is no test for the BeOS GUI, if it's selected it's used if test -z "$SKIP_BEOS"; then diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 3e5870bb9..3304167f1 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2114,7 +2114,7 @@ do_one_cmd(cmdlinep, sourcing, */ if ((ea.cmdidx == CMD_make || ea.cmdidx == CMD_grep || ea.cmdidx == CMD_grepadd) - && !grep_internal(&ea)) + && !grep_internal(ea.cmdidx)) { char_u *new_cmdline; char_u *program; @@ -3164,7 +3164,13 @@ set_one_cmd_context(xp, buff) p++; xp->xp_pattern = p; - if (argt & XFILE) + if ((argt & XFILE) +#ifdef FEAT_QUICKFIX + || cmdidx == CMD_vimgrep + || cmdidx == CMD_vimgrepadd + || grep_internal(cmdidx) +#endif + ) { int in_quote = FALSE; char_u *bow = NULL; /* Beginning of word */ @@ -4204,14 +4210,19 @@ separate_nextcmd(eap) p = eap->arg; #ifdef FEAT_QUICKFIX - if (eap->cmdidx == CMD_vimgrep - || eap->cmdidx == CMD_vimgrepadd - || grep_internal(eap)) + if (*p != NUL && (eap->cmdidx == CMD_vimgrep + || eap->cmdidx == CMD_vimgrepadd + || grep_internal(eap->cmdidx))) { /* Skip over the pattern. */ - p = skip_regexp(p + 1, *p, TRUE, NULL); - if (*p == *eap->arg) - ++p; + if (vim_isIDc(*p)) + p = skiptowhite(p); + else + { + p = skip_regexp(p + 1, *p, TRUE, NULL); + if (*p == *eap->arg) + ++p; + } } #endif diff --git a/src/ex_getln.c b/src/ex_getln.c index 103bf1b30..235e29e0b 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -2080,7 +2080,8 @@ cmdline_at_end() } #endif -#if (defined(FEAT_XIM) && defined(FEAT_GUI_GTK)) || defined(PROTO) +#if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE))) \ + || defined(PROTO) /* * Return the virtual column number at the current cursor position. * This is used by the IM code to obtain the start of the preedit string. diff --git a/src/feature.h b/src/feature.h index 928234c68..7e4ddd52b 100644 --- a/src/feature.h +++ b/src/feature.h @@ -650,7 +650,8 @@ * +xfontset X fontset support. For outputting wide characters. */ #ifndef FEAT_XFONTSET -# if defined(FEAT_MBYTE) && defined(HAVE_X11) && !defined(HAVE_GTK2) +# if defined(FEAT_MBYTE) && defined(HAVE_X11) \ + && !defined(HAVE_GTK2) && !defined(FEAT_GUI_KDE) # define FEAT_XFONTSET # else /* # define FEAT_XFONTSET */ @@ -1172,7 +1173,7 @@ || defined(FEAT_NETBEANS_INTG)) # define FEAT_BEVAL # if !defined(FEAT_XFONTSET) && !defined(FEAT_GUI_GTK) \ - && !defined(FEAT_GUI_W32) + && !defined(FEAT_GUI_KDE) && !defined(FEAT_GUI_W32) # define FEAT_XFONTSET # endif #endif diff --git a/src/globals.h b/src/globals.h index 7e78e8ef6..97e2f90cd 100644 --- a/src/globals.h +++ b/src/globals.h @@ -725,6 +725,7 @@ EXTERN int* (*iconv_errno) (void); #ifdef FEAT_XIM # ifdef FEAT_GUI_KDE EXTERN colnr_T preedit_start_col INIT(= MAXCOL); +EXTERN colnr_T preedit_end_col INIT(= MAXCOL); EXTERN char *draw_feedback INIT(= NULL); # endif # ifdef FEAT_GUI_GTK @@ -1918,7 +1918,7 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) long_u hl_mask_todo; guicolor_T fg_color; guicolor_T bg_color; -#if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2) +#if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2) && !defined(FEAT_GUI_KDE) GuiFont font = NOFONT; # ifdef FEAT_XFONTSET GuiFontset fontset = NOFONTSET; @@ -1972,7 +1972,7 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) highlight_mask = gui.highlight_mask; hl_mask_todo = highlight_mask; -#if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2) +#if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2) && !defined(FEAT_GUI_KDE) /* Set the font */ if (aep != NULL && aep->ae_u.gui.font != NOFONT) font = aep->ae_u.gui.font; @@ -2148,7 +2148,7 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) /* print the string so far if it's the last character or there is * a composing character. */ if (i + cl >= len || (comping && i > start) || dowide -# if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined (FEAT_GUI_KDE) +# if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) || (cn > 1 # ifdef FEAT_XFONTSET /* No fontset: At least draw char after wide char at @@ -2173,10 +2173,14 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) cells = 0; if (dowide) { +#ifndef FEAT_GUI_KDE gui_mch_set_font(gui.wide_font); +#endif gui_mch_draw_string(gui.row, scol - cn, s + start, cl, draw_flags); +#ifndef FEAT_GUI_KDE gui_mch_set_font(font); +#endif start += cl; } diff --git a/src/gui_kde.cc b/src/gui_kde.cc index 1ac8db990..62c4ba61a 100644 --- a/src/gui_kde.cc +++ b/src/gui_kde.cc @@ -206,9 +206,7 @@ pixmap_create_by_dir(char_u *name)//{{{ char_u full_pathname[MAXPATHL + 1]; if (gui_find_bitmap(name, full_pathname, "xpm") == OK) - { return QPixmap((const char *)full_pathname); - } else return QPixmap(); }//}}} @@ -222,7 +220,7 @@ pixmap_create_from_file(char_u *file) #endif void -gui_mch_add_menu(vimmenu_T * menu, int idx)//{{{ +gui_mch_add_menu(vimmenu_T *menu, int idx)//{{{ { #ifdef FEAT_MENU QPopupMenu *me; @@ -230,7 +228,7 @@ gui_mch_add_menu(vimmenu_T * menu, int idx)//{{{ if (menu_is_popup(menu->name)) { - menu->widget = new QPopupMenu(vmw , (const char *)menu->name); + menu->widget = new QPopupMenu(vmw , QSTR(menu->name)); QObject::connect(menu->widget, SIGNAL(activated(int)), vmw, SLOT(menu_activated(int))); return; @@ -242,15 +240,13 @@ gui_mch_add_menu(vimmenu_T * menu, int idx)//{{{ if (parent) { idx++; // for tearoffs to be first in menus - me = new QPopupMenu(parent->widget, (const char *)menu->name); - parent->widget->insertItem(QString((const char *)menu->name), me, - (int)me, idx); + me = new QPopupMenu(parent->widget, QSTR(menu->name)); + parent->widget->insertItem(QSTR(menu->name), me, (int)me, idx); } else { - me = new QPopupMenu(vmw->menuBar() , (const char *)menu->name); - vmw->menuBar()->insertItem(QString((const char *)menu->name), me, - (int)me, idx); + me = new QPopupMenu(vmw->menuBar(), QSTR(menu->name)); + vmw->menuBar()->insertItem(QSTR(menu->name), me, (int)me, idx); } me->setCaption((const char *)(menu->dname)); @@ -264,7 +260,7 @@ gui_mch_add_menu(vimmenu_T * menu, int idx)//{{{ void -gui_mch_add_menu_item(vimmenu_T * menu, int idx)//{{{ +gui_mch_add_menu_item(vimmenu_T *menu, int idx)//{{{ { #ifdef FEAT_MENU vimmenu_T *parent = menu->parent; @@ -302,7 +298,7 @@ gui_mch_add_menu_item(vimmenu_T * menu, int idx)//{{{ pix, (int)menu, // id true, - (char *)(menu->strings[MENU_INDEX_TIP]), // tooltip or text + QSTR(menu->strings[MENU_INDEX_TIP]), // tooltip or text idx); menu->parent=parent; return; @@ -315,7 +311,7 @@ gui_mch_add_menu_item(vimmenu_T * menu, int idx)//{{{ parent->widget->insertSeparator(); return; } - parent->widget->insertItem(QString((const char *)menu->name), (int)menu, idx); + parent->widget->insertItem(QSTR(menu->name), (int)menu, idx); #endif }//}}} @@ -378,8 +374,8 @@ toggle_tearoffs(vimmenu_T *menu, int enable)//{{{ void gui_mch_toggle_tearoffs(int enable)//{{{ { - vmw->have_tearoff=enable; - toggle_tearoffs(root_menu, enable); + vmw->have_tearoff=enable; + toggle_tearoffs(root_menu, enable); }//}}} #endif @@ -389,7 +385,7 @@ gui_mch_toggle_tearoffs(int enable)//{{{ * Destroy the machine specific menu widget. */ void -gui_mch_destroy_menu(vimmenu_T * menu)//{{{ +gui_mch_destroy_menu(vimmenu_T *menu)//{{{ { #ifdef FEAT_TOOLBAR if (menu->parent && menu_is_toolbar(menu->parent->name)) @@ -429,6 +425,7 @@ gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)//{{{ { if (!sb->w) return; + //we add the menubar and toolbar height/width int X = 0; int Y = 0; @@ -480,7 +477,7 @@ gui_mch_create_scrollbar(scrollbar_T *sb, int orient)//{{{ }//}}} void -gui_mch_destroy_scrollbar(scrollbar_T * sb)//{{{ +gui_mch_destroy_scrollbar(scrollbar_T *sb)//{{{ { sbpool->destroy(sb); }//}}} @@ -503,11 +500,11 @@ gui_mch_destroy_scrollbar(scrollbar_T * sb)//{{{ /*ARGSUSED*/ char_u * gui_mch_browse(int saving,//{{{ - char_u * title, - char_u * dflt, - char_u * ext, - char_u * initdir, - char_u * filter) + char_u *title, + char_u *dflt, + char_u *ext, + char_u *initdir, + char_u *filter) { char *filt_glob; @@ -524,8 +521,8 @@ gui_mch_browse(int saving,//{{{ QString s; if (!saving) - s = KFileDialog::getOpenFileName((char *)initdir, (char *)filt_glob, - vmw, (char *)title); + s = KFileDialog::getOpenFileName(QSTR(initdir), QSTR(filt_glob), + vmw, QSTR(title)); else s = KFileDialog::getSaveFileName(); @@ -552,7 +549,7 @@ gui_mch_dialog(int type, /* type of dialog *///{{{ char_u *title, /* title of dialog */ char_u *message, /* message text */ char_u *buttons, /* names of buttons */ - int def_but, /* default button */ + int def_but, /* default button */ char_u *textfield) { gui_mch_mousehide(FALSE); @@ -566,7 +563,7 @@ gui_mch_dialog(int type, /* type of dialog *///{{{ #if defined(FEAT_MENU) || defined(PROTO) void -gui_mch_show_popupmenu(vimmenu_T * menu)//{{{ +gui_mch_show_popupmenu(vimmenu_T *menu)//{{{ { menu->widget->popup(QCursor::pos()); }//}}} diff --git a/src/gui_kde_wid.cc b/src/gui_kde_wid.cc index fefbe9a4b..52d1c9ead 100644 --- a/src/gui_kde_wid.cc +++ b/src/gui_kde_wid.cc @@ -69,84 +69,85 @@ struct special_key {//{{{ char_u code1; } special_keys[] = { - { Qt::Key_Up, 'k', 'u' }, - { Qt::Key_Down, 'k', 'd' }, - { Qt::Key_Left, 'k', 'l' }, - { Qt::Key_Right, 'k', 'r' }, - { Qt::Key_F1, 'k', '1' }, - { Qt::Key_F2, 'k', '2' }, - { Qt::Key_F3, 'k', '3' }, - { Qt::Key_F4, 'k', '4' }, - { Qt::Key_F5, 'k', '5' }, - { Qt::Key_F6, 'k', '6' }, - { Qt::Key_F7, 'k', '7' }, - { Qt::Key_F8, 'k', '8' }, - { Qt::Key_F9, 'k', '9' }, - { Qt::Key_F10, 'k', ';' }, - { Qt::Key_F11, 'F', '1' }, - { Qt::Key_F12, 'F', '2' }, - { Qt::Key_F13, 'F', '3' }, - { Qt::Key_F14, 'F', '4' }, - { Qt::Key_F15, 'F', '5' }, - { Qt::Key_F16, 'F', '6' }, - { Qt::Key_F17, 'F', '7' }, - { Qt::Key_F18, 'F', '8' }, - { Qt::Key_F19, 'F', '9' }, - { Qt::Key_F20, 'F', 'A' }, - { Qt::Key_F21, 'F', 'B' }, - { Qt::Key_F22, 'F', 'C' }, - { Qt::Key_F23, 'F', 'D' }, - { Qt::Key_F24, 'F', 'E' }, - { Qt::Key_F25, 'F', 'F' }, - { Qt::Key_F26, 'F', 'G' }, - { Qt::Key_F27, 'F', 'H' }, - { Qt::Key_F28, 'F', 'I' }, - { Qt::Key_F29, 'F', 'J' }, - { Qt::Key_F30, 'F', 'K' }, - { Qt::Key_F31, 'F', 'L' }, - { Qt::Key_F32, 'F', 'M' }, - { Qt::Key_F33, 'F', 'N' }, - { Qt::Key_F34, 'F', 'O' }, - { Qt::Key_F35, 'F', 'P' }, - { Qt::Key_Help, '%', '1' }, - // { Qt::Key_Undo, '&', '8' }, <= hmmm ? - { Qt::Key_BackSpace, 'k', 'b' }, - { Qt::Key_Insert, KS_EXTRA, KE_KINS }, - { Qt::Key_Delete, KS_EXTRA, KE_KDEL }, - { Qt::Key_Home, 'K', '1' }, - { Qt::Key_End, 'K', '4' }, - { Qt::Key_Prior, 'K', '3' }, - { Qt::Key_Next, 'K', '5' }, - { Qt::Key_Print, '%', '9' }, - - { Qt::Key_Plus, 'K', '6'}, - { Qt::Key_Minus, 'K', '7'}, - { Qt::Key_Slash, 'K', '8'}, - { Qt::Key_multiply, 'K', '9'}, - { Qt::Key_Enter, 'K', 'A'}, - { Qt::Key_Period, 'K', 'B'}, - - { Qt::Key_0, 'K', 'C'}, - { Qt::Key_1, 'K', 'D'}, - { Qt::Key_2, 'K', 'E'}, - { Qt::Key_3, 'K', 'F'}, - { Qt::Key_4, 'K', 'G'}, - { Qt::Key_5, 'K', 'H'}, - { Qt::Key_6, 'K', 'I'}, - { Qt::Key_7, 'K', 'J'}, - { Qt::Key_8, 'K', 'K'}, - { Qt::Key_9, 'K', 'L'}, + {Qt::Key_Up, 'k', 'u'}, + {Qt::Key_Down, 'k', 'd'}, + {Qt::Key_Left, 'k', 'l'}, + {Qt::Key_Right, 'k', 'r'}, + {Qt::Key_F1, 'k', '1'}, + {Qt::Key_F2, 'k', '2'}, + {Qt::Key_F3, 'k', '3'}, + {Qt::Key_F4, 'k', '4'}, + {Qt::Key_F5, 'k', '5'}, + {Qt::Key_F6, 'k', '6'}, + {Qt::Key_F7, 'k', '7'}, + {Qt::Key_F8, 'k', '8'}, + {Qt::Key_F9, 'k', '9'}, + {Qt::Key_F10, 'k', ';'}, + {Qt::Key_F11, 'F', '1'}, + {Qt::Key_F12, 'F', '2'}, + {Qt::Key_F13, 'F', '3'}, + {Qt::Key_F14, 'F', '4'}, + {Qt::Key_F15, 'F', '5'}, + {Qt::Key_F16, 'F', '6'}, + {Qt::Key_F17, 'F', '7'}, + {Qt::Key_F18, 'F', '8'}, + {Qt::Key_F19, 'F', '9'}, + {Qt::Key_F20, 'F', 'A'}, + {Qt::Key_F21, 'F', 'B'}, + {Qt::Key_F22, 'F', 'C'}, + {Qt::Key_F23, 'F', 'D'}, + {Qt::Key_F24, 'F', 'E'}, + {Qt::Key_F25, 'F', 'F'}, + {Qt::Key_F26, 'F', 'G'}, + {Qt::Key_F27, 'F', 'H'}, + {Qt::Key_F28, 'F', 'I'}, + {Qt::Key_F29, 'F', 'J'}, + {Qt::Key_F30, 'F', 'K'}, + {Qt::Key_F31, 'F', 'L'}, + {Qt::Key_F32, 'F', 'M'}, + {Qt::Key_F33, 'F', 'N'}, + {Qt::Key_F34, 'F', 'O'}, + {Qt::Key_F35, 'F', 'P'}, + {Qt::Key_Help, '%', '1'}, + // { Qt::Key_Undo, '&', '8'}, <= hmmm ? + {Qt::Key_BackSpace, 'k', 'b'}, + {Qt::Key_Insert, KS_EXTRA, KE_KINS }, + {Qt::Key_Delete, KS_EXTRA, KE_KDEL }, + {Qt::Key_Home, 'K', '1'}, + {Qt::Key_End, 'K', '4'}, + {Qt::Key_Prior, 'K', '3'}, + {Qt::Key_Next, 'K', '5'}, + {Qt::Key_Print, '%', '9'}, + + {Qt::Key_Plus, 'K', '6'}, + {Qt::Key_Minus, 'K', '7'}, + {Qt::Key_Slash, 'K', '8'}, + {Qt::Key_multiply, 'K', '9'}, + {Qt::Key_Enter, 'K', 'A'}, + {Qt::Key_Period, 'K', 'B'}, + + {Qt::Key_0, 'K', 'C'}, + {Qt::Key_1, 'K', 'D'}, + {Qt::Key_2, 'K', 'E'}, + {Qt::Key_3, 'K', 'F'}, + {Qt::Key_4, 'K', 'G'}, + {Qt::Key_5, 'K', 'H'}, + {Qt::Key_6, 'K', 'I'}, + {Qt::Key_7, 'K', 'J'}, + {Qt::Key_8, 'K', 'K'}, + {Qt::Key_9, 'K', 'L'}, + /* End of list marker: */ - { 0, 0, 0 } + {0, 0, 0} };//}}} #ifdef FEAT_CLIENTSERVER -typedef int (*QX11EventFilter) (XEvent*); -extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter); -static QX11EventFilter oldFilter = 0; -static int kvim_x11_event_filter( XEvent* e); +typedef int (*QX11EventFilter)(XEvent*); +extern QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter); +static QX11EventFilter oldFilter = 0; +static int kvim_x11_event_filter(XEvent* e); #endif -void gui_keypress(QKeyEvent *e); +void gui_keypress(QKeyEvent *e); /* * Return OK if the key with the termcap name "name" is supported. @@ -164,26 +165,30 @@ gui_mch_haskey(char_u * name)//{{{ /* * custom Frame for drawing ... */ -void VimWidget::paintEvent(QPaintEvent *e)//{{{ + void +VimWidget::paintEvent(QPaintEvent *e)//{{{ { QRect r = e->rect(); gui_redraw(r.x(), r.y(), r.width(), r.height()); }//}}} -void VimWidget::draw_string(int x, int y, QString s, int len, int flags)//{{{ + void +VimWidget::draw_string(int x, int y, QString s, int len, int flags)//{{{ { gui.current_font->setBold(flags & DRAW_BOLD); gui.current_font->setUnderline(flags & DRAW_UNDERL); gui.current_font->setItalic(flags & DRAW_ITALIC); - painter->setBackgroundMode(flags & DRAW_TRANSP ? Qt::TransparentMode : Qt::OpaqueMode); + painter->setBackgroundMode(flags & DRAW_TRANSP + ? Qt::TransparentMode : Qt::OpaqueMode); painter->setFont(*(gui.current_font)); painter->drawText(x, y, s, len); }//}}} -void VimWidget::mousePressEvent(QMouseEvent *event)//{{{ + void +VimWidget::mousePressEvent(QMouseEvent *event)//{{{ { - int button=0; - int modifiers=0; + int button = 0; + int modifiers = 0; ButtonState state = event->state(); ButtonState buttons = event->button(); @@ -201,18 +206,21 @@ void VimWidget::mousePressEvent(QMouseEvent *event)//{{{ modifiers |= MOUSE_CTRL; if (state & QMouseEvent::AltButton) modifiers |= MOUSE_ALT; - gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers); + gui_send_mouse_event(button, event->x(), event->y(), FALSE, modifiers); #if QT_VERSION>=300 QByteArray params; QDataStream stream(params, IO_WriteOnly); - stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; - kapp->dcopClient()->emitDCOPSignal("mousePEvent(QCString,int,int,int,int)", params); + stream << kapp->dcopClient()->appId() << button << modifiers + << gui.row << gui.col; + kapp->dcopClient()->emitDCOPSignal( + "mousePEvent(QCString, int, int, int, int)", params); #endif event->accept(); }//}}} #if defined(FEAT_SESSION) -void VimMainWindow::saveGlobalProperties (KConfig *conf) + void +VimMainWindow::saveGlobalProperties(KConfig *conf) { //we write a mksession file to a file written in the user's ~/.kde/share/config/ //the name of the file in saved in 'conf' @@ -227,7 +235,8 @@ void VimMainWindow::saveGlobalProperties (KConfig *conf) #endif } -void VimMainWindow::readGlobalProperties (KConfig *conf) + void +VimMainWindow::readGlobalProperties (KConfig *conf) { #if 0 QString filename = conf->readPathEntry("sessionfile"); @@ -239,194 +248,218 @@ void VimMainWindow::readGlobalProperties (KConfig *conf) } #endif -void VimMainWindow::wheelEvent (QWheelEvent *event)//{{{ + void +VimMainWindow::wheelEvent (QWheelEvent *event)//{{{ { ButtonState state = event->state(); - int button=0; - int modifiers=0; + int button = 0; + int modifiers = 0; - if (event->delta()>0) - button|=MOUSE_4; - else button|=MOUSE_5; + if (event->delta() > 0) + button |= MOUSE_4; + else button |= MOUSE_5; if (state & ShiftButton) - modifiers|=MOUSE_SHIFT; + modifiers |= MOUSE_SHIFT; if (state & ControlButton) - modifiers|=MOUSE_CTRL; + modifiers |= MOUSE_CTRL; if (state & AltButton) - modifiers|=MOUSE_ALT; + modifiers |= MOUSE_ALT; - gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers); + gui_send_mouse_event(button, event->x(), event->y(), FALSE, modifiers); #if QT_VERSION>=300 QByteArray params; QDataStream stream(params, IO_WriteOnly); - stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; - kapp->dcopClient()->emitDCOPSignal("mouseWhlEvent(QCString, int, int,int,int)", params); + stream << kapp->dcopClient()->appId() << button << modifiers + << gui.row << gui.col; + kapp->dcopClient()->emitDCOPSignal( + "mouseWhlEvent(QCString, int, int, int, int)", params); #endif event->accept(); }//}}} -void VimWidget::mouseDoubleClickEvent(QMouseEvent *event)//{{{ + void +VimWidget::mouseDoubleClickEvent(QMouseEvent *event)//{{{ { ButtonState state = event->state(); ButtonState buttons = event->button(); - int modifiers=0; - int button=0; + int modifiers = 0; + int button = 0; //Look at button states if (buttons & LeftButton) - button|=MOUSE_LEFT; + button |= MOUSE_LEFT; if (buttons & RightButton) - button|=MOUSE_RIGHT; + button |= MOUSE_RIGHT; if (buttons & MidButton) - button|=MOUSE_MIDDLE; + button |= MOUSE_MIDDLE; //Look for keyboard modifiers if (state & ShiftButton) - modifiers|=MOUSE_SHIFT; + modifiers |= MOUSE_SHIFT; if (state & ControlButton) - modifiers|=MOUSE_CTRL; + modifiers |= MOUSE_CTRL; if (state & AltButton) - modifiers|=MOUSE_ALT; + modifiers |= MOUSE_ALT; - gui_send_mouse_event(button,event->x(),event->y(),TRUE,modifiers); + gui_send_mouse_event(button, event->x(), event->y(), TRUE, modifiers); #if QT_VERSION>=300 QByteArray params; QDataStream stream(params, IO_WriteOnly); - stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col; - kapp->dcopClient()->emitDCOPSignal("mouseDblClickEvent(QCString, int, int,int,int)", params); + stream << kapp->dcopClient()->appId() << button << modifiers + << gui.row << gui.col; + kapp->dcopClient()->emitDCOPSignal( + "mouseDblClickEvent(QCString, int, int, int, int)", params); #endif event->accept(); }//}}} -void VimWidget::mouseMoveEvent(QMouseEvent *event){//{{{ + void +VimWidget::mouseMoveEvent(QMouseEvent *event)//{{{ +{ ButtonState state = event->state(); - int modifiers=0; - int button=0; + int modifiers = 0; + int button = 0; gui_mch_mousehide(FALSE); //Look at button states //warning: we use state here, this is important ! - if (state & QMouseEvent::LeftButton || state & QMouseEvent::RightButton || state & QMouseEvent::MidButton) - button|=MOUSE_DRAG; + if (state & QMouseEvent::LeftButton + || state & QMouseEvent::RightButton + || state & QMouseEvent::MidButton) + button |= MOUSE_DRAG; //Look for keyboard modifiers if (state & ShiftButton) - modifiers|=MOUSE_SHIFT; + modifiers |= MOUSE_SHIFT; if (state & ControlButton) - modifiers|=MOUSE_CTRL; + modifiers |= MOUSE_CTRL; if (state & AltButton) - modifiers|=MOUSE_ALT; - if (button!=MOUSE_DRAG) - gui_mouse_moved(event->x(),event->y()); + modifiers |= MOUSE_ALT; + if (button != MOUSE_DRAG) + gui_mouse_moved(event->x(), event->y()); else - gui_send_mouse_event(MOUSE_DRAG,event->x(),event->y(),FALSE,modifiers); + gui_send_mouse_event(MOUSE_DRAG, event->x(), event->y(), + FALSE, modifiers); }//}}} -void VimWidget::mouseReleaseEvent(QMouseEvent *event)//{{{ + void +VimWidget::mouseReleaseEvent(QMouseEvent *event)//{{{ { ButtonState state = event->state(); - int modifiers=0; + int modifiers = 0; //Look for keyboard modifiers if (state & ShiftButton) - modifiers|=MOUSE_SHIFT; + modifiers |= MOUSE_SHIFT; if (state & ControlButton) - modifiers|=MOUSE_CTRL; + modifiers |= MOUSE_CTRL; if (state & AltButton) - modifiers|=MOUSE_ALT; + modifiers |= MOUSE_ALT; - gui_send_mouse_event(MOUSE_RELEASE,event->x(),event->y(),FALSE,modifiers); + gui_send_mouse_event(MOUSE_RELEASE, event->x(), event->y(), + FALSE, modifiers); event->accept(); }//}}} /* * The main widget (everything but toolbar/menubar) */ - VimWidget::VimWidget( QWidget *parent, const char *name, WFlags f )//{{{ -:QWidget(parent, name, f) - ,DCOPObject("KVim") +VimWidget::VimWidget(QWidget *parent, const char *name, WFlags f)//{{{ + :QWidget(parent, name, f) + , DCOPObject("KVim") #ifdef FEAT_MZSCHEME - ,mzscheme_timer_id(-1) + , mzscheme_timer_id(-1) #endif { //to be able to show/hide the cursor when moving the mouse setMouseTracking(true); - painter=new QPainter(this); + painter = new QPainter(this); setKeyCompression(true); - setFocusPolicy( QWidget::StrongFocus ); + setFocusPolicy(QWidget::StrongFocus); setAcceptDrops(TRUE); // DND blink_state = BLINK_NONE; blink_on_time = 700; blink_off_time = 400; blink_wait_time = 250; - connect( &blink_timer, SIGNAL( timeout() ), SLOT( blink_cursor() )); - connect( &wait_timer, SIGNAL( timeout() ), SLOT ( wait_timeout() )); + connect( &blink_timer, SIGNAL(timeout()), SLOT(blink_cursor())); + connect( &wait_timer, SIGNAL(timeout()), SLOT(wait_timeout())); + setInputMethodEnabled(true); }//}}} -void VimWidget::execNormal(QString command)//{{{ + void +VimWidget::execNormal(QString command)//{{{ { QString cmd("execute 'normal "); - cmd+=command; - cmd+="'"; + cmd += command; + cmd += "'"; QCString unistring = vmw->codec->fromUnicode(cmd); do_cmdline_cmd((char_u *)(const char*)unistring); gui_update_screen(); }//}}} -void VimWidget::execInsert(QString command)//{{{ + void +VimWidget::execInsert(QString command)//{{{ { QString cmd("execute 'normal i"); - cmd+=command; - cmd+="'"; + cmd += command; + cmd += "'"; QCString unistring = vmw->codec->fromUnicode(cmd); do_cmdline_cmd((char_u *)(const char*)unistring); gui_update_screen(); }//}}} -void VimWidget::execRaw(QString command)//{{{ + void +VimWidget::execRaw(QString command)//{{{ { QString cmd("execute '"); - cmd+=command; - cmd+="'"; + cmd += command; + cmd += "'"; QCString unistring = vmw->codec->fromUnicode(cmd); do_cmdline_cmd((char_u *)(const char*)unistring); gui_update_screen(); }//}}} -void VimWidget::execCmd(QString command)//{{{ + void +VimWidget::execCmd(QString command)//{{{ { QCString unistring = vmw->codec->fromUnicode(command); do_cmdline_cmd((char_u *)(const char*)unistring); gui_update_screen(); }//}}} -QString VimWidget::eval(QString expr)//{{{ + QString +VimWidget::eval(QString expr)//{{{ { #ifdef FEAT_EVAL QCString unistring = vmw->codec->fromUnicode(expr); - QString val((const char *)eval_to_string((char_u *)(const char*)unistring,NULL)); + QString val((const char *)eval_to_string( + (char_u *)(const char*)unistring, NULL)); return val; #else return QString::null; #endif }//}}} -void VimWidget::wait(long wtime)//{{{ + void +VimWidget::wait(long wtime)//{{{ { - if ( wait_timer.isActive() ) wait_timer.stop(); + if (wait_timer.isActive()) + wait_timer.stop(); wait_done = false; wait_timer.start( wtime, true); }//}}} -void VimWidget::wait_timeout() //{{{ + void +VimWidget::wait_timeout() //{{{ { wait_done = true; }//}}} -void VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{ + void +VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{ { #if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO) e->accept(QUriDrag::canDecode(e)); @@ -435,10 +468,11 @@ void VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{ #endif }//}}} -void VimWidget::dropEvent (QDropEvent *e) // {{{ + void +VimWidget::dropEvent(QDropEvent *e) // {{{ { #if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO) - QStrList urls; + QStrList urls; char_u **fnames; int redo_dirs = FALSE; @@ -452,19 +486,19 @@ void VimWidget::dropEvent (QDropEvent *e) // {{{ if (QUriDrag::decode(e, urls)) { n = urls.count(); - fnames = (char_u **)lalloc((n+1) * sizeof(char_u *), TRUE); + fnames = (char_u **)lalloc((n+1) * sizeof(char_u *), TRUE); nfiles = 0; #if QT_VERSION>=300 QPtrListIterator<char> it(urls); - for (; it.current(); ++it ) + for (; it.current(); ++it) { KURL u(*it); #else - for (i=0;i<urls.count();++i) + for (i = 0; i < urls.count(); ++i) { KURL u(urls.at(i)); #endif - if ( !u.isLocalFile() ) + if (!u.isLocalFile()) url = TRUE; else { @@ -511,6 +545,7 @@ void VimWidget::dropEvent (QDropEvent *e) // {{{ { char_u dirname[MAXPATHL]; char_u *s; + if (mch_dirname(dirname, MAXPATHL) == OK) for (i = 0; i < nfiles; ++i) if (fnames[i] != NULL) @@ -544,27 +579,35 @@ void VimWidget::dropEvent (QDropEvent *e) // {{{ #endif } // }}} -void VimWidget::keyPressEvent( QKeyEvent *e ) // {{{ + void +VimWidget::keyPressEvent(QKeyEvent *e) // {{{ { gui_keypress(e); } // }}} -void gui_keypress(QKeyEvent *e) { // {{{ - int key = (int)e->key(); - int modifiers = 0,i; - uchar string[256],string2[256]; - uchar *s,*d; + void +gui_keypress(QKeyEvent *e) // {{{ +{ + int key = (int)e->key(); + int modifiers = 0, i; + uchar string[256], string2[256]; + uchar *s, *d; Qt::ButtonState state = e->state(); QCString unistring = vmw->codec->fromUnicode(e->text()); - if (unistring.length()>0) - strncpy((char*)string, (const char*)unistring,unistring.length()); + if (unistring.length() > 0) + strncpy((char*)string, (const char*)unistring, unistring.length()); string[unistring.length()] = 0; - int len=unistring.length(); + int len = unistring.length(); // ignore certain keys - if (key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Meta - || key == Qt::Key_CapsLock || key == Qt::Key_NumLock || key == Qt::Key_ScrollLock ) + if (key == Qt::Key_Shift + || key == Qt::Key_Alt + || key == Qt::Key_Control + || key == Qt::Key_Meta + || key == Qt::Key_CapsLock + || key == Qt::Key_NumLock + || key == Qt::Key_ScrollLock) { e->ignore(); return; @@ -595,12 +638,11 @@ void gui_keypress(QKeyEvent *e) { // {{{ // change shift-tab (backtab) into S_TAB - if ( key == Qt::Key_BackTab && state & Qt::ShiftButton) + if (key == Qt::Key_BackTab && state & Qt::ShiftButton) key = Qt::Key_Tab; // Change C-@ and C-2 in NUL ? Gtk does this - if ( (key == Qt::Key_2 || key == Qt::Key_At) - && state & Qt::ControlButton ) + if ((key == Qt::Key_2 || key == Qt::Key_At) && state & Qt::ControlButton) { string[0] = NUL; len = 1; @@ -642,13 +684,14 @@ void gui_keypress(QKeyEvent *e) { // {{{ /* Check for special keys, making sure BS and DEL are recognised. */ if (len == 0 || key == Qt::Key_BackSpace || key == Qt::Key_Delete) { - while (special_keys[i].qtkey != 0 && special_keys[i].qtkey != key ) i++; + while (special_keys[i].qtkey != 0 && special_keys[i].qtkey != key) + i++; if (special_keys[i].qtkey != 0) { - string[0] = CSI; - string[1] = special_keys[i].code0; - string[2] = special_keys[i].code1; - len = -3; + string[0] = CSI; + string[1] = special_keys[i].code0; + string[2] = special_keys[i].code1; + len = -3; } /* for (i = 0; special_keys[i].qtkey != 0 ; i++) @@ -674,15 +717,20 @@ void gui_keypress(QKeyEvent *e) { // {{{ /* Special keys (and a few others) may have modifiers */ - if (len == -3 || key == Qt::Key_Space || key == Qt::Key_Tab || - key == Qt::Key_Return || key == Qt::Key_Enter || - key == Qt::Key_Escape) + if (len == -3 + || key == Qt::Key_Space + || key == Qt::Key_Tab + || key == Qt::Key_Return + || key == Qt::Key_Enter + || key == Qt::Key_Escape) { - modifiers = 0; - if (state & Qt::ShiftButton) modifiers |= MOD_MASK_SHIFT; - if (state & Qt::ControlButton) modifiers |= MOD_MASK_CTRL; - if (state & Qt::AltButton) modifiers |= MOD_MASK_ALT; + if (state & Qt::ShiftButton) + modifiers |= MOD_MASK_SHIFT; + if (state & Qt::ControlButton) + modifiers |= MOD_MASK_CTRL; + if (state & Qt::AltButton) + modifiers |= MOD_MASK_ALT; /* * For some keys a shift modifier is translated into another key @@ -695,7 +743,8 @@ void gui_keypress(QKeyEvent *e) { // {{{ key = string[0]; key = simplify_key(key, &modifiers); - if (key == CSI) key=K_CSI; + if (key == CSI) + key = K_CSI; if (IS_SPECIAL(key)) { @@ -710,8 +759,7 @@ void gui_keypress(QKeyEvent *e) { // {{{ len = 1; } - - if (modifiers!=0) + if (modifiers != 0) { uchar string2[10]; string2[0] = CSI; @@ -723,7 +771,7 @@ void gui_keypress(QKeyEvent *e) { // {{{ } /* special keys */ if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) - || (string[0] == intr_char && intr_char != Ctrl_C))) + || (string[0] == intr_char && intr_char != Ctrl_C))) { trash_input_buf(); got_int = TRUE; @@ -748,13 +796,15 @@ void gui_keypress(QKeyEvent *e) { // {{{ QByteArray params; QDataStream stream(params, IO_WriteOnly); stream << kapp->dcopClient()->appId() << unistring << gui.row << gui.col; - kapp->dcopClient()->emitDCOPSignal("keyboardEvent(QCString, QCString,int,int)", params); + kapp->dcopClient()->emitDCOPSignal( + "keyboardEvent(QCString, QCString, int, int)", params); #endif e->ignore(); } // }}} #ifdef FEAT_CLIENTSERVER -void VimWidget::serverActivate(WId id) //{{{ + void +VimWidget::serverActivate(WId id) //{{{ { if (serverName == NULL && serverDelayedStartName != NULL) { @@ -767,53 +817,175 @@ void VimWidget::serverActivate(WId id) //{{{ #endif #ifdef FEAT_XIM -void VimWidget::imStartEvent(QIMEvent *e) + +static int preedit_buf_len = 0; +static int im_preedit_cursor = 0; +static int im_preedit_trailing = 0; + + static void +im_delete_preedit(void) { + char_u bskey[] = {CSI, 'k', 'b'}; + char_u delkey[] = {CSI, 'k', 'D'}; + + if (State & NORMAL) + { + im_preedit_cursor = 0; + return; + } + for (; im_preedit_cursor > 0; --im_preedit_cursor) + add_to_input_buf(bskey, (int)sizeof(bskey)); + + for (; im_preedit_trailing > 0; --im_preedit_trailing) + add_to_input_buf(delkey, (int)sizeof(delkey)); +} + + void +im_set_position(int row, int col) +{ + vmw->w->setMicroFocusHint( + TEXT_X(gui.col), + TEXT_Y(gui.row), 0, 0, TRUE, &vmw->w->font()); +} + + int +im_is_preediting() +{ + return (preedit_start_col != MAXCOL); +} + + int +im_get_feedback_attr(int col) +{ + if (draw_feedback != NULL && col < preedit_buf_len) + { + if (draw_feedback[col] & XIMReverse) + return HL_INVERSE; + else if (draw_feedback[col] & XIMUnderline) + return HL_UNDERLINE; + else + return hl_attr(HLF_V); + } + + return -1; +} + + void +VimWidget::imStartEvent(QIMEvent *e) +{ + if (State & CMDLINE) + preedit_start_col = cmdline_getvcol_cursor(); + else if (curwin != NULL) + getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); + xic = (XIC)!NULL; e->accept(); } -void VimWidget::imEndEvent(QIMEvent *e) + void +VimWidget::imEndEvent(QIMEvent *e) { uchar string[256]; + im_delete_preedit(); + QCString unistring = vmw->codec->fromUnicode(e->text()); - if (unistring.length()>0) - strncpy((char*)string, (const char*)unistring,unistring.length()); + if (unistring.length() > 0) + strncpy((char*)string, (const char*)unistring, unistring.length()); string[unistring.length()] = 0; - int len=unistring.length(); - - add_to_input_buf(string, len); + int len = unistring.length(); + + add_to_input_buf_csi(string, len); + im_preedit_cursor = 0; + im_preedit_trailing = 0; + preedit_start_col = MAXCOL; + preedit_buf_len = 0; + if (draw_feedback) + { + free(draw_feedback); + draw_feedback = NULL; + } + xic = 0; e->accept(); } -void VimWidget::imComposeEvent(QIMEvent *e) + void +VimWidget::imComposeEvent(QIMEvent *e) { - //i should do something here, displaying the text somewhere ... (status area ?) + uchar string[256]; + char_u backkey[] = {CSI, 'k', 'l'}; + + im_delete_preedit(); + + if (State & NORMAL) + { + im_preedit_cursor = 0; + return; + } + + QCString unistring = vmw->codec->fromUnicode(e->text()); + if (unistring.length() > 0) + strncpy((char*)string, (const char*)unistring,unistring.length()); + string[unistring.length()] = 0; + int len = unistring.length(); + add_to_input_buf_csi(string, len); + + preedit_buf_len = e->text().length(); + if (draw_feedback == NULL) + draw_feedback = (char *)alloc(preedit_buf_len); + else + draw_feedback = (char *)realloc(draw_feedback, preedit_buf_len); + preedit_end_col = preedit_start_col; + + char_u *p = string; + for (int n = 0; n < preedit_buf_len; n++) + { + if (n < e->cursorPos() || n >= e->cursorPos() + e->selectionLength()) + draw_feedback[n] = XIMUnderline; + else + draw_feedback[n] = XIMReverse; + preedit_end_col += (*mb_ptr2cells)(p); + p += (*mb_ptr2len_check)(p); + } + im_preedit_cursor = e->cursorPos(); + im_preedit_trailing = preedit_buf_len - im_preedit_cursor; + +# ifdef FEAT_RIGHTLEFT + if ((State & CMDLINE) == 0 && curwin != NULL && curwin->w_p_rl) + backkey[2] = 'r'; +# endif + for (int n = 0; n < im_preedit_trailing; n++) + add_to_input_buf(backkey, (int)sizeof(backkey)); + e->accept(); } #endif -void VimMainWindow::lock() + void +VimMainWindow::lock() { - locked=true; + locked = true; } -void VimMainWindow::unlock() + void +VimMainWindow::unlock() { - locked=false; + locked = false; } -bool VimMainWindow::isLocked() + bool +VimMainWindow::isLocked() { return locked; } // ->resize VimWidget if not locked // -void VimMainWindow::resizeEvent ( QResizeEvent *e ) //{{{ + void +VimMainWindow::resizeEvent(QResizeEvent *e) //{{{ { - if ( vmw->isLocked() ) return; + if (vmw->isLocked()) + return; //remove toolbar and menubar height int height = e->size().height(); int width = e->size().width(); @@ -825,21 +997,23 @@ void VimMainWindow::resizeEvent ( QResizeEvent *e ) //{{{ ) height -= vmw->menuBar()->height(); #ifdef FEAT_TOOLBAR - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Top || - vmw->toolBar()->barPos()==KToolBar::Bottom)) + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Top + || vmw->toolBar()->barPos() == KToolBar::Bottom)) height -= vmw->toolBar()->height(); - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Left || - vmw->toolBar()->barPos()==KToolBar::Right)) + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Left + || vmw->toolBar()->barPos() == KToolBar::Right)) width -= vmw->toolBar()->width(); #endif - height = ( ((int)(height/gui.char_height))*gui.char_height ); - if (!vmw->isLocked()) gui_resize_shell(width,height); + height = ((int)(height/gui.char_height))*gui.char_height; + if (!vmw->isLocked()) + gui_resize_shell(width, height); }//}}} -void VimWidget::focusInEvent( QFocusEvent * fe ) // {{{ + void +VimWidget::focusInEvent(QFocusEvent *fe) // {{{ { gui_focus_change(true); @@ -847,7 +1021,8 @@ void VimWidget::focusInEvent( QFocusEvent * fe ) // {{{ gui_mch_start_blink(); } // }}} -void VimWidget::focusOutEvent( QFocusEvent * fe )//{{{ + void +VimWidget::focusOutEvent(QFocusEvent *fe)//{{{ { gui_focus_change(false); @@ -855,16 +1030,19 @@ void VimWidget::focusOutEvent( QFocusEvent * fe )//{{{ gui_mch_stop_blink(); }//}}} -void VimWidget::set_blink_time( long wait, long on, long off)//{{{ + void +VimWidget::set_blink_time(long wait, long on, long off)//{{{ { blink_wait_time = wait; blink_on_time = on; blink_off_time = off; }//}}} -void VimWidget::start_cursor_blinking()//{{{ + void +VimWidget::start_cursor_blinking()//{{{ { - if (blink_timer.isActive()) blink_timer.stop(); + if (blink_timer.isActive()) + blink_timer.stop(); /* Only switch blinking on if none of the times is zero */ if (blink_wait_time && blink_on_time && blink_off_time && gui.in_focus) @@ -876,7 +1054,8 @@ void VimWidget::start_cursor_blinking()//{{{ } }//}}} -void VimWidget::blink_cursor()//{{{ + void +VimWidget::blink_cursor()//{{{ { if (blink_state == BLINK_ON) { @@ -894,9 +1073,11 @@ void VimWidget::blink_cursor()//{{{ } }//}}} -void VimWidget::stop_cursor_blinking()//{{{ + void +VimWidget::stop_cursor_blinking()//{{{ { - if (blink_timer.isActive()) blink_timer.stop(); + if (blink_timer.isActive()) + blink_timer.stop(); if (blink_state == BLINK_OFF) gui_update_cursor(TRUE, FALSE); @@ -905,33 +1086,37 @@ void VimWidget::stop_cursor_blinking()//{{{ }//}}} #ifdef FEAT_MZSCHEME -void VimWidget::timerEvent( QTimerEvent * evnt)//{{{ + void +VimWidget::timerEvent(QTimerEvent * evnt)//{{{ { if (evnt->timerId() == mzscheme_timer_id) timer_proc(); }//}}} -void VimWidget::enable_mzscheme_threads()//{{{ + void +VimWidget::enable_mzscheme_threads()//{{{ { mzscheme_timer_id = startTimer(p_mzq); }//}}} -void VimWidget::disable_mzscheme_threads()//{{{ + void +VimWidget::disable_mzscheme_threads()//{{{ { killTimer(mzscheme_timer_id); }//}}} #endif -void VimWidget::flash()//{{{ + void +VimWidget::flash()//{{{ { QPainter p(this); p.setRasterOp(Qt::XorROP); - p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF)); + p.fillRect(geometry(), QColor(0xFF, 0xFF, 0xFF)); p.flush(); //FIXME: Make this a little smarter. Maybe add a timer or something usleep(19000); - p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF)); + p.fillRect(geometry(), QColor(0xFF, 0xFF, 0xFF)); p.flush(); p.end(); }//}}} @@ -940,13 +1125,13 @@ void VimWidget::flash()//{{{ /* * The main Window */ - VimMainWindow::VimMainWindow ( const char *name , WFlags f)//{{{ -:KMainWindow(0L, name,f) +VimMainWindow::VimMainWindow(const char *name , WFlags f)//{{{ + :KMainWindow(0L, name, f) { #ifdef FEAT_CLIENTSERVER - oldFilter = qt_set_x11_event_filter( kvim_x11_event_filter ); + oldFilter = qt_set_x11_event_filter(kvim_x11_event_filter); #endif - if (echo_wid_arg== 1) + if (echo_wid_arg == 1) { fprintf(stderr, "WID: %ld\n", (long)winId()); fflush(stderr); @@ -956,14 +1141,15 @@ void VimWidget::flash()//{{{ gui.w = w; setFocusProxy(w); w->setFocus(); - have_tearoff=0; + have_tearoff = 0; - finddlg=new KEdFind (this,0,false); - repldlg=new KEdReplace (this,0,false); - QObject::connect( finddlg, SIGNAL(search()), this, SLOT(slotSearch()) ); - QObject::connect( repldlg, SIGNAL(find()), this, SLOT(slotFind()) ); - QObject::connect( repldlg, SIGNAL(replace()), this, SLOT(slotReplace()) ); - QObject::connect( repldlg, SIGNAL(replaceAll()), this, SLOT(slotReplaceAll()) ); + finddlg = new KEdFind(this, 0, false); + repldlg = new KEdReplace(this, 0, false); + QObject::connect(finddlg, SIGNAL(search()), this, SLOT(slotSearch())); + QObject::connect(repldlg, SIGNAL(find()), this, SLOT(slotFind())); + QObject::connect(repldlg, SIGNAL(replace()), this, SLOT(slotReplace())); + QObject::connect(repldlg, SIGNAL(replaceAll()), this, + SLOT(slotReplaceAll())); #ifdef FEAT_TOOLBAR connect(toolBar(), SIGNAL(clicked(int)), this, SLOT(menu_activated(int))); @@ -971,51 +1157,59 @@ void VimWidget::flash()//{{{ #ifdef FEAT_CLIENTSERVER w->serverActivate(winId()); - if (serverName!=NULL) - kapp->dcopClient()->registerAs(QCString((const char*)serverName),false); - else if (serverDelayedStartName!=NULL) - kapp->dcopClient()->registerAs(QCString((const char*)serverDelayedStartName),false); - else if (argServerName!=NULL) - kapp->dcopClient()->registerAs(argServerName->utf8(),false); + if (serverName != NULL) + kapp->dcopClient()->registerAs(QCString((const char*)serverName), + false); + else if (serverDelayedStartName != NULL) + kapp->dcopClient()->registerAs( + QCString((const char*)serverDelayedStartName), false); + else if (argServerName != NULL) + kapp->dcopClient()->registerAs(argServerName->utf8(), false); #else - if (argServerName!=NULL) - kapp->dcopClient()->registerAs(argServerName->utf8(),false); + if (argServerName != NULL) + kapp->dcopClient()->registerAs(argServerName->utf8(), false); #endif QXEmbed::initialize(); }//{{{ -bool VimMainWindow::queryClose()//{{{ + bool +VimMainWindow::queryClose()//{{{ { gui_shell_closed(); return true; }//}}} -bool VimMainWindow::queryExit()//{{{ + bool +VimMainWindow::queryExit()//{{{ { return true; }//}}} -void VimMainWindow::menu_activated(int dx)//{{{ + void +VimMainWindow::menu_activated(int dx)//{{{ { #ifdef FEAT_MENU - if (!dx) { // tearoff + if (!dx) // tearoff return; - } gui_mch_set_foreground(); - gui_menu_cb((VimMenu *) dx); + gui_menu_cb((VimMenu *)dx); #endif }//}}} -void VimMainWindow::clipboard_selection_update(){//{{{ + void +VimMainWindow::clipboard_selection_update()//{{{ +{ if (kapp->clipboard()->ownsSelection()) clip_own_selection(&clip_star); else clip_lose_selection(&clip_star); }//}}} -void VimMainWindow::clipboard_data_update(){//{{{ + void +VimMainWindow::clipboard_data_update()//{{{ +{ #if QT_VERSION>=300 if (kapp->clipboard()->ownsClipboard()) clip_own_selection(&clip_plus); @@ -1029,7 +1223,8 @@ void VimMainWindow::clipboard_data_update(){//{{{ #endif }//}}} -void VimMainWindow::slotSearch()//{{{ + void +VimMainWindow::slotSearch()//{{{ { QString find_text; bool direction_down = TRUE; @@ -1041,78 +1236,89 @@ void VimMainWindow::slotSearch()//{{{ casesensitive = finddlg->case_sensitive(); // if (casesensitive) find_text = "\\C" + find_text; // else find_text = "\\c" + find_text; - if (casesensitive) flags|=FRD_MATCH_CASE; + if (casesensitive) + flags |= FRD_MATCH_CASE; QCString unistring = vmw->codec->fromUnicode(find_text); - gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down); + gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL, + (int)direction_down); }//}}} -void VimMainWindow::slotFind()//{{{ + void +VimMainWindow::slotFind()//{{{ { QString find_text; - bool direction_down=TRUE; + bool direction_down = TRUE; bool casesensitive = TRUE; int flags = FRD_R_FINDNEXT; - find_text=repldlg->getText(); + find_text = repldlg->getText(); direction_down = !(repldlg->get_direction()); casesensitive = repldlg->case_sensitive(); // if (casesensitive) find_text = "\\C" + find_text; // else find_text = "\\c" + find_text; - if (casesensitive) flags|=FRD_MATCH_CASE; + if (casesensitive) flags |= FRD_MATCH_CASE; QCString unistring = vmw->codec->fromUnicode(find_text); - gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down); + gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL, + (int)direction_down); }//}}} -void VimMainWindow::slotReplace()//{{{ + void +VimMainWindow::slotReplace()//{{{ { QString find_text; QString repl_text; - bool direction_down=TRUE; + bool direction_down = TRUE; bool casesensitive = TRUE; int flags = FRD_REPLACE; - find_text=repldlg->getText(); - repl_text=repldlg->getReplaceText(); + find_text = repldlg->getText(); + repl_text = repldlg->getReplaceText(); direction_down = !(repldlg->get_direction()); //if (casesensitive) find_text = "\\C" + find_text; //else find_text = "\\c" + find_text; - if (casesensitive) flags|=FRD_MATCH_CASE; + if (casesensitive) flags |= FRD_MATCH_CASE; QCString unistring = vmw->codec->fromUnicode(find_text); QCString unistring2 = vmw->codec->fromUnicode(repl_text); - gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down); + gui_do_findrepl(flags, (char_u *)(const char *)unistring, + (char_u *)(const char*)unistring2, (int)direction_down); }//}}} -void VimMainWindow::slotReplaceAll()//{{{ + void +VimMainWindow::slotReplaceAll()//{{{ { QString find_text; QString repl_text; - bool direction_down=TRUE; + bool direction_down = TRUE; bool casesensitive = TRUE; int flags = FRD_REPLACEALL; - find_text=repldlg->getText(); - repl_text=repldlg->getReplaceText(); + find_text = repldlg->getText(); + repl_text = repldlg->getReplaceText(); direction_down = !(repldlg->get_direction()); casesensitive = repldlg->case_sensitive(); // if (casesensitive) find_text = "\\C" + find_text; // else find_text = "\\c" + find_text; - if (casesensitive) flags|=FRD_MATCH_CASE; + if (casesensitive) + flags |= FRD_MATCH_CASE; QCString unistring = vmw->codec->fromUnicode(find_text); QCString unistring2 = vmw->codec->fromUnicode(repl_text); - gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down); + gui_do_findrepl(flags, (char_u *)(const char *)unistring, + (char_u *)(const char*)unistring2, (int)direction_down); }//}}} -void VimMainWindow::showAboutKDE() + void +VimMainWindow::showAboutKDE() { KAboutKDE *kde = new KAboutKDE(this); kde->show(); } -void VimMainWindow::showAboutApplication()//{{{ + void +VimMainWindow::showAboutApplication()//{{{ { - KAboutData *aboutData = new KAboutData ( + KAboutData *aboutData = new KAboutData( "kvim" , I18N_NOOP("KVim") , VIM_VERSION_SHORT @@ -1173,23 +1379,27 @@ Or read the file $VIMRUNTIME/doc/uganda.txt."); about->show(); }//}}} -void VimMainWindow::showTipOfTheDay() + void +VimMainWindow::showTipOfTheDay() { #if QT_VERSION>=300 - KTipDialog::showTip (vmw,QString::null,true); + KTipDialog::showTip(vmw, QString::null, true); #endif } -void VimMainWindow::buffersToolbar() + void +VimMainWindow::buffersToolbar() { } -void VimMainWindow::showBugReport() + void +VimMainWindow::showBugReport() { - KBugReport *bug= new KBugReport(this,true); + KBugReport *bug= new KBugReport(this, true); bug->show(); } + /* * Vim Dialog * @@ -1198,13 +1408,13 @@ void VimMainWindow::showBugReport() * 1- : nb of the pressed button */ -VimDialog::VimDialog (int type, /* type of dialog *///{{{ +VimDialog::VimDialog(int type, /* type of dialog *///{{{ char_u * title, /* title of dialog */ char_u * message, /* message text */ char_u * buttons, /* names of buttons */ int def_but, /* default button */ - char_u *textfield ) /* input field */ -:QDialog(vmw, "vim generic dialog", true), // true is for "modal" + char_u *textfield) /* input field */ + :QDialog(vmw, "vim generic dialog", true), // true is for "modal" mapper(this, "dialog signal mapper") { /* @@ -1231,73 +1441,74 @@ VimDialog::VimDialog (int type, /* type of dialog *///{{{ default: icon_data = generic_xpm; }; - QLabel * icon = new QLabel( this ); - icon->setPixmap( QPixmap( (const char **) icon_data ) ); - icon->setFixedSize( icon->sizeHint() ); + QLabel * icon = new QLabel(this); + icon->setPixmap(QPixmap((const char **) icon_data)); + icon->setFixedSize(icon->sizeHint()); - QLabel * text = new QLabel( (const char *)message, this ); - text->setAlignment( AlignHCenter | AlignVCenter | ExpandTabs ); + QLabel * text = new QLabel(QSTR(message), this); + text->setAlignment(AlignHCenter | AlignVCenter | ExpandTabs); - QStringList buttonText = QStringList::split( DLG_BUTTON_SEP, (char *) buttons); + QStringList buttonText = QStringList::split(DLG_BUTTON_SEP, QSTR(buttons)); int butNb = buttonText.count(); /* * Layout */ - QVBoxLayout * vly = new QVBoxLayout( this, 5, 5 ); - QHBoxLayout * hly1 = new QHBoxLayout( vly, 5); - hly1->addWidget( icon ); - hly1->addWidget( text ); - QHBoxLayout * hly3 = new QHBoxLayout ( vly , 5); - if (textfield!=NULL) + QVBoxLayout * vly = new QVBoxLayout(this, 5, 5); + QHBoxLayout * hly1 = new QHBoxLayout(vly, 5); + hly1->addWidget(icon); + hly1->addWidget(text); + QHBoxLayout * hly3 = new QHBoxLayout(vly , 5); + if (textfield != NULL) { - entry = new QLineEdit((const char *)textfield,this); - entry->setText((const char *)textfield); - hly3->addWidget( entry ); - ret=textfield; + entry = new QLineEdit(QSTR(textfield), this); + entry->setText(QSTR(textfield)); + hly3->addWidget(entry); + ret = textfield; } else - entry=NULL; + entry = NULL; - QHBoxLayout * hly2 = new QHBoxLayout( vly, 15); + QHBoxLayout * hly2 = new QHBoxLayout(vly, 15); QString s; QPushButton * pushButton = 0L; - for (int i=0; i<butNb; i++) + for (int i = 0; i<butNb; i++) { s = buttonText[i]; - pushButton = new QPushButton(s, this ); + pushButton = new QPushButton(s, this); if (s.find('&') != -1) - pushButton->setAccel(s.at(s.find('&')+1).latin1()); + pushButton->setAccel(s.at(s.find('&') + 1).latin1()); - hly2->addWidget( pushButton ); - if (i == def_but-1) + hly2->addWidget(pushButton); + if (i == def_but - 1) { - pushButton->setDefault( true ); - pushButton->setAutoDefault( true ); - setResult( i+1 ); + pushButton->setDefault(true); + pushButton->setAutoDefault(true); + setResult(i + 1); } connect(pushButton, SIGNAL(clicked()), &mapper, SLOT(map())); - mapper.setMapping(pushButton, i+1); + mapper.setMapping(pushButton, i + 1); } - connect( &mapper, SIGNAL(mapped(int)), this, SLOT(done(int))); + connect(&mapper, SIGNAL(mapped(int)), this, SLOT(done(int))); - setCaption((const char *) title); + setCaption(QSTR(title)); vly->activate(); }//}}} -void VimDialog::done(int r) + void +VimDialog::done(int r) { - if (entry!=NULL) + if (entry != NULL) { - if (r) + if (r) { - QCString unistring=vmw->codec->fromUnicode(entry->text()); - STRCPY(ret,(const char*)unistring); + QCString unistring = vmw->codec->fromUnicode(entry->text()); + STRCPY(ret, (const char*)unistring); } else - *ret=NUL; + *ret = NUL; } QDialog::done(r); } @@ -1312,7 +1523,8 @@ SBPool::SBPool(void)//{{{ }//}}} -void SBPool::create(GuiScrollbar * sb, int orient)//{{{ + void +SBPool::create(GuiScrollbar * sb, int orient)//{{{ { switch(orient) { @@ -1332,23 +1544,27 @@ void SBPool::create(GuiScrollbar * sb, int orient)//{{{ }//}}} -void SBPool::sbUsed(int who)//{{{ + void +SBPool::sbUsed(int who)//{{{ { GuiScrollbar *sb = (GuiScrollbar*)who; - gui_drag_scrollbar( sb, sb->w->value(), FALSE); + gui_drag_scrollbar(sb, sb->w->value(), FALSE); }//}}} -void SBPool::destroy(GuiScrollbar * sb)//{{{ + void +SBPool::destroy(GuiScrollbar *sb)//{{{ { - if (!sb->w) return; + if (!sb->w) + return; delete sb->w; sb->w = 0; }//}}} #ifdef FEAT_CLIENTSERVER -static int kvim_x11_event_filter( XEvent* e)//{{{ + static int +kvim_x11_event_filter(XEvent* e)//{{{ { if (e->xproperty.type == PropertyNotify && e->xproperty.atom == commProperty @@ -1356,14 +1572,16 @@ static int kvim_x11_event_filter( XEvent* e)//{{{ && e->xproperty.state == PropertyNewValue) serverEventProc(qt_xdisplay(), e); - if (oldFilter) return oldFilter( e ); + if (oldFilter) + return oldFilter( e ); return FALSE; }//}}} #endif //add some QT 3 fonts usefull functions #if QT_VERSION<300 -QString KVimUtils::toString(QFont *f) + QString +KVimUtils::toString(QFont *f) { QStringList l; l.append(f->family()); @@ -1379,17 +1597,18 @@ QString KVimUtils::toString(QFont *f) return l.join(","); } -bool KVimUtils::fromString(QFont *f, QString descrip) + bool +KVimUtils::fromString(QFont *f, QString descrip) { QStringList l(QStringList::split(',', descrip)); int count = l.count(); if (count != 10 && count != 9) - return FALSE; + return FALSE; f->setFamily(l[0]); f->setPointSize(l[1].toInt()); - if ( count == 9 ) + if (count == 9) { f->setStyleHint((QFont::StyleHint) l[2].toInt()); f->setWeight(l[3].toInt()); @@ -1414,9 +1633,12 @@ bool KVimUtils::fromString(QFont *f, QString descrip) } #endif -QString KVimUtils::convertEncodingName(QString name) + QString +KVimUtils::convertEncodingName(QString name) { - if (name.startsWith("ucs") || name.startsWith("utf-16")) return QString("utf16"); - if (name=="cp950") return QString("Big5"); + if (name.startsWith("ucs") || name.startsWith("utf-16")) + return QString("utf16"); + if (name == "cp950") + return QString("Big5"); return QString(); } diff --git a/src/gui_kde_wid.h b/src/gui_kde_wid.h index 39102daa5..4eb67be72 100644 --- a/src/gui_kde_wid.h +++ b/src/gui_kde_wid.h @@ -68,7 +68,8 @@ class QLineEdit; class QSignalMapper; class QPaintEvent; -enum BlinkState { +enum BlinkState +{ BLINK_NONE, BLINK_ON, BLINK_OFF @@ -79,12 +80,12 @@ class VimWidget : public QWidget, virtual public KVim Q_OBJECT public: - VimWidget( QWidget *parent=0, const char *name=0, WFlags f=0 ); - virtual void paintEvent( QPaintEvent *); + VimWidget(QWidget *parent = 0, const char *name = 0, WFlags f = 0); + virtual void paintEvent(QPaintEvent *); void draw_string(int x, int y, QString s, int len, int flags); /** Init the blinking time */ - void set_blink_time( long, long, long ); + void set_blink_time(long, long, long); void start_cursor_blinking(); void stop_cursor_blinking(); void wait(long); @@ -108,24 +109,28 @@ public: BlinkState blink_state; QPainter *painter; QPopupMenu *menu; + virtual void setMicroFocusHint(int x, int y, int w, int h, bool text=TRUE, QFont *f = 0) + { + QWidget::setMicroFocusHint(x, y, w, h, text, f); + } protected: - virtual void keyPressEvent( QKeyEvent * ); - virtual void mousePressEvent( QMouseEvent *); - virtual void mouseDoubleClickEvent( QMouseEvent *); - virtual void mouseReleaseEvent( QMouseEvent *); - virtual void mouseMoveEvent( QMouseEvent *); - virtual void focusInEvent( QFocusEvent * ); - virtual void focusOutEvent( QFocusEvent * ); - virtual void dragEnterEvent (QDragEnterEvent *); - virtual void dropEvent (QDropEvent *); + virtual void keyPressEvent(QKeyEvent *); + virtual void mousePressEvent(QMouseEvent *); + virtual void mouseDoubleClickEvent(QMouseEvent *); + virtual void mouseReleaseEvent(QMouseEvent *); + virtual void mouseMoveEvent(QMouseEvent *); + virtual void focusInEvent(QFocusEvent *); + virtual void focusOutEvent(QFocusEvent *); + virtual void dragEnterEvent(QDragEnterEvent *); + virtual void dropEvent(QDropEvent *); #ifdef FEAT_XIM - virtual void imStartEvent ( QIMEvent * ); - virtual void imEndEvent ( QIMEvent * ); - virtual void imComposeEvent ( QIMEvent * ); + virtual void imStartEvent(QIMEvent *); + virtual void imEndEvent(QIMEvent *); + virtual void imComposeEvent(QIMEvent *); #endif #ifdef FEAT_MZSCHEME - virtual void timerEvent( QTimerEvent * ); + virtual void timerEvent(QTimerEvent *); #endif /* cursor blinking stuff */ @@ -149,24 +154,24 @@ class VimMainWindow : public KMainWindow Q_OBJECT public: - VimMainWindow ( const char *name = 0L, WFlags f = WDestructiveClose ); + VimMainWindow(const char *name = 0L, WFlags f = WDestructiveClose); /** called when the widget closes */ // bool close(bool alsoDelete); VimWidget *w; - KEdFind *finddlg; - KEdReplace *repldlg; + KEdFind *finddlg; + KEdReplace *repldlg; int have_tearoff; QTextCodec *codec; public slots: void menu_activated(int dx); - void clipboard_selection_update(); - void clipboard_data_update(); - void slotSearch(); - void slotFind(); - void slotReplace(); - void slotReplaceAll(); + void clipboard_selection_update(); + void clipboard_data_update(); + void slotSearch(); + void slotFind(); + void slotReplace(); + void slotReplaceAll(); void showAboutApplication(); void showAboutKDE(); void showBugReport(); @@ -177,12 +182,12 @@ public slots: void unlock(); protected: - virtual void wheelEvent (QWheelEvent *); - virtual void resizeEvent ( QResizeEvent *e ); + virtual void wheelEvent(QWheelEvent *); + virtual void resizeEvent(QResizeEvent *e); #if defined(FEAT_SESSION) - void saveGlobalProperties (KConfig *conf); - void readGlobalProperties (KConfig *conf); + void saveGlobalProperties(KConfig *conf); + void readGlobalProperties(KConfig *conf); #endif bool queryClose(); bool queryExit(); @@ -194,10 +199,10 @@ class VimDialog : public QDialog { Q_OBJECT public: - VimDialog (int type, /* type of dialog */ - unsigned char * title, /* title of dialog */ - unsigned char * message, /* message text */ - unsigned char * buttons, /* names of buttons */ + VimDialog(int type, /* type of dialog */ + unsigned char *title, /* title of dialog */ + unsigned char *message, /* message text */ + unsigned char *buttons, /* names of buttons */ int def_but, /* default button */ char_u *textfield); /* input text */ private: @@ -229,7 +234,8 @@ private: QSignalMapper mapper; }; -class KVimUtils { +class KVimUtils +{ public: static QString convertEncodingName(QString); #if QT_VERSION<300 @@ -240,6 +246,13 @@ public: extern VimMainWindow *vmw; extern SBPool *sbpool; -extern QString *argServerName; +extern QString *argServerName; + +#define QSTR(x) \ + (has_mbyte ? \ + (enc_utf8 ? \ + QString::fromUtf8((const char *)x) : \ + QString::fromLocal8Bit((const char *)x)) : \ + QString((const char *)x)) #endif // GUI_KDE_WIDGET diff --git a/src/gui_kde_x11.cc b/src/gui_kde_x11.cc index 77a7f807c..8956264d4 100644 --- a/src/gui_kde_x11.cc +++ b/src/gui_kde_x11.cc @@ -58,9 +58,9 @@ extern "C" { /* * global variable for KDE, we can't put them in Gui, cause there are C++ types */ -VimMainWindow *vmw=0; -SBPool *sbpool=0; -QString *argServerName=0; +VimMainWindow *vmw = 0; +SBPool *sbpool = 0; +QString *argServerName = 0; #ifdef FEAT_MOUSESHAPE /* The last set mouse pointer shape is remembered, to be used when it goes @@ -73,153 +73,170 @@ static int last_shape = 0; */ #if QT_VERSION>=300 -static int tip=0; // 1 no dialog, 0 use it if enabled in conf, 2 force the tip +static int tip = 0; // 1 no dialog, 0 use it if enabled in conf, + // 2 force the tip #endif -static int reverse=0; // 0 bg : white, 1 : bg : black -QString *startfont; -QSize *startsize; -static int gui_argc = 0; -static char **gui_argv = NULL; +static int reverse = 0; // 0 bg : white, 1 : bg : black +QString *startfont; +QSize *startsize; +static int gui_argc = 0; +static char **gui_argv = NULL; /* * Parse the GUI related command-line arguments. Any arguments used are * deleted from argv, and *argc is decremented accordingly. This is called * when vim is started, whether or not the GUI has been started. */ - void + void gui_mch_prepare(int *argc, char **argv)// {{{ { - //copy args for KDE/Qt - gui_argc = 0; - //this one is not really good as all options are not for KDE/Qt ... - gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE); - if (gui_argv == NULL) - return; - gui_argv[gui_argc++] = argv[0]; - - int found = 0; - for (int i = 1; i < *argc ; i++) + // copy args for KDE/Qt + gui_argc = 0; + + // this one is not really good as all options are not for KDE/Qt ... + gui_argv = (char **)lalloc((long_u)(*argc * sizeof(char *)), FALSE); + if (gui_argv == NULL) + return; + gui_argv[gui_argc++] = argv[0]; + + int found = 0; + for (int i = 1; i < *argc ; i++) + { + if (found != 2) + found = 0; + else + { + found = 0; + // remove from the list of argv + if (--*argc > i) + { + mch_memmove(&argv[i], &argv[i + 1], + (*argc - i) * sizeof(char *)); + } + i--; + continue; + } + + if (strcmp(argv[i], "--servername") == 0) { - if (found!=2) - found = 0; - else { - found=0; - //remove from the list of argv - if (--*argc>i) { - mch_memmove(&argv[i], &argv[i + 1], - (*argc - i) * sizeof(char *)); - } - i--; - continue; - } - - if (strcmp(argv[i],"--servername")==0) { - argServerName = new QString(argv[i+1]); // to get the serverName now - } + argServerName = new QString(argv[i+1]); // to get the serverName now + } #if QT_VERSION>+300 - if (strcmp(argv[i],"-tip")==0 ) { - tip=2; - found=1; - } - if (strcmp(argv[i],"-notip")==0 ) { - tip=1; - found=1; - } + if (strcmp(argv[i], "-tip") == 0 ) + { + tip = 2; + found = 1; + } + if (strcmp(argv[i], "-notip") == 0 ) + { + tip = 1; + found = 1; + } #endif - if (strcmp(argv[i],"-black")==0 ) { - reverse=1; - found=1; - } - /* replaced by -black */ -/* if (strcmp(argv[i],"-rv")==0 ) { - reverse=1; - found=1; - }*/ - if (strcmp(argv[i],"-font")==0 || strcmp(argv[i], "-fn")==0 ) { - startfont=new QString(argv[i+1]); - found=2; - } - if (strcmp(argv[i],"-geometry")==0 || strcmp (argv[i],"-geom")==0 ) { - found=2; - QString text(argv[i+1]); - QStringList list = QStringList::split(QChar('x'), text); - startsize = new QSize(list[0].toInt(),list[1].toInt()); - } - if (strcmp (argv[i],"-display")==0 ) { //XXX: this does not work, - // too many -display options in main.c ! - // ask Bram ... - gui_argv[gui_argc++] = strdup("--display"); - gui_argv[gui_argc++] = argv[i+1]; - found=0; - } - if (strcmp (argv[i],"--display")==0 ) { - gui_argv[gui_argc++] = argv[i]; - gui_argv[gui_argc++] = argv[i+1]; - found=2; - } - //KDE/Qt options with no args - if (strcmp(argv[i],"--help-kde")==0 || strcmp (argv[i],"--help-qt")==0 - || strcmp(argv[i], "--help-all")==0 - || strcmp(argv[i], "--reverse")==0 - || strcmp(argv[i], "--author")==0 -// || strcmp(argv[i], "--version")==0 //disabled we need these for kcmvim -// || strcmp(argv[i], "-v")==0 - || strcmp(argv[i], "--license")==0 - || strcmp(argv[i], "--cmap")==0 - || strcmp(argv[i], "--nograb")==0 - || strcmp(argv[i], "--dograb")==0 - || strcmp(argv[i], "--sync")==0 - || strcmp(argv[i], "--noxim")==0 - || strcmp(argv[i], "--nocrashhandler")==0 - || strcmp(argv[i], "--waitforwm")==0 - ) { - gui_argv[gui_argc++] = argv[i]; - found=1; - } - //this outputs KDE and Vim versions :) - if (strcmp(argv[i],"--version")==0 - || strcmp (argv[i],"-v")==0 - ) { - gui_argv[gui_argc++] = argv[i]; - } - - - //KDE/Qt options with one arg - if ( strcmp(argv[i],"--session")==0 - || strcmp(argv[i],"--ncols")==0 - || strcmp(argv[i],"--bg")==0 - || strcmp(argv[i],"--background")==0 - || strcmp(argv[i],"--fg")==0 - || strcmp(argv[i],"--foreground")==0 - || strcmp(argv[i],"--btn")==0 - || strcmp(argv[i],"--name")==0 - || strcmp(argv[i],"--title")==0 - || strcmp(argv[i],"--inputstyle")==0 - || strcmp(argv[i],"--im")==0 - || strcmp(argv[i],"--caption")==0 - || strcmp(argv[i],"--icon")==0 - || strcmp(argv[i],"--miniicon")==0 - || strcmp(argv[i],"--config")==0 - || strcmp(argv[i],"--dcopserver")==0 - || strcmp(argv[i],"--style")==0 - || strcmp(argv[i],"--geometry")==0 - || strcmp(argv[i],"--smkey")==0 - || strcmp(argv[i],"-smkey")==0 - || strcmp(argv[i],"-session")==0 - ) { - gui_argv[gui_argc++] = argv[i]; - gui_argv[gui_argc++] = argv[i+1]; - found=2; - } - - //remove from the list of argv - if (found >= 1 && --*argc>i) { - mch_memmove(&argv[i], &argv[i + 1], - (*argc - i) * sizeof(char *)); - i--; - } + if (strcmp(argv[i], "-black") == 0 ) + { + reverse = 1; + found = 1; + } + /* replaced by -black */ + /* if (strcmp(argv[i], "-rv") == 0 ) + * { + reverse = 1; + found = 1; + }*/ + if (strcmp(argv[i], "-font") == 0 || strcmp(argv[i], "-fn") == 0) + { + startfont = new QString(argv[i+1]); + found = 2; + } + if (strcmp(argv[i], "-geometry") == 0 || strcmp(argv[i], "-geom") == 0) + { + found = 2; + QString text(argv[i + 1]); + QStringList list = QStringList::split(QChar('x'), text); + startsize = new QSize(list[0].toInt(), list[1].toInt()); + } + if (strcmp(argv[i], "-display") == 0) //XXX: this does not work, + // too many -display options in main.c ! + // ask Bram ... + { + gui_argv[gui_argc++] = strdup("--display"); + gui_argv[gui_argc++] = argv[i+1]; + found = 0; + } + if (strcmp(argv[i], "--display") == 0 ) + { + gui_argv[gui_argc++] = argv[i]; + gui_argv[gui_argc++] = argv[i+1]; + found = 2; + } + //KDE/Qt options with no args + if (strcmp(argv[i], "--help-kde") == 0 + || strcmp(argv[i], "--help-qt") == 0 + || strcmp(argv[i], "--help-all") == 0 + || strcmp(argv[i], "--reverse") == 0 + || strcmp(argv[i], "--author") == 0 + // || strcmp(argv[i], "--version") == 0 //disabled we need these for kcmvim + // || strcmp(argv[i], "-v") == 0 + || strcmp(argv[i], "--license") == 0 + || strcmp(argv[i], "--cmap") == 0 + || strcmp(argv[i], "--nograb") == 0 + || strcmp(argv[i], "--dograb") == 0 + || strcmp(argv[i], "--sync") == 0 + || strcmp(argv[i], "--noxim") == 0 + || strcmp(argv[i], "--nocrashhandler") == 0 + || strcmp(argv[i], "--waitforwm") == 0 + ) + { + gui_argv[gui_argc++] = argv[i]; + found = 1; + } + //this outputs KDE and Vim versions :) + if (strcmp(argv[i], "--version") == 0 + || strcmp(argv[i], "-v") == 0) + { + gui_argv[gui_argc++] = argv[i]; + } + + + // KDE/Qt options with one arg + if (strcmp(argv[i], "--session") == 0 + || strcmp(argv[i], "--ncols") == 0 + || strcmp(argv[i], "--bg") == 0 + || strcmp(argv[i], "--background") == 0 + || strcmp(argv[i], "--fg") == 0 + || strcmp(argv[i], "--foreground") == 0 + || strcmp(argv[i], "--btn") == 0 + || strcmp(argv[i], "--name") == 0 + || strcmp(argv[i], "--title") == 0 + || strcmp(argv[i], "--inputstyle") == 0 + || strcmp(argv[i], "--im") == 0 + || strcmp(argv[i], "--caption") == 0 + || strcmp(argv[i], "--icon") == 0 + || strcmp(argv[i], "--miniicon") == 0 + || strcmp(argv[i], "--config") == 0 + || strcmp(argv[i], "--dcopserver") == 0 + || strcmp(argv[i], "--style") == 0 + || strcmp(argv[i], "--geometry") == 0 + || strcmp(argv[i], "--smkey") == 0 + || strcmp(argv[i], "-smkey") == 0 + || strcmp(argv[i], "-session") == 0 + ) + { + gui_argv[gui_argc++] = argv[i]; + gui_argv[gui_argc++] = argv[i + 1]; + found = 2; + } + + // remove from the list of argv + if (found >= 1 && --*argc > i) + { + mch_memmove(&argv[i], &argv[i + 1], (*argc - i) * sizeof(char *)); + i--; } - KCmdLineArgs::init( gui_argc,gui_argv,"kvim", I18N_NOOP("Vim inside KDE"),VIM_VERSION_SHORT); + } + KCmdLineArgs::init(gui_argc, gui_argv, "kvim", + I18N_NOOP("Vim inside KDE"), VIM_VERSION_SHORT); }// }}} /**************************************************************************** @@ -229,41 +246,41 @@ gui_mch_prepare(int *argc, char **argv)// {{{ /* * Initialises time intervals for the cursor blinking */ - void + void gui_mch_set_blinking(long waittime, long on, long off)//{{{ { - gui.w->set_blink_time( waittime, on, off ); + gui.w->set_blink_time(waittime, on, off); }//}}} /* * Stop the cursor blinking. Show the cursor if it wasn't shown. */ - void + void gui_mch_stop_blink()//{{{ { - gui.w->stop_cursor_blinking(); + gui.w->stop_cursor_blinking(); }//}}} /* * Start the cursor blinking. If it was already blinking, this restarts the * waiting time and shows the cursor. */ - void + void gui_mch_start_blink()//{{{ { - gui.w->start_cursor_blinking(); + gui.w->start_cursor_blinking(); }//}}} #ifdef FEAT_MZSCHEME - void + void mzscheme_kde_start_timer()//{{{ { - gui.w->enable_mzscheme_threads(); + gui.w->enable_mzscheme_threads(); }//}}} - void + void mzscheme_kde_stop_timer()//{{{ { - gui.w->disable_mzscheme_threads(); + gui.w->disable_mzscheme_threads(); }//}}} #endif @@ -271,164 +288,177 @@ mzscheme_kde_stop_timer()//{{{ * Check if the GUI can be started. Called before gvimrc is sourced. * Return OK or FAIL. */ - int + int gui_mch_init_check(void)//{{{ { - gui.dpy = qt_xdisplay(); - return OK; + gui.dpy = qt_xdisplay(); + return OK; }//}}} /* * Initialise the X GUI. Create all the windows, set up all the call-backs etc. * Returns OK for success, FAIL when the GUI can't be started. */ - int + int gui_mch_init()//{{{ { - (void) new KApplication(); - KApplication::kApplication()->dcopClient()->registerAs(KApplication::kApplication()->name(),false); -// dbf("%s %s",KGlobal::locale()->language().latin1(),KLocale::defaultLanguage().latin1()); + (void) new KApplication(); + KApplication::kApplication()->dcopClient()->registerAs( + KApplication::kApplication()->name(), false); + // dbf("%s %s", KGlobal::locale()->language().latin1(), KLocale::defaultLanguage().latin1()); - vmw = new VimMainWindow("KVim",0); - vmw->setFrameBorderWidth(0); - kapp->setMainWidget(vmw); - kapp->setTopWidget(vmw); + vmw = new VimMainWindow("KVim", 0); + vmw->setFrameBorderWidth(0); + kapp->setMainWidget(vmw); + kapp->setTopWidget(vmw); - sbpool = new SBPool; + sbpool = new SBPool; #if QT_VERSION>=300 - vmw->connect(kapp->clipboard(),SIGNAL(selectionChanged()),vmw,SLOT(clipboard_selection_update())); + vmw->connect(kapp->clipboard(), SIGNAL(selectionChanged()), + vmw, SLOT(clipboard_selection_update())); #endif - vmw->connect(kapp->clipboard(),SIGNAL(dataChanged()),vmw,SLOT(clipboard_data_update())); - clip_lose_selection(&clip_plus); - clip_lose_selection(&clip_star); + vmw->connect(kapp->clipboard(), SIGNAL(dataChanged()), + vmw, SLOT(clipboard_data_update())); + clip_lose_selection(&clip_plus); + clip_lose_selection(&clip_star); - gui.in_focus = FALSE; // will be updated + gui.in_focus = FALSE; // will be updated - if (reverse) { - gui.def_norm_pixel = gui_get_color((char_u *)"White"); - gui.def_back_pixel = gui_get_color((char_u *)"Black"); + if (reverse) + { + gui.def_norm_pixel = gui_get_color((char_u *)"White"); + gui.def_back_pixel = gui_get_color((char_u *)"Black"); #if QT_VERSION>=300 - gui.w->setEraseColor ( QColor(Qt::black) ); + gui.w->setEraseColor(QColor(Qt::black)); #else - gui.w->setBackgroundColor ( QColor(Qt::black) ); + gui.w->setBackgroundColor(QColor(Qt::black)); #endif - } else { - gui.def_norm_pixel = gui_get_color((char_u *)"Black"); - gui.def_back_pixel = gui_get_color((char_u *)"White"); + } + else + { + gui.def_norm_pixel = gui_get_color((char_u *)"Black"); + gui.def_back_pixel = gui_get_color((char_u *)"White"); #if QT_VERSION>=300 - gui.w->setEraseColor ( QColor(Qt::white) ); + gui.w->setEraseColor(QColor(Qt::white)); #else - gui.w->setBackgroundColor ( QColor(Qt::white) ); + gui.w->setBackgroundColor(QColor(Qt::white)); #endif - } + } - gui.norm_pixel = gui.def_norm_pixel; - gui.back_pixel = gui.def_back_pixel; + gui.norm_pixel = gui.def_norm_pixel; + gui.back_pixel = gui.def_back_pixel; - gui.border_width = 1; - gui.border_offset = 1;//gui.border_width; - gui.scrollbar_width=SB_DEFAULT_WIDTH; - gui.scrollbar_height=SB_DEFAULT_WIDTH; + gui.border_width = 1; + gui.border_offset = 1;//gui.border_width; + gui.scrollbar_width = SB_DEFAULT_WIDTH; + gui.scrollbar_height = SB_DEFAULT_WIDTH; - //gui.menu_height=vmw->menuBar()->height()+1; - //gui.toolbar_height=vmw->toolBar()->height(); + //gui.menu_height = vmw->menuBar()->height()+1; + //gui.toolbar_height = vmw->toolBar()->height(); - return OK; + return OK; }//}}} /* * Called when the foreground or background color has been changed. */ - void + void gui_mch_new_colors()//{{{ { - QColor rgb; - rgb.setRgb(gui.back_pixel); + QColor rgb; + rgb.setRgb(gui.back_pixel); #if QT_VERSION>=300 - gui.w->setEraseColor(rgb); + gui.w->setEraseColor(rgb); #else - gui.w->setBackgroundColor(rgb); + gui.w->setBackgroundColor(rgb); #endif }//}}} /* * Open the GUI window which was created by a call to gui_mch_init(). */ - int + int gui_mch_open()//{{{ { - gui.dpy=qt_xdisplay(); - set_normal_colors(); + gui.dpy = qt_xdisplay(); + set_normal_colors(); - /* Check that none of the colors are the same as the background color */ - gui_check_colors(); + /* Check that none of the colors are the same as the background color */ + gui_check_colors(); - /* Get the colors for the highlight groups (gui_check_colors() might have - * changed them). - */ - highlight_gui_started(); /* re-init colors and fonts */ + /* Get the colors for the highlight groups (gui_check_colors() might have + * changed them). + */ + highlight_gui_started(); /* re-init colors and fonts */ #ifdef FEAT_MENU - vmw->w->menu = new QPopupMenu(vmw); + vmw->w->menu = new QPopupMenu(vmw); #if QT_VERSION>=300 - vmw->w->menu->insertItem(SmallIcon("ktip"), i18n("&Tip of the day..."), vmw, SLOT(showTipOfTheDay())); - vmw->w->menu->insertSeparator(); + vmw->w->menu->insertItem(SmallIcon("ktip"), i18n("&Tip of the day..."), + vmw, SLOT(showTipOfTheDay())); + vmw->w->menu->insertSeparator(); #endif - if (vmw->have_tearoff) vmw->w->menu->insertTearOffHandle(0,0); - vmw->w->menu->insertItem(i18n("&Report Bug ..."), vmw, SLOT(showBugReport())); - vmw->w->menu->insertSeparator(); - vmw->w->menu->insertItem(SmallIcon("kvim"), i18n("&About KVim..."), vmw, SLOT(showAboutApplication())); - vmw->w->menu->insertItem(SmallIcon("about_kde"), i18n("About &KDE..."), vmw, SLOT(showAboutKDE())); - vmw->menuBar()->insertItem("&KVim", vmw->w->menu); + if (vmw->have_tearoff) + vmw->w->menu->insertTearOffHandle(0, 0); + vmw->w->menu->insertItem(i18n("&Report Bug ..."), + vmw, SLOT(showBugReport())); + vmw->w->menu->insertSeparator(); + vmw->w->menu->insertItem(SmallIcon("kvim"), i18n("&About KVim..."), + vmw, SLOT(showAboutApplication())); + vmw->w->menu->insertItem(SmallIcon("about_kde"), i18n("About &KDE..."), + vmw, SLOT(showAboutKDE())); + vmw->menuBar()->insertItem("&KVim", vmw->w->menu); #endif - if (startfont!=NULL) - gui_mch_init_font((char_u*)startfont->latin1(), FALSE); + if (startfont != NULL) + gui_mch_init_font((char_u*)startfont->latin1(), FALSE); - if (startsize!=NULL) - vmw->resize(startsize->width(), startsize->height()); + if (startsize != NULL) + vmw->resize(startsize->width(), startsize->height()); - gui_mch_update_codec(); + gui_mch_update_codec(); - if (kapp->isRestored()) - if (KMainWindow::canBeRestored(1)) - vmw->restore(1); + if (kapp->isRestored()) + if (KMainWindow::canBeRestored(1)) + vmw->restore(1); - vmw->show(); + vmw->show(); #if QT_VERSION>=300 - if (tip==2) KTipDialog::showTip (vmw,QString::null,true); - else if (tip==0) KTipDialog::showTip (vmw); + if (tip == 2) + KTipDialog::showTip(vmw, QString::null, true); + else if (tip == 0) + KTipDialog::showTip(vmw); #endif - return OK; + return OK; }//}}} - void + void gui_mch_exit(int rc)//{{{ { - kapp->quit(); + kapp->quit(); }//}}} /* * Get the position of the top left corner of the window. */ - int + int gui_mch_get_winpos(int *x, int *y)//{{{ { - *x = vmw->x(); - *y = vmw->y(); - return OK; + *x = vmw->x(); + *y = vmw->y(); + return OK; }//}}} /* * Set the position of the top left corner of the window to the given * coordinates. */ - void + void gui_mch_set_winpos(int x, int y)//{{{ { - vmw->move(x,y); + vmw->move(x, y); }//}}} /* @@ -436,47 +466,51 @@ gui_mch_set_winpos(int x, int y)//{{{ * ->resize VimWidget * ->resize vmw (block any events generated from here) */ -void + void gui_mch_set_shellsize(int width, int height,//{{{ int min_width, int min_height, int base_width, int base_height) { - //resize VimWidget - vmw->w->resize(width,height); - - //resize vmw - int vheight, vwidth; - vheight = height; - vwidth = width; - - if (gui.which_scrollbars[SBAR_LEFT]) vwidth+=gui.scrollbar_width; - if (gui.which_scrollbars[SBAR_RIGHT]) vwidth+=gui.scrollbar_width; - if (gui.which_scrollbars[SBAR_BOTTOM]) vheight+=gui.scrollbar_height; - - if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() + //resize VimWidget + vmw->w->resize(width, height); + + //resize vmw + int vheight, vwidth; + vheight = height; + vwidth = width; + + if (gui.which_scrollbars[SBAR_LEFT]) + vwidth += gui.scrollbar_width; + if (gui.which_scrollbars[SBAR_RIGHT]) + vwidth += gui.scrollbar_width; + if (gui.which_scrollbars[SBAR_BOTTOM]) + vheight += gui.scrollbar_height; + + if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() #if QT_VERSION>=300 - && !vmw->menuBar()->isTopLevelMenu() + && !vmw->menuBar()->isTopLevelMenu() #endif - ) - vheight += vmw->menuBar()->height(); + ) + vheight += vmw->menuBar()->height(); #ifdef FEAT_TOOLBAR - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Top || - vmw->toolBar()->barPos()==KToolBar::Bottom)) - vheight += vmw->toolBar()->height(); - - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Left || - vmw->toolBar()->barPos()==KToolBar::Right)) - vwidth += vmw->toolBar()->width(); + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Top + || vmw->toolBar()->barPos() == KToolBar::Bottom)) + vheight += vmw->toolBar()->height(); + + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Left + || vmw->toolBar()->barPos() == KToolBar::Right)) + vwidth += vmw->toolBar()->width(); #endif - vmw->lock(); - vmw->resize(vwidth,vheight); - gui_mch_update(); - //size should be nearly perfect, update baseSize and sizeIncrement - vmw->setBaseSize(base_width,vmw->menuBar()->height()+1+vmw->toolBar()->height()+gui.char_height*2); - vmw->setSizeIncrement( ( ( int )( gui.char_width/2 )*2 ),gui.char_height); - vmw->unlock(); + vmw->lock(); + vmw->resize(vwidth, vheight); + gui_mch_update(); + //size should be nearly perfect, update baseSize and sizeIncrement + vmw->setBaseSize(base_width, vmw->menuBar()->height() + 1 + + vmw->toolBar()->height() + gui.char_height * 2); + vmw->setSizeIncrement((( int )(gui.char_width / 2) * 2), gui.char_height); + vmw->unlock(); }//}}} @@ -485,35 +519,35 @@ gui_mch_set_shellsize(int width, int height,//{{{ * then the screen. This subtracts some room for menubar, toolbar and window * decorations. */ - void + void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)//{{{ { - *screen_w = kapp->desktop()->width(); - *screen_h = kapp->desktop()->height(); + *screen_w = kapp->desktop()->width(); + *screen_h = kapp->desktop()->height(); }//}}} #if defined(FEAT_MENU) || defined(PROTO) - void + void gui_mch_enable_menu(int showit)//{{{ { - if (showit) - vmw->menuBar()->show(); - else - vmw->menuBar()->hide(); - vmw->resize(vmw->width(),vmw->height()); + if (showit) + vmw->menuBar()->show(); + else + vmw->menuBar()->hide(); + vmw->resize(vmw->width(), vmw->height()); }//}}} #endif #if defined(FEAT_TOOLBAR) || defined(PROTO) - void + void gui_mch_show_toolbar(int showit)//{{{ { - if (showit) - vmw->toolBar()->show(); - else - vmw->toolBar()->hide(); - vmw->resize(vmw->width(),vmw->height()); + if (showit) + vmw->toolBar()->show(); + else + vmw->toolBar()->hide(); + vmw->resize(vmw->width(), vmw->height()); }//}}} #endif @@ -523,140 +557,147 @@ gui_mch_show_toolbar(int showit)//{{{ * Return NULL when cancelled. */ -char_u *gui_mch_font_dialog (char_u *oldval)//{{{ + char_u * +gui_mch_font_dialog(char_u *oldval)//{{{ { - QFont myFont( vmw->w->font() ); - if (gui.fontname) { - gui.fontname=NULL; - } - int result = KFontDialog::getFont( myFont, true ); - if ( result != KFontDialog::Accepted ) { - return NULL; - } -// myFont.setFixedPitch(true); + QFont myFont(vmw->w->font()); + if (gui.fontname) + gui.fontname = NULL; + + int result = KFontDialog::getFont(myFont, true); + if (result != KFontDialog::Accepted) + return NULL; + + // myFont.setFixedPitch(true); #if QT_VERSION>=300 - QString n = myFont.toString(); + QString n = myFont.toString(); #else - QString n = KVimUtils::toString(&myFont); + QString n = KVimUtils::toString(&myFont); #endif - n.replace(QRegExp(","),"/"); - gui.fontname = (char_u *)strdup((const char *)n); - n.replace(QRegExp(" "),"\\ "); - 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"); + n.replace(QRegExp(","), "/"); + gui.fontname = (char_u *)strdup((const char *)n); + n.replace(QRegExp(" "), "\\ "); + 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"); - //display a message box which explains how to save your font settings - KMessageBox::information(vmw, n,"Font Selection", "kvimselectfont"); + //display a message box which explains how to save your font settings + KMessageBox::information(vmw, n, "Font Selection", "kvimselectfont"); - return vim_strsave(gui.fontname); + return vim_strsave(gui.fontname); }//}}} /* * Initialise vim to use the font with the given name. * Return FAIL if the font could not be loaded, OK otherwise. */ - int + int gui_mch_init_font(char_u * font_name, int fontset)//{{{ { - QString fontname; - GuiFont font = NULL; + QString fontname; + GuiFont font = NULL; - if (font_name == NULL) - { + if (font_name == NULL) + { #if 0 #if QT_VERSION>=300 - KConfig *base = KGlobal::config(); + KConfig *base = KGlobal::config(); #else - KConfigBase *base = KGlobal::config(); + KConfigBase *base = KGlobal::config(); #endif - base->setGroup("General"); - if (!base->hasKey("fixed")) { - 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')"); - return FAIL; - } + base->setGroup("General"); + if (!base->hasKey("fixed")) + { + 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')"); + return FAIL; + } #if QT_VERSION>=300 - QString f = base->readEntry("fixed"); + QString f = base->readEntry("fixed"); #else - QFont ft = base->readFontEntry("fixed", NULL); - QString f = KVimUtils::toString(&ft); + QFont ft = base->readFontEntry("fixed", NULL); + QString f = KVimUtils::toString(&ft); #endif - font_name = (char_u*)strdup(f.latin1()); //latin1 ? + font_name = (char_u*)strdup(f.latin1()); //latin1 ? #else - font_name = (char_u*)strdup("misc-fixed/10/-1/5/50/0/0/0/1/0"); + font_name = (char_u*)strdup("misc-fixed/10/-1/5/50/0/0/0/1/0"); #endif - } - fontname = (const char *)font_name; -/* fontname.replace(QRegExp("/"),","); + } + fontname = (const char *)font_name; + /* fontname.replace(QRegExp("/"), ","); font = new QFont(); font->fromString( fontname ); -*/ + */ #ifdef FEAT_XFONTSET - if (fontset) - font = gui_mch_get_fontset(font_name, TRUE, TRUE); - if (font == NULL) + if (fontset) + font = gui_mch_get_fontset(font_name, TRUE, TRUE); + if (font == NULL) #endif - font = gui_mch_get_font(font_name, FALSE); + font = gui_mch_get_font(font_name, FALSE); - if (font == NULL) - return FAIL; - if (fontname.contains('*') && fontname.contains('-')) - return FAIL; + if (font == NULL) + return FAIL; + if (fontname.contains('*') && fontname.contains('-')) + return FAIL; - gui_mch_free_font(gui.norm_font); + gui_mch_free_font(gui.norm_font); #ifdef FEAT_XFONTSET - gui_mch_free_fontset(gui.fontset); - gui.fontset = NOFONTSET; - if (fontset) - { - gui.fontset = font; - gui.norm_font = NOFONT; - } - else + gui_mch_free_fontset(gui.fontset); + gui.fontset = NOFONTSET; + if (fontset) + { + gui.fontset = font; + gui.norm_font = NOFONT; + } + else #endif - gui.norm_font = font; - - /* Compute the width of the character cell. Some fonts include - * double-width characters. Use the width of ASCII characters to find - * out if this is so. */ - QFontMetrics f(*font); - int width_max = 0; - for (char c = 32; c < 127; c++) - if (width_max < f.width((QChar)c)) - width_max = f.width((QChar)c); - if (width_max <= f.maxWidth() / 2) - width_max = f.maxWidth() / 2; - gui.char_width = width_max; - gui.char_height = f.height()+p_linespace; - gui.char_ascent = f.ascent()+p_linespace; - - //check values, just to make sure and avoid a crash - if (gui.char_width<=0) gui.char_width=8; - if (gui.char_height<=0) gui.char_height=1; - - hl_set_font_name(font_name); - - return OK; + gui.norm_font = font; + + /* Compute the width of the character cell. Some fonts include + * double-width characters. Use the width of ASCII characters to find + * out if this is so. */ + QFontMetrics f(*font); + int width_max = 0; + for (char c = 32; c < 127; c++) + if (width_max < f.width((QChar)c)) + width_max = f.width((QChar)c); + if (width_max <= f.maxWidth() / 2) + width_max = f.maxWidth() / 2; + gui.char_width = width_max; + gui.char_height = f.height() + p_linespace; + gui.char_ascent = f.ascent() + p_linespace; + + //check values, just to make sure and avoid a crash + if (gui.char_width <= 0) + gui.char_width = 8; + if (gui.char_height <= 0) + gui.char_height = 1; + + hl_set_font_name(font_name); + + vmw->w->setFont(*font); + + return OK; }//}}} - GuiFont + GuiFont gui_mch_get_font(char_u * name, int report_error)//{{{ { - QString fontname((const char *)name); - if (!gui.in_use || name == NULL) - return NOFONT; - if (fontname.contains('*') && fontname.contains('-')) - return NOFONT; // XFLD names not allowed anymore - QFont *myFont = new QFont(); - fontname.replace(QRegExp("/"),","); -// myFont->setRawMode(TRUE); + QString fontname((const char *)name); + if (!gui.in_use || name == NULL) + return NOFONT; + if (fontname.contains('*') && fontname.contains('-')) + return NOFONT; // XFLD names not allowed anymore + QFont *myFont = new QFont(); + fontname.replace(QRegExp("/"), ","); + // myFont->setRawMode(TRUE); #if QT_VERSION>=300 - myFont->fromString(fontname); + myFont->fromString(fontname); #else - KVimUtils::fromString(myFont,fontname); + KVimUtils::fromString(myFont, fontname); #endif - myFont->setFixedPitch(true); - if (!myFont->fixedPitch()) dbf("Non fixed-width font"); - return (GuiFont) myFont; + myFont->setFixedPitch(true); + if (!myFont->fixedPitch()) + dbf("Non fixed-width font"); + return (GuiFont) myFont; }//}}} /* @@ -664,60 +705,62 @@ gui_mch_get_font(char_u * name, int report_error)//{{{ * Don't know how to get the actual name, thus use the provided name. */ char_u * -gui_mch_get_fontname(font, name) - GuiFont font; - char_u *name; +gui_mch_get_fontname(GuiFont font, char_u *name)//{{{ { if (name == NULL) return NULL; return vim_strsave(name); -} +}//}}} /* * Set the current text font. * Since we create all GC on demand, we use just gui.current_font to * indicate the desired current font. */ - void + void gui_mch_set_font(GuiFont font)//{{{ { - gui.current_font=font; - gui.w->painter->setFont( *(gui.current_font) ); + gui.current_font = font; + gui.w->painter->setFont(*(gui.current_font)); }//}}} /* * If a font is not going to be used, free its structure. */ - void + void gui_mch_free_font(GuiFont font)//{{{ { if (font) delete font; // this is a QFont , we can delete it :) }//}}} -GuiFontset gui_mch_get_fontset (char_u *name, int report_error, int fixed_width) + GuiFontset +gui_mch_get_fontset(char_u *name, int report_error, int fixed_width) { - return (GuiFontset)gui_mch_get_font(name,report_error); + return (GuiFontset)gui_mch_get_font(name, report_error); } -void gui_mch_set_fontset (GuiFontset fontset) + void +gui_mch_set_fontset(GuiFontset fontset) { gui_mch_set_font((GuiFont)fontset); } -void gui_mch_free_fontset (GuiFontset fontset) + void +gui_mch_free_fontset(GuiFontset fontset) { if (fontset) delete fontset; } -void gui_mch_settitle (char_u *title, char_u *icon)//{{{ + void +gui_mch_settitle(char_u *title, char_u *icon)//{{{ { - if (!gui.in_use) /* can't do this when GUI not running */ - return; - vmw->setPlainCaption((const char *)title); - QPixmap p((const char *)icon); - vmw->setIcon(p); //FIXME + if (!gui.in_use) /* can't do this when GUI not running */ + return; + vmw->setPlainCaption((const char *)title); + QPixmap p((const char *)icon); + vmw->setIcon(p); //FIXME }//}}} /* @@ -726,69 +769,72 @@ void gui_mch_settitle (char_u *title, char_u *icon)//{{{ * Programmer's Guide. * Return -1 for error. */ - guicolor_T + guicolor_T gui_mch_get_color(char_u * name)//{{{ { - int i; - static char *(vimnames[][2]) = + int i; + static char *(vimnames[][2]) = + { + /* A number of colors that some X11 systems don't have */ + {"LightRed", "#FFA0A0"}, + {"LightGreen", "#80FF80"}, + {"LightMagenta", "#FFA0FF"}, + {"DarkCyan", "#008080"}, + {"DarkBlue", "#0000C0"}, + {"DarkRed", "#C00000"}, + {"DarkMagenta", "#C000C0"}, + {"DarkGrey", "#C0C0C0"}, + {NULL, NULL} + }; + + if (!gui.in_use) /* can't do this when GUI not running */ + return (guicolor_T)(-1); + + QColor _color((const char *)name); + + if (_color.isValid()) + { + // return (_color.red() << 16) + ((_color.green() << 8)) + // + (_color.blue()); + return _color.rgb(); + // return (guicolor_T) _color.pixel(); + } + + /* add a few builtin names */ + for (i = 0;; ++i) + { + if (vimnames[i][0] == NULL) + return (guicolor_T)(-1); + if (STRICMP(name, vimnames[i][0]) == 0) { - /* A number of colors that some X11 systems don't have */ - {"LightRed", "#FFA0A0"}, - {"LightGreen", "#80FF80"}, - {"LightMagenta", "#FFA0FF"}, - {"DarkCyan", "#008080"}, - {"DarkBlue", "#0000C0"}, - {"DarkRed", "#C00000"}, - {"DarkMagenta", "#C000C0"}, - {"DarkGrey", "#C0C0C0"}, - {NULL, NULL} - }; - - if (!gui.in_use) /* can't do this when GUI not running */ - return (guicolor_T)(-1); - - QColor _color((const char *)name); - - - if (_color.isValid()) { - //return (_color.red() << 16) + ((_color.green() << 8)) + (_color.blue()); - return _color.rgb(); - //return (guicolor_T) _color.pixel(); - } - - /* add a few builtin names */ - for (i = 0;; ++i) { - if (vimnames[i][0] == NULL) - return (guicolor_T)(-1); - if (STRICMP(name, vimnames[i][0]) == 0) { - name = (char_u *) vimnames[i][1]; - return gui_mch_get_color(name); - } + name = (char_u *) vimnames[i][1]; + return gui_mch_get_color(name); } + } - return (guicolor_T)(-1); // dead code, should not be reached.. + return (guicolor_T)(-1); // dead code, should not be reached.. }//}}} /* * Set the current text foreground color. */ - void + void gui_mch_set_fg_color(guicolor_T color)//{{{ { - QColor rgb; - rgb.setRgb(color); - gui.w->painter->setPen( rgb ); + QColor rgb; + rgb.setRgb(color); + gui.w->painter->setPen(rgb); }//}}} /* * Set the current text background color. */ - void + void gui_mch_set_bg_color(guicolor_T color)//{{{ { - QColor rgb; - rgb.setRgb(color); - gui.w->painter->setBackgroundColor(rgb); + QColor rgb; + rgb.setRgb(color); + gui.w->painter->setBackgroundColor(rgb); }//}}} /* @@ -796,127 +842,129 @@ gui_mch_set_bg_color(guicolor_T color)//{{{ * * hide: TRUE = use blank ptr, FALSE = use parent ptr */ - void + void gui_mch_mousehide(int hide)//{{{ { - if (hide == gui.pointer_hidden) return; - //#ifdef FEAT_MOUSESHAPE - // if (!hide) mch_set_mouse_shape(last_shape); - //#else + if (hide == gui.pointer_hidden) + return; + //#ifdef FEAT_MOUSESHAPE + // if (!hide) mch_set_mouse_shape(last_shape); + //#else # if (QT_VERSION<300) - gui.w->setCursor((hide)?BlankCursor:ArrowCursor); + gui.w->setCursor((hide)?BlankCursor:ArrowCursor); # else - gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor); + gui.w->setCursor((hide)?Qt::BlankCursor:Qt::ArrowCursor); # endif - //#endif - gui.pointer_hidden = hide; + //#endif + gui.pointer_hidden = hide; }//}}} - void + void gui_mch_update_codec() { #ifdef FEAT_MBYTE - if (!gui.in_use) return; - vmw->codec = QTextCodec::codecForName((const char *)p_enc); - if (vmw->codec==NULL) - vmw->codec = QTextCodec::codecForName(KVimUtils::convertEncodingName(QString((const char*)p_enc))); - if (vmw->codec==NULL) - vmw->codec = QTextCodec::codecForLocale(); + if (!gui.in_use) + return; + vmw->codec = QTextCodec::codecForName((const char *)p_enc); + if (vmw->codec == NULL) + vmw->codec = QTextCodec::codecForName( + KVimUtils::convertEncodingName(QString((const char*)p_enc))); + if (vmw->codec == NULL) + vmw->codec = QTextCodec::codecForLocale(); #else - vmw->codec = QTextCodec::codecForLocale(); + vmw->codec = QTextCodec::codecForLocale(); #endif - if (vmw->codec==NULL) - vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback + if (vmw->codec == NULL) + vmw->codec = QTextCodec::codecForName("ISO-8859-1"); //fallback } - void + void gui_mch_draw_string(int row, int col, char_u * s, int len, int flags)//{{{ { - QString text = vmw->codec->toUnicode((const char *)s,len); - gui.w->draw_string( TEXT_X(col), TEXT_Y(row), text, text.length(), flags ); + QString text = vmw->codec->toUnicode((const char *)s, len); + gui.w->draw_string(TEXT_X(col), TEXT_Y(row), text, text.length(), flags); }//}}} #if defined(FEAT_TITLE) || defined(PROTO) /* * Return the text window-id and display. Only required for X-based GUI's */ - int + int gui_get_x11_windis(Window * win, Display ** dis)//{{{ { - *win = /*vmw*/gui.w->winId(); - *dis = qt_xdisplay(); - return OK; + *win = /*vmw*/gui.w->winId(); + *dis = qt_xdisplay(); + return OK; }//}}} #endif - void + void gui_mch_beep()//{{{ { - kapp->beep(); + kapp->beep(); }//}}} - void + void gui_mch_flash(int msec)//{{{ { - gui.w->flash(); + gui.w->flash(); }//}}} /* * Invert a rectangle from row r, column c, for nr rows and nc columns. */ - void + void gui_mch_invert_rectangle(int r, int c, int nr, int nc)//{{{ { - bitBlt ( - gui.w, - FILL_X(c), FILL_Y(r), - gui.w, - FILL_X(c), FILL_Y(r), - (nc) * gui.char_width, - (nr) * gui.char_height, - Qt::NotROP, // raster Operation - true ); // ignoreMask + bitBlt(gui.w, + FILL_X(c), FILL_Y(r), + gui.w, + FILL_X(c), FILL_Y(r), + (nc) * gui.char_width, + (nr) * gui.char_height, + Qt::NotROP, // raster Operation + true); // ignoreMask }//}}} /* * Iconify the GUI window. */ - void + void gui_mch_iconify()//{{{ { - vmw->showMinimized(); + vmw->showMinimized(); }//}}} /* * Draw a cursor without focus. */ - void + void gui_mch_draw_hollow_cursor(guicolor_T color)//{{{ { - QPainter p(gui.w); - p.setPen( color ); - - p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1, gui.char_height - 1 ); + QPainter p(gui.w); + p.setPen(color); - p.end(); + p.drawRect(FILL_X(gui.col), FILL_Y(gui.row), gui.char_width - 1, + gui.char_height - 1); + p.end(); }//}}} /* * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using * color "color". */ - void + void gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{ { - QPainter p(gui.w); - p.setPen( color ); - p.fillRect( - FILL_X(gui.col), - FILL_Y(gui.row) + gui.char_height - h +1, - w, h-2, QColor( color, color)); - p.drawRect(FILL_X(gui.col),FILL_Y(gui.row) + gui.char_height - h + (int)p_linespace / 2, - w, h - (int)p_linespace ); - + QPainter p(gui.w); + p.setPen(color); + p.fillRect( + FILL_X(gui.col), + FILL_Y(gui.row) + gui.char_height - h + 1, + w, h - 2, QColor( color, color)); + p.drawRect(FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h + + (int)p_linespace / 2, + w, h - (int)p_linespace); }//}}} @@ -926,10 +974,10 @@ gui_mch_draw_part_cursor(int w, int h, guicolor_T color)//{{{ * nothing in the X11 event queue (& no timers pending), then we return * immediately. */ - void + void gui_mch_update()//{{{ { - kapp->processEvents(); + kapp->processEvents(); }//}}} @@ -942,21 +990,22 @@ gui_mch_update()//{{{ * Returns OK if a character was found to be available within the given time, * or FAIL otherwise. */ - int + int gui_mch_wait_for_chars(long wtime)//{{{ { - // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug - if (wtime>0) { - gui.w->wait( wtime ); - while ( vim_is_input_buf_empty() && !gui.w->wait_done ) - kapp->processOneEvent(); - return vim_is_input_buf_empty() ? FAIL : OK; - } else - while (vim_is_input_buf_empty() ) { - kapp->processOneEvent(); - } - - return OK; + // malte@kde.org's gift to KVim ;), thanks to him :) for this hard to find bug + if (wtime > 0) + { + gui.w->wait(wtime); + while (vim_is_input_buf_empty() && !gui.w->wait_done) + kapp->processOneEvent(); + return vim_is_input_buf_empty() ? FAIL : OK; + } + else + while (vim_is_input_buf_empty()) + kapp->processOneEvent(); + + return OK; }//}}} @@ -966,28 +1015,28 @@ gui_mch_wait_for_chars(long wtime)//{{{ /* Flush any output to the screen */ - void + void gui_mch_flush()//{{{ { - kapp->flushX(); + kapp->flushX(); }//}}} /* * Clear a rectangular region of the screen from text pos (row1, col1) to * (row2, col2) inclusive. */ - void + void gui_mch_clear_block(int row1, int col1, int row2, int col2)//{{{ { - gui.w->erase (FILL_X(col1), FILL_Y(row1), - (col2 - col1 + 1) * gui.char_width+ (col2 == Columns - 1), - (row2 - row1 + 1) * gui.char_height ); + gui.w->erase(FILL_X(col1), FILL_Y(row1), + (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), + (row2 - row1 + 1) * gui.char_height); }//}}} - void + void gui_mch_clear_all(void)//{{{ { - gui.w->erase(); + gui.w->erase(); }//}}} @@ -995,139 +1044,157 @@ gui_mch_clear_all(void)//{{{ * Delete the given number of lines from the given row, scrolling up any * text further down within the scroll region. */ - void + void gui_mch_delete_lines(int row, int num_lines)//{{{ { - if (num_lines <= 0) - return; - - if (row + num_lines > gui.scroll_region_bot) { - /* Scrolled out of region, just blank the lines out */ - gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot, gui.scroll_region_right); - } else { - bitBlt ( - gui.w, - FILL_X(gui.scroll_region_left), FILL_Y(row), - gui.w, - FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), - gui.char_width * (gui.scroll_region_right -gui.scroll_region_left + 1) + 1, - gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), - Qt::CopyROP, // raster Operation - true ); // ignoreMask - - /* Update gui.cursor_row if the cursor scrolled or copied over */ - if (gui.cursor_row >= row) { - if (gui.cursor_row < row + num_lines) - gui.cursor_is_valid = FALSE; - else if (gui.cursor_row <= gui.scroll_region_bot) - gui.cursor_row -= num_lines; - } - - gui_clear_block(gui.scroll_region_bot - num_lines + 1, gui.scroll_region_left, - gui.scroll_region_bot, gui.scroll_region_right); - + if (num_lines <= 0) + return; + + if (row + num_lines > gui.scroll_region_bot) + { + /* Scrolled out of region, just blank the lines out */ + gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot, + gui.scroll_region_right); + } + else + { + bitBlt(gui.w, + FILL_X(gui.scroll_region_left), FILL_Y(row), + gui.w, + FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), + gui.char_width * (gui.scroll_region_right + - gui.scroll_region_left + 1) + 1, + gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), + Qt::CopyROP, // raster Operation + true); // ignoreMask + + /* Update gui.cursor_row if the cursor scrolled or copied over */ + if (gui.cursor_row >= row) + { + if (gui.cursor_row < row + num_lines) + gui.cursor_is_valid = FALSE; + else if (gui.cursor_row <= gui.scroll_region_bot) + gui.cursor_row -= num_lines; } + + gui_clear_block(gui.scroll_region_bot - num_lines + 1, + gui.scroll_region_left, + gui.scroll_region_bot, gui.scroll_region_right); + } }//}}} /* * Insert the given number of lines before the given row, scrolling down any * following text within the scroll region. */ - void + void gui_mch_insert_lines(int row, int num_lines)//{{{ { - if (num_lines <= 0) - return; - - if (row + num_lines > gui.scroll_region_bot) { - /* Scrolled out of region, just blank the lines out */ - gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot, gui.scroll_region_right - 1); - } else { - bitBlt ( - gui.w, - FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), - gui.w, - FILL_X(gui.scroll_region_left), FILL_Y(row), - gui.char_width * ( gui.scroll_region_right - gui.scroll_region_left + 1 ) + 1, - gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), - Qt::CopyROP, // raster Operation - true ); // ignoreMask - - /* Update gui.cursor_row if the cursor scrolled or copied over */ - if (gui.cursor_row >= gui.row) { - if (gui.cursor_row <= gui.scroll_region_bot - num_lines) - gui.cursor_row += num_lines; - else if (gui.cursor_row <= gui.scroll_region_bot) - gui.cursor_is_valid = FALSE; - } - - gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1, gui.scroll_region_right); + if (num_lines <= 0) + return; + + if (row + num_lines > gui.scroll_region_bot) + { + /* Scrolled out of region, just blank the lines out */ + gui_clear_block(row, gui.scroll_region_left, gui.scroll_region_bot, + gui.scroll_region_right - 1); + } + else + { + bitBlt(gui.w, + FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), + gui.w, + FILL_X(gui.scroll_region_left), FILL_Y(row), + gui.char_width * ( gui.scroll_region_right + - gui.scroll_region_left + 1 ) + 1, + gui.char_height * (gui.scroll_region_bot - row - num_lines + 1), + Qt::CopyROP, // raster Operation + true); // ignoreMask + + /* Update gui.cursor_row if the cursor scrolled or copied over */ + if (gui.cursor_row >= gui.row) + { + if (gui.cursor_row <= gui.scroll_region_bot - num_lines) + gui.cursor_row += num_lines; + else if (gui.cursor_row <= gui.scroll_region_bot) + gui.cursor_is_valid = FALSE; } + + gui_clear_block(row, gui.scroll_region_left, row + num_lines - 1, + gui.scroll_region_right); + } }//}}} /* * X Selection stuff, for cutting and pasting text to other windows. */ - void + void clip_mch_request_selection(VimClipboard *cbd)//{{{ { #if QT_VERSION>=300 - if (cbd==&clip_star) kapp->clipboard()->setSelectionMode(true); + if (cbd == &clip_star) + kapp->clipboard()->setSelectionMode(true); #endif - QString selection = kapp->clipboard()->text(); + QString selection = kapp->clipboard()->text(); - QCString unistring = vmw->codec->fromUnicode(selection); - clip_yank_selection(MCHAR,(char_u *)(const char*)unistring,(long) unistring.length(),cbd); + QCString unistring = vmw->codec->fromUnicode(selection); + clip_yank_selection(MCHAR, (char_u *)(const char*)unistring, + (long)unistring.length(), cbd); #if QT_VERSION>=300 - if (cbd==&clip_star) kapp->clipboard()->setSelectionMode(false); + if (cbd == &clip_star) + kapp->clipboard()->setSelectionMode(false); #endif }//}}} - void + void clip_mch_lose_selection(VimClipboard *cbd)//{{{ { - //Don't need to do anything here - gui_mch_update(); + // Don't need to do anything here + gui_mch_update(); }//}}} /* * Check whatever we allready own the selection. */ - int + int clip_mch_own_selection(VimClipboard *cbd)//{{{ { - if (kapp->clipboard()->ownsSelection()) - return OK; - else { + if (kapp->clipboard()->ownsSelection()) + return OK; + else + { #if QT_VERSION>=300 - kapp->clipboard()->setSelectionMode(true); + kapp->clipboard()->setSelectionMode(true); #endif - return OK; - } + return OK; + } }//}}} /* * Send the current selection to the clipboard. */ -void -clip_mch_set_selection(VimClipboard *cbd){//{{{ - char_u *data; - long_u length; + void +clip_mch_set_selection(VimClipboard *cbd)//{{{ +{ + char_u *data; + long_u length; - clip_get_selection(cbd); - if (clip_convert_selection(&data,&length,cbd)<0) return; + clip_get_selection(cbd); + if (clip_convert_selection(&data, &length, cbd) < 0) + return; - QString selection((const char *) data); - //We must turncate the string because it is not - // null terminated - selection.truncate((uint) length); + QString selection((const char *)data); + // We must turncate the string because it is not + // null terminated + selection.truncate((uint) length); #if QT_VERSION>=300 - if (cbd==&clip_star) kapp->clipboard()->setSelectionMode(true); + if (cbd == &clip_star) + kapp->clipboard()->setSelectionMode(true); #endif - kapp->clipboard()->setText(selection); + kapp->clipboard()->setText(selection); #if QT_VERSION>=300 - kapp->clipboard()->setSelectionMode(false); + kapp->clipboard()->setSelectionMode(false); #endif }//}}} @@ -1136,114 +1203,123 @@ clip_mch_set_selection(VimClipboard *cbd){//{{{ /* * Make a menu item appear either active or not active (grey or not grey). */ - void + void gui_mch_menu_grey(vimmenu_T * menu, int grey)//{{{ { - if ( !menu || !menu->parent || !menu->parent->widget ) return; - menu->parent->widget->setItemEnabled((int)menu, !grey); - gui_mch_update(); + if (!menu || !menu->parent || !menu->parent->widget) + return; + menu->parent->widget->setItemEnabled((int)menu, !grey); + gui_mch_update(); }//}}} /* * Make menu item hidden or not hidden. */ - void + void gui_mch_menu_hidden(vimmenu_T * menu, int hidden)//{{{ { - //FIXME: cannot be fixed AFAIK - gui_mch_menu_grey(menu,hidden); // it's hard to remove an item in a QPopupMenu + // FIXME: cannot be fixed AFAIK + // it's hard to remove an item in a QPopupMenu + gui_mch_menu_grey(menu, hidden); }//}}} /* * This is called after setting all the menus to grey/hidden or not. */ - void + void gui_mch_draw_menubar()//{{{ { - // nothing to do under kde + // nothing to do under kde }//}}} #endif /* * Scrollbar stuff. */ - void -gui_mch_enable_scrollbar(scrollbar_T * sb, int flag)//{{{ + void +gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)//{{{ { - if (!sb->w) return; - int width = gui.w->width(); - int height = gui.w->height(); - int neww = vmw->width(); - int newh = vmw->height(); - - if (gui.which_scrollbars[SBAR_LEFT]) width += gui.scrollbar_width; - if (gui.which_scrollbars[SBAR_RIGHT]) width += gui.scrollbar_width; - if (gui.which_scrollbars[SBAR_BOTTOM]) height += gui.scrollbar_height; - - if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() + if (!sb->w) + return; + int width = gui.w->width(); + int height = gui.w->height(); + int neww = vmw->width(); + int newh = vmw->height(); + + if (gui.which_scrollbars[SBAR_LEFT]) + width += gui.scrollbar_width; + if (gui.which_scrollbars[SBAR_RIGHT]) + width += gui.scrollbar_width; + if (gui.which_scrollbars[SBAR_BOTTOM]) + height += gui.scrollbar_height; + + if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled() #if QT_VERSION>=300 - && !vmw->menuBar()->isTopLevelMenu() + && !vmw->menuBar()->isTopLevelMenu() #endif - ) - height += vmw->menuBar()->height(); + ) + height += vmw->menuBar()->height(); #ifdef FEAT_TOOLBAR - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Top || - vmw->toolBar()->barPos()==KToolBar::Bottom)) - height += vmw->toolBar()->height(); - - if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() && - (vmw->toolBar()->barPos()==KToolBar::Left || - vmw->toolBar()->barPos()==KToolBar::Right)) - width += vmw->toolBar()->width(); + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Top + || vmw->toolBar()->barPos() == KToolBar::Bottom)) + height += vmw->toolBar()->height(); + + if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() + && (vmw->toolBar()->barPos() == KToolBar::Left + || vmw->toolBar()->barPos() == KToolBar::Right)) + width += vmw->toolBar()->width(); #endif - if ( abs(vmw->width() - width)>5 && (sb->type==SBAR_LEFT || sb->type==SBAR_RIGHT) ) - neww=width; - if (abs(vmw->height() - height)>5 && (sb->type==SBAR_BOTTOM) ) - newh=height; - - if (flag) - sb->w->show(); - else - sb->w->hide(); - gui_mch_update(); - vmw->lock(); - vmw->resize(neww,newh); - vmw->unlock(); - gui_mch_update(); + if (abs(vmw->width() - width) > 5 + && (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)) + neww = width; + if (abs(vmw->height() - height) > 5 && (sb->type == SBAR_BOTTOM)) + newh = height; + + if (flag) + sb->w->show(); + else + sb->w->hide(); + gui_mch_update(); + vmw->lock(); + vmw->resize(neww, newh); + vmw->unlock(); + gui_mch_update(); }//}}} /* * Return the RGB value of a pixel as "#RRGGBB". */ - long_u + long_u gui_mch_get_rgb(guicolor_T pixel)//{{{ { -// QColor c(pixel,pixel); -// return (c.red() << 16) + ((c.green() << 8)) + (c.blue()); - return pixel; // funny no ? it looks like with Qt we can always use directly the rgb value (i hope i don't break colors again ;p) + // QColor c(pixel, pixel); + // return (c.red() << 16) + ((c.green() << 8)) + (c.blue()); + return pixel; + // funny no ? it looks like with Qt we can always use directly the rgb + // value (i hope i don't break colors again ;p) }//}}} /* * Get current y mouse coordinate in text window. * Return -1 when unknown. */ - int + int gui_mch_get_mouse_x(void)//{{{ { - return vmw->mapFromGlobal( QCursor::pos() ).x(); + return vmw->mapFromGlobal(QCursor::pos()).x(); }//}}} - int + int gui_mch_get_mouse_y(void)//{{{ { - return vmw->mapFromGlobal( QCursor::pos() ).y(); + return vmw->mapFromGlobal(QCursor::pos()).y(); }//}}} - void + void gui_mch_setmouse(int x, int y)//{{{ { - QCursor::setPos( vmw->mapToGlobal( QPoint(x,y)) ); + QCursor::setPos(vmw->mapToGlobal(QPoint(x, y))); }//}}} #if defined(FEAT_MOUSESHAPE) || defined(PROTO) @@ -1256,16 +1332,16 @@ static int mshape_ids[] = {//{{{ Qt::SplitHCursor, /* udsizing */ Qt::SizeHorCursor, /* leftright */ Qt::SizeHorCursor, /* lrsizing */ - Qt::WaitCursor, /* busy */ - Qt::ForbiddenCursor, /* no */ + Qt::WaitCursor, /* busy */ + Qt::ForbiddenCursor, /* no */ Qt::CrossCursor, /* crosshair */ - Qt::PointingHandCursor, /* hand1 */ - Qt::PointingHandCursor, /* hand2 */ + Qt::PointingHandCursor, /* hand1 */ + Qt::PointingHandCursor, /* hand2 */ Qt::ArrowCursor, /* pencil */ - Qt::WhatsThisCursor, /* question */ + Qt::WhatsThisCursor, /* question */ Qt::ArrowCursor, /* right-arrow */ Qt::UpArrowCursor, /* up-arrow */ - Qt::ArrowCursor /* last one */ + Qt::ArrowCursor /* last one */ };//}}} #else static int mshape_ids[] = {//{{{ @@ -1276,68 +1352,65 @@ static int mshape_ids[] = {//{{{ SplitHCursor, /* udsizing */ SizeHorCursor, /* leftright */ SizeHorCursor, /* lrsizing */ - WaitCursor, /* busy */ - ForbiddenCursor, /* no */ + WaitCursor, /* busy */ + ForbiddenCursor, /* no */ CrossCursor, /* crosshair */ - PointingHandCursor, /* hand1 */ - PointingHandCursor, /* hand2 */ + PointingHandCursor, /* hand1 */ + PointingHandCursor, /* hand2 */ ArrowCursor, /* pencil */ ArrowCursor, /* question */ ArrowCursor, /* right-arrow */ UpArrowCursor, /* up-arrow */ - ArrowCursor /* last one */ + ArrowCursor /* last one */ };//}}} #endif - void + void mch_set_mouse_shape (int shape)//{{{ { - int id; + int id; - if (shape == MSHAPE_HIDE || gui.pointer_hidden) + if (shape == MSHAPE_HIDE || gui.pointer_hidden) #if QT_VERSION>=300 - gui.w->setCursor(Qt::BlankCursor); + gui.w->setCursor(Qt::BlankCursor); #else - gui.w->setCursor(BlankCursor); + gui.w->setCursor(BlankCursor); #endif - else + else + { + if (shape >= MSHAPE_NUMBERED) { - if (shape >= MSHAPE_NUMBERED) - { - id = shape - MSHAPE_NUMBERED; - /* if (id >= GDK_NUM_GLYPHS) - id = GDK_LEFT_PTR; - else - id &= ~1;*/ /* they are always even (why?) */ - id &= -1; - } - else - id = mshape_ids[shape]; - - gui.w->setCursor(id); + id = shape - MSHAPE_NUMBERED; + /* if (id >= GDK_NUM_GLYPHS) + id = GDK_LEFT_PTR; + else + id &= ~1;*/ /* they are always even (why?) */ + id &= -1; } - if (shape != MSHAPE_HIDE) - last_shape = shape; + else + id = mshape_ids[shape]; + + gui.w->setCursor(id); + } + if (shape != MSHAPE_HIDE) + last_shape = shape; }//}}} #endif - int + int gui_mch_adjust_charsize ()//{{{ { - QFont f(*(gui.current_font)); - QFontMetrics fm (f); - gui.char_height = fm.height() + p_linespace; - //gui.char_height = fm.ascent() + fm.descent() + p_linespace; - gui.char_ascent = fm.ascent() + p_linespace/2; + QFont f(*(gui.current_font)); + QFontMetrics fm(f); + gui.char_height = fm.height() + p_linespace; + //gui.char_height = fm.ascent() + fm.descent() + p_linespace; + gui.char_ascent = fm.ascent() + p_linespace / 2; - return OK; + return OK; }//}}} - void + void gui_mch_set_foreground ()//{{{ { - KWin::setActiveWindow(vmw->winId()); + KWin::setActiveWindow(vmw->winId()); }//}}} - - - diff --git a/src/mbyte.c b/src/mbyte.c index 8b997af0c..2278de626 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4341,6 +4341,7 @@ xim_set_focus(focus) } } +#ifndef FEAT_GUI_KDE /*ARGSUSED*/ void im_set_position(row, col) @@ -4349,6 +4350,7 @@ im_set_position(row, col) { xim_set_preedit(); } +#endif /* * Set the XIM to the current cursor position. @@ -4642,7 +4644,7 @@ xim_set_status_area() #endif } -#if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) +#if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) static char e_xim[] = N_("E285: Failed to create input context"); #endif @@ -5414,7 +5416,7 @@ xim_get_status_area_height() if (xim_input_style & (int)GDK_IM_STATUS_AREA) return gui.char_height; #elif defined FEAT_GUI_KDE -#warning FIXME + /* always return zero? */ #else if (status_area_enabled) return gui.char_height; @@ -5435,6 +5437,10 @@ im_get_status() if (xim_input_style & (int)GDK_IM_PREEDIT_CALLBACKS) return xim_can_preediting; # endif +# ifdef FEAT_GUI_KDE + if (preedit_start_col != MAXCOL) + return TRUE; +# endif return xim_has_focus; } diff --git a/src/os_unix.c b/src/os_unix.c index 0dbc1cb15..fce731b9a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1320,14 +1320,13 @@ x_error_handler(dpy, error_event) Display *dpy; XErrorEvent *error_event; { - /* KDE sometimes produces X error that we want to ignore */ -#if defined(FEAT_GUI_KDE) XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); - STRCAT(IObuff, "\nVim: Got X error but we continue...\n"); - fprintf(stderr, IObuff); +#if defined(FEAT_GUI_KDE) + /* KDE sometimes produces X error that we want to ignore */ + STRCAT(IObuff, _("\nVim: Got X error but we continue...\n")); + mch_errmsg((char *)IObuff); return 0; #else - XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); STRCAT(IObuff, _("\nVim: Got X error\n")); /* We cannot print a message and continue, because no X calls are allowed diff --git a/src/proto/buffer.pro b/src/proto/buffer.pro index 4f00e9c00..8641c75b5 100644 --- a/src/proto/buffer.pro +++ b/src/proto/buffer.pro @@ -14,6 +14,7 @@ buf_T *buflist_new __ARGS((char_u *ffname, char_u *sfname, linenr_T lnum, int fl void free_buf_options __ARGS((buf_T *buf, int free_p_ff)); int buflist_getfile __ARGS((int n, linenr_T lnum, int options, int forceit)); void buflist_getfpos __ARGS((void)); +buf_T *buflist_findname_exp __ARGS((char_u *fname)); buf_T *buflist_findname __ARGS((char_u *ffname)); int buflist_findpat __ARGS((char_u *pattern, char_u *pattern_end, int unlisted, int diffmode)); int ExpandBufnames __ARGS((char_u *pat, int *num_file, char_u ***file, int options)); @@ -24,7 +25,7 @@ pos_T *buflist_findfpos __ARGS((buf_T *buf)); linenr_T buflist_findlnum __ARGS((buf_T *buf)); void buflist_list __ARGS((exarg_T *eap)); int buflist_name_nr __ARGS((int fnum, char_u **fname, linenr_T *lnum)); -int setfname __ARGS((buf_T *buf, char_u *ffname, char_u *sfname, int message)); +int setfname __ARGS((buf_T *buf, char_u *ffname, char_u *sfname, int exist_msg)); void buf_set_name __ARGS((int fnum, char_u *name)); void buf_name_changed __ARGS((buf_T *buf)); buf_T *setaltfname __ARGS((char_u *ffname, char_u *sfname, linenr_T lnum)); diff --git a/src/proto/gui_kde_x11.pro b/src/proto/gui_kde_x11.pro index c4eb5b0e8..cae8208fa 100644 --- a/src/proto/gui_kde_x11.pro +++ b/src/proto/gui_kde_x11.pro @@ -18,6 +18,7 @@ int gui_mch_adjust_charsize __ARGS((void)); GuiFontset gui_mch_get_fontset __ARGS((char_u *name, int report_error, int fixed_width)); int gui_mch_init_font __ARGS((char_u *font_name, int fontset)); GuiFont gui_mch_get_font __ARGS((char_u *name, int report_error)); +char_u *gui_mch_get_fontname __ARGS((GuiFont font, char_u *name)); void gui_mch_set_font __ARGS((GuiFont font)); void gui_mch_set_fontset __ARGS((GuiFontset fontset)); void gui_mch_free_font __ARGS((GuiFont font)); diff --git a/src/quickfix.c b/src/quickfix.c index dbde1550f..fd6eba648 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -105,6 +105,9 @@ static void qf_update_buffer __ARGS((void)); static void qf_fill_buffer __ARGS((void)); #endif static char_u *get_mef_name __ARGS((void)); +static buf_T *load_dummy_buffer __ARGS((char_u *fname)); +static void wipe_dummy_buffer __ARGS((buf_T *buf)); +static void unload_dummy_buffer __ARGS((buf_T *buf)); /* * Read the errorfile "efile" into memory, line by line, building the error @@ -2063,10 +2066,10 @@ buf_hide(buf) * Return TRUE when using ":vimgrep" for ":grep". */ int -grep_internal(eap) - exarg_T *eap; +grep_internal(cmdidx) + cmdidx_T cmdidx; { - return ((eap->cmdidx == CMD_grep || eap->cmdidx == CMD_grepadd) + return ((cmdidx == CMD_grep || cmdidx == CMD_grepadd) && STRCMP("internal", *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0); } @@ -2083,7 +2086,7 @@ ex_make(eap) unsigned len; /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ - if (grep_internal(eap)) + if (grep_internal(eap->cmdidx)) { ex_vimgrep(eap); return; @@ -2249,35 +2252,50 @@ ex_cfile(eap) ex_vimgrep(eap) exarg_T *eap; { - regmatch_T regmatch; + regmmatch_T regmatch; char_u *save_cpo; int fcount; char_u **fnames; + char_u *s; char_u *p; int i; - FILE *fd; int fi; struct qf_line *prevp = NULL; long lnum; garray_T ga; + buf_T *buf; + int duplicate_name = FALSE; + int using_dummy; + int found_match; + int first_match = TRUE; /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ save_cpo = p_cpo; p_cpo = empty_option; - /* Get the search pattern */ + /* Get the search pattern: either white-separated or enclosed in // */ regmatch.regprog = NULL; - p = skip_regexp(eap->arg + 1, *eap->arg, TRUE, NULL); - if (*p != *eap->arg) + if (vim_isIDc(*eap->arg)) { - EMSG(_("E682: Invalid search pattern or delimiter")); - goto theend; + s = eap->arg; + p = skiptowhite(s); + } + else + { + s = eap->arg + 1; + p = skip_regexp(s, *eap->arg, TRUE, NULL); + if (*p != *eap->arg) + { + EMSG(_("E682: Invalid search pattern or delimiter")); + goto theend; + } } - *p++ = NUL; - regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC); + if (*p != NUL) + *p++ = NUL; + regmatch.regprog = vim_regcomp(s, RE_MAGIC); if (regmatch.regprog == NULL) goto theend; - regmatch.rm_ic = FALSE; + regmatch.rmm_ic = FALSE; p = skipwhite(p); if (*p == NUL) @@ -2312,28 +2330,37 @@ ex_vimgrep(eap) for (fi = 0; fi < fcount && !got_int; ++fi) { - fd = fopen((char *)fnames[fi], "r"); - if (fd == NULL) + buf = buflist_findname_exp(fnames[fi]); + if (buf == NULL || buf->b_ml.ml_mfp == NULL) + { + /* Remember that a buffer with this name already exists. */ + duplicate_name = (buf != NULL); + + /* Load file into a buffer, so that 'fileencoding' is detected, + * autocommands applied, etc. */ + buf = load_dummy_buffer(fnames[fi]); + using_dummy = TRUE; + } + else + /* Use existing, loaded buffer. */ + using_dummy = FALSE; + if (buf == NULL) smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]); else { - lnum = 1; - while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) + found_match = FALSE; + for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) { - if (vim_regexec(®match, IObuff, (colnr_T)0)) + if (vim_regexec_multi(®match, curwin, buf, lnum, + (colnr_T)0) > 0) { - int l = STRLEN(IObuff); - - /* remove trailing CR, LF, spaces, etc. */ - while (l > 0 && IObuff[l - 1] <= ' ') - IObuff[--l] = NUL; - if (qf_add_entry(&prevp, NULL, /* dir */ fnames[fi], - IObuff, - lnum, - (int)(regmatch.startp[0] - IObuff) + 1,/* col */ + ml_get_buf(buf, + regmatch.startpos[0].lnum + lnum, FALSE), + regmatch.startpos[0].lnum + lnum, + regmatch.startpos[0].col + 1, FALSE, /* virt_col */ 0, /* nr */ 0, /* type */ @@ -2343,11 +2370,34 @@ ex_vimgrep(eap) got_int = TRUE; break; } + else + found_match = TRUE; } - ++lnum; line_breakcheck(); + if (got_int) + break; + } + + if (using_dummy) + { + if (duplicate_name) + /* Never keep a dummy buffer if there is another buffer + * with the same name. */ + wipe_dummy_buffer(buf); + else if (!buf_hide(buf)) + { + /* When not hiding the buffer and no match was found we + * don't need to remember the buffer, wipe it out. If + * there was a match and it wasn't the first one: only + * unload the buffer. */ + if (!found_match) + wipe_dummy_buffer(buf); + else if (!first_match) + unload_dummy_buffer(buf); + } } - fclose(fd); + if (found_match) + first_match = FALSE; } } @@ -2364,6 +2414,8 @@ ex_vimgrep(eap) /* Jump to first match. */ if (qf_lists[qf_curlist].qf_count > 0) qf_jump(0, 0, FALSE); + else + EMSG2(_(e_nomatch2), s); theend: vim_free(regmatch.regprog); @@ -2376,6 +2428,104 @@ theend: } /* + * Load file "fname" into a dummy buffer and return the buffer pointer. + * Returns NULL if it fails. + * Must call unload_dummy_buffer() or wipe_dummy_buffer() later! + */ + static buf_T * +load_dummy_buffer(fname) + char_u *fname; +{ + buf_T *newbuf; + int failed = TRUE; +#ifdef FEAT_AUTOCMD + aco_save_T aco; +#else + buf_T *old_curbuf = curbuf; +#endif + + /* Allocate a buffer without putting it in the buffer list. */ + newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); + if (newbuf == NULL) + return NULL; + +#ifdef FEAT_AUTOCMD + /* set curwin/curbuf to buf and save a few things */ + aucmd_prepbuf(&aco, newbuf); +#else + curbuf = newbuf; + curwin->w_buffer = newbuf; +#endif + + /* Need to set the filename for autocommands. */ + (void)setfname(curbuf, fname, NULL, FALSE); + + if (ml_open() == OK) + { + /* Create swap file now to avoid the ATTENTION message. */ + check_need_swap(TRUE); + + /* Remove the "dummy" flag, otherwise autocommands may not + * work. */ + curbuf->b_flags &= ~BF_DUMMY; + + if (readfile(fname, NULL, + (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, + NULL, READ_NEW | READ_DUMMY) == OK + && !(curbuf->b_flags & BF_NEW)) + { + failed = FALSE; + if (curbuf != newbuf) + { + /* Bloody autocommands changed the buffer! */ + if (buf_valid(newbuf)) + wipe_buffer(newbuf, FALSE); + newbuf = curbuf; + } + } + } + +#ifdef FEAT_AUTOCMD + /* restore curwin/curbuf and a few other things */ + aucmd_restbuf(&aco); +#else + curbuf = old_curbuf; + curwin->w_buffer = old_curbuf; +#endif + + if (!buf_valid(newbuf)) + return NULL; + if (failed) + { + wipe_dummy_buffer(newbuf); + return NULL; + } + return newbuf; +} + +/* + * Wipe out the dummy buffer that load_dummy_buffer() created. + */ + static void +wipe_dummy_buffer(buf) + buf_T *buf; +{ + if (curbuf != buf) /* safety check */ + wipe_buffer(buf, FALSE); +} + +/* + * Unload the dummy buffer that load_dummy_buffer() created. + */ + static void +unload_dummy_buffer(buf) + buf_T *buf; +{ + if (curbuf != buf) /* safety check */ + close_buffer(NULL, buf, DOBUF_UNLOAD); +} + +/* * ":[range]cbuffer [bufnr]" command. */ void @@ -2487,7 +2637,8 @@ ex_helpgrep(eap) fnames[fi], IObuff, lnum, - 0, /* col */ + (int)(regmatch.startp[0] - IObuff) + + 1, /* col */ FALSE, /* virt_col */ 0, /* nr */ 1, /* type */ diff --git a/src/screen.c b/src/screen.c index e986a223b..11b4dcc5f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -3780,7 +3780,7 @@ win_line(wp, lnum, startrow, endrow) && (search_attr == 0 || char_attr != search_attr)) char_attr = extra_attr; -#if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)) +#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) /* XIM don't send preedit_start and preedit_end, but they send * preedit_changed and commit. Thus Vim can't set "im_is_active", use * im_is_preediting() here. */ @@ -4771,7 +4771,7 @@ status_match_len(xp, s) #endif ) ++s; - len += ptr2cells(s++); + len += ptr2cells(s); mb_ptr_adv(s); } diff --git a/src/version.h b/src/version.h index ba8cee618..4eaa08a9e 100644 --- a/src/version.h +++ b/src/version.h @@ -36,5 +36,5 @@ #define VIM_VERSION_NODOT "vim70aa" #define VIM_VERSION_SHORT "7.0aa" #define VIM_VERSION_MEDIUM "7.0aa ALPHA" -#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2004 Dec 24)" -#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2004 Dec 24, compiled " +#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2004 Dec 29)" +#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2004 Dec 29, compiled " @@ -604,6 +604,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname); #define BF_NEW 0x10 /* file didn't exist when editing started */ #define BF_NEW_W 0x20 /* Warned for BF_NEW and file created */ #define BF_READERR 0x40 /* got errors while reading the file */ +#define BF_DUMMY 0x80 /* dummy buffer, only used internally */ /* Mask to check for flags that prevent normal writing */ #define BF_WRITE_MASK (BF_NOTEDITED + BF_NEW + BF_READERR) |