]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/NSWindow.mm
Fixed separator handling for menus.
[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
f910a887 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;
8fc821cc
DE
42- (void)windowDidBecomeMain: (NSNotification *)notification;
43- (void)windowDidResignMain: (NSNotification *)notification;
eb3426e7 44- (BOOL)windowShouldClose: (id)sender;
9692f42b 45- (void)windowWillClose: (NSNotification *)notification;
78c67cb6 46@end //interface wxNSWindowDelegate
720e01c3 47
78c67cb6 48@implementation wxNSWindowDelegate : NSObject
720e01c3 49
78c67cb6 50- (void)windowDidBecomeKey: (NSNotification *)notification
720e01c3
DE
51{
52 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
2b030203 53 wxCHECK_RET(win,wxT("notificationDidBecomeKey received but no wxWindow exists"));
aa992c59 54 win->CocoaDelegate_windowDidBecomeKey();
720e01c3
DE
55}
56
78c67cb6 57- (void)windowDidResignKey: (NSNotification *)notification
720e01c3
DE
58{
59 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
2b030203 60 wxCHECK_RET(win,wxT("notificationDidResignKey received but no wxWindow exists"));
aa992c59 61 win->CocoaDelegate_windowDidResignKey();
720e01c3
DE
62}
63
8fc821cc
DE
64- (void)windowDidBecomeMain: (NSNotification *)notification
65{
66 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
2b030203 67 wxCHECK_RET(win,wxT("notificationDidBecomeMain received but no wxWindow exists"));
8fc821cc
DE
68 win->CocoaDelegate_windowDidBecomeMain();
69}
70
71- (void)windowDidResignMain: (NSNotification *)notification
72{
73 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
2b030203 74 wxCHECK_RET(win,wxT("notificationDidResignMain received but no wxWindow exists"));
8fc821cc
DE
75 win->CocoaDelegate_windowDidResignMain();
76}
77
eb3426e7
DE
78- (BOOL)windowShouldClose: (id)sender
79{
48580976 80 wxLogTrace(wxTRACE_COCOA,wxT("windowShouldClose"));
eb3426e7 81 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
aa992c59 82 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
eb3426e7 83 {
48580976 84 wxLogTrace(wxTRACE_COCOA,wxT("Window will not be closed"));
eb3426e7
DE
85 return NO;
86 }
48580976 87 wxLogTrace(wxTRACE_COCOA,wxT("Window will be closed"));
eb3426e7
DE
88 return YES;
89}
90
9692f42b
DE
91- (void)windowWillClose: (NSNotification *)notification
92{
93 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
2b030203 94 wxCHECK_RET(win,wxT("windowWillClose received but no wxWindow exists"));
9692f42b
DE
95 win->CocoaDelegate_windowWillClose();
96}
97
78c67cb6 98@end //implementation wxNSWindowDelegate
720e01c3
DE
99
100// ============================================================================
101// class wxCocoaNSWindow
102// ============================================================================
fb896a32 103
fb896a32
DE
104WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
105
78c67cb6 106struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
720e01c3 107
fb896a32
DE
108void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
109{
bac6f234
DE
110 if(cocoaNSWindow)
111 {
112 [cocoaNSWindow setReleasedWhenClosed: NO];
113 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
78c67cb6 114 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
720e01c3
DE
115 }
116}
117
118void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
119{
120 if(cocoaNSWindow)
121 {
78c67cb6 122 [cocoaNSWindow setDelegate: nil];
720e01c3 123 sm_cocoaHash.erase(cocoaNSWindow);
bac6f234 124 }
fb896a32
DE
125}
126
8ded703d 127wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win)
360be3c0
DE
128{
129 return NULL;
130}
131
fb896a32
DE
132// ============================================================================
133// @class wxPoserNSWindow
134// ============================================================================
135@interface wxPoserNSWindow : NSWindow
136{
137}
138
8fc821cc 139- (BOOL)canBecomeMainWindow;
fb896a32
DE
140@end // wxPoserNSwindow
141
142WX_IMPLEMENT_POSER(wxPoserNSWindow);
143@implementation wxPoserNSWindow : NSWindow
144
8fc821cc
DE
145- (BOOL)canBecomeMainWindow
146{
147 bool canBecome = false;
148 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
149 if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome))
150 canBecome = [super canBecomeMainWindow];
151 return canBecome;
152}
153
fb896a32
DE
154@end // implementation wxPoserNSWindow
155