]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/window.mm
minor changes to eliminate unused parameter warning + some cleanup
[wxWidgets.git] / src / cocoa / window.mm
index d32720d412a68f8f767e37d3411a468bca1c8a08..33e54d67d32803bd83597ddfda8c58f539aa9d02 100644 (file)
@@ -12,6 +12,8 @@
 #include "wx/window.h"
 #include "wx/log.h"
 
+#include "wx/cocoa/autorelease.h"
+
 #import <Appkit/NSView.h>
 #import <AppKit/NSEvent.h>
 
@@ -25,6 +27,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
 END_EVENT_TABLE()
 
+wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
+
 // Constructor
 void wxWindowCocoa::Init()
 {
@@ -33,6 +37,7 @@ void wxWindowCocoa::Init()
     m_cocoaNSView = NULL;
     m_dummyNSView = NULL;
     m_isBeingDeleted = FALSE;
+    m_isInPaint = FALSE;
 }
 
 // Constructor
@@ -63,6 +68,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
 // Destructor
 wxWindow::~wxWindow()
 {
+    wxAutoNSAutoreleasePool pool;
     DestroyChildren();
 
     if(m_parent)
@@ -107,23 +113,32 @@ void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
 {
     bool need_debug = cocoaNSView || m_cocoaNSView;
     if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d",this,m_cocoaNSView,[m_cocoaNSView retainCount]);
-    if(m_cocoaNSView)
-        DisassociateNSView(m_cocoaNSView);
+    DisassociateNSView(m_cocoaNSView);
     [cocoaNSView retain];
     [m_cocoaNSView release];
     m_cocoaNSView = cocoaNSView;
-    if(m_cocoaNSView)
-        AssociateNSView(m_cocoaNSView);
+    AssociateNSView(m_cocoaNSView);
     if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]);
 }
 
 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
 {
     wxLogDebug("Cocoa_drawRect");
+    // Recursion can happen if the event loop runs from within the paint
+    // handler.  For instance, if an assertion dialog is shown.
+    // FIXME: This seems less than ideal.
+    if(m_isInPaint)
+    {
+        wxLogDebug("Paint event recursion!");
+        return false;
+    }
     //FIXME: should probably turn that rect into the update region
+    m_isInPaint = TRUE;
     wxPaintEvent event(m_windowId);
     event.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(event);
+    bool ret = GetEventHandler()->ProcessEvent(event);
+    m_isInPaint = FALSE;
+    return ret;
 }
 
 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
@@ -234,17 +249,19 @@ bool wxWindow::Close(bool force)
 
 bool wxWindow::Show(bool show)
 {
+    wxAutoNSAutoreleasePool pool;
     // If the window is marked as visible, then it shouldn't have a dummy view
     // If the window is marked hidden, then it should have a dummy view
-    wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),"wxWindow: m_isShown does not agree with m_dummyNSView");
+    // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
+//    wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),"wxWindow: m_isShown does not agree with m_dummyNSView");
     // Return false if there isn't a window to show or hide
     if(!m_cocoaNSView)
         return false;
-    // Return false if the state isn't changing
-    if( show == m_isShown )
-        return false;
     if(show)
     {
+        // If state isn't changing, return false
+        if(!m_dummyNSView)
+            return false;
         // replaceSubView releases m_dummyNSView, balancing the alloc
         [m_cocoaNSView retain];
         [[m_dummyNSView superview] replaceSubview:m_dummyNSView with:m_cocoaNSView];
@@ -256,6 +273,9 @@ bool wxWindow::Show(bool show)
     }
     else
     {
+        // If state isn't changing, return false
+        if(m_dummyNSView)
+            return false;
         m_dummyNSView = [[NSView alloc] initWithFrame: [m_cocoaNSView frame]];
         [m_dummyNSView retain];
         // NOTE: replaceSubView will cause m_cocaNSView to be released
@@ -368,11 +388,13 @@ void wxWindow::SetFocus()
 void wxWindow::DoCaptureMouse()
 {
     // TODO
+    sm_capturedWindow = this;
 }
 
 void wxWindow::DoReleaseMouse()
 {
     // TODO
+    sm_capturedWindow = NULL;
 }
 
 void wxWindow::DoScreenToClient(int *x, int *y) const
@@ -475,6 +497,7 @@ void wxWindow::Clear()
 // Raise the window to the top of the Z order
 void wxWindow::Raise()
 {
+    wxAutoNSAutoreleasePool pool;
     NSView *nsview = m_dummyNSView?m_dummyNSView:m_cocoaNSView;
     NSView *superview = [nsview superview];
     [nsview retain];
@@ -503,7 +526,7 @@ wxWindow *wxWindowBase::FindFocus()
 /* static */ wxWindow *wxWindowBase::GetCapture()
 {
     // TODO
-    return NULL;
+    return wxWindowCocoa::sm_capturedWindow;
 }
 
 wxWindow *wxGetActiveWindow()
@@ -512,3 +535,15 @@ wxWindow *wxGetActiveWindow()
     return NULL;
 }
 
+wxPoint wxGetMousePosition()
+{
+    // TODO
+    return wxDefaultPosition;
+}
+
+wxWindow* wxFindWindowAtPointer(wxPoint& pt)
+{
+    pt = wxGetMousePosition();
+    return NULL;
+}
+