[vlc-commits] macosx: implement proper zooming for Leopard and Snow Leopard based upon code from the GNUstep library (as indicated)
Felix Paul Kühne
git at videolan.org
Wed Dec 28 01:39:50 CET 2011
vlc/vlc-1.2 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Dec 24 01:55:11 2011 +0100| [14311e5932386bbe4f2c4b6e40a8fc81fd5f4139] | committer: Jean-Baptiste Kempf
macosx: implement proper zooming for Leopard and Snow Leopard based upon code from the GNUstep library (as indicated)
(cherry picked from commit c43bd662808f11092fc87419359910003dc407d6)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=14311e5932386bbe4f2c4b6e40a8fc81fd5f4139
---
modules/gui/macosx/MainWindow.h | 4 +
modules/gui/macosx/MainWindow.m | 117 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 119 insertions(+), 2 deletions(-)
diff --git a/modules/gui/macosx/MainWindow.h b/modules/gui/macosx/MainWindow.h
index 8ce3906..f0a67c6 100644
--- a/modules/gui/macosx/MainWindow.h
+++ b/modules/gui/macosx/MainWindow.h
@@ -30,6 +30,7 @@
#import <vlc_input.h>
#import "misc.h"
#import "fspanel.h"
+#import "MainWindowTitle.h"
@interface VLCMainWindow : NSWindow <PXSourceListDataSource, PXSourceListDelegate, NSWindowDelegate, NSAnimationDelegate> {
IBOutlet id o_play_btn;
@@ -113,6 +114,7 @@
NSSize nativeVideoSize;
NSInteger i_originalLevel;
+ NSString *o_previouslySavedFrame;
}
+ (VLCMainWindow *)sharedInstance;
@@ -130,6 +132,8 @@
- (IBAction)dropzoneButtonAction:(id)sender;
- (void)setTitle:(NSString *)title;
+- (void) customZoom: (id)sender;
+
- (void)showDropZone;
- (void)hideDropZone;
- (void)updateTimeSlider;
diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 68d3635..c8bdfee 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -107,6 +107,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)dealloc
{
config_PutInt( VLCIntf->p_libvlc, "volume", i_lastShownVolume );
+ [self saveFrameUsingName: [self frameAutosaveName]];
[o_sidebaritems release];
[super dealloc];
}
@@ -666,13 +667,125 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)setTitle:(NSString *)title
{
- [o_titlebar_view setWindowTitle: title];
+ if (b_dark_interface)
+ [o_titlebar_view setWindowTitle: title];
[super setTitle: title];
}
- (void)performZoom:(id)sender
{
- [super zoom: sender];
+ if (b_dark_interface)
+ [self customZoom: sender];
+ else
+ [super performZoom: sender];
+}
+
+- (void)zoom:(id)sender
+{
+ if (b_dark_interface)
+ [self customZoom: sender];
+ else
+ [super zoom: sender];
+}
+
+/**
+ * Given a proposed frame rectangle, return a modified version
+ * which will fit inside the screen.
+ *
+ * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
+ * Authors: Scott Christley <scottc at net-community.com>, Venkat Ajjanagadde <venkat at ocbi.com>,
+ * Felipe A. Rodriguez <far at ix.netcom.com>, Richard Frith-Macdonald <richard at brainstorm.co.uk>
+ * Copyright (C) 1996 Free Software Foundation, Inc.
+ */
+- (NSRect) constrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
+{
+ NSRect screenRect = [screen visibleFrame];
+ float difference;
+
+ /* Move top edge of the window inside the screen */
+ difference = NSMaxY (frameRect) - NSMaxY (screenRect);
+ if (difference > 0)
+ {
+ frameRect.origin.y -= difference;
+ }
+
+ /* If the window is resizable, resize it (if needed) so that the
+ bottom edge is on the screen or can be on the screen when the user moves
+ the window */
+ difference = NSMaxY (screenRect) - NSMaxY (frameRect);
+ if (_styleMask & NSResizableWindowMask)
+ {
+ float difference2;
+
+ difference2 = screenRect.origin.y - frameRect.origin.y;
+ difference2 -= difference;
+ // Take in account the space between the top of window and the top of the
+ // screen which can be used to move the bottom of the window on the screen
+ if (difference2 > 0)
+ {
+ frameRect.size.height -= difference2;
+ frameRect.origin.y += difference2;
+ }
+
+ /* Ensure that resizing doesn't makewindow smaller than minimum */
+ difference2 = [self minSize].height - frameRect.size.height;
+ if (difference2 > 0)
+ {
+ frameRect.size.height += difference2;
+ frameRect.origin.y -= difference2;
+ }
+ }
+
+ return frameRect;
+}
+
+#define DIST 3
+
+/**
+ Zooms the receiver. This method calls the delegate method
+ windowShouldZoom:toFrame: to determine if the window should
+ be allowed to zoom to full screen.
+ *
+ * This method is based upon NSWindow.m, part of the GNUstep GUI Library, licensed under LGPLv2+.
+ * Authors: Scott Christley <scottc at net-community.com>, Venkat Ajjanagadde <venkat at ocbi.com>,
+ * Felipe A. Rodriguez <far at ix.netcom.com>, Richard Frith-Macdonald <richard at brainstorm.co.uk>
+ * Copyright (C) 1996 Free Software Foundation, Inc.
+ */
+- (void) customZoom: (id)sender
+{
+ NSRect maxRect = [[self screen] visibleFrame];
+ NSRect currentFrame = [self frame];
+
+ if ([[self delegate] respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)])
+ {
+ maxRect = [[self delegate] windowWillUseStandardFrame: self defaultFrame: maxRect];
+ }
+
+ maxRect = [self constrainFrameRect: maxRect toScreen: [self screen]];
+
+ // Compare the new frame with the current one
+ if ((abs(NSMaxX(maxRect) - NSMaxX(currentFrame)) < DIST)
+ && (abs(NSMaxY(maxRect) - NSMaxY(currentFrame)) < DIST)
+ && (abs(NSMinX(maxRect) - NSMinX(currentFrame)) < DIST)
+ && (abs(NSMinY(maxRect) - NSMinY(currentFrame)) < DIST))
+ {
+ // Already in zoomed mode, reset user frame, if stored
+ if ([self frameAutosaveName] != nil)
+ {
+ [self setFrameFromString: o_previouslySavedFrame];
+ [self saveFrameUsingName: [self frameAutosaveName]];
+ }
+ return;
+ }
+
+ if ([self frameAutosaveName] != nil)
+ {
+ [self saveFrameUsingName: [self frameAutosaveName]];
+ [o_previouslySavedFrame release];
+ o_previouslySavedFrame = [[self stringWithSavedFrame] retain];
+ }
+
+ [self setFrame: maxRect display: YES];
}
#pragma mark -
More information about the vlc-commits
mailing list