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