mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 05:31:07 +00:00
Implement manual resize and move.
2007-10-31 Richard Hult <richard@imendio.com> * gdk/quartz/GdkQuartzWindow.c: * gdk/quartz/GdkQuartzWindow.h: * gdk/quartz/gdkwindow-quartz.c: (gdk_window_begin_resize_drag), (gdk_window_begin_move_drag): Implement manual resize and move. svn path=/trunk/; revision=18955
This commit is contained in:
parent
75aabd416d
commit
568228dec3
@ -1,3 +1,10 @@
|
|||||||
|
2007-10-31 Richard Hult <richard@imendio.com>
|
||||||
|
|
||||||
|
* gdk/quartz/GdkQuartzWindow.c:
|
||||||
|
* gdk/quartz/GdkQuartzWindow.h:
|
||||||
|
* gdk/quartz/gdkwindow-quartz.c: (gdk_window_begin_resize_drag),
|
||||||
|
(gdk_window_begin_move_drag): Implement manual resize and move.
|
||||||
|
|
||||||
2007-10-31 Richard Hult <richard@imendio.com>
|
2007-10-31 Richard Hult <richard@imendio.com>
|
||||||
|
|
||||||
* gdk/quartz/gdkwindow-quartz.c:
|
* gdk/quartz/gdkwindow-quartz.c:
|
||||||
|
@ -113,6 +113,13 @@
|
|||||||
case NSLeftMouseUp:
|
case NSLeftMouseUp:
|
||||||
leftDown = NO;
|
leftDown = NO;
|
||||||
inMove = NO;
|
inMove = NO;
|
||||||
|
inManualMove = NO;
|
||||||
|
inManualResize = NO;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NSLeftMouseDragged:
|
||||||
|
if ([self trackManualMove] || [self trackManualResize])
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -256,6 +263,98 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)trackManualMove
|
||||||
|
{
|
||||||
|
NSPoint currentLocation;
|
||||||
|
NSPoint newOrigin;
|
||||||
|
NSRect screenFrame = [[NSScreen mainScreen] visibleFrame];
|
||||||
|
NSRect windowFrame = [self frame];
|
||||||
|
|
||||||
|
if (!inManualMove)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
|
||||||
|
newOrigin.x = currentLocation.x - initialMoveLocation.x;
|
||||||
|
newOrigin.y = currentLocation.y - initialMoveLocation.y;
|
||||||
|
|
||||||
|
/* Clamp vertical position to below the menu bar. */
|
||||||
|
if (newOrigin.y + windowFrame.size.height > screenFrame.origin.y + screenFrame.size.height)
|
||||||
|
newOrigin.y = screenFrame.origin.y + screenFrame.size.height - windowFrame.size.height;
|
||||||
|
|
||||||
|
[self setFrameOrigin:newOrigin];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)beginManualMove
|
||||||
|
{
|
||||||
|
NSRect frame = [self frame];
|
||||||
|
|
||||||
|
if (inMove || inManualMove || inManualResize)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inManualMove = YES;
|
||||||
|
|
||||||
|
initialMoveLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
|
||||||
|
initialMoveLocation.x -= frame.origin.x;
|
||||||
|
initialMoveLocation.y -= frame.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)trackManualResize
|
||||||
|
{
|
||||||
|
NSPoint currentLocation;
|
||||||
|
NSRect newFrame;
|
||||||
|
float dx, dy;
|
||||||
|
NSSize min_size;
|
||||||
|
|
||||||
|
if (!inManualResize)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
|
||||||
|
currentLocation.x -= initialResizeFrame.origin.x;
|
||||||
|
currentLocation.y -= initialResizeFrame.origin.y;
|
||||||
|
|
||||||
|
dx = currentLocation.x - initialResizeLocation.x;
|
||||||
|
dy = -(currentLocation.y - initialResizeLocation.y);
|
||||||
|
|
||||||
|
newFrame = initialResizeFrame;
|
||||||
|
newFrame.size.width = initialResizeFrame.size.width + dx;
|
||||||
|
newFrame.size.height = initialResizeFrame.size.height + dy;
|
||||||
|
|
||||||
|
min_size = [self contentMinSize];
|
||||||
|
if (newFrame.size.width < min_size.width)
|
||||||
|
newFrame.size.width = min_size.width;
|
||||||
|
if (newFrame.size.height < min_size.height)
|
||||||
|
newFrame.size.height = min_size.height;
|
||||||
|
|
||||||
|
/* We could also apply aspect ratio:
|
||||||
|
newFrame.size.height = newFrame.size.width / [self aspectRatio].width * [self aspectRatio].height;
|
||||||
|
*/
|
||||||
|
|
||||||
|
dy = newFrame.size.height - initialResizeFrame.size.height;
|
||||||
|
|
||||||
|
newFrame.origin.x = initialResizeFrame.origin.x;
|
||||||
|
newFrame.origin.y = initialResizeFrame.origin.y - dy;
|
||||||
|
|
||||||
|
[self setFrame:newFrame display:YES];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)beginManualResize
|
||||||
|
{
|
||||||
|
if (inMove || inManualMove || inManualResize)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inManualResize = YES;
|
||||||
|
|
||||||
|
initialResizeFrame = [self frame];
|
||||||
|
initialResizeLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
|
||||||
|
initialResizeLocation.x -= initialResizeFrame.origin.x;
|
||||||
|
initialResizeLocation.y -= initialResizeFrame.origin.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GdkDragContext *current_context = NULL;
|
static GdkDragContext *current_context = NULL;
|
||||||
|
|
||||||
static GdkDragAction
|
static GdkDragAction
|
||||||
|
@ -24,9 +24,20 @@
|
|||||||
@interface GdkQuartzWindow : NSWindow {
|
@interface GdkQuartzWindow : NSWindow {
|
||||||
BOOL leftDown;
|
BOOL leftDown;
|
||||||
BOOL inMove;
|
BOOL inMove;
|
||||||
|
|
||||||
|
/* Manually triggered move/resize (not by the window manager) */
|
||||||
|
BOOL inManualMove;
|
||||||
|
BOOL inManualResize;
|
||||||
|
NSPoint initialMoveLocation;
|
||||||
|
NSPoint initialResizeLocation;
|
||||||
|
NSRect initialResizeFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)isInMove;
|
-(BOOL)isInMove;
|
||||||
|
-(void)beginManualMove;
|
||||||
|
-(BOOL)trackManualMove;
|
||||||
|
-(void)beginManualResize;
|
||||||
|
-(BOOL)trackManualResize;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -2356,9 +2356,30 @@ gdk_window_begin_resize_drag (GdkWindow *window,
|
|||||||
gint root_y,
|
gint root_y,
|
||||||
guint32 timestamp)
|
guint32 timestamp)
|
||||||
{
|
{
|
||||||
|
GdkWindowObject *private;
|
||||||
|
GdkWindowImplQuartz *impl;
|
||||||
|
|
||||||
g_return_if_fail (GDK_IS_WINDOW (window));
|
g_return_if_fail (GDK_IS_WINDOW (window));
|
||||||
|
|
||||||
/* FIXME: Implement */
|
if (edge != GDK_WINDOW_EDGE_SOUTH_EAST)
|
||||||
|
{
|
||||||
|
g_warning ("Resizing is only implemented for GDK_WINDOW_EDGE_SOUTH_EAST on Mac OS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GDK_WINDOW_DESTROYED (window))
|
||||||
|
return;
|
||||||
|
|
||||||
|
private = GDK_WINDOW_OBJECT (window);
|
||||||
|
impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
|
||||||
|
|
||||||
|
if (!impl->toplevel)
|
||||||
|
{
|
||||||
|
g_warning ("Can't call gdk_window_begin_resize_drag on non-toplevel window");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[(GdkQuartzWindow *)impl->toplevel beginManualResize];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -2368,9 +2389,24 @@ gdk_window_begin_move_drag (GdkWindow *window,
|
|||||||
gint root_y,
|
gint root_y,
|
||||||
guint32 timestamp)
|
guint32 timestamp)
|
||||||
{
|
{
|
||||||
|
GdkWindowObject *private;
|
||||||
|
GdkWindowImplQuartz *impl;
|
||||||
|
|
||||||
g_return_if_fail (GDK_IS_WINDOW (window));
|
g_return_if_fail (GDK_IS_WINDOW (window));
|
||||||
|
|
||||||
/* FIXME: Implement */
|
if (GDK_WINDOW_DESTROYED (window))
|
||||||
|
return;
|
||||||
|
|
||||||
|
private = GDK_WINDOW_OBJECT (window);
|
||||||
|
impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
|
||||||
|
|
||||||
|
if (!impl->toplevel)
|
||||||
|
{
|
||||||
|
g_warning ("Can't call gdk_window_begin_move_drag on non-toplevel window");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[(GdkQuartzWindow *)impl->toplevel beginManualMove];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user