Adding accessor methods for URL and Title, and another revision of the window sizing hack. Tested this one with wxWidgets sample, a notebook/splitter sample, and Documancer, a wxPython app, all with correct results.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33560 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2005-04-13 05:12:41 +00:00
parent 85f7030424
commit b4fd164d9c
3 changed files with 104 additions and 43 deletions

View File

@@ -67,6 +67,8 @@ public:
bool CanGetPageSource(); bool CanGetPageSource();
wxString GetPageSource(); wxString GetPageSource();
void SetPageSource(wxString& source, const wxString& baseUrl = wxEmptyString); void SetPageSource(wxString& source, const wxString& baseUrl = wxEmptyString);
wxString GetPageURL(){ return m_currentURL; }
wxString GetPageTitle(){ return m_pageTitle; }
//we need to resize the webview when the control size changes //we need to resize the webview when the control size changes
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);

View File

@@ -145,8 +145,8 @@ bool wxWebKitCtrl::Create(wxWindow *parent,
SetInitialFrameRect(pos,sizeInstance); SetInitialFrameRect(pos,sizeInstance);
#else #else
m_macIsUserPane = false; m_macIsUserPane = false;
wxControl::Create(parent, m_windowID, pos, size, style , validator , name);
m_peer = new wxMacControl(this); m_peer = new wxMacControl(this);
wxControl::Create(parent, m_windowID, pos, size, style , validator , name);
WebInitForCarbon(); WebInitForCarbon();
HIWebViewCreate( m_peer->GetControlRefAddr() ); HIWebViewCreate( m_peer->GetControlRefAddr() );
@@ -258,51 +258,108 @@ void wxWebKitCtrl::SetPageSource(wxString& source, const wxString& baseUrl){
void wxWebKitCtrl::OnSize(wxSizeEvent &event){ void wxWebKitCtrl::OnSize(wxSizeEvent &event){
// This is a nasty hack because WebKit seems to lose its position when it is embedded // 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. // in a control that is not itself the content view for a TLW.
// I put it in OnSize because these calcs are not perfect, and in fact are basically
// guesses based on reverse engineering, so it's best to give people the option of
// overriding OnSize with their own calcs if need be.
// I also left some test debugging print statements as a convenience if a(nother)
// problem crops up.
wxWindow* parent = GetParent(); // Let's hope that Tiger fixes this mess...
bool isParentTopLevel = true;
if (!parent->IsTopLevel())
isParentTopLevel = false;
int x = GetPosition().x; int x, y;
// we must take into account the title bar size as well, which is 26 pixels x = 0;
int y = GetPosition().y + 26; y = 0;
NSRect bounds = [m_webView frame]; bool isParentTopLevel = true;
wxWindow* tlw = NULL;
while(parent != NULL) wxWindow* parent = GetParent();
{
if (parent->IsTopLevel())
tlw = parent;
x += parent->GetPosition().x; wxWindow* tlw = MacGetTopLevelWindow();
y += parent->GetPosition().y;
if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ){ // This must be the case that Apple tested with, because well, in this one case
//manually account for the size the tabs take up // we don't need to do anything! It just works. ;)
y += 14; if (parent == tlw){
} return;
}
//if ( parent->GetClassInfo()->GetClassName() == wxT("wxSplitterWindow") ){ while(parent != NULL)
// x += 3; {
//} if ( parent->GetClassInfo()->GetClassName() == wxT("wxSplitterWindow") ){
//do nothing in this case
}
else{
if (!parent->IsTopLevel()) {
//printf("Parent: %s\n", parent->GetClassInfo()->GetClassName());
int plusx = 0;
plusx = parent->GetClientAreaOrigin().x + parent->GetPosition().x;
if (plusx > 0){
x += plusx;
//printf("Parent: %s Added x: %d\n", parent->GetClassInfo()->GetClassName(), parent->GetClientAreaOrigin().x + parent->GetPosition().x);
}
parent = parent->GetParent(); int plusy = 0;
} plusy = parent->GetClientAreaOrigin().y + parent->GetPosition().y;
if (plusy > 0){
y += plusy;
//printf("Parent: %s Added y: %d\n", parent->GetClassInfo()->GetClassName(), parent->GetClientAreaOrigin().y + parent->GetPosition().y);
}
else{
//printf("Parent: %s Origin: %d Position:%d\n", parent->GetClassInfo()->GetClassName(), parent->GetClientAreaOrigin().y, parent->GetPosition().y);
}
if (!isParentTopLevel){ }
if (tlw){ else{
//x = tlw->GetSize().x - (GetSize().x + x); //
y = tlw->GetSize().y - (GetSize().y + y); x += parent->GetClientAreaOrigin().x;
} // calculate the title bar height (26 pixels) into the top offset.
NSRect bounds = [m_webView frame]; // This becomes important later when we must flip the y coordinate
bounds.origin.x += x; // to convert to Cocoa's coordinate system.
bounds.origin.y += y; y += parent->GetClientAreaOrigin().y += 26;
//leaving debug checks in until I know it works everywhere ;-) //printf("x: %d, y:%d\n", x, y);
//printf("Added to bounds x=%d, y=%d\n", x, y); }
[m_webView setFrame:bounds]; //we still need to add the y, because we have to convert/flip coordinates for Cocoa
}
if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ){
//Not sure why calcs are off in this one scenario...
x -= 3;
//printf("x: %d, y:%d\n", x, y);
}
if (parent->IsKindOf( CLASSINFO( wxPanel ) ) ){
// Another strange case. Adding a wxPanel to the parent heirarchy
// causes wxWebKitCtrl's Cocoa y origin to be 4 pixels off
// for some reason, even if the panel has a position and origin of 0.
// This corrects that. Man, I wish I could debug Carbon/HIWebView!! ;)
y -= 4;
}
}
parent = parent->GetParent();
}
// Tried using MacWindowToRootWindow both for wxWebKitCtrl and its parent,
// but coordinates were off by a significant amount.
// Am leaving the code here if anyone wants to play with it.
//int x2, y2 = 0;
//if (GetParent())
// GetParent()->MacWindowToRootWindow(&x2, &y2);
//printf("x = %d, y = %d\n", x, y);
//printf("x2 = %d, y2 = %d\n", x2, y2);
//x = x2;
//y = y2;
if (tlw){
//flip the y coordinate to convert to Cocoa coordinates
//printf("tlw y: %d, y: %d\n", tlw->GetSize().y, (GetSize().y + y));
y = tlw->GetSize().y - ((GetSize().y) + y);
}
//printf("Added to bounds x=%d, y=%d\n", x, y);
NSRect bounds = [m_webView frame];
bounds.origin.x = x;
bounds.origin.y = y;
[m_webView setFrame:bounds];
//printf("Carbon position x=%d, y=%d\n", GetPosition().x, GetPosition().y); //printf("Carbon position x=%d, y=%d\n", GetPosition().x, GetPosition().y);
if (IsShown()) if (IsShown())

View File

@@ -86,6 +86,8 @@ public:
bool CanGetPageSource() { return false; } bool CanGetPageSource() { return false; }
wxString GetPageSource() { return wxEmptyString; } wxString GetPageSource() { return wxEmptyString; }
void SetPageSource(wxString& source, const wxString& baseUrl = wxEmptyString) {} void SetPageSource(wxString& source, const wxString& baseUrl = wxEmptyString) {}
wxString GetPageURL(){ return m_currentURL; }
wxString GetPageTitle(){ return m_pageTitle; }
}; };