1 /*****************************************************************************
2 * MainWindowTitle.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2011 Felix Paul Kühne
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
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.
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.
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 *****************************************************************************/
24 #import <vlc_common.h>
26 #import "MainWindowTitle.h"
27 #import "CoreInteraction.h"
29 /*****************************************************************************
30 * VLCMainWindowTitleView
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 *****************************************************************************/
37 @implementation VLCMainWindowTitleView
41 [self setImageScaling: NSScaleToFit];
42 [self setImageFrameStyle: NSImageFrameNone];
43 [self setImageAlignment: NSImageAlignCenter];
44 [self setImage: [NSImage imageNamed:@"bottom-background_dark"]];
45 [self setAutoresizesSubviews: YES];
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];
65 - (BOOL)mouseDownCanMoveWindow
70 - (IBAction)buttonAction:(id)sender
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];
81 msg_Err( VLCIntf, "unknown button action sender" );
84 - (void)setWindowTitle:(NSString *)title
86 [o_title_lbl setStringValue: title];
89 - (void)setFullscreenButtonHidden:(BOOL)b_value
91 [o_fullscreen_btn setHidden: b_value];
94 - (void)setWindowButtonOver:(BOOL)b_value
98 [o_red_btn setImage: [NSImage imageNamed:@"window-close-over"]];
99 [o_yellow_btn setImage: [NSImage imageNamed:@"window-minimize-over"]];
100 [o_green_btn setImage: [NSImage imageNamed:@"window-zoom-over"]];
104 [o_red_btn setImage: [NSImage imageNamed:@"window-close"]];
105 [o_yellow_btn setImage: [NSImage imageNamed:@"window-minimize"]];
106 [o_green_btn setImage: [NSImage imageNamed:@"window-zoom"]];
110 - (void)setWindowFullscreenButtonOver:(BOOL)b_value
113 [o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen-over"]];
115 [o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen"]];
120 /*****************************************************************************
121 * VLCWindowButtonCell
123 * since the title bar cannot fetch these mouse events (the more top-level
124 * NSButton is unable fetch them as well), we are using a subclass of the
125 * button cell to do so. It's set in the nib for the respective objects.
126 *****************************************************************************/
128 @implementation VLCWindowButtonCell
130 - (void)mouseEntered:(NSEvent *)theEvent
133 [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowFullscreenButtonOver: YES];
135 [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowButtonOver: YES];
138 - (void)mouseExited:(NSEvent *)theEvent
141 [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowFullscreenButtonOver: NO];
143 [(VLCMainWindowTitleView *)[[self controlView] superview] setWindowButtonOver: NO];
149 /*****************************************************************************
152 * For Leopard and Snow Leopard, we need to emulate the resize control on the
153 * bottom right of the window, since it is gone by using the borderless window
154 * mask. A proper fix would be Lion-only.
155 *****************************************************************************/
157 @implementation VLCResizeControl
159 - (void)mouseDragged:(NSEvent *)theEvent
161 NSRect windowFrame = [[self window] frame];
162 CGFloat deltaX, deltaY, oldOriginY;
163 deltaX = [theEvent deltaX];
164 deltaY = [theEvent deltaY];
165 oldOriginY = windowFrame.origin.y;
167 windowFrame.origin.y = (oldOriginY + windowFrame.size.height) - (windowFrame.size.height + deltaY);
168 windowFrame.size.width += deltaX;
169 windowFrame.size.height += deltaY;
171 NSSize winMinSize = [self window].minSize;
172 if (windowFrame.size.width < winMinSize.width)
173 windowFrame.size.width = winMinSize.width;
175 if (windowFrame.size.height < winMinSize.height)
177 windowFrame.size.height = winMinSize.height;
178 windowFrame.origin.y = oldOriginY;
181 [[self window] setFrame: windowFrame display: YES animate: NO];