24- (id)initWithFrame:(NSRect)frame {
25 self = [
super initWithFrame:frame];
30 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutSubviews) name:NSViewFrameDidChangeNotification object:self];
36 [[NSNotificationCenter defaultCenter] removeObserver:self];
37 [subviewsInOrder release];
47#define borderDistance 8.0
48#define cellDistance 4.0
50-(void) layoutSubviews {
51 NSRect bounds = [
self bounds];
53 NSUInteger numOfSubViews = [subviewsInOrder count];
55 if (numOfSubViews > 0) {
58 CGFloat sizesHeight[numOfSubViews];
59 CGFloat sizesWidth[numOfSubViews];
60 CGFloat exclusiveHeight = 0.0;
61 NSUInteger exclusiveChilds = 0;
64 for (i=0; i<numOfSubViews; i++) {
65 NSView* subview = [subviewsInOrder objectAtIndex:i];
66 if ([subview conformsToProtocol:
@protocol(CocoaGwenGUIProtocol)]) {
67 if ([(<CocoaGwenGUIProtocol>)subview
fillX]) sizesWidth[i] = -1.0;
69 CGFloat neededWidth = [(<CocoaGwenGUIProtocol>)subview minSize].width;
70 sizesWidth[i] = neededWidth;
72 if ([(<CocoaGwenGUIProtocol>)subview
fillY]) sizesHeight[i] = -1.0;
74 CGFloat neededHeight = [(<CocoaGwenGUIProtocol>)subview minSize].height;
75 sizesHeight[i] = neededHeight;
76 exclusiveHeight += neededHeight;
82 sizesHeight[i] = -1.0;
89 CGFloat stdHeight = 0.0;
90 if (numOfSubViews > exclusiveChilds) {
91 CGFloat fillHeight = bounds.size.height-exclusiveHeight;
95 CGFloat fillHeight = bounds.size.height;
105 NSRect actualFrame = bounds;
108 for (i=0; i<numOfSubViews; i++) {
110 CGFloat usedHeight = sizesHeight[i];
111 if (usedHeight < 0.0) usedHeight = stdHeight;
112 actualFrame.origin.y -= usedHeight;
113 actualFrame.size.height = usedHeight;
117 CGFloat usedWidth = sizesWidth[i];
118 if (usedWidth < 0.0) usedWidth = stdWidth;
119 NSView* subview = [subviewsInOrder objectAtIndex:i];
120 actualFrame.size.width = usedWidth;
122 [subview setFrame:actualFrame];
129-(void) addLayoutSubview:(NSView*)new_subview {
130 [subviewsInOrder addObject:new_subview];
131 [
self addSubview:new_subview];
132 [
self layoutSubviews];