Skip navigation.
 
mlNewbie Question: Controls not redrawing on changes
FROM : Christopher Kempke
DATE : Sat May 03 23:42:01 2008

I'm attempting to convert my "Modern Carbon"/Windows GDI+ application 
framework to Cocoa for 64-bit support, and am paradoxically finding 
the "easy" things hard and the "hard" things easy.  My latest case in 
point:  My controls (checkboxes) aren't redrawing when they change 
state, and default buttons in the same dialog are drawn in blue but 
not throbbing.    When I click on the check box, it's changing state 
(as determined by a call to [theControl state], but not redrawing on 
screen.    This is all programatic; not using Interface Builder.

Here's some random clips from my code.  The Windows for my (modal) 
dialog are are created by:

           theWindow = [[NSWindow alloc] 
initWithContentRect:*(NSRect*)&platRect styleMask:winStyleMask  &~ 
(NSClosableWindowMask | NSMiniaturizableWindowMask | 
NSResizableWindowMask) backing:NSBackingStoreRetained defer:YES];
           [theWindow setLevel: NSModalPanelWindowLevel];


I create the checkbox with:

       case kAOControlCheckbox:
           ctl = [[NSButton alloc] init];
           [(NSButton*)ctl setButtonType:NSSwitchButton];
           [(NSButton*)ctl setTitle:(NSString*)title];
           SetPlatformCheckOrRadioValue(ctl, initValue);
           break;

Ad add it to the parent view:

   [parent addSubview:ctl];
   [ctl setFrame:*(NSRect*)&nrect];
   if (![ctl isEnabled])
       [ctl setEnabled:YES];

Then I draw the window with:

   [iWindow makeKeyAndOrderFront:nil];

And run it as a modal dialog with:

   [NSApp runModalForWindow:iWindow];

(The app itself is launched with [NSApp run]; )

This draws my dialog correctly, including all the controls.  But the 
buttons don't visibly respond when the mouse is held down on them, 
default buttons are blue but don't throb, and checkboxes change 
programatic state but not visible state when clicked.  If buttons are 
hooked to action targets, they're getting called when the button is 
clicked.  I discovered by accident that when drawing a custom view 
elsewhere in the dialog that if I included:

       [[NSGraphicsContext currentContext] flushGraphics];

in the drawRect: method of the view, that all the controls would 
update when that view did (triggered by a mousedown handler in just 
that custom view).  But the description of both flushGraphics and     
[NSButton setState] seem to indicate that it should be happening 
automatically.

I've turned off all assignments of actions and targets, thinking I was 
"stealing" some event the system needed, but no go.  I don't have 
mouseAnything: handlers on the checkboxes; in fact, I'm not even 
subclassing them.

I'm guessing I've missed a step, something that provides the context 
flush and the throb heartbeat.  Anyone care to take pity on me?

--Christopher Kempke

Related mailsAuthorDate
mlNewbie Question: Controls not redrawing on changes Christopher Kempke May 3, 23:42
mlRe: Newbie Question: Controls not redrawing on changes Nathan Kinsinger May 4, 00:10
mlRe: Newbie Question: Controls not redrawing on changes Michael Ash May 4, 00:25
mlRe: Newbie Question: Controls not redrawing on changes Christopher Kempke May 4, 01:08
mlRe: Newbie Question: Controls not redrawing on changes Kyle Sluder May 4, 05:47
mlRe: Newbie Question: Controls not redrawing on changes Christopher Kempke May 4, 11:19
mlRe: Newbie Question: Controls not redrawing on changes Mike Abdullah May 4, 12:07