Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kev786

macrumors newbie
Original poster
Jan 5, 2010
9
0
Hi,
I have a problem: I want to place a NSButton with type of "Recessed Button" on NSView and part of button should be on view and another part should be outside of this view
That's ok, but when cursor of mouse move inside button and outside view, button receive event about this.
What need to do for this event do not send to button when cursor move outside my view ?
Thanks
 
You could try overriding hitTest: in a subclass of NSButton and return nil if the point doesn't lie within the view (see convertPoint:toView:). I'm not even sure if that'd work.
 
Thanks for the answer, but when I clicked on the button - that's ok, problem is appear when I moved cursor on the Recessed Button and not clicked.
Because it's Recessed - it light when cursor place inside button and fade when cursor place outside.
hitTest send when mouse click, but not when mouse moved

I try override mouseEntered: and mouseExited: events, but it's not help me
 
Maybe try subclassing NSButtonCell and play around with the various mouse handling methods in NSCell (look at the Tracking the Mouse section for NSCell's documentation).
 
You could subclass NSButton and override the -mouseMoved: method or subclass the cell and override -setState:

The latter might be a little more work because you would have to handle -setState: for when the button is clicked.
 
I'm trying it, but no effect ((( I try override functions in NSButtonCell and override functions in NSButton , but it's not help me ((
Functions mouseMoved: is ignored when I override it
setState: ignored when mouse moved over button, it's send when clicked on button

I think that if replace options in NSTrackingArea for NSButton it will be help me
In Debugger I saw that default options is 4225 - I think that it's NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingAssumeInside
I want replace it to NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisibleRect
But if I do it in awakeFromNib function and add breakpoint in drawRect: -- it have first value. Somewhere value overwrite before drawRect:

Code:
 //MyButton.mm
 - (void)awakeFromNib
 {
 NSArray *a = [self trackingAreas];
 NSTrackingArea * t = [[NSTrackingArea alloc] initWithRect:(NSRect){0, 0, 100, 50} 
 options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisibleRect
 owner:self 
 userInfo:nil];
 [self removeTrackingArea:[a objectAtIndex:0]];
 [self addTrackingArea:t];
 [t release];
 
 }
 
 - (void)drawRect:(NSRect)aRect
 {
 NSArray *a = [self trackingAreas];
 NSTrackingArea *t1 = [a objectAtIndex:0]; //always first value !!!
 
 [super drawRect: aRect];
 }
 
Why do you want a button to overlap other views in the first place? Can you possibly post a screenshot of what you're doing? You might be better off creating one big view that tracks the mouse and draws all the controls yourself. A button that only tracks the mouse on part of itself seems like an awkward UI.
 
I try to use NSViewCollection for displaying items like iTunes , when mouse move over some item it will be highlighted. If I place in representation view Recessed Button - this effect work, problem appear when content scrolling and some row with items appear not all
 
Move the button to the ContentView or another view that is big enough. In Interface Builder, you may have to position it manually since dragging the button with the mouse automatically places it inside the top most view.
 
Seems like it could be as simple as overlaying part of the button with a transparent custom view when necessary to cature the troublesome mouse movements and prevent them from getting to the button.
 
It's not help me to ((

I attached little demo project. Maybe Recessed Button replace on the some view, but how ? Maybe exist different way to do this ? I want make interface like iTunes when on the item highlighted info icon
 

Attachments

  • test.zip
    59.2 KB · Views: 118
  • 1.png
    1.png
    18.8 KB · Views: 78
  • 2.png
    2.png
    15.5 KB · Views: 107
  • 3.png
    3.png
    16 KB · Views: 86
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.