root/trunk/Views/JVSplitView.m

Revision 3418, 2.4 kB (checked in by timothy, 2 years ago)

Turing on more warnings and fixing more of them.

Line 
1 #import "JVSplitView.h"
2 #import "NSImageAdditions.h"
3
4 @implementation JVSplitView
5 - (NSString *) stringWithSavedPosition {
6         NSMutableString *result = [NSMutableString string];
7         NSEnumerator *subviews = [[self subviews] objectEnumerator];
8         NSView *subview = nil;
9
10         while( ( subview = [subviews nextObject] ) ) {
11                 if( [result length] ) [result appendString:@";"];
12                 [result appendString:NSStringFromRect( [subview frame] )];
13         }
14
15         return result;
16 }
17
18 - (void) setPositionFromString:(NSString *) string {
19         if( ! [string length] ) return;
20
21         NSEnumerator *subviews = [[self subviews] objectEnumerator];
22         NSEnumerator *frames = [[string componentsSeparatedByString:@";"] objectEnumerator];
23         NSView *subview = nil;
24         NSString *frame = nil;
25
26         while( ( subview = [subviews nextObject] ) && ( frame = [frames nextObject] ) ) {
27                 NSRect rect = NSRectFromString( frame );
28                 if( [self isVertical] ) [subview setFrame:NSMakeRect( NSMinX( rect ), NSMinY( [subview frame] ), NSWidth( rect ), NSHeight( [subview frame] ) )];
29                 else [subview setFrame:NSMakeRect( NSMinX( [subview frame] ), NSMinY( rect ), NSWidth( [subview frame] ), NSHeight( rect ) )];
30         }
31
32         [self adjustSubviews];
33 }
34
35 - (void) savePositionUsingName:(NSString *) name {
36         NSParameterAssert( name != nil );
37         NSParameterAssert( [name length] > 0 );
38
39         [[NSUserDefaults standardUserDefaults] setObject:[self stringWithSavedPosition] forKey:name];
40 }
41
42 - (BOOL) setPositionUsingName:(NSString *) name {
43         NSParameterAssert( name != nil );
44         NSParameterAssert( [name length] > 0 );
45
46         NSString *sizes = [[NSUserDefaults standardUserDefaults] objectForKey:name];
47         if( [sizes length] ) {
48                 [self setPositionFromString:sizes];
49                 return YES;
50         }
51
52         return NO;
53 }
54
55 #pragma mark -
56
57 - (void) setMainSubviewIndex:(long) index {
58         _mainSubviewIndex = index;
59 }
60
61 - (BOOL) mainSubviewIndex {
62         return _mainSubviewIndex;
63 }
64
65 #pragma mark -
66
67 - (void) resetCursorRects {
68         if( ! [self isPaneSplitter] )
69                 [super resetCursorRects];
70 }
71
72 - (float) dividerThickness {
73         if( ! [self isVertical] ) return 10.;
74         return [super dividerThickness];
75 }
76
77 - (void) drawDividerInRect:(NSRect) rect {
78         if( ! [self isVertical] ) {
79                 rect.origin.y += 10.;
80                 [[NSImage imageNamed:@"splitviewDividerBackground"] tileInRect:rect];
81                 if( ! [self isPaneSplitter] )
82                         [[NSImage imageNamed:@"splitviewDimple"] compositeToPoint:NSMakePoint( ( NSWidth( rect ) / 2. ) - 3., rect.origin.y ) operation:NSCompositeCopy];
83         } else [super drawDividerInRect:rect];
84 }
85 @end
Note: See TracBrowser for help on using the browser.