]> err.no Git - sope/blob - sope-appserver/WEExtensions/JSClipboard.m
new Xcode projects, removed old Xcode project
[sope] / sope-appserver / WEExtensions / JSClipboard.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
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:
22
23 #include <NGObjWeb/NGObjWeb.h>
24 #include <NGObjWeb/WEClientCapabilities.h>
25 #include "common.h"
26
27 @interface JSClipboard : WODynamicElement
28 {
29   WOAssociation *filename;
30   WOAssociation *imgURL;
31   WOAssociation *string;
32   WOAssociation *toolTip;
33   WOAssociation *value;
34 }
35 @end
36
37 @implementation JSClipboard
38
39 - (id)initWithName:(NSString *)_name
40   associations:(NSDictionary *)_config
41   template:(WOElement *)_subs
42 {
43   if((self = [super initWithName:_name associations:_config template:_subs])) {
44     self->filename = OWGetProperty(_config,@"filename");
45     self->imgURL   = OWGetProperty(_config,@"imgURL");
46     self->string   = OWGetProperty(_config,@"string");
47     self->toolTip  = OWGetProperty(_config,@"toolTip");
48     self->value    = OWGetProperty(_config,@"value");
49   }
50   return self;
51 }
52
53 - (void)dealloc {
54   [self->imgURL  release];
55   [self->string  release];
56   [self->toolTip release];
57   [self->value   release];
58   [super dealloc];
59 }
60
61 /* operations */
62
63 - (NSString *)imageByFilename:(NSString *)_name
64   inContext:(WOContext *)_ctx
65   framework:(NSString *)_framework
66 {
67   WOResourceManager *rm;
68   NSString          *tmp;
69   NSArray           *languages;
70
71   rm = [[_ctx application] resourceManager];
72     
73   languages = [_ctx hasSession]
74     ? [[_ctx session] languages]
75     : [[_ctx request] browserLanguages];
76     
77   tmp = [rm urlForResourceNamed:_name
78             inFramework:_framework
79             languages:languages
80             request:[_ctx request]];
81   return tmp;
82 }
83
84 - (void)appendToResponse:(WOResponse *)_response
85                inContext:(WOContext *)_ctx
86 {
87   WOComponent          *comp;
88   NSString             *tmp;
89   NSString             *tt;    // toolTip
90   WEClientCapabilities *ccaps;
91
92   comp    = [_ctx component];
93   ccaps   = [[_ctx request] clientCapabilities];
94   tt      = [self->toolTip stringValueInComponent:comp];
95   tt      = tt ? tt : @"";
96
97   if (![ccaps isInternetExplorer]) return;
98   if ([ccaps isMacBrowser]) return;
99
100   tmp = [[NSString alloc] initWithFormat:
101                   @"<a href=\"#\" onclick=\"javascript:clipboardData."
102                   @"setData('text', '%@');return false;\" title=\"%@\">",
103                   [self->value stringValueInComponent:comp], tt];
104   [_response appendContentString:tmp];
105   [tmp release]; tmp = nil;
106   
107   NSAssert(self->imgURL != nil || self->string != nil || self->filename != nil,
108            @"ERROR: no imageURL or string defined...");
109
110   if (self->filename) {
111     NSString *imageFilename;
112
113     imageFilename =
114       [self imageByFilename:[self->filename stringValueInComponent:comp]
115             inContext:_ctx
116             framework:[comp frameworkName]];
117
118     tmp = [[NSString alloc] initWithFormat:
119                     @"<img border=\"0\"src=\"%@\" /></a>",
120                     imageFilename];
121   }
122   else if (self->imgURL) {
123     tmp = [[NSString alloc] initWithFormat:
124                     @"<img border=\"0\"src=\"%@\" /></a>",
125                     [self->imgURL stringValueInComponent:comp]];
126   }
127   else {
128     tmp = [[NSString alloc] initWithFormat:
129                     @"%@</a>",
130                     [self->string stringValueInComponent:comp]];
131   }
132   [_response appendContentString:tmp];
133   [tmp release];
134 }
135
136 @end /* JSClipboard */