gwenhywfar 5.14.1
CocoaTextBrowser.m
Go to the documentation of this file.
1//
2// CocoaTextBrowser.m
3//
4//
5// Created by Samuel Strupp on 18.08.10.
6//
7
8#ifdef HAVE_CONFIG_H
9# include <config.h>
10#endif
11
12
13#import "CocoaTextBrowser.h"
14
15
16@implementation CocoaTextBrowser
17
18@synthesize fillX;
19@synthesize fillY;
20
21- (id) initWithFrame:(NSRect)frameRect frameName:(NSString *)frameName groupName:(NSString *)groupName {
22 self = [super initWithFrame:frameRect frameName:frameName groupName:groupName];
23 if (self) {
24 fillX = NO;
25 fillY = NO;
26 loadedString = nil;
27 //[[[self mainFrame] frameView] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
28 }
29 return self;
30}
31
32-(void) dealloc {
33 [loadedString release];
34 [super dealloc];
35}
36
37#pragma mark Special Methods
38
39-(void) setStringValue:(NSString*)value BasePath:(NSString*)base {
40 if (value) {
41 [loadedString release];
42 loadedString = [value retain];
43
44
45 NSString *basePath = base;
46 if (!basePath) {
47 basePath = [[NSBundle mainBundle] resourcePath];
48 if (!basePath) basePath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
49 }
50 NSURL *baseURL = [NSURL fileURLWithPath:basePath];
51
52 if (value) {
53 NSRange htmlRange = [value rangeOfString:@"<html>"];
54 if (htmlRange.location != NSNotFound) {
55 NSRange endHtmlRange = [value rangeOfString:@"</html>"];
56 if (endHtmlRange.location != NSNotFound) {
57 NSString *stringToUse = @"";
58 NSRange useRange = NSUnionRange(htmlRange, endHtmlRange);
59 stringToUse = [value substringWithRange:useRange];
60 [[self mainFrame] loadHTMLString:stringToUse baseURL:baseURL];
61 return;
62 }
63 }
64 [[self mainFrame] loadHTMLString:value baseURL:baseURL];
65 }
66 }
67 else {
68 [loadedString release];
69 loadedString = nil;
70 }
71
72}
73
74-(void) setStringValue:(NSString*)value {
75 [self setStringValue:value BasePath:nil];
76}
77
78-(NSString*) stringValue {
79 return loadedString;
80}
81
82#pragma mark Protocoll Methods
83
84- (NSSize) minSize {
85 return NSMakeSize(30.0, 30.0);
86}
87
88- (BOOL) fillX {
89 return fillX;
90}
91
92- (BOOL) fillY {
93 return fillY;
94}
95
96- (void)setFrame:(NSRect)frameRect {
97 if (frameRect.size.width < 0.0) frameRect.size.width = 0.0;
98 if (frameRect.size.height < 0.0) frameRect.size.height = 0.0;
99 [super setFrame:frameRect];
100}
101
102@end
NSString * stringValue()
NSString * loadedString
void setStringValue:BasePath:(NSString *value,[BasePath] NSString *base)