#pragma implementation "webkit.h"
#endif
-#if wxUSE_WEBKIT
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/wx.h"
#endif
+#if wxUSE_WEBKIT
+
#ifdef __WXCOCOA__
#include "wx/cocoa/autorelease.h"
#else
m_currentURL = strURL;
//m_pageTitle = _("Untitled Page");
-
+
//still needed for wxCocoa??
/*
int width, height;
wxSize sizeInstance;
- if (size.x == -1 || size.y == -1)
+ if (size.x == wxDefaultCoord || size.y == wxDefaultCoord)
{
m_parent->GetClientSize(&width, &height);
sizeInstance.x = width;
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;
SetInitialFrameRect(pos,sizeInstance);
#else
m_macIsUserPane = false;
+ m_peer = new wxMacControl(this);
wxControl::Create(parent, m_windowID, pos, size, style , validator , name);
WebInitForCarbon();
- HIWebViewCreate( (HIViewRef*) *m_peer );
-
- m_webView = (WebView*) HIWebViewGetWebView( (HIViewRef) *m_peer );
+ HIWebViewCreate( m_peer->GetControlRefAddr() );
+
+ m_webView = (WebView*) HIWebViewGetWebView( m_peer->GetControlRef() );
MacPostControlCreate(pos, size);
- HIViewSetVisible( (HIViewRef) *m_peer, true );
+ 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;
}
{
if( !m_webView )
return;
-
+
[[m_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:wxNSStringWithWxString(url)]]];
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 result = [(WebView*)m_webView goBack];
+ return result;
}
-bool wxWebKitCtrl::GoForward(){
+bool wxWebKitCtrl::GoForward(){
if ( !m_webView )
return false;
-
- [m_webView goForward];
- return true;
+
+ bool result = [(WebView*)m_webView goForward];
+ return result;
}
-void wxWebKitCtrl::Reload(){
+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 false;
-
+
WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
return ( [[dataSource representation] canProvideDocumentSource] );
}
wxString wxWebKitCtrl::GetPageSource(){
- if ( !m_webView )
- return wxT("");
-
+
if (CanGetPageSource()){
WebDataSource* dataSource = [[m_webView mainFrame] dataSource];
return wxStringWithNSString( [[dataSource representation] documentSource] );
}
-
+
+ return wxEmptyString;
}
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 )]];
}
}
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.
+ // 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 inNotebook = false;
- int x = 0;
- int y = 18;
+ 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)
{
- // 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->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->IsKindOf( CLASSINFO( wxNotebook ) ) ){
- inNotebook = true;
- }
+
+ //if ( parent->GetClassInfo()->GetClassName() == wxT("wxSplitterWindow") ){
+ // x += 3;
+ //}
+
parent = parent->GetParent();
}
-
- if (inNotebook){
+
+ 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];
}
-
- [m_webView display];
+
+ //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( (HIViewRef)*m_peer);
+ bool isHidden = !IsControlVisible( m_peer->GetControlRef());
+ if (!isHidden)
+ [m_webView display];
+
[m_webView setHidden:isHidden];
}
}
@end
-#endif //wxUSE_WEBKIT
\ No newline at end of file
+#endif //wxUSE_WEBKIT