-
Notifications
You must be signed in to change notification settings - Fork 3
/
TopBar.m
142 lines (121 loc) · 4.12 KB
/
TopBar.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
#import "TopBar.h"
#import "ClockView.h"
#import "UserView.h"
#import "GNUstepGUI/GSTheme.h"
@implementation MyDelegate : NSObject
- (void) dealloc
{
RELEASE (topBar);
[super dealloc];
}
- (NSColor *) backgroundColor
{
NSColor *color = [[GSTheme theme] menuItemBackgroundColor];
return color;
}
- (NSColor *) transparentColor
{
NSColor *color = [NSColor colorWithCalibratedRed: 0.992 green: 0.992 blue: 0.992 alpha: 0.0];
return color;
}
-(id) init
{
if ((self = [super init]) != nil)
{
}
return self;
}
-(void) createTopBar
{
const CGFloat menuBarHeight = [[GSTheme theme] menuBarHeight];
NSRect rect;
NSSize stringSize;
NSColor *color;
//NSSize logoSize;
//NSImage *logo=nil;
//NSPopUpButton *logoButton;
//NSMenu *buttonMenu;
//NSMenuItemCell * cell=nil;
NSButton *label;
NSFont *menuFont=[NSFont menuBarFontOfSize:0];
NSMutableDictionary *attributes ;
attributes = [NSMutableDictionary new];
[attributes setObject:menuFont
forKey:NSFontAttributeName];
screenFrame = [[NSScreen mainScreen] frame];
screenSize = screenFrame.size;
color = [self backgroundColor];
/*
// Creation of the popup menu
logo = [[NSImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Logo.tiff" ofType:nil] ];
logoSize = logo.size;
logoButton= [[NSPopUpButton alloc] initWithFrame:NSMakeRect(11,0,logoSize.width+10,menuBarHeight)];
[logoButton setBezelStyle: NSRegularSquareBezelStyle];
[logoButton setTitle: @""];
[logoButton setImage: logo];
[logoButton setPullsDown: YES];
[logoButton setBordered: NO];//FixMe : this doesn't work with my popup button.
buttonMenu = [logoButton menu];
NSMenuItem *menuItem = [logoButton itemAtIndex: 0];
[menuItem setImage: logo];
cell = [[NSMenuItemCell alloc] init];
[cell setMenuItem: menuItem];
[cell setImagePosition: NSImageLeft]; // FixMe : it seems that popup buttons can't use this to put the image at the left of the title.
[buttonMenu addItemWithTitle:_(@"Launch xterm")
action: @selector (launchXterm:)
keyEquivalent: @""];
[buttonMenu addItemWithTitle:_(@"Quit")
action: @selector (terminate:)
keyEquivalent: @"q "];
*/
// Creation of the label
NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString: @"GNUstep" ];
[titleString setAttributes:attributes range:NSMakeRange(0,[titleString length])];
stringSize=[titleString size];
label = [[NSButton alloc] initWithFrame:
NSMakeRect (screenSize.width/2-stringSize.width/2,menuBarHeight/2 - stringSize.height/2,stringSize.width,stringSize.height)];
[label setFont: menuFont];
[label setBordered: NO];
[label setTitle: @"GNUstep"];
//Creation of the UserView
UserView *userView = [[UserView alloc] initWithOrigin: screenSize.width - RIGHTPADDING
height: menuBarHeight];
NSMutableArray *users = [userView users];
NSLog(@"Users : %@", users);
// Creation of the clock
ClockView *clockView = [[ClockView alloc] initWithOrigin: screenSize.width - PADDING - RIGHTPADDING - [userView width]
height: menuBarHeight];
//Creation of the topBar
rect = NSMakeRect (0, screenSize.height-menuBarHeight, screenSize.width, menuBarHeight);
topBar = [[NSWindow alloc] initWithContentRect: rect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer:NO];
[topBar setTitle: @"TopBar"];
[topBar setBackgroundColor:color];
[topBar setAlphaValue: 1.0];
[topBar setLevel:NSTornOffMenuWindowLevel-1];
[topBar setCanHide:NO];
[topBar setHidesOnDeactivate:NO];
// Add subviews
// [[topBar contentView] addSubview: logoButton];
[[topBar contentView] addSubview: label];
[[topBar contentView] addSubview: [userView userButton]];
[[topBar contentView] addSubview: [clockView clockButton]];
//[logoButton release];
//[logo release];
[label release];
[titleString release];
[clockView release];
[userView release];
//[cell release];
}
- (void) applicationWillFinishLaunching:(NSNotification *)not
{
[self createTopBar];
}
- (void) applicationDidFinishLaunching:(NSNotification *)not
{
[topBar orderFront: self];
}
@end