OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [qt-peer/] [eventmethods.h] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* eventmethods.cpp --
2
   Copyright (C)  2005, 2006  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
#ifdef I_KNOW_WHAT_IM_DOING
39
 
40
bool draw;
41
 
42
private:
43
  JavaVM* vm;
44
  jobject target;
45
  jclass componentCls;
46
 
47
  void setup(JNIEnv *env, jobject obj)
48
  {
49
    env->GetJavaVM(&vm);
50
    componentCls = NULL;
51
    target = env->NewGlobalRef(obj);
52
    componentCls = (jclass)env->NewGlobalRef(env->GetObjectClass( target ));
53
    setMouseTracking( true );
54
    draw = true;
55
  }
56
 
57
  void destroy()
58
  {
59
    JNIEnv *env;
60
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
61
    env->DeleteGlobalRef(target);
62
    env->DeleteGlobalRef(componentCls);
63
  }
64
 
65
  void callVoidMethod(const char *methodName)
66
  {
67
    JNIEnv *env;
68
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
69
    jmethodID fireEventID = env->GetMethodID( componentCls,
70
                                              methodName,
71
                                              "()V" );
72
    env->CallVoidMethod( target, fireEventID );
73
  }
74
 
75
  void callMouseMethod(const char *methodName,
76
                       int modifiers, int x, int y, int clickCount)
77
  {
78
    JNIEnv *env;
79
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
80
    jmethodID fireEventID = env->GetMethodID( componentCls,
81
                                              methodName,
82
                                              "(IIII)V" );
83
    env->CallVoidMethod( target, fireEventID, modifiers, x, y, clickCount );
84
  }
85
 
86
protected:
87
 
88
  void closeEvent( QCloseEvent *e )
89
  {
90
    PARENT::closeEvent(e);
91
    callVoidMethod("closeEvent");
92
  }
93
 
94
  void focusInEvent( QFocusEvent *e )
95
  {
96
    PARENT::focusInEvent(e);
97
    callVoidMethod("focusInEvent");
98
  }
99
 
100
  void focusOutEvent( QFocusEvent *e )
101
  {
102
    PARENT::focusOutEvent(e);
103
    callVoidMethod("focusOutEvent");
104
  }
105
 
106
  void enterEvent( QEvent *e )
107
  {
108
    PARENT::enterEvent(e);
109
    QPoint p = mapFromGlobal( QCursor::pos() );
110
    int modifiers = getKeyModifiers( QApplication::keyboardModifiers() );
111
    callMouseMethod("enterEvent", modifiers, p.x(), p.y(), 0);
112
  }
113
 
114
  void keyPressEvent( QKeyEvent *e )
115
  {
116
    PARENT::keyPressEvent(e);
117
    int modifiers, x, y;
118
    modifiers = getKeyModifiers(e->modifiers());
119
    x = mapKeyCode(e);
120
    y = getUnicode(e);
121
    callMouseMethod("keyPressEvent", modifiers, x, y, 0);
122
  }
123
 
124
  void keyReleaseEvent( QKeyEvent *e )
125
  {
126
    PARENT::keyReleaseEvent(e);
127
    int modifiers, x, y;
128
    modifiers = getKeyModifiers(e->modifiers());
129
    x = mapKeyCode(e);
130
    y = getUnicode(e);
131
    callMouseMethod("keyReleaseEvent", modifiers, x, y, 0);
132
  }
133
 
134
  void leaveEvent( QEvent *e )
135
  {
136
    PARENT::leaveEvent(e);
137
    QPoint p = mapFromGlobal( QCursor::pos() );
138
    int modifiers = getKeyModifiers( QApplication::keyboardModifiers() );
139
    callMouseMethod("leaveEvent", modifiers, p.x(), p.y(), 0);
140
  }
141
 
142
  void mouseDoubleClickEvent( QMouseEvent *e )
143
  {
144
    PARENT::mouseDoubleClickEvent(e);
145
    int modifiers, x, y, clickCount;
146
    clickCount = 2;
147
    modifiers = getMouseModifiers(e);
148
    x = e->x();
149
    y = e->y();
150
    callMouseMethod("mouseDoubleClickEvent", modifiers, x, y, clickCount);
151
  }
152
 
153
  void mouseMoveEvent( QMouseEvent *e )
154
  {
155
    PARENT::mouseMoveEvent(e);
156
    int modifiers, x, y, clickCount;
157
    clickCount = 0;
158
    modifiers = getMouseModifiers(e);
159
    x = e->x();
160
    y = e->y();
161
    callMouseMethod("mouseMoveEvent", modifiers, x, y, clickCount);
162
  }
163
 
164
  void mousePressEvent( QMouseEvent *e )
165
  {
166
    PARENT::mousePressEvent(e);
167
    int modifiers, x, y, clickCount;
168
    clickCount = 0;
169
    modifiers = getMouseModifiers(e);
170
    x = e->x();
171
    y = e->y();
172
    callMouseMethod("mousePressEvent", modifiers, x, y, clickCount);
173
  }
174
 
175
  void mouseReleaseEvent( QMouseEvent *e )
176
  {
177
    PARENT::mouseReleaseEvent(e);
178
    int modifiers, x, y, clickCount;
179
    modifiers = 0;
180
 
181
    modifiers |= getReleaseModifiers( e );
182
    x = e->x();
183
    y = e->y();
184
    callMouseMethod("mouseReleaseEvent", modifiers, x, y, 0);
185
  }
186
 
187
  void moveEvent( QMoveEvent *e )
188
  {
189
    PARENT::moveEvent(e);
190
    callMouseMethod("moveEvent", e->pos().x(), e->pos().y(),
191
                    e->oldPos().x(), e->oldPos().y());
192
  }
193
 
194
  void resizeEvent( QResizeEvent *e )
195
  {
196
    PARENT::resizeEvent(e);
197
    callMouseMethod("resizeEvent",
198
                    e->oldSize().width(), e->oldSize().height(),
199
                    e->size().width(), e->size().height());
200
  }
201
 
202
  void hideEvent( QHideEvent *e )
203
  {
204
    PARENT::hideEvent(e);
205
    callVoidMethod("hideEvent");
206
  }
207
 
208
  void showEvent( QShowEvent *e )
209
  {
210
    PARENT::showEvent(e);
211
    callVoidMethod("showEvent");
212
  }
213
 
214
  void paintEvent ( QPaintEvent * e )
215
  {
216
    PARENT::paintEvent( e );
217
    if ( draw )
218
      {
219
        // Create a QPainter
220
        GraphicsPainter painter( this );
221
        int x, y, w, h;
222
        e->rect().getRect ( &x, &y, &w, &h );
223
 
224
        // Get the environment.
225
        JNIEnv *env;
226
        vm->GetEnv((void **)&env, JNI_VERSION_1_1);
227
 
228
        // create a QtGraphics wrapper for the QPainter
229
        jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtComponentGraphics" );
230
        jmethodID mid = env->GetMethodID(cls, "<init>", "(JLgnu/java/awt/peer/qt/QtComponentPeer;IIII)V");
231
        jobject graphics = env->NewObject(cls, mid, (jlong)&painter, target,
232
                                          (jint)x, (jint)y, (jint)w, (jint)h);
233
 
234
        // call QtComponentPeer.paintEvent()
235
        jmethodID paintEventID = env->GetMethodID( componentCls,
236
                                                   "paint",
237
                                                   "(Ljava/awt/Graphics;)V" );
238
        env->CallVoidMethod( target, paintEventID, graphics );
239
        env->DeleteLocalRef( cls );
240
        env->DeleteLocalRef( graphics );
241
        painter.end();
242
      }
243
  }
244
 
245
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.