]> git.sesse.net Git - vlc/blob - modules/gui/macosx/MainWindowTitle.m
macosx: minor appearance fixes
[vlc] / modules / gui / macosx / MainWindowTitle.m
1 /*****************************************************************************
2  * MainWindowTitle.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import <vlc_common.h>
25 #import "intf.h"
26 #import "MainWindowTitle.h"
27 #import "CoreInteraction.h"
28
29 /*****************************************************************************
30  * VLCMainWindowTitleView
31  *
32  * this is our title bar, which can do anything a title should do
33  * it relies on the VLCWindowButtonCell to display the correct traffic light
34  * states, since we can't capture the mouse-moved events here correctly
35  *****************************************************************************/
36
37 @implementation VLCMainWindowTitleView
38
39 - (void)awakeFromNib
40 {
41     [self setImageScaling: NSScaleToFit];
42     [self setImageFrameStyle: NSImageFrameNone];
43     [self setImageAlignment: NSImageAlignCenter];
44     [self setImage: [NSImage imageNamed:@"bottom-background_dark"]];
45     [self setAutoresizesSubviews: YES];
46
47     [o_red_btn setImage: [NSImage imageNamed:@"window-close"]];
48     [o_red_btn setAlternateImage: [NSImage imageNamed:@"window-close-on"]];
49     [[o_red_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
50     [[o_red_btn cell] setTag: 0];
51     [o_yellow_btn setImage: [NSImage imageNamed:@"window-minimize"]];
52     [o_yellow_btn setAlternateImage: [NSImage imageNamed:@"window-minimize-on"]];
53     [[o_yellow_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
54     [[o_yellow_btn cell] setTag: 1];
55     [o_green_btn setImage: [NSImage imageNamed:@"window-zoom"]];
56     [o_green_btn setAlternateImage: [NSImage imageNamed:@"window-zoom-on"]];
57     [[o_green_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
58     [[o_green_btn cell] setTag: 2];
59     [o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen"]];
60     [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"window-fullscreen-on"]];
61     [[o_fullscreen_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
62     [[o_fullscreen_btn cell] setTag: 3];
63 }
64
65 - (BOOL)mouseDownCanMoveWindow
66 {
67     return YES;
68 }
69
70 - (IBAction)buttonAction:(id)sender
71 {
72     if (sender == o_red_btn)
73         [[self window] orderOut: sender];
74     else if (sender == o_yellow_btn)
75         [[self window] miniaturize: sender];
76     else if (sender == o_green_btn)
77         [[self window] performZoom: sender];
78     else if (sender == o_fullscreen_btn)
79         [[VLCCoreInteraction sharedInstance] toggleFullscreen];
80     else
81         msg_Err( VLCIntf, "unknown button action sender" );
82
83     [self setWindowButtonOver: NO];
84     [self setWindowFullscreenButtonOver: NO];
85 }
86
87 - (void)setWindowTitle:(NSString *)title
88 {
89     [o_title_lbl setStringValue: title];
90 }
91
92 - (void)setFullscreenButtonHidden:(BOOL)b_value
93 {
94     [o_fullscreen_btn setHidden: b_value];
95 }
96
97 - (void)setWindowButtonOver:(BOOL)b_value
98 {
99     if( b_value )
100     {
101         [o_red_btn setImage: [NSImage imageNamed:@"window-close-over"]];
102         [o_yellow_btn setImage: [NSImage imageNamed:@"window-minimize-over"]];
103         [o_green_btn setImage: [NSImage imageNamed:@"window-zoom-over"]];
104     }
105     else
106     {
107         [o_red_btn setImage: [NSImage imageNamed:@"window-close"]];
108         [o_yellow_btn setImage: [NSImage imageNamed:@"window-minimize"]];
109         [o_green_btn setImage: [NSImage imageNamed:@"window-zoom"]];
110     }
111 }
112
113 - (void)setWindowFullscreenButtonOver:(BOOL)b_value
114 {
115     if (b_value)
116         [o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen-over"]];
117     else
118         [o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen"]];
119 }
120
121 @end
122
123 /*****************************************************************************
124  * VLCWindowButtonCell
125  *
126  * since the title bar cannot fetch these mouse events (the more top-level
127  * NSButton is unable fetch them as well), we are using a subclass of the
128  * button cell to do so. It's set in the nib for the respective objects.
129  *****************************************************************************/
130
131 @implementation VLCWindowButtonCell
132
133 - (void)mouseEntered:(NSEvent *)theEvent
134 {
135     if ([self tag] == 3)
136         [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowFullscreenButtonOver: YES];
137     else
138         [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowButtonOver: YES];
139 }
140
141 - (void)mouseExited:(NSEvent *)theEvent
142 {
143     if ([self tag] == 3)
144         [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowFullscreenButtonOver: NO];
145     else
146         [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowButtonOver: NO];
147 }
148
149 @end
150
151
152 /*****************************************************************************
153  * VLCResizeControl
154  *
155  * For Leopard and Snow Leopard, we need to emulate the resize control on the
156  * bottom right of the window, since it is gone by using the borderless window
157  * mask. A proper fix would be Lion-only.
158  *****************************************************************************/
159
160 @implementation VLCResizeControl
161
162 - (void)mouseDragged:(NSEvent *)theEvent
163 {
164     NSRect windowFrame = [[self window] frame];
165     CGFloat deltaX, deltaY, oldOriginY;
166     deltaX = [theEvent deltaX];
167     deltaY = [theEvent deltaY];
168     oldOriginY = windowFrame.origin.y;
169
170     windowFrame.origin.y = (oldOriginY + windowFrame.size.height) - (windowFrame.size.height + deltaY);
171     windowFrame.size.width += deltaX;
172     windowFrame.size.height += deltaY;
173
174     NSSize winMinSize = [self window].minSize;
175     if (windowFrame.size.width < winMinSize.width)
176         windowFrame.size.width = winMinSize.width;
177
178     if (windowFrame.size.height < winMinSize.height)
179     {
180         windowFrame.size.height = winMinSize.height;
181         windowFrame.origin.y = oldOriginY;
182     }
183
184     [[self window] setFrame: windowFrame display: YES animate: NO];
185 }
186
187 @end