forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolbarPanel.m
executable file
·174 lines (137 loc) · 4.74 KB
/
ToolbarPanel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import "ToolbarPanel.h"
#import "ToolBarNSWindow.h"
#import "ViewerController.h"
#import "AppController.h"
#import "NSWindow+N2.h"
#import "N2Debug.h"
#import "Notifications.h"
extern BOOL USETOOLBARPANEL;
//static int MacOSVersion109orHigher = -1;
static int fixedHeight = 92;
@implementation ToolbarPanelController
@synthesize viewer;
- (long) fixedHeight
{
return fixedHeight;
}
+ (long) hiddenHeight {
return 15;
}
- (long) exposedHeight {
return fixedHeight - [ToolbarPanelController hiddenHeight];
}
+ (long) exposedHeight {
return fixedHeight - [ToolbarPanelController hiddenHeight];
}
+ (void) checkForValidToolbar
{
// Check that a toolbar is visible for all screens
for( NSScreen *s in [NSScreen screens])
{
ViewerController *v = [ViewerController frontMostDisplayed2DViewerForScreen: s];
if( v) {
if( [v.toolbarPanel.window.toolbar customizationPaletteIsRunning] == NO)
[v.toolbarPanel.window orderBack: self];
}
}
}
-(void)applicationDidChangeScreenParameters:(NSNotification*)aNotification
{
NSRect screenRect = [viewer.window.screen visibleFrame];
NSRect dstframe;
dstframe.size.height = [self fixedHeight];
dstframe.size.width = screenRect.size.width;
dstframe.origin.x = screenRect.origin.x;
dstframe.origin.y = screenRect.origin.y + screenRect.size.height - dstframe.size.height + [ToolbarPanelController hiddenHeight];
if( NSEqualRects( dstframe, self.window.frame) == NO)
[[self window] setFrame:dstframe display:YES];
}
- (id)initForViewer:(ViewerController *)v withToolbar:(NSToolbar *)t
{
if (self = [super initWithWindowNibName:@"ToolbarPanel"])
{
toolbar = [t retain];
viewer = [v retain];
[[self window] setAnimationBehavior: NSWindowAnimationBehaviorNone];
[[self window] setToolbar: toolbar];
[[self window] setLevel: NSNormalWindowLevel];
[[self window] makeMainWindow];
[toolbar setShowsBaselineSeparator: NO];
[toolbar setVisible: YES];
[self applicationDidChangeScreenParameters: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeScreenParameters:) name:NSApplicationDidChangeScreenParametersNotification object:NSApp];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewerWillClose:) name: OsirixCloseViewerNotification object: nil];
if( [AppController hasMacOSXSnowLeopard])
[[self window] setCollectionBehavior: 1 << 6]; //NSWindowCollectionBehaviorIgnoresCycle
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:0];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:0];
[self.window safelySetMovable:NO];
[self.window setShowsToolbarButton:NO];
}
return self;
}
- (void) close
{
[self.window orderOut: self];
[super close];
self.window.toolbar = nil;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[viewer release];
[toolbar release];
[super dealloc];
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
if( [aNotification object] == [self window])
{
if( [[viewer window] isVisible])
{
if( [self.window.toolbar customizationPaletteIsRunning] == NO)
{
[[viewer window] makeKeyAndOrderFront: self];
[self.window orderBack: self];
}
}
else
[self.window orderOut: self];
}
}
- (void)windowDidBecomeMain:(NSNotification *)aNotification
{
if( [aNotification object] == [self window])
{
if( [[viewer window] isVisible])
{
if( [self.window.toolbar customizationPaletteIsRunning] == NO)
{
[[viewer window] makeKeyAndOrderFront: self];
[self.window orderBack: self];
}
}
else
[self.window orderOut: self];
}
}
- (NSToolbar*) toolbar
{
return toolbar;
}
- (void) viewerWillClose: (NSNotification*) n
{
if( [n object] == viewer)
[self.window orderOut: self];
}
@end