NSView | NSTextField Right Click issue
I have a NSView and inside that, there is a Label : NSTextField Control, Inside NSView i have to show a context menu on the right click, its working fine except few below issue,
At some place it didn't work, i.e. if i do right click , it doesn't open the Context Menu, further i realized i have kept length/Width of Label is too big and right click happening over the Label, but since this is the empty area, so as par user experience, it should allow to open the context menu, i feel following two approaches to solve this problem
1 -- Check the width/Length of the NSTextField runtime to set the开发者_JS百科 proper width,
2 -- Pass Mouse event ( or at-least Right-click )from NSTextField( Label ) to its ParentView,
Can anyone suggest me, how can i achieve that ?
Kind Regards
Rohan
I'm not sure if this helps but when you click with the right mouse button on the nstextfield in the Interface Builder you'll see a "menu" object. Connecting this with a NSMenu and you have a default context menu.
So far its working with following piece of code,
-(void)initSubViews{ /* In this function just init the sub-views */ NSSize imageSize = [pStatusImage size];
pStatusImageView = [[NSImageView alloc]initWithFrame:NSMakeRect(0, 0,
imageSize.width,imageSize.height)];
pDisplayName = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 0,
STATUS_WIDTH,STATUS_HEIGHT)];
[pDisplayName becomeFirstResponder];
**[pDisplayName setMenu:pCTTableMenu];**
..........................................................
..........................................................
..........................................................
}
so i can able to see the menu on the right click,
Kind Regards Rohan
精彩评论