gwenhywfar  4.3.3
CocoaScrollBox.m
Go to the documentation of this file.
00001 //
00002 //  CocoaScrollBox.m
00003 //  
00004 //
00005 //  Created by Samuel Strupp on 17.08.10.
00006 //
00007 
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011 
00012 
00013 #import "CocoaScrollBox.h"
00014 
00015 #ifndef COCOA_SCROLL_BOX_M
00016 #define COCOA_SCROLL_BOX_M
00017 
00018 @implementation CocoaScrollBox
00019 
00020 @synthesize fillX;
00021 @synthesize fillY;
00022 
00023 - (id)initWithFrame:(NSRect)frame {
00024     self = [super initWithFrame:frame];
00025     if (self) {
00026                 fillX = NO;
00027                 fillY = NO;
00028                 //subviewsInOrder = [[NSMutableArray alloc] init];
00029                 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutSubviews) name:NSViewFrameDidChangeNotification object:self];
00030     }
00031     return self;
00032 }
00033 
00034 -(void) dealloc {
00035         [[NSNotificationCenter defaultCenter] removeObserver:self];
00036         //[subviewsInOrder release];
00037         [super dealloc];
00038 }
00039 
00040 /*- (void)drawRect:(NSRect)dirtyRect {
00041         //debug colors
00042     [[NSColor greenColor] set];
00043         NSRectFill(dirtyRect);
00044 }*/
00045 
00046 #define borderDistance 8.0
00047 #define cellDistance 4.0
00048 
00049 -(void) layoutSubviews {
00050         
00051         NSView *documentView = [self documentView];
00052         
00053         if (documentView && [documentView conformsToProtocol:@protocol(CocoaGwenGUIProtocol)]) {
00054                 NSSize neededMinSize = [(<CocoaGwenGUIProtocol>)documentView minSize];
00055                 NSSize contentSize = [self contentSize];
00056                 
00057                 NSRect newFrame = NSMakeRect(0.0, 0.0, neededMinSize.width, neededMinSize.height);
00058                 if ([(<CocoaGwenGUIProtocol>)documentView fillX] && neededMinSize.width < contentSize.width)
00059                         newFrame.size.width = contentSize.width;
00060                 if ([(<CocoaGwenGUIProtocol>)documentView fillY] && neededMinSize.height < contentSize.height)
00061                         newFrame.size.height = contentSize.height;
00062                 
00063                 [documentView setFrame:newFrame];
00064         }
00065 }
00066 
00067 -(void) setLayoutedDocumentView:(NSView*)new_documentView {
00068         [self setDocumentView:new_documentView];
00069         [self layoutSubviews];
00070 }
00071 
00072 #pragma mark Protocoll Methods
00073 
00074 - (NSSize) minSize {
00075         return NSMakeSize(50.0, 50.0);
00076 }
00077 
00078 /*- (void)setFrame:(NSRect)frameRect {
00079         NSSize minSize = [self minSize];
00080         if (frameRect.size.height < minSize.height) {
00081                 frameRect.size.height = minSize.height;
00082         }
00083         if (frameRect.size.width < minSize.width) {
00084                 frameRect.size.width = minSize.width;
00085         }
00086         [super setFrame:frameRect];
00087 }*/
00088 
00089 @end
00090 
00091 #endif