gwenhywfar  4.7.0beta
CocoaScrollBox.m
Go to the documentation of this file.
1 //
2 // CocoaScrollBox.m
3 //
4 //
5 // Created by Samuel Strupp on 17.08.10.
6 //
7 
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11 
12 
13 #import "CocoaScrollBox.h"
14 
15 #ifndef COCOA_SCROLL_BOX_M
16 #define COCOA_SCROLL_BOX_M
17 
18 @implementation CocoaScrollBox
19 
20 @synthesize fillX;
21 @synthesize fillY;
22 
23 - (id)initWithFrame:(NSRect)frame {
24  self = [super initWithFrame:frame];
25  if (self) {
26  fillX = NO;
27  fillY = NO;
28  //subviewsInOrder = [[NSMutableArray alloc] init];
29  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutSubviews) name:NSViewFrameDidChangeNotification object:self];
30  }
31  return self;
32 }
33 
34 -(void) dealloc {
35  [[NSNotificationCenter defaultCenter] removeObserver:self];
36  //[subviewsInOrder release];
37  [super dealloc];
38 }
39 
40 /*- (void)drawRect:(NSRect)dirtyRect {
41  //debug colors
42  [[NSColor greenColor] set];
43  NSRectFill(dirtyRect);
44 }*/
45 
46 #define borderDistance 8.0
47 #define cellDistance 4.0
48 
49 -(void) layoutSubviews {
50 
51  NSView *documentView = [self documentView];
52 
53  if (documentView && [documentView conformsToProtocol:@protocol(CocoaGwenGUIProtocol)]) {
54  NSSize neededMinSize = [(<CocoaGwenGUIProtocol>)documentView minSize];
55  NSSize contentSize = [self contentSize];
56 
57  NSRect newFrame = NSMakeRect(0.0, 0.0, neededMinSize.width, neededMinSize.height);
58  if ([(<CocoaGwenGUIProtocol>)documentView fillX] && neededMinSize.width < contentSize.width)
59  newFrame.size.width = contentSize.width;
60  if ([(<CocoaGwenGUIProtocol>)documentView fillY] && neededMinSize.height < contentSize.height)
61  newFrame.size.height = contentSize.height;
62 
63  [documentView setFrame:newFrame];
64  }
65 }
66 
67 -(void) setLayoutedDocumentView:(NSView*)new_documentView {
68  [self setDocumentView:new_documentView];
69  [self layoutSubviews];
70 }
71 
72 #pragma mark Protocoll Methods
73 
74 - (NSSize) minSize {
75  return NSMakeSize(50.0, 50.0);
76 }
77 
78 /*- (void)setFrame:(NSRect)frameRect {
79  NSSize minSize = [self minSize];
80  if (frameRect.size.height < minSize.height) {
81  frameRect.size.height = minSize.height;
82  }
83  if (frameRect.size.width < minSize.width) {
84  frameRect.size.width = minSize.width;
85  }
86  [super setFrame:frameRect];
87 }*/
88 
89 @end
90 
91 #endif