comparison src/gui.c @ 15595:1ec942f1b648 v8.1.0805

patch 8.1.0805: too many #ifdefs commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:04:48 2019 +0100 patch 8.1.0805: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 1.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 15:15:06 +0100
parents dd725a8ab112
children 6f1c7e9a6393
comparison
equal deleted inserted replaced
15594:7a8983fe4f97 15595:1ec942f1b648
11 #include "vim.h" 11 #include "vim.h"
12 12
13 /* Structure containing all the GUI information */ 13 /* Structure containing all the GUI information */
14 gui_T gui; 14 gui_T gui;
15 15
16 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) 16 #if !defined(FEAT_GUI_GTK)
17 static void set_guifontwide(char_u *font_name); 17 static void set_guifontwide(char_u *font_name);
18 #endif 18 #endif
19 static void gui_check_pos(void); 19 static void gui_check_pos(void);
20 static void gui_outstr(char_u *, int); 20 static void gui_outstr(char_u *, int);
21 static int gui_screenchar(int off, int flags, guicolor_T fg, guicolor_T bg, int back); 21 static int gui_screenchar(int off, int flags, guicolor_T fg, guicolor_T bg, int back);
395 gui.boldital_font = NOFONT; 395 gui.boldital_font = NOFONT;
396 # ifdef FEAT_XFONTSET 396 # ifdef FEAT_XFONTSET
397 gui.fontset = NOFONTSET; 397 gui.fontset = NOFONTSET;
398 # endif 398 # endif
399 #endif 399 #endif
400 #ifdef FEAT_MBYTE
401 gui.wide_font = NOFONT; 400 gui.wide_font = NOFONT;
402 # ifndef FEAT_GUI_GTK 401 #ifndef FEAT_GUI_GTK
403 gui.wide_bold_font = NOFONT; 402 gui.wide_bold_font = NOFONT;
404 gui.wide_ital_font = NOFONT; 403 gui.wide_ital_font = NOFONT;
405 gui.wide_boldital_font = NOFONT; 404 gui.wide_boldital_font = NOFONT;
406 # endif
407 #endif 405 #endif
408 406
409 #ifdef FEAT_MENU 407 #ifdef FEAT_MENU
410 # ifndef FEAT_GUI_GTK 408 # ifndef FEAT_GUI_GTK
411 # ifdef FONTSET_ALWAYS 409 # ifdef FONTSET_ALWAYS
650 : p_guifont, FALSE) == FAIL) 648 : p_guifont, FALSE) == FAIL)
651 { 649 {
652 emsg(_("E665: Cannot start GUI, no valid font found")); 650 emsg(_("E665: Cannot start GUI, no valid font found"));
653 goto error2; 651 goto error2;
654 } 652 }
655 #ifdef FEAT_MBYTE
656 if (gui_get_wide_font() == FAIL) 653 if (gui_get_wide_font() == FAIL)
657 emsg(_("E231: 'guifontwide' invalid")); 654 emsg(_("E231: 'guifontwide' invalid"));
658 #endif
659 655
660 gui.num_cols = Columns; 656 gui.num_cols = Columns;
661 gui.num_rows = Rows; 657 gui.num_rows = Rows;
662 gui_reset_scroll_region(); 658 gui_reset_scroll_region();
663 659
872 * name, which frees the old value. This makes font_list 868 * name, which frees the old value. This makes font_list
873 * invalid. Thus when OK is returned here, font_list must no 869 * invalid. Thus when OK is returned here, font_list must no
874 * longer be used! */ 870 * longer be used! */
875 if (gui_mch_init_font(font_name, FALSE) == OK) 871 if (gui_mch_init_font(font_name, FALSE) == OK)
876 { 872 {
877 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) 873 #if !defined(FEAT_GUI_GTK)
878 /* If it's a Unicode font, try setting 'guifontwide' to a 874 /* If it's a Unicode font, try setting 'guifontwide' to a
879 * similar double-width font. */ 875 * similar double-width font. */
880 if ((p_guifontwide == NULL || *p_guifontwide == NUL) 876 if ((p_guifontwide == NULL || *p_guifontwide == NUL)
881 && strstr((char *)font_name, "10646") != NULL) 877 && strstr((char *)font_name, "10646") != NULL)
882 set_guifontwide(font_name); 878 set_guifontwide(font_name);
914 } 910 }
915 911
916 return ret; 912 return ret;
917 } 913 }
918 914
919 #if defined(FEAT_MBYTE) || defined(PROTO) 915 #ifndef FEAT_GUI_GTK
920 # ifndef FEAT_GUI_GTK
921 /* 916 /*
922 * Try setting 'guifontwide' to a font twice as wide as "name". 917 * Try setting 'guifontwide' to a font twice as wide as "name".
923 */ 918 */
924 static void 919 static void
925 set_guifontwide(char_u *name) 920 set_guifontwide(char_u *name)
962 break; 957 break;
963 } 958 }
964 } 959 }
965 } 960 }
966 } 961 }
967 # endif /* !FEAT_GUI_GTK */ 962 #endif /* !FEAT_GUI_GTK */
968 963
969 /* 964 /*
970 * Get the font for 'guifontwide'. 965 * Get the font for 'guifontwide'.
971 * Return FAIL for an invalid font name. 966 * Return FAIL for an invalid font name.
972 */ 967 */
993 if (font == NOFONT) 988 if (font == NOFONT)
994 return FAIL; 989 return FAIL;
995 } 990 }
996 991
997 gui_mch_free_font(gui.wide_font); 992 gui_mch_free_font(gui.wide_font);
998 # ifdef FEAT_GUI_GTK 993 #ifdef FEAT_GUI_GTK
999 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ 994 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */
1000 if (font != NOFONT && gui.norm_font != NOFONT 995 if (font != NOFONT && gui.norm_font != NOFONT
1001 && pango_font_description_equal(font, gui.norm_font)) 996 && pango_font_description_equal(font, gui.norm_font))
1002 { 997 {
1003 gui.wide_font = NOFONT; 998 gui.wide_font = NOFONT;
1004 gui_mch_free_font(font); 999 gui_mch_free_font(font);
1005 } 1000 }
1006 else 1001 else
1007 # endif 1002 #endif
1008 gui.wide_font = font; 1003 gui.wide_font = font;
1009 # ifdef FEAT_GUI_MSWIN 1004 #ifdef FEAT_GUI_MSWIN
1010 gui_mch_wide_font_changed(); 1005 gui_mch_wide_font_changed();
1011 # else 1006 #else
1012 /* 1007 /*
1013 * TODO: setup wide_bold_font, wide_ital_font and wide_boldital_font to 1008 * TODO: setup wide_bold_font, wide_ital_font and wide_boldital_font to
1014 * support those fonts for 'guifontwide'. 1009 * support those fonts for 'guifontwide'.
1015 */ 1010 */
1016 # endif 1011 #endif
1017 return OK; 1012 return OK;
1018 } 1013 }
1019 #endif
1020 1014
1021 void 1015 void
1022 gui_set_cursor(int row, int col) 1016 gui_set_cursor(int row, int col)
1023 { 1017 {
1024 gui.row = row; 1018 gui.row = row;
1256 (void)gui_screenchar(LineOffset[gui.row] + gui.col, 1250 (void)gui_screenchar(LineOffset[gui.row] + gui.col,
1257 GUI_MON_IS_CURSOR | GUI_MON_NOCLEAR, cfg, cbg, 0); 1251 GUI_MON_IS_CURSOR | GUI_MON_NOCLEAR, cfg, cbg, 0);
1258 } 1252 }
1259 else 1253 else
1260 { 1254 {
1261 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT) 1255 #if defined(FEAT_RIGHTLEFT)
1262 int col_off = FALSE; 1256 int col_off = FALSE;
1263 #endif 1257 #endif
1264 /* 1258 /*
1265 * First draw the partial cursor, then overwrite with the text 1259 * First draw the partial cursor, then overwrite with the text
1266 * character, using a transparent background. 1260 * character, using a transparent background.
1273 else 1267 else
1274 { 1268 {
1275 cur_height = (gui.char_height * shape->percentage + 99) / 100; 1269 cur_height = (gui.char_height * shape->percentage + 99) / 100;
1276 cur_width = gui.char_width; 1270 cur_width = gui.char_width;
1277 } 1271 }
1278 #ifdef FEAT_MBYTE
1279 if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col, 1272 if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col,
1280 LineOffset[gui.row] + screen_Columns) > 1) 1273 LineOffset[gui.row] + screen_Columns) > 1)
1281 { 1274 {
1282 /* Double wide character. */ 1275 /* Double wide character. */
1283 if (shape->shape != SHAPE_VER) 1276 if (shape->shape != SHAPE_VER)
1284 cur_width += gui.char_width; 1277 cur_width += gui.char_width;
1285 # ifdef FEAT_RIGHTLEFT 1278 #ifdef FEAT_RIGHTLEFT
1286 if (CURSOR_BAR_RIGHT) 1279 if (CURSOR_BAR_RIGHT)
1287 { 1280 {
1288 /* gui.col points to the left halve of the character but 1281 /* gui.col points to the left halve of the character but
1289 * the vertical line needs to be on the right halve. 1282 * the vertical line needs to be on the right halve.
1290 * A double-wide horizontal line is also drawn from the 1283 * A double-wide horizontal line is also drawn from the
1291 * right halve in gui_mch_draw_part_cursor(). */ 1284 * right halve in gui_mch_draw_part_cursor(). */
1292 col_off = TRUE; 1285 col_off = TRUE;
1293 ++gui.col; 1286 ++gui.col;
1294 } 1287 }
1295 # endif 1288 #endif
1296 } 1289 }
1297 #endif
1298 gui_mch_draw_part_cursor(cur_width, cur_height, cbg); 1290 gui_mch_draw_part_cursor(cur_width, cur_height, cbg);
1299 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT) 1291 #if defined(FEAT_RIGHTLEFT)
1300 if (col_off) 1292 if (col_off)
1301 --gui.col; 1293 --gui.col;
1302 #endif 1294 #endif
1303 1295
1304 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */ 1296 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */
2021 2013
2022 static void 2014 static void
2023 gui_outstr(char_u *s, int len) 2015 gui_outstr(char_u *s, int len)
2024 { 2016 {
2025 int this_len; 2017 int this_len;
2026 #ifdef FEAT_MBYTE
2027 int cells; 2018 int cells;
2028 #endif
2029 2019
2030 if (len == 0) 2020 if (len == 0)
2031 return; 2021 return;
2032 2022
2033 if (len < 0) 2023 if (len < 0)
2034 len = (int)STRLEN(s); 2024 len = (int)STRLEN(s);
2035 2025
2036 while (len > 0) 2026 while (len > 0)
2037 { 2027 {
2038 #ifdef FEAT_MBYTE
2039 if (has_mbyte) 2028 if (has_mbyte)
2040 { 2029 {
2041 /* Find out how many chars fit in the current line. */ 2030 /* Find out how many chars fit in the current line. */
2042 cells = 0; 2031 cells = 0;
2043 for (this_len = 0; this_len < len; ) 2032 for (this_len = 0; this_len < len; )
2049 } 2038 }
2050 if (this_len > len) 2039 if (this_len > len)
2051 this_len = len; /* don't include following composing char */ 2040 this_len = len; /* don't include following composing char */
2052 } 2041 }
2053 else 2042 else
2054 #endif
2055 if (gui.col + len > Columns) 2043 if (gui.col + len > Columns)
2056 this_len = Columns - gui.col; 2044 this_len = Columns - gui.col;
2057 else 2045 else
2058 this_len = len; 2046 this_len = len;
2059 2047
2060 (void)gui_outstr_nowrap(s, this_len, 2048 (void)gui_outstr_nowrap(s, this_len,
2061 0, (guicolor_T)0, (guicolor_T)0, 0); 2049 0, (guicolor_T)0, (guicolor_T)0, 0);
2062 s += this_len; 2050 s += this_len;
2063 len -= this_len; 2051 len -= this_len;
2064 #ifdef FEAT_MBYTE
2065 /* fill up for a double-width char that doesn't fit. */ 2052 /* fill up for a double-width char that doesn't fit. */
2066 if (len > 0 && gui.col < Columns) 2053 if (len > 0 && gui.col < Columns)
2067 (void)gui_outstr_nowrap((char_u *)" ", 1, 2054 (void)gui_outstr_nowrap((char_u *)" ", 1,
2068 0, (guicolor_T)0, (guicolor_T)0, 0); 2055 0, (guicolor_T)0, (guicolor_T)0, 0);
2069 #endif
2070 /* The cursor may wrap to the next line. */ 2056 /* The cursor may wrap to the next line. */
2071 if (gui.col >= Columns) 2057 if (gui.col >= Columns)
2072 { 2058 {
2073 gui.col = 0; 2059 gui.col = 0;
2074 gui.row++; 2060 gui.row++;
2087 int flags, 2073 int flags,
2088 guicolor_T fg, /* colors for cursor */ 2074 guicolor_T fg, /* colors for cursor */
2089 guicolor_T bg, /* colors for cursor */ 2075 guicolor_T bg, /* colors for cursor */
2090 int back) /* backup this many chars when using bold trick */ 2076 int back) /* backup this many chars when using bold trick */
2091 { 2077 {
2092 #ifdef FEAT_MBYTE
2093 char_u buf[MB_MAXBYTES + 1]; 2078 char_u buf[MB_MAXBYTES + 1];
2094 2079
2095 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */ 2080 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */
2096 if (enc_utf8 && ScreenLines[off] == 0) 2081 if (enc_utf8 && ScreenLines[off] == 0)
2097 return OK; 2082 return OK;
2110 2095
2111 /* Draw non-multi-byte character or DBCS character. */ 2096 /* Draw non-multi-byte character or DBCS character. */
2112 return gui_outstr_nowrap(ScreenLines + off, 2097 return gui_outstr_nowrap(ScreenLines + off,
2113 enc_dbcs ? (*mb_ptr2len)(ScreenLines + off) : 1, 2098 enc_dbcs ? (*mb_ptr2len)(ScreenLines + off) : 1,
2114 flags, fg, bg, back); 2099 flags, fg, bg, back);
2115 #else
2116 return gui_outstr_nowrap(ScreenLines + off, 1, flags, fg, bg, back);
2117 #endif
2118 } 2100 }
2119 2101
2120 #ifdef FEAT_GUI_GTK 2102 #ifdef FEAT_GUI_GTK
2121 /* 2103 /*
2122 * Output the string at the given screen position. This is used in place 2104 * Output the string at the given screen position. This is used in place
2221 guicolor_T fg_color; 2203 guicolor_T fg_color;
2222 guicolor_T bg_color; 2204 guicolor_T bg_color;
2223 guicolor_T sp_color; 2205 guicolor_T sp_color;
2224 #if !defined(FEAT_GUI_GTK) 2206 #if !defined(FEAT_GUI_GTK)
2225 GuiFont font = NOFONT; 2207 GuiFont font = NOFONT;
2226 # ifdef FEAT_MBYTE
2227 GuiFont wide_font = NOFONT; 2208 GuiFont wide_font = NOFONT;
2228 # endif
2229 # ifdef FEAT_XFONTSET 2209 # ifdef FEAT_XFONTSET
2230 GuiFontset fontset = NOFONTSET; 2210 GuiFontset fontset = NOFONTSET;
2231 # endif 2211 # endif
2232 #endif 2212 #endif
2233 attrentry_T *aep = NULL; 2213 attrentry_T *aep = NULL;
2314 hl_mask_todo &= ~HL_ITALIC; 2294 hl_mask_todo &= ~HL_ITALIC;
2315 } 2295 }
2316 else 2296 else
2317 font = gui.norm_font; 2297 font = gui.norm_font;
2318 2298
2319 # ifdef FEAT_MBYTE
2320 /* 2299 /*
2321 * Choose correct wide_font by font. wide_font should be set with font 2300 * Choose correct wide_font by font. wide_font should be set with font
2322 * at same time in above block. But it will make many "ifdef" nasty 2301 * at same time in above block. But it will make many "ifdef" nasty
2323 * blocks. So we do it here. 2302 * blocks. So we do it here.
2324 */ 2303 */
2328 wide_font = gui.wide_bold_font; 2307 wide_font = gui.wide_bold_font;
2329 else if (font == gui.ital_font && gui.wide_ital_font) 2308 else if (font == gui.ital_font && gui.wide_ital_font)
2330 wide_font = gui.wide_ital_font; 2309 wide_font = gui.wide_ital_font;
2331 else if (font == gui.norm_font && gui.wide_font) 2310 else if (font == gui.norm_font && gui.wide_font)
2332 wide_font = gui.wide_font; 2311 wide_font = gui.wide_font;
2333 # endif
2334
2335 } 2312 }
2336 # ifdef FEAT_XFONTSET 2313 # ifdef FEAT_XFONTSET
2337 if (fontset != NOFONTSET) 2314 if (fontset != NOFONTSET)
2338 gui_mch_set_fontset(fontset); 2315 gui_mch_set_fontset(fontset);
2339 else 2316 else
2439 */ 2416 */
2440 #ifdef FEAT_GUI_GTK 2417 #ifdef FEAT_GUI_GTK
2441 /* The value returned is the length in display cells */ 2418 /* The value returned is the length in display cells */
2442 len = gui_gtk2_draw_string(gui.row, col, s, len, draw_flags); 2419 len = gui_gtk2_draw_string(gui.row, col, s, len, draw_flags);
2443 #else 2420 #else
2444 # ifdef FEAT_MBYTE
2445 if (enc_utf8) 2421 if (enc_utf8)
2446 { 2422 {
2447 int start; /* index of bytes to be drawn */ 2423 int start; /* index of bytes to be drawn */
2448 int cells; /* cellwidth of bytes to be drawn */ 2424 int cells; /* cellwidth of bytes to be drawn */
2449 int thislen; /* length of bytes to be drawn */ 2425 int thislen; /* length of bytes to be drawn */
2454 int comping; /* current char is composing */ 2430 int comping; /* current char is composing */
2455 int scol = col; /* screen column */ 2431 int scol = col; /* screen column */
2456 int curr_wide = FALSE; /* use 'guifontwide' */ 2432 int curr_wide = FALSE; /* use 'guifontwide' */
2457 int prev_wide = FALSE; 2433 int prev_wide = FALSE;
2458 int wide_changed; 2434 int wide_changed;
2459 # ifdef WIN3264 2435 # ifdef WIN3264
2460 int sep_comp = FALSE; /* Don't separate composing chars. */ 2436 int sep_comp = FALSE; /* Don't separate composing chars. */
2461 # else 2437 # else
2462 int sep_comp = TRUE; /* Separate composing chars. */ 2438 int sep_comp = TRUE; /* Separate composing chars. */
2463 # endif 2439 # endif
2464 2440
2465 /* Break the string at a composing character, it has to be drawn on 2441 /* Break the string at a composing character, it has to be drawn on
2466 * top of the previous character. */ 2442 * top of the previous character. */
2467 start = 0; 2443 start = 0;
2468 cells = 0; 2444 cells = 0;
2474 if (!comping) /* count cells from non-composing chars */ 2450 if (!comping) /* count cells from non-composing chars */
2475 cells += cn; 2451 cells += cn;
2476 if (!comping || sep_comp) 2452 if (!comping || sep_comp)
2477 { 2453 {
2478 if (cn > 1 2454 if (cn > 1
2479 # ifdef FEAT_XFONTSET 2455 # ifdef FEAT_XFONTSET
2480 && fontset == NOFONTSET 2456 && fontset == NOFONTSET
2481 # endif 2457 # endif
2482 && wide_font != NOFONT) 2458 && wide_font != NOFONT)
2483 curr_wide = TRUE; 2459 curr_wide = TRUE;
2484 else 2460 else
2485 curr_wide = FALSE; 2461 curr_wide = FALSE;
2486 } 2462 }
2492 2468
2493 /* Print the string so far if it's the last character or there is 2469 /* Print the string so far if it's the last character or there is
2494 * a composing character. */ 2470 * a composing character. */
2495 if (i + cl >= len || (comping && sep_comp && i > start) 2471 if (i + cl >= len || (comping && sep_comp && i > start)
2496 || wide_changed 2472 || wide_changed
2497 # if defined(FEAT_GUI_X11) 2473 # if defined(FEAT_GUI_X11)
2498 || (cn > 1 2474 || (cn > 1
2499 # ifdef FEAT_XFONTSET 2475 # ifdef FEAT_XFONTSET
2500 /* No fontset: At least draw char after wide char at 2476 /* No fontset: At least draw char after wide char at
2501 * right position. */ 2477 * right position. */
2502 && fontset == NOFONTSET 2478 && fontset == NOFONTSET
2503 # endif 2479 # endif
2504 ) 2480 )
2505 # endif 2481 # endif
2506 ) 2482 )
2507 { 2483 {
2508 if ((comping && sep_comp) || wide_changed) 2484 if ((comping && sep_comp) || wide_changed)
2509 thislen = i - start; 2485 thislen = i - start;
2510 else 2486 else
2527 { 2503 {
2528 scol -= cn; 2504 scol -= cn;
2529 cl = 0; 2505 cl = 0;
2530 } 2506 }
2531 2507
2532 # if defined(FEAT_GUI_X11) 2508 # if defined(FEAT_GUI_X11)
2533 /* No fontset: draw a space to fill the gap after a wide char 2509 /* No fontset: draw a space to fill the gap after a wide char
2534 * */ 2510 * */
2535 if (cn > 1 && (draw_flags & DRAW_TRANSP) == 0 2511 if (cn > 1 && (draw_flags & DRAW_TRANSP) == 0
2536 # ifdef FEAT_XFONTSET 2512 # ifdef FEAT_XFONTSET
2537 && fontset == NOFONTSET 2513 && fontset == NOFONTSET
2538 # endif 2514 # endif
2539 && !wide_changed) 2515 && !wide_changed)
2540 gui_mch_draw_string(gui.row, scol - 1, (char_u *)" ", 2516 gui_mch_draw_string(gui.row, scol - 1, (char_u *)" ",
2541 1, draw_flags); 2517 1, draw_flags);
2542 # endif 2518 # endif
2543 } 2519 }
2544 /* Draw a composing char on top of the previous char. */ 2520 /* Draw a composing char on top of the previous char. */
2545 if (comping && sep_comp) 2521 if (comping && sep_comp)
2546 { 2522 {
2547 # if defined(__APPLE_CC__) && TARGET_API_MAC_CARBON 2523 # if defined(__APPLE_CC__) && TARGET_API_MAC_CARBON
2548 /* Carbon ATSUI autodraws composing char over previous char */ 2524 /* Carbon ATSUI autodraws composing char over previous char */
2549 gui_mch_draw_string(gui.row, scol, s + i, cl, 2525 gui_mch_draw_string(gui.row, scol, s + i, cl,
2550 draw_flags | DRAW_TRANSP); 2526 draw_flags | DRAW_TRANSP);
2551 # else 2527 # else
2552 gui_mch_draw_string(gui.row, scol - cn, s + i, cl, 2528 gui_mch_draw_string(gui.row, scol - cn, s + i, cl,
2553 draw_flags | DRAW_TRANSP); 2529 draw_flags | DRAW_TRANSP);
2554 # endif 2530 # endif
2555 start = i + cl; 2531 start = i + cl;
2556 } 2532 }
2557 prev_wide = curr_wide; 2533 prev_wide = curr_wide;
2558 } 2534 }
2559 /* The stuff below assumes "len" is the length in screen columns. */ 2535 /* The stuff below assumes "len" is the length in screen columns. */
2560 len = scol - col; 2536 len = scol - col;
2561 } 2537 }
2562 else 2538 else
2563 # endif
2564 { 2539 {
2565 gui_mch_draw_string(gui.row, col, s, len, draw_flags); 2540 gui_mch_draw_string(gui.row, col, s, len, draw_flags);
2566 # ifdef FEAT_MBYTE
2567 if (enc_dbcs == DBCS_JPNU) 2541 if (enc_dbcs == DBCS_JPNU)
2568 { 2542 {
2569 /* Get the length in display cells, this can be different from the 2543 /* Get the length in display cells, this can be different from the
2570 * number of bytes for "euc-jp". */ 2544 * number of bytes for "euc-jp". */
2571 len = mb_string2cells(s, len); 2545 len = mb_string2cells(s, len);
2572 } 2546 }
2573 # endif
2574 } 2547 }
2575 #endif /* !FEAT_GUI_GTK */ 2548 #endif /* !FEAT_GUI_GTK */
2576 2549
2577 if (!(flags & (GUI_MON_IS_CURSOR | GUI_MON_TRS_CURSOR))) 2550 if (!(flags & (GUI_MON_IS_CURSOR | GUI_MON_TRS_CURSOR)))
2578 gui.col = col + len; 2551 gui.col = col + len;
2695 int off; 2668 int off;
2696 sattr_T first_attr; 2669 sattr_T first_attr;
2697 int idx, len; 2670 int idx, len;
2698 int back, nback; 2671 int back, nback;
2699 int retval = FALSE; 2672 int retval = FALSE;
2700 #ifdef FEAT_MBYTE
2701 int orig_col1, orig_col2; 2673 int orig_col1, orig_col2;
2702 #endif
2703 2674
2704 /* Don't try to update when ScreenLines is not valid */ 2675 /* Don't try to update when ScreenLines is not valid */
2705 if (!screen_cleared || ScreenLines == NULL) 2676 if (!screen_cleared || ScreenLines == NULL)
2706 return retval; 2677 return retval;
2707 2678
2714 2685
2715 /* Remember where our cursor was */ 2686 /* Remember where our cursor was */
2716 old_row = gui.row; 2687 old_row = gui.row;
2717 old_col = gui.col; 2688 old_col = gui.col;
2718 old_hl_mask = gui.highlight_mask; 2689 old_hl_mask = gui.highlight_mask;
2719 #ifdef FEAT_MBYTE
2720 orig_col1 = col1; 2690 orig_col1 = col1;
2721 orig_col2 = col2; 2691 orig_col2 = col2;
2722 #endif
2723 2692
2724 for (gui.row = row1; gui.row <= row2; gui.row++) 2693 for (gui.row = row1; gui.row <= row2; gui.row++)
2725 { 2694 {
2726 #ifdef FEAT_MBYTE
2727 /* When only half of a double-wide character is in the block, include 2695 /* When only half of a double-wide character is in the block, include
2728 * the other half. */ 2696 * the other half. */
2729 col1 = orig_col1; 2697 col1 = orig_col1;
2730 col2 = orig_col2; 2698 col2 = orig_col2;
2731 off = LineOffset[gui.row]; 2699 off = LineOffset[gui.row];
2751 "INTERNAL ERROR: NUL in ScreenLines in row %ld", 2719 "INTERNAL ERROR: NUL in ScreenLines in row %ld",
2752 (long)gui.row); 2720 (long)gui.row);
2753 msg((char *)IObuff); 2721 msg((char *)IObuff);
2754 } 2722 }
2755 } 2723 }
2756 # ifdef FEAT_GUI_GTK 2724 #ifdef FEAT_GUI_GTK
2757 if (col2 + 1 < Columns && ScreenLines[off + col2 + 1] == 0) 2725 if (col2 + 1 < Columns && ScreenLines[off + col2 + 1] == 0)
2758 ++col2; 2726 ++col2;
2759 # endif 2727 #endif
2760 } 2728 }
2761 #endif
2762 gui.col = col1; 2729 gui.col = col1;
2763 off = LineOffset[gui.row] + gui.col; 2730 off = LineOffset[gui.row] + gui.col;
2764 len = col2 - col1 + 1; 2731 len = col2 - col1 + 1;
2765 2732
2766 /* Find how many chars back this highlighting starts, or where a space 2733 /* Find how many chars back this highlighting starts, or where a space
2776 /* Print UTF-8 characters individually. */ 2743 /* Print UTF-8 characters individually. */
2777 while (len > 0) 2744 while (len > 0)
2778 { 2745 {
2779 first_attr = ScreenAttrs[off]; 2746 first_attr = ScreenAttrs[off];
2780 gui.highlight_mask = first_attr; 2747 gui.highlight_mask = first_attr;
2781 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) 2748 #if !defined(FEAT_GUI_GTK)
2782 if (enc_utf8 && ScreenLinesUC[off] != 0) 2749 if (enc_utf8 && ScreenLinesUC[off] != 0)
2783 { 2750 {
2784 /* output multi-byte character separately */ 2751 /* output multi-byte character separately */
2785 nback = gui_screenchar(off, flags, 2752 nback = gui_screenchar(off, flags,
2786 (guicolor_T)0, (guicolor_T)0, back); 2753 (guicolor_T)0, (guicolor_T)0, back);
2812 (guicolor_T)0, (guicolor_T)0, back); 2779 (guicolor_T)0, (guicolor_T)0, back);
2813 #else 2780 #else
2814 for (idx = 0; idx < len && ScreenAttrs[off + idx] == first_attr; 2781 for (idx = 0; idx < len && ScreenAttrs[off + idx] == first_attr;
2815 idx++) 2782 idx++)
2816 { 2783 {
2817 # ifdef FEAT_MBYTE
2818 /* Stop at a multi-byte Unicode character. */ 2784 /* Stop at a multi-byte Unicode character. */
2819 if (enc_utf8 && ScreenLinesUC[off + idx] != 0) 2785 if (enc_utf8 && ScreenLinesUC[off + idx] != 0)
2820 break; 2786 break;
2821 if (enc_dbcs == DBCS_JPNU) 2787 if (enc_dbcs == DBCS_JPNU)
2822 { 2788 {
2825 break; 2791 break;
2826 if (len > 1 && (*mb_ptr2len)(ScreenLines 2792 if (len > 1 && (*mb_ptr2len)(ScreenLines
2827 + off + idx) == 2) 2793 + off + idx) == 2)
2828 ++idx; /* skip second byte of double-byte char */ 2794 ++idx; /* skip second byte of double-byte char */
2829 } 2795 }
2830 # endif
2831 } 2796 }
2832 nback = gui_outstr_nowrap(ScreenLines + off, idx, flags, 2797 nback = gui_outstr_nowrap(ScreenLines + off, idx, flags,
2833 (guicolor_T)0, (guicolor_T)0, back); 2798 (guicolor_T)0, (guicolor_T)0, back);
2834 #endif 2799 #endif
2835 } 2800 }
3388 gui_xy2colrow(int x, int y, int *colp) 3353 gui_xy2colrow(int x, int y, int *colp)
3389 { 3354 {
3390 int col = check_col(X_2_COL(x)); 3355 int col = check_col(X_2_COL(x));
3391 int row = check_row(Y_2_ROW(y)); 3356 int row = check_row(Y_2_ROW(y));
3392 3357
3393 #ifdef FEAT_MBYTE
3394 *colp = mb_fix_col(col, row); 3358 *colp = mb_fix_col(col, row);
3395 #else
3396 *colp = col;
3397 #endif
3398 return row; 3359 return row;
3399 } 3360 }
3400 3361
3401 #if defined(FEAT_MENU) || defined(PROTO) 3362 #if defined(FEAT_MENU) || defined(PROTO)
3402 /* 3363 /*