From 98aaa0f90f2520ba0662ae5c909d1d8adc4bc490 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 30 Jul 2012 01:05:30 +0000 Subject: - Fix custom selection colours using a translucent colour being blended through to black or the window background, addressing incorrect colours in the Custom Query view when using selection colours with alpha values and window backgrounds showing through CREATE SYNTAX sheets (Issue #1099) - Fix crashes when editing certain colours in editor preferences after a window had been closed, due to not unregistering all observers on SPTextView dealloc - Enable "Draws Background" on the main Custom Query view text view, as custom colours were no longer being drawn after a change in r3750 --- Interfaces/English.lproj/DBView.xib | 103 ++++++++++++++++-------------------- Source/SPTextView.m | 67 ++++++++++++++++++----- 2 files changed, 100 insertions(+), 70 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index e52bcecf..55736cbd 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,6 +23,7 @@ YES + YES @@ -46,7 +47,7 @@ NSApplication - + 274 YES @@ -202,6 +203,7 @@ {{1, 1}, {218, 38}} + 6 @@ -233,6 +235,7 @@ {{-1, -13}, {220, 40}} + 133122 @@ -397,6 +400,7 @@ {214, 352} + 4 @@ -424,6 +428,7 @@ {214, 352} + 133648 @@ -527,6 +532,7 @@ {216, 146} + 6 @@ -553,6 +559,7 @@ {{-1, 0}, {216, 146}} + 133648 @@ -638,6 +645,7 @@ {214, 146} + 6 @@ -665,6 +673,7 @@ {214, 146} + 133632 @@ -3254,7 +3263,7 @@ customQuery - + 256 YES @@ -3449,6 +3458,29 @@ 6418 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {97, 14} @@ -3471,7 +3503,7 @@ 1 - 100691043 + 100691299 0 @@ -4351,7 +4383,7 @@ 2322 - {222, 14} + {222, 13} @@ -4553,6 +4585,7 @@ {{10, 7}, {705, 544}} + Custom Query @@ -5513,7 +5546,7 @@ relations - + 256 YES @@ -5731,6 +5764,7 @@ {{1.5, 17}, {693, 454}} + 2 @@ -5763,6 +5797,7 @@ {{1.5, 0}, {693, 17}} + 4 @@ -5770,6 +5805,7 @@ {{6, 33}, {695, 472}} + 133682 @@ -5887,7 +5923,6 @@ {{10, 7}, {705, 544}} - Relations @@ -6333,14 +6368,14 @@ - + 134217731 YES YES YES - + @@ -6356,6 +6391,7 @@ {943, 549} + NSView @@ -9727,9 +9763,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSPanel + {1.7976931348623157e+308, 1.7976931348623157e+308} {600, 317} - + 256 YES @@ -9758,7 +9795,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 274 {752, 125} - _NS:1843 YES @@ -9766,7 +9802,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {752, 17} - _NS:1845 @@ -9827,7 +9862,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 17}, {752, 125}} - _NS:1841 @@ -9839,7 +9873,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{224, 17}, {15, 102}} - _NS:1860 _doScroller: @@ -9851,7 +9884,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{1, 95.8515625}, {751.61328125, 15}} - _NS:1862 1 @@ -9867,7 +9899,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {752, 17} - _NS:1846 @@ -9877,7 +9908,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {752, 142} - _NS:1839 133680 @@ -9890,7 +9920,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {752, 141} - _NS:1082 NSView @@ -9904,7 +9933,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{554, 19}, {181, 14}} - _NS:4068 YES @@ -9931,7 +9959,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{678, 35}, {55, 16}} - _NS:610 YES @@ -9958,7 +9985,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{537, 37}, {137, 14}} - _NS:4068 YES @@ -9977,7 +10003,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{537, 59}, {197, 18}} - _NS:682 YES @@ -10002,7 +10027,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{537, 79}, {197, 18}} - _NS:682 YES @@ -10027,7 +10051,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 265 {{537, 99}, {197, 18}} - _NS:682 YES @@ -10095,7 +10118,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {480, 14} - @@ -10161,7 +10183,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {480, 71} - @@ -10173,7 +10194,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{464, 1}, {15, 91}} - _doScroller: 1 @@ -10184,7 +10204,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{1, 57.015625}, {481.71875, 15}} - 1 _doScroller: @@ -10194,7 +10213,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{18, 14}, {480, 71}} - 133680 @@ -10204,13 +10222,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{1, 1}, {516, 95}} - _NS:21 {{17, 16}, {518, 111}} - _NS:18 {0, 0} @@ -10233,14 +10249,12 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 142}, {752, 135}} - _NS:1084 NSView {{0, 40}, {752, 277}} - _NS:1080 2 @@ -10249,7 +10263,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 289 {{595, 12}, {143, 32}} - _NS:610 YES @@ -10273,7 +10286,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 292 {{14, 12}, {216, 32}} - _NS:610 YES @@ -10297,7 +10309,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 289 {{452, 12}, {143, 32}} - _NS:610 YES @@ -10318,8 +10329,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {752, 317} - - _NS:103 {{0, 0}, {1440, 878}} @@ -10340,7 +10349,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {251, 102} {251, 102} - + 256 YES @@ -10349,7 +10358,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 289 {{140, 13}, {96, 28}} - 1 YES @@ -10371,7 +10379,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 257 {{46, 13}, {96, 28}} - YES 67239424 @@ -10392,7 +10399,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 268 {{17, 76}, {208, 14}} - YES 68288064 @@ -10409,7 +10415,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 266 {{20, 51}, {214, 22}} - YES 343014976 @@ -10486,7 +10491,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 292 {{17, 14}, {25, 25}} - YES 67239424 @@ -10504,8 +10508,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {251, 102} - - {{0, 0}, {1920, 1058}} {251, 124} @@ -11300,10 +11302,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSView - - YES - FilterTableDefaultOperator - YES @@ -30540,7 +30538,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 setDefaultOperator: showDefaultOperaterHelp: showFilterTable: - swapFilterTable: tableFilterClear: toggleDistinctSelect: toggleFilterField: @@ -30566,7 +30563,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id - id NSButton @@ -30585,7 +30581,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 setDefaultOperator: showDefaultOperaterHelp: showFilterTable: - swapFilterTable: tableFilterClear: toggleDistinctSelect: toggleFilterField: @@ -30639,10 +30634,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 showFilterTable: id - - swapFilterTable: - id - tableFilterClear: id diff --git a/Source/SPTextView.m b/Source/SPTextView.m index e3d3d70c..44ee35d1 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -94,7 +94,13 @@ YY_BUFFER_STATE yy_scan_string (const char *); #pragma mark - +@interface SPTextView (Private_API) + NSInteger _alphabeticSort(id string1, id string2, void *reverse); +- (void)_setTextSelectionColor:(NSColor *)newSelectionColor onBackgroundColor:(NSColor *)aBackgroundColor; + +@end + // some helper functions for handling rectangles and points // needed in roundedBezierPathAroundRange: @@ -128,14 +134,6 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS @synthesize mySQLConnection; #endif -/** - * Sort function (mainly used to sort the words in the textView) - */ -NSInteger _alphabeticSort(id string1, id string2, void *reverse) -{ - return [string1 localizedCaseInsensitiveCompare:string2]; -} - - (void) awakeFromNib { #ifndef SP_REFACTOR /* init ivars */ @@ -212,7 +210,8 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [self setTextColor:otherTextColor]; [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCaretColor]]]; [self setShouldHiliteQuery:[prefs boolForKey:SPCustomQueryHighlightCurrentQuery]]; - [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]], NSBackgroundColorAttributeName, nil]]; + + [self _setTextSelectionColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]] onBackgroundColor:backgroundColor]; // Register observers for the when editor background colors preference changes [prefs addObserver:self forKeyPath:SPCustomQueryEditorSelectionColor options:NSKeyValueObservingOptionNew context:NULL]; @@ -264,6 +263,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) NSColor *backgroundColor = [NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]; [self setQueryEditorBackgroundColor:backgroundColor]; [self setBackgroundColor:backgroundColor]; + [self _setTextSelectionColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorSelectionColor]] onBackgroundColor:backgroundColor]; [self setNeedsDisplayInRect:[self bounds]]; } else if ([keyPath isEqualToString:SPCustomQueryEditorFont]) { [self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; @@ -275,7 +275,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [self setInsertionPointColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; [self setNeedsDisplayInRect:[self bounds]]; } else if ([keyPath isEqualToString:SPCustomQueryEditorSelectionColor]) { - [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]], NSBackgroundColorAttributeName, nil]]; + [self _setTextSelectionColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] onBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]]; [self setNeedsDisplayInRect:[self bounds]]; } else if ([keyPath isEqualToString:SPCustomQueryHighlightCurrentQuery]) { [self setShouldHiliteQuery:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]]; @@ -2990,7 +2990,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if([[self delegate] isKindOfClass:[SPCustomQuery class]]) { - // Highlightes the current query if set in the Pref and no snippet session + // Highlights the current query if set in the Pref and no snippet session // and if nothing is selected in the text view if ([self shouldHiliteQuery] && snippetControlCounter<=-1 && ![self selectedRange].length && [[self string] length] < SP_MAX_TEXT_SIZE_FOR_SYNTAX_HIGHLIGHTING) { NSUInteger rectCount; @@ -3668,9 +3668,6 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) #endif } -#pragma mark - - - #pragma mark - - (void) dealloc @@ -3682,6 +3679,8 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // Remove observers [[NSNotificationCenter defaultCenter] removeObserver:self]; #ifndef SP_REFACTOR + [prefs removeObserver:self forKeyPath:SPCustomQueryEditorSelectionColor]; + [prefs removeObserver:self forKeyPath:SPCustomQueryEditorCaretColor]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorFont]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorBackgroundColor]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorHighlightQueryColor]; @@ -3715,3 +3714,43 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) } @end + +#pragma mark - +#pragma mark Private API + +@implementation SPTextView (Private_API) + +/** + * Sort function (mainly used to sort the words in the textView) + */ +NSInteger _alphabeticSort(id string1, id string2, void *reverse) +{ + return [string1 localizedCaseInsensitiveCompare:string2]; +} + +/** + * Take a supplied text selection colour, and if it contains an alpha component, + * pre-multiply it by the background colour before setting it to avoid drawing problems. + */ +- (void)_setTextSelectionColor:(NSColor *)newSelectionColor onBackgroundColor:(NSColor *)aBackgroundColor +{ + + // If the selection colour has an alpha component, modify it + if ([newSelectionColor alphaComponent] < 1.f) { + NSColorSpace *rgbColorSpace = [NSColorSpace genericRGBColorSpace]; + + newSelectionColor = [newSelectionColor colorUsingColorSpace:rgbColorSpace]; + NSColor *backgroundColor = [[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]] colorUsingColorSpace:rgbColorSpace]; + + CGFloat modifiedRedComponent = ([backgroundColor redComponent] * (1.f - [newSelectionColor alphaComponent])) + ([newSelectionColor redComponent] * [newSelectionColor alphaComponent]); + CGFloat modifiedGreenComponent = ([backgroundColor greenComponent] * (1.f - [newSelectionColor alphaComponent])) + ([newSelectionColor greenComponent] * [newSelectionColor alphaComponent]); + CGFloat modifiedBlueComponent = ([backgroundColor blueComponent] * (1.f - [newSelectionColor alphaComponent])) + ([newSelectionColor blueComponent] * [newSelectionColor alphaComponent]); + newSelectionColor = [NSColor colorWithDeviceRed:modifiedRedComponent green:modifiedGreenComponent blue:modifiedBlueComponent alpha:1.f]; + } + + // Set the selection colour + [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:newSelectionColor, NSBackgroundColorAttributeName, nil]]; +} + +@end + -- cgit v1.2.3