• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLVED] NSControls in drawers attached to modal panels under 10.2.8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] NSControls in drawers attached to modal panels under 10.2.8


  • Subject: [SOLVED] NSControls in drawers attached to modal panels under 10.2.8
  • From: Tim Hewett <email@hidden>
  • Date: Fri, 19 Nov 2004 17:11:20 +0000

Hello,

A while back I reported being unable to get buttons and other
controls to call their action methods when those controls were
located in a NSDrawer attached to a modal NSPanel under
10.2.8. Clicking the button/slider/matrix etc just caused a system
beep with the action method not being called at all.

This was kludged by subclassing the control and providing a
mouseDown replacement which handled all the highlighting
of the button, and the calling of the action method on the target.
Worked fine, but now my app needs to have a NSSlider call an
action method continuously while sliding, which resulted in a
hail of system beep "bullets" like a machine gun... Overloading
mouseDown for NSSlider was getting complex since it is more
than just a button so a different way was found (now I'm a little
further a long the learning curve since last time) by overloading
the sendAction:to: NSControl method instead.

This turns out to be a generic solution for all NSControls that
won't work in modal panel drawers, and doesn't disrupt behaviour
under 10.3 either. This is the code sample:

@implementation MyButton	// inherits from NSButton

- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{
    if ( !theAction || !theTarget )
        return FALSE;

    objc_msgSend( theTarget, theAction, self );
    return TRUE;
}

@end

It lacks one feature of the normal implementation, where the target
can be nil leading to a search algorithm being triggered to find an
object which supports the particular selector. There are possible
other things missing too, but it works well enough for me.

BTW I don't know why objc_msgSend() has to be used instead of
performSelector:withObject:afterDelay: but it does.

Note that if this is used for NSMatrix then for some reason theAction
and theTarget are always received as nil, so instead do:

    objc_msgSend( [self target], [self action], self );

Works great.

HTH,

Tim Hewett.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSPanel with just a close button & title on title bar?
  • Next by Date: Crash when using [NSTimer fire]
  • Previous by thread: User click lost in space for a NSTableView
  • Next by thread: Crash when using [NSTimer fire]
  • Index(es):
    • Date
    • Thread