]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/NSWindow.mm
wxCocoa: Added mbarman.(mm|h)
[wxWidgets.git] / src / cocoa / NSWindow.mm
CommitLineData
fb896a32
DE
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
fb45bb1f 26#include "wx/cocoa/ObjcPose.h"
fb896a32
DE
27#include "wx/cocoa/NSWindow.h"
28
29#import <Appkit/NSWindow.h>
720e01c3
DE
30#import <Foundation/NSNotification.h>
31#import <Foundation/NSString.h>
32
33// ============================================================================
78c67cb6 34// @class wxNSWindowDelegate
720e01c3 35// ============================================================================
78c67cb6 36@interface wxNSWindowDelegate : NSObject
720e01c3
DE
37{
38}
39
78c67cb6
DE
40- (void)windowDidBecomeKey: (NSNotification *)notification;
41- (void)windowDidResignKey: (NSNotification *)notification;
eb3426e7 42- (BOOL)windowShouldClose: (id)sender;
78c67cb6 43@end //interface wxNSWindowDelegate
720e01c3 44
78c67cb6 45@implementation wxNSWindowDelegate : NSObject
720e01c3 46
78c67cb6 47- (void)windowDidBecomeKey: (NSNotification *)notification
720e01c3
DE
48{
49 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
50 wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
aa992c59 51 win->CocoaDelegate_windowDidBecomeKey();
720e01c3
DE
52}
53
78c67cb6 54- (void)windowDidResignKey: (NSNotification *)notification
720e01c3
DE
55{
56 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
57 wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
aa992c59 58 win->CocoaDelegate_windowDidResignKey();
720e01c3
DE
59}
60
eb3426e7
DE
61- (BOOL)windowShouldClose: (id)sender
62{
63 wxLogDebug("windowShouldClose");
64 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
aa992c59 65 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
eb3426e7
DE
66 {
67 wxLogDebug("Window will not be closed");
68 return NO;
69 }
70 wxLogDebug("Window will be closed");
71 return YES;
72}
73
78c67cb6 74@end //implementation wxNSWindowDelegate
720e01c3
DE
75
76// ============================================================================
77// class wxCocoaNSWindow
78// ============================================================================
fb896a32 79
fb896a32
DE
80WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
81
78c67cb6 82struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
720e01c3 83
fb896a32
DE
84void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
85{
bac6f234
DE
86 if(cocoaNSWindow)
87 {
88 [cocoaNSWindow setReleasedWhenClosed: NO];
89 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
78c67cb6 90 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
720e01c3
DE
91 }
92}
93
94void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
95{
96 if(cocoaNSWindow)
97 {
78c67cb6 98 [cocoaNSWindow setDelegate: nil];
720e01c3 99 sm_cocoaHash.erase(cocoaNSWindow);
bac6f234 100 }
fb896a32
DE
101}
102
103// ============================================================================
104// @class wxPoserNSWindow
105// ============================================================================
106@interface wxPoserNSWindow : NSWindow
107{
108}
109
110- (void)close;
fb896a32
DE
111@end // wxPoserNSwindow
112
113WX_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
fb896a32
DE
125@end // implementation wxPoserNSWindow
126