]> err.no Git - sope/blob - sope-appserver/WEExtensions/WETreeMatrixElement.m
code reorgs
[sope] / sope-appserver / WEExtensions / WETreeMatrixElement.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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
22 #include "WETreeMatrixElement.h"
23 #include "common.h"
24
25 @implementation _WETreeMatrixElement
26
27 static Class StrClass = Nil;
28
29 + (void)initialize {
30   StrClass = [NSString class];
31 }
32
33 - (id)initWithElement:(_WETreeMatrixElement *)_element {
34   if ((self = [super init])) {
35     int j;
36     
37     for (j = 0; j < MAX_TREE_DEPTH; j++)
38       self->elements[j] = 0;
39     
40     if (_element) {
41       int i;
42       
43       self->depth = _element->depth + 1;
44       for (i = 0; i < self->depth; i++) {
45         self->leaf         = _element->leaf;
46         self->elements[i]  = [_element->elements[i] retain];
47         self->indexPath[i] = _element->indexPath[i];
48         self->itemPath[i]  = [_element->itemPath[i] retain];
49       }
50     }
51     else
52       self->depth = 0;
53   }
54   return self;  
55 }
56
57 - (id)init {
58   return [self initWithElement:nil];
59 }
60
61 - (void)dealloc {
62   int i;
63
64   for (i = 0; i < self->depth; i++) {
65     [self->itemPath[i] release];
66     [self->elements[i] release];
67   }
68   [super dealloc];
69 }
70
71 /* accessors */
72   
73 - (void)setElement:(NSString *)_element {
74   ASSIGN(self->elements[self->depth], _element);
75 }
76 - (NSString *)elementAtIndex:(int)_index {
77   return self->elements[_index];
78 }
79
80 - (void)setItem:(id)_item {
81   ASSIGN(self->itemPath[self->depth], _item);
82 }
83 - (id)item {
84   return self->itemPath[self->depth-1];
85 }
86
87 - (void)setIndex:(int)_index {
88   self->indexPath[self->depth] = _index;
89 }
90 - (int)index {
91   return self->indexPath[self->depth-1];
92 }
93
94 - (void)setLeaf:(NSString *)_leaf {
95   ASSIGN(self->leaf, _leaf);
96 }
97 - (NSString *)leaf {
98   return self->leaf;
99 }
100
101 - (void)setColspan:(int)_colspan {
102   self->colspan = _colspan;
103 }
104
105 - (NSString *)colspanAsString {
106   char buf[8];
107   sprintf(buf, "%d", self->colspan);
108   return [NSString stringWithCString:buf];
109 }
110
111 - (int)depth {
112   return self->depth;
113 }
114
115 - (NSArray *)currentPath {
116   NSMutableArray *result;
117   int            i;
118
119   result = [NSMutableArray arrayWithCapacity:self->depth];
120   for (i = 0; i < self->depth+1; i++) {
121     if (self->itemPath[i] == nil)
122       break;
123     [result addObject:self->itemPath[i]];
124   }
125   return (NSArray *)result;
126 }
127
128 - (NSString *)elementID {
129   // TODO: improve performance
130   NSMutableArray *tmp;
131   NSString *s;
132   int            i;
133   
134   tmp = [[NSMutableArray alloc] initWithCapacity:self->depth];
135   
136   for (i = 0; i < self->depth; i++) {
137     s = [[StrClass alloc] initWithFormat:@"%d", self->indexPath[i]];
138     [tmp addObject:s];
139     [s release];
140   }
141   s = [tmp componentsJoinedByString:@"."];
142   [tmp release];
143   return s;
144 }
145
146 @end /* _WETreeMatrixElement */