Hi everyone.

I have been trying to write a sample code for embedding mozilla in
wxWidgets.
I dont seem to be able to embed Mozilla even though i follow all the steps
given in http://developer.mozilla.org/en/docs/XPCOM_Glue and
http://developer.mozilla.org/en/docs/GRE
I am running Ubuntu 8.04.

Code:

#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#define XPCOM_GLUE

#include "xpcom-config.h"
#include "nsXPCOMGlue.h"
#include "nsDebug.h"
#include "nsCOMPtr.h"
#include "widget/nsIBaseWindow.h"
#include "nsILocalFile.h"
#include "nsIWebBrowser.h"
#include "docshell/nsIWebNavigation.h"
#include "nsEmbedCID.h"
#include "nsEmbedString.h"
#include "xulapp/nsXULAppAPI.h"
#include "nsComponentManagerUtils.h"

#define wxCSTR wxString::FromAscii

XRE_InitEmbeddingType XRE_InitEmbedding;
XRE_TermEmbeddingType XRE_TermEmbedding;

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString& title);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

private:
    DECLARE_EVENT_TABLE()
};

enum
{
    Minimal_Quit = wxID_EXIT,

    Minimal_About = wxID_ABOUT
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
    EVT_MENU(Minimal_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return false;
    MyFrame *frame = new MyFrame(wxCSTR("Minimal wxWidgets App"));
    SetTopWindow(frame);
    frame->Show(true);

    nsCOMPtr<nsIBaseWindow> baseWindow;
    nsCOMPtr<nsIWebBrowser> webBrowser;
    nsCOMPtr<nsILocalFile> libxul;
    nsCOMPtr<nsILocalFile> appDir;
    nsCOMPtr<nsIWebNavigation> webNavigation;
    nsDynamicFunctionLoad nsFuncs[] = { {"XRE_InitEmbedding",
(NSFuncPtr*)&XRE_InitEmbedding},
                                        {"XRE_TermEmbedding",
(NSFuncPtr*)&XRE_TermEmbedding},
                                        {0, 0} };
    nsresult rv;
    rv = XPCOMGlueStartup("/home/raravi/xulrunner-sdk/bin/libxpcom.so");
    if (NS_FAILED(rv))
    {
        printf("XPCOMGlueStartup\n");
    }
    rv = XPCOMGlueLoadXULFunctions(nsFuncs);
    if (NS_FAILED(rv))
    {
        printf("XPCOMGlueLoadXULFunctions\n");
    }
    rv = NS_NewNativeLocalFile(
nsEmbedCString("/home/raravi/xulrunner-sdk/bin"), PR_FALSE,
                                getter_AddRefs(libxul));
    if (NS_FAILED(rv))
    {
        printf("NS_NewNativeLocalFile\n");
    }
    rv = NS_NewNativeLocalFile(
nsEmbedCString("/home/raravi/NetBeansProjects/wxXULTest/dist/Debug/GNU-Linux-x86"),
                                PR_FALSE, getter_AddRefs(appDir));
    if(NS_FAILED(rv))
    {
        printf("NS_NewNativeLocalFile\n");
    }
    rv = XRE_InitEmbedding(libxul, appDir, 0, 0, 0);
    if (NS_FAILED(rv))
    {
        printf("XRE_InitEmbedding\n");
    }
    webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
    if (NS_FAILED(rv))
    {
        printf("do_CreateInstance webBrowser\n");
    }
    baseWindow = do_QueryInterface(webBrowser);
    rv = baseWindow->InitWindow(frame, 0, 0, 0, 300, 400);
    if (NS_FAILED(rv))
    {
        printf("InitWindow\n");
    }
    rv = baseWindow->Create();
    if (NS_FAILED(rv))
    {
        printf("Create\n");
    }
    rv =baseWindow->SetVisibility(PR_TRUE);
    if (NS_FAILED(rv))
    {
        printf("SetVisibility\n");
    }
    webNavigation = do_QueryInterface(webBrowser);
    rv = webNavigation->LoadURI(NS_LITERAL_STRING("http://mail.yahoo.com/
").get(),
                                nsIWebNavigation::LOAD_FLAGS_NONE, 0, 0, 0);
    if (NS_FAILED(rv))
    {
        printf("LoadURI\n");
    }

    return true;
}

MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
    wxMenu *fileMenu = new wxMenu;
    wxMenu *helpMenu = new wxMenu;
    wxMenuBar *menuBar = new wxMenuBar();
    helpMenu->Append(Minimal_About, wxCSTR("&About...\tF1"), wxCSTR("Show
about dialog"));
    fileMenu->Append(Minimal_Quit, wxCSTR("E&xit\tAlt-X"), wxCSTR("Quit this
program"));
    menuBar->Append(fileMenu, wxCSTR("&File"));
    menuBar->Append(helpMenu, wxCSTR("&Help"));
    SetMenuBar(menuBar);
    CreateStatusBar(2);
    SetStatusText(wxCSTR("Welcome to wxWidgets!"));
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    XRE_TermEmbedding();
    XPCOMGlueShutdown();
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxMessageBox(wxCSTR("This is the minimal wxWidgets sample\n"),
                 wxCSTR("About wxWidgets minimal sample"),
                 wxOK | wxICON_INFORMATION,
                 this);
}

This code compiles and runs successfully. But when run, i dont see the
embedded mozilla window...:-(

Its as if i am running a normal wxWidgets app. What am i doing wrong?

These are the cmds i use.

g++ `wx-config --cppflags` -fshort-wchar    -c -g
-I/home/raravi/xulrunner-sdk/sdk/include
-I/home/raravi/xulrunner-sdk/include -o
build/Debug/GNU-Linux-x86/_ext/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.o
/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.cpp

g++ `wx-config --cppflags` -fshort-wchar     `wx-config --libs` -o
dist/Debug/GNU-Linux-x86/wxxultest
build/Debug/GNU-Linux-x86/_ext/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.o
/home/raravi/xulrunner-sdk/lib/libxpcomglue.a

Any help would be greatly appreciately.

-- 

The most successful people are those who are good at plan B

rArAvi
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to