Newbie Question: Controls not redrawing on changes
Newbie Question: Controls not redrawing on changes
- Subject: Newbie Question: Controls not redrawing on changes
- From: Christopher Kempke <email@hidden>
- Date: Sat, 3 May 2008 14:42:01 -0700
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden