source: trunk/Cocoa/Pester/Source/NJRSplitView.m@ 312

Last change on this file since 312 was 102, checked in by Nicholas Riley, 22 years ago

Pester 1.1b3

File size: 3.5 KB
Line 
1//
2// NJRSplitView.m
3// Pester
4//
5// Created by Nicholas Riley on Thu Feb 20 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRSplitView.h"
10
11
12@implementation NJRSplitView
13
14// inspiration (but very little code remaining) from <http://cocoa.mamasam.com/COCOADEV/2003/02/1/55911.php>
15// XXX need to generalize: assumes the split is vertical, and you want to collapse a previous view
16// XXX shouldn't set width to 0 as it can destroy layouts, but we have no other choice
17
18- (void)collapseSubview:(NSView *)subview;
19{
20 NSSize size = [subview frame].size;
21 NSAssert([self isVertical] && size.width > 1, @"unsupported configuration");
22 expandedWidth = size.width;
23 size.width = 0;
24 [subview setFrameSize: size];
25 [self setNeedsDisplay: YES];
26}
27
28// XXX this is a horrendous hack to work around NSSplitView bugs, and leaks memory
29- (void)expandSubview:(NSView *)subview;
30{
31 NSArray *subviews = [self subviews];
32 NSAssert([subviews count] == 2, @"unsupported configuration");
33 NSBox *leftView = [subviews objectAtIndex: 0];
34 NSView *rightView = [subviews objectAtIndex: 1];
35 NSRect leftFrame = [leftView frame], rightFrame = [rightView frame];
36 NSAssert([self isVertical] && subview == leftView, @"unsupported configuration");
37 if (expandedWidth == 0) {
38 expandedWidth = (rightFrame.size.width - [self dividerThickness]) / 2;
39 }
40 if ([[self delegate] respondsToSelector: @selector(splitView:constrainMaxCoordinate:ofSubviewAt:)]) {
41 expandedWidth = [[self delegate] splitView: self constrainMaxCoordinate: expandedWidth ofSubviewAt: 0];
42 }
43 // begin hack
44 NSBox *newLeftView = [[NSBox alloc] initWithFrame: leftFrame];
45 [newLeftView setBorderType: [leftView borderType]];
46 [newLeftView setTitlePosition: [leftView titlePosition]];
47 [newLeftView setBoxType: [leftView boxType]];
48 [newLeftView setAutoresizingMask: [leftView autoresizingMask]];
49 [newLeftView setContentViewMargins: [leftView contentViewMargins]];
50 NSView *leftContentView = [leftView contentView];
51 [leftContentView retain];
52 [leftContentView removeFromSuperviewWithoutNeedingDisplay];
53 [newLeftView setContentView: leftContentView];
54 [leftContentView release];
55 leftFrame.origin = NSZeroPoint;
56 rightFrame.origin.x += expandedWidth;
57 leftFrame.size.width = expandedWidth;
58 rightFrame.size.width -= expandedWidth;
59 [leftView removeFromSuperviewWithoutNeedingDisplay];
60 [rightView retain];
61 [rightView removeFromSuperviewWithoutNeedingDisplay];
62 [newLeftView setFrame: leftFrame];
63 [rightView setFrame: rightFrame];
64 [self addSubview: newLeftView];
65 [self addSubview: rightView];
66 [newLeftView release];
67 [rightView release];
68 // end hack
69 [self setNeedsDisplay: YES];
70}
71
72- (void)mouseDown:(NSEvent *)event;
73{
74 if ([event clickCount] == 2) {
75 NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil];
76 NSArray *subviews = [self subviews];
77 NSView *leftView = [subviews objectAtIndex: 0];
78 if (NSPointInRect(location, [leftView frame]) ||
79 NSPointInRect(location, [[subviews objectAtIndex: 1] frame])) return;
80 if ([self isSubviewCollapsed: leftView]) {
81 [self expandSubview: leftView];
82 } else {
83 [self collapseSubview: leftView];
84 }
85 }
86 [super mouseDown: event];
87}
88
89- (BOOL)isSubviewCollapsed:(NSView *)subview;
90{
91 NSRect frame = [subview frame];
92 if (frame.origin.x == 1e6) return YES;
93 if (frame.size.width <= 1) return YES;
94 return NO;
95}
96
97@end
Note: See TracBrowser for help on using the repository browser.