1/*
2    This file is part of HelpViewer (http://www.roard.com/helpviewer)
3    Copyright (C) 2003 Nicolas Roard (nicolas@roard.com)
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include "Page.h"
21
22@implementation Part
23
24- (id) init {
25    self = [super init];
26    sections = [[NSMutableArray alloc] init];
27    subviews = [[NSMutableArray alloc] init];
28    title = [[NSString alloc] initWithString: @""];
29    text = [[NSMutableAttributedString alloc] initWithString: @"\n"];
30
31    return self;
32}
33
34- (void) dealloc {
35    RELEASE (sections);
36    RELEASE (subviews);
37    RELEASE (title);
38    RELEASE (text);
39}
40
41- (NSString*) title {
42    return title;
43}
44
45- (void) setTitle: (NSString*) ptitle {
46    ASSIGN (title, ptitle);
47}
48
49- (NSMutableAttributedString*) text {
50    return text;
51}
52
53- (void) addSection: (Section*) section {
54    [sections addObject: section];
55}
56
57- (void) addSubview: (NSView*) view {
58    [subviews addObject: view];
59}
60
61- (void) addSubviewsToView: (NSView*) view {
62    int i;
63
64    for (i=0; i < [subviews count]; i++)
65    {
66	[view addSubview: [subviews objectAtIndex: i]];
67    }
68}
69
70- (void) removeSubviews {
71    int i;
72
73    for (i=0; i < [subviews count]; i++)
74    {
75	[[subviews objectAtIndex: i] removeFromSuperview];
76    }
77}
78
79- (NSAttributedString*) getPage {
80    int i;
81    NSMutableAttributedString* ret = [[NSMutableAttributedString alloc] initWithAttributedString: text];
82    AUTORELEASE (ret);
83
84    NSLog (@"sections count : %d", [sections count]);
85    for (i=0; i < [sections count]; i++)
86    {
87	NSMutableAttributedString* current;
88	current = [(Section*)[sections objectAtIndex: i] text];
89	[[sections objectAtIndex: i] setRange: NSMakeRange ([ret length], [current length])];
90	[ret appendAttributedString: AUTORELEASE([[NSMutableAttributedString alloc] initWithString: @"\n"])];
91	[ret appendAttributedString: current];
92    }
93
94    /*
95    NSMutableAttributedString* ret = [[NSMutableAttributedString alloc] initWithString: @"Ceci est un test"];
96    AUTORELEASE (ret);
97    NSFont* font = [NSFont boldSystemFontOfSize: 80];
98    NSDictionary* att = [NSDictionary dictionaryWithObject: font forKey: @"NSFontAttributeName"];
99    [ret addAttributes: att range: NSMakeRange (0,10)];
100    */
101
102    NSLog (@"Page retourn�e : %@", ret);
103
104    return ret;
105}
106
107- (NSArray*) sections {
108    return sections;
109}
110
111@end
112
113