diff --git a/src/MacVim/MMAtsuiTextView.h b/src/MacVim/MMAtsuiTextView.h index 47e6cc2e9d..7006093c8f 100644 --- a/src/MacVim/MMAtsuiTextView.h +++ b/src/MacVim/MMAtsuiTextView.h @@ -68,6 +68,7 @@ enum { MMMaxCellsPerChar = 2 }; // // MMTextView methods // +- (void)deleteSign:(NSString *)signName; - (void)setPreEditRow:(int)row column:(int)col; - (void)setMouseShape:(int)shape; - (void)setAntialias:(BOOL)state; diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index 3137ea2cbe..ae7d070bd1 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -336,6 +336,10 @@ defaultLineHeightForFont(NSFont *font) { } +- (void)deleteSign:(NSString *)signName +{ +} + - (void)setPreEditRow:(int)row column:(int)col { [helper setPreEditRow:row column:col]; diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index ac9499ca3b..2bf4b070cd 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -85,6 +85,11 @@ fraction:(int)percent color:(int)color; - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nr numColumns:(int)nc invert:(int)invert; +- (void)drawSign:(NSString *)imgName + atRow:(int)row + column:(int)col + width:(int)width + height:(int)height; - (void)update; - (void)flushQueue:(BOOL)force; - (BOOL)waitForInput:(int)milliseconds; diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 416ba42cbe..cff2f276b2 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -589,6 +589,26 @@ extern GuiFont gui_mch_retain_font(GuiFont font); [drawData appendBytes:&invert length:sizeof(int)]; } +- (void)drawSign:(NSString *)imgName + atRow:(int)row + column:(int)col + width:(int)width + height:(int)height +{ + int type = DrawSignDrawType; + [drawData appendBytes:&type length:sizeof(int)]; + + const char* utf8String = [imgName UTF8String]; + int strSize = (int)strlen(utf8String) + 1; + [drawData appendBytes:&strSize length:sizeof(int)]; + [drawData appendBytes:utf8String length:strSize]; + + [drawData appendBytes:&col length:sizeof(int)]; + [drawData appendBytes:&row length:sizeof(int)]; + [drawData appendBytes:&width length:sizeof(int)]; + [drawData appendBytes:&height length:sizeof(int)]; +} + - (void)update { // Keep running the run-loop until there is no more input to process. diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index 2423c3ef6f..1254e86d13 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -66,6 +66,7 @@ // // MMTextView methods // +- (void)deleteSign:(NSString *)signName; - (void)setShouldDrawInsertionPoint:(BOOL)on; - (void)setPreEditRow:(int)row column:(int)col; - (void)setMouseShape:(int)shape; diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 069e4c4e2e..853eb807be 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -47,14 +47,6 @@ #define DRAW_CURSOR 0x20 #define DRAW_WIDE 0x40 /* draw wide text */ - -#define BLUE(argb) ((argb & 0xff)/255.0f) -#define GREEN(argb) (((argb>>8) & 0xff)/255.0f) -#define RED(argb) (((argb>>16) & 0xff)/255.0f) -#define ALPHA(argb) (((argb>>24) & 0xff)/255.0f) - - - @interface MMCoreTextView (Private) - (MMWindowController *)windowController; - (MMVimController *)vimController; @@ -377,6 +369,11 @@ defaultAdvanceForFont(CTFontRef fontRef) +- (void)deleteSign:(NSString *)signName +{ + [helper deleteImage:signName]; +} + - (void)setShouldDrawInsertionPoint:(BOOL)on { } @@ -907,6 +904,26 @@ defaultAdvanceForFont(CTFontRef fontRef) [self deleteLinesFromRow:row lineCount:count scrollBottom:bot left:left right:right color:color]; + } else if (DrawSignDrawType == type) { + int strSize = *((int*)bytes); bytes += sizeof(int); + NSString *imgName = + [NSString stringWithUTF8String:(const char*)bytes]; + bytes += strSize; + + int col = *((int*)bytes); bytes += sizeof(int); + int row = *((int*)bytes); bytes += sizeof(int); + int width = *((int*)bytes); bytes += sizeof(int); + int height = *((int*)bytes); bytes += sizeof(int); + + NSImage *signImg = [helper signImageForName:imgName]; + NSRect r = [self rectForRow:row + column:col + numRows:height + numColumns:width]; + [signImg drawInRect:r + fromRect:NSZeroRect + operation:NSCompositeSourceOver + fraction:1.0]; } else if (DrawStringDrawType == type) { int bg = *((int*)bytes); bytes += sizeof(int); int fg = *((int*)bytes); bytes += sizeof(int); diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index 910fbeb3ba..65cbfd9397 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -59,10 +59,10 @@ - (NSSize)desiredSize; - (NSSize)minSize; - - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column; - (NSPoint)pointForRow:(int)row column:(int)col; - (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr numColumns:(int)nc; +- (void)deleteSign:(NSString *)signName; @end diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 569c8dd165..e96c5478de 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -492,6 +492,10 @@ return rect; } +- (void)deleteSign:(NSString *)signName +{ +} + - (BOOL)isOpaque { return NO; diff --git a/src/MacVim/MMTextViewHelper.h b/src/MacVim/MMTextViewHelper.h index 715dec6404..61090e5bdc 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -16,6 +16,12 @@ #endif +#define BLUE(argb) ((argb & 0xff)/255.0f) +#define GREEN(argb) (((argb>>8) & 0xff)/255.0f) +#define RED(argb) (((argb>>16) & 0xff)/255.0f) +#define ALPHA(argb) (((argb>>24) & 0xff)/255.0f) + + enum { // These values are chosen so that the min text view size is not too small // with the default font (they only affect resizing with the mouse, you can @@ -38,12 +44,13 @@ enum { NSColor *insertionPointColor; BOOL interpretKeyEventsSwallowedKey; NSEvent *currentEvent; + NSMutableDictionary *signImages; // Input Manager NSRange imRange; NSRange markedRange; NSDictionary *markedTextAttributes; - NSMutableAttributedString *markedText; + NSMutableAttributedString *markedText; int preEditRow; int preEditColumn; BOOL imControl; @@ -54,6 +61,7 @@ enum { #endif } +- (id)init; - (void)setTextView:(id)view; - (void)setInsertionPointColor:(NSColor *)color; - (NSColor *)insertionPointColor; @@ -77,6 +85,8 @@ enum { - (NSDragOperation)draggingUpdated:(id )sender; - (void)setMouseShape:(int)shape; - (void)changeFont:(id)sender; +- (NSImage *)signImageForName:(NSString *)imgName; +- (void)deleteImage:(NSString *)imgName; // Input Manager - (BOOL)hasMarkedText; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index ce7e2984bf..95b86b3a59 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -70,6 +70,16 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) @implementation MMTextViewHelper +- (id)init +{ + if (!(self = [super init])) + return nil; + + signImages = [[NSMutableDictionary alloc] init]; + + return self; +} + - (void)dealloc { ASLogDebug(@""); @@ -77,6 +87,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) [insertionPointColor release]; insertionPointColor = nil; [markedText release]; markedText = nil; [markedTextAttributes release]; markedTextAttributes = nil; + [signImages release]; signImages = nil; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (asciiImSource) { @@ -607,6 +618,26 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) } } +- (NSImage *)signImageForName:(NSString *)imgName +{ + NSImage *img = [signImages objectForKey:imgName]; + if (img) + return img; + + img = [[NSImage alloc] initWithContentsOfFile:imgName]; + if (img) { + [signImages setObject:img forKey:imgName]; + [img autorelease]; + } + + return img; +} + +- (void)deleteImage:(NSString *)imgName +{ + [signImages removeObjectForKey:imgName]; +} + - (BOOL)hasMarkedText { return markedRange.length > 0 ? YES : NO; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index b66b4cf601..d300cd7d90 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -97,6 +97,7 @@ static BOOL isUnsafeMessage(int msgid); - (void)scheduleClose; - (void)handleBrowseForFile:(NSDictionary *)attr; - (void)handleShowDialog:(NSDictionary *)attr; +- (void)handleDeleteSign:(NSDictionary *)attr; @end @@ -819,6 +820,10 @@ static BOOL isUnsafeMessage(int msgid); NSDictionary *dict = [NSDictionary dictionaryWithData:data]; if (dict) [self handleShowDialog:dict]; + } else if (DeleteSignMsgID == msgid) { + NSDictionary *dict = [NSDictionary dictionaryWithData:data]; + if (dict) + [self handleDeleteSign:dict]; } else if (ZoomMsgID == msgid) { const void *bytes = [data bytes]; int rows = *((int*)bytes); bytes += sizeof(int); @@ -1438,6 +1443,11 @@ static BOOL isUnsafeMessage(int msgid); [alert release]; } +- (void)handleDeleteSign:(NSDictionary *)attr +{ + MMTextView *view = [[windowController vimView] textView]; + [view deleteSign:[attr objectForKey:@"imgName"]]; +} @end // MMVimController (Private) diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 927a887cc1..0158a60088 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -192,6 +192,7 @@ enum { SetMarkedTextMsgID, ZoomMsgID, SetWindowPositionMsgID, + DeleteSignMsgID, LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM! }; @@ -205,6 +206,7 @@ enum { DrawCursorDrawType, SetCursorPosDrawType, DrawInvertedRectDrawType, + DrawSignDrawType, }; enum { diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index ce060d2494..c9520ebcfe 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -95,6 +95,7 @@ char *MessageStrings[] = "SetMarkedTextMsgID", "ZoomMsgID", "SetWindowPositionMsgID", + "DeleteSignMsgID", "END OF MESSAGE IDs" // NOTE: Must be last! }; diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 4d5e3b96ba..dcd4507610 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -22,6 +22,7 @@ // HACK! Used in gui.c to determine which string drawing code to use. int use_gui_macvim_draw_string = 1; +static int use_graphical_sign = 0; // NOTE: The default font is bundled with the application. static NSString *MMDefaultFontName = @"DejaVu Sans Mono"; @@ -149,6 +150,10 @@ gui_macvim_after_fork_init() if (keyValid) { ASLogInfo(@"Use renderer=%d", val); use_gui_macvim_draw_string = (val != MMRendererCoreText); + + // For now only the Core Text renderer knows how to render graphical + // signs. + use_graphical_sign = (val == MMRendererCoreText); } } @@ -2283,3 +2288,69 @@ gui_macvim_set_netbeans_socket(int socket) } #endif // FEAT_NETBEANS_INTG + + + +// -- Graphical Sign Support ------------------------------------------------ + +#if defined(FEAT_SIGN_ICONS) + void +gui_mch_drawsign(int row, int col, int typenr) +{ + if (!gui.in_use) + return; + + NSString *imgName = (NSString *)sign_get_image(typenr); + if (!imgName) + return; + + char_u *txt = sign_get_text(typenr); + int txtSize = txt ? strlen((char*)txt) : 2; + + [[MMBackend sharedInstance] drawSign:imgName + atRow:row + column:col + width:txtSize + height:1]; +} + + void * +gui_mch_register_sign(char_u *signfile) +{ + if (!use_graphical_sign) + return NULL; + + NSString *imgName = [NSString stringWithVimString:signfile]; + NSImage *img = [[NSImage alloc] initWithContentsOfFile:imgName]; + if (!img) { + EMSG(_(e_signdata)); + return NULL; + } + + [img release]; + + return (void*)[imgName retain]; +} + + void +gui_mch_destroy_sign(void *sign) +{ + NSString *imgName = (NSString *)sign; + if (!imgName) + return; + + [[MMBackend sharedInstance] + queueMessage:DeleteSignMsgID + properties:[NSDictionary dictionaryWithObjectsAndKeys: + imgName, @"imgName", nil]]; + [imgName release]; +} + +# ifdef FEAT_NETBEANS_INTG + void +netbeans_draw_multisign_indicator(int row) +{ +} +# endif // FEAT_NETBEANS_INTG + +#endif // FEAT_SIGN_ICONS diff --git a/src/feature.h b/src/feature.h index a7663d887a..38d7721f17 100644 --- a/src/feature.h +++ b/src/feature.h @@ -1227,6 +1227,7 @@ # if ((defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) \ && defined(HAVE_X11_XPM_H)) \ || defined(FEAT_GUI_GTK) \ + || defined(FEAT_GUI_MACVIM) \ || (defined(WIN32) && defined(FEAT_GUI)) # define FEAT_SIGN_ICONS # endif diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index a8947ae103..111424e2aa 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -224,3 +224,13 @@ im_set_control(int enable); void gui_macvim_set_netbeans_socket(int socket); + + void +gui_mch_drawsign(int row, int col, int typenr); + + void * +gui_mch_register_sign(char_u *signfile); + + void +gui_mch_destroy_sign(void *sign); +