nsapplication

objc_getProtocol() returns NULL for `NSApplicationDelegate"?

社会主义新天地 提交于 2019-12-07 04:37:16
问题 I'm trying to use the objc_getProtocol() function to get a reference to the struct representing the NSApplicationDelegate protocol: Protocol *protocol = objc_getProtocol("NSApplicationDelegate"); However, for some reason, this always returns NULL . Other protocols such as NSObject , NSCoding , NSTableViewDelegate , and NSTableViewDataSource work fine. Is there something special about NSApplicationDelegate , or am I doing something wrong? 回答1: Found the answer in the Apple docs: http:/

macOS: Is there any way to know when the user has tried to quit an application via its Dock icon?

人盡茶涼 提交于 2019-12-07 03:13:04
问题 Is there any way for a Cocoa application to detect when the user has tried to quit it via its Dock menu, and not by some other method? Normally it's possible to catch and respond to quit events using the application delegate's applicationShouldTerminate: method. However, this method doesn't seem to distinguish between the request to quit coming from the application's main menu, from its Dock icon, from an Apple event, or any other conventional method of quitting the application. I'm curious

Cocoa: Call App Delegate Method from another Class

无人久伴 提交于 2019-12-06 07:33:36
I'm currently trying to get the path of a file from a drag and drop operation inside of a custom view, and then pass that path to my app delegate. I'm currently using the following: - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { NSPasteboard *pb = [sender draggingPasteboard]; NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]; NSArray *array = [[pb stringForType:type] propertyList]; //access the app delegate NSApplication *myApplication; myApplication = [NSApplication sharedApplication]; [myApplication uploadFiles:array]; return NO; }

Cocoa: int main function

我的梦境 提交于 2019-12-06 01:37:23
问题 I'm curious, what role does the int main function play in a Cocoa program? Virtually all of the sample code I've been looking at has only the following code in main.m: #import <Cocoa/Cocoa.h> int main(int argc, char *argv[]) { return NSApplicationMain(argc, (const char **) argv); } What exactly is this doing, and where does the program actually start stepping through commands? It seems my conceptions need readjustment. 回答1: Since a Cocoa project starts like any other, the entry point for the

What exactly should I pass to -[NSApp activateIgnoringOtherApps:] to get my application to start “naturally” in comparison to most other OS X apps?

你。 提交于 2019-12-05 21:53:18
When I learned how to start NSApplications on my own, the code I used (based on here and here ) did [NSApp activateIgnoringOtherApps:YES]; which forces the app to the front at startup. I'd like to know what most other apps do. I want to be able to run programs both directly from the binary and from an app bundle, and I'm not using Xcode to build this (raw building). So I'd rather this act naturally, so to speak. The docs do say Finder issues NO , but... why Finder? Isn't this a method that's run from within the process, not outside? (I'm not in control of the choice.) And what about the Dock

objc_getProtocol() returns NULL for `NSApplicationDelegate\"?

女生的网名这么多〃 提交于 2019-12-05 08:54:24
I'm trying to use the objc_getProtocol() function to get a reference to the struct representing the NSApplicationDelegate protocol: Protocol *protocol = objc_getProtocol("NSApplicationDelegate"); However, for some reason, this always returns NULL . Other protocols such as NSObject , NSCoding , NSTableViewDelegate , and NSTableViewDataSource work fine. Is there something special about NSApplicationDelegate , or am I doing something wrong? Found the answer in the Apple docs: http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Chapters/ocProtocols.html#//apple_ref

Not displaying Mouse cursor

拜拜、爱过 提交于 2019-12-05 07:16:34
I am developing Mac desktop application, where i am capturing the screen using CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault); and display the screen shot, The problem is, i am expecting it should show the mouse cursor too, but its not showing, do i need to enable any settings for that ? I tried following before calling this function CGDisplayShowCursor(kCGDirectMainDisplay); CGAssociateMouseAndMouseCursorPosition(true); but it didn't work, When i checked using following bool bCursor = CGCursorIsDrawnInFramebuffer

Cocoa application menu bar not clickable

故事扮演 提交于 2019-12-05 02:41:05
问题 I'm building a menu bar in my cocoa application with the following code in the @implementation of my custom application CustomApplication : +(void) setUpMenuBar { [CustomApplication sharedApplication]; // Main menu NSMenu* mainMenu = [NSApp mainMenu]; if (mainMenu != nil) return; // We set it already mainMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; [NSApp setMainMenu:mainMenu]; // Application menu NSMenuItem* appleItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]

Document sheet not responding to keyboard events

孤街醉人 提交于 2019-12-04 17:52:06
问题 I think it's a first responder problem, but I'm not sure. I'm implementing an edit window for data in a table view. Very similar in concept to the UI for editing filter rules in Mail.app. I have an editing window that I attach to my primary window with: [NSApp beginSheet: criteriaEditPanel modalForWindow: [self window] modalDelegate: self didEndSelector: @selector(criteriaEditDidEnd:returnCode:contextInfo:) contextInfo: (void *)[criteriaList objectAtIndex: index]]; The panel displays properly

Cocoa application menu bar not clickable

有些话、适合烂在心里 提交于 2019-12-03 16:26:31
I'm building a menu bar in my cocoa application with the following code in the @implementation of my custom application CustomApplication : +(void) setUpMenuBar { [CustomApplication sharedApplication]; // Main menu NSMenu* mainMenu = [NSApp mainMenu]; if (mainMenu != nil) return; // We set it already mainMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; [NSApp setMainMenu:mainMenu]; // Application menu NSMenuItem* appleItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; NSString* appName = @"MyApp"; NSMenu* appleMenu = [[NSMenu alloc] initWithTitle:@""]; // Apple menu