2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #include <NGObjWeb/NGObjWeb.h>
24 #include <NGObjWeb/WEClientCapabilities.h>
27 @interface JSClipboard : WODynamicElement
29 WOAssociation *filename;
30 WOAssociation *imgURL;
31 WOAssociation *string;
32 WOAssociation *toolTip;
37 @implementation JSClipboard
39 - (id)initWithName:(NSString *)_name
40 associations:(NSDictionary *)_config
41 template:(WOElement *)_subs
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");
54 [self->imgURL release];
55 [self->string release];
56 [self->toolTip release];
57 [self->value release];
63 - (NSString *)imageByFilename:(NSString *)_name
64 inContext:(WOContext *)_ctx
65 framework:(NSString *)_framework
67 WOResourceManager *rm;
71 rm = [[_ctx application] resourceManager];
73 languages = [_ctx hasSession]
74 ? [[_ctx session] languages]
75 : [[_ctx request] browserLanguages];
77 tmp = [rm urlForResourceNamed:_name
78 inFramework:_framework
80 request:[_ctx request]];
84 - (void)appendToResponse:(WOResponse *)_response
85 inContext:(WOContext *)_ctx
89 NSString *tt; // toolTip
90 WEClientCapabilities *ccaps;
92 comp = [_ctx component];
93 ccaps = [[_ctx request] clientCapabilities];
94 tt = [self->toolTip stringValueInComponent:comp];
97 if (![ccaps isInternetExplorer]) return;
98 if ([ccaps isMacBrowser]) return;
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;
107 NSAssert(self->imgURL != nil || self->string != nil || self->filename != nil,
108 @"ERROR: no imageURL or string defined...");
110 if (self->filename) {
111 NSString *imageFilename;
114 [self imageByFilename:[self->filename stringValueInComponent:comp]
116 framework:[comp frameworkName]];
118 tmp = [[NSString alloc] initWithFormat:
119 @"<img border=\"0\"src=\"%@\" /></a>",
122 else if (self->imgURL) {
123 tmp = [[NSString alloc] initWithFormat:
124 @"<img border=\"0\"src=\"%@\" /></a>",
125 [self->imgURL stringValueInComponent:comp]];
128 tmp = [[NSString alloc] initWithFormat:
130 [self->string stringValueInComponent:comp]];
132 [_response appendContentString:tmp];
136 @end /* JSClipboard */