]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/NSWindow.mm
return the index of the inserted/appended item
[wxWidgets.git] / src / cocoa / NSWindow.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/NSWindow.mm
3 // Purpose: wxCocoaNSWindow
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/03/16
7 // RCS-ID: $Id:
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21 #ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/menuitem.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/cocoa/ObjcPose.h"
27 #include "wx/cocoa/NSWindow.h"
28
29 #import <Appkit/NSWindow.h>
30 #import <Foundation/NSNotification.h>
31 #import <Foundation/NSString.h>
32
33 // ============================================================================
34 // @class wxNSWindowDelegate
35 // ============================================================================
36 @interface wxNSWindowDelegate : NSObject
37 {
38 }
39
40 - (void)windowDidBecomeKey: (NSNotification *)notification;
41 - (void)windowDidResignKey: (NSNotification *)notification;
42 - (BOOL)windowShouldClose: (id)sender;
43 @end //interface wxNSWindowDelegate
44
45 @implementation wxNSWindowDelegate : NSObject
46
47 - (void)windowDidBecomeKey: (NSNotification *)notification
48 {
49 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
50 wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
51 win->CocoaDelegate_windowDidBecomeKey();
52 }
53
54 - (void)windowDidResignKey: (NSNotification *)notification
55 {
56 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
57 wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
58 win->CocoaDelegate_windowDidResignKey();
59 }
60
61 - (BOOL)windowShouldClose: (id)sender
62 {
63 wxLogDebug("windowShouldClose");
64 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
65 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
66 {
67 wxLogDebug("Window will not be closed");
68 return NO;
69 }
70 wxLogDebug("Window will be closed");
71 return YES;
72 }
73
74 @end //implementation wxNSWindowDelegate
75
76 // ============================================================================
77 // class wxCocoaNSWindow
78 // ============================================================================
79
80 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
81
82 struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
83
84 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
85 {
86 if(cocoaNSWindow)
87 {
88 [cocoaNSWindow setReleasedWhenClosed: NO];
89 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
90 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
91 }
92 }
93
94 void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
95 {
96 if(cocoaNSWindow)
97 {
98 [cocoaNSWindow setDelegate: nil];
99 sm_cocoaHash.erase(cocoaNSWindow);
100 }
101 }
102
103 // ============================================================================
104 // @class wxPoserNSWindow
105 // ============================================================================
106 @interface wxPoserNSWindow : NSWindow
107 {
108 }
109
110 - (void)close;
111 @end // wxPoserNSwindow
112
113 WX_IMPLEMENT_POSER(wxPoserNSWindow);
114 @implementation wxPoserNSWindow : NSWindow
115
116 - (void)close
117 {
118 wxLogDebug("close");
119 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
120 if(tlw)
121 tlw->Cocoa_close();
122 [super close];
123 }
124
125 @end // implementation wxPoserNSWindow
126