summaryrefslogtreecommitdiffstats
path: root/kjsembed/jseventutils.cpp
blob: 2aabf7620a1a5c2503982c798ca75952d2ab5422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
 *  Copyright (C) 2003, Richard J. Moore <rich@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#include "kjsembedpart.h"
#include "jsfactory.h"
#include "jsobjectproxy.h"
#include "jsopaqueproxy.h"
#include "jsbinding.h"

#include "jseventutils.h"

namespace KJSEmbed {

JSFactory *JSEventUtils::factory( const JSObjectProxy *prx )
{
    return prx->part()->factory();
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQMouseEvent *ev, const JSObjectProxy *context )
{
    KJS::Object mev = convertEvent( exec, (TTQEvent *)ev, context);

    mev.put( exec, "pos", convertToValue( exec, TTQVariant(ev->pos()) ) );
    mev.put( exec, "x", KJS::Number(ev->x()) );
    mev.put( exec, "y", KJS::Number(ev->y()) );

    mev.put( exec, "globalPos", convertToValue( exec, TTQVariant(ev->globalPos()) ) );
    mev.put( exec, "globalX", KJS::Number(ev->globalX()) );
    mev.put( exec, "globalY", KJS::Number(ev->globalY()) );

    mev.put( exec, "button", KJS::Number(ev->button()) );
    mev.put( exec, "state", KJS::Number(ev->state()) );
    mev.put( exec, "stateAfter", KJS::Number(ev->stateAfter()) );

    return mev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQPaintEvent *ev, const JSObjectProxy *context )
{
    KJS::Object pev = convertEvent( exec, (TTQEvent *)ev, context);

    pev.put( exec, "rect", convertToValue( exec, TTQVariant(ev->rect()) ) );
    pev.put( exec, "erased", convertToValue( exec, TTQVariant(ev->erased()) ) );
    return pev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQKeyEvent *ev, const JSObjectProxy *context )
{
    KJS::Object kev = convertEvent( exec, (TTQEvent *)ev, context);

    kev.put( exec, "key", KJS::Number(ev->key()) );
    kev.put( exec, "ascii", KJS::Number(ev->ascii()) );
    kev.put( exec, "state", KJS::Number(ev->state()) );
    kev.put( exec, "stateAfter", KJS::Number(ev->stateAfter()) );
    kev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
    kev.put( exec, "text", KJS::String(ev->text()));
    kev.put( exec, "isAutoRepeat", KJS::Boolean(ev->isAutoRepeat()) );
    kev.put( exec, "count", KJS::Number( ev->count()) );
    //kev.put( exec, "accept", KJS::Void( exec, TTQVariant(ev->accept()), context ) );
    //kev.put( exec, "ignore", KJS::Void( exec, TTQVariant(ev->ignore()), context ) );
    return kev;
}
KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQIMEvent *ev, const JSObjectProxy *context )
{
    KJS::Object qev = convertEvent( exec, (TTQEvent *)ev, context);

    qev.put( exec, "text", KJS::String(ev->text()) );
    qev.put( exec, "cursorPos", KJS::Number(ev->cursorPos()) );
    qev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
    //qev.put( exec, "accept", KJS::Void( exec, TTQVariant(ev->accept()), context ) );
    //qev.put( exec, "ignore", KJS::Void( exec, TTQVariant(ev->ignore()), context ) );
    return qev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQResizeEvent *ev, const JSObjectProxy *context )
{
    KJS::Object rev = convertEvent( exec, (TTQEvent *)ev, context);

    rev.put( exec, "size", convertToValue( exec, TTQVariant(ev->size()) ));
    rev.put( exec, "oldSize", convertToValue( exec, TTQVariant(ev->oldSize())  ));
    return rev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQFocusEvent *ev, const JSObjectProxy *context )
{
    KJS::Object fev = convertEvent( exec, (TTQEvent *)ev, context);

    fev.put( exec, "gotFocus", KJS::Boolean(ev->gotFocus()) );
    fev.put( exec, "lostFocus", KJS::Boolean(ev->lostFocus()) );
    return fev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQCloseEvent *ev, const JSObjectProxy *context )
{
    KJS::Object cev = convertEvent( exec, (TTQEvent *)ev, context);

    cev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
    //cev.put( exec, "accept", KJS::Void( exec, TTQVariant(ev->accept()), context ) );
    //cev.put( exec, "ignore", KJS::Void( exec, TTQVariant(ev->ignore()), context ) );
    return cev;
}

#ifdef ENABLE_CHILDEVENTS
KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQChildEvent *ev, const JSObjectProxy *context )
{
    KJS::Object cev = convertEvent( exec, (TTQEvent *)ev, context);

    cev.put( exec, "inserted", KJS::Boolean(ev->inserted()) );
    cev.put( exec, "removed", KJS::Boolean(ev->removed()) );
    cev.put( exec, "child", factory(context)->createProxy( exec, ev->child(), context ) );

    return cev;
}
#endif

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQMoveEvent *ev, const JSObjectProxy *context )
{
    KJS::Object mev = convertEvent( exec, (TTQEvent *)ev, context);

    mev.put( exec, "pos", convertToValue( exec, TTQVariant(ev->pos()) ));
    mev.put( exec, "oldPos", convertToValue( exec, TTQVariant(ev->oldPos()) ));
    return mev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQWheelEvent *ev, const JSObjectProxy *context )
{
    KJS::Object wev = convertEvent( exec, (TTQEvent *)ev, context);

    wev.put( exec, "delta", KJS::Number(ev->delta()) );
    wev.put( exec, "pos", convertToValue( exec, TTQVariant(ev->pos()) ) );
    wev.put( exec, "globalPos", convertToValue( exec, TTQVariant(ev->globalPos()) ) );
    wev.put( exec, "x", KJS::Number(ev->x()) );
    wev.put( exec, "y", KJS::Number(ev->y()) );
    wev.put( exec, "globalX", KJS::Number(ev->globalX()) );
    wev.put( exec, "globalY", KJS::Number(ev->globalY()) );

    wev.put( exec, "state", KJS::Number(ev->state()) );
    wev.put( exec, "orientation", KJS::Number(ev->orientation()) );
    wev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
    //wev.put( exec, "accept", KJS::Void( exec, TTQVariant(ev->accept()), context ) );
    //wev.put( exec, "ignore", KJS::Void( exec, TTQVariant(ev->ignore()), context ) );
    return wev;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
					const TTQEvent *ev, const JSObjectProxy * /*context*/)
{
    KJS::Object evnt( new JSOpaqueProxy(ev) );
    evnt.put( exec, "type", KJS::Number( (int) ev->type()) );
    evnt.put( exec, "spontaneous", KJS::Boolean(ev->spontaneous()) );
    return evnt;
}

KJS::Object JSEventUtils::convertEvent( KJS::ExecState * exec, const TTQDropEvent * ev, const JSObjectProxy * context )
{
	KJS::Object dev = convertEvent( exec, (TTQEvent *)ev, context);
	dev.put( exec, "pos", convertToValue( exec, TTQVariant(ev->pos()) ) );
	dev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
	dev.put( exec, "isActionAccepted", KJS::Boolean(ev->isActionAccepted()) );
	dev.put( exec, "source", factory(context)->createProxy(exec, ev->source(), context) );
	dev.put( exec, "action", KJS::Number( (int)(ev->action()) ) );
	return dev;
} 

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
				const TTQDragMoveEvent *ev, const JSObjectProxy *context )
{
	KJS::Object mev = convertEvent(exec, (TTQDropEvent *)ev, context);
	mev.put( exec, "answerRect", convertToValue( exec, TTQVariant(ev->answerRect()) ) );
	return mev;
} 

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
				const TTQTimerEvent *ev, const JSObjectProxy *context )
{
	KJS::Object dev = convertEvent( exec, (TTQEvent *)ev, context);
	dev.put( exec, "timerId", KJS::Number(ev->timerId()) );
	return dev;
} 

KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec,
				const TTQContextMenuEvent *ev, const JSObjectProxy *context )
{
	KJS::Object cxev = convertEvent( exec, (TTQEvent *)ev, context);
	cxev.put( exec, "x", KJS::Number(ev->x()) );
	cxev.put( exec, "y", KJS::Number(ev->y()) );
	cxev.put( exec, "globalX", KJS::Number(ev->globalX()) );
	cxev.put( exec, "globalY", KJS::Number(ev->globalY()) );
	cxev.put( exec, "pos",convertToValue( exec, TTQVariant(ev->pos()) ) );
	cxev.put( exec, "globalPos", convertToValue( exec, TTQVariant(ev->globalPos()) ) );
	cxev.put( exec, "state", KJS::Number( (int) ev->state()) );
	cxev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) );
	cxev.put( exec, "isConsumed", KJS::Boolean(ev->isConsumed()) );
	cxev.put( exec, "reason", KJS::Number((int)ev->reason()) );
	return cxev;	
} 



}// namespace KJSEmbed