Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / native / jni / qt-peer / componentevent.cpp
blobae88af01929b63dcee0bcf1ae10ace28a3076294
1 /* componentevent.cpp --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
38 #include <assert.h>
39 #include <QWidget>
40 #include <QPoint>
42 #include "componentevent.h"
44 AWTInitEvent::AWTInitEvent(JNIEnv *env, jobject obj) : AWTEvent()
46 env->GetJavaVM( &vm );
47 target = env->NewGlobalRef( obj );
50 void AWTInitEvent::runEvent()
52 JNIEnv *env;
53 vm->GetEnv((void **)&env, JNI_VERSION_1_1);
54 jclass targetCls = env->GetObjectClass( target );
55 // call init()
56 jmethodID mID = env->GetMethodID( targetCls,
57 "init",
58 "()V" );
59 env->CallVoidMethod( target, mID );
61 // call notify()
62 mID = env->GetMethodID( targetCls,
63 "notify",
64 "()V" );
65 assert(mID != NULL);
66 env->MonitorEnter( target );
67 env->CallVoidMethod( target, mID );
68 env->MonitorExit( target );
70 env->DeleteGlobalRef( target );
73 AWTShowEvent::AWTShowEvent(QWidget *w, bool v) : AWTEvent()
75 widget = w;
76 visible = v;
79 void AWTShowEvent::runEvent()
81 widget->setVisible( visible );
84 AWTEnableEvent::AWTEnableEvent(QWidget *w, bool v) : AWTEvent()
86 widget = w;
87 enabled = v;
90 void AWTEnableEvent::runEvent()
92 widget->setEnabled( enabled );
95 AWTCursorEvent::AWTCursorEvent(QWidget *w, Qt::CursorShape s) : AWTEvent()
97 widget = w;
98 shape = s;
101 void AWTCursorEvent::runEvent()
103 QCursor *s = new QCursor(shape);
104 widget->setCursor( *s );
107 AWTResizeEvent::AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0)
109 widget = wid;
110 x = x0; y = y0;
111 w = w0; h = h0;
112 if(w == 0 && h == 0) w = h = 10;
115 void AWTResizeEvent::runEvent()
117 QRect g = widget->geometry();
118 if(g.x() != x || g.y() != y || g.width() != w || g.height() != h)
119 widget->setGeometry( x, y, w, h );
122 AWTBackgroundEvent::AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr)
124 widget = wid;
125 foreground = fg;
126 color = clr;
129 void AWTBackgroundEvent::runEvent()
131 QPalette p = widget->palette();
132 if (foreground)
134 p.setColor(QPalette::Active, QPalette::Foreground, *color);
135 p.setColor(QPalette::Active, QPalette::Text, *color);
137 else
139 p.setColor(QPalette::Active, QPalette::Background, *color);
140 p.setColor(QPalette::Active, QPalette::Button, *color);
141 p.setColor(QPalette::Active, QPalette::Base, *color);
142 p.setColor(QPalette::Active, QPalette::AlternateBase, *color);
144 widget->setPalette(p);
145 widget->repaint();
146 delete color;
149 AWTGetOriginEvent::AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj) : AWTEvent()
151 widget = w;
152 env->GetJavaVM( &vm );
153 target = env->NewGlobalRef( obj );
156 void AWTGetOriginEvent::runEvent()
158 JNIEnv *env;
159 vm->GetEnv((void **)&env, JNI_VERSION_1_1);
160 jclass targetCls = env->GetObjectClass( target );
162 QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
163 // call init()
164 jmethodID mID = env->GetMethodID( targetCls,
165 "setLocation",
166 "(II)V" );
167 env->CallVoidMethod( target, mID, p->x(), p->y() );
168 delete p;
170 // call notify()
171 mID = env->GetMethodID( targetCls,
172 "notify",
173 "()V" );
174 assert(mID != NULL);
175 env->MonitorEnter( target );
176 env->CallVoidMethod( target, mID );
177 env->MonitorExit( target );
179 env->DeleteGlobalRef( target );
182 GetSizeEvent::GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p) : AWTEvent()
184 widget = w;
185 env->GetJavaVM( &vm );
186 target = env->NewGlobalRef( obj );
187 pref = p;
190 void GetSizeEvent::runEvent()
192 JNIEnv *env;
193 vm->GetEnv((void **)&env, JNI_VERSION_1_1);
194 jclass targetCls = env->GetObjectClass( target );
196 QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
197 QSize s;
198 if( pref )
199 s = widget->sizeHint();
200 else
201 s = widget->minimumSizeHint();
203 // call init()
204 jmethodID mID = env->GetMethodID( targetCls,
205 "setSize",
206 "(II)V" );
207 env->CallVoidMethod( target, mID, s.width(), s.height() );
209 // call notify()
210 mID = env->GetMethodID( targetCls,
211 "notify",
212 "()V" );
213 assert(mID != NULL);
214 env->MonitorEnter( target );
215 env->CallVoidMethod( target, mID );
216 env->MonitorExit( target );
218 env->DeleteGlobalRef( target );