Carbon's HTML rendering library not showing images

Discussion in 'Mac Programming' started by syl22-00, May 30, 2011.

  1. syl22-00 macrumors newbie

    Apr 13, 2011

    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:

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

    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.

  2. kainjow Moderator emeritus


    Jun 15, 2000
    Those functions were deprecated in 10.4, so I wouldn't be surprised to hear it's not working in 10.6.

    Same thing for QuickDraw, and I've seen issues with that on 10.6.

    Accessing the WebKit From Carbon Applications

    Looks pretty simple to me :)
  3. syl22-00 thread starter macrumors newbie

    Apr 13, 2011
    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).
  4. kainjow Moderator emeritus


    Jun 15, 2000
    If you're using code from the sample LoadURL function, that needs to be compiled in a separate Objective-C file (with .m extension).
  5. syl22-00 thread starter macrumors newbie

    Apr 13, 2011
    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

  6. kainjow Moderator emeritus


    Jun 15, 2000
    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?
  7. syl22-00 thread starter macrumors newbie

    Apr 13, 2011
    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...
  8. Madd the Sane macrumors 6502a

    Madd the Sane

    Nov 8, 2010
    If you were compiling the source code using C++, compile them using Objective C++. That might help.
  9. syl22-00 thread starter macrumors newbie

    Apr 13, 2011
    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:

    #ifdef __cplusplus
    #define EXTERN_C extern "C"
    #define EXTERN_C extern
    #import <Carbon/Carbon.h>
    #import <webkit/WebView.h>
    EXTERN_C void LoadURL( HIViewRef inView, CFURLRef inURL );
    #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];

Share This Page