]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/htmlctrl/webkit/webkit.mm
draw focus rect for wxCheckListBox item
[wxWidgets.git] / src / html / htmlctrl / webkit / webkit.mm
index 5af328fa45ee0eeaf5eaf72f9e94e4baa633d545..86ae7405618a81e18bf17152dfc77317670b409d 100644 (file)
@@ -26,7 +26,7 @@
 #ifdef __WXCOCOA__
 #include "wx/cocoa/autorelease.h"
 #else
-#include "wx/mac/uma.h"
+#include "wx/osx/uma.h"
 #include <Carbon/Carbon.h>
 #include <WebKit/WebKit.h>
 #include <WebKit/HIWebView.h>
@@ -288,27 +288,50 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebKitCtrlEventHandler )
 
 IMPLEMENT_DYNAMIC_CLASS( wxWebKitStateChangedEvent, wxCommandEvent )
 
-DEFINE_EVENT_TYPE( wxEVT_WEBKIT_STATE_CHANGED )
+wxDEFINE_EVENT( wxEVT_WEBKIT_STATE_CHANGED, wxWebKitStateChangedEvent );
 
 wxWebKitStateChangedEvent::wxWebKitStateChangedEvent( wxWindow* win )
 {
     SetEventType( wxEVT_WEBKIT_STATE_CHANGED);
-    SetEventObject( win );
-    SetId(win->GetId());
+    if ( win )
+    {
+        SetEventObject( win );
+        SetId(win->GetId());
+    }
 }
 
 IMPLEMENT_DYNAMIC_CLASS( wxWebKitBeforeLoadEvent, wxCommandEvent )
 
-DEFINE_EVENT_TYPE( wxEVT_WEBKIT_BEFORE_LOAD )
+wxDEFINE_EVENT( wxEVT_WEBKIT_BEFORE_LOAD, wxWebKitBeforeLoadEvent );
 
 wxWebKitBeforeLoadEvent::wxWebKitBeforeLoadEvent( wxWindow* win )
 {
     m_cancelled = false;
     SetEventType( wxEVT_WEBKIT_BEFORE_LOAD);
-    SetEventObject( win );
-    SetId(win->GetId());
+    if ( win )
+    {
+        SetEventObject( win );
+        SetId(win->GetId());
+    }
+}
+
+
+IMPLEMENT_DYNAMIC_CLASS( wxWebKitNewWindowEvent, wxCommandEvent )
+
+wxDEFINE_EVENT( wxEVT_WEBKIT_NEW_WINDOW, wxWebKitNewWindowEvent );
+
+wxWebKitNewWindowEvent::wxWebKitNewWindowEvent( wxWindow* win )
+{
+    SetEventType( wxEVT_WEBKIT_NEW_WINDOW);
+    if ( win )
+    {
+        SetEventObject( win );
+        SetId(win->GetId());
+    }
 }
 
+
+
 //---------------------------------------------------------
 // helper functions for NSString<->wxString conversion
 //---------------------------------------------------------
@@ -454,7 +477,16 @@ bool wxWebKitCtrl::Create(wxWindow *parent,
 
 wxWebKitCtrl::~wxWebKitCtrl()
 {
-
+    MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate];
+    MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate];
+    [m_webView setFrameLoadDelegate: nil];
+    [m_webView setPolicyDelegate: nil];
+    
+    if (myFrameLoadMonitor)
+        [myFrameLoadMonitor release];
+        
+    if (myPolicyDelegate)
+        [myPolicyDelegate release];
 }
 
 // ----------------------------------------------------------------------------
@@ -668,8 +700,8 @@ void wxWebKitCtrl::OnSize(wxSizeEvent &event){
 
     wxWindow* tlw = MacGetTopLevelWindow();
 
-    NSRect frame = [m_webView frame];
-    NSRect bounds = [m_webView bounds];
+    NSRect frame = [(WebView*)m_webView frame];
+    NSRect bounds = [(WebView*)m_webView bounds];
 
 #if DEBUG_WEBKIT_SIZING
     fprintf(stderr,"Carbon window x=%d, y=%d, width=%d, height=%d\n", GetPosition().x, GetPosition().y, GetSize().x, GetSize().y);
@@ -720,7 +752,7 @@ void wxWebKitCtrl::OnSize(wxSizeEvent &event){
 
     frame.origin.x = x;
     frame.origin.y = y;
-    [m_webView setFrame:frame];
+    [(WebView*)m_webView setFrame:frame];
 
     if (IsShown())
         [(WebView*)m_webView display];
@@ -858,6 +890,19 @@ void wxWebKitCtrl::MacVisibilityChanged(){
         [listener use];
 }
 
+- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
+{
+    wxWebKitNewWindowEvent thisEvent(webKitWindow);
+
+    NSString *url = [[request URL] absoluteString];
+    thisEvent.SetURL( wxStringWithNSString( url ) );
+    thisEvent.SetTargetName( wxStringWithNSString( frameName ) );
+    
+    if (webKitWindow && webKitWindow->GetEventHandler())
+        webKitWindow->GetEventHandler()->ProcessEvent(thisEvent);
+
+    [listener use];
+}
 @end
 
 #endif //wxUSE_WEBKIT