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

syl22-00

macrumors newbie
Original poster
Apr 13, 2011
6
0
Hi,

I am working on porting an old program that uses an embedded browser using the HTML Rendering library from Carbon. I am migrating it from codewarrior to Xcode, using the 10.4 SDK. The HTML page is displayed correctly, including links but images don't show up. I can see the alt content, and dimensions are properly set with the width and height fields.

I am doing the initialization with:

Code:
OSErr err = HRNewReference(m_HRRef, kHRRendererHTML32Type,
            GetWindowPort((WindowRef) m_pWindow));
And then I open my local HTML file with:

Code:
err = HRGoToFSRef(m_HRRef, &f, false, false);

My images are also stored locally but just do not appear, it was working fine previously on my ppc only codewarrior compilation.

I tried with web pages on Internet with HRGoToURL, and I tried replacing my pictures src fields with http:// or file:// links to images, in jpg, gif and png, always with the same result.

Are you aware of any issue like this? I know I could, and probably should, migrate to WebKit but that would me more involved.

Sylvain
 

syl22-00

macrumors newbie
Original poster
Apr 13, 2011
6
0

Thank you.

Yes it does not look too complicated to me, however, I can't get the Cocoa view in my Carbon app. WebView and WebFrame are both defined in WebView.h and I am getting plenty of conflicts when I try to include that file. I am reading about Cocoa-Carbon integration, but getting either deprecated material or things relevant to the 10.5+ SDK, and I am using the 10.4 SDK (I have to).
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you're using code from the sample LoadURL function, that needs to be compiled in a separate Objective-C file (with .m extension).
 

syl22-00

macrumors newbie
Original poster
Apr 13, 2011
6
0
If you're using code from the sample LoadURL function, that needs to be compiled in a separate Objective-C file (with .m extension).

Thank you Kainjow for your help. I have never used Objective-C before.

So I added a new empty file to my project, called loadurl.m, added the code inside and tried to import a few header files (such as WebKit/WebView.h), I always get errors related to objc.h.

I found that gcc is called with -x c++, but File Type is set to sourcecode.c.obj. Am I doing something wrong?

Thanks a lot for your patience

Sylvain
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Where do the errors originate? Usually if errors are coming from within a framework's header, the build window will show the file in your code where the #include/#import originated.

Can you post the code for the .h/.m files? Which version of Xcode are you using?
 

syl22-00

macrumors newbie
Original poster
Apr 13, 2011
6
0
Where do the errors originate? Usually if errors are coming from within a framework's header, the build window will show the file in your code where the #include/#import originated.

Can you post the code for the .h/.m files? Which version of Xcode are you using?

I found that in my project, I was forcing files to be compiled in C++, that's why it could not compile my objective-c file although is was sourcecode-objc type. The problem is that when I changed my project to compile files depending on their type, I am getting thousand of errors in my own code (or the code I should make my own). It might be because my .h files are all set as c header files, I am trying to change them as c++ header files without much success so far...
 

syl22-00

macrumors newbie
Original poster
Apr 13, 2011
6
0
Thank you Madd and Kainjow,

I finally managed to have things working... well I can't see the web page yet, but it is just a matter of getting to know how to use the webkit API as the app compiles and links successfully.

In case it can help other people, here were the issues:

. My app was set to be compiled in C++, so even .m files would be compiled in c++. After changing "Compile source as" from "C++" to "according to file type", I would then have thousand of error because of my precompiled headers being compiled in C. The solution was to include the header files inside a "#if defined __cplusplus". Apparently the reason is that the compiler will attempt to compile the precompiled header both in C and C++, and you don't want them to be compiled in C.

. In the header file for the loadURL function, you need a extern "C" directive if compiled in C++ because C++ would mangle the names, not objective C.

So here are the .h and .m files:

loadurl.h:
Code:
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C extern
#import <Carbon/Carbon.h>
#import <webkit/WebView.h>
#endif

EXTERN_C void LoadURL( HIViewRef inView, CFURLRef inURL );

loadurl.m:
Code:
#import <webkit/webkit.h>
#import <webkit/HIWebView.h>
#import "loadurl.h"

void LoadURL( HIViewRef inView, CFURLRef inURL )
{
    WebView*            nativeView;
    NSURLRequest*       request;
    WebFrame*           mainFrame;
	
    nativeView = HIWebViewGetWebView( inView ); // get the Cocoa view
	
    // Use Objective-C calls to load the actual content
    request = [NSURLRequest requestWithURL:(NSURL*)inURL];
    mainFrame = [nativeView mainFrame];
    [mainFrame loadRequest:request];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.