nsmenuitem

Weird issue with NSMenuItem, custom view and mouseUp:

拥有回忆 提交于 2019-12-21 11:35:03
问题 I'm having a very very strange issue here with a NSMenu. About half the NSMenuItems I use have custom views on them through the setView: method on NSMenuItem. In this custom view I've implemented mouseUp: to catch when the user clicks on the menu item, and this works perfectly the first time I open the menu. The second time though, the mouseUp doesn't get called on any of these menu items if I hold the mouse steady when clicking. However, if I click down, then move the cursor ever so slightly

How do I set the sender on a NSMenuItem's action?

时间秒杀一切 提交于 2019-12-20 10:01:28
问题 The Apple documentation says that the sender passed to the NSMenuItem's action can be set to some custom object, but I can't seem to figure out how to do this. Is there a method I'm not seeing someplace in the documentation? 回答1: I'm not sure what piece of documentation you're referring to (a link would help). You can use the -setRepresentedObject: method of NSMenuItem to associate an arbitrary object with a menu item: //assume "item" is an NSMenuItem object: NSString* someObj = @"Some

How to remove NSMenuItem gap above custom view

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 07:14:23
问题 I was looking for something discussed in following posts. Gap above NSMenuItem custom view. Reverse engineering an NSMenu for a Status Bar Item I tried the carbon code provided by Pierre Bernard initially, i was getting same error "EXC_BAD_ACCESS on the line InstallControlEventHandler" like other had. I play with the code lots and accidently found the solution. I have just replaced the InstallControlEventHandler function call to HIViewInstallEventHandler and everything is working fine. Hope

Update NSMenuItem while the host menu is shown

点点圈 提交于 2019-12-17 23:28:13
问题 I have an NSMenuItem that I need to update to show a progress (like Time machine does with it's backup). The problem is that when I set a new title on that NSMenuItem and the title is not changing. It is in fact changing when I close and reopen the menu, but I want to update it while the user is looking at it. I also tried remove an item and re-inserting it with no result. Any pointers? 回答1: This actually works with no additional effort if your updating code runs in the run loop mode which is

Reverse engineering an NSMenu for a Status Bar Item

烂漫一生 提交于 2019-12-17 17:54:09
问题 I'm want to create a menu for a status bar item like the one seen in Tapbot's PastebotSync application: Does anyone have any ideas how to achieve the custom area at the top of the menu which is flush with the top? I've tried/thought of a few potential ways of doing it: Standard NSMenuItem with a view - isn't flush with the top of the menu Some hack-ish code to place an NSWindow over the area at the top of the menu - not great as it doesn't fade out nicely with the menu when it closes

Connecting Menu Items in Document Based Applications

北城余情 提交于 2019-12-14 00:30:40
问题 I've already asked a couple questions on this topic, and haven't really received a real answer on how to do it (it actually received the "Tumbleweed Badge" lol). I have a document based application (meaning the Menu.Xib is separate from MyDocument.Xib). Say I want to add a 'Bold' button, or a Check Spelling button (items that are listed in Menu.xib (under Format > Font etc) to MyDocument (the primary interface). I cannot figure out how to do this. Any help would be greatly appreciated (I will

Get default font name in Cocoa for NSMenuItem?

社会主义新天地 提交于 2019-12-13 13:19:34
问题 I am using NSAttributed NSString in my NSMenuItem, but it's Font is changed as compare to default font, I wants to use default font for Attributed string. Can any one explain, how to find or fetch the default Font for NSMenuItems. Right now I am using this : NSDictionary *attributes = @{ NSFontAttributeName: [NSFont fontWithName:@"Helvetica" size:14], NSForegroundColorAttributeName: [NSColor blackColor], NSParagraphStyleAttributeName:paragraphStyle }; Thanks 回答1: To get the default font of an

NSImageView on NSVisualEffectView

牧云@^-^@ 提交于 2019-12-13 07:25:19
问题 I need to make NSMenuItem with icon at the right side. I ended up with custom view which contains NSTextField and NSImageView on top of NSVisualEffectView with selection material, that I use to imitate system selection. NSVisualEffectView is hidden by default. But when the item is selected, my NSVisualEffectView appears on screen and image is drawn with background. How can I get rid of it? wantsLayer = YES and backgroundColor = CGColor.clear did not help. Thanks in advance. 回答1: You don't

Why does my clickable box needs a double click to have a clickcount that is equal to 1?

冷暖自知 提交于 2019-12-12 04:01:36
问题 I have an NSStatusItem that has an NSMenuItem which contains a custom NSView. this NSView contains 3 Subviews of NSBox which are clickable (implemented the mouseDown event). Strangely, when I run the application and I enter the statusItem right after I pressed the 'Play'-Button I have to click the NSBox just one time (this returns clickCount = 1). When I enter another window or view and I go back to the statusItem and I try to click one of the NSBoxes nothing happens. When I double click the

Loading NSView subclass from a XIB

一世执手 提交于 2019-12-12 01:46:07
问题 I need to use a custom view into a NSMenuItem. I've created a new view XIB and customized the view in it. How can I load that view and set it in the NSMenuItem using the setView: method? UPDATE : I've found a solution but now the menu item with the custom view doesn't highlight on mouse over. Ho can I solve this problem? 回答1: I've created a NSViewController subclass and set it as the file's owner in the XIB. Then I've set the view outlet of the file's owner to the view in the XIB and finally