[Clickdrag-cvs] ClickDrag ClickDrag.m,1.3,1.4
Status: Pre-Alpha
Brought to you by:
stevecheckoway
|
From: Steve C. <ste...@us...> - 2004-08-31 08:21:09
|
Update of /cvsroot/clickdrag/ClickDrag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4122 Modified Files: ClickDrag.m Log Message: Fix resizing bugs, only allow resizing to the menubar and to the the bottom of the visible screen. Index: ClickDrag.m =================================================================== RCS file: /cvsroot/clickdrag/ClickDrag/ClickDrag.m,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- ClickDrag.m 15 Jun 2004 13:05:07 -0000 1.3 +++ ClickDrag.m 31 Aug 2004 08:20:59 -0000 1.4 @@ -1,15 +1,25 @@ #import "ClickDrag.h" #import "ClickDragWindow.h" +#import <CoreFoundation/CFPreferences.h> @implementation ClickDrag + (void) load { - [ClickDragWindow poseAsClass:[NSWindow class]]; - gClickDrag = [[ClickDrag alloc] init]; +#if 0 + Boolean b; + CFStringRef name = (CFStringRef)[[NSProcessInfo processInfo] processName]; + + if (CFPreferencesGetAppBooleanValue(name, CFSTR("com.sc.clickdrag"), &b)) +#endif + { + [ClickDragWindow poseAsClass:[NSWindow class]]; + gClickDrag = [[ClickDrag alloc] init]; + } } - (id) init { + [super init]; mDragging = NO; mResizing = NO; return self; @@ -20,9 +30,9 @@ NSEventType type = [event type]; NSPoint location; NSRect rect; - NSSize size; - int deltaWidth; - int deltaHeight; + NSSize size, resizeInc; + int deltaX; + int deltaY; if (!window) return NO; @@ -138,41 +148,95 @@ if (!mResizing) return NO; location = [event locationInWindow]; - deltaWidth = location.x - mX; - deltaHeight = mY - location.y; - size = [window resizeIncrements]; - deltaWidth /= size.width; - deltaWidth *= size.width; - deltaHeight /= size.height; - deltaHeight *= size.height; - + deltaX = location.x - mX; + deltaY = location.y - mY; + resizeInc = [window resizeIncrements]; rect = [window frame]; - mX = location.x; - mY = location.y; + if (mFromBottom) { - rect.origin.y -= deltaHeight; - rect.size.height += deltaHeight; - mY += deltaHeight; + if (deltaY > 0) + { + size = [window minSize]; + if (rect.size.height - deltaY < size.height) + deltaY = rect.size.height - size.height; + } + else + { + NSRect screenRect = [[window screen] visibleFrame]; + + size = [window maxSize]; + if (rect.size.height - deltaY > size.height) + deltaY = rect.size.height - size.height; + if (rect.origin.y + deltaY < screenRect.origin.y) + deltaY = screenRect.origin.y - rect.origin.y; + if (deltaY > 0) + deltaY = 0; + } + deltaY = deltaY / resizeInc.height * resizeInc.height; + rect.origin.y += deltaY; + rect.size.height -= deltaY; } else if (mFromTop) - rect.size.height -= deltaHeight; + { + if (deltaY > 0) + { + NSRect screenRect = [[window screen] visibleFrame]; + int temp1 = rect.origin.y + rect.size.height; + int temp2 = screenRect.origin.y + screenRect.size.height; + + size = [window maxSize]; + if (rect.size.height + deltaY > size.height) + deltaY = size.height - rect.size.height; + if (temp1 + deltaY > temp2) + deltaY = temp2 - temp1; + } + else + { + size = [window minSize]; + if (rect.size.height + deltaY < size.height) + deltaY = size.height - rect.size.height; + } + deltaY = deltaY / resizeInc.height * resizeInc.height; + rect.size.height += deltaY; + mY += deltaY; + } if (mFromLeft) { - rect.origin.x += deltaWidth; - rect.size.width -= deltaWidth; - mX -= deltaWidth; + if (deltaX > 0) + { + size = [window minSize]; + if (rect.size.width - deltaX < size.width) + deltaX = rect.size.width - size.width; + } + else + { + size = [window maxSize]; + if (rect.size.width - deltaX > size.width) + deltaX = rect.size.width - size.width; + } + deltaX = deltaX / resizeInc.width * resizeInc.width; + rect.origin.x += deltaX; + rect.size.width -= deltaX; } else if (mFromRight) - rect.size.width += deltaWidth; - - size = [window minSize]; - rect.size.height = MAX(rect.size.height, size.height); - rect.size.width = MAX(rect.size.width, size.width); - - size = [window maxSize]; - rect.size.height = MIN(rect.size.height, size.height); - rect.size.width = MIN(rect.size.width, size.width); + { + if (deltaX > 0) + { + size = [window maxSize]; + if (rect.size.width + deltaX > size.width) + deltaX = size.width - rect.size.width; + } + else + { + size = [window minSize]; + if (rect.size.width + deltaX < size.width) + deltaX = size.width - rect.size.width; + } + deltaX = deltaX / resizeInc.width * resizeInc.width; + rect.size.width += deltaX; + mX += deltaX; + } [window setFrame:rect display:YES animate:NO]; break; @@ -183,7 +247,7 @@ } @end -ClickDrag *gClickDrag; +ClickDrag *gClickDrag = nil; /* * Copyright (c) 2004 Steve Checkoway |