2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #include "WETreeMatrixElement.h"
26 @implementation _WETreeMatrixElement
28 static Class StrClass = Nil;
31 StrClass = [NSString class];
34 - (id)initWithElement:(_WETreeMatrixElement *)_element {
35 if ((self = [super init])) {
38 for (j = 0; j < MAX_TREE_DEPTH; j++)
39 self->elements[j] = 0;
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];
59 return [self initWithElement:nil];
65 for (i = 0; i < self->depth; i++) {
66 [self->itemPath[i] release];
67 [self->elements[i] release];
74 - (void)setElement:(NSString *)_element {
75 ASSIGN(self->elements[self->depth], _element);
77 - (NSString *)elementAtIndex:(int)_index {
78 return self->elements[_index];
81 - (void)setItem:(id)_item {
82 ASSIGN(self->itemPath[self->depth], _item);
85 return self->itemPath[self->depth-1];
88 - (void)setIndex:(int)_index {
89 self->indexPath[self->depth] = _index;
92 return self->indexPath[self->depth-1];
95 - (void)setLeaf:(NSString *)_leaf {
96 ASSIGN(self->leaf, _leaf);
102 - (void)setColspan:(int)_colspan {
103 self->colspan = _colspan;
106 - (NSString *)colspanAsString {
107 unsigned char buf[8];
108 sprintf(buf, "%d", self->colspan);
109 return [NSString stringWithCString:buf];
116 - (NSArray *)currentPath {
117 NSMutableArray *result;
120 result = [NSMutableArray arrayWithCapacity:self->depth];
121 for (i = 0; i < self->depth+1; i++) {
122 if (self->itemPath[i] == nil)
124 [result addObject:self->itemPath[i]];
126 return (NSArray *)result;
129 - (NSString *)elementID {
130 // TODO: improve performance
135 tmp = [[NSMutableArray alloc] initWithCapacity:self->depth];
137 for (i = 0; i < self->depth; i++) {
138 s = [[StrClass alloc] initWithFormat:@"%d", self->indexPath[i]];
142 s = [tmp componentsJoinedByString:@"."];
147 @end /* _WETreeMatrixElement */