X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2c990ba6d4f88e18e6666f61efe55c7a8b5cc948..a91fbc8e34b7b4bf203b03ac66f129e85cdfa53b:/src/html/htmlctrl/webkit/webkit.mm?ds=sidebyside diff --git a/src/html/htmlctrl/webkit/webkit.mm b/src/html/htmlctrl/webkit/webkit.mm index df80d539e6..cb85a483a4 100755 --- a/src/html/htmlctrl/webkit/webkit.mm +++ b/src/html/htmlctrl/webkit/webkit.mm @@ -9,21 +9,19 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ - #pragma implementation "wxWebKit.h" +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) + #pragma implementation "webkit.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 +#if wxUSE_WEBKIT + #ifdef __WXCOCOA__ #include "wx/cocoa/autorelease.h" #else @@ -34,7 +32,7 @@ #endif #include "wx/html/webkit.h" -//#include "wx/html/wklisten.h" +#include "wx/notebook.h" // ---------------------------------------------------------------------------- @@ -46,7 +44,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxWebKitCtrl, wxControl) #endif BEGIN_EVENT_TABLE(wxWebKitCtrl, wxControl) - //EVT_SIZE(wxWebKitCtrl::OnSize) + EVT_SIZE(wxWebKitCtrl::OnSize) END_EVENT_TABLE() // ---------------------------------------------------------------------------- @@ -61,7 +59,7 @@ wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win ) { SetEventType( wxEVT_WEBKIT_STATE_CHANGED); SetEventObject( win ); - SetId(win->GetId()); + SetId(win->GetId()); } //--------------------------------------------------------- @@ -100,41 +98,41 @@ inline NSString* wxNSStringWithWxString(const wxString &wxstring) // ---------------------------------------------------------------------------- bool wxWebKitCtrl::Create(wxWindow *parent, - wxWindowID winID, + wxWindowID winID, const wxString& strURL, const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) { m_currentURL = strURL; - m_pageTitle = ""; + //m_pageTitle = _("Untitled Page"); //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... + 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); + SetSize(pos.x, pos.y, sizeInstance.x, sizeInstance.y); wxTopLevelWindowCocoa *topWin = wxDynamicCast(this, wxTopLevelWindowCocoa); NSWindow* nsWin = topWin->GetNSWindow(); - NSRect rect; + NSRect rect; rect.origin.x = pos.x; rect.origin.y = pos.y; rect.size.width = sizeInstance.x; @@ -147,19 +145,21 @@ bool wxWebKitCtrl::Create(wxWindow *parent, SetInitialFrameRect(pos,sizeInstance); #else m_macIsUserPane = false; + m_peer = new wxMacControl(); wxControl::Create(parent, m_windowID, pos, size, style , validator , name); WebInitForCarbon(); - HIWebViewCreate( (HIViewRef*) &m_macControl ); - MacPostControlCreate(pos, size); - - HIViewSetVisible( (HIViewRef) m_macControl, true ); + HIWebViewCreate( m_peer->GetControlRefAddr() ); - m_webView = (WebView*) HIWebViewGetWebView( (HIViewRef) m_macControl ); + m_webView = (WebView*) HIWebViewGetWebView( m_peer->GetControlRef() ); + MacPostControlCreate(pos, size); + HIViewSetVisible( m_peer->GetControlRef(), true ); + [m_webView setHidden:false]; #endif // Register event listener interfaces MyFrameLoadMonitor* myFrameLoadMonitor = [[MyFrameLoadMonitor alloc] initWithWxWindow: (wxWindow*)this]; - [m_webView setFrameLoadDelegate:myFrameLoadMonitor]; + [m_webView setFrameLoadDelegate:myFrameLoadMonitor]; + LoadURL(m_currentURL); return true; } @@ -178,7 +178,7 @@ void wxWebKitCtrl::LoadURL(const wxString &url) if( !m_webView ) return; - [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithCString:url.c_str()]]]]; + [[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:wxNSStringWithWxString(url)]]]; m_currentURL = url; } @@ -200,17 +200,17 @@ bool wxWebKitCtrl::CanGoForward(){ bool wxWebKitCtrl::GoBack(){ if ( !m_webView ) return false; - - [m_webView goBack]; - return true; + + bool result = [(WebView*)m_webView goBack]; + return result; } bool wxWebKitCtrl::GoForward(){ if ( !m_webView ) return false; - [m_webView goForward]; - return true; + bool result = [(WebView*)m_webView goForward]; + return result; } void wxWebKitCtrl::Reload(){ @@ -229,21 +229,20 @@ void wxWebKitCtrl::Stop(){ bool wxWebKitCtrl::CanGetPageSource(){ if ( !m_webView ) - return; + return false; 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] ); } + return wxT(""); } void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ @@ -256,6 +255,47 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ } +void wxWebKitCtrl::OnSize(wxSizeEvent &event){ + // This is a nasty hack because WebKit does not seem to recognize a Tabs control as its parent. + // Therefore, coordinates must be relative to the left-hand side of the screen, rather than + // relative to the Tabs control. + wxWindow* parent = GetParent(); + bool inNotebook = false; + int x = 0; + int y = 18; + while(parent != NULL) + { + // keep adding the position until we hit the notebook + if (!inNotebook){ + x += parent->GetPosition().x; + y += parent->GetPosition().y; + } + + if ( parent->GetClassInfo()->GetClassName() == wxT("wxSplitterWindow") ){ + x += 3; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ){ + inNotebook = true; + } + parent = parent->GetParent(); + } + + if (inNotebook){ + NSRect bounds = [m_webView frame]; + bounds.origin.x += x; + bounds.origin.y += y; + [m_webView setFrame:bounds]; + } + + [m_webView display]; + event.Skip(); +} + +void wxWebKitCtrl::MacVisibilityChanged(){ + bool isHidden = !IsControlVisible( m_peer->GetControlRef()); + [m_webView setHidden:isHidden]; +} //------------------------------------------------------------ // Listener interfaces @@ -266,7 +306,7 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ - initWithWxWindow: (wxWindow*)inWindow { [super init]; - webKitWindow = inWindow; // non retained + webKitWindow = inWindow; // non retained return self; } @@ -284,7 +324,7 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { if (frame == [sender mainFrame]){ - NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + NSString *url = [[[[frame dataSource] request] URL] absoluteString]; wxWebKitStateChangedEvent thisEvent(webKitWindow); thisEvent.SetState(wxWEBKIT_STATE_TRANSFERRING); thisEvent.SetURL( wxStringWithNSString( url ) ); @@ -295,7 +335,7 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { if (frame == [sender mainFrame]){ - NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + NSString *url = [[[[frame dataSource] request] URL] absoluteString]; wxWebKitStateChangedEvent thisEvent(webKitWindow); thisEvent.SetState(wxWEBKIT_STATE_STOP); thisEvent.SetURL( wxStringWithNSString( url ) ); @@ -306,7 +346,7 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ - (void)webView:(WebView *)sender didFailLoadWithError:(NSError*) error forFrame:(WebFrame *)frame { if (frame == [sender mainFrame]){ - NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString]; + NSString *url = [[[[frame dataSource] request] URL] absoluteString]; wxWebKitStateChangedEvent thisEvent(webKitWindow); thisEvent.SetState(wxWEBKIT_STATE_FAILED); thisEvent.SetURL( wxStringWithNSString( url ) ); @@ -331,4 +371,6 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ webKitWindow->SetTitle(wxStringWithNSString( title )); } } -@end \ No newline at end of file +@end + +#endif //wxUSE_WEBKIT