diff --git a/MMBackend.m b/MMBackend.m index 2456ff1d4b..d1b4959119 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -84,6 +84,13 @@ static int eventButtonNumberToVimMouseButton(int buttonNumber); { defaultBackgroundColor = bg; defaultForegroundColor = fg; + + NSMutableData *data = [NSMutableData data]; + + [data appendBytes:&bg length:sizeof(int)]; + [data appendBytes:&fg length:sizeof(int)]; + + [self queueMessage:SetDefaultColorsMsgID data:data]; } - (BOOL)checkin diff --git a/MMTextStorage.h b/MMTextStorage.h index 922e0bb8fd..db2b863f8f 100644 --- a/MMTextStorage.h +++ b/MMTextStorage.h @@ -17,6 +17,7 @@ int maxRows, maxColumns; NSAttributedString *emptyRowString; NSFont *font; + NSColor *defaultBackgroundColor; //NSMutableParagraphStyle *paragraphStyle; } @@ -43,6 +44,8 @@ - (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2 column:(int)col2 color:(NSColor *)color; - (void)clearAllWithColor:(NSColor *)color; +- (void)setDefaultColorsBackground:(NSColor *)bgColor + foreground:(NSColor *)fgColor; - (void)setFont:(NSFont*)newFont; - (NSFont*)font; - (float)widthOfEmptyRow; diff --git a/MMTextStorage.m b/MMTextStorage.m index 13315018ef..2bb207b28f 100644 --- a/MMTextStorage.m +++ b/MMTextStorage.m @@ -59,6 +59,7 @@ [emptyRowString release]; //[paragraphStyle release]; [font release]; + [defaultBackgroundColor release]; [attribString release]; [super dealloc]; } @@ -130,9 +131,15 @@ NSString *fmt = [NSString stringWithFormat:@"%%%dc\%C", maxColumns, NSLineSeparatorCharacter]; - NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - nil]; + NSDictionary *dict; + if (defaultBackgroundColor) { + dict = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + defaultBackgroundColor, NSBackgroundColorAttributeName, nil]; + } else { + dict = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, nil]; + } [emptyRowString release]; emptyRowString = [[NSAttributedString alloc] @@ -359,6 +366,31 @@ [self edited:NSTextStorageEditedAttributes range:range changeInLength:0]; } +- (void)setDefaultColorsBackground:(NSColor *)bgColor + foreground:(NSColor *)fgColor +{ + // NOTE: Foreground color is ignored. + [defaultBackgroundColor release]; + +#if 0 + if (bgColor) { + defaultBackgroundColor = [bgColor retain]; +#if 1 + NSMutableAttributedString *string = [emptyRowString mutableCopy]; + [string addAttribute:NSBackgroundColorAttributeName value:bgColor + range:NSMakeRange(0, [emptyRowString length])]; + [emptyRowString release]; + emptyRowString = string; +#endif + [self clearAllWithColor:bgColor]; + } else { + defaultBackgroundColor = nil; + } +#else + defaultBackgroundColor = bgColor ? [bgColor retain] : nil; +#endif +} + - (void)setFont:(NSFont*)newFont { #if 0 @@ -374,7 +406,7 @@ changeInLength:0]; } #else - if (font != newFont) { + if (newFont && font != newFont) { //NSLog(@"Setting font %@", newFont); [font release]; font = [newFont retain]; diff --git a/MMVimController.m b/MMVimController.m index 85864b62c7..fe84934d57 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -650,6 +650,17 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) } [name release]; + } else if (SetDefaultColorsMsgID == msgid) { + const void *bytes = [data bytes]; + int bg = *((int*)bytes); bytes += sizeof(int); + int fg = *((int*)bytes); bytes += sizeof(int); + + MMTextStorage *textStorage = [windowController textStorage]; + if (textStorage) { + [textStorage + setDefaultColorsBackground:[NSColor colorWithRgbInt:bg] + foreground:[NSColor colorWithRgbInt:fg]]; + } } else { NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid); } diff --git a/MacVim.h b/MacVim.h index 2945850216..a984419c48 100644 --- a/MacVim.h +++ b/MacVim.h @@ -81,6 +81,7 @@ enum { ScrollbarEventMsgID, SetFontMsgID, VimShouldCloseMsgID, + SetDefaultColorsMsgID, }; diff --git a/gui_macvim.m b/gui_macvim.m index 21bf4cf8f9..0f78d5fab9 100644 --- a/gui_macvim.m +++ b/gui_macvim.m @@ -83,9 +83,7 @@ gui_mch_init(void) gui.char_width = 1; gui.char_ascent = 0; - // Default foreground and background colors are black and white. - gui.def_norm_pixel = gui.norm_pixel = 0; - gui.def_back_pixel = gui.back_pixel = 0xffffff; + gui_mch_def_colors(); [[MMBackend sharedInstance] setDefaultColorsBackground:gui.back_pixel foreground:gui.norm_pixel]; @@ -1060,6 +1058,15 @@ gui_mch_new_colors(void) } + void +gui_mch_def_colors() +{ + // Default foreground and background colors are black and white. + gui.def_norm_pixel = gui.norm_pixel = 0; + gui.def_back_pixel = gui.back_pixel = 0xffffff; +} + + /* * Set the current text background color. */