diff --git a/MMBackend.h b/MMBackend.h index cee40ad813..a7767aca80 100644 --- a/MMBackend.h +++ b/MMBackend.h @@ -31,11 +31,11 @@ NSDictionary *sysColorDict; BOOL inputReceived; BOOL tabBarVisible; - int backgroundColor; - int foregroundColor; - int specialColor; - int defaultBackgroundColor; - int defaultForegroundColor; + unsigned backgroundColor; + unsigned foregroundColor; + unsigned specialColor; + unsigned defaultBackgroundColor; + unsigned defaultForegroundColor; NSDate *lastFlushDate; id dialogReturn; NSTimer *blinkTimer; diff --git a/MMBackend.m b/MMBackend.m index 74f3766249..7978b1fcba 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -12,6 +12,13 @@ +// NOTE: Colors in MMBackend are stored as unsigned ints on the form 0xaarrggbb +// whereas colors in Vim are int without the alpha component. +#define MM_COLOR(col) ((unsigned)( ((col)&0xffffff) | 0xff000000 )) +#define MM_COLOR_WITH_TRANSP(col,transp) \ + ((unsigned)( ((col)&0xffffff) | (((unsigned)(255-(transp))&0xff)<<24) )) + + // This constant controls how often the command queue may be flushed. If it is // too small the app might feel unresponsive; if it is too large there might be // long periods without the screen updating (e.g. when sourcing a large session @@ -135,28 +142,28 @@ enum { - (void)setBackgroundColor:(int)color { - backgroundColor = color; + backgroundColor = MM_COLOR_WITH_TRANSP(color,p_transp); } - (void)setForegroundColor:(int)color { - foregroundColor = color; + foregroundColor = MM_COLOR(color); } - (void)setSpecialColor:(int)color { - specialColor = color; + specialColor = MM_COLOR(color); } - (void)setDefaultColorsBackground:(int)bg foreground:(int)fg { - defaultBackgroundColor = bg; - defaultForegroundColor = fg; + defaultBackgroundColor = MM_COLOR_WITH_TRANSP(bg,p_transp); + defaultForegroundColor = MM_COLOR(fg); NSMutableData *data = [NSMutableData data]; - [data appendBytes:&bg length:sizeof(int)]; - [data appendBytes:&fg length:sizeof(int)]; + [data appendBytes:&defaultBackgroundColor length:sizeof(unsigned)]; + [data appendBytes:&defaultForegroundColor length:sizeof(unsigned)]; [self queueMessage:SetDefaultColorsMsgID data:data]; } @@ -272,7 +279,7 @@ enum { [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&defaultBackgroundColor length:sizeof(int)]; + [drawData appendBytes:&defaultBackgroundColor length:sizeof(unsigned)]; } - (void)clearBlockFromRow:(int)row1 column:(int)col1 @@ -282,7 +289,7 @@ enum { [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&defaultBackgroundColor length:sizeof(int)]; + [drawData appendBytes:&defaultBackgroundColor length:sizeof(unsigned)]; [drawData appendBytes:&row1 length:sizeof(int)]; [drawData appendBytes:&col1 length:sizeof(int)]; [drawData appendBytes:&row2 length:sizeof(int)]; @@ -296,7 +303,7 @@ enum { [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&defaultBackgroundColor length:sizeof(int)]; + [drawData appendBytes:&defaultBackgroundColor length:sizeof(unsigned)]; [drawData appendBytes:&row length:sizeof(int)]; [drawData appendBytes:&count length:sizeof(int)]; [drawData appendBytes:&bottom length:sizeof(int)]; @@ -313,9 +320,9 @@ enum { [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&backgroundColor length:sizeof(int)]; - [drawData appendBytes:&foregroundColor length:sizeof(int)]; - [drawData appendBytes:&specialColor length:sizeof(int)]; + [drawData appendBytes:&backgroundColor length:sizeof(unsigned)]; + [drawData appendBytes:&foregroundColor length:sizeof(unsigned)]; + [drawData appendBytes:&specialColor length:sizeof(unsigned)]; [drawData appendBytes:&row length:sizeof(int)]; [drawData appendBytes:&col length:sizeof(int)]; [drawData appendBytes:&flags length:sizeof(int)]; @@ -330,7 +337,7 @@ enum { [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&defaultBackgroundColor length:sizeof(int)]; + [drawData appendBytes:&defaultBackgroundColor length:sizeof(unsigned)]; [drawData appendBytes:&row length:sizeof(int)]; [drawData appendBytes:&count length:sizeof(int)]; [drawData appendBytes:&bottom length:sizeof(int)]; @@ -342,10 +349,11 @@ enum { fraction:(int)percent color:(int)color { int type = DrawCursorDrawType; + unsigned uc = MM_COLOR(color); [drawData appendBytes:&type length:sizeof(int)]; - [drawData appendBytes:&color length:sizeof(int)]; + [drawData appendBytes:&uc length:sizeof(unsigned)]; [drawData appendBytes:&row length:sizeof(int)]; [drawData appendBytes:&col length:sizeof(int)]; [drawData appendBytes:&shape length:sizeof(int)]; diff --git a/MMTextStorage.m b/MMTextStorage.m index 89de6b8f0f..1bfb77ed54 100644 --- a/MMTextStorage.m +++ b/MMTextStorage.m @@ -292,14 +292,20 @@ srcRange.location += maxColumns+1; } + NSRange emptyRange = {0,width}; + NSAttributedString *emptyString = + [emptyRowString attributedSubstringFromRange: emptyRange]; + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; + for (i = 0; i < count; ++i) { - NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - color, NSForegroundColorAttributeName, - color, NSBackgroundColorAttributeName, nil]; + [attribString replaceCharactersInRange:destRange + withAttributedString:emptyString]; [attribString setAttributes:attribs range:destRange]; - [self edited:NSTextStorageEditedAttributes range:destRange - changeInLength:0]; + [self edited:(NSTextStorageEditedAttributes + | NSTextStorageEditedCharacters) range:destRange + changeInLength:0]; destRange.location += maxColumns+1; } } @@ -339,15 +345,21 @@ destRange.location -= maxColumns+1; srcRange.location -= maxColumns+1; } - + + NSRange emptyRange = {0,width}; + NSAttributedString *emptyString = + [emptyRowString attributedSubstringFromRange:emptyRange]; + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; + for (i = 0; i < count; ++i) { - NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - color, NSForegroundColorAttributeName, - color, NSBackgroundColorAttributeName, nil]; + [attribString replaceCharactersInRange:destRange + withAttributedString:emptyString]; [attribString setAttributes:attribs range:destRange]; - [self edited:NSTextStorageEditedAttributes range:destRange - changeInLength:0]; + [self edited:(NSTextStorageEditedAttributes + | NSTextStorageEditedCharacters) range:destRange + changeInLength:0]; destRange.location -= maxColumns+1; } } @@ -368,16 +380,21 @@ NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, - color, NSForegroundColorAttributeName, color, NSBackgroundColorAttributeName, nil]; NSRange range = { row1*(maxColumns+1) + col1, col2-col1+1 }; - + + NSRange emptyRange = {0,col2-col1+1}; + NSAttributedString *emptyString = + [emptyRowString attributedSubstringFromRange:emptyRange]; int r; for (r=row1; r<=row2; ++r) { + [attribString replaceCharactersInRange:range + withAttributedString:emptyString]; [attribString setAttributes:attribs range:range]; - [self edited:NSTextStorageEditedAttributes range:range - changeInLength:0]; + [self edited:(NSTextStorageEditedAttributes + | NSTextStorageEditedCharacters) range:range + changeInLength:0]; range.location += maxColumns+1; } } @@ -385,14 +402,23 @@ - (void)clearAllWithColor:(NSColor *)color { //NSLog(@"%s%@", _cmd, color); + [self lazyResize]; + + [attribString release]; + attribString = [[NSMutableAttributedString alloc] init]; + NSRange fullRange = NSMakeRange(0, [attribString length]); + + int i; + for (i=0; i>16) & 0xff)/255.0f; float g = ((rgb>>8) & 0xff)/255.0f; @@ -1253,6 +1254,16 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f]; } ++ (NSColor *)colorWithArgbInt:(unsigned)argb +{ + float a = ((argb>>24) & 0xff)/255.0f; + float r = ((argb>>16) & 0xff)/255.0f; + float g = ((argb>>8) & 0xff)/255.0f; + float b = (argb & 0xff)/255.0f; + + return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a]; +} + @end // NSColor (MMProtocol) diff --git a/MMWindowController.m b/MMWindowController.m index d91e023bd3..edac1ac21d 100644 --- a/MMWindowController.m +++ b/MMWindowController.m @@ -90,6 +90,12 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) } #endif +// Note: This hack allows us to set content shadowing separately from +// the window shadow. This is apparently what webkit and terminal do. +@interface NSWindow (NSWindowPrivate) // new Tiger private method +- (void) _setContentHasShadow:(BOOL)shadow; +@end + @implementation MMWindowController @@ -127,7 +133,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) [textStorage addLayoutManager:lm]; [lm addTextContainer:tc]; - NSView *contentView = [[self window] contentView]; + NSWindow *win = [self window]; + NSView *contentView = [win contentView]; textView = [[MMTextView alloc] initWithFrame:[contentView frame] textContainer:tc]; @@ -185,8 +192,12 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) [contentView addSubview:tabBarControl]; [contentView addSubview:tablineSeparator]; - [[self window] setDelegate:self]; - [[self window] setInitialFirstResponder:textView]; + [win setDelegate:self]; + [win setInitialFirstResponder:textView]; + + // Make us safe on pre-tiger OSX + if ([win respondsToSelector:@selector(_setContentHasShadow:)]) + [win _setContentHasShadow:NO]; } return self; @@ -444,6 +455,11 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) - (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore { + // NOTE: This is called when the transparency changes so set the opacity + // flag on the window here (should be faster if the window is opaque). + BOOL isOpaque = [back alphaComponent] == 1.0f; + [[self window] setOpaque:isOpaque]; + [textStorage setDefaultColorsBackground:back foreground:fore]; [textView setBackgroundColor:back]; }