]> err.no Git - sope/blob - sope-appserver/WEExtensions/WETreeMatrixElement.m
new Xcode projects, removed old Xcode project
[sope] / sope-appserver / WEExtensions / WETreeMatrixElement.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "WETreeMatrixElement.h"
24 #include "common.h"
25
26 @implementation _WETreeMatrixElement
27
28 static Class StrClass = Nil;
29
30 + (void)initialize {
31   StrClass = [NSString class];
32 }
33
34 - (id)initWithElement:(_WETreeMatrixElement *)_element {
35   if ((self = [super init])) {
36     int j;
37     
38     for (j = 0; j < MAX_TREE_DEPTH; j++)
39       self->elements[j] = 0;
40     
41     if (_element) {
42       int i;
43       
44       self->depth = _element->depth + 1;
45       for (i = 0; i < self->depth; i++) {
46         self->leaf         = _element->leaf;
47         self->elements[i]  = [_element->elements[i] retain];
48         self->indexPath[i] = _element->indexPath[i];
49         self->itemPath[i]  = [_element->itemPath[i] retain];
50       }
51     }
52     else
53       self->depth = 0;
54   }
55   return self;  
56 }
57
58 - (id)init {
59   return [self initWithElement:nil];
60 }
61
62 - (void)dealloc {
63   int i;
64
65   for (i = 0; i < self->depth; i++) {
66     [self->itemPath[i] release];
67     [self->elements[i] release];
68   }
69   [super dealloc];
70 }
71
72 /* accessors */
73   
74 - (void)setElement:(NSString *)_element {
75   ASSIGN(self->elements[self->depth], _element);
76 }
77 - (NSString *)elementAtIndex:(int)_index {
78   return self->elements[_index];
79 }
80
81 - (void)setItem:(id)_item {
82   ASSIGN(self->itemPath[self->depth], _item);
83 }
84 - (id)item {
85   return self->itemPath[self->depth-1];
86 }
87
88 - (void)setIndex:(int)_index {
89   self->indexPath[self->depth] = _index;
90 }
91 - (int)index {
92   return self->indexPath[self->depth-1];
93 }
94
95 - (void)setLeaf:(NSString *)_leaf {
96   ASSIGN(self->leaf, _leaf);
97 }
98 - (NSString *)leaf {
99   return self->leaf;
100 }
101
102 - (void)setColspan:(int)_colspan {
103   self->colspan = _colspan;
104 }
105
106 - (NSString *)colspanAsString {
107   unsigned char buf[8];
108   sprintf(buf, "%d", self->colspan);
109   return [NSString stringWithCString:buf];
110 }
111
112 - (int)depth {
113   return self->depth;
114 }
115
116 - (NSArray *)currentPath {
117   NSMutableArray *result;
118   int            i;
119
120   result = [NSMutableArray arrayWithCapacity:self->depth];
121   for (i = 0; i < self->depth+1; i++) {
122     if (self->itemPath[i] == nil)
123       break;
124     [result addObject:self->itemPath[i]];
125   }
126   return (NSArray *)result;
127 }
128
129 - (NSString *)elementID {
130   // TODO: improve performance
131   NSMutableArray *tmp;
132   NSString *s;
133   int            i;
134   
135   tmp = [[NSMutableArray alloc] initWithCapacity:self->depth];
136   
137   for (i = 0; i < self->depth; i++) {
138     s = [[StrClass alloc] initWithFormat:@"%d", self->indexPath[i]];
139     [tmp addObject:s];
140     [s release];
141   }
142   s = [tmp componentsJoinedByString:@"."];
143   [tmp release];
144   return s;
145 }
146
147 @end /* _WETreeMatrixElement */