1 |
769 |
jeremybenn |
/* GtkGenericPeer.java - Has a hashcode. Yuck.
|
2 |
|
|
Copyright (C) 1998, 1999, 2002, 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 |
|
|
|
39 |
|
|
package gnu.java.awt.peer.gtk;
|
40 |
|
|
|
41 |
|
|
import java.awt.EventQueue;
|
42 |
|
|
import java.awt.Font;
|
43 |
|
|
import java.awt.Toolkit;
|
44 |
|
|
import java.awt.event.ActionEvent;
|
45 |
|
|
|
46 |
|
|
import gnu.classpath.Pointer;
|
47 |
|
|
|
48 |
|
|
public class GtkGenericPeer
|
49 |
|
|
{
|
50 |
|
|
// Used by Native State Association (NSA) functions to map
|
51 |
|
|
// gtk_widget to peer object.
|
52 |
|
|
final int native_state = getUniqueInteger ();
|
53 |
|
|
|
54 |
|
|
// Next native state value we will assign.
|
55 |
|
|
private static int next_native_state = 0;
|
56 |
|
|
|
57 |
|
|
// The widget or other java-side object we wrap.
|
58 |
|
|
protected final Object awtWidget;
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* The pointer to the native GTK widget.
|
62 |
|
|
*
|
63 |
|
|
* This field is manipulated by native code. Don't change or remove
|
64 |
|
|
* without adjusting the native code.
|
65 |
|
|
*/
|
66 |
|
|
private Pointer widget;
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* The pointer to the global reference to this object. The native
|
70 |
|
|
* code creates a JNI global reference of the peer object to be able
|
71 |
|
|
* to pass it to the event callbacks. It gets stored here, so that
|
72 |
|
|
* we can later delete it in the dispose() method.
|
73 |
|
|
*
|
74 |
|
|
* This field is manipulated by native code. Don't change or remove
|
75 |
|
|
* without adjusting the native code.
|
76 |
|
|
*/
|
77 |
|
|
private Pointer globalRef;
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* We initialize the field IDs that are used by native code here because
|
81 |
|
|
* these remain valid until a class gets unloaded.
|
82 |
|
|
*/
|
83 |
|
|
static
|
84 |
|
|
{
|
85 |
|
|
GtkToolkit.initializeGlobalIDs();
|
86 |
|
|
initIDs();
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Initializes the field IDs that are used by the native code.
|
91 |
|
|
*/
|
92 |
|
|
private static native void initIDs();
|
93 |
|
|
|
94 |
|
|
/**
|
95 |
|
|
* Dispose of our native state. Calls gtk_widget_destroy on the
|
96 |
|
|
* native widget and removes the awtWidget from the native state
|
97 |
|
|
* tables. Should be overridden by subclasses if this is not (all)
|
98 |
|
|
* that needs to be done.
|
99 |
|
|
*/
|
100 |
|
|
public native void dispose ();
|
101 |
|
|
|
102 |
|
|
static EventQueue q ()
|
103 |
|
|
{
|
104 |
|
|
return Toolkit.getDefaultToolkit ().getSystemEventQueue ();
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
protected GtkGenericPeer (Object awtWidget)
|
108 |
|
|
{
|
109 |
|
|
this.awtWidget = awtWidget;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
protected void postActionEvent (String command, int mods)
|
113 |
|
|
{
|
114 |
|
|
q().postEvent (new ActionEvent (awtWidget, ActionEvent.ACTION_PERFORMED,
|
115 |
|
|
command, mods));
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
// Return a unique integer for use in the native state mapping
|
119 |
|
|
// code. We can't use a hash code since that is not guaranteed to
|
120 |
|
|
// be unique.
|
121 |
|
|
static synchronized int getUniqueInteger ()
|
122 |
|
|
{
|
123 |
|
|
// Let's assume this will never wrap.
|
124 |
|
|
return next_native_state++;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
/**
|
128 |
|
|
* Helper method to set Font for Gtk Widget.
|
129 |
|
|
*/
|
130 |
|
|
protected void gtkWidgetModifyFont(Font f)
|
131 |
|
|
{
|
132 |
|
|
gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/**
|
136 |
|
|
* Sets font for this Gtk Widget. Should be overridden by peers which
|
137 |
|
|
* are composed of different widgets or are contained in bins.
|
138 |
|
|
*/
|
139 |
|
|
protected native void gtkWidgetModifyFont(String name, int style, int size);
|
140 |
|
|
|
141 |
|
|
static void printCurrentThread ()
|
142 |
|
|
{
|
143 |
|
|
System.out.println ("gtkgenericpeer, thread: " + Thread.currentThread ());
|
144 |
|
|
}
|
145 |
|
|
}
|