X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ca7ba7403b46d7aabe75b03d539cfc41a4bd49a..74c5a810e54fd8fcd6a94e5d66d8c9addb68a8b9:/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 03dd2920a8..1b6155d173 100755 --- a/src/html/htmlctrl/webkit/webkit.mm +++ b/src/html/htmlctrl/webkit/webkit.mm @@ -20,6 +20,8 @@ #include "wx/wx.h" #endif +#if wxUSE_WEBKIT + #ifdef __WXCOCOA__ #include "wx/cocoa/autorelease.h" #else @@ -30,7 +32,7 @@ #endif #include "wx/html/webkit.h" -//#include "wx/html/wklisten.h" +#include "wx/notebook.h" // ---------------------------------------------------------------------------- @@ -42,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() // ---------------------------------------------------------------------------- @@ -105,7 +107,7 @@ bool wxWebKitCtrl::Create(wxWindow *parent, { m_currentURL = strURL; - m_pageTitle = wxT(""); + //m_pageTitle = _("Untitled Page"); //still needed for wxCocoa?? /* @@ -143,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]; + LoadURL(m_currentURL); return true; } @@ -225,7 +229,7 @@ void wxWebKitCtrl::Stop(){ bool wxWebKitCtrl::CanGetPageSource(){ if ( !m_webView ) - return; + return false; WebDataSource* dataSource = [[m_webView mainFrame] dataSource]; return ( [[dataSource representation] canProvideDocumentSource] ); @@ -233,7 +237,7 @@ bool wxWebKitCtrl::CanGetPageSource(){ wxString wxWebKitCtrl::GetPageSource(){ if ( !m_webView ) - return; + return wxT(""); if (CanGetPageSource()){ WebDataSource* dataSource = [[m_webView mainFrame] dataSource]; @@ -252,6 +256,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 @@ -280,7 +325,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 ) ); @@ -291,7 +336,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 ) ); @@ -302,7 +347,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 ) ); @@ -328,3 +373,5 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){ } } @end + +#endif //wxUSE_WEBKIT