mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-07 15:37:14 +02:00
- Integrated George Harker's transparency patch - Added 'transparency' option
git-svn-id: http://macvim.googlecode.com/svn/trunk@296 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
+5
-5
@@ -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;
|
||||
|
||||
+23
-15
@@ -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)];
|
||||
|
||||
+47
-21
@@ -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<maxRows; ++i)
|
||||
[attribString appendAttributedString:emptyRowString];
|
||||
|
||||
NSRange range = { 0, [attribString length] };
|
||||
NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
font, NSFontAttributeName,
|
||||
color, NSForegroundColorAttributeName,
|
||||
color, NSBackgroundColorAttributeName, nil];
|
||||
[attribString setAttributes:attribs range:range];
|
||||
[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
|
||||
[attribString setAttributes:attribs range:fullRange];
|
||||
|
||||
[self edited:(NSTextStorageEditedCharacters|NSTextStorageEditedAttributes)
|
||||
range:fullRange changeInLength:0];
|
||||
}
|
||||
|
||||
- (void)setDefaultColorsBackground:(NSColor *)bgColor
|
||||
|
||||
@@ -100,6 +100,11 @@ static NSString *MMKeypadEnterString = @"KA";
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
@@ -147,6 +152,22 @@ static NSString *MMKeypadEnterString = @"KA";
|
||||
// NSStringFromRect(ipRect), insertionPointShape,
|
||||
// [self insertionPointColor]);
|
||||
}
|
||||
#if 0
|
||||
// this code invalidates the shadow, so we don't
|
||||
// get shifting ghost text on scroll and resize
|
||||
// but makes speed unusable
|
||||
MMTextStorage *ts = (MMTextStorage*)[self textStorage];
|
||||
if ([ts defaultBackgroundAlpha] < 1.0f) {
|
||||
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_1)
|
||||
{
|
||||
[[self window] setHasShadow:NO];
|
||||
[[self window] setHasShadow:YES];
|
||||
}
|
||||
else
|
||||
[[self window] invalidateShadow];
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
|
||||
+26
-15
@@ -75,7 +75,8 @@ static NSTimeInterval MMResendInterval = 0.5;
|
||||
|
||||
// TODO: Move to separate file
|
||||
@interface NSColor (MMProtocol)
|
||||
+ (NSColor *)colorWithRgbInt:(int)rgb;
|
||||
+ (NSColor *)colorWithRgbInt:(unsigned)rgb;
|
||||
+ (NSColor *)colorWithArgbInt:(unsigned)argb;
|
||||
@end
|
||||
|
||||
|
||||
@@ -728,9 +729,9 @@ 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);
|
||||
NSColor *back = [NSColor colorWithRgbInt:bg];
|
||||
unsigned bg = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
unsigned fg = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
NSColor *back = [NSColor colorWithArgbInt:bg];
|
||||
NSColor *fore = [NSColor colorWithRgbInt:fg];
|
||||
|
||||
[windowController setDefaultColorsBackground:back foreground:fore];
|
||||
@@ -815,14 +816,14 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
int type = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
if (ClearAllDrawType == type) {
|
||||
int color = *((int*)bytes); bytes += sizeof(int);
|
||||
unsigned color = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
|
||||
#if MM_DEBUG_DRAWING
|
||||
NSLog(@" Clear all");
|
||||
#endif
|
||||
[textStorage clearAllWithColor:[NSColor colorWithRgbInt:color]];
|
||||
[textStorage clearAllWithColor:[NSColor colorWithArgbInt:color]];
|
||||
} else if (ClearBlockDrawType == type) {
|
||||
int color = *((int*)bytes); bytes += sizeof(int);
|
||||
unsigned color = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
int row1 = *((int*)bytes); bytes += sizeof(int);
|
||||
int col1 = *((int*)bytes); bytes += sizeof(int);
|
||||
int row2 = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -834,9 +835,9 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
#endif
|
||||
[textStorage clearBlockFromRow:row1 column:col1
|
||||
toRow:row2 column:col2
|
||||
color:[NSColor colorWithRgbInt:color]];
|
||||
color:[NSColor colorWithArgbInt:color]];
|
||||
} else if (DeleteLinesDrawType == type) {
|
||||
int color = *((int*)bytes); bytes += sizeof(int);
|
||||
unsigned color = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int count = *((int*)bytes); bytes += sizeof(int);
|
||||
int bot = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -848,7 +849,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
#endif
|
||||
[textStorage deleteLinesFromRow:row lineCount:count
|
||||
scrollBottom:bot left:left right:right
|
||||
color:[NSColor colorWithRgbInt:color]];
|
||||
color:[NSColor colorWithArgbInt:color]];
|
||||
} else if (ReplaceStringDrawType == type) {
|
||||
int bg = *((int*)bytes); bytes += sizeof(int);
|
||||
int fg = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -882,12 +883,12 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
atRow:row column:col
|
||||
withFlags:flags
|
||||
foregroundColor:[NSColor colorWithRgbInt:fg]
|
||||
backgroundColor:[NSColor colorWithRgbInt:bg]
|
||||
backgroundColor:[NSColor colorWithArgbInt:bg]
|
||||
specialColor:[NSColor colorWithRgbInt:sp]];
|
||||
|
||||
[string release];
|
||||
} else if (InsertLinesDrawType == type) {
|
||||
int color = *((int*)bytes); bytes += sizeof(int);
|
||||
unsigned color = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int count = *((int*)bytes); bytes += sizeof(int);
|
||||
int bot = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -899,9 +900,9 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
#endif
|
||||
[textStorage insertLinesAtRow:row lineCount:count
|
||||
scrollBottom:bot left:left right:right
|
||||
color:[NSColor colorWithRgbInt:color]];
|
||||
color:[NSColor colorWithArgbInt:color]];
|
||||
} else if (DrawCursorDrawType == type) {
|
||||
int color = *((int*)bytes); bytes += sizeof(int);
|
||||
unsigned color = *((unsigned*)bytes); bytes += sizeof(unsigned);
|
||||
int row = *((int*)bytes); bytes += sizeof(int);
|
||||
int col = *((int*)bytes); bytes += sizeof(int);
|
||||
int shape = *((int*)bytes); bytes += sizeof(int);
|
||||
@@ -1244,7 +1245,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
|
||||
@implementation NSColor (MMProtocol)
|
||||
|
||||
+ (NSColor *)colorWithRgbInt:(int)rgb
|
||||
+ (NSColor *)colorWithRgbInt:(unsigned)rgb
|
||||
{
|
||||
float r = ((rgb>>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)
|
||||
|
||||
|
||||
|
||||
+19
-3
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user