]> err.no Git - sope/blob - sope-appserver/WEExtensions/WETreeHeader.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / WETreeHeader.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 /*
23   WETreeHeader
24
25   Take a look at WETreeView for more information.
26
27   WETreeHeader associations:
28     isTreeElement
29     icon
30     cornerIcon
31     title
32     string
33
34   Example:
35       TreeHeaderCell: WETreeHeader {
36         isTreeElement = YES;
37       }
38       HeaderCell: WETreeHeader {
39         isTreeElement = NO;
40       }
41 */
42
43 #include <NGObjWeb/WODynamicElement.h>
44
45 @interface WETreeHeader : WODynamicElement
46 {
47 @protected
48   WOAssociation  *isTreeElement;
49   WOElement      *template;
50   WOAssociation  *string;
51 }
52 @end
53
54 #include "WETreeContextKeys.h"
55 #include "common.h"
56
57 @implementation WETreeHeader
58
59 - (id)initWithName:(NSString *)_name
60   associations:(NSDictionary *)_config
61   template:(WOElement *)_subs
62 {
63   if ((self=[super initWithName:_name associations:_config template:_subs])) {
64     self->isTreeElement = WOExtGetProperty(_config, @"isTreeElement");
65     self->string        = WOExtGetProperty(_config, @"string");
66     
67     self->template      = [_subs retain];
68   }
69   return self;
70 }
71
72 - (void)dealloc {
73   [self->string        release];
74   [self->isTreeElement release];
75   [self->template      release];
76   [super dealloc];
77 }
78
79 /* request processing */
80
81 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
82   [self->template takeValuesFromRequest:_rq inContext:_ctx];
83 }
84
85 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
86   return [self->template invokeActionForRequest:_rq inContext:_ctx];
87 }
88
89 /* response generation */
90
91 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
92   NSString *content;
93   BOOL isTree;
94   BOOL doTable;
95
96   if (![_ctx objectForKey:WETreeView_HEADER_MODE])
97     return;
98     
99   isTree  = [self->isTreeElement boolValueInComponent:[_ctx component]];
100   doTable = ([_ctx objectForKey:WETreeView_RenderNoTable] == nil);
101   content = [self->string        stringValueInComponent:[_ctx component]];
102     
103   if (doTable) {
104     [_response appendContentString:@"<td"];
105     [self appendExtraAttributesToResponse:_response inContext:_ctx];
106     if (self->otherTagString) {
107       [_response appendContentCharacter:' '];
108       [_response appendContentString:
109                  [self->otherTagString stringValueInComponent:
110                       [_ctx component]]];
111     }
112     if (isTree) {
113       [_response appendContentString:@" colspan=\""];
114       [_response appendContentString:
115                  [[_ctx objectForKey:WETreeView_HEADER_MODE] stringValue]];
116       [_response appendContentString:@"\"><nobr>"];
117     }
118     else
119       [_response appendContentString:@"><nobr>"];
120   }
121     
122   /* add cell content */
123   [self->template appendToResponse:_response inContext:_ctx];
124   if (content)
125     [_response appendContentHTMLString:content];
126
127   if (doTable)
128     [_response appendContentString:@"</nobr></td>"];
129 }
130
131 @end /* WETreeHeader */