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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qtcheckboxpeer.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 <QAbstractButton>
40
#include <QCheckBox>
41
#include <QRadioButton>
42
#include <gnu_java_awt_peer_qt_QtCheckboxPeer.h>
43
#include "qtstrings.h"
44
#include "qtcomponent.h"
45
#include "keybindings.h"
46
#include "buttonevent.h"
47
#include "slotcallbacks.h"
48
 
49
class CheckboxCheckEvent : public AWTEvent {
50
 
51
 private:
52
  QAbstractButton *widget;
53
  bool checked;
54
 
55
 public:
56
  CheckboxCheckEvent(QAbstractButton *w, bool c)
57
  {
58
    widget = w;
59
    checked = c;
60
  }
61
 
62
  void runEvent()
63
  {
64
    if (checked != widget->isChecked())
65
      widget->setChecked( checked );
66
  }
67
};
68
 
69
class MyCheckBox : public QCheckBox
70
{
71
public:
72
  MyCheckBox(JNIEnv *env, jobject obj, QWidget *parent) : QCheckBox( parent )
73
  {
74
    setup(env, obj);
75
  }
76
 
77
  ~MyCheckBox()
78
  {
79
    destroy();
80
  }
81
 
82
#define I_KNOW_WHAT_IM_DOING
83
#define PARENT QCheckBox
84
#include "eventmethods.h"
85
};
86
 
87
/**
88
 * Determines whether the darn native object should be a radio button or not
89
 */
90
static bool isRadioButton( JNIEnv *env, jobject obj )
91
{
92
  jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtCheckboxPeer" );
93
  jfieldID field = env->GetFieldID( cls, "group", "Ljava/awt/CheckboxGroup;" );
94
  if (env->GetObjectField( obj, field ) != NULL)
95
    return true;
96
  return false;
97
}
98
 
99
/**
100
 * Construct the native object.
101
 */
102
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_init
103
(JNIEnv *env, jobject obj)
104
{
105
  QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
106
 
107
  QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
108
  if (cb)
109
    delete cb;
110
 
111
  bool radioButton;
112
  {
113
    jclass cls = env->GetObjectClass( obj );
114
    jfieldID field = env->GetFieldID( cls, "owner", "Ljava/awt/Component;" );
115
    assert(field != NULL);
116
    jobject owner = env->GetObjectField( obj, field );
117
    assert(owner != NULL);
118
    cls = env->GetObjectClass( owner );
119
    jmethodID method = env->GetMethodID( cls,
120
                                         "getCheckboxGroup",
121
                                         "()Ljava/awt/CheckboxGroup;" );
122
    assert(method != NULL);
123
    jobject group = env->CallObjectMethod( owner, method, 0);
124
    radioButton = (group != NULL);
125
  }
126
 
127
  if(radioButton)
128
    cb = new QRadioButton( parentWidget );
129
  else
130
    cb = new QCheckBox( parentWidget );
131
  //    cb = new MyCheckBox( env, obj, parentWidget );
132
  assert( cb );
133
 
134
  connectToggle(cb, env, obj); // connect the native event.
135
 
136
  setNativeObject( env, obj, cb );
137
}
138
 
139
/*
140
 * Sets the checkbox label.
141
 */
142
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setLabel
143
(JNIEnv *env, jobject obj, jstring label)
144
{
145
  /* Both QCheckbox and QRadioButton inherit QAbstractButton */
146
  QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
147
  assert( cb );
148
 
149
  QString *qStr = getQString(env, label);
150
  mainThread->postEventToMain( new AWTLabelEvent( cb, qStr ) );
151
  // AWTLabelEvent takes care of disposal of qStr
152
}
153
 
154
/*
155
 * Sets the checkbox state.
156
 */
157
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setState
158
(JNIEnv *env, jobject obj, jboolean state)
159
{
160
  QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
161
  assert( cb );
162
  mainThread->postEventToMain( new CheckboxCheckEvent( cb, (state == JNI_TRUE) ) );
163
}
164
 

powered by: WebSVN 2.1.0

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