Re: Custom NSView / NSToolbar drawing woes
Re: Custom NSView / NSToolbar drawing woes
- Subject: Re: Custom NSView / NSToolbar drawing woes
- From: Graham Cox <email@hidden>
- Date: Fri, 30 Nov 2012 16:20:34 +1100
When your custom view is activated, it should be made first responder, which is responsible for validating the toolbar - check out NSUserInterfaceValidation.
Your -drawRect: does not need to account for the toolbar (but it also should take some care not to mess up the graphics environment, though that is hard to do - I doubt that's the problem)
--Graham
On 30/11/2012, at 2:32 PM, João Varela <email@hidden> wrote:
> I would really appreciate if someone could help me with this mixed bag of
> problems I'm having while drawing a custom NSView:
>
> I have a textured window on which I display either an NSOutlineView or this
> custom view (both are subviews of the window's content view). This window
> has a toolbar with several items, a few of which are enabled / disabled
> depending upon if there is a selected item on the NSOutline view. When I
> display the NSOutlineView the toolbar draws without a glitch, i.e., all
> items of the toolbar are properly drawn. However, when the user switches to
> the custom view (I implement this by hiding the NSOutlineView and by
> unhiding the custom view when the user hits a segmented control) only the
> toolbar items that have changed their enable/disable status by the
> validating method draw properly; the items whose enable/disable status has
> not changed do not draw at all, although they are still enabled (you can
> click on them and their actions are triggered even though they became
> invisible by this update bug). This toolbar update bug becomes even worse
> when you deactivate the window or the app by switching to another
> application. After this context switch the toolbar items are not drawn at
> all even if the window is made key and is switched to front. However, when
> the user switches back to the NSOutlineView then the toolbar items are drawn
> properly again.
>
> The workaround I found that works partially on (Mountain) Lion is to force
> the toolbar to update by removing and reinserting the toolbar items,
> although that causes a flicker in the toolbar, but the items are drawn and
> updated properly when the user switches to this custom view. However, this
> "hack" does not work when the user deactivates the app or the window (items
> seem to be drawn and then erased a few milliseconds afterwards).
>
> It seems as though the custom drawing code of my view is messing up the
> drawing of the toolbar items. But why? Does anyone have a clue of what I am
> doing wrong? Does my custom code has to take into account the existence of a
> toolbar so that the drawing done in drawRect: does not messes up the drawing
> of the toolbar?
>
> I would be extremely grateful If someone could point me to a solution to
> this problem or to sample code that deals with drawing a custom view on a
> window with a toolbar on it.
>
> TIA
>
> João
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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