Talk:Embedding/NewApi/Win32: Difference between revisions
| Line 191: | Line 191: | ||
{ | { | ||
m_private->mozView.CreateBrowser( | m_private->mozView.CreateBrowser( | ||
(void*)parent, | (void*)parent->GetHandle(), | ||
parent->GetRect().GetLeft(), | parent->GetRect().GetLeft(), | ||
parent->GetRect().GetTop(), | parent->GetRect().GetTop(), | ||
Revision as of 14:22, 31 December 2009
Hi,
I am trying to embed a rudimentary browser into my C++ app on Linux and Windows (MinGW) using wxWidgets.
This page looks like where I need to be however it contains virtually no information about how to embed. Most of the content on the page is how to compile XULRunner or use the SDK.
I downloaded the code samples from Mercurial but there are many folders/files and the code does not include a lot of high level comments. Very difficult for a newbie.
IMHO the key questions that should be addressed on this page:
- How do I insert a browser window in my app?
- How do I load a web page?
- How do I load content from memory?
- How do I implement basic navigation?
- What libraries from xulrunner do I need to link to my app?
I don't mind contributing that content once I figure it out but if somebody beats me to it, even better!
/~jc
Hi jc,
I think you did not carefully take a look at the instruction about the Embeded New API. There is clear manual and test sample project on the main page of New API.
https://wiki.mozilla.org/Embedding/NewApi
But it did not have example for wxWidget. Here I give you a simple example (learned from the QT sample project) to help you getting started with the MozView (embeded API)
Using embeded API in wxWidget application
Setup system environment
Please refer to https://wiki.mozilla.org/Embedding/NewApi/Win32
Extended wxWidgets using embeded API
Create an new Class wxMozView inheriting wxWindows
Header file wxMozView.h
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The code follows the example of embeded API QT project.
* Contact: Jiez <MagicDesign.CN@Gmail.Com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _EXTERN_WXWIDGET_EMBEDED_MOZILLA_WXMOZVIE_H_
#define _EXTERN_WXWIDGET_EMBEDED_MOZILLA_WXMOZVIE_H_
#include "embed.h"
#include <wx/window.h>
#include <wx/string.h>
class wxMozViewListener;
class nsIInterfaceRequestor;
/////////////////////////////////////////////////////
///Class wxMozView
/////////////////////////////////////////////////////
class wxMozView :
public wxWindow
{
public:
explicit wxMozView(wxWindow* parent = NULL,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxPanelNameStr);
virtual ~wxMozView();
void LoadUri(const wxString& uri);
void GetInterfaceRequestor(nsIInterfaceRequestor** aRequestor);
wxString EvaluateJavaScript(const wxString& script);
void GetSize(int *width, int *height);
protected:
virtual void OnSize(wxSizeEvent& e);
virtual wxMozView* OpenWindow(unsigned int flags);
private:
//here I am using the QT way to create the private members for the class wxMozView.
//It is really a good way to hide private info of a class. :)
//I love QT!
class Private;
Private * const m_private;
friend class wxMozViewListener;
};
/////////////////////////////////////////////////////
///Class wxMozViewListener
/////////////////////////////////////////////////////
class wxMozViewListener :
public MozViewListener
{
public:
wxMozViewListener(wxMozView* awxMozView) : pwxMozView(awxMozView) {}
virtual ~wxMozViewListener() {}
void StatusChanged(const char* newStatus, PRUint32 statusType);
void LocationChanged(const char* newLocation);
MozView* OpenWindow(PRUint32 flags);
void SizeTo(PRUint32 width, PRUint32 height);
private:
wxMozView* pwxMozView;
};
#endif // _EXTERN_WXWIDGET_EMBEDED_MOZILLA_WXMOZVIE_H_
File wxMozView.cpp
#include "wxMozView.h"
///////////////////////////////////////////
//Class Private
class wxMozView::Private
{
public:
Private(wxMozView* awxMozView) :
listener(awxMozView)
{
mozView.SetListener(&listener);
}
MozView mozView;
wxMozViewListener listener;
wxSize preferredSize;
};
////////////////////////////////////////////
//Implement class wxMozViewListener
void wxMozViewListener::StatusChanged(const char* newStatus, PRUint32 statusType)
{
//add your own code to deal with the status changed events
pwxMozView->Refresh();
}
void wxMozViewListener::LocationChanged(const char* newLocation)
{
//add your own code to deal with the location changed events
pwxMozView->Refresh();
}
MozView* wxMozViewListener::OpenWindow(PRUint32 flags)
{
wxMozView* newwxMozView = pwxMozView->OpenWindow(flags);
if(!newwxMozView)
return 0;
return &(newwxMozView->m_private->mozView);
}
void wxMozViewListener::SizeTo(PRUint32 width, PRUint32 height)
{
pwxMozView->m_private->preferredSize = wxSize(width, height);
pwxMozView->Update();
pwxMozView->GetParent()->Fit();
}
///////////////////////////////////////////////////
//Implement class wxMozView
wxMozView::wxMozView(wxWindow* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) :
wxWindow(parent, id, pos, size, style, name),
m_private(new Private(this))
{
m_private->mozView.CreateBrowser(
(void*)parent->GetHandle(),
parent->GetRect().GetLeft(),
parent->GetRect().GetTop(),
parent->GetRect().GetRight() - parent->GetRect().GetLeft(),
parent->GetRect().GetBottom() - parent->GetRect().GetTop(),
1);
}
wxMozView::~wxMozView()
{
delete m_private;
}
void wxMozView::OnSize(wxSizeEvent& e)
{
int width = 0, height = 0;
GetSize(&width, &height);
m_private->mozView.SetPositionAndSize(0, 0, width, height);
}
void wxMozView::LoadUri(const wxString &uri)
{
m_private->mozView.LoadURI(uri.char_str(wxMBConvUTF8()));
}
void wxMozView::GetInterfaceRequestor(nsIInterfaceRequestor** aRequestor)
{
*aRequestor = 0;
m_private->mozView.GetInterfaceRequestor(aRequestor);
}
wxString wxMozView::EvaluateJavaScript(const wxString& script)
{
return wxString::FromUTF8(m_private->mozView.EvaluateJavaScript(script.char_str(wxMBConvUTF8())));
}
wxMozView* wxMozView::OpenWindow(unsigned int flags)
{
return 0;
}
void wxMozView::GetSize(int *width, int *height)
{
*width = m_private->preferredSize.GetWidth();
*height = m_private->preferredSize.GetHeight();
}
//
// (C) 2009 Copyrights
// All rights opened under MPL/GPL