Re: NSTextView and changing the selected text's color
On Wed, Jun 11, 2008 at 6:15 PM, Mattias Arrelid [EMAIL PROTECTED] wrote: Hi Douglas, On Wed, Jun 11, 2008 at 5:30 PM, Douglas Davidson [EMAIL PROTECTED] wrote: On Jun 11, 2008, at 3:24 AM, Mattias Arrelid wrote: Haven't anyone stumbled upon something similar, or a solution to this? I believe it was answered. You don't want to use setMarkedTextAttributes:, because marked text is the uncommitted text you see while using an input method. You can use setSelectedTextAttributes: instead. It seems that I forgot to mention that I've tried that without success. I can successfully set the background color of the selection using this (in the initWithFrame: method of my custom text view): NSMutableDictionary *dict = [[[self selectedTextAttributes] mutableCopy] autorelease]; [dict setObject:[NSColor redColor] forKey:NSBackgroundColorAttributeName]; [self setSelectedTextAttributes:dict]; Now, any selected text will have a red background selection. Changing the NSBackgroundColorAttributeName attribute to NSForegroundColorAttributeName makes the selection background color the system's default again, but doesn't affect the color of the selected text. Am I missing something here? Just to test things; I did setup a simple test project, and in there it works just fine setting the foreground color. Back to the debugger to see where that call to setSelectedTextAttributes: is going. Thanks again. / Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
On Thu, Jun 12, 2008 at 11:14 AM, Mattias Arrelid [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 6:15 PM, Mattias Arrelid [EMAIL PROTECTED] wrote: Hi Douglas, On Wed, Jun 11, 2008 at 5:30 PM, Douglas Davidson [EMAIL PROTECTED] wrote: On Jun 11, 2008, at 3:24 AM, Mattias Arrelid wrote: Haven't anyone stumbled upon something similar, or a solution to this? I believe it was answered. You don't want to use setMarkedTextAttributes:, because marked text is the uncommitted text you see while using an input method. You can use setSelectedTextAttributes: instead. It seems that I forgot to mention that I've tried that without success. I can successfully set the background color of the selection using this (in the initWithFrame: method of my custom text view): NSMutableDictionary *dict = [[[self selectedTextAttributes] mutableCopy] autorelease]; [dict setObject:[NSColor redColor] forKey:NSBackgroundColorAttributeName]; [self setSelectedTextAttributes:dict]; Now, any selected text will have a red background selection. Changing the NSBackgroundColorAttributeName attribute to NSForegroundColorAttributeName makes the selection background color the system's default again, but doesn't affect the color of the selected text. Am I missing something here? Just to test things; I did setup a simple test project, and in there it works just fine setting the foreground color. Back to the debugger to see where that call to setSelectedTextAttributes: is going. Sorry for my many replies... It turns out that if you set the NSForegroundColorAttributeName of the attributed string in NSTextView's text storage, the call to setSelectedTextAttributes: doesn't have any effect when called as described below: NSMutableDictionary *dict = [[[textView selectedTextAttributes] mutableCopy] autorelease]; [dict setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; [textView setSelectedTextAttributes:dict]; Setting the background color works fine though. I cannot see anything regarding this limitation in the documentation - is it by design or is it a bug? Best regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
Definitely sounds like a bug - file it anyway, they can only say behaves as expected (and probably will... ;-) I would expect that if I set my foreground text to some pale colour, I could set a different colour for selected text so it has contrast with the background selection colour, not just work for black text. G. On 12 Jun 2008, at 7:47 pm, Mattias Arrelid wrote: Sorry for my many replies... It turns out that if you set the NSForegroundColorAttributeName of the attributed string in NSTextView's text storage, the call to setSelectedTextAttributes: doesn't have any effect when called as described below: NSMutableDictionary *dict = [[[textView selectedTextAttributes] mutableCopy] autorelease]; [dict setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]; [textView setSelectedTextAttributes:dict]; Setting the background color works fine though. I cannot see anything regarding this limitation in the documentation - is it by design or is it a bug? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
On Jun 12, 2008, at 2:47 AM, Mattias Arrelid wrote: It turns out that if you set the NSForegroundColorAttributeName of the attributed string in NSTextView's text storage, the call to setSelectedTextAttributes: doesn't have any effect when called as described below: File a bug and we'll look into it. Douglas Davidson ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
On Thu, Jun 12, 2008 at 5:40 PM, Douglas Davidson [EMAIL PROTECTED] wrote: On Jun 12, 2008, at 2:47 AM, Mattias Arrelid wrote: It turns out that if you set the NSForegroundColorAttributeName of the attributed string in NSTextView's text storage, the call to setSelectedTextAttributes: doesn't have any effect when called as described below: File a bug and we'll look into it. A bug has been filed: rdar://problem/6003324 Regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Fwd: NSTextView and changing the selected text's color
Haven't anyone stumbled upon something similar, or a solution to this? Best regards Mattias -- Forwarded message -- From: Mattias Arrelid [EMAIL PROTECTED] Date: Fri, May 30, 2008 at 1:25 PM Subject: NSTextView and changing the selected text's color To: cocoa-dev@lists.apple.com Hi everyone, We have a subclass of NSTextView (SPTextView). A couple of these have some text with [NSColor grayColor] set as the NSForegroundColorAttributeName. It looks good, but when the user starts selecting text things go bad ™. Since grey on light blue (the default system selection color) isn't very readable one could argue that we should change the selection color. That is pretty straight forward, but we'd rather not mess with this since the user might have her own highlight color set (through System Preferences / Appearance). The next approach would be to use NSTextView's setMarkedTextAttributes:. It takes a dictionary as paramater, with the following restrictions (according to the documentation): A dictionary of attributes used to draw marked text. Text color, background color, and underline are the only supported attributes for marked text.. Regardless of how I try to specify these (I assume the attributes that are valid are NSForegroundColorAttributeName, NSBackgroundColorAttributeName, NSUnderlineColorAttributeName and NSUnderlineStyleAttributeName), that call doesn't affect the view. As a last resort, we could implement setSelectedRange:affinity:stillSelecting: in our NSTextView subclass, and set the foreground color of the selected range... but that would mean that we would have to change it back to whatever color it had before the selection took place. That doesn't feel right. Reading http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html indicates that setMarkedTextAttributes: should do just this, but I cannot seem to get it working. Any suggestions? Best regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
On Jun 11, 2008, at 3:24 AM, Mattias Arrelid wrote: Haven't anyone stumbled upon something similar, or a solution to this? I believe it was answered. You don't want to use setMarkedTextAttributes:, because marked text is the uncommitted text you see while using an input method. You can use setSelectedTextAttributes: instead. Douglas Davidson ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
Hi Douglas, On Wed, Jun 11, 2008 at 5:30 PM, Douglas Davidson [EMAIL PROTECTED] wrote: On Jun 11, 2008, at 3:24 AM, Mattias Arrelid wrote: Haven't anyone stumbled upon something similar, or a solution to this? I believe it was answered. You don't want to use setMarkedTextAttributes:, because marked text is the uncommitted text you see while using an input method. You can use setSelectedTextAttributes: instead. It seems that I forgot to mention that I've tried that without success. I can successfully set the background color of the selection using this (in the initWithFrame: method of my custom text view): NSMutableDictionary *dict = [[[self selectedTextAttributes] mutableCopy] autorelease]; [dict setObject:[NSColor redColor] forKey:NSBackgroundColorAttributeName]; [self setSelectedTextAttributes:dict]; Now, any selected text will have a red background selection. Changing the NSBackgroundColorAttributeName attribute to NSForegroundColorAttributeName makes the selection background color the system's default again, but doesn't affect the color of the selected text. Am I missing something here? Regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
NSTextView and changing the selected text's color
Hi everyone, We have a subclass of NSTextView (SPTextView). A couple of these have some text with [NSColor grayColor] set as the NSForegroundColorAttributeName. It looks good, but when the user starts selecting text things go bad™. Since grey on light blue (the default system selection color) isn't very readable one could argue that we should change the selection color. That is pretty straight forward, but we'd rather not mess with this since the user might have her own highlight color set (through System Preferences / Appearance). The next approach would be to use NSTextView's setMarkedTextAttributes:. It takes a dictionary as paramater, with the following restrictions (according to the documentation): A dictionary of attributes used to draw marked text. Text color, background color, and underline are the only supported attributes for marked text.. Regardless of how I try to specify these (I assume the attributes that are valid are NSForegroundColorAttributeName, NSBackgroundColorAttributeName, NSUnderlineColorAttributeName and NSUnderlineStyleAttributeName), that call doesn't affect the view. As a last resort, we could implement setSelectedRange:affinity:stillSelecting: in our NSTextView subclass, and set the foreground color of the selected range... but that would mean that we would have to change it back to whatever color it had before the selection took place. That doesn't feel right. Reading http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html indicates that setMarkedTextAttributes: should do just this, but I cannot seem to get it working. Any suggestions? Best regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
Instead of NSTextView setMarkedTextAttributes:, I think you want to look at setSelectedTextAttributes:. Marked text refers to text input that is not final. When you type option-e, NSTextView displays an accent glyph with a yellow background. That's marked text. When you type a letter, the the glyph is completed and the yellow marking goes away. Ross On May 30, 2008, at 7:25 AM, Mattias Arrelid wrote: Hi everyone, We have a subclass of NSTextView (SPTextView). A couple of these have some text with [NSColor grayColor] set as the NSForegroundColorAttributeName. It looks good, but when the user starts selecting text things go bad™. Since grey on light blue (the default system selection color) isn't very readable one could argue that we should change the selection color. That is pretty straight forward, but we'd rather not mess with this since the user might have her own highlight color set (through System Preferences / Appearance). The next approach would be to use NSTextView's setMarkedTextAttributes:. It takes a dictionary as paramater, with the following restrictions (according to the documentation): A dictionary of attributes used to draw marked text. Text color, background color, and underline are the only supported attributes for marked text.. Regardless of how I try to specify these (I assume the attributes that are valid are NSForegroundColorAttributeName, NSBackgroundColorAttributeName, NSUnderlineColorAttributeName and NSUnderlineStyleAttributeName), that call doesn't affect the view. As a last resort, we could implement setSelectedRange:affinity:stillSelecting: in our NSTextView subclass, and set the foreground color of the selected range... but that would mean that we would have to change it back to whatever color it had before the selection took place. That doesn't feel right. Reading http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html indicates that setMarkedTextAttributes: should do just this, but I cannot seem to get it working. Any suggestions? Best regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/rosscarter%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSTextView and changing the selected text's color
As for the color choices to use when drawing selected color text, what I've found most readable to my users is to continue using the selection color as chosen by the user but to draw the text shadowed as the Finder does it, with the text being white and the shadow color being the color of the text. So, red text being selected with a blue highlight color would show up as white text, red shadow, drawn on top of a blue field...kind of American patriotic, don't you think? ;-) I've also darkened or lightened the shadow color if it's too close to the highlight color, causing a near-invisible blending; if the highlight color is light, I darken it, but I lighten it if the highlight color is a dark color. Using HSB/HSL helps with this adjustment. This usually works because the colors in my application are used to denote particular states of information and so are typically very different. And, if you want to help out color-blind users (I'd consider the worst case of color blindness), you could use a grayscale check for the near-invisible blending issue. There's no perfect solution to this, but I hope this helps you consider your options. Mattias Arrelid wrote: Hi everyone, We have a subclass of NSTextView (SPTextView). A couple of these have some text with [NSColor grayColor] set as the NSForegroundColorAttributeName. It looks good, but when the user starts selecting text things go bad™. Since grey on light blue (the default system selection color) isn't very readable one could argue that we should change the selection color. That is pretty straight forward, but we'd rather not mess with this since the user might have her own highlight color set (through System Preferences / Appearance). The next approach would be to use NSTextView's setMarkedTextAttributes:. It takes a dictionary as paramater, with the following restrictions (according to the documentation): A dictionary of attributes used to draw marked text. Text color, background color, and underline are the only supported attributes for marked text.. Regardless of how I try to specify these (I assume the attributes that are valid are NSForegroundColorAttributeName, NSBackgroundColorAttributeName, NSUnderlineColorAttributeName and NSUnderlineStyleAttributeName), that call doesn't affect the view. As a last resort, we could implement setSelectedRange:affinity:stillSelecting: in our NSTextView subclass, and set the foreground color of the selected range... but that would mean that we would have to change it back to whatever color it had before the selection took place. That doesn't feel right. Reading http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/SetFocus.html indicates that setMarkedTextAttributes: should do just this, but I cannot seem to get it working. Any suggestions? Best regards Mattias ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/garywade%40desisoftsystems.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]