Hyperlinks not working in PDFView (in my cocoa app) - cocoa

I have a PDFView object in one of my windows and wondering if there's anything special I need to do in order for the hyperlinks to work.
The same pdf files have working hyperlinks when opened in other apps (like skim, preview, etc).
Any ideas?

Add a delegate to your PDFView that responds to this selector
- (void)PDFViewWillClickOnLink:(PDFView *)sender withURL:(NSURL *)url
{
[[NSWorkspace sharedWorkspace] openURL:url];
}

Turned out that I simply had to enable this in my derived class: [super mouseDown:theEvent];

Related

Load WebView URL inside Notification Bar NSPopover

I'm a noob OSX Developer having issues getting a WebView to load a URL when inside of a Custom View using NSPopover...My NSPopover is activated when a notification bar item is clicked.
This code is in my application delegate under
"- (void)applicationDidFinishLaunching:(NSNotification *)aNotification":
NSURL*url=[NSURL URLWithString:#"http://www.google.com"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
[[_webView mainFrame] loadRequest:request];
It works just fine if I move the WebView to any other window, but the WebView in my Custom View for this NSPopover displays as a blank page. Any ideas why? Any additional information you might need? Limitation of the CustomView?
You have created the Outlet in IB for the UIWebView in your Custom View ? and strung it together?

Event issue when embed cocoa webview to QT application

I intend to replace QT webkit with OSX native webkit in a QT based application, what I did right now is making an QT control inherited from QMacCocoaViewContainer and embed a cocoa web view in it. It could show the page correctly, but cocoa web view can't receive mouse moved event, so the js/css hover effect can't be shown. I tried to compare it with native cocoa Application, and found that cocoa web view could get NSMouseMovedNotifcation from notification center in native cocoa App, but QT app builds its own event loop and send event with its own strategy, this notification isn't received.
Who can tell me how to fix it? Any comments are very appreciated.
QTWebView(QWidget *pparent): QMacCocoaViewContainer(0, pparent)
{
...
xwebview = [[WebView alloc] init];
setCocoaView(xwebview);
NSString *urldefault = #"http://www.google.com";
[[xwebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urldefault]]];
...
}
I was having a similar issue and I resolved it by implementing the macEvent(EventHandlerCallerRef, EventRef) function. Create an NSEvent from the eventRef
NSEvent* nsEvent = [NSEvent eventWithEventRef:event];
If the event is a MouseMoved event then send a mouseMoved: event to the NSView where the NSView is (NSView*)winId().
I hope this helps

How does window management work in Mac development for MenuBar apps?

I'll preface this by saying this is my first Mac application, though I've been building iOs apps for some time.
I've got a menu bar app (system tray app) by which I mean I've got this.
I now want to show an NSWindow I've created in Interface Builder so I've created a class that's derived from NSWindow. Made my class the Window's delegate and from the App Delegate I do this:
MyClass *myClass = [[MyClass alloc] init];
[myClass display];
[myClass center];
[NSApp activateIgnoringOtherApps:YES];
[viewer makeKeyAndOrderFront:nil];
This seems to show a window without the standard window buttons (minimise, maximise, close) rather than the window I've defined.
Is this the right way to be showing windows? and how should the Window be defined so it shows my designed interface?
In Windows Forms programming this would be:
Form myForm = new Form();
myForm.Show();
You rarely need to subclass NSWindow unless you want to override a window's behavior. A more typical usage scenario would be to use an instance of NSWindowController or a subclass of NSWindowController to manage the window, by making that class the File's Owner in Interface Builder. Once this is done, to grab an instance of the window use:
NSWindowController *wc = [[NSWindowController alloc] initWithWindowNibName:#"NIBNAMEHERE"];
[wc showWindow:nil];
Another alternative in your app would be to add an NSWindow IBOutlet to your app delegate, and load the window in your app delegate with:
[NSBundle loadNibNamed:#"NIBFILENAME" owner:self];
[_window makeKeyAndOrderFront];

iPad: Launch MainWindow.xib's primary view without using InterfaceBuilder confi

I get really confused using InterfaceBuilder to setup the main window xib file's primary controller view. Is there a good example or simple way to launch the ViewController I want to show by default in the Application Delegate instead of setting it up in InterfaceBuilder's MainWindow.xib file?
you can show your view by code as
FirstViewController *fvc = [[FirstViewController alloc] init];
[window addSubView:fvc];

WebKit won't render on a layer backed view

I have a simple NSView that hosts a WebView.
When I try to make the view layer backed, the WebView stops rendering content - all it renders are the scroll bars.
For simplicity, I added the following code to the applicationDidFinishLaunching method of the app delegate of a brand new xcode project :-
NSView* view = [window contentView];
[view setWantsLayer:YES]; // This is the problematic line!
WebView* webView = [[WebView alloc] initWithFrame:NSMakeRect(0,0,400,400)];
WebFrame* mainFrame = [webView mainFrame];
[view addSubview:webView];
[mainFrame loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
If I leave out setWantsLayered the WebKit renders the web page. If I set it, WebKit just renders a white square with scroll bars.
Layer backed WebView's aren't supported. From the Leopard release notes:
Most of the standard views and controls that AppKit and Mac OS X's other Cocoa frameworks provide are able to function in layer-backed mode in Leopard, with the exception of certain specialized views such as WebKit WebViews and Quartz Composer QCViews, whose use in layer-backed mode is not presently supported.
(http://developer.apple.com/mac/library/releasenotes/cocoa/AppKitOlderNotes.html#Animation - Last paragraph of the "New View Animation Facilities, and Layer-Backed View Drawing" section)
You should file a bug with Apple and reference rdar://5270371 as found in this mailing list post http://lists.apple.com/archives/Webkitsdk-dev/2007/Dec/msg00042.html.
This now seems to work.
I have just tried out the same code on Mountain Lion and all is OK.

Resources