]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/window.mm
1) some compilers (Watcom) don't like it if wxBase library PCH file contains
[wxWidgets.git] / src / cocoa / window.mm
index 3155c35f687f9f0c0470f58a2b5f5f53bb9ed590..8405b331827152973c53c41f4e5e563c8f89d2f5 100644 (file)
@@ -27,6 +27,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
 END_EVENT_TABLE()
 
+wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
+
 // Constructor
 void wxWindowCocoa::Init()
 {
 // Constructor
 void wxWindowCocoa::Init()
 {
@@ -78,13 +80,6 @@ wxWindow::~wxWindow()
 
 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
 {
 
 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
 {
-    [child->m_cocoaNSView retain];
-    // NOTE: addSubView takes ownership of, but does not retain the subview
-    // Upon a removeFromView or closing the super view, the child WILL be
-    // released!!!  I think the idea here is that normally you would alloc
-    // the subview and add it to the superview and this way you don't have
-    // to release what you just alloced.  Unfortunately, that doesn't
-    // make sense for wxCocoa, so we do this instead.
     [m_cocoaNSView addSubview: child->m_cocoaNSView];
     wxASSERT(!child->m_dummyNSView);
     child->m_isShown = true;
     [m_cocoaNSView addSubview: child->m_cocoaNSView];
     wxASSERT(!child->m_dummyNSView);
     child->m_isShown = true;
@@ -95,9 +90,9 @@ void wxWindowCocoa::CocoaRemoveFromParent(void)
     if(m_dummyNSView)
     {
         wxASSERT(m_cocoaNSView);
     if(m_dummyNSView)
     {
         wxASSERT(m_cocoaNSView);
-        // balances the alloc
+        // balances the replaceSubView:with:
         [m_dummyNSView removeFromSuperview];
         [m_dummyNSView removeFromSuperview];
-        // But since we also retained it ourselves
+        // But since we were the ones to alloc it
         [m_dummyNSView release];
         m_dummyNSView = nil;
         // m_cocoaNSView has of course already been removed by virtue of
         [m_dummyNSView release];
         m_dummyNSView = nil;
         // m_cocoaNSView has of course already been removed by virtue of
@@ -260,11 +255,11 @@ bool wxWindow::Show(bool show)
         // If state isn't changing, return false
         if(!m_dummyNSView)
             return false;
         // If state isn't changing, return false
         if(!m_dummyNSView)
             return false;
-        // replaceSubView releases m_dummyNSView, balancing the alloc
-        [m_cocoaNSView retain];
+        // replaceSubView:with: releases m_dummyNSView, balancing the
+        // previous replaceSubView:with
         [[m_dummyNSView superview] replaceSubview:m_dummyNSView with:m_cocoaNSView];
         [[m_dummyNSView superview] replaceSubview:m_dummyNSView with:m_cocoaNSView];
-        // But since we also retained it ourselves
         wxASSERT(![m_dummyNSView superview]);
         wxASSERT(![m_dummyNSView superview]);
+        // But since we were the ones to alloc it
         [m_dummyNSView release];
         m_dummyNSView = nil;
         wxASSERT([m_cocoaNSView superview]);
         [m_dummyNSView release];
         m_dummyNSView = nil;
         wxASSERT([m_cocoaNSView superview]);
@@ -275,8 +270,8 @@ bool wxWindow::Show(bool show)
         if(m_dummyNSView)
             return false;
         m_dummyNSView = [[NSView alloc] initWithFrame: [m_cocoaNSView frame]];
         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
+        // NOTE: replaceSubView will cause m_cocaNSView to be (auto)released
+        // which balances out addSubView
         [[m_cocoaNSView superview] replaceSubview:m_cocoaNSView with:m_dummyNSView];
         // m_coocaNSView is now only retained by us
         wxASSERT([m_dummyNSView superview]);
         [[m_cocoaNSView superview] replaceSubview:m_cocoaNSView with:m_dummyNSView];
         // m_coocaNSView is now only retained by us
         wxASSERT([m_dummyNSView superview]);
@@ -386,11 +381,13 @@ void wxWindow::SetFocus()
 void wxWindow::DoCaptureMouse()
 {
     // TODO
 void wxWindow::DoCaptureMouse()
 {
     // TODO
+    sm_capturedWindow = this;
 }
 
 void wxWindow::DoReleaseMouse()
 {
     // TODO
 }
 
 void wxWindow::DoReleaseMouse()
 {
     // TODO
+    sm_capturedWindow = NULL;
 }
 
 void wxWindow::DoScreenToClient(int *x, int *y) const
 }
 
 void wxWindow::DoScreenToClient(int *x, int *y) const
@@ -496,7 +493,6 @@ void wxWindow::Raise()
     wxAutoNSAutoreleasePool pool;
     NSView *nsview = m_dummyNSView?m_dummyNSView:m_cocoaNSView;
     NSView *superview = [nsview superview];
     wxAutoNSAutoreleasePool pool;
     NSView *nsview = m_dummyNSView?m_dummyNSView:m_cocoaNSView;
     NSView *superview = [nsview superview];
-    [nsview retain];
     [nsview removeFromSuperview];
     [superview addSubview:nsview];
 }
     [nsview removeFromSuperview];
     [superview addSubview:nsview];
 }
@@ -522,7 +518,7 @@ wxWindow *wxWindowBase::FindFocus()
 /* static */ wxWindow *wxWindowBase::GetCapture()
 {
     // TODO
 /* static */ wxWindow *wxWindowBase::GetCapture()
 {
     // TODO
-    return NULL;
+    return wxWindowCocoa::sm_capturedWindow;
 }
 
 wxWindow *wxGetActiveWindow()
 }
 
 wxWindow *wxGetActiveWindow()