From 2c990ba6d4f88e18e6666f61efe55c7a8b5cc948 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Wed, 19 May 2004 02:20:53 +0000 Subject: [PATCH] Initial import of wxWebKitCtrl sources and htmlctrl (right now wxWebKit) sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27349 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/html/webkit.h | 129 +++++++++++ samples/html/htmlctrl/Makefile.in | 168 +++++++++++++++ samples/html/htmlctrl/htmlctrl.bkl | 14 ++ samples/html/htmlctrl/htmlctrl.cpp | 247 +++++++++++++++++++++ src/html/htmlctrl/webkit/webkit.mm | 334 +++++++++++++++++++++++++++++ 5 files changed, 892 insertions(+) create mode 100755 include/wx/html/webkit.h create mode 100644 samples/html/htmlctrl/Makefile.in create mode 100644 samples/html/htmlctrl/htmlctrl.bkl create mode 100755 samples/html/htmlctrl/htmlctrl.cpp create mode 100755 src/html/htmlctrl/webkit/webkit.mm diff --git a/include/wx/html/webkit.h b/include/wx/html/webkit.h new file mode 100755 index 0000000000..b0656d9222 --- /dev/null +++ b/include/wx/html/webkit.h @@ -0,0 +1,129 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: webkit.h +// Purpose: wxWebKitCtrl - embeddable web kit control +// Author: Jethro Grassie / Kevin Ollivier +// Modified by: +// Created: 2004-4-16 +// RCS-ID: $Id$ +// Copyright: (c) Jethro Grassie / Kevin Ollivier +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WEBKIT_H +#define _WX_WEBKIT_H + +#ifdef __GNUG__ +#pragma interface "webkit.h" +#endif + +#if !defined(__WXMAC__) && !defined(__WXCOCOA__) +#error "wxWebKitCtrl not implemented for this platform" +#endif + +#ifdef __WXCOCOA +#include +#endif +#include "wx/control.h" + +// ---------------------------------------------------------------------------- +// Web Kit Control +// ---------------------------------------------------------------------------- + +class wxWebKitCtrl : public wxControl +{ +public: + DECLARE_DYNAMIC_CLASS(wxWebKitCtrl) + + wxWebKitCtrl() {}; + wxWebKitCtrl(wxWindow *parent, + wxWindowID winID, + const wxString& strURL, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxString("default_webkit_name")) + { + Create(parent, winID, strURL, pos, size, style, validator, name); + }; + bool Create(wxWindow *parent, + wxWindowID winID, + const wxString& strURL, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxString("default_webkit_name")); + virtual ~wxWebKitCtrl(); + + void LoadURL(const wxString &url); + + bool CanGoBack(); + bool CanGoForward(); + bool GoBack(); + bool GoForward(); + void Reload(); + void Stop(); + bool CanGetPageSource(); + wxString GetPageSource(); + void SetPageSource(wxString& source, const wxString& baseUrl = wxString("")); + + //we need to resize the webview when the control size changes + //void OnSize(wxSizeEvent &event); +protected: + DECLARE_EVENT_TABLE() + +private: + wxWindow *m_parent; + wxWindowID m_windowID; + wxString m_currentURL; + wxString m_pageTitle; + void* m_webView; + //It should be WebView, but WebView is Cocoa only, so any class which included + //this header would have to link to Cocoa, so for now use void* instead. +}; + +// ---------------------------------------------------------------------------- +// Web Kit Events +// ---------------------------------------------------------------------------- + +enum { + wxWEBKIT_STATE_START = 1, + wxWEBKIT_STATE_NEGOTIATING = 2, + wxWEBKIT_STATE_REDIRECTING = 4, + wxWEBKIT_STATE_TRANSFERRING = 8, + wxWEBKIT_STATE_STOP = 16, + wxWEBKIT_STATE_FAILED = 32 +}; + +class wxWebKitStateChangedEvent : public wxCommandEvent +{ + DECLARE_DYNAMIC_CLASS( wxWebKitStateChangedEvent ) + +public: + int GetState() { return m_state; } + void SetState(const int state) { m_state = state; } + wxString GetURL() { return m_url; } + void SetURL(const wxString& url) { m_url = url; } + + wxWebKitStateChangedEvent( wxWindow* win = (wxWindow*) NULL ); + wxEvent *Clone(void) const { return new wxWebKitStateChangedEvent(*this); } + +protected: + int m_state; + wxString m_url; +}; + +typedef void (wxEvtHandler::*wxWebKitStateChangedEventFunction)(wxWebKitStateChangedEvent&); + +BEGIN_DECLARE_EVENT_TYPES() + DECLARE_LOCAL_EVENT_TYPE(wxEVT_WEBKIT_STATE_CHANGED, -1) +END_DECLARE_EVENT_TYPES() + +#define EVT_WEBKIT_STATE_CHANGED(func) \ + DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBKIT_STATE_CHANGED, \ + -1, \ + -1, \ + (wxObjectEventFunction) \ + (wxWebKitStateChangedEventFunction) & func, \ + (wxObject *) NULL ), + +#endif // _WX_WEBKIT_H_ diff --git a/samples/html/htmlctrl/Makefile.in b/samples/html/htmlctrl/Makefile.in new file mode 100644 index 0000000000..c5a9baea9e --- /dev/null +++ b/samples/html/htmlctrl/Makefile.in @@ -0,0 +1,168 @@ +# ========================================================================= +# This makefile was generated by +# Bakefile 0.1.4 (http://bakefile.sourceforge.net) +# Do not modify, all changes will be overwritten! +# ========================================================================= + + +@MAKE_SET@ + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +INSTALL = @INSTALL@ +EXEEXT = @EXEEXT@ +RESCOMP = @RESCOMP@ +SETFILE = @SETFILE@ +NM = @NM@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ +LDFLAGS_GUI = @LDFLAGS_GUI@ +CXX = @CXX@ +CXXFLAGS = @CXXFLAGS@ +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +TOOLKIT = @TOOLKIT@ +TOOLKIT_LOWERCASE = @TOOLKIT_LOWERCASE@ +TOOLKIT_VERSION = @TOOLKIT_VERSION@ +TOOLCHAIN_NAME = @TOOLCHAIN_NAME@ +EXTRALIBS = @EXTRALIBS@ +EXTRALIBS_GUI = @EXTRALIBS_GUI@ +HOST_SUFFIX = @HOST_SUFFIX@ +SAMPLES_RPATH_FLAG = @SAMPLES_RPATH_FLAG@ +SAMPLES_RPATH_POSTLINK = @SAMPLES_RPATH_POSTLINK@ + +### Variables: ### + +DESTDIR = +WX_VERSION = 2.5.1 +LIBDIRNAME = $(top_builddir)lib +HTMLCTRL_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) -I$(srcdir) \ + $(__DLLFLAG_p) -I$(srcdir)/../../../samples $(CPPFLAGS) $(CXXFLAGS) +HTMLCTRL_OBJECTS = \ + $(__htmlctrl___win32rc) \ + $(__htmlctrl_os2_lib_res) \ + htmlctrl_htmlctrl.o + +### Conditionally set variables: ### + +@COND_DEPS_TRACKING_0@CXXC = $(CXX) +@COND_DEPS_TRACKING_1@CXXC = $(top_builddir)./bk-deps $(CXX) +@COND_USE_GUI_0@PORTNAME = base +@COND_USE_GUI_1@PORTNAME = $(TOOLKIT_LOWERCASE)$(TOOLKIT_VERSION) +@COND_TOOLKIT_MAC@WXBASEPORT = _carbon +@COND_BUILD_DEBUG_DEBUG_FLAG_DEFAULT@WXDEBUGFLAG = d +@COND_DEBUG_FLAG_1@WXDEBUGFLAG = d +@COND_UNICODE_1@WXUNICODEFLAG = u +@COND_WXUNIV_1@WXUNIVNAME = univ +@COND_PLATFORM_MAC_1@__htmlctrl___mac_setfilecmd = \ +@COND_PLATFORM_MAC_1@ $(SETFILE) -a C htmlctrl$(EXEEXT) +@COND_PLATFORM_MAC_1@__htmlctrl___mac_rezcmd = $(__MACOSX_RESOURCES_p_1) +@COND_WXUNIV_1@__WXUNIV_DEFINE_p = -D__WXUNIVERSAL__ +@COND_WXUNIV_1@__WXUNIV_DEFINE_p_1 = -d __WXUNIVERSAL__ +@COND_WXUNIV_1@__WXUNIV_DEFINE_p_2 = --define __WXUNIVERSAL__ +@COND_SHARED_1@__DLLFLAG_p = -DWXUSINGDLL +@COND_SHARED_1@__DLLFLAG_p_1 = -d WXUSINGDLL +@COND_SHARED_1@__DLLFLAG_p_2 = --define WXUSINGDLL +COND_PLATFORM_OS2_1___htmlctrl___os2_emxbindcmd = $(NM) htmlctrl$(EXEEXT) | if \ + grep -q pmwin.763 ; then emxbind -ep htmlctrl$(EXEEXT) ; fi +@COND_PLATFORM_OS2_1@__htmlctrl___os2_emxbindcmd = $(COND_PLATFORM_OS2_1___htmlctrl___os2_emxbindcmd) +@COND_PLATFORM_WIN32_1@__htmlctrl___win32rc = htmlctrl_sample_rc.o +@COND_PLATFORM_OS2_1@__htmlctrl_os2_lib_res = \ +@COND_PLATFORM_OS2_1@ $(top_srcdir)/include/wx/os2/wx.res +@COND_PLATFORM_MACOSX_1@__htmlctrl_bundle___depname = htmlctrl_bundle +@COND_TOOLKIT_COCOA@____htmlctrl_BUNDLE_TGT_REF_DEP = \ +@COND_TOOLKIT_COCOA@ htmlctrl.app/Contents/PkgInfo +@COND_TOOLKIT_MAC@____htmlctrl_BUNDLE_TGT_REF_DEP = \ +@COND_TOOLKIT_MAC@ htmlctrl.app/Contents/PkgInfo +COND_MONOLITHIC_0___WXLIB_CORE_p = \ + -lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)_core-2.5$(HOST_SUFFIX) +@COND_MONOLITHIC_0@__WXLIB_CORE_p = $(COND_MONOLITHIC_0___WXLIB_CORE_p) +@COND_MONOLITHIC_0@__WXLIB_BASE_p = \ +@COND_MONOLITHIC_0@ -lwx_base$(WXBASEPORT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)-2.5$(HOST_SUFFIX) +COND_MONOLITHIC_1___WXLIB_MONO_p = \ + -lwx_$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)-2.5$(HOST_SUFFIX) +@COND_MONOLITHIC_1@__WXLIB_MONO_p = $(COND_MONOLITHIC_1___WXLIB_MONO_p) +@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@__LIB_TIFF_p \ +@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@ = \ +@COND_USE_GUI_1_WXUSE_LIBTIFF_BUILTIN@ -lwxtiff$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@__LIB_JPEG_p \ +@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@ = \ +@COND_USE_GUI_1_WXUSE_LIBJPEG_BUILTIN@ -lwxjpeg$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@__LIB_PNG_p \ +@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@ = \ +@COND_USE_GUI_1_WXUSE_LIBPNG_BUILTIN@ -lwxpng$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_WXUSE_ZLIB_BUILTIN@__LIB_ZLIB_p = \ +@COND_WXUSE_ZLIB_BUILTIN@ -lwxzlib$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_WXUSE_ODBC_BUILTIN@__LIB_ODBC_p = \ +@COND_WXUSE_ODBC_BUILTIN@ -lwxodbc$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_WXUSE_REGEX_BUILTIN@__LIB_REGEX_p = \ +@COND_WXUSE_REGEX_BUILTIN@ -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(HOST_SUFFIX) +@COND_WXUSE_EXPAT_BUILTIN@__LIB_EXPAT_p = \ +@COND_WXUSE_EXPAT_BUILTIN@ -lwxexpat$(WXDEBUGFLAG)$(HOST_SUFFIX) +COND_TOOLKIT_MAC___MACOSX_RESOURCES_p_1 = $(RESCOMP) -d __DARWIN__ -t APPL -d \ + __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_1) -i $(srcdir) $(__DLLFLAG_p_1) -i \ + $(srcdir)/../../../samples -i $(top_srcdir)/include -o htmlctrl$(EXEEXT) \ + Carbon.r $(LIBDIRNAME)/libwx_$(TOOLCHAIN_NAME).1.r sample.r +@COND_TOOLKIT_MAC@__MACOSX_RESOURCES_p_1 = $(COND_TOOLKIT_MAC___MACOSX_RESOURCES_p_1) + +### Targets: ### + +all: htmlctrl$(EXEEXT) $(__htmlctrl_bundle___depname) + +install: all + +uninstall: + +install-strip: install + +clean: + rm -rf ./.deps ./.pch + rm -f ./*.o + rm -f htmlctrl$(EXEEXT) + rm -rf htmlctrl.app + +distclean: clean + rm -f configure config.cache config.log config.status bk-deps bk-make-pch shared-ld-sh Makefile + +htmlctrl$(EXEEXT): $(HTMLCTRL_OBJECTS) $(__htmlctrl___win32rc) + $(CXX) -o $@ $(HTMLCTRL_OBJECTS) $(LDFLAGS) -L$(LIBDIRNAME) $(LDFLAGS_GUI) $(SAMPLES_RPATH_FLAG) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) $(__LIB_ZLIB_p) $(__LIB_ODBC_p) $(__LIB_REGEX_p) $(__LIB_EXPAT_p) $(EXTRALIBS) $(EXTRALIBS_GUI) + $(__htmlctrl___mac_rezcmd) + $(__htmlctrl___mac_setfilecmd) + $(__htmlctrl___os2_emxbindcmd) + $(SAMPLES_RPATH_POSTLINK) + +htmlctrl.app/Contents/PkgInfo: htmlctrl$(EXEEXT) $(top_srcdir)/src/mac/carbon/Info.plist.in $(LIBDIRNAME)/libwx_$(TOOLCHAIN_NAME).1.rsrc $(top_srcdir)/src/mac/carbon/wxmac.icns + mkdir -p htmlctrl.app/Contents + mkdir -p htmlctrl.app/Contents/MacOS + mkdir -p htmlctrl.app/Contents/Resources + + + sed -e "s/IDENTIFIER/`echo $(srcdir) | sed -e 's,\.\./,,g' | sed -e 's,/,.,g'`/" \ + -e "s/EXECUTABLE/htmlctrl/" \ + -e "s/VERSION/$(WX_VERSION)/" \ + $(top_srcdir)/src/mac/carbon/Info.plist.in >htmlctrl.app/Contents/Info.plist + + + echo -n "APPL????" >htmlctrl.app/Contents/PkgInfo + + + ln -f htmlctrl$(EXEEXT) htmlctrl.app/Contents/MacOS/htmlctrl + + + cp -f $(LIBDIRNAME)/libwx_$(TOOLCHAIN_NAME).1.rsrc htmlctrl.app/Contents/Resources/htmlctrl.rsrc + cp -f $(top_srcdir)/src/mac/carbon/wxmac.icns htmlctrl.app/Contents/Resources/wxmac.icns + +@COND_PLATFORM_MACOSX_1@htmlctrl_bundle: $(____htmlctrl_BUNDLE_TGT_REF_DEP) + +htmlctrl_sample_rc.o: $(srcdir)/../../../samples/sample.rc + $(RESCOMP) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_2) --include-dir $(srcdir) $(__DLLFLAG_p_2) --include-dir $(srcdir)/../../../samples --include-dir $(top_srcdir)/include + +htmlctrl_htmlctrl.o: $(srcdir)/htmlctrl.cpp + $(CXXC) -c -o $@ $(HTMLCTRL_CXXFLAGS) $< + + +# Include dependency info, if present: +@IF_GNU_MAKE@-include .deps/*.d + +.PHONY: all install uninstall clean distclean htmlctrl_bundle diff --git a/samples/html/htmlctrl/htmlctrl.bkl b/samples/html/htmlctrl/htmlctrl.bkl new file mode 100644 index 0000000000..55e5ec4be8 --- /dev/null +++ b/samples/html/htmlctrl/htmlctrl.bkl @@ -0,0 +1,14 @@ + + + + + + + + + htmlctrl.cpp + core + base + + + diff --git a/samples/html/htmlctrl/htmlctrl.cpp b/samples/html/htmlctrl/htmlctrl.cpp new file mode 100755 index 0000000000..58d01fbc2f --- /dev/null +++ b/samples/html/htmlctrl/htmlctrl.cpp @@ -0,0 +1,247 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: htmlctrl.cpp +// Purpose: HtmlCtrl sample +// Author: Julian Smart / Kevin Ollivier +// Modified by: +// Created: 04/16/2004 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart / Kevin Ollivier +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +// for all others, include the necessary headers (this file is usually all you +// need because it includes almost all "standard" wxWindows headers) +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/html/wxWebKit.h" + +// ---------------------------------------------------------------------------- +// resources +// ---------------------------------------------------------------------------- + +// the application icon (under Windows and OS/2 it is in resources and even +// though we could still include the XPM here it would be unused) +#if !defined(__WXMSW__) && !defined(__WXPM__) + #include "../../sample.xpm" +#endif + +enum { + ID_BACK = wxID_HIGHEST + 1, + ID_NEXT = wxID_HIGHEST + 2, + ID_RELOAD = wxID_HIGHEST + 3, + ID_URLLIST = wxID_HIGHEST + 4, + ID_STOP = wxID_HIGHEST + 5, + ID_WEBKIT = wxID_HIGHEST + 6, + ID_VIEW_SOURCE = wxID_HIGHEST + 7, + ID_OPEN = wxID_HIGHEST + 8, + ID_SAVE = wxID_HIGHEST + 9, + ID_SET_SOURCE = wxID_HIGHEST + 10 + }; + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// Define a new application type, each program should derive a class from wxApp +class MyApp : public wxApp +{ +public: + // override base class virtuals + // ---------------------------- + + // this one is called on application startup and is a good place for the app + // initialization (doing it here and not in the ctor allows to have an error + // return: if OnInit() returns false, the application terminates) + virtual bool OnInit(); +}; + +// Define a new frame type: this is going to be our main frame +class MyFrame : public wxFrame +{ +public: + // ctor(s) + MyFrame(const wxString& title); + void OnBackButton(wxCommandEvent& myEvent); + void OnNextButton(wxCommandEvent& myEvent); + void OnURLEnter(wxCommandEvent& myEvent); + void OnStopButton(wxCommandEvent& myEvent); + void OnReloadButton(wxCommandEvent& myEvent); + void OnViewSource(wxCommandEvent& myEvent); + void OnSetSource(wxCommandEvent& myEvent); + void OnStateChanged(wxWebKitStateChangedEvent& myEvent); + wxWebKitControl* mySafari; + wxTextCtrl* urlText; +private: + // any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() +}; + +// ---------------------------------------------------------------------------- +// event tables and other macros for wxWindows +// ---------------------------------------------------------------------------- + +// the event tables connect the wxWindows events with the functions (event +// handlers) which process them. It can be also done at run-time, but for the +// simple menu events like this the static method is much simpler. +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_BUTTON(ID_BACK, MyFrame::OnBackButton) + EVT_BUTTON(ID_NEXT, MyFrame::OnNextButton) + EVT_BUTTON(ID_STOP, MyFrame::OnStopButton) + EVT_BUTTON(ID_RELOAD, MyFrame::OnReloadButton) + EVT_MENU(ID_VIEW_SOURCE, MyFrame::OnViewSource) + EVT_MENU(ID_SET_SOURCE, MyFrame::OnSetSource) + EVT_TEXT_ENTER(ID_URLLIST, MyFrame::OnURLEnter) + EVT_WEBKIT_STATE_CHANGED(MyFrame::OnStateChanged) + //EVT_MENU(Minimal_Quit, MyFrame::OnQuit) + //EVT_MENU(Minimal_About, MyFrame::OnAbout) +END_EVENT_TABLE() + +// Create a new application object: this macro will allow wxWindows to create +// the application object during program execution (it's better than using a +// static object for many reasons) and also implements the accessor function +// wxGetApp() which will return the reference of the right type (i.e. MyApp and +// not wxApp) +IMPLEMENT_APP(MyApp) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// the application class +// ---------------------------------------------------------------------------- + +// 'Main program' equivalent: the program execution "starts" here +bool MyApp::OnInit() +{ + // create the main application window + MyFrame *frame = new MyFrame(_T("wxWebKit Sample")); + + // and show it (the frames, unlike simple controls, are not shown when + // created initially) + frame->Show(true); + + // success: wxApp::OnRun() will be called which will enter the main message + // loop and the application will run. If we returned false here, the + // application would exit immediately. + return true; +} + +// ---------------------------------------------------------------------------- +// main frame +// ---------------------------------------------------------------------------- + +// frame constructor +MyFrame::MyFrame(const wxString& title) + : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(500,500)) +{ + wxMenuBar* myBar = new wxMenuBar(); + wxMenu* fileMenu = new wxMenu(_("&File")); + fileMenu->Append(ID_OPEN, _("Open")); + fileMenu->Append(ID_SAVE, _("Save")); + myBar->Append(fileMenu, _("File")); + + wxMenu* editMenu = new wxMenu(_("Edit")); + editMenu->Append(ID_SET_SOURCE, _("Set Page Source")); + myBar->Append(editMenu, _("Edit")); + + //wxMenu* viewMenu = new wxMenu(_("View")); + //viewMenu->Append(ID_VIEW_SOURCE, _("View Source")); + //myBar->Append(viewMenu, _("View")); + + SetMenuBar(myBar); + + wxToolBar* myToolbar = CreateToolBar(); + wxButton* btnBack = new wxButton(myToolbar, ID_BACK, _("Back")); + myToolbar->AddControl(btnBack); + myToolbar->AddSeparator(); + wxButton* btnNext = new wxButton(myToolbar, ID_NEXT, _("Next")); + myToolbar->AddControl(btnNext); + myToolbar->AddSeparator(); + wxButton* btnStop = new wxButton(myToolbar, ID_STOP, _("Stop")); + myToolbar->AddControl(btnStop); + myToolbar->AddSeparator(); + wxButton* btnReload = new wxButton(myToolbar, ID_RELOAD, _("Reload")); + myToolbar->AddControl(btnReload); + myToolbar->AddSeparator(); + urlText = new wxTextCtrl(myToolbar, ID_URLLIST, _T("http://www.wxwidgets.org"), wxDefaultPosition, wxSize(220, -1), wxTE_PROCESS_ENTER); + myToolbar->AddControl(urlText); + myToolbar->AddSeparator(); + myToolbar->Realize(); + + mySafari = new wxWebKitControl(this, ID_WEBKIT, _T("http://www.wxwidgets.org"), wxDefaultPosition, wxSize(200, 200)); + +#if wxUSE_STATUSBAR + CreateStatusBar(2); +#endif // wxUSE_STATUSBAR +} + +void MyFrame::OnBackButton(wxCommandEvent& myEvent){ + if (mySafari->CanGoBack()) + mySafari->GoBack(); +} + +void MyFrame::OnNextButton(wxCommandEvent& myEvent){ + if (mySafari->CanGoForward()) + mySafari->GoForward(); +} + +void MyFrame::OnStopButton(wxCommandEvent& myEvent){ + mySafari->Stop(); +} + +void MyFrame::OnReloadButton(wxCommandEvent& myEvent){ + mySafari->Reload(); +} + +void MyFrame::OnURLEnter(wxCommandEvent& myEvent){ + mySafari->LoadURL(urlText->GetValue()); +} + +void MyFrame::OnStateChanged(wxWebKitStateChangedEvent& myEvent){ + if (GetStatusBar() != NULL){ + if (myEvent.GetState() == wxWEBKIT_STATE_NEGOTIATING){ + GetStatusBar()->SetStatusText(_("Contacting ") + myEvent.GetURL()); + } + else if (myEvent.GetState() == wxWEBKIT_STATE_TRANSFERRING){ + GetStatusBar()->SetStatusText(_("Loading ") + myEvent.GetURL()); + } + else if (myEvent.GetState() == wxWEBKIT_STATE_STOP){ + GetStatusBar()->SetStatusText(_("Load complete.")); + SetTitle(mySafari->GetTitle()); + } + else if (myEvent.GetState() == wxWEBKIT_STATE_FAILED){ + GetStatusBar()->SetStatusText(_("Failed to load ") + myEvent.GetURL()); + } + } + +} + +void MyFrame::OnViewSource(wxCommandEvent& myEvent){ + if (mySafari->CanGetPageSource()) + wxMessageBox(mySafari->GetPageSource()); +} + +void MyFrame::OnSetSource(wxCommandEvent& myEvent){ + if (mySafari){ + wxString myText = wxString("

Hello world!

"); + mySafari->SetPageSource(myText); + } +} diff --git a/src/html/htmlctrl/webkit/webkit.mm b/src/html/htmlctrl/webkit/webkit.mm new file mode 100755 index 0000000000..df80d539e6 --- /dev/null +++ b/src/html/htmlctrl/webkit/webkit.mm @@ -0,0 +1,334 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: webkit.mm +// Purpose: wxWebKitCtrl - embeddable web kit control +// Author: Jethro Grassie / Kevin Ollivier +// Modified by: +// Created: 2004-4-16 +// RCS-ID: $Id$ +// Copyright: (c) Jethro Grassie / Kevin Ollivier +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ + #pragma implementation "wxWebKit.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#ifdef __WXCOCOA__ +#include "wx/cocoa/autorelease.h" +#else +#include "wx/mac/uma.h" +#include +#include +#include +#endif + +#include "wx/html/webkit.h" +//#include "wx/html/wklisten.h" + + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl) +#endif + +BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl) + //EVT_SIZE(wxWebKitCtrl::OnSize) +END_EVENT_TABLE() + +// ---------------------------------------------------------------------------- +// wxWebKit Events +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS( wxWebKitStateChangedEvent, wxCommandEvent ) + +DEFINE_EVENT_TYPE( wxEVT_WEBKIT_STATE_CHANGED ) + +wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win ) +{ + SetEventType( wxEVT_WEBKIT_STATE_CHANGED); + SetEventObject( win ); + SetId(win->GetId()); +} + +//--------------------------------------------------------- +// helper functions for NSString<->wxString conversion +//--------------------------------------------------------- + +inline wxString wxStringWithNSString(NSString *nsstring) +{ +#if wxUSE_UNICODE + return wxString([nsstring UTF8String], wxConvUTF8); +#else + return wxString([nsstring lossyCString]); +#endif // wxUSE_UNICODE +} + +inline NSString* wxNSStringWithWxString(const wxString &wxstring) +{ +#if wxUSE_UNICODE + return [NSString stringWithUTF8String: wxstring.mb_str(wxConvUTF8)]; +#else + return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()]; +#endif // wxUSE_UNICODE +} + +@interface MyFrameLoadMonitor : NSObject +{ + wxWindow* webKitWindow; +} + +- initWithWxWindow: (wxWindow*)inWindow; + +@end + +// ---------------------------------------------------------------------------- +// creation/destruction +// ---------------------------------------------------------------------------- + +bool wxWebKitCtrl::Create(wxWindow *parent, + wxWindowID winID, + const wxString& strURL, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + + m_currentURL = strURL; + m_pageTitle = ""; + + //still needed for wxCocoa?? +/* + int width, height; + wxSize sizeInstance; + if (size.x == -1 || size.y == -1) + { + m_parent->GetClientSize(&width, &height); + sizeInstance.x = width; + sizeInstance.y = height; + } + else + { + sizeInstance.x = size.x; + sizeInstance.y = size.y; + } +*/ + // now create and attach WebKit view... +#ifdef __WXCOCOA__ + wxControl::Create(parent, m_windowID, pos, sizeInstance, style , validator , name); + SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y); + + wxTopLevelWindowCocoa *topWin = wxDynamicCast(this, wxTopLevelWindowCocoa); + NSWindow* nsWin = topWin->GetNSWindow(); + NSRect rect; + rect.origin.x = pos.x; + rect.origin.y = pos.y; + rect.size.width = sizeInstance.x; + rect.size.height = sizeInstance.y; + m_webView = (WebView*)[[WebView alloc] initWithFrame:rect frameName:@"webkitFrame" groupName:@"webkitGroup"]; + SetNSView(m_webView); + [m_cocoaNSView release]; + + if(m_parent) m_parent->CocoaAddChild(this); + SetInitialFrameRect(pos,sizeInstance); +#else + m_macIsUserPane = false; + wxControl::Create(parent, m_windowID, pos, size, style , validator , name); + WebInitForCarbon(); + HIWebViewCreate( (HIViewRef*) &m_macControl ); + MacPostControlCreate(pos, size); + + HIViewSetVisible( (HIViewRef) m_macControl, true ); + + m_webView = (WebView*) HIWebViewGetWebView( (HIViewRef) m_macControl ); +#endif + + // Register event listener interfaces + MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: (wxWindow*)this]; + [m_webView setFrameLoadDelegate:myFrameLoadMonitor]; + LoadURL(m_currentURL); + return true; +} + +wxWebKitCtrl::~wxWebKitCtrl() +{ + +} + +// ---------------------------------------------------------------------------- +// public methods +// ---------------------------------------------------------------------------- + +void wxWebKitCtrl::LoadURL(const wxString &url) +{ + if( !m_webView ) + return; + + [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithCString:url.c_str()]]]]; + + m_currentURL = url; +} + +bool wxWebKitCtrl::CanGoBack(){ + if ( !m_webView ) + return false; + + return [m_webView canGoBack]; +} + +bool wxWebKitCtrl::CanGoForward(){ + if ( !m_webView ) + return false; + + return [m_webView canGoForward]; +} + +bool wxWebKitCtrl::GoBack(){ + if ( !m_webView ) + return false; + + [m_webView goBack]; + return true; +} + +bool wxWebKitCtrl::GoForward(){ + if ( !m_webView ) + return false; + + [m_webView goForward]; + return true; +} + +void wxWebKitCtrl::Reload(){ + if ( !m_webView ) + return; + + [[m_webView mainFrame] reload]; +} + +void wxWebKitCtrl::Stop(){ + if ( !m_webView ) + return; + + [[m_webView mainFrame] stopLoading]; +} + +bool wxWebKitCtrl::CanGetPageSource(){ + if ( !m_webView ) + return; + + WebDataSource* dataSource = [[m_webView mainFrame] dataSource]; + return ( [[dataSource representation] canProvideDocumentSource] ); +} + +wxString wxWebKitCtrl::GetPageSource(){ + if ( !m_webView ) + return; + + if (CanGetPageSource()){ + WebDataSource* dataSource = [[m_webView mainFrame] dataSource]; + return wxStringWithNSString( [[dataSource representation] documentSource] ); + } + +} + +void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ + if ( !m_webView ) + return; + + if (CanGetPageSource()){ + [[m_webView mainFrame] loadHTMLString:(NSString*)wxNSStringWithWxString( source ) baseURL:[NSURL URLWithString:wxNSStringWithWxString( baseUrl )]]; + } + +} + + +//------------------------------------------------------------ +// Listener interfaces +//------------------------------------------------------------ + +@implementation MyFrameLoadMonitor + +- initWithWxWindow: (wxWindow*)inWindow +{ + [super init]; + webKitWindow = inWindow; // non retained + return self; +} + +- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + wxWebKitStateChangedEvent thisEvent(webKitWindow); + thisEvent.SetState(wxWEBKIT_STATE_NEGOTIATING); + thisEvent.SetURL( wxStringWithNSString( url ) ); + webKitWindow->GetEventHandler()->ProcessEvent( thisEvent ); + } +} + +- (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + wxWebKitStateChangedEvent thisEvent(webKitWindow); + thisEvent.SetState(wxWEBKIT_STATE_TRANSFERRING); + thisEvent.SetURL( wxStringWithNSString( url ) ); + webKitWindow->GetEventHandler()->ProcessEvent( thisEvent ); + } +} + +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + wxWebKitStateChangedEvent thisEvent(webKitWindow); + thisEvent.SetState(wxWEBKIT_STATE_STOP); + thisEvent.SetURL( wxStringWithNSString( url ) ); + webKitWindow->GetEventHandler()->ProcessEvent( thisEvent ); + } +} + +- (void)webView:(WebView *)sender didFailLoadWithError:(NSError*) error forFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + wxWebKitStateChangedEvent thisEvent(webKitWindow); + thisEvent.SetState(wxWEBKIT_STATE_FAILED); + thisEvent.SetURL( wxStringWithNSString( url ) ); + webKitWindow->GetEventHandler()->ProcessEvent( thisEvent ); + } +} + +- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError*) error forFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + wxWebKitStateChangedEvent thisEvent(webKitWindow); + thisEvent.SetState(wxWEBKIT_STATE_FAILED); + thisEvent.SetURL( wxStringWithNSString( url ) ); + webKitWindow->GetEventHandler()->ProcessEvent( thisEvent ); + } +} + +- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame +{ + if (frame == [sender mainFrame]){ + webKitWindow->SetTitle(wxStringWithNSString( title )); + } +} +@end \ No newline at end of file -- 2.45.2