gwenhywfar  4.3.3
CocoaTextBrowser.m
Go to the documentation of this file.
00001 //
00002 //  CocoaTextBrowser.m
00003 //  
00004 //
00005 //  Created by Samuel Strupp on 18.08.10.
00006 //
00007 
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011 
00012 
00013 #import "CocoaTextBrowser.h"
00014 
00015 
00016 @implementation CocoaTextBrowser
00017 
00018 @synthesize fillX;
00019 @synthesize fillY;
00020 
00021 - (id) initWithFrame:(NSRect)frameRect frameName:(NSString *)frameName groupName:(NSString *)groupName {
00022     self = [super initWithFrame:frameRect frameName:frameName groupName:groupName];
00023     if (self) {
00024                 fillX = NO;
00025                 fillY = NO;
00026                 loadedString = nil;
00027                 //[[[self mainFrame] frameView] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
00028     }
00029     return self;
00030 }
00031 
00032 -(void) dealloc {
00033         [loadedString release];
00034         [super dealloc];
00035 }
00036 
00037 #pragma mark Special Methods
00038 
00039 -(void) setStringValue:(NSString*)value BasePath:(NSString*)base {
00040         if (value) {
00041                 [loadedString release];
00042                 loadedString = [value retain];
00043                 
00044                 
00045                 NSString *basePath = base;
00046                 if (!basePath) {
00047                         basePath = [[NSBundle mainBundle] resourcePath];
00048                         if (!basePath) basePath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
00049                 }
00050                 NSURL *baseURL = [NSURL fileURLWithPath:basePath];
00051                 
00052                 if (value) {
00053                         NSRange htmlRange = [value rangeOfString:@"<html>"];
00054                         if (htmlRange.location != NSNotFound) {
00055                                 NSRange endHtmlRange = [value rangeOfString:@"</html>"];
00056                                 if (endHtmlRange.location != NSNotFound) {
00057                                         NSString *stringToUse = @"";
00058                                         NSRange useRange = NSUnionRange(htmlRange, endHtmlRange);
00059                                         stringToUse = [value substringWithRange:useRange];
00060                                         [[self mainFrame] loadHTMLString:stringToUse baseURL:baseURL];
00061                                         return;
00062                                 }
00063                         }
00064                         [[self mainFrame] loadHTMLString:value baseURL:baseURL];
00065                 }
00066         }
00067         else {
00068                 [loadedString release];
00069                 loadedString = nil;
00070         }
00071 
00072 }
00073 
00074 -(void) setStringValue:(NSString*)value {
00075         [self setStringValue:value BasePath:nil];
00076 }
00077 
00078 -(NSString*) stringValue {
00079         return loadedString;
00080 }
00081 
00082 #pragma mark Protocoll Methods
00083 
00084 - (NSSize) minSize {
00085         return NSMakeSize(30.0, 30.0);
00086 }
00087 
00088 - (BOOL) fillX {
00089         return fillX;
00090 }
00091 
00092 - (BOOL) fillY {
00093         return fillY;
00094 }
00095 
00096 - (void)setFrame:(NSRect)frameRect {
00097         if (frameRect.size.width < 0.0) frameRect.size.width = 0.0;
00098         if (frameRect.size.height < 0.0) frameRect.size.height = 0.0;
00099         [super setFrame:frameRect];
00100 }
00101 
00102 @end