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