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