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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qtcomponentpeer.cpp --
2
   Copyright (C)  2005  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
#include <assert.h>
39
#include <QApplication>
40
#include <QDesktopWidget>
41
#include <QShowEvent>
42
#include <QHideEvent>
43
#include <QColor>
44
#include <QCursor>
45
#include <QWidget>
46
#include <gnu_java_awt_peer_qt_QtComponentPeer.h>
47
#include "qtcomponent.h"
48
#include "componentevent.h"
49
#include "qtfont.h"
50
 
51
extern QApplication *qApplication;
52
 
53
// Java Cursor types.
54
#define DEFAULT_CURSOR          0
55
#define CROSSHAIR_CURSOR        1
56
#define TEXT_CURSOR             2
57
#define WAIT_CURSOR             3
58
#define SW_RESIZE_CURSOR        4
59
#define SE_RESIZE_CURSOR        5
60
#define NW_RESIZE_CURSOR        6
61
#define NE_RESIZE_CURSOR        7
62
#define N_RESIZE_CURSOR         8
63
#define S_RESIZE_CURSOR         9
64
#define W_RESIZE_CURSOR         10
65
#define E_RESIZE_CURSOR         11
66
#define HAND_CURSOR             12
67
#define MOVE_CURSOR             13
68
 
69
/**
70
 * Call back the init() method from the main thread.
71
 */
72
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_callInit
73
(JNIEnv *env, jobject obj)
74
{
75
  mainThread->postEventToMain( new AWTInitEvent( env, obj ) );
76
}
77
 
78
/*
79
 * Generic disposal.
80
 */
81
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_disposeNative
82
(JNIEnv *env, jobject obj)
83
{
84
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
85
  setNativeObject(env, obj, NULL);
86
  mainThread->postEventToMain( new AWTDestroyEvent( widget ) );
87
}
88
 
89
/**
90
 * Returns the on-screen location of the component.
91
 */
92
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getLocationOnScreenNative
93
(JNIEnv *env, jobject obj, jobject point)
94
{
95
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
96
  assert( widget );
97
  mainThread->postEventToMain( new AWTGetOriginEvent( widget, env, point) );
98
}
99
 
100
/*
101
 * Get the preferred/minimum size of the widget
102
 */
103
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getSizeNative
104
(JNIEnv *env, jobject obj, jobject size, jboolean preferred)
105
{
106
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
107
  assert( widget );
108
 
109
  mainThread->postEventToMain
110
    (new GetSizeEvent( widget, env, size, (preferred == JNI_TRUE)));
111
}
112
 
113
/*
114
 */
115
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isObscured
116
(JNIEnv *env, jobject obj)
117
{
118
  jboolean retVal;
119
 
120
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
121
  assert( widget );
122
 
123
  retVal = (widget->isVisible() == TRUE) ? JNI_TRUE : JNI_FALSE;
124
 
125
  return retVal;
126
}
127
 
128
/*
129
 * Returns whether the widget is focusable or not.
130
 */
131
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isFocusable
132
(JNIEnv *env, jobject obj)
133
{
134
  jboolean retVal;
135
 
136
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
137
  assert( widget );
138
 
139
  retVal = (widget->focusPolicy() != Qt::NoFocus) ? JNI_TRUE : JNI_FALSE;
140
 
141
  return retVal;
142
}
143
 
144
/**
145
 * Requests the focus
146
 */
147
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_requestFocus
148
  (JNIEnv *env, jobject obj)
149
{
150
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
151
  assert( widget );
152
  mainThread->postEventToMain( new AWTReqFocusEvent( widget ) );
153
}
154
 
155
/*
156
 * Sets the size and position. Important.
157
 */
158
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setBoundsNative
159
(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
160
{
161
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
162
  assert( widget );
163
  mainThread->postEventToMain
164
    (new AWTResizeEvent( widget, x, y, width, height ) );
165
}
166
 
167
/*
168
 * Sets the mouse cursor
169
 */
170
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setCursor
171
  (JNIEnv *env, jobject obj, jint cursortype)
172
{
173
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
174
  assert( widget );
175
 
176
  Qt::CursorShape shape;
177
  switch(cursortype)
178
    {
179
    case CROSSHAIR_CURSOR:
180
      shape = Qt::CrossCursor;
181
      break;
182
 
183
    case W_RESIZE_CURSOR:
184
    case E_RESIZE_CURSOR:
185
      shape = Qt::SizeHorCursor;
186
      break;
187
    case N_RESIZE_CURSOR:
188
    case S_RESIZE_CURSOR:
189
      shape = Qt::SizeVerCursor;
190
      break;
191
    case HAND_CURSOR:
192
      shape = Qt::PointingHandCursor;
193
      break;
194
    case MOVE_CURSOR:
195
      shape = Qt::SizeAllCursor;
196
      break;
197
 
198
    case NE_RESIZE_CURSOR:
199
    case SW_RESIZE_CURSOR:
200
      shape = Qt::SizeBDiagCursor;
201
      break;
202
    case NW_RESIZE_CURSOR:
203
    case SE_RESIZE_CURSOR:
204
      shape = Qt::SizeFDiagCursor;
205
      break;
206
    case TEXT_CURSOR:
207
      shape = Qt::IBeamCursor;
208
      break;
209
    case WAIT_CURSOR:
210
      shape = Qt::WaitCursor;
211
      break;
212
 
213
    case DEFAULT_CURSOR:
214
    default:
215
      shape = Qt::ArrowCursor;
216
      break;
217
    }
218
 
219
  mainThread->postEventToMain( new AWTCursorEvent( widget, shape ) );
220
}
221
 
222
/*
223
 * Enable, disable.
224
 */
225
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setEnabled
226
(JNIEnv *env, jobject obj, jboolean state)
227
{
228
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
229
  assert(widget != NULL);
230
 
231
  mainThread->postEventToMain( new AWTEnableEvent( widget, (state == JNI_TRUE) ) );
232
}
233
 
234
/**
235
 * Set the font
236
 */
237
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setFontNative
238
(JNIEnv *env, jobject obj, jobject fontpeer)
239
{
240
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
241
  assert( widget );
242
  QFont *font = (QFont *) getFont( env, fontpeer );
243
  assert( font );
244
 
245
  mainThread->postEventToMain( new AWTFontEvent(widget, font) );
246
}
247
 
248
/*
249
 * Sets the back- or foreground color.
250
 */
251
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setGround
252
(JNIEnv *env, jobject obj, jint r, jint g, jint b, jboolean isForeground)
253
{
254
  QColor *color = new QColor(r, g, b);
255
 
256
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
257
  assert(widget);
258
  mainThread->postEventToMain( new AWTBackgroundEvent(widget,
259
                                                      (isForeground == JNI_TRUE),
260
                                                      color) );
261
}
262
 
263
/*
264
 * Sets the visibility.
265
 */
266
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setVisible
267
(JNIEnv *env, jobject obj, jboolean state)
268
{
269
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
270
  assert(widget != NULL);
271
  mainThread->postEventToMain( new AWTShowEvent( widget, (state == JNI_TRUE) ) );
272
}
273
 
274
/*
275
 * Returns whether the widget handles wheel scrolling.
276
 */
277
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_handlesWheelScrolling
278
(JNIEnv *env, jobject obj)
279
{
280
  jboolean handles = JNI_FALSE;
281
 
282
  QWidget *cb = (QWidget *) getNativeObject( env, obj );
283
  if( cb )
284
    if( cb->focusPolicy() & Qt::WheelFocus )
285
      handles = JNI_TRUE;
286
 
287
  return handles;
288
}
289
 
290
/**
291
 * calls qwidget::update on the compnent.
292
 */
293
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdateArea
294
(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
295
{
296
  QWidget *cb = (QWidget *) getNativeObject( env, obj );
297
  if( cb )
298
    mainThread->postEventToMain( new AWTUpdateEvent
299
                                 (cb, false, x, y, w, h ) );
300
}
301
 
302
/*
303
 * calls qwidget::update on the compnent.
304
 */
305
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdate
306
(JNIEnv *env, jobject obj)
307
{
308
  QWidget *cb = (QWidget *) getNativeObject( env, obj );
309
  if( cb )
310
    mainThread->postEventToMain( new AWTUpdateEvent
311
                                 ( cb, true, 0, 0, 0, 0 ) );
312
}
313
 
314
/*
315
 * Returns the native background color.
316
 */
317
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getNativeBackground
318
(JNIEnv *env, jobject obj)
319
{
320
  QWidget *cb = (QWidget *) getNativeObject( env, obj );
321
  assert(cb);
322
  QColor c = cb->palette().background().color().toRgb();
323
 
324
  jclass cls = env->FindClass("java/awt/Color");
325
  jmethodID mid = env->GetMethodID(cls, "<init>", "(III)V");
326
  jvalue values[3];
327
 
328
  values[0].i = (jint) c.red();
329
  values[1].i = (jint) c.green();
330
  values[2].i = (jint) c.blue();
331
 
332
  return env->NewObjectA(cls, mid, values);
333
}
334
 
335
/*
336
 * Returns which screen the component is on.
337
 */
338
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_whichScreen
339
(JNIEnv *env, jobject obj)
340
{
341
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
342
  assert( widget );
343
  return (jint) qApplication->desktop()->screenNumber( widget );
344
}
345
 
346
/*
347
 * Reparents the widget.
348
 */
349
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_reparentNative
350
(JNIEnv *env, jobject obj, jobject newparent)
351
{
352
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
353
  assert( widget );
354
  QWidget *parentWidget = (QWidget *) getNativeObject( env, newparent );
355
  assert( parentWidget );
356
  mainThread->postEventToMain( new AWTReparent(widget, parentWidget ) );
357
}
358
 
359
/*
360
 * Get the preferred size of the widget
361
 */
362
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getBounds
363
 
364
(JNIEnv *env, jobject obj)
365
{
366
  QWidget *widget = (QWidget *) getNativeObject( env, obj );
367
  assert( widget );
368
 
369
  int x, y, w, h;
370
  widget->geometry().getRect(&x, &y, &w, &h);
371
 
372
  jclass cls = env->FindClass("java/awt/Rectangle");
373
  assert( cls != NULL);
374
  jmethodID mid = env->GetMethodID(cls, "<init>", "(IIII)V");
375
  assert( mid != NULL);
376
  jvalue values[4];
377
 
378
  values[0].i = (jint) x;
379
  values[1].i = (jint) y;
380
  values[2].i = (jint) w;
381
  values[3].i = (jint) h;
382
 
383
  return env->NewObjectA(cls, mid, values);
384
}

powered by: WebSVN 2.1.0

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