From 30125f4b1060dfa55848ca173a8f2e5a376db33a Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Mon, 15 Feb 2010 15:57:18 +0900 Subject: [PATCH] draw thick underline for IM target in preedit text --- src/MacVim/MMAtsuiTextView.m | 12 ++++++++++++ src/MacVim/MMBackend.m | 4 ++-- src/MacVim/MMCoreTextView.m | 7 +++++++ src/MacVim/MMTextStorage.m | 7 +++++++ src/gui.c | 6 ++++++ src/gui.h | 1 + src/mbyte.c | 10 ++++++++-- src/vim.h | 7 ++++++- 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index 3137ea2c..8747aae4 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -43,9 +43,12 @@ #define DRAW_ITALIC 0x10 /* draw italic text */ #define DRAW_CURSOR 0x20 #define DRAW_WIDE 0x40 /* draw wide text */ +#define DRAW_TUNDERL 0x100 /* draw thick underline text */ #define kUnderlineOffset (-2) #define kUnderlineHeight 1 +#define kThickUnderlineOffset (-1) +#define kThickUnderlineHeight 2 #define kUndercurlHeight 2 #define kUndercurlOffset (-2) #define kUndercurlDotWidth 2 @@ -1180,6 +1183,15 @@ defaultLineHeightForFont(NSFont *font) rect.size.width, kUnderlineHeight)); } + if (flags & DRAW_TUNDERL) + { + [sp set]; + NSRectFill(NSMakeRect(rect.origin.x, + (row + 1) * cellSize.height + + kThickUnderlineOffset, + rect.size.width, kThickUnderlineHeight)); + } + if (flags & DRAW_UNDERC) { [sp set]; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 4d4a1aac..7811343d 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -59,7 +59,7 @@ static id evalExprCocoa(NSString * expr, NSString ** errstr); extern void im_preedit_start_macvim(); extern void im_preedit_end_macvim(); extern void im_preedit_abandon_macvim(); -extern void im_preedit_changed_macvim(char *preedit_string, int cursor_index); +extern void im_preedit_changed_macvim(char *preedit_string, int start_index, int cursor_index); enum { MMBlinkStateNone = 0, @@ -2827,7 +2827,7 @@ static void netbeansReadCallback(CFSocketRef s, if (!preedit_get_status()) im_preedit_start_macvim(); - im_preedit_changed_macvim(chars, pos + len); + im_preedit_changed_macvim(chars, pos, pos + len); } } diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index fd50b585..8a0f45cd 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -46,6 +46,7 @@ #define DRAW_ITALIC 0x10 /* draw italic text */ #define DRAW_CURSOR 0x20 #define DRAW_WIDE 0x40 /* draw wide text */ +#define DRAW_TUNDERL 0x100 /* draw double underline text */ #define BLUE(argb) ((argb & 0xff)/255.0f) @@ -1131,6 +1132,12 @@ recurseDraw(const unichar *chars, CGGlyph *glyphs, CGSize *advances, CGContextSetRGBFillColor(context, RED(sp), GREEN(sp), BLUE(sp), ALPHA(sp)); CGContextFillRect(context, rect); + } else if (flags & DRAW_TUNDERL) { + // Draw underline + CGRect rect = { {x, y+0.3*fontDescent}, {cells*cellSize.width, 2} }; + CGContextSetRGBFillColor(context, RED(sp), GREEN(sp), BLUE(sp), + ALPHA(sp)); + CGContextFillRect(context, rect); } else if (flags & DRAW_UNDERC) { // Draw curly underline int k; diff --git a/src/MacVim/MMTextStorage.m b/src/MacVim/MMTextStorage.m index e81f6769..686f8009 100644 --- a/src/MacVim/MMTextStorage.m +++ b/src/MacVim/MMTextStorage.m @@ -54,6 +54,7 @@ #define DRAW_ITALIC 0x10 /* draw italic text */ #define DRAW_CURSOR 0x20 #define DRAW_WIDE 0x40 /* draw wide text */ +#define DRAW_TUNDERL 0x100 /* draw thick underline text */ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; @@ -304,6 +305,12 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; [attributes setObject:value forKey:NSUnderlineStyleAttributeName]; } + if (flags & DRAW_TUNDERL) { + NSNumber *value = [NSNumber numberWithInt:(NSUnderlineStyleThick + | NSUnderlinePatternSolid)]; // | NSUnderlineByWordMask + [attributes setObject:value forKey:NSUnderlineStyleAttributeName]; + } + if (flags & DRAW_UNDERC) { // TODO: figure out how do draw proper undercurls NSNumber *value = [NSNumber numberWithInt:(NSUnderlineStyleThick diff --git a/src/gui.c b/src/gui.c index f727bf30..db52d52a 100644 --- a/src/gui.c +++ b/src/gui.c @@ -2220,6 +2220,12 @@ gui_outstr_nowrap(s, len, flags, fg, bg, back) /* Do we underline the text? */ if (hl_mask_todo & HL_UNDERLINE) draw_flags |= DRAW_UNDERL; + +# if defined(FEAT_GUI_MACVIM) + /* Do we thick underline the text? */ + if (hl_mask_todo & HL_THICKUNDERLINE) + draw_flags |= DRAW_TUNDERL; +# endif #else /* Do we underline the text? */ if ((hl_mask_todo & HL_UNDERLINE) diff --git a/src/gui.h b/src/gui.h index edbaeb0c..4c1363ad 100644 --- a/src/gui.h +++ b/src/gui.h @@ -158,6 +158,7 @@ #define DRAW_CURSOR 0x20 /* drawing block cursor (win32) */ #define DRAW_WIDE 0x40 /* drawing wide char (MacVim) */ #define DRAW_COMP 0x80 /* drawing composing char (MacVim) */ +#define DRAW_TUNDERL 0x100 /* drawing thick underline text (MacVim) */ /* For our own tearoff menu item */ #define TEAR_STRING "-->Detach" diff --git a/src/mbyte.c b/src/mbyte.c index 9ecf8039..6674f84e 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4251,6 +4251,7 @@ init_preedit_start_col(void) static int im_is_active = FALSE; /* IM is enabled for current mode */ static int preedit_is_active = FALSE; +static int im_preedit_start = 0; /* start offset in characters */ static int im_preedit_cursor = 0; /* cursor offset in characters */ static int im_preedit_trailing = 0; /* number of characters after cursor */ @@ -4609,7 +4610,7 @@ im_preedit_abandon_macvim() im_preedit_changed_cb(GtkIMContext *context, gpointer data UNUSED) # else void -im_preedit_changed_macvim(char *preedit_string, int cursor_index) +im_preedit_changed_macvim(char *preedit_string, int start_index, int cursor_index) # endif { # ifndef FEAT_GUI_MACVIM @@ -4625,6 +4626,8 @@ im_preedit_changed_macvim(char *preedit_string, int cursor_index) gtk_im_context_get_preedit_string(context, &preedit_string, NULL, &cursor_index); +# else + im_preedit_start = start_index; # endif #ifdef XIM_DEBUG @@ -4797,7 +4800,10 @@ im_get_feedback_attr(int col) return char_attr; # else - return HL_UNDERLINE; + if (col >= im_preedit_start && col < im_preedit_cursor) + return HL_THICKUNDERLINE; + else + return HL_UNDERLINE; # endif } diff --git a/src/vim.h b/src/vim.h index 16858bf5..ce5633f7 100644 --- a/src/vim.h +++ b/src/vim.h @@ -613,7 +613,12 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname); #define HL_UNDERLINE 0x08 #define HL_UNDERCURL 0x10 #define HL_STANDOUT 0x20 -#define HL_ALL 0x3f +#if defined(FEAT_GUI_MACVIM) +# define HL_THICKUNDERLINE 0x40 +# define HL_ALL 0x7f +#else +# define HL_ALL 0x3f +#endif /* special attribute addition: Put message in history */ #define MSG_HIST 0x1000 -- 2.11.4.GIT