[26305] users/rhwood/Pallet
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jun 19 03:10:39 PDT 2007
Revision: 26305
http://trac.macosforge.org/projects/macports/changeset/26305
Author: rhwood at macports.org
Date: 2007-06-19 03:10:38 -0700 (Tue, 19 Jun 2007)
Log Message:
-----------
Add classes for self expanding text field. As of now this field expands in the wrong direction and the window does not respond.
Added Paths:
-----------
users/rhwood/Pallet/ASNSViewAdditions.h
users/rhwood/Pallet/ASNSViewAdditions.m
users/rhwood/Pallet/ASNSWindowAdditions.h
users/rhwood/Pallet/ASNSWindowAdditions.m
users/rhwood/Pallet/ASSpringyPanel.h
users/rhwood/Pallet/ASSpringyPanel.m
users/rhwood/Pallet/ASSpringyTextField.h
users/rhwood/Pallet/ASSpringyTextField.m
Added: users/rhwood/Pallet/ASNSViewAdditions.h
===================================================================
--- users/rhwood/Pallet/ASNSViewAdditions.h (rev 0)
+++ users/rhwood/Pallet/ASNSViewAdditions.h 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,17 @@
+//
+// ASNSViewAdditions.h
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface NSView (ASNSViewAdditions)
+
+- (void)registerObserver:(id)anObserver forSizeChanges:(SEL)callback;
+- (NSSize)checkIntersections:(NSRect)aFrame;
+
+ at end
Added: users/rhwood/Pallet/ASNSViewAdditions.m
===================================================================
--- users/rhwood/Pallet/ASNSViewAdditions.m (rev 0)
+++ users/rhwood/Pallet/ASNSViewAdditions.m 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,50 @@
+//
+// ASNSViewAdditions.m
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import "ASNSViewAdditions.h"
+
+#define max(a,b) (((a)>(b))?(a):(b))
+
+ at implementation NSView (ASNSViewAdditions)
+
+- (void)registerObserver:(id)anObserver forSizeChanges:(SEL)callback {
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+ if ([self postsFrameChangedNotifications]) {
+ [nc addObserver:anObserver
+ selector:callback
+ name:NSViewFrameDidChangeNotification
+ object:self];
+ }
+ NSArray *children = [self subviews];
+ if ( children != nil) {
+ int childCount = [children count];
+ int i = 0;
+ for (i = 0; i < childCount; i++) {
+ NSView *child = (NSView *) [children objectAtIndex: i];
+ [child registerObserver: anObserver forSizeChanges: callback];
+ }
+ }
+}
+
+- (NSSize)checkIntersections:(NSRect)aFrame {
+ NSRect intersection = NSIntersectionRect([self frame], aFrame);
+ NSSize delta = NSMakeSize(NSWidth([self frame]) - NSWidth(intersection),
+ NSHeight([self frame]) - NSHeight(intersection));
+ NSArray *children = [self subviews];
+ if ( children != nil) {
+ int childCount = [children count];
+ int i=0;
+ for (i=0; i < childCount; i++) {
+ NSSize childDelta = [[children objectAtIndex: i] checkIntersections: aFrame];
+ delta = NSMakeSize(max(delta.width, childDelta.width), max(delta.height, childDelta.height));
+ }
+ }
+ return delta;
+}
+
+ at end
\ No newline at end of file
Added: users/rhwood/Pallet/ASNSWindowAdditions.h
===================================================================
--- users/rhwood/Pallet/ASNSWindowAdditions.h (rev 0)
+++ users/rhwood/Pallet/ASNSWindowAdditions.h 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,18 @@
+//
+// ASNSWindowAdditions.h
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface NSWindow (ASNSWindowAdditions)
+
+- (void)observeSizeChanges:(SEL)callback;
+- (void)setFrameSizeMaintaingOrigin:(NSSize)newFrameSize;
+- (void)contentResized:(NSNotification *)notification;
+
+ at end
Added: users/rhwood/Pallet/ASNSWindowAdditions.m
===================================================================
--- users/rhwood/Pallet/ASNSWindowAdditions.m (rev 0)
+++ users/rhwood/Pallet/ASNSWindowAdditions.m 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,54 @@
+//
+// ASNSWindowAdditions.m
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import "ASNSWindowAdditions.h"
+#import "ASNSViewAdditions.h"
+
+ at interface NSWindow (ASNSWindowAdditionsPrivateMethods)
+- (void) sizeToFit;
+ at end
+
+ at implementation NSWindow (ASNSWindowAdditions)
+
+- (void)observeSizeChanges:(SEL)callback {
+ NSView *view = [self contentView];
+ if (view == nil) {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ } else {
+ [view registerObserver:self forSizeChanges:callback];
+ }
+}
+
+- (void)contentResized:(NSNotification *)notification {
+ if ([self contentView] != nil) {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [self sizeToFit];
+ [self observeSizeChanges:@selector(contentResized:)];
+ }
+}
+
+- (void)sizeToFit {
+ NSSize size = [self minSize];
+ NSSize maxSize = [self maxSize];
+ NSSize delta = NSMakeSize(-1, -1);
+ while (size.width <= maxSize.width && size.height <= maxSize.height && !NSEqualSizes(delta, NSZeroSize)) {
+ [self setFrameSizeMaintaingOrigin:size];
+ delta = [[self contentView] checkIntersections:[[self contentView] bounds]];
+ size.width += delta.width;
+ size.height += delta.height;
+ }
+}
+
+- (void)setFrameSizeMaintaingOrigin:(NSSize)newFrameSize {
+ NSPoint origin = [self frame].origin;
+ float originalHeight = NSHeight([self frame]);
+ origin.y += (originalHeight - newFrameSize.height);
+ [self setFrame:NSMakeRect(origin.x, origin.y, newFrameSize.width, newFrameSize.height) display:YES animate:YES];
+}
+
+ at end
Added: users/rhwood/Pallet/ASSpringyPanel.h
===================================================================
--- users/rhwood/Pallet/ASSpringyPanel.h (rev 0)
+++ users/rhwood/Pallet/ASSpringyPanel.h 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,16 @@
+//
+// ASSpringyPanel.h
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface ASSpringyPanel : NSPanel {
+ at private
+}
+
+ at end
Added: users/rhwood/Pallet/ASSpringyPanel.m
===================================================================
--- users/rhwood/Pallet/ASSpringyPanel.m (rev 0)
+++ users/rhwood/Pallet/ASSpringyPanel.m 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,30 @@
+//
+// ASSpringyPanel.m
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import "ASSpringyPanel.h"
+#import "ASNSViewAdditions.h"
+#import "ASNSWindowAdditions.h"
+
+ at implementation ASSpringyPanel
+
+- (void)awakeFromNib {
+ [self contentResized:[NSNotification notificationWithName:
+ NSViewFrameDidChangeNotification object:[self contentView]]];
+}
+
+- (void)setContentView:(NSView *)aView {
+ [super setContentView:aView];
+ [self observeSizeChanges:@selector(contentResized:)];
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [super dealloc];
+}
+
+ at end
Added: users/rhwood/Pallet/ASSpringyTextField.h
===================================================================
--- users/rhwood/Pallet/ASSpringyTextField.h (rev 0)
+++ users/rhwood/Pallet/ASSpringyTextField.h 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,14 @@
+//
+// ASSpringyTextField.h
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface ASSpringyTextField : NSTextField
+
+ at end
Added: users/rhwood/Pallet/ASSpringyTextField.m
===================================================================
--- users/rhwood/Pallet/ASSpringyTextField.m (rev 0)
+++ users/rhwood/Pallet/ASSpringyTextField.m 2007-06-19 10:10:38 UTC (rev 26305)
@@ -0,0 +1,46 @@
+//
+// ASSpringyTextField.m
+// Pallet
+//
+// Created by Randall Hansen Wood on 19/6/2007.
+// Copyright 2007 __MyCompanyName__. All rights reserved.
+//
+
+#import "ASSpringyTextField.h"
+
+ at implementation ASSpringyTextField
+
+- (void)bind:(NSString *)binding toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options {
+ [super bind:binding toObject:observableController withKeyPath:keyPath options:options];
+}
+
+- (void)setStringValue:(NSString *)aString {
+ [super setStringValue:aString];
+ [self sizeToFit];
+}
+
+- (void)setObjectValue:(id <NSCopying>)object {
+ [super setObjectValue:object];
+ [self sizeToFit];
+}
+
+- (void)setFont:(NSFont *)aFont {
+ [super setFont:aFont];
+ [self sizeToFit];
+}
+
+- (void)sizeToFit {
+ float oldHeight = NSHeight([self bounds]);
+ [self setPostsFrameChangedNotifications: NO];
+ [super sizeToFit];
+ float heightDiff = oldHeight - NSHeight([self bounds]);
+ NSPoint origin = [self frame].origin;
+ [self setFrameOrigin: NSMakePoint(origin.x, origin.y + heightDiff)];
+ [[self superview] setNeedsDisplay: YES]; //needed to ensure we don't get garbage when the field shrinks
+
+ //this actually causes a notification to be fired
+ [self setPostsFrameChangedNotifications: YES];
+
+}
+
+ at end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070619/f04b9fdb/attachment.html
More information about the macports-changes
mailing list