Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > system color change notifications

system color change notifications
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Nov 5, 2002, 01:38 AM
 
Ive subclassed NSTableView to give me alternating row colors ala iTunes. How can I tell my subclass to redisplay itself? Ive tried [self setNeedsDisplay:YES]; also I know that the notification NSControlTintDidChangeNotification is posted whenever the user changes between aqua and graphite in the system/general/preferences. What is the notification that is posted when ever the user changes their highlight color preference? I know there is one as evidenced by NSTableViews changing their selection color whenever the user changes the highlight color.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Nov 5, 2002, 02:46 AM
 
If you call [self setNeedsDisplay: YES], your subview will redraw itself the next time through the event loop (provided you don't call it again with NO before that happens).

If you want it to redraw and reload the info that it's drawing, use [self reloadData].

Take a look at NSSystemColorsDidChangeNotification in the NSColor documentation.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Nov 5, 2002, 03:01 AM
 
Those didnt do the trick yet either. Perhaps your knowing what method im overiding will shed some light on why my table wont redraw.

// This is called after the table background is filled in, but before the cell contents are drawn.
// We override it so we can do our own light-blue row stripes a la iTunes.
- (void) highlightSelectionInClipRect:(NSRect)rect {
[self drawStripesInRect:rect];
[super highlightSelectionInClipRect:rect];
}

// This routine does the actual blue stripe drawing, filling in every other row of the table
// with a blue background so you can follow the rows easier with your eyes.
- (void) drawStripesInRect:(NSRect)clipRect {
NSRect stripeRect;
float fullRowHeight = [self rowHeight] + [self intercellSpacing].height;
float clipBottom = NSMaxY(clipRect);
int firstStripe = clipRect.origin.y / fullRowHeight;
if (firstStripe % 2 != 0)
firstStripe++; // we're only interested in drawing the stripes
// set up first rect
stripeRect.origin.x = clipRect.origin.x;
stripeRect.origin.y = firstStripe * fullRowHeight;
stripeRect.size.width = clipRect.size.width;
stripeRect.size.height = fullRowHeight;
// set the color
if (sStripeColor == nil)
sStripeColor = [[[NSColor alternateSelectedControlColor] highlightWithLevel:0.90] retain];

// sStripeColor = [[[NSUserDefaults standardUserDefaults] colorForKey:@"oddRowColor"] retain];
// sStripeColor = [[NSColor colorWithCalibratedRed:STRIPE_RED green:STRIPE_GREEN blue:STRIPE_BLUE alpha:1.0] retain];
[sStripeColor set];
// and draw the stripes
while (stripeRect.origin.y < clipBottom) {
NSRectFill(stripeRect);
stripeRect.origin.y += fullRowHeight * 2.0;
}
}



I see the problem now. In the above code which I got from apple, note the line:
if (sStripeColor == nil)

Since it isnt nil, when I change the colors, it doesnt get set. Should I leave that if test in there, but set it to nil, whenever, i get the systemColorsDidChangeNotification?
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Nov 5, 2002, 06:11 PM
 
Why don't you set the color in your notification handler? That way, you set it only when the system color has changed.

Also, isn't
[super highlightSelectionInClipRect:rect];
going to draw over the stripes you just drew?
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2