2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGObjWeb/NGObjWeb.h>
23 #include <NGObjWeb/WEClientCapabilities.h>
26 @interface JSClipboard : WODynamicElement
28 WOAssociation *filename;
29 WOAssociation *imgURL;
30 WOAssociation *string;
31 WOAssociation *toolTip;
36 @implementation JSClipboard
38 - (id)initWithName:(NSString *)_name
39 associations:(NSDictionary *)_config
40 template:(WOElement *)_subs
42 if((self = [super initWithName:_name associations:_config template:_subs])) {
43 self->filename = OWGetProperty(_config,@"filename");
44 self->imgURL = OWGetProperty(_config,@"imgURL");
45 self->string = OWGetProperty(_config,@"string");
46 self->toolTip = OWGetProperty(_config,@"toolTip");
47 self->value = OWGetProperty(_config,@"value");
53 [self->imgURL release];
54 [self->string release];
55 [self->toolTip release];
56 [self->value release];
62 - (NSString *)imageByFilename:(NSString *)_name
63 inContext:(WOContext *)_ctx
64 framework:(NSString *)_framework
66 WOResourceManager *rm;
70 rm = [[_ctx application] resourceManager];
71 languages = [_ctx resourceLookupLanguages];
72 tmp = [rm urlForResourceNamed:_name
73 inFramework:_framework
75 request:[_ctx request]];
79 - (void)appendToResponse:(WOResponse *)_response
80 inContext:(WOContext *)_ctx
84 NSString *tt; // toolTip
85 WEClientCapabilities *ccaps;
87 comp = [_ctx component];
88 ccaps = [[_ctx request] clientCapabilities];
89 tt = [self->toolTip stringValueInComponent:comp];
92 if (![ccaps isInternetExplorer]) return;
93 if ([ccaps isMacBrowser]) return;
95 tmp = [[NSString alloc] initWithFormat:
96 @"<a href=\"#\" onclick=\"javascript:clipboardData."
97 @"setData('text', '%@');return false;\" title=\"%@\">",
98 [self->value stringValueInComponent:comp], tt];
99 [_response appendContentString:tmp];
100 [tmp release]; tmp = nil;
102 NSAssert(self->imgURL != nil || self->string != nil || self->filename != nil,
103 @"ERROR: no imageURL or string defined...");
105 if (self->filename) {
106 NSString *imageFilename;
109 [self imageByFilename:[self->filename stringValueInComponent:comp]
111 framework:[comp frameworkName]];
113 tmp = [[NSString alloc] initWithFormat:
114 @"<img border=\"0\"src=\"%@\" /></a>",
117 else if (self->imgURL) {
118 tmp = [[NSString alloc] initWithFormat:
119 @"<img border=\"0\"src=\"%@\" /></a>",
120 [self->imgURL stringValueInComponent:comp]];
123 tmp = [[NSString alloc] initWithFormat:
125 [self->string stringValueInComponent:comp]];
127 [_response appendContentString:tmp];
131 @end /* JSClipboard */