#include "wx/wx.h"
#endif
+#if wxUSE_WEBKIT
+
#ifdef __WXCOCOA__
#include "wx/cocoa/autorelease.h"
#else
#endif
#include "wx/html/webkit.h"
-//#include "wx/html/wklisten.h"
+#include "wx/notebook.h"
// ----------------------------------------------------------------------------
{
m_currentURL = strURL;
- m_pageTitle = wxT("");
+ //m_pageTitle = _("Untitled Page");
//still needed for wxCocoa??
/*
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;
}
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(){
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){
}
void wxWebKitCtrl::OnSize(wxSizeEvent &event){
- [m_webView display];
+ // This is a nasty hack because WebKit seems to lose its position when it is embedded
+ // in a control that is not itself the content view for a TLW.
+
+ wxWindow* parent = GetParent();
+ bool isParentTopLevel = true;
+ if (!parent->IsTopLevel())
+ isParentTopLevel = false;
+
+ int x = GetPosition().x;
+ // we must take into account the title bar size as well, which is 26 pixels
+ int y = GetPosition().y + 26;
+
+ NSRect bounds = [m_webView frame];
+ wxWindow* tlw = NULL;
+
+ while(parent != NULL)
+ {
+ if (parent->IsTopLevel())
+ tlw = parent;
+
+ x += parent->GetPosition().x;
+ y += parent->GetPosition().y;
+
+ if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ){
+ //manually account for the size the tabs take up
+ y += 14;
+ }
+
+ //if ( parent->GetClassInfo()->GetClassName() == wxT("wxSplitterWindow") ){
+ // x += 3;
+ //}
+
+ parent = parent->GetParent();
+ }
+
+ if (!isParentTopLevel){
+ if (tlw){
+ //x = tlw->GetSize().x - (GetSize().x + x);
+ y = tlw->GetSize().y - (GetSize().y + y);
+ }
+ NSRect bounds = [m_webView frame];
+ bounds.origin.x += x;
+ bounds.origin.y += y;
+ //leaving debug checks in until I know it works everywhere ;-)
+ //printf("Added to bounds x=%d, y=%d\n", x, y);
+ [m_webView setFrame:bounds];
+ }
+
+ //printf("Carbon position x=%d, y=%d\n", GetPosition().x, GetPosition().y);
+ if (IsShown())
+ [m_webView display];
event.Skip();
}
+void wxWebKitCtrl::MacVisibilityChanged(){
+ bool isHidden = !IsControlVisible( m_peer->GetControlRef());
+ if (!isHidden)
+ [m_webView display];
+
+ [m_webView setHidden:isHidden];
+}
+
//------------------------------------------------------------
// Listener interfaces
//------------------------------------------------------------
- (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 ) );
- (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 ) );
- (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 ) );
}
}
@end
+
+#endif //wxUSE_WEBKIT