]> err.no Git - scalable-opengroupware.org/blob - UI/Common/common.h
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1162 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Common / common.h
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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
22 #import <NGObjWeb/WOAssociation.h>
23 #import <NGObjWeb/WOContext+SoObjects.h>
24 #import <NGObjWeb/WODynamicElement.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <NGObjWeb/WOResourceManager.h>
27 #import <NGObjWeb/WOSession.h>
28 #import <NGExtensions/NSObject+Logs.h>
29
30 @interface WOContext(WOExtensionsPrivate)
31 - (void)addActiveFormElement:(WOElement *)_element;
32 @end
33
34 static inline id WOExtGetProperty(NSDictionary *_set, NSString *_name) {
35     id propValue = [_set objectForKey:_name];
36     
37     if (propValue) {
38         propValue = [propValue retain];
39         [(NSMutableDictionary *)_set removeObjectForKey:_name];
40     }
41     return propValue;
42 }
43
44 static inline NSString *WEUriOfResource(NSString *_name, WOContext *_ctx) {
45     NSArray           *languages;
46     WOResourceManager *resourceManager;
47     NSString          *uri;
48     
49     if (_name == nil)
50         return nil;
51     
52     languages = [_ctx hasSession]
53         ? [[_ctx session] languages]
54         : [[_ctx request] browserLanguages];
55     
56     resourceManager = [[_ctx application] resourceManager];
57     
58     uri = [resourceManager urlForResourceNamed:_name
59                                    inFramework:nil
60                                      languages:languages
61                                        request:[_ctx request]];
62     if ([uri rangeOfString:@"/missingresource?"].length > 0)
63         uri = nil;
64     
65     return uri;
66 }
67
68 static inline void WEAppendFont(WOResponse *_resp,
69                                 NSString   *_color,
70                                 NSString   *_face,
71                                 NSString   *_size)
72 {
73     [_resp appendContentString:@"<font"];
74     if (_color) {
75         [_resp appendContentString:@" color=\""];
76         [_resp appendContentHTMLAttributeValue:_color];
77         [_resp appendContentCharacter:'"'];
78     }
79     if (_face) {
80         [_resp appendContentString:@" face=\""];
81         [_resp appendContentHTMLAttributeValue:_face];
82         [_resp appendContentCharacter:'"'];
83     }
84     if (_size) {
85         [_resp appendContentString:@" size=\""];
86         [_resp appendContentHTMLAttributeValue:_size];
87         [_resp appendContentCharacter:'"'];
88     }
89     [_resp appendContentCharacter:'>'];
90 }
91
92 static inline void WEAppendTD(WOResponse *_resp,
93                               NSString   *_align,
94                               NSString   *_valign,
95                               NSString   *_bgColor)
96 {
97     [_resp appendContentString:@"<td"];
98     if (_bgColor) {
99         [_resp appendContentString:@" bgcolor=\""];
100         [_resp appendContentHTMLAttributeValue:_bgColor];
101         [_resp appendContentCharacter:'"'];
102     }
103     if (_align) {
104         [_resp appendContentString:@" align=\""];
105         [_resp appendContentHTMLAttributeValue:_align];
106         [_resp appendContentCharacter:'"'];
107     }
108     if (_valign) {
109         [_resp appendContentString:@" valign=\""];
110         [_resp appendContentHTMLAttributeValue:_valign];
111         [_resp appendContentCharacter:'"'];
112     }
113     [_resp appendContentCharacter:'>'];
114 }
115
116 static inline WOElement *WECreateElement(NSString *_className,
117                                          NSString *_name,
118                                          NSDictionary *_config,
119                                          WOElement *_template)
120 {
121     Class               c;
122     WOElement           *result = nil;
123     NSMutableDictionary *config = nil;
124     
125     if ((c = NSClassFromString(_className)) == Nil) {
126         NSLog(@"%s: missing '%@' class", __PRETTY_FUNCTION__, _className);
127         return nil;
128     }
129     config = [NSMutableDictionary dictionaryWithCapacity:4];
130     {
131         NSEnumerator *keyEnum;
132         id           key;
133         
134         keyEnum = [_config keyEnumerator];
135         
136         while ((key = [keyEnum nextObject])) {
137             WOAssociation *a;
138             
139             a = [WOAssociation associationWithValue:[_config objectForKey:key]];
140             [config setObject:a forKey:key];
141         }
142     }
143     result = [[c alloc] initWithName:_name
144                         associations:config
145                             template:_template];
146     return [result autorelease];
147 }
148
149 #define OWGetProperty WOExtGetProperty