Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/motif')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh59
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/gnome.c153
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc509
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/library.c32
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak86
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/make_solaris.mak69
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.c1364
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.h459
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c7899
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/libswt-gnome0105.sobin0 -> 4713 bytes
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/libswt0105.sobin0 -> 1825715 bytes
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java197
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java154
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java434
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java24
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java164
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java321
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java47
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java1367
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java17
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java872
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java79
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java71
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/GNOME.java18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java54
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java1250
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/Visual.java16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XAnyEvent.java11
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XButtonEvent.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCharStruct.java16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XColor.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XConfigureEvent.java16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCrossingEvent.java19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XEvent.java15
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XExposeEvent.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFocusChangeEvent.java18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFontStruct.java36
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XGCValues.java33
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XImage.java25
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XInputEvent.java10
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XKeyEvent.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XMotionEvent.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XRectangle.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XSetWindowAttributes.java25
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowAttributes.java31
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowChanges.java15
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowEvent.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmAnyCallbackStruct.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDragProcCallback.java21
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropFinishCallback.java19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropProcCallback.java21
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextBlockRec.java13
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct.java16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XtWidgetGeometry.java15
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/AbstractTreeItem.java318
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java631
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java212
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java402
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java525
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java1196
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java439
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java1813
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java544
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java296
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java324
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java220
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java1401
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java254
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java870
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyle.java91
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyles.java133
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java246
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Header.java336
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java408
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java1584
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java648
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java705
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java319
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java262
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java227
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java300
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java558
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java217
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItem.java320
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItemWidget.java2027
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java865
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java406
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabFolder.java885
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabItem.java337
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Table.java2361
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableColumn.java461
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableItem.java1032
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java1261
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java211
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java31
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java763
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java193
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tree.java1469
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeItem.java1146
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeRoots.java157
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java725
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java121
102 files changed, 46444 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh
new file mode 100755
index 0000000000..f0cbe6f358
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh
@@ -0,0 +1,59 @@
+#!/bin/csh
+# (c) Copyright IBM Corp 1999, 2000
+# This command script can be invoked with the "clean" argument.
+
+# The major and minor version numbers and the build numbers are returned by the
+# getSharedLibraryMajorVersionNumber and getSharedLibraryMinorVersionNumber
+# calls so java can query the swt shared library version number
+
+setenv MAJOR_VER 0
+setenv MINOR_VER 105
+setenv BUILD_NUM 0
+
+# Some UNIX/Linux compilers don't like <CR>'s in files (DOS format).
+set fixup_files = `grep -l "\ " *.[ch]`
+if ( "$fixup_files" != "" ) then
+ echo "Converting files from DOS to UNIX format:"
+ foreach file ($fixup_files)
+ echo " $file"
+ ex $file << EOF >& /dev/null
+g/ \$/s///
+w
+EOF
+ end
+endif
+
+# Determine the operating system being built
+set OS=`uname -s`
+switch ($OS )
+
+ case Linux:
+ if ( "$1" == "clean" ) then
+ make -f make_linux.mak clean
+ else
+ echo "Building Linux version of SWT and GNOME DLLs."
+ make -f make_linux.mak make_swt make_gnome
+
+ set build_kde = `rpm -q kdebase | grep "not installed"`
+ set build_kde = "not ported" # KDE porting not complete yet (KJC)
+ if ( "$build_kde" == "" ) then
+ echo "Building Linux version of KDE DLL."
+ make -f make_linux.mak make_kde
+ endif
+ endif
+ breaksw
+
+ case SunOS:
+ if ( "$1" == "clean" ) then
+ make -f make_solaris.mak clean
+ else
+ echo "Building Solaris version of SWT and CDE DLLs."
+ make -f make_solaris.mak make_swt
+ # KJC make -f make_solaris.mak make_cde
+ endif
+ breaksw
+
+ default:
+ echo "Unknown"
+ breaksw
+endsw
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/gnome.c b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/gnome.c
new file mode 100755
index 0000000000..89ce255fad
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/gnome.c
@@ -0,0 +1,153 @@
+/**
+ * SWT GNOME natives implementation.
+ */
+
+/* #define PRINT_FAILED_RCODES */
+#define NDEBUG
+
+#include "globals.h"
+#include "structs.h"
+
+#include <stdio.h>
+#include <assert.h>
+#include <gnome.h>
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: g_1get_1home_1dir
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_GNOME_g_1get_1home_1dir
+ (JNIEnv *env, jclass that)
+{
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "g_1get_1home_1dir\n");
+#endif
+ rc = (jint) g_get_home_dir();
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1datadir_1file
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1datadir_1file
+ (JNIEnv * env, jclass that, jbyteArray fileName)
+{
+ jbyte *fileName1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1datadir_1file\n");
+#endif
+
+ if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
+ rc = (jint) gnome_datadir_file(fileName1);
+ if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1desktop_1entry_1load
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1desktop_1entry_1load
+ (JNIEnv * env, jclass that, jbyteArray fileName)
+{
+ jbyte *fileName1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1desktop_1entry_1load\n");
+#endif
+
+ if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
+ rc = (jint) gnome_desktop_entry_load(fileName1);
+ if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1desktop_1entry_1free
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1desktop_1entry_1free
+ (JNIEnv * env, jclass that, jint entry)
+{
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1desktop_1entry_1free\n");
+#endif
+
+ gnome_desktop_entry_free((GnomeDesktopEntry*)entry);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1mime_1get_1value
+ * Signature: ([B[B)I
+ */
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1mime_1get_1value
+ (JNIEnv *env, jclass that, jbyteArray mimeType, jbyteArray key)
+{
+ jbyte *mimeType1 = NULL;
+ jbyte *key1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1mime_1get_1value\n");
+#endif
+
+ if (mimeType) mimeType1 = (*env)->GetByteArrayElements(env, mimeType, NULL);
+ if (key) key1 = (*env)->GetByteArrayElements(env, key, NULL);
+ rc = (jint) gnome_mime_get_value(mimeType1, key1);
+ if (mimeType) (*env)->ReleaseByteArrayElements(env, mimeType, mimeType1, 0);
+ if (key) (*env)->ReleaseByteArrayElements(env, key, key1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1mime_1type
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1mime_1type
+ (JNIEnv *env, jclass that, jbyteArray fileName)
+{
+ jbyte *fileName1 = NULL;
+ const char* rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1mime_1type\n");
+#endif
+
+ if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
+ rc = gnome_mime_type(fileName1);
+ if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
+ return (jint) rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_GNOME
+ * Method: gnome_1pixmap_1file
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_GNOME_gnome_1pixmap_1file
+ (JNIEnv * env, jclass that, jbyteArray fileName)
+{
+ jbyte *fileName1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "gnome_1pixmap_1file\n");
+#endif
+
+ if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
+ rc = (jint) gnome_pixmap_file(fileName1);
+ if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
+ return rc;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc
new file mode 100755
index 0000000000..374593b370
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc
@@ -0,0 +1,509 @@
+/**
+ * SWT KDE natives implementation.
+ */
+
+/* #define PRINT_FAILED_RCODES */
+#define NDEBUG
+
+#include <stdio.h>
+#include "jni.h"
+
+#include <kapp.h>
+#include <kservice.h>
+#include <kmimetype.h>
+#include <kuserprofile.h>
+#include <kurl.h>
+#include <qstring.h>
+
+extern "C" {
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KApplication_1new
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KApplication_1new
+ (JNIEnv *env, jclass that, int appName)
+{
+ int myArgc = 0;
+ char* myArgv[1];
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KApplication_1new\n");
+#endif
+ QCString qcString = *((QCString*) appName);
+ KApplication* app = new KApplication(myArgc, myArgv, qcString);
+ return (jint) app;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KGlobal_1iconLoader
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KGlobal_1iconLoader
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KGlobal_1iconLoader\n");
+#endif
+ return (jint) KGlobal::iconLoader();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KIconLoader_1iconPath
+ * Signature: (IIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KIconLoader_1iconPath
+ (JNIEnv *env, jclass that, jint receiver, jint iconQString, jint iconType, jint canReturnNull)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KIconLoader_1iconPath\n");
+#endif
+ KIconLoader* loader = (KIconLoader*) receiver;
+ QString iconName = *((QString*) iconQString);
+ QString iconPath = loader->iconPath(iconName, iconType, canReturnNull);
+ if (iconPath == 0) return 0;
+ QString* answer = new QString();
+ *answer = iconPath;
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeType_1findByURL
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1findByURL
+ (JNIEnv *env, jclass that, jint kurl)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeType_1findByURL\n");
+#endif
+ KURL url = *((KURL*) kurl);
+ KSharedPtr<KMimeType>* mimeType = new KSharedPtr<KMimeType>();
+ *mimeType = KMimeType::findByURL(url);
+ return (jint) mimeType;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeType_1icon
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1icon
+ (JNIEnv *env, jclass that, jint receiver, jint unused1, jint unused2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeType_1icon\n");
+#endif
+ KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) receiver);
+ QString* answer = new QString();
+ *answer = mimeType->icon((const QString&) NULL, 0);
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeType_1name
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1name
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeType_1name\n");
+#endif
+ KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) receiver);
+ QString* answer = new QString();
+ *answer = mimeType->name();
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1allServices
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1allServices
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1allServices\n");
+#endif
+ KService::List* pointer = new KService::List();
+ *pointer = KService::allServices();
+ return (jint) pointer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1exec
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1exec
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1exec\n");
+#endif
+ KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
+ QString* answer = new QString();
+ *answer = service->exec();
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1icon
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1icon
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1icon\n");
+#endif
+ KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
+ QString* answer = new QString();
+ *answer = service->icon();
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1name
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1name
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1name\n");
+#endif
+ KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
+ QString* answer = new QString();
+ *answer = service->name();
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1serviceByName
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1serviceByName
+ (JNIEnv *env, jclass that, jint serviceName)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1serviceByName\n");
+#endif
+ QString* name = (QString*) serviceName;
+ KSharedPtr<KService> service = KService::serviceByName(*name);
+ if (service == 0) return 0;
+ KSharedPtr<KService>* pointer = new KSharedPtr<KService>();
+ *pointer = service;
+ return (jint) pointer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KService_1type
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1type
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KService_1type\n");
+#endif
+ KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
+ QString* answer = new QString();
+ *answer = service->type();
+ return (jint) answer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceTypeProfile_1preferredService
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceTypeProfile_1preferredService
+ (JNIEnv *env, jclass that, jint mimeTypeQString, jint needApp)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceTypeProfile_1preferredService\n");
+#endif
+ QString mimeTypeName = *((QString*) mimeTypeQString);
+ KSharedPtr<KService> service = KServiceTypeProfile::preferredService(mimeTypeName, needApp);
+ if (service == 0) return 0;
+ KSharedPtr<KService>* pointer = new KSharedPtr<KService>();
+ *pointer = service;
+ return (jint) pointer;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KURL_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1delete
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KURL_1delete\n");
+#endif
+ delete (KURL*) receiver;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KURL_1new
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1new
+ (JNIEnv *env, jclass that, jint qString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KURL_1new\n");
+#endif
+ QString urlString = *((QString*) qString);
+ return (jint) new KURL(urlString);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceList_1begin
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1begin
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceList_1begin\n");
+#endif
+ KService::List *list= (KService::List*) receiver;
+ QValueListConstIterator<KService::Ptr>* beginning = new QValueListConstIterator<KService::Ptr>();
+ *beginning = list->begin();
+ return (jint) beginning;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceList_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1delete
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceList_1delete\n");
+#endif
+ delete (KService::List*) receiver;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceList_1end
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1end
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceList_1end\n");
+#endif
+ KService::List *list = (KService::List*) receiver;
+ QValueListConstIterator<KService::Ptr>* end = new QValueListConstIterator<KService::Ptr>();
+ *end = list->end();
+ return (jint) end;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QCString_1data
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1data
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QCString_1data\n");
+#endif
+ return (jint) ((QCString*) receiver)->data();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QCString_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1delete
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QCString_1delete\n");
+#endif
+ delete (QCString*) receiver;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QCString_1new
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1new
+ (JNIEnv *env, jclass that, jbyteArray text)
+{
+ jbyte *text1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QCString_1new\n");
+#endif
+ if (text) text1 = env->GetByteArrayElements(text, NULL);
+ QCString* qcString = new QCString((char*) text1);
+ if (text) env->ReleaseByteArrayElements(text, text1, 0);
+ return (jint) qcString;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QString_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1delete
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QString_1delete\n");
+#endif
+ delete (QString*) receiver;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QString_1equals
+ * Signature: (I[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1equals
+ (JNIEnv *env, jclass that, jint receiver, jint object)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QString_1equals\n");
+#endif
+ return *((QString*) receiver) == *((QString*) object);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QString_1new
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1new
+ (JNIEnv *env, jclass that, jbyteArray text)
+{
+ jbyte *text1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QString_1new\n");
+#endif
+ if (text) text1 = env->GetByteArrayElements(text, NULL);
+ QString* qString = new QString((char*) text1);
+ if (text) env->ReleaseByteArrayElements(text, text1, 0);
+ return (jint) qString;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QString_1utf8
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1utf8
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QString_1utf8\n");
+#endif
+ QString string = *((QString*) receiver);
+ QCString* qcString = new QCString();
+ *qcString = string.utf8();
+ return (jint) qcString;
+}
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceListIterator_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1delete
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceListIterator_1delete\n");
+#endif
+ delete (QValueListIterator<KService::Ptr>*) receiver;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceListIterator_1dereference
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1dereference
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceListIterator_1dereference\n");
+#endif
+ KSharedPtr<KService>* service = new KSharedPtr<KService>();
+ *service = *(*((QValueListIterator<KService::Ptr>*) receiver));
+ return (jint) service;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceListIterator_1increment
+ * Signature: (I)I
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1increment
+ (JNIEnv *env, jclass that, jint receiver)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceListIterator_1increment\n");
+#endif
+ ++(*((QValueListIterator<KService::Ptr>*) receiver));
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceListIterator_1new
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1new
+ (JNIEnv *env, jclass that, jint listBeginning)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceListIterator_1new\n");
+#endif
+ const QValueListIterator<KService::Ptr> *iterator =
+ (const QValueListIterator<KService::Ptr> *) listBeginning;
+
+ return (jint) new QValueListIterator<KService::Ptr>(*iterator);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KServiceListIterator_1equals
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1equals
+ (JNIEnv *env, jclass that, jint receiver, jint object)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KServiceListIterator_1equals\n");
+#endif
+ return *((QValueListIterator<KService::Ptr>*) receiver) ==
+ *((QValueListIterator<KService::Ptr>*) object);
+}
+
+
+} /* extern "C" */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/library.c b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/library.c
new file mode 100755
index 0000000000..9a2a6e8b8e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/library.c
@@ -0,0 +1,32 @@
+/**
+ * library.c
+ *
+ * This file contains the implementation of the
+ * shared libraries functions.
+ *
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+unsigned int OpenLibrary(char *name)
+{
+ void * handle = dlopen (name, RTLD_LAZY | RTLD_GLOBAL);
+ if (handle == NULL) {
+ char buf[512];
+ sprintf(buf, "lib%s.so", name);
+ handle = dlopen (buf, 1);
+ }
+ return (unsigned int)handle;
+}
+
+unsigned int LibraryLookupName(unsigned int handle, char *name)
+{
+ if (handle == 0) return 0;
+ return (unsigned int)dlsym ((void *)handle, name);
+}
+
+void CloseLibrary(unsigned int handle)
+{
+ if (handle != 0) dlclose ((void *)handle);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak
new file mode 100755
index 0000000000..8a0c7a8c99
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak
@@ -0,0 +1,86 @@
+# Makefile for creating SWT libraries on Linux
+#
+# The following environment variables are assumed to be defined:
+#
+# MAJOR_VER - the major version number
+# MINOR_VER - the minor version number
+# BUILD_NUM - the build number
+
+DLL_VERSION=$(MAJOR_VER)$(MINOR_VER)
+
+
+# Define the installation directories for various products.
+# IVE_HOME - IBM's version of Java (J9)
+# MOTIF_HOME - Motif includes and libraries
+# QT_HOME - identifier namespace package (used by KDE)
+IVE_HOME = /bluebird/teamswt/swt-builddir/ive/bin
+MOTIF_HOME = /bluebird/teamswt/swt-builddir/motif21
+QT_HOME = /usr/lib/qt-2.2.0
+
+
+# Define the various DLL (shared) libraries to be made.
+
+SWT_PREFIX = swt
+SWT_DLL = lib$(SWT_PREFIX)$(DLL_VERSION).so
+SWT_OBJ = callback.o globals.o library.o structs.o swt.o
+SWT_LIB = $(MOTIF_HOME)/lib/libXm.a -L/usr/lib -L/usr/X11R6/lib \
+ -x -shared -lX11 -lm -lXext -lXt -lXp -lXpm -ldl
+
+GNOME_PREFIX = swt-gnome
+GNOME_DLL = lib$(GNOME_PREFIX)$(DLL_VERSION).so
+GNOME_OBJ = gnome.o
+GNOME_LIB = -x -shared \
+ `gnome-config --libs gnome`
+
+KDE_PREFIX = swt-kde
+KDE_DLL = lib$(KDE_PREFIX)$(DLL_VERSION).so
+KDE_OBJ = kde.o
+KDE_LIB = -L/usr/lib -L$(QT_HOME)/lib \
+ -shared -lksycoca -lkdecore -lq
+
+#
+# The following CFLAGS are for compiling both the SWT library and the GNOME
+# library. The KDE library uses its own (C++) flags.
+#
+CFLAGS = -O -s \
+ -DSWT_LIBRARY_MAJOR_VERSION=$(MAJOR_VER) \
+ -DSWT_LIBRARY_MINOR_VERSION=$(MINOR_VER) \
+ -DLINUX -DMOTIF -DGNOME -DXPM \
+ -fpic \
+ -I./ \
+ -I$(IVE_HOME)/include \
+ -I$(MOTIF_HOME)/include \
+ -I/usr/X11R6/include \
+ `gnome-config --cflags gnome gnomeui`
+
+
+all: make_swt make_gnome
+
+kde: make_kde
+
+
+make_swt: $(SWT_DLL)
+
+$(SWT_DLL): $(SWT_OBJ)
+ ld -o $@ $(SWT_OBJ) $(SWT_LIB)
+
+
+make_gnome: $(GNOME_DLL)
+
+$(GNOME_DLL): $(GNOME_OBJ)
+ ld -o $@ $(GNOME_OBJ) $(GNOME_LIB)
+
+
+make_kde: $(KDE_DLL)
+
+$(KDE_DLL): $(KDE_OBJ)
+ ld -o $@ $(KDE_OBJ) $(KDE_LIB)
+
+$(KDE_OBJ): kde.cc
+ g++ -c -O -I/usr/include/kde -I$(QT_HOME)/include -I./ \
+ -I../ -I$(IVE_HOME)/include -fno-rtti -o kde.o kde.cc
+
+clean:
+ rm -f $(SWT_OBJ) $(SWT_DLL) $(GNOME_OBJ) $(GNOME_DLL)
+ rm -f $(KDE_OBJ) $(KDE_DLL)
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_solaris.mak b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_solaris.mak
new file mode 100755
index 0000000000..89b698fa7b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_solaris.mak
@@ -0,0 +1,69 @@
+# Makefile for creating SWT libraries on Solaris
+#
+# The following environment variables are assumed to be defined:
+#
+# MAJOR_VER - the major version number
+# MINOR_VER - the minor version number
+# BUILD_NUM - the build number
+
+DLL_VERSION=$(MAJOR_VER)$(MINOR_VER)
+
+
+# Define the installation directories for various products.
+# JAVA_HOME - Sun's version of Java (JDK2)
+# MOTIF_HOME - Motif includes and libraries
+JAVA_HOME = /tools/java1.3
+MOTIF_HOME = /usr/dt
+CDE_HOME = /usr/dt
+
+
+# Define the various DLL (shared) libraries to be made.
+
+SWT_PREFIX = swt
+SWT_DLL = lib$(SWT_PREFIX)$(DLL_VERSION).so
+SWT_OBJ = callback.o globals.o library.o structs.o swt.o
+SWT_LIB = -L$(MOTIF_HOME)/lib -L/usr/lib \
+ -G -lXm -lXt -lX11 -lm
+
+CDE_PREFIX = swt-cde
+CDE_DLL = lib$(CDE_PREFIX)$(DLL_VERSION).so
+CDE_OBJ =
+CDE_LIB = -G -L$(CDE_HOME) -L. -l$(SWT_PREFIX)$(DLL_VERSION)
+
+
+#
+# The following CFLAGS are for compiling both the SWT library and the CDE
+# library.
+#
+# Note:
+# The flag -xarch=generic ensure the compiled modules will be targeted
+# for 32-bit architectures. If this flag is not
+#
+CFLAGS = -O -s \
+ -xarch=generic \
+ -DSWT_LIBRARY_MAJOR_VERSION=$(MAJOR_VER) \
+ -DSWT_LIBRARY_MINOR_VERSION=$(MINOR_VER) \
+ -DSOLARIS -DMOTIF -DCDE \
+ -KPIC \
+ -I./ \
+ -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/solaris \
+ -I$(MOTIF_HOME)/include \
+ -I$(CDE_HOME)/include
+
+
+all: make_swt make_cde
+
+make_swt: $(SWT_DLL)
+
+$(SWT_DLL): $(SWT_OBJ)
+ ld -o $@ $(SWT_OBJ) $(SWT_LIB)
+
+
+make_cde: $(CDE_DLL)
+
+$(CDE_DLL): $(CDE_OBJ)
+ ld -o $@ $(CDE_OBJ) $(CDE_LIB)
+
+
+clean:
+ rm -f $(SWT_OBJ) $(SWT_DLL) $(CDE_OBJ) $(CDE_DLL)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.c b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.c
new file mode 100755
index 0000000000..02445f103d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.c
@@ -0,0 +1,1364 @@
+/**
+ * JNI SWT object field getters and setters declarations for Motif structs.
+ */
+
+#include <jni.h>
+#include "structs.h"
+
+/* ----------- fid and class caches ----------- */
+/*
+ * Used for Java objects passed into JNI that are
+ * declared like:
+ *
+ * nativeFunction (Rectangle p1, Rectangle p2, Rectangle p3)
+ *
+ * and not like this
+ *
+ * nativeFunction (Object p1, Object p2, Object p3)
+ *
+ *
+ */
+
+void cacheXimageFids(JNIEnv *env, jobject lpXimage, PXIMAGE_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->ximageClass = (*env)->GetObjectClass(env,lpXimage);
+
+ lpCache->width = (*env)->GetFieldID(env,lpCache->ximageClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->ximageClass,"height","I");
+ lpCache->xoffset = (*env)->GetFieldID(env,lpCache->ximageClass,"xoffset","I");
+ lpCache->format = (*env)->GetFieldID(env,lpCache->ximageClass,"format","I");
+ lpCache->data = (*env)->GetFieldID(env,lpCache->ximageClass,"data","I");
+ lpCache->byte_order = (*env)->GetFieldID(env,lpCache->ximageClass,"byte_order","I");
+ lpCache->bitmap_unit = (*env)->GetFieldID(env,lpCache->ximageClass,"bitmap_unit","I");
+ lpCache->bitmap_bit_order = (*env)->GetFieldID(env,lpCache->ximageClass,"bitmap_bit_order","I");
+ lpCache->bitmap_pad = (*env)->GetFieldID(env,lpCache->ximageClass,"bitmap_pad","I");
+ lpCache->depth = (*env)->GetFieldID(env,lpCache->ximageClass,"depth","I");
+ lpCache->bytes_per_line = (*env)->GetFieldID(env,lpCache->ximageClass,"bytes_per_line","I");
+ lpCache->bits_per_pixel = (*env)->GetFieldID(env,lpCache->ximageClass,"bits_per_pixel","I");
+ lpCache->red_mask = (*env)->GetFieldID(env,lpCache->ximageClass,"red_mask","I");
+ lpCache->green_mask = (*env)->GetFieldID(env,lpCache->ximageClass,"green_mask","I");
+ lpCache->blue_mask = (*env)->GetFieldID(env,lpCache->ximageClass,"blue_mask","I");
+ lpCache->obdata = (*env)->GetFieldID(env,lpCache->ximageClass,"obdata","I");
+ lpCache->create_image = (*env)->GetFieldID(env,lpCache->ximageClass,"create_image","I");
+ lpCache->destroy_image = (*env)->GetFieldID(env,lpCache->ximageClass,"destroy_image","I");
+ lpCache->get_pixel = (*env)->GetFieldID(env,lpCache->ximageClass,"get_pixel","I");
+ lpCache->put_pixel = (*env)->GetFieldID(env,lpCache->ximageClass,"put_pixel","I");
+ lpCache->sub_image = (*env)->GetFieldID(env,lpCache->ximageClass,"sub_image","I");
+ lpCache->add_pixel = (*env)->GetFieldID(env,lpCache->ximageClass,"add_pixel","I");
+ lpCache->cached = 1;
+}
+
+void cacheVisualFids(JNIEnv *env, jobject lpVisual, PVISUAL_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->visualClass = (*env)->GetObjectClass(env,lpVisual);
+
+ lpCache->ext_data = (*env)->GetFieldID(env,lpCache->visualClass,"ext_data","I");
+ lpCache->visualid = (*env)->GetFieldID(env,lpCache->visualClass,"visualid","I");
+ lpCache->c_class = (*env)->GetFieldID(env,lpCache->visualClass,"c_class","I");
+ lpCache->red_mask = (*env)->GetFieldID(env,lpCache->visualClass,"red_mask","I");
+ lpCache->green_mask = (*env)->GetFieldID(env,lpCache->visualClass,"green_mask","I");
+ lpCache->blue_mask = (*env)->GetFieldID(env,lpCache->visualClass,"blue_mask","I");
+ lpCache->bits_per_rgb = (*env)->GetFieldID(env,lpCache->visualClass,"bits_per_rgb","I");
+ lpCache->map_entries = (*env)->GetFieldID(env,lpCache->visualClass,"map_entries","I");
+ lpCache->cached = 1;
+}
+
+void cacheXanyeventFids(JNIEnv *env, jobject lpXevent, PXANYEVENT_FID_CACHE lpCache)
+{
+ int i;
+
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ for (i=0; i<19; i++) {
+ char buffer [8];
+ sprintf(buffer, "pad%d", i);
+ lpCache->pad[i] = (*env)->GetFieldID(env,lpCache->xeventClass,buffer,"I");
+ }
+ lpCache->cached = 1;
+}
+
+void cacheXbuttoneventFids(JNIEnv *env, jobject lpXevent, PXBUTTONEVENT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->root = (*env)->GetFieldID(env,lpCache->xeventClass,"root","I");
+ lpCache->subwindow = (*env)->GetFieldID(env,lpCache->xeventClass,"subwindow","I");
+ lpCache->time = (*env)->GetFieldID(env,lpCache->xeventClass,"time","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xeventClass,"y","I");
+ lpCache->x_root = (*env)->GetFieldID(env,lpCache->xeventClass,"x_root","I");
+ lpCache->y_root = (*env)->GetFieldID(env,lpCache->xeventClass,"y_root","I");
+ lpCache->state = (*env)->GetFieldID(env,lpCache->xeventClass,"state","I");
+ lpCache->button = (*env)->GetFieldID(env,lpCache->xeventClass,"button","I");
+ lpCache->same_screen = (*env)->GetFieldID(env,lpCache->xeventClass,"same_screen","I");
+ lpCache->cached = 1;
+}
+
+void cacheXcharstructFids(JNIEnv *env, jobject lpXcharstruct, PXCHARSTRUCT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xcharstructClass = (*env)->GetObjectClass(env,lpXcharstruct);
+
+ lpCache->lbearing = (*env)->GetFieldID(env,lpCache->xcharstructClass,"lbearing","S");
+ lpCache->rbearing = (*env)->GetFieldID(env,lpCache->xcharstructClass,"rbearing","S");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xcharstructClass,"width","S");
+ lpCache->ascent = (*env)->GetFieldID(env,lpCache->xcharstructClass,"ascent","S");
+ lpCache->descent = (*env)->GetFieldID(env,lpCache->xcharstructClass,"descent","S");
+ lpCache->attributes = (*env)->GetFieldID(env,lpCache->xcharstructClass,"attributes","S");
+ lpCache->cached = 1;
+}
+
+void cacheXconfigureeventFids(JNIEnv *env, jobject lpXevent, PXCONFIGUREEVENT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xeventClass,"y","I");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xeventClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xeventClass,"height","I");
+ lpCache->border_width = (*env)->GetFieldID(env,lpCache->xeventClass,"border_width","I");
+ lpCache->above = (*env)->GetFieldID(env,lpCache->xeventClass,"above","I");
+ lpCache->override_redirect = (*env)->GetFieldID(env,lpCache->xeventClass,"override_redirect","I");
+ lpCache->cached = 1;
+}
+
+void cacheXcrossingeventFids(JNIEnv *env, jobject lpXcrossingevent, PXCROSSINGEVENT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xcrossingeventClass = (*env)->GetObjectClass(env,lpXcrossingevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"window","I");
+ lpCache->root = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"root","I");
+ lpCache->subwindow = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"subwindow","I");
+ lpCache->time = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"time","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"y","I");
+ lpCache->x_root = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"x_root","I");
+ lpCache->y_root = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"y_root","I");
+ lpCache->mode = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"mode","I");
+ lpCache->detail = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"detail","I");
+ lpCache->same_screen = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"same_screen","I");
+ lpCache->focus = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"focus","I");
+ lpCache->state = (*env)->GetFieldID(env,lpCache->xcrossingeventClass,"state","I");
+ lpCache->cached = 1;
+}
+
+void cacheXexposeeventFids(JNIEnv *env, jobject lpXevent, PXEXPOSEEVENT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xeventClass,"y","I");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xeventClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xeventClass,"height","I");
+ lpCache->count = (*env)->GetFieldID(env,lpCache->xeventClass,"count","I");
+ lpCache->cached = 1;
+}
+
+void cacheXfocuschangeeventFids(JNIEnv *env, jobject lpXevent, PXFOCUSCHANGEEVENT_FID_CACHE lpCache)
+{
+ int i;
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->mode = (*env)->GetFieldID(env,lpCache->xeventClass,"mode","I");
+ lpCache->detail = (*env)->GetFieldID(env,lpCache->xeventClass,"detail","I");
+ for (i=0; i<17; i++) {
+ char buffer [8];
+ sprintf(buffer, "pad%d", i);
+ lpCache->pad[i] = (*env)->GetFieldID(env,lpCache->xeventClass,buffer,"I");
+ }
+ lpCache->cached = 1;
+}
+
+void cacheXfontstructFids(JNIEnv *env, jobject lpXfontstruct, PXFONTSTRUCT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xfontstructClass = (*env)->GetObjectClass(env,lpXfontstruct);
+
+ lpCache->ext_data = (*env)->GetFieldID(env,lpCache->xfontstructClass,"ext_data","I");
+ lpCache->fid = (*env)->GetFieldID(env,lpCache->xfontstructClass,"fid","I");
+ lpCache->direction = (*env)->GetFieldID(env,lpCache->xfontstructClass,"direction","I");
+ lpCache->min_char_or_byte2 = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_char_or_byte2","I");
+ lpCache->max_char_or_byte2 = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_char_or_byte2","I");
+ lpCache->min_byte1 = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_byte1","I");
+ lpCache->max_byte1 = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_byte1","I");
+ lpCache->all_chars_exist = (*env)->GetFieldID(env,lpCache->xfontstructClass,"all_chars_exist","I");
+ lpCache->default_char = (*env)->GetFieldID(env,lpCache->xfontstructClass,"default_char","I");
+ lpCache->n_properties = (*env)->GetFieldID(env,lpCache->xfontstructClass,"n_properties","I");
+ lpCache->properties = (*env)->GetFieldID(env,lpCache->xfontstructClass,"properties","I");
+ lpCache->min_bounds_lbearing = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_lbearing","S");
+ lpCache->min_bounds_rbearing = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_rbearing","S");
+ lpCache->min_bounds_width = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_width","S");
+ lpCache->min_bounds_ascent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_ascent","S");
+ lpCache->min_bounds_descent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_descent","S");
+ lpCache->min_bounds_attributes = (*env)->GetFieldID(env,lpCache->xfontstructClass,"min_bounds_attributes","S");
+ lpCache->max_bounds_lbearing = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_lbearing","S");
+ lpCache->max_bounds_rbearing = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_rbearing","S");
+ lpCache->max_bounds_width = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_width","S");
+ lpCache->max_bounds_ascent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_ascent","S");
+ lpCache->max_bounds_descent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_descent","S");
+ lpCache->max_bounds_attributes = (*env)->GetFieldID(env,lpCache->xfontstructClass,"max_bounds_attributes","S");
+ lpCache->per_char = (*env)->GetFieldID(env,lpCache->xfontstructClass,"per_char","I");
+ lpCache->ascent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"ascent","I");
+ lpCache->descent = (*env)->GetFieldID(env,lpCache->xfontstructClass,"descent","I");
+ lpCache->cached = 1;
+}
+
+void cacheXkeyeventFids(JNIEnv *env, jobject lpXevent, PXKEYEVENT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->root = (*env)->GetFieldID(env,lpCache->xeventClass,"root","I");
+ lpCache->subwindow = (*env)->GetFieldID(env,lpCache->xeventClass,"subwindow","I");
+ lpCache->time = (*env)->GetFieldID(env,lpCache->xeventClass,"time","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xeventClass,"y","I");
+ lpCache->x_root = (*env)->GetFieldID(env,lpCache->xeventClass,"x_root","I");
+ lpCache->y_root = (*env)->GetFieldID(env,lpCache->xeventClass,"y_root","I");
+ lpCache->state = (*env)->GetFieldID(env,lpCache->xeventClass,"state","I");
+ lpCache->keycode = (*env)->GetFieldID(env,lpCache->xeventClass,"keycode","I");
+ lpCache->same_screen = (*env)->GetFieldID(env,lpCache->xeventClass,"same_screen","I");
+ lpCache->cached = 1;
+}
+
+void cacheXmotioneventFids(JNIEnv *env, jobject lpXevent, PXMOTIONEVENT_FID_CACHE lpCache)
+{
+ int i;
+ if (lpCache->cached) return;
+
+ lpCache->xeventClass = (*env)->GetObjectClass(env,lpXevent);
+
+ lpCache->type = (*env)->GetFieldID(env,lpCache->xeventClass,"type","I");
+ lpCache->serial = (*env)->GetFieldID(env,lpCache->xeventClass,"serial","I");
+ lpCache->send_event = (*env)->GetFieldID(env,lpCache->xeventClass,"send_event","I");
+ lpCache->display = (*env)->GetFieldID(env,lpCache->xeventClass,"display","I");
+ lpCache->window = (*env)->GetFieldID(env,lpCache->xeventClass,"window","I");
+ lpCache->root = (*env)->GetFieldID(env,lpCache->xeventClass,"root","I");
+ lpCache->subwindow = (*env)->GetFieldID(env,lpCache->xeventClass,"subwindow","I");
+ lpCache->time = (*env)->GetFieldID(env,lpCache->xeventClass,"time","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xeventClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xeventClass,"y","I");
+ lpCache->x_root = (*env)->GetFieldID(env,lpCache->xeventClass,"x_root","I");
+ lpCache->y_root = (*env)->GetFieldID(env,lpCache->xeventClass,"y_root","I");
+ lpCache->state = (*env)->GetFieldID(env,lpCache->xeventClass,"state","I");
+ lpCache->is_hint = (*env)->GetFieldID(env,lpCache->xeventClass,"is_hint","I");
+ lpCache->same_screen = (*env)->GetFieldID(env,lpCache->xeventClass,"same_screen","I");
+ for (i=0; i<10; i++) {
+ char buffer [8];
+ sprintf(buffer, "pad%d", i);
+ lpCache->pad[i] = (*env)->GetFieldID(env,lpCache->xeventClass,buffer,"I");
+ }
+ lpCache->cached = 1;
+}
+
+void cacheXcolorFids(JNIEnv *env, jobject lpXcolor, PXCOLOR_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xcolorClass = (*env)->GetObjectClass(env,lpXcolor);
+
+ lpCache->pixel = (*env)->GetFieldID(env,lpCache->xcolorClass,"pixel","I");
+ lpCache->red = (*env)->GetFieldID(env,lpCache->xcolorClass,"red","S");
+ lpCache->green = (*env)->GetFieldID(env,lpCache->xcolorClass,"green","S");
+ lpCache->blue = (*env)->GetFieldID(env,lpCache->xcolorClass,"blue","S");
+ lpCache->flags = (*env)->GetFieldID(env,lpCache->xcolorClass,"flags","B");
+ lpCache->pad = (*env)->GetFieldID(env,lpCache->xcolorClass,"pad","B");
+ lpCache->cached = 1;
+}
+
+void cacheXgcvaluesFids(JNIEnv *env, jobject lpXgcvalues, PXGCVALUES_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xgcvaluesClass = (*env)->GetObjectClass(env,lpXgcvalues);
+
+ lpCache->function = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"function","I");
+ lpCache->plane_mask = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"plane_mask","I");
+ lpCache->foreground = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"foreground","I");
+ lpCache->background = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"background","I");
+ lpCache->line_width = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"line_width","I");
+ lpCache->line_style = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"line_style","I");
+ lpCache->cap_style = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"cap_style","I");
+ lpCache->join_style = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"join_style","I");
+ lpCache->fill_style = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"fill_style","I");
+ lpCache->fill_rule = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"fill_rule","I");
+ lpCache->arc_mode = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"arc_mode","I");
+ lpCache->tile = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"tile","I");
+ lpCache->stipple = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"stipple","I");
+ lpCache->ts_x_origin = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"ts_x_origin","I");
+ lpCache->ts_y_origin = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"ts_y_origin","I");
+ lpCache->font = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"font","I");
+ lpCache->subwindow_mode = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"subwindow_mode","I");
+ lpCache->graphics_exposures = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"graphics_exposures","I");
+ lpCache->clip_x_origin = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"clip_x_origin","I");
+ lpCache->clip_y_origin = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"clip_y_origin","I");
+ lpCache->clip_mask = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"clip_mask","I");
+ lpCache->dash_offset = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"dash_offset","I");
+
+ lpCache->dashes = (*env)->GetFieldID(env,lpCache->xgcvaluesClass,"dashes","B");
+ lpCache->cached = 1;
+}
+
+void cacheXmanycallbackstructFids(JNIEnv *env, jobject lpXmanycallback, PXMANYCALLBACKSTRUCT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmanycallbackstructClass = (*env)->GetObjectClass(env,lpXmanycallback);
+
+ lpCache->reason = (*env)->GetFieldID(env,lpCache->xmanycallbackstructClass,"reason","I");
+ lpCache->event = (*env)->GetFieldID(env,lpCache->xmanycallbackstructClass,"event","I");
+ lpCache->cached = 1;
+}
+
+void cacheXmdragproccallbackFids(JNIEnv *env, jobject lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmdragproccallbackClass = (*env)->GetObjectClass(env,lpXmdragproccallback);
+
+ lpCache->reason = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"reason","I");
+ lpCache->event = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"event","I");
+ lpCache->timeStamp = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"timeStamp","I");
+ lpCache->dragContext = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"dragContext","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"x","S");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"y","S");
+ lpCache->dropSiteStatus = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"dropSiteStatus","B");
+ lpCache->operation = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"operation","B");
+ lpCache->operations = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"operations","B");
+ lpCache->animate = (*env)->GetFieldID(env,lpCache->xmdragproccallbackClass,"animate","B");
+ lpCache->cached = 1;
+}
+
+void cacheXmdropproccallbackFids(JNIEnv *env, jobject lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmdropproccallbackClass = (*env)->GetObjectClass(env,lpXmdropproccallback);
+
+ lpCache->reason = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"reason","I");
+ lpCache->event = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"event","I");
+ lpCache->timeStamp = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"timeStamp","I");
+ lpCache->dragContext = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"dragContext","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"x","S");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"y","S");
+ lpCache->dropSiteStatus = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"dropSiteStatus","B");
+ lpCache->operation = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"operation","B");
+ lpCache->operations = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"operations","B");
+ lpCache->dropAction = (*env)->GetFieldID(env,lpCache->xmdropproccallbackClass,"dropAction","B");
+ lpCache->cached = 1;
+}
+
+void cacheXmdropfinishcallbackFids(JNIEnv *env, jobject lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmdropfinishcallbackClass = (*env)->GetObjectClass(env,lpXmdropfinishcallback);
+
+ lpCache->reason = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"reason","I");
+ lpCache->event = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"event","I");
+ lpCache->timeStamp = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"timeStamp","I");
+ lpCache->operation = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"operation","B");
+ lpCache->operations = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"operations","B");
+ lpCache->dropSiteStatus = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"dropSiteStatus","B");
+ lpCache->dropAction = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"dropAction","B");
+ lpCache->completionStatus = (*env)->GetFieldID(env,lpCache->xmdropfinishcallbackClass,"completionStatus","B");
+ lpCache->cached = 1;
+}
+
+void cacheXmtextblockrecFids(JNIEnv *env, jobject lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmtextblockrecClass = (*env)->GetObjectClass(env,lpXmtextblockrec);
+
+ lpCache->ptr = (*env)->GetFieldID(env,lpCache->xmtextblockrecClass,"ptr","I");
+ lpCache->length = (*env)->GetFieldID(env,lpCache->xmtextblockrecClass,"length","I");
+ lpCache->format = (*env)->GetFieldID(env,lpCache->xmtextblockrecClass,"format","I");
+ lpCache->cached = 1;
+}
+
+void cacheXmtextverifycallbackstructFids(JNIEnv *env, jobject lpXmtextverifycallback, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xmtextverifycallbackstructClass = (*env)->GetObjectClass(env,lpXmtextverifycallback);
+
+ lpCache->reason = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"reason","I");
+ lpCache->event = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"event","I");
+ lpCache->doit = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"doit","B");
+ lpCache->currInsert = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"currInsert","I");
+ lpCache->newInsert = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"newInsert","I");
+ lpCache->startPos = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"startPos","I");
+ lpCache->endPos = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"endPos","I");
+ lpCache->text = (*env)->GetFieldID(env,lpCache->xmtextverifycallbackstructClass,"text","I");
+ lpCache->cached = 1;
+}
+
+void cacheXrectangleFids(JNIEnv *env, jobject lpXrect, PXRECTANGLE_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xrectClass = (*env)->GetObjectClass(env,lpXrect);
+
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xrectClass,"x","S");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xrectClass,"y","S");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xrectClass,"width","S");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xrectClass,"height","S");
+ lpCache->cached = 1;
+}
+
+void cacheXsetwindowattributesFids(JNIEnv *env, jobject lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xsetwindowattributesClass = (*env)->GetObjectClass(env,lpXsetwindowattributes);
+
+ lpCache->background_pixmap = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"background_pixmap","I");
+ lpCache->background_pixel = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"background_pixel","I");
+ lpCache->border_pixmap = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"border_pixmap","I");
+ lpCache->border_pixel = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"border_pixel","I");
+ lpCache->bit_gravity = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"bit_gravity","I");
+ lpCache->win_gravity = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"win_gravity","I");
+ lpCache->backing_store = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"backing_store","I");
+ lpCache->backing_planes = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"backing_planes","I");
+ lpCache->backing_pixel = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"backing_pixel","I");
+ lpCache->save_under = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"save_under","I");
+ lpCache->event_mask = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"event_mask","I");
+ lpCache->do_not_propagate_mask = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"do_not_propagate_mask","I");
+ lpCache->override_redirect = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"override_redirect","I");
+ lpCache->colormap = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"colormap","I");
+ lpCache->cursor = (*env)->GetFieldID(env,lpCache->xsetwindowattributesClass,"cursor","I");
+ lpCache->cached = 1;
+}
+
+void cacheXwindowattributesFids(JNIEnv *env, jobject lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xwindowattributesClass = (*env)->GetObjectClass(env,lpXwindowattributes);
+
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"y","I");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"height","I");
+ lpCache->border_width = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"border_width","I");
+ lpCache->depth = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"depth","I");
+ lpCache->visual = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"visual","I");
+ lpCache->root = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"root","I");
+ lpCache->class = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"c_class","I");
+ lpCache->bit_gravity = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"bit_gravity","I");
+ lpCache->win_gravity = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"win_gravity","I");
+ lpCache->backing_store = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"backing_store","I");
+ lpCache->backing_planes = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"backing_planes","I");
+ lpCache->backing_pixel = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"backing_pixel","I");
+ lpCache->save_under = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"save_under","I");
+ lpCache->colormap = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"colormap","I");
+ lpCache->map_installed = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"map_installed","I");
+ lpCache->map_state = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"map_state","I");
+ lpCache->all_event_masks = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"all_event_masks","I");
+ lpCache->your_event_mask = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"your_event_mask","I");
+ lpCache->do_not_propagate_mask = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"do_not_propagate_mask","I");
+ lpCache->override_redirect = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"override_redirect","I");
+ lpCache->screen = (*env)->GetFieldID(env,lpCache->xwindowattributesClass,"screen","I");
+ lpCache->cached = 1;
+}
+
+void cacheXwindowchangesFids(JNIEnv *env, jobject lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xwindowchangesClass = (*env)->GetObjectClass(env,lpXwindowchanges);
+
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"y","I");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"height","I");
+ lpCache->border_width = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"border_width","I");
+ lpCache->sibling = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"sibling","I");
+ lpCache->stack_mode = (*env)->GetFieldID(env,lpCache->xwindowchangesClass,"stack_mode","I");
+ lpCache->cached = 1;
+}
+
+void cacheXtwidgetgeometryFids(JNIEnv *env, jobject lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+
+ lpCache->xtwidgetgeometryClass = (*env)->GetObjectClass(env,lpXtwidgetgeometry);
+
+ lpCache->request_mode = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"request_mode","I");
+ lpCache->x = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"y","I");
+ lpCache->width = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"width","I");
+ lpCache->height = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"height","I");
+ lpCache->border_width = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"border_width","I");
+ lpCache->sibling = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"sibling","I");
+ lpCache->stack_mode = (*env)->GetFieldID(env,lpCache->xtwidgetgeometryClass,"stack_mode","I");
+ lpCache->cached = 1;
+}
+
+/* ----------- getters and setters ----------- */
+/**
+ * These functions get or set object field ids assuming that the
+ * fids for these objects have already been cached.
+ *
+ */
+
+void getVisualFields(JNIEnv *env, jobject lpObject, Visual *lpVisual, VISUAL_FID_CACHE *lpVisualFc)
+{
+ lpVisual->ext_data = (XExtData *)(*env)->GetIntField(env,lpObject,lpVisualFc->ext_data);
+ lpVisual->visualid = (*env)->GetIntField(env,lpObject,lpVisualFc->visualid);
+ lpVisual->class = (*env)->GetIntField(env,lpObject,lpVisualFc->c_class);
+ lpVisual->red_mask = (*env)->GetIntField(env,lpObject,lpVisualFc->red_mask);
+ lpVisual->green_mask = (*env)->GetIntField(env,lpObject,lpVisualFc->green_mask);
+ lpVisual->blue_mask = (*env)->GetIntField(env,lpObject,lpVisualFc->blue_mask);
+ lpVisual->bits_per_rgb = (*env)->GetIntField(env,lpObject,lpVisualFc->bits_per_rgb);
+ lpVisual->map_entries = (*env)->GetIntField(env,lpObject,lpVisualFc->map_entries);
+}
+
+void setVisualFields(JNIEnv *env, jobject lpObject, Visual *lpVisual, VISUAL_FID_CACHE *lpVisualFc)
+{
+ (*env)->SetIntField(env,lpObject,lpVisualFc->ext_data, (jint)lpVisual->ext_data);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->visualid, lpVisual->visualid);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->c_class, lpVisual->class);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->red_mask, (int)lpVisual->red_mask);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->green_mask, lpVisual->green_mask);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->blue_mask, lpVisual->blue_mask);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->bits_per_rgb, (int)lpVisual->bits_per_rgb);
+ (*env)->SetIntField(env,lpObject,lpVisualFc->map_entries, lpVisual->map_entries);
+}
+
+void getXanyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XANYEVENT_FID_CACHE *lpXanyeventFc)
+{
+ int i;
+
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXanyeventFc->type);
+ lpXevent->xany.serial = (*env)->GetIntField(env,lpObject,lpXanyeventFc->serial);
+ lpXevent->xany.send_event = (*env)->GetIntField(env,lpObject,lpXanyeventFc->send_event);
+ lpXevent->xany.display = (Display *)(*env)->GetIntField(env,lpObject,lpXanyeventFc->display);
+ lpXevent->xany.window = (*env)->GetIntField(env,lpObject,lpXanyeventFc->window);
+ for (i=0; i<19; i++) {
+ lpXevent->pad[i+5] = (*env)->GetIntField(env,lpObject,lpXanyeventFc->pad[i]);
+ }
+}
+
+void setXanyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XANYEVENT_FID_CACHE *lpXanyeventFc)
+{
+ int i;
+
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->serial, lpXevent->xany.serial);
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->send_event, lpXevent->xany.send_event);
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->display, (int)lpXevent->xany.display);
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->window, lpXevent->xany.window);
+ for (i=0; i<19; i++) {
+ (*env)->SetIntField(env,lpObject,lpXanyeventFc->pad[i],lpXevent->pad[i+5]);
+ }
+}
+
+void getXbuttoneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XBUTTONEVENT_FID_CACHE *lpXbuttoneventFc)
+{
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->type);
+ lpXevent->xbutton.serial = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->serial);
+ lpXevent->xbutton.send_event = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->send_event);
+ lpXevent->xbutton.display = (Display *)(*env)->GetIntField(env,lpObject,lpXbuttoneventFc->display);
+ lpXevent->xbutton.window = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->window);
+ lpXevent->xbutton.root = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->root);
+ lpXevent->xbutton.subwindow = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->subwindow);
+ lpXevent->xbutton.time = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->time);
+ lpXevent->xbutton.x = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->x);
+ lpXevent->xbutton.y = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->y);
+ lpXevent->xbutton.x_root = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->x_root);
+ lpXevent->xbutton.y_root = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->y_root);
+ lpXevent->xbutton.state = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->state);
+ lpXevent->xbutton.button = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->button);
+ lpXevent->xbutton.same_screen = (*env)->GetIntField(env,lpObject,lpXbuttoneventFc->same_screen);
+}
+
+void setXbuttoneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XBUTTONEVENT_FID_CACHE *lpXbuttoneventFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->serial, lpXevent->xbutton.serial);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->send_event, lpXevent->xbutton.send_event);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->display, (int)lpXevent->xbutton.display);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->window, lpXevent->xbutton.window);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->root, lpXevent->xbutton.root);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->subwindow, lpXevent->xbutton.subwindow);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->time, lpXevent->xbutton.time);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->x, lpXevent->xbutton.x);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->y, lpXevent->xbutton.y);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->x_root, lpXevent->xbutton.x_root);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->y_root, lpXevent->xbutton.y_root);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->state, lpXevent->xbutton.state);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->button, lpXevent->xbutton.button);
+ (*env)->SetIntField(env,lpObject,lpXbuttoneventFc->same_screen, lpXevent->xbutton.same_screen);
+}
+
+void getXconfigureeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XCONFIGUREEVENT_FID_CACHE *lpXconfigureeventFc)
+{
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->type);
+ lpXevent->xconfigure.serial = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->serial);
+ lpXevent->xconfigure.send_event = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->send_event);
+ lpXevent->xconfigure.display = (Display *)(*env)->GetIntField(env,lpObject,lpXconfigureeventFc->display);
+ lpXevent->xconfigure.window = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->window);
+ lpXevent->xconfigure.x = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->x);
+ lpXevent->xconfigure.y = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->y);
+ lpXevent->xconfigure.width = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->width);
+ lpXevent->xconfigure.height = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->height);
+ lpXevent->xconfigure.border_width = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->border_width);
+ lpXevent->xconfigure.above = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->above);
+ lpXevent->xconfigure.override_redirect = (*env)->GetIntField(env,lpObject,lpXconfigureeventFc->override_redirect);
+}
+
+void setXconfigureeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XCONFIGUREEVENT_FID_CACHE *lpXconfigureeventFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->serial, lpXevent->xconfigure.serial);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->send_event, lpXevent->xconfigure.send_event);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->display, (int)lpXevent->xconfigure.display);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->window, lpXevent->xconfigure.window);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->x, lpXevent->xconfigure.x);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->y, lpXevent->xconfigure.y);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->width, lpXevent->xconfigure.width);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->height, lpXevent->xconfigure.height);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->border_width, lpXevent->xconfigure.border_width);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->above, lpXevent->xconfigure.above);
+ (*env)->SetIntField(env,lpObject,lpXconfigureeventFc->override_redirect, lpXevent->xconfigure.override_redirect);
+}
+
+void getXcharstructFields(JNIEnv *env, jobject lpObject, XCharStruct *lpXcharstruct, XCHARSTRUCT_FID_CACHE *lpXcharstructFc)
+{
+ lpXcharstruct->lbearing = (*env)->GetShortField(env,lpObject,lpXcharstructFc->lbearing);
+ lpXcharstruct->rbearing = (*env)->GetShortField(env,lpObject,lpXcharstructFc->rbearing);
+ lpXcharstruct->width = (*env)->GetShortField(env,lpObject,lpXcharstructFc->width);
+ lpXcharstruct->ascent = (*env)->GetShortField(env,lpObject,lpXcharstructFc->ascent);
+ lpXcharstruct->descent = (*env)->GetShortField(env,lpObject,lpXcharstructFc->descent);
+ lpXcharstruct->attributes = (*env)->GetShortField(env,lpObject,lpXcharstructFc->attributes);
+}
+
+void setXcharstructFields(JNIEnv *env, jobject lpObject, XCharStruct *lpXcharstruct, XCHARSTRUCT_FID_CACHE *lpXcharstructFc)
+{
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->lbearing, lpXcharstruct->lbearing);
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->rbearing, lpXcharstruct->rbearing);
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->width, lpXcharstruct->width);
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->ascent, lpXcharstruct->ascent);
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->descent, lpXcharstruct->descent);
+ (*env)->SetShortField(env,lpObject,lpXcharstructFc->attributes, lpXcharstruct->attributes);
+
+}
+
+void getXcrossingeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXcrossingevent, XCROSSINGEVENT_FID_CACHE *lpXcrossingeventFc)
+{
+ int i;
+
+ lpXcrossingevent->type = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->type);
+ lpXcrossingevent->xcrossing.serial = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->serial);
+ lpXcrossingevent->xcrossing.send_event = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->send_event);
+ lpXcrossingevent->xcrossing.display = (Display *)(*env)->GetIntField(env,lpObject,lpXcrossingeventFc->display);
+ lpXcrossingevent->xcrossing.window = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->window);
+ lpXcrossingevent->xcrossing.root = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->root);
+ lpXcrossingevent->xcrossing.subwindow = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->subwindow);
+ lpXcrossingevent->xcrossing.time = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->time);
+ lpXcrossingevent->xcrossing.x = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->x);
+ lpXcrossingevent->xcrossing.y = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->y);
+ lpXcrossingevent->xcrossing.x_root = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->x_root);
+ lpXcrossingevent->xcrossing.y_root = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->y_root);
+ lpXcrossingevent->xcrossing.mode = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->mode);
+ lpXcrossingevent->xcrossing.detail = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->detail);
+ lpXcrossingevent->xcrossing.same_screen = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->same_screen);
+ lpXcrossingevent->xcrossing.focus = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->focus);
+ lpXcrossingevent->xcrossing.state = (*env)->GetIntField(env,lpObject,lpXcrossingeventFc->state);
+}
+
+void setXcrossingeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXcrossingevent, XCROSSINGEVENT_FID_CACHE *lpXcrossingeventFc)
+{
+ int i;
+
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->type, lpXcrossingevent->type);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->serial, lpXcrossingevent->xcrossing.serial);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->send_event, lpXcrossingevent->xcrossing.send_event);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->display, (int)lpXcrossingevent->xcrossing.display);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->window, lpXcrossingevent->xcrossing.window);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->root, lpXcrossingevent->xcrossing.root);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->subwindow, lpXcrossingevent->xcrossing.subwindow);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->time, lpXcrossingevent->xcrossing.time);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->x, lpXcrossingevent->xcrossing.x);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->y, lpXcrossingevent->xcrossing.y);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->x_root, lpXcrossingevent->xcrossing.x_root);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->y_root, lpXcrossingevent->xcrossing.y_root);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->mode, lpXcrossingevent->xcrossing.mode);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->detail, lpXcrossingevent->xcrossing.detail);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->same_screen, lpXcrossingevent->xcrossing.same_screen);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->focus, lpXcrossingevent->xcrossing.focus);
+ (*env)->SetIntField(env,lpObject,lpXcrossingeventFc->state, lpXcrossingevent->xcrossing.state);
+}
+
+void getXexposeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XEXPOSEEVENT_FID_CACHE *lpXexposeeventFc)
+{
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->type);
+ lpXevent->xexpose.serial = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->serial);
+ lpXevent->xexpose.send_event = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->send_event);
+ lpXevent->xexpose.display = (Display *)(*env)->GetIntField(env,lpObject,lpXexposeeventFc->display);
+ lpXevent->xexpose.window = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->window);
+ lpXevent->xexpose.x = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->x);
+ lpXevent->xexpose.y = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->y);
+ lpXevent->xexpose.width = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->width);
+ lpXevent->xexpose.height = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->height);
+ lpXevent->xexpose.count = (*env)->GetIntField(env,lpObject,lpXexposeeventFc->count);
+}
+
+void setXexposeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XEXPOSEEVENT_FID_CACHE *lpXexposeeventFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->serial, lpXevent->xexpose.serial);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->send_event, lpXevent->xexpose.send_event);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->display, (int)lpXevent->xexpose.display);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->window, lpXevent->xexpose.window);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->x, lpXevent->xexpose.x);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->y, lpXevent->xexpose.y);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->width, lpXevent->xexpose.width);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->height, lpXevent->xexpose.height);
+ (*env)->SetIntField(env,lpObject,lpXexposeeventFc->count, lpXevent->xexpose.count);
+}
+
+void getXfontstructFields(JNIEnv *env, jobject lpObject, XFontStruct *lpXfontstruct, XFONTSTRUCT_FID_CACHE *lpXfontstructFc)
+{
+ lpXfontstruct->ext_data = (XExtData *)(*env)->GetIntField(env,lpObject,lpXfontstructFc->ext_data);
+ lpXfontstruct->fid = (Font)(*env)->GetIntField(env,lpObject,lpXfontstructFc->fid);
+ lpXfontstruct->direction = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->direction);
+ lpXfontstruct->min_char_or_byte2 = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->min_char_or_byte2);
+ lpXfontstruct->max_char_or_byte2 = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->max_char_or_byte2);
+ lpXfontstruct->min_byte1 = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->min_byte1);
+ lpXfontstruct->max_byte1 = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->max_byte1);
+ lpXfontstruct->all_chars_exist = (Bool)(*env)->GetIntField(env,lpObject,lpXfontstructFc->all_chars_exist);
+ lpXfontstruct->default_char = (unsigned)(*env)->GetIntField(env,lpObject,lpXfontstructFc->default_char);
+ lpXfontstruct->n_properties = (*env)->GetIntField(env,lpObject,lpXfontstructFc->n_properties);
+ lpXfontstruct->properties = (XFontProp *)(*env)->GetIntField(env,lpObject,lpXfontstructFc->properties);
+ lpXfontstruct->min_bounds.lbearing = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing);
+ lpXfontstruct->min_bounds.rbearing = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_rbearing);
+ lpXfontstruct->min_bounds.width = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing);
+ lpXfontstruct->min_bounds.ascent = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing);
+ lpXfontstruct->min_bounds.descent = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing);
+ lpXfontstruct->min_bounds.attributes = (*env)->GetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing);
+ lpXfontstruct->max_bounds.lbearing = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_lbearing);
+ lpXfontstruct->max_bounds.rbearing = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_rbearing);
+ lpXfontstruct->max_bounds.width = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_width);
+ lpXfontstruct->max_bounds.ascent = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_ascent);
+ lpXfontstruct->max_bounds.descent = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_descent);
+ lpXfontstruct->max_bounds.attributes = (*env)->GetShortField(env,lpObject,lpXfontstructFc->max_bounds_attributes);
+ lpXfontstruct->per_char = (XCharStruct *)(*env)->GetIntField(env,lpObject,lpXfontstructFc->per_char);
+ lpXfontstruct->ascent = (*env)->GetIntField(env,lpObject,lpXfontstructFc->ascent);
+ lpXfontstruct->descent = (*env)->GetIntField(env,lpObject,lpXfontstructFc->descent);
+}
+
+void setXfontstructFields(JNIEnv *env, jobject lpObject, XFontStruct *lpXfontstruct, XFONTSTRUCT_FID_CACHE *lpXfontstructFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->ext_data, (jint)lpXfontstruct->ext_data);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->fid, (jint)lpXfontstruct->fid);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->direction, (jint)lpXfontstruct->direction);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->min_char_or_byte2, (jint)lpXfontstruct->min_char_or_byte2);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->max_char_or_byte2, (jint)lpXfontstruct->max_char_or_byte2);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->min_byte1, (jint)lpXfontstruct->min_byte1);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->max_byte1, (jint)lpXfontstruct->max_byte1);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->all_chars_exist, (jint)lpXfontstruct->all_chars_exist);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->default_char, (jint)lpXfontstruct->default_char);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->n_properties, (jint)lpXfontstruct->n_properties);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->properties, (jint)lpXfontstruct->properties);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_lbearing, (jint)lpXfontstruct->min_bounds.lbearing);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_rbearing, (jint)lpXfontstruct->min_bounds.rbearing);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_width, (jint)lpXfontstruct->min_bounds.width);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_ascent, (jint)lpXfontstruct->min_bounds.ascent);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_descent, (jint)lpXfontstruct->min_bounds.descent);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->min_bounds_attributes, (jint)lpXfontstruct->min_bounds.attributes);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_lbearing, (jint)lpXfontstruct->max_bounds.lbearing);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_rbearing, (jint)lpXfontstruct->max_bounds.rbearing);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_width, (jint)lpXfontstruct->max_bounds.width);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_ascent, (jint)lpXfontstruct->max_bounds.ascent);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_descent, (jint)lpXfontstruct->max_bounds.descent);
+ (*env)->SetShortField(env,lpObject,lpXfontstructFc->max_bounds_attributes, (jint)lpXfontstruct->max_bounds.attributes);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->per_char, (jint)lpXfontstruct->per_char);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->ascent, (jint)lpXfontstruct->ascent);
+ (*env)->SetIntField(env,lpObject,lpXfontstructFc->descent, (jint)lpXfontstruct->descent);
+}
+
+
+void getXfocuschangeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XFOCUSCHANGEEVENT_FID_CACHE *lpXfocuschangeeventFc)
+{
+ int i;
+
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->type);
+ lpXevent->xfocus.serial = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->serial);
+ lpXevent->xfocus.send_event = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->send_event);
+ lpXevent->xfocus.display = (Display *)(*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->display);
+ lpXevent->xfocus.window = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->window);
+ lpXevent->xfocus.mode = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->mode);
+ lpXevent->xfocus.detail = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->detail);
+ for (i=0; i<17; i++) {
+ lpXevent->pad[i+7] = (*env)->GetIntField(env,lpObject,lpXfocuschangeeventFc->pad[i]);
+ }
+}
+
+void setXfocuschangeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XFOCUSCHANGEEVENT_FID_CACHE *lpXfocuschangeeventFc)
+{
+ int i;
+
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->serial, lpXevent->xfocus.serial);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->send_event, lpXevent->xfocus.send_event);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->display, (int)lpXevent->xfocus.display);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->window, lpXevent->xfocus.window);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->mode, lpXevent->xfocus.mode);
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->detail, lpXevent->xfocus.detail);
+ for (i=0; i<17; i++) {
+ (*env)->SetIntField(env,lpObject,lpXfocuschangeeventFc->pad[i],lpXevent->pad[i+7]);
+ }
+}
+
+void getXimageFields(JNIEnv *env, jobject lpObject, XImage *lpXimage, XIMAGE_FID_CACHE *lpXimageFc)
+{
+ lpXimage->width = (*env)->GetIntField(env,lpObject,lpXimageFc->width);
+ lpXimage->height = (*env)->GetIntField(env,lpObject,lpXimageFc->height);
+ lpXimage->xoffset = (*env)->GetIntField(env,lpObject,lpXimageFc->xoffset);
+ lpXimage->format = (*env)->GetIntField(env,lpObject,lpXimageFc->format);
+ lpXimage->data = (char *)(*env)->GetIntField(env,lpObject,lpXimageFc->data);
+ lpXimage->byte_order = (*env)->GetIntField(env,lpObject,lpXimageFc->byte_order);
+ lpXimage->bitmap_unit = (*env)->GetIntField(env,lpObject,lpXimageFc->bitmap_unit);
+ lpXimage->bitmap_bit_order = (*env)->GetIntField(env,lpObject,lpXimageFc->bitmap_bit_order);
+ lpXimage-> bitmap_pad= (*env)->GetIntField(env,lpObject,lpXimageFc->bitmap_pad);
+ lpXimage->depth = (*env)->GetIntField(env,lpObject,lpXimageFc->depth);
+ lpXimage->bytes_per_line = (*env)->GetIntField(env,lpObject,lpXimageFc->bytes_per_line);
+ lpXimage->bits_per_pixel = (*env)->GetIntField(env,lpObject,lpXimageFc->bits_per_pixel);
+ lpXimage->red_mask = (*env)->GetIntField(env,lpObject,lpXimageFc->red_mask);
+ lpXimage->green_mask = (*env)->GetIntField(env,lpObject,lpXimageFc->green_mask);
+ lpXimage->blue_mask = (*env)->GetIntField(env,lpObject,lpXimageFc->blue_mask);
+ lpXimage->obdata = (char *)(*env)->GetIntField(env,lpObject,lpXimageFc->obdata);
+ lpXimage->f.create_image = (struct _XImage *(*)())(*env)->GetIntField(env,lpObject,lpXimageFc->create_image);
+ lpXimage->f.destroy_image = (int (*)(struct _XImage *))(*env)->GetIntField(env,lpObject,lpXimageFc->destroy_image);
+ lpXimage->f.get_pixel = (unsigned long (*)(struct _XImage *, int, int))(*env)->GetIntField(env,lpObject,lpXimageFc->get_pixel);
+ lpXimage->f.put_pixel = (int (*)(struct _XImage *, int, int, unsigned long))(*env)->GetIntField(env,lpObject,lpXimageFc->put_pixel);
+ lpXimage->f.sub_image = (struct _XImage *(*)(struct _XImage *, int, int, unsigned int, unsigned int))(*env)->GetIntField(env,lpObject,lpXimageFc->sub_image);
+ lpXimage->f.add_pixel = (int (*)(struct _XImage *, long))(*env)->GetIntField(env,lpObject,lpXimageFc->add_pixel);
+}
+
+void setXimageFields(JNIEnv *env, jobject lpObject, XImage *lpXimage, XIMAGE_FID_CACHE *lpXimageFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXimageFc->width, lpXimage->width);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->height, lpXimage->height);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->xoffset, lpXimage->xoffset);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->format, lpXimage->format);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->data, (jint)lpXimage->data);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->byte_order, lpXimage->byte_order);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->bitmap_unit, lpXimage->bitmap_unit);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->bitmap_bit_order, lpXimage->bitmap_bit_order);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->bitmap_pad, lpXimage->bitmap_pad);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->depth, lpXimage->depth);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->bytes_per_line, lpXimage->bytes_per_line);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->bits_per_pixel, lpXimage->bits_per_pixel);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->red_mask, lpXimage->red_mask);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->green_mask, lpXimage->green_mask);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->blue_mask, lpXimage->blue_mask);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->obdata, (jint)lpXimage->obdata);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->create_image, (jint)lpXimage->f.create_image);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->destroy_image, (jint)lpXimage->f.destroy_image);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->get_pixel, (jint)lpXimage->f.get_pixel);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->put_pixel, (jint)lpXimage->f.put_pixel);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->sub_image, (jint)lpXimage->f.sub_image);
+ (*env)->SetIntField(env,lpObject,lpXimageFc->add_pixel, (jint)lpXimage->f.add_pixel);
+}
+
+void getXkeyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XKEYEVENT_FID_CACHE *lpXkeyeventFc)
+{
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->type);
+ lpXevent->xkey.serial = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->serial);
+ lpXevent->xkey.send_event = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->send_event);
+ lpXevent->xkey.display = (Display *)(*env)->GetIntField(env,lpObject,lpXkeyeventFc->display);
+ lpXevent->xkey.window = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->window);
+ lpXevent->xkey.root = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->root);
+ lpXevent->xkey.subwindow = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->subwindow);
+ lpXevent->xkey.time = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->time);
+ lpXevent->xkey.x = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->x);
+ lpXevent->xkey.y = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->y);
+ lpXevent->xkey.x_root = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->x_root);
+ lpXevent->xkey.y_root = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->y_root);
+ lpXevent->xkey.state = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->state);
+ lpXevent->xkey.keycode = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->keycode);
+ lpXevent->xkey.same_screen = (*env)->GetIntField(env,lpObject,lpXkeyeventFc->same_screen);
+}
+
+void setXkeyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XKEYEVENT_FID_CACHE *lpXkeyeventFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->serial, lpXevent->xkey.serial);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->send_event, lpXevent->xkey.send_event);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->display, (int)lpXevent->xkey.display);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->window, lpXevent->xkey.window);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->root, lpXevent->xkey.root);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->subwindow, lpXevent->xkey.subwindow);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->time, lpXevent->xkey.time);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->x, lpXevent->xkey.x);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->y, lpXevent->xkey.y);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->x_root, lpXevent->xkey.x_root);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->y_root, lpXevent->xkey.y_root);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->state, lpXevent->xkey.state);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->keycode, lpXevent->xkey.keycode);
+ (*env)->SetIntField(env,lpObject,lpXkeyeventFc->same_screen, lpXevent->xkey.same_screen);
+}
+
+void getXmotioneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XMOTIONEVENT_FID_CACHE *lpXmotioneventFc)
+{
+ int i;
+
+ lpXevent->type = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->type);
+ lpXevent->xmotion.serial = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->serial);
+ lpXevent->xmotion.send_event = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->send_event);
+ lpXevent->xmotion.display = (Display *)(*env)->GetIntField(env,lpObject,lpXmotioneventFc->display);
+ lpXevent->xmotion.window = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->window);
+ lpXevent->xmotion.root = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->root);
+ lpXevent->xmotion.subwindow = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->subwindow);
+ lpXevent->xmotion.time = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->time);
+ lpXevent->xmotion.x = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->x);
+ lpXevent->xmotion.y = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->y);
+ lpXevent->xmotion.x_root = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->x_root);
+ lpXevent->xmotion.y_root = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->y_root);
+ lpXevent->xmotion.state = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->state);
+ lpXevent->xmotion.is_hint = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->is_hint);
+ lpXevent->xmotion.same_screen = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->same_screen);
+ for (i=0; i<10; i++) {
+ lpXevent->pad[i+15] = (*env)->GetIntField(env,lpObject,lpXmotioneventFc->pad[i]);
+ }
+}
+
+void setXmotioneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XMOTIONEVENT_FID_CACHE *lpXmotioneventFc)
+{
+ int i;
+
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->type, lpXevent->type);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->serial, lpXevent->xmotion.serial);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->send_event, lpXevent->xmotion.send_event);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->display, (int)lpXevent->xmotion.display);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->window, lpXevent->xmotion.window);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->root, lpXevent->xmotion.root);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->subwindow, lpXevent->xmotion.subwindow);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->time, lpXevent->xmotion.time);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->x, lpXevent->xmotion.x);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->y, lpXevent->xmotion.y);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->x_root, lpXevent->xmotion.x_root);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->y_root, lpXevent->xmotion.y_root);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->state, lpXevent->xmotion.state);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->is_hint, lpXevent->xmotion.is_hint);
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->same_screen, lpXevent->xmotion.same_screen);
+ for (i=0; i<10; i++) {
+ (*env)->SetIntField(env,lpObject,lpXmotioneventFc->pad[i],lpXevent->pad[i+15]);
+ }
+}
+
+void getXcolorFields(JNIEnv *env, jobject lpObject, XColor *lpXcolor, PXCOLOR_FID_CACHE lpXcolorFc)
+{
+ lpXcolor->pixel = (*env)->GetIntField(env,lpObject,lpXcolorFc->pixel);
+ lpXcolor->red = (*env)->GetShortField(env,lpObject,lpXcolorFc->red);
+ lpXcolor->green = (*env)->GetShortField(env,lpObject,lpXcolorFc->green);
+ lpXcolor->blue = (*env)->GetShortField(env,lpObject,lpXcolorFc->blue);
+ lpXcolor->flags = (*env)->GetByteField(env,lpObject,lpXcolorFc->flags);
+ lpXcolor->pad = (*env)->GetByteField(env,lpObject,lpXcolorFc->pad);
+}
+
+void setXcolorFields(JNIEnv *env, jobject lpObject, XColor *lpXcolor, PXCOLOR_FID_CACHE lpXcolorFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXcolorFc->pixel, lpXcolor->pixel);
+ (*env)->SetShortField(env,lpObject,lpXcolorFc->red, lpXcolor->red);
+ (*env)->SetShortField(env,lpObject,lpXcolorFc->green, lpXcolor->green);
+ (*env)->SetShortField(env,lpObject,lpXcolorFc->blue, lpXcolor->blue);
+ (*env)->SetByteField(env,lpObject,lpXcolorFc->flags, lpXcolor->flags);
+ (*env)->SetByteField(env,lpObject,lpXcolorFc->pad, lpXcolor->pad);
+}
+
+void getXgcvaluesFields(JNIEnv *env, jobject lpObject, XGCValues *lpXgcvalues, PXGCVALUES_FID_CACHE lpXgcvaluesFc)
+{
+ lpXgcvalues->function = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->function);
+ lpXgcvalues->plane_mask = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->plane_mask);
+ lpXgcvalues->foreground = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->foreground);
+ lpXgcvalues->background = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->background);
+ lpXgcvalues->line_width = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->line_width);
+ lpXgcvalues->line_style = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->line_style);
+ lpXgcvalues->cap_style = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->cap_style);
+ lpXgcvalues->join_style = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->join_style);
+ lpXgcvalues->fill_style = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->fill_style);
+ lpXgcvalues->fill_rule = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->fill_rule);
+ lpXgcvalues->arc_mode = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->arc_mode);
+ lpXgcvalues->tile = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->tile);
+ lpXgcvalues->stipple = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->stipple);
+ lpXgcvalues->ts_x_origin = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->ts_x_origin);
+ lpXgcvalues->ts_y_origin = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->ts_y_origin);
+ lpXgcvalues->font = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->font);
+ lpXgcvalues->subwindow_mode = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->subwindow_mode);
+ lpXgcvalues->graphics_exposures = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->graphics_exposures);
+ lpXgcvalues->clip_x_origin = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->clip_x_origin);
+ lpXgcvalues->clip_y_origin = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->clip_y_origin);
+ lpXgcvalues->clip_mask = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->clip_mask);
+ lpXgcvalues->dash_offset = (*env)->GetIntField(env,lpObject,lpXgcvaluesFc->dash_offset);
+ lpXgcvalues->dashes = (*env)->GetByteField(env,lpObject,lpXgcvaluesFc->dashes);
+}
+
+void setXgcvaluesFields(JNIEnv *env, jobject lpObject, XGCValues *lpXgcvalues, PXGCVALUES_FID_CACHE lpXgcvaluesFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->function, lpXgcvalues->function);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->plane_mask, lpXgcvalues->plane_mask);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->foreground, lpXgcvalues->foreground);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->background, lpXgcvalues->background);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->line_width, lpXgcvalues->line_width);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->line_style, lpXgcvalues->line_style);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->cap_style, lpXgcvalues->cap_style);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->join_style, lpXgcvalues->join_style);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->fill_style, lpXgcvalues->fill_style);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->fill_rule, lpXgcvalues->fill_rule);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->arc_mode, lpXgcvalues->arc_mode);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->tile, lpXgcvalues->tile);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->stipple, lpXgcvalues->stipple);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->ts_x_origin, lpXgcvalues->ts_x_origin);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->ts_y_origin, lpXgcvalues->ts_y_origin);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->font, lpXgcvalues->font);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->subwindow_mode, lpXgcvalues->subwindow_mode);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->graphics_exposures, lpXgcvalues->graphics_exposures);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->clip_x_origin, lpXgcvalues->clip_x_origin);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->clip_y_origin, lpXgcvalues->clip_y_origin);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->clip_mask, lpXgcvalues->clip_mask);
+ (*env)->SetIntField(env,lpObject,lpXgcvaluesFc->dash_offset, lpXgcvalues->dash_offset);
+
+ (*env)->SetByteField(env,lpObject,lpXgcvaluesFc->dashes, lpXgcvalues->dashes);
+}
+
+void getXmanycallbackstructFields(JNIEnv *env, jobject lpObject, XmAnyCallbackStruct *lpXmanycallbackstruct, PXMANYCALLBACKSTRUCT_FID_CACHE lpXmanycallbackstructFc)
+{
+ lpXmanycallbackstruct->reason = (*env)->GetIntField(env,lpObject,lpXmanycallbackstructFc->reason);
+ lpXmanycallbackstruct->event = (XEvent *)(*env)->GetIntField(env,lpObject,lpXmanycallbackstructFc->event);
+}
+
+void setXmanycallbackstructFields(JNIEnv *env, jobject lpObject, XmAnyCallbackStruct *lpXmanycallbackstruct, PXMANYCALLBACKSTRUCT_FID_CACHE lpXmanycallbackstructFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmanycallbackstructFc->reason, lpXmanycallbackstruct->reason);
+ (*env)->SetIntField(env,lpObject,lpXmanycallbackstructFc->event, (jint)lpXmanycallbackstruct->event);
+}
+
+void getXmdragproccallbackFields(JNIEnv *env, jobject lpObject, XmDragProcCallbackStruct *lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpXmdragproccallbackFc)
+{
+ lpXmdragproccallback->reason = (*env)->GetIntField(env,lpObject,lpXmdragproccallbackFc->reason);
+ lpXmdragproccallback->event = (XEvent *)(*env)->GetIntField(env,lpObject,lpXmdragproccallbackFc->event);
+ lpXmdragproccallback->timeStamp = (*env)->GetIntField(env,lpObject,lpXmdragproccallbackFc->timeStamp);
+ lpXmdragproccallback->dragContext = (Widget)(*env)->GetIntField(env,lpObject,lpXmdragproccallbackFc->dragContext);
+ lpXmdragproccallback->x = (*env)->GetShortField(env,lpObject,lpXmdragproccallbackFc->x);
+ lpXmdragproccallback->y = (*env)->GetShortField(env,lpObject,lpXmdragproccallbackFc->y);
+ lpXmdragproccallback->dropSiteStatus = (*env)->GetByteField(env,lpObject,lpXmdragproccallbackFc->dropSiteStatus);
+ lpXmdragproccallback->operation = (*env)->GetByteField(env,lpObject,lpXmdragproccallbackFc->operation);
+ lpXmdragproccallback->operations = (*env)->GetByteField(env,lpObject,lpXmdragproccallbackFc->operations);
+ lpXmdragproccallback->animate = (*env)->GetByteField(env,lpObject,lpXmdragproccallbackFc->animate);
+}
+
+void setXmdragproccallbackFields(JNIEnv *env, jobject lpObject, XmDragProcCallbackStruct *lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpXmdragproccallbackFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmdragproccallbackFc->reason, lpXmdragproccallback->reason);
+ (*env)->SetIntField(env,lpObject,lpXmdragproccallbackFc->event, (jint)lpXmdragproccallback->event);
+ (*env)->SetIntField(env,lpObject,lpXmdragproccallbackFc->timeStamp, lpXmdragproccallback->timeStamp);
+ (*env)->SetIntField(env,lpObject,lpXmdragproccallbackFc->dragContext, (jint)lpXmdragproccallback->dragContext);
+ (*env)->SetShortField(env,lpObject,lpXmdragproccallbackFc->x, lpXmdragproccallback->x);
+ (*env)->SetShortField(env,lpObject,lpXmdragproccallbackFc->y, lpXmdragproccallback->y);
+ (*env)->SetByteField(env,lpObject,lpXmdragproccallbackFc->dropSiteStatus, lpXmdragproccallback->dropSiteStatus);
+ (*env)->SetByteField(env,lpObject,lpXmdragproccallbackFc->operation, lpXmdragproccallback->operation);
+ (*env)->SetByteField(env,lpObject,lpXmdragproccallbackFc->operations, lpXmdragproccallback->operations);
+ (*env)->SetByteField(env,lpObject,lpXmdragproccallbackFc->animate, lpXmdragproccallback->animate);
+}
+
+void getXmdropproccallbackFields(JNIEnv *env, jobject lpObject, XmDropProcCallbackStruct *lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpXmdropproccallbackFc)
+{
+ lpXmdropproccallback->reason = (*env)->GetIntField(env,lpObject,lpXmdropproccallbackFc->reason);
+ lpXmdropproccallback->event = (XEvent *)(*env)->GetIntField(env,lpObject,lpXmdropproccallbackFc->event);
+ lpXmdropproccallback->timeStamp = (*env)->GetIntField(env,lpObject,lpXmdropproccallbackFc->timeStamp);
+ lpXmdropproccallback->dragContext = (Widget)(*env)->GetIntField(env,lpObject,lpXmdropproccallbackFc->dragContext);
+ lpXmdropproccallback->x = (*env)->GetShortField(env,lpObject,lpXmdropproccallbackFc->x);
+ lpXmdropproccallback->y = (*env)->GetShortField(env,lpObject,lpXmdropproccallbackFc->y);
+ lpXmdropproccallback->dropSiteStatus = (*env)->GetByteField(env,lpObject,lpXmdropproccallbackFc->dropSiteStatus);
+ lpXmdropproccallback->operation = (*env)->GetByteField(env,lpObject,lpXmdropproccallbackFc->operation);
+ lpXmdropproccallback->operations = (*env)->GetByteField(env,lpObject,lpXmdropproccallbackFc->operations);
+ lpXmdropproccallback->dropAction = (*env)->GetByteField(env,lpObject,lpXmdropproccallbackFc->dropAction);
+}
+
+void setXmdropproccallbackFields(JNIEnv *env, jobject lpObject, XmDropProcCallbackStruct *lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpXmdropproccallbackFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmdropproccallbackFc->reason, lpXmdropproccallback->reason);
+ (*env)->SetIntField(env,lpObject,lpXmdropproccallbackFc->event, (jint)lpXmdropproccallback->event);
+ (*env)->SetIntField(env,lpObject,lpXmdropproccallbackFc->timeStamp, lpXmdropproccallback->timeStamp);
+ (*env)->SetIntField(env,lpObject,lpXmdropproccallbackFc->dragContext, (jint)lpXmdropproccallback->dragContext);
+ (*env)->SetShortField(env,lpObject,lpXmdropproccallbackFc->x, lpXmdropproccallback->x);
+ (*env)->SetShortField(env,lpObject,lpXmdropproccallbackFc->y, lpXmdropproccallback->y);
+ (*env)->SetByteField(env,lpObject,lpXmdropproccallbackFc->dropSiteStatus, lpXmdropproccallback->dropSiteStatus);
+ (*env)->SetByteField(env,lpObject,lpXmdropproccallbackFc->operation, lpXmdropproccallback->operation);
+ (*env)->SetByteField(env,lpObject,lpXmdropproccallbackFc->operations, lpXmdropproccallback->operations);
+ (*env)->SetByteField(env,lpObject,lpXmdropproccallbackFc->dropAction, lpXmdropproccallback->dropAction);
+}
+
+void getXmdropfinishcallbackFields(JNIEnv *env, jobject lpObject, XmDropFinishCallbackStruct *lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpXmdropfinishcallbackFc)
+{
+ lpXmdropfinishcallback->reason = (*env)->GetIntField(env,lpObject,lpXmdropfinishcallbackFc->reason);
+ lpXmdropfinishcallback->event = (XEvent *)(*env)->GetIntField(env,lpObject,lpXmdropfinishcallbackFc->event);
+ lpXmdropfinishcallback->timeStamp = (*env)->GetIntField(env,lpObject,lpXmdropfinishcallbackFc->timeStamp);
+ lpXmdropfinishcallback->operation = (*env)->GetByteField(env,lpObject,lpXmdropfinishcallbackFc->operation);
+ lpXmdropfinishcallback->operations = (*env)->GetByteField(env,lpObject,lpXmdropfinishcallbackFc->operations);
+ lpXmdropfinishcallback->dropSiteStatus = (*env)->GetByteField(env,lpObject,lpXmdropfinishcallbackFc->dropSiteStatus);
+ lpXmdropfinishcallback->dropAction = (*env)->GetByteField(env,lpObject,lpXmdropfinishcallbackFc->dropAction);
+ lpXmdropfinishcallback->completionStatus = (*env)->GetByteField(env,lpObject,lpXmdropfinishcallbackFc->completionStatus);
+}
+
+void setXmdropfinishcallbackFields(JNIEnv *env, jobject lpObject, XmDropFinishCallbackStruct *lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpXmdropfinishcallbackFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmdropfinishcallbackFc->reason, lpXmdropfinishcallback->reason);
+ (*env)->SetIntField(env,lpObject,lpXmdropfinishcallbackFc->event, (jint)lpXmdropfinishcallback->event);
+ (*env)->SetIntField(env,lpObject,lpXmdropfinishcallbackFc->timeStamp, lpXmdropfinishcallback->timeStamp);
+ (*env)->SetByteField(env,lpObject,lpXmdropfinishcallbackFc->operation, lpXmdropfinishcallback->operation);
+ (*env)->SetByteField(env,lpObject,lpXmdropfinishcallbackFc->operations, lpXmdropfinishcallback->operations);
+ (*env)->SetByteField(env,lpObject,lpXmdropfinishcallbackFc->dropSiteStatus, lpXmdropfinishcallback->dropSiteStatus);
+ (*env)->SetByteField(env,lpObject,lpXmdropfinishcallbackFc->dropAction, lpXmdropfinishcallback->dropAction);
+ (*env)->SetByteField(env,lpObject,lpXmdropfinishcallbackFc->completionStatus, lpXmdropfinishcallback->completionStatus);
+}
+
+void getXmtextblockrecFields(JNIEnv *env, jobject lpObject, XmTextBlockRec *lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpXmtextblockrecFc)
+{
+ lpXmtextblockrec->ptr = (char *)(*env)->GetIntField(env,lpObject,lpXmtextblockrecFc->ptr);
+ lpXmtextblockrec->length = (*env)->GetIntField(env,lpObject,lpXmtextblockrecFc->length);
+ lpXmtextblockrec->format = (XmTextFormat)(*env)->GetIntField(env,lpObject,lpXmtextblockrecFc->format);
+}
+
+void setXmtextblockrecFields(JNIEnv *env, jobject lpObject, XmTextBlockRec *lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpXmtextblockrecFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmtextblockrecFc->ptr, (jint)lpXmtextblockrec->ptr);
+ (*env)->SetIntField(env,lpObject,lpXmtextblockrecFc->length, lpXmtextblockrec->length);
+ (*env)->SetIntField(env,lpObject,lpXmtextblockrecFc->format, (jint)lpXmtextblockrec->format);
+}
+
+void getXmtextverifycallbackstructFields(JNIEnv *env, jobject lpObject, XmTextVerifyCallbackStruct *lpXmtextverifycallbackstruct, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpXmtextverifycallbackstructFc)
+{
+ lpXmtextverifycallbackstruct->reason = (*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->reason);
+ lpXmtextverifycallbackstruct->event = (XEvent *)(*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->event);
+ lpXmtextverifycallbackstruct->doit = (Boolean)(*env)->GetByteField(env,lpObject,lpXmtextverifycallbackstructFc->doit);
+ lpXmtextverifycallbackstruct->currInsert = (*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->currInsert);
+ lpXmtextverifycallbackstruct->newInsert = (*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->newInsert);
+ lpXmtextverifycallbackstruct->startPos = (*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->startPos);
+ lpXmtextverifycallbackstruct->endPos = (*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->endPos);
+ lpXmtextverifycallbackstruct->text = (XmTextBlock)(*env)->GetIntField(env,lpObject,lpXmtextverifycallbackstructFc->text);
+}
+
+void setXmtextverifycallbackstructFields(JNIEnv *env, jobject lpObject, XmTextVerifyCallbackStruct *lpXmtextverifycallbackstruct, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpXmtextverifycallbackstructFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->reason, lpXmtextverifycallbackstruct->reason);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->event, (jint)lpXmtextverifycallbackstruct->event);
+ (*env)->SetByteField(env,lpObject,lpXmtextverifycallbackstructFc->doit, (jint)lpXmtextverifycallbackstruct->doit);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->currInsert, lpXmtextverifycallbackstruct->currInsert);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->newInsert, lpXmtextverifycallbackstruct->newInsert);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->startPos, lpXmtextverifycallbackstruct->startPos);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->endPos, lpXmtextverifycallbackstruct->endPos);
+ (*env)->SetIntField(env,lpObject,lpXmtextverifycallbackstructFc->text, (jint)lpXmtextverifycallbackstruct->text);
+}
+
+void getXrectangleFields(JNIEnv *env, jobject lpObject, XRectangle *lpXrect, PXRECTANGLE_FID_CACHE lpXrectFc)
+{
+ lpXrect->x = (*env)->GetShortField(env,lpObject,lpXrectFc->x);
+ lpXrect->y = (*env)->GetShortField(env,lpObject,lpXrectFc->y);
+ lpXrect->width = (*env)->GetShortField(env,lpObject,lpXrectFc->width);
+ lpXrect->height = (*env)->GetShortField(env,lpObject,lpXrectFc->height);
+}
+
+void setXrectangleFields(JNIEnv *env, jobject lpObject, XRectangle *lpXrect, PXRECTANGLE_FID_CACHE lpXrectFc)
+{
+ (*env)->SetShortField(env,lpObject,lpXrectFc->x, lpXrect->x);
+ (*env)->SetShortField(env,lpObject,lpXrectFc->y, lpXrect->y);
+ (*env)->SetShortField(env,lpObject,lpXrectFc->width, lpXrect->width);
+ (*env)->SetShortField(env,lpObject,lpXrectFc->height, lpXrect->height);
+}
+
+void getXsetwindowattributesFields(JNIEnv *env, jobject lpObject, XSetWindowAttributes *lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpXsetwindowattributesFc)
+{
+ lpXsetwindowattributes->background_pixmap = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->background_pixmap);
+ lpXsetwindowattributes->background_pixel = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->background_pixel);
+ lpXsetwindowattributes->border_pixmap = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->border_pixmap);
+ lpXsetwindowattributes->border_pixel = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->border_pixel);
+ lpXsetwindowattributes->bit_gravity = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->bit_gravity);
+ lpXsetwindowattributes->win_gravity = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->win_gravity);
+ lpXsetwindowattributes->backing_store = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->backing_store);
+ lpXsetwindowattributes->backing_planes = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->backing_planes);
+ lpXsetwindowattributes->backing_pixel = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->backing_pixel);
+ lpXsetwindowattributes->save_under = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->save_under);
+ lpXsetwindowattributes->event_mask = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->event_mask);
+ lpXsetwindowattributes->do_not_propagate_mask = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->do_not_propagate_mask);
+ lpXsetwindowattributes->override_redirect = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->override_redirect);
+ lpXsetwindowattributes->colormap = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->colormap);
+ lpXsetwindowattributes->cursor = (*env)->GetIntField(env,lpObject,lpXsetwindowattributesFc->cursor);
+}
+
+void setXsetwindowattributesFields(JNIEnv *env, jobject lpObject, XSetWindowAttributes *lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpXsetwindowattributesFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->background_pixmap, lpXsetwindowattributes->background_pixmap);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->background_pixel, lpXsetwindowattributes->background_pixel);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->border_pixmap, lpXsetwindowattributes->border_pixmap);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->border_pixel, lpXsetwindowattributes->border_pixel);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->bit_gravity, lpXsetwindowattributes->bit_gravity);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->win_gravity, lpXsetwindowattributes->win_gravity);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->backing_store, lpXsetwindowattributes->backing_store);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->backing_planes, lpXsetwindowattributes->backing_planes);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->backing_pixel, lpXsetwindowattributes->backing_pixel);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->save_under, lpXsetwindowattributes->save_under);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->event_mask, lpXsetwindowattributes->event_mask);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->do_not_propagate_mask, lpXsetwindowattributes->do_not_propagate_mask);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->override_redirect, lpXsetwindowattributes->override_redirect);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->colormap, lpXsetwindowattributes->colormap);
+ (*env)->SetIntField(env,lpObject,lpXsetwindowattributesFc->cursor, lpXsetwindowattributes->cursor);
+}
+
+void getXwindowattributesFields(JNIEnv *env, jobject lpObject, XWindowAttributes *lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpXwindowattributesFc)
+{
+ lpXwindowattributes->x = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->x);
+ lpXwindowattributes->y = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->y);
+ lpXwindowattributes->width = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->width);
+ lpXwindowattributes->height = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->height);
+ lpXwindowattributes->border_width = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->border_width);
+ lpXwindowattributes->depth = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->depth);
+ lpXwindowattributes->visual = (Visual *)(*env)->GetIntField(env,lpObject,lpXwindowattributesFc->visual);
+ lpXwindowattributes->root = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->root);
+ lpXwindowattributes->class = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->class);
+ lpXwindowattributes->bit_gravity = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->bit_gravity);
+ lpXwindowattributes->win_gravity = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->win_gravity);
+ lpXwindowattributes->backing_store = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->backing_store);
+ lpXwindowattributes->backing_planes = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->backing_planes);
+ lpXwindowattributes->backing_pixel = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->backing_pixel);
+ lpXwindowattributes->save_under = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->save_under);
+ lpXwindowattributes->colormap = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->colormap);
+ lpXwindowattributes->map_installed = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->map_installed);
+ lpXwindowattributes->map_state = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->map_state);
+ lpXwindowattributes->all_event_masks = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->all_event_masks);
+ lpXwindowattributes->your_event_mask = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->your_event_mask);
+ lpXwindowattributes->do_not_propagate_mask = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->do_not_propagate_mask);
+ lpXwindowattributes->override_redirect = (*env)->GetIntField(env,lpObject,lpXwindowattributesFc->override_redirect);
+ lpXwindowattributes->screen = (Screen *)(*env)->GetIntField(env,lpObject,lpXwindowattributesFc->screen);
+}
+
+void setXwindowattributesFields(JNIEnv *env, jobject lpObject, XWindowAttributes *lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpXwindowattributesFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->x, lpXwindowattributes->x);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->y, lpXwindowattributes->y);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->width, lpXwindowattributes->width);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->height, lpXwindowattributes->height);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->border_width, lpXwindowattributes->border_width);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->depth, lpXwindowattributes->depth);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->visual, (int)lpXwindowattributes->visual);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->root, lpXwindowattributes->root);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->class, lpXwindowattributes->class);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->bit_gravity, lpXwindowattributes->bit_gravity);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->win_gravity, lpXwindowattributes->win_gravity);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->backing_store, lpXwindowattributes->backing_store);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->backing_planes, lpXwindowattributes->backing_planes);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->backing_pixel, lpXwindowattributes->backing_pixel);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->save_under, lpXwindowattributes->save_under);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->colormap, lpXwindowattributes->colormap);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->map_installed, lpXwindowattributes->map_installed);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->map_state, lpXwindowattributes->map_state);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->all_event_masks, lpXwindowattributes->all_event_masks);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->your_event_mask, lpXwindowattributes->your_event_mask);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->do_not_propagate_mask, lpXwindowattributes->do_not_propagate_mask);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->override_redirect, lpXwindowattributes->override_redirect);
+ (*env)->SetIntField(env,lpObject,lpXwindowattributesFc->screen, (int)lpXwindowattributes->screen);
+}
+
+void getXwindowchangesFields(JNIEnv *env, jobject lpObject, XWindowChanges *lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpXwindowchangesFc)
+{
+ lpXwindowchanges->x = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->x);
+ lpXwindowchanges->y = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->y);
+ lpXwindowchanges->width = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->width);
+ lpXwindowchanges->height = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->height);
+ lpXwindowchanges->border_width = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->border_width);
+ lpXwindowchanges->sibling = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->sibling);
+ lpXwindowchanges->stack_mode = (*env)->GetIntField(env,lpObject,lpXwindowchangesFc->stack_mode);
+}
+
+void setXwindowchangesFields(JNIEnv *env, jobject lpObject, XWindowChanges *lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpXwindowchangesFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->x, lpXwindowchanges->x);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->y, lpXwindowchanges->y);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->width, lpXwindowchanges->width);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->height, lpXwindowchanges->height);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->border_width, lpXwindowchanges->border_width);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->sibling, lpXwindowchanges->sibling);
+ (*env)->SetIntField(env,lpObject,lpXwindowchangesFc->stack_mode, lpXwindowchanges->stack_mode);
+}
+
+void getXtwidgetgeometryFields(JNIEnv *env, jobject lpObject, XtWidgetGeometry *lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpXtwidgetgeometryFc)
+{
+ lpXtwidgetgeometry->request_mode = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->request_mode);
+ lpXtwidgetgeometry->x = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->x);
+ lpXtwidgetgeometry->y = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->y);
+ lpXtwidgetgeometry->width = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->width);
+ lpXtwidgetgeometry->height = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->height);
+ lpXtwidgetgeometry->border_width = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->border_width);
+ lpXtwidgetgeometry->sibling = (Widget)(*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->sibling);
+ lpXtwidgetgeometry->stack_mode = (*env)->GetIntField(env,lpObject,lpXtwidgetgeometryFc->stack_mode);
+}
+
+void setXtwidgetgeometryFields(JNIEnv *env, jobject lpObject, XtWidgetGeometry *lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpXtwidgetgeometryFc)
+{
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->request_mode, lpXtwidgetgeometry->request_mode);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->x, lpXtwidgetgeometry->x);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->y, lpXtwidgetgeometry->y);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->width, lpXtwidgetgeometry->width);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->height, lpXtwidgetgeometry->height);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->border_width, lpXtwidgetgeometry->border_width);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->sibling, (int)lpXtwidgetgeometry->sibling);
+ (*env)->SetIntField(env,lpObject,lpXtwidgetgeometryFc->stack_mode, lpXtwidgetgeometry->stack_mode);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.h b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.h
new file mode 100755
index 0000000000..27368d54e0
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/structs.h
@@ -0,0 +1,459 @@
+/**
+ * JNI SWT object field getters and setters declarations for Motif structs
+ */
+
+#ifndef INC_structs_H
+#define INC_structs_H
+
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/IntrinsicP.h>
+#include <X11/Intrinsic.h>
+#include <X11/Shell.h>
+#include <X11/keysym.h>
+
+#include <Xm/XmAll.h>
+#include <Mrm/MrmPublic.h>
+
+/* All globals declared in globals.h */
+#define FID_CACHE_GLOBALS \
+ VISUAL_FID_CACHE VisualFc; \
+ XANYEVENT_FID_CACHE XanyeventFc; \
+ XBUTTONEVENT_FID_CACHE XbuttoneventFc; \
+ XCHARSTRUCT_FID_CACHE XcharstructFc; \
+ XCOLOR_FID_CACHE XcolorFc; \
+ XCONFIGUREEVENT_FID_CACHE XconfigureeventFc; \
+ XCROSSINGEVENT_FID_CACHE XcrossingeventFc; \
+ XEXPOSEEVENT_FID_CACHE XexposeeventFc; \
+ XFOCUSCHANGEEVENT_FID_CACHE XfocuschangeeventFc; \
+ XFONTSTRUCT_FID_CACHE XfontstructFc; \
+ XGCVALUES_FID_CACHE XgcvaluesFc; \
+ XIMAGE_FID_CACHE XimageFc; \
+ XKEYEVENT_FID_CACHE XkeyeventFc; \
+ XMANYCALLBACKSTRUCT_FID_CACHE XmanycallbackstructFc; \
+ XMDRAGPROCCALLBACK_FID_CACHE XmdragproccallbackFc; \
+ XMDROPFINISHCALLBACK_FID_CACHE XmdropfinishcallbackFc; \
+ XMDROPPROCCALLBACK_FID_CACHE XmdropproccallbackFc; \
+ XMOTIONEVENT_FID_CACHE XmotioneventFc; \
+ XMTEXTBLOCKREC_FID_CACHE XmtextblockrecFc; \
+ XMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE XmtextverifycallbackstructFc; \
+ XRECTANGLE_FID_CACHE XrectangleFc; \
+ XSETWINDOWATTRIBUTES_FID_CACHE XsetwindowattributesFc; \
+ XTWIDGETGEOMETRY_FID_CACHE XtwidgetgeometryFc; \
+ XWINDOWATTRIBUTES_FID_CACHE XwindowattributesFc; \
+ XWINDOWCHANGES_FID_CACHE XwindowchangesFc;
+
+/* ----------- fid and class caches ----------- */
+/**
+ * Used for Java objects passed into JNI that are
+ * declared like:
+ *
+ * nativeFunction (Rectangle p1, Rectangle p2, Rectangle p3)
+ *
+ * and not like this
+ *
+ * nativeFunction (Object p1, Object p2, Object p3)
+ *
+ *
+ */
+
+/* VISUAL struct */
+typedef struct VISUAL_FID_CACHE {
+
+ int cached;
+ jclass visualClass;
+ jfieldID ext_data, visualid, c_class, red_mask, green_mask, blue_mask, bits_per_rgb, map_entries;
+
+} VISUAL_FID_CACHE;
+
+typedef VISUAL_FID_CACHE *PVISUAL_FID_CACHE;
+
+/* XANYEVENT struct */
+typedef struct XANYEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, pad[19];
+/*
+ pad0, pad1, pad2, pad3,
+ pad4, pad5, pad6, pad7, pad8, pad9, pad10, pad11, pad12, pad13
+ pad14, pad15, pad16, pad17, pad18;
+*/
+
+} XANYEVENT_FID_CACHE;
+
+typedef XANYEVENT_FID_CACHE *PXANYEVENT_FID_CACHE;
+
+/* XBUTTONEVENT struct */
+typedef struct XBUTTONEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, x_root, y_root, state, button, same_screen;
+
+} XBUTTONEVENT_FID_CACHE;
+
+typedef XBUTTONEVENT_FID_CACHE *PXBUTTONEVENT_FID_CACHE;
+
+/* XCHARSTRUCT struct */
+typedef struct XCHARSTRUCT_FID_CACHE {
+
+ int cached;
+ jclass xcharstructClass;
+ jfieldID lbearing, rbearing, width, ascent, descent, attributes;
+
+} XCHARSTRUCT_FID_CACHE;
+
+typedef XCHARSTRUCT_FID_CACHE *PXCHARSTRUCT_FID_CACHE;
+
+/* XCONFIGUREEVENT struct */
+typedef struct XCONFIGUREEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, width, height, border_width, above, override_redirect;
+
+} XCONFIGUREEVENT_FID_CACHE;
+
+typedef XCONFIGUREEVENT_FID_CACHE *PXCONFIGUREEVENT_FID_CACHE;
+
+/* XCROSSINGEVENT struct */
+typedef struct XCROSSINGEVENT_FID_CACHE {
+
+ int cached;
+ jclass xcrossingeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, x_root, y_root, mode, detail, same_screen, focus,
+ state, pad[8];
+/*
+ pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7;
+*/
+
+} XCROSSINGEVENT_FID_CACHE;
+
+typedef XCROSSINGEVENT_FID_CACHE *PXCROSSINGEVENT_FID_CACHE;
+
+/* XEXPOSEEVENT struct */
+typedef struct XEXPOSEEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, width, height, count;
+
+} XEXPOSEEVENT_FID_CACHE;
+
+typedef XEXPOSEEVENT_FID_CACHE *PXEXPOSEEVENT_FID_CACHE;
+
+/* XFOCUSCHANGEEVENT struct */
+typedef struct XFOCUSCHANGEEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, mode, detail, pad[17];
+
+} XFOCUSCHANGEEVENT_FID_CACHE;
+
+typedef XFOCUSCHANGEEVENT_FID_CACHE *PXFOCUSCHANGEEVENT_FID_CACHE;
+
+/* XFONTSTRUCT struct */
+typedef struct XFONTSTRUCT_FID_CACHE {
+
+ int cached;
+ jclass xfontstructClass;
+ jfieldID ext_data, fid, direction, min_char_or_byte2, max_char_or_byte2, \
+ min_byte1, max_byte1, all_chars_exist, default_char, n_properties, \
+ properties, min_bounds_lbearing, min_bounds_rbearing, min_bounds_width, \
+ min_bounds_ascent, min_bounds_descent, min_bounds_attributes, \
+ max_bounds_lbearing, max_bounds_rbearing, max_bounds_width, \
+ max_bounds_ascent, max_bounds_descent, max_bounds_attributes, per_char, \
+ ascent, descent;
+
+} XFONTSTRUCT_FID_CACHE;
+
+typedef XFONTSTRUCT_FID_CACHE *PXFONTSTRUCT_FID_CACHE;
+
+/* XIMAGE struct */
+typedef struct XIMAGE_FID_CACHE {
+
+ int cached;
+ jclass ximageClass;
+ jfieldID width, height, xoffset, format, data, byte_order, bitmap_unit,
+ bitmap_bit_order, bitmap_pad, depth, bytes_per_line, bits_per_pixel,
+ red_mask, green_mask, blue_mask, obdata, create_image, destroy_image,
+ get_pixel, put_pixel, sub_image, add_pixel;
+
+} XIMAGE_FID_CACHE;
+
+typedef XIMAGE_FID_CACHE *PXIMAGE_FID_CACHE;
+
+/* XKEYEVENT struct */
+typedef struct XKEYEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, x_root, y_root, state, keycode, same_screen;
+
+} XKEYEVENT_FID_CACHE;
+
+typedef XKEYEVENT_FID_CACHE *PXKEYEVENT_FID_CACHE;
+
+/* XMOTIONEVENT struct */
+typedef struct XMOTIONEVENT_FID_CACHE {
+
+ int cached;
+ jclass xeventClass;
+ jfieldID type, serial, send_event, display, window, root, subwindow, time,
+ x, y, x_root, y_root, state, is_hint, same_screen, pad[10];
+
+} XMOTIONEVENT_FID_CACHE;
+
+typedef XMOTIONEVENT_FID_CACHE *PXMOTIONEVENT_FID_CACHE;
+
+/* XCOLOR struct */
+typedef struct XCOLOR_FID_CACHE {
+
+ int cached;
+ jclass xcolorClass;
+ jfieldID pixel, red, green, blue, flags, pad;
+
+} XCOLOR_FID_CACHE;
+
+typedef XCOLOR_FID_CACHE *PXCOLOR_FID_CACHE;
+
+/* XGCVALUES struct */
+typedef struct XGCVALUES_FID_CACHE {
+
+ int cached;
+ jclass xgcvaluesClass;
+ jfieldID function, plane_mask, foreground, background, line_width, line_style, cap_style,
+ join_style, fill_style, fill_rule, arc_mode, tile, stipple, ts_x_origin, ts_y_origin,
+ font, subwindow_mode, graphics_exposures, clip_x_origin, clip_y_origin, clip_mask,
+ dash_offset, dashes;
+
+} XGCVALUES_FID_CACHE;
+
+typedef XGCVALUES_FID_CACHE *PXGCVALUES_FID_CACHE;
+
+/* XMANYCALLBACKSTRUCT struct */
+typedef struct XMANYCALLBACKSTRUCT_FID_CACHE {
+
+ int cached;
+ jclass xmanycallbackstructClass;
+ jfieldID reason, event;
+
+} XMANYCALLBACKSTRUCT_FID_CACHE;
+
+typedef XMANYCALLBACKSTRUCT_FID_CACHE *PXMANYCALLBACKSTRUCT_FID_CACHE;
+
+/* XMDRAGPROCCALLBACK struct */
+typedef struct XMDRAGPROCCALLBACK_FID_CACHE {
+
+ int cached;
+ jclass xmdragproccallbackClass;
+ jfieldID reason, event, timeStamp, dragContext, x, y,
+ dropSiteStatus, operation, operations, animate;
+
+} XMDRAGPROCCALLBACK_FID_CACHE;
+
+typedef XMDRAGPROCCALLBACK_FID_CACHE *PXMDRAGPROCCALLBACK_FID_CACHE;
+
+/* XMDROPPROCCALLBACK struct */
+typedef struct XMDROPPROCCALLBACK_FID_CACHE {
+
+ int cached;
+ jclass xmdropproccallbackClass;
+ jfieldID reason, event, timeStamp, dragContext, x, y,
+ dropSiteStatus, operation, operations, dropAction;
+
+} XMDROPPROCCALLBACK_FID_CACHE;
+
+typedef XMDROPPROCCALLBACK_FID_CACHE *PXMDROPPROCCALLBACK_FID_CACHE;
+
+/* XMDROPFINISHCALLBACK struct */
+typedef struct XMDROPFINISHCALLBACK_FID_CACHE {
+
+ int cached;
+ jclass xmdropfinishcallbackClass;
+ jfieldID reason, event, timeStamp,
+ operation, operations, dropSiteStatus, dropAction, completionStatus;
+
+} XMDROPFINISHCALLBACK_FID_CACHE;
+
+typedef XMDROPFINISHCALLBACK_FID_CACHE *PXMDROPFINISHCALLBACK_FID_CACHE;
+
+/* XMTEXTBLOCKREC struct */
+typedef struct XMTEXTBLOCKREC_FID_CACHE {
+
+ int cached;
+ jclass xmtextblockrecClass;
+ jfieldID ptr, length, format;
+
+} XMTEXTBLOCKREC_FID_CACHE;
+
+typedef XMTEXTBLOCKREC_FID_CACHE *PXMTEXTBLOCKREC_FID_CACHE;
+
+/* XMTEXTVERIFYCALLBACKSTRUCT struct */
+typedef struct XMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE {
+
+ int cached;
+ jclass xmtextverifycallbackstructClass;
+ jfieldID reason, event, doit, currInsert, newInsert, startPos, endPos, text;
+
+} XMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE;
+
+typedef XMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE *PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE;
+
+/* XRECTANGLE struct */
+typedef struct XRECTANGLE_FID_CACHE {
+
+ int cached;
+ jclass xrectClass;
+ jfieldID x, y, width, height;
+
+} XRECTANGLE_FID_CACHE;
+
+typedef XRECTANGLE_FID_CACHE *PXRECTANGLE_FID_CACHE;
+
+/* XWINDOWCHANGES struct */
+typedef struct XWINDOWCHANGES_FID_CACHE {
+
+ int cached;
+ jclass xwindowchangesClass;
+ jfieldID x, y, width, height, border_width, sibling, stack_mode;
+
+} XWINDOWCHANGES_FID_CACHE;
+
+typedef XWINDOWCHANGES_FID_CACHE *PXWINDOWCHANGES_FID_CACHE;
+
+/* XSETWINDOWATTRIBUTES struct */
+typedef struct XSETWINDOWATTRIBUTES_FID_CACHE {
+
+ int cached;
+ jclass xsetwindowattributesClass;
+ jfieldID background_pixmap, background_pixel, border_pixmap, border_pixel, bit_gravity, win_gravity,
+ backing_store, backing_planes, backing_pixel, save_under, event_mask, do_not_propagate_mask,
+ override_redirect, colormap, cursor;
+
+} XSETWINDOWATTRIBUTES_FID_CACHE;
+
+typedef XSETWINDOWATTRIBUTES_FID_CACHE *PXSETWINDOWATTRIBUTES_FID_CACHE;
+
+/* XWINDOWATTRIBUTES struct */
+typedef struct XWINDOWATTRIBUTES_FID_CACHE {
+
+ int cached;
+ jclass xwindowattributesClass;
+ jfieldID x, y, width, height, border_width, depth, visual, root,
+ class, bit_gravity, win_gravity, backing_store, backing_planes,
+ backing_pixel, save_under, colormap, map_installed, map_state, all_event_masks,
+ your_event_mask, do_not_propagate_mask, override_redirect, screen;
+
+} XWINDOWATTRIBUTES_FID_CACHE;
+
+typedef XWINDOWATTRIBUTES_FID_CACHE *PXWINDOWATTRIBUTES_FID_CACHE;
+
+/* XTWIDGETGEOMETRY struct */
+typedef struct XTWIDGETGEOMETRY_FID_CACHE {
+
+ int cached;
+ jclass xtwidgetgeometryClass;
+ jfieldID request_mode, x, y, width, height, border_width, sibling, stack_mode;
+
+} XTWIDGETGEOMETRY_FID_CACHE;
+
+typedef XTWIDGETGEOMETRY_FID_CACHE *PXTWIDGETGEOMETRY_FID_CACHE;
+
+/* ----------- cache function prototypes ----------- */
+
+void cacheXimageFids(JNIEnv *env, jobject lpXimage, PXIMAGE_FID_CACHE lpCache);
+void cacheVisualFids(JNIEnv *env, jobject lpVisual, PVISUAL_FID_CACHE lpCache);
+void cacheXanyeventFids(JNIEnv *env, jobject lpXevent, PXANYEVENT_FID_CACHE lpCache);
+void cacheXbuttoneventFids(JNIEnv *env, jobject lpXevent, PXBUTTONEVENT_FID_CACHE lpCache);
+void cacheXcharstructFids(JNIEnv *env, jobject lpXcharstruct, PXCHARSTRUCT_FID_CACHE lpCache);
+void cacheXconfigureeventFids(JNIEnv *env, jobject lpXevent, PXCONFIGUREEVENT_FID_CACHE lpCache);
+void cacheXcrossingeventFids(JNIEnv *env, jobject lpXcrossingevent, PXCROSSINGEVENT_FID_CACHE lpCache);
+void cacheXexposeeventFids(JNIEnv *env, jobject lpXevent, PXEXPOSEEVENT_FID_CACHE lpCache);
+void cacheXfocuschangeeventFids(JNIEnv *env, jobject lpXevent, PXFOCUSCHANGEEVENT_FID_CACHE lpCache);
+void cacheXfontstructFids(JNIEnv *env, jobject lpXfontstruct, PXFONTSTRUCT_FID_CACHE lpCache);
+void cacheXkeyeventFids(JNIEnv *env, jobject lpXevent, PXKEYEVENT_FID_CACHE lpCache);
+void cacheXmotioneventFids(JNIEnv *env, jobject lpXevent, PXMOTIONEVENT_FID_CACHE lpCache);
+void cacheXanyeventFids(JNIEnv *env, jobject lpXevent, PXANYEVENT_FID_CACHE lpCache);
+void cacheXcolorFids(JNIEnv *env, jobject lpXcolor, PXCOLOR_FID_CACHE lpCache);
+void cacheXgcvaluesFids(JNIEnv *env, jobject lpXgcvalues, PXGCVALUES_FID_CACHE lpCache);
+void cacheXmanycallbackstructFids(JNIEnv *env, jobject lpXmanycallbackstruct, PXMANYCALLBACKSTRUCT_FID_CACHE lpCache);
+void cacheXmdragproccallbackFids(JNIEnv *env, jobject lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpCache);
+void cacheXmdropproccallbackFids(JNIEnv *env, jobject lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpCache);
+void cacheXmdropfinishcallbackFids(JNIEnv *env, jobject lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpCache);
+void cacheXmtextblockrecFids(JNIEnv *env, jobject lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpCache);
+void cacheXmtextverifycallbackstructFids(JNIEnv *env, jobject lpXmtextverifycallbackstruct, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpCache);
+void cacheXrectangleFids(JNIEnv *env, jobject lpRect, PXRECTANGLE_FID_CACHE lpCache);
+void cacheXwindowchangesFids(JNIEnv *env, jobject lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpCache);
+void cacheXsetwindowattributesFids(JNIEnv *env, jobject lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpCache);
+void cacheXwindowattributesFids(JNIEnv *env, jobject lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpCache);
+void cacheXtwidgetgeometryFids(JNIEnv *env, jobject lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpCache);
+
+/* ----------- getters and setters ----------- */
+/**
+ * These functions get or set object field ids assuming that the
+ * fids for these objects have already been cached.
+ *
+ * The header file just contains function prototypes
+ */
+
+void getVisualFields(JNIEnv *env, jobject lpObject, Visual *lpVisual, VISUAL_FID_CACHE *lpVisualFc);
+void setVisualFields(JNIEnv *env, jobject lpObject, Visual *lpVisual, VISUAL_FID_CACHE *lpVisualFc);
+void getXanyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XANYEVENT_FID_CACHE *lpXeventFc);
+void setXanyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XANYEVENT_FID_CACHE *lpXeventFc);
+void getXbuttoneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, PXBUTTONEVENT_FID_CACHE lpXbuttoneventFc);
+void setXbuttoneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, PXBUTTONEVENT_FID_CACHE lpXbuttoneventFc);
+void getXcharstructFields(JNIEnv *env, jobject lpObject, XCharStruct *lpXcharstruct, XCHARSTRUCT_FID_CACHE *lpXcharstructFc);
+void setXcharstructFields(JNIEnv *env, jobject lpObject, XCharStruct *lpXcharstruct, XCHARSTRUCT_FID_CACHE *lpXcharstructFc);
+void getXconfigureeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, PXCONFIGUREEVENT_FID_CACHE lpXconfigureeventFc);
+void setXconfigureeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, PXCONFIGUREEVENT_FID_CACHE lpXconfigureeventFc);
+void getXcrossingeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXcrossingevent, PXCROSSINGEVENT_FID_CACHE lpXcrossingeventFc);
+void setXcrossingeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXcrossingevent, PXCROSSINGEVENT_FID_CACHE lpXcrossingeventFc);
+void getXexposeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XEXPOSEEVENT_FID_CACHE *lpXexposeeventFc);
+void setXexposeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XEXPOSEEVENT_FID_CACHE *lpXexposeeventFc);
+void getXfocuschangeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XFOCUSCHANGEEVENT_FID_CACHE *lpXfocuschangeeventFc);
+void setXfocuschangeeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XFOCUSCHANGEEVENT_FID_CACHE *lpXfocuschangeeventFc);
+void getXfontstructFields(JNIEnv *env, jobject lpObject, XFontStruct *lpXfontstruct, XFONTSTRUCT_FID_CACHE *lpXfontstructFc);
+void setXfontstructFields(JNIEnv *env, jobject lpObject, XFontStruct *lpXfontstruct, XFONTSTRUCT_FID_CACHE *lpXfontstructFc);
+void getXimageFields(JNIEnv *env, jobject lpObject, XImage *lpXimage, XIMAGE_FID_CACHE *lpXimageFc);
+void setXimageFields(JNIEnv *env, jobject lpObject, XImage *lpXimage, XIMAGE_FID_CACHE *lpXimageFc);
+void getXkeyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XKEYEVENT_FID_CACHE *lpXkeyeventFc);
+void setXkeyeventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XKEYEVENT_FID_CACHE *lpXkeyeventFc);
+void getXmotioneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XMOTIONEVENT_FID_CACHE *lpXmotioneventFc);
+void setXmotioneventFields(JNIEnv *env, jobject lpObject, XEvent *lpXevent, XMOTIONEVENT_FID_CACHE *lpXmotioneventFc);
+void getXcolorFields(JNIEnv *env, jobject lpObject, XColor *lpXcolor, XCOLOR_FID_CACHE *lpXcolorFc);
+void setXcolorFields(JNIEnv *env, jobject lpObject, XColor *lpXcolor, XCOLOR_FID_CACHE *lpXcolorFc);
+void getXgcvaluesFields(JNIEnv *env, jobject lpObject, XGCValues *lpXgcvalues, PXGCVALUES_FID_CACHE lpXgcvaluesFc);
+void setXgcvaluesFields(JNIEnv *env, jobject lpObject, XGCValues *lpXgcvalues, PXGCVALUES_FID_CACHE lpXgcvaluesFc);
+void getXmanycallbackstructFields(JNIEnv *env, jobject lpObject, XmAnyCallbackStruct *lpXmanycallbackstruct, PXMANYCALLBACKSTRUCT_FID_CACHE lpXmanycallbackstructFc);
+void setXmanycallbackstructFields(JNIEnv *env, jobject lpObject, XmAnyCallbackStruct *lpXmanycallbackstruct, PXMANYCALLBACKSTRUCT_FID_CACHE lpXmanycallbackstructFc);
+void getXmdragproccallbackFields(JNIEnv *env, jobject lpObject, XmDragProcCallbackStruct *lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpXmdragproccallbackFc);
+void setXmdragproccallbackFields(JNIEnv *env, jobject lpObject, XmDragProcCallbackStruct *lpXmdragproccallback, PXMDRAGPROCCALLBACK_FID_CACHE lpXmdragproccallbackFc);
+void getXmdropproccallbackFields(JNIEnv *env, jobject lpObject, XmDropProcCallbackStruct *lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpXmdropproccallbackFc);
+void setXmdropproccallbackFields(JNIEnv *env, jobject lpObject, XmDropProcCallbackStruct *lpXmdropproccallback, PXMDROPPROCCALLBACK_FID_CACHE lpXmdropproccallbackFc);
+void getXmdropfinishcallbackFields(JNIEnv *env, jobject lpObject, XmDropFinishCallbackStruct *lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpXmdropfinishcallbackFc);
+void setXmdropfinishcallbackFields(JNIEnv *env, jobject lpObject, XmDropFinishCallbackStruct *lpXmdropfinishcallback, PXMDROPFINISHCALLBACK_FID_CACHE lpXmdropfinishcallbackFc);
+void getXmtextblockrecFields(JNIEnv *env, jobject lpObject, XmTextBlockRec *lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpXmtextblockrecFc);
+void setXmtextblockrecFields(JNIEnv *env, jobject lpObject, XmTextBlockRec *lpXmtextblockrec, PXMTEXTBLOCKREC_FID_CACHE lpXmtextblockrecFc);
+void getXmtextverifycallbackstructFields(JNIEnv *env, jobject lpObject, XmTextVerifyCallbackStruct *lpXmtextverifycallbackstruct, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpXmtextverifycallbackstructFc);
+void setXmtextverifycallbackstructFields(JNIEnv *env, jobject lpObject, XmTextVerifyCallbackStruct *lpXmtextverifycallbackstruct, PXMTEXTVERIFYCALLBACKSTRUCT_FID_CACHE lpXmtextverifycallbackstructFc);
+void getXrectangleFields(JNIEnv *env, jobject lpObject, XRectangle *lpXrect, PXRECTANGLE_FID_CACHE lpXrectFc);
+void setXrectangleFields(JNIEnv *env, jobject lpObject, XRectangle *lpXrect, PXRECTANGLE_FID_CACHE lpXrectFc);
+void getXsetwindowattributesFields(JNIEnv *env, jobject lpObject, XSetWindowAttributes *lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpXsetwindowattributesFc);
+void setXsetwindowattributesFields(JNIEnv *env, jobject lpObject, XSetWindowAttributes *lpXsetwindowattributes, PXSETWINDOWATTRIBUTES_FID_CACHE lpXsetwindowattributesFc);
+void getXwindowattributesFields(JNIEnv *env, jobject lpObject, XWindowAttributes *lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpXwindowattributesFc);
+void setXwindowattributesFields(JNIEnv *env, jobject lpObject, XWindowAttributes *lpXwindowattributes, PXWINDOWATTRIBUTES_FID_CACHE lpXwindowattributesFc);
+void getXwindowchangesFields(JNIEnv *env, jobject lpObject, XWindowChanges *lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpXwindowchangesFc);
+void setXwindowchangesFields(JNIEnv *env, jobject lpObject, XWindowChanges *lpXwindowchanges, PXWINDOWCHANGES_FID_CACHE lpXwindowchangesFc);
+void getXtwidgetgeometryFields(JNIEnv *env, jobject lpObject, XtWidgetGeometry *lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpXtwidgetgeometryFc);
+void setXtwidgetgeometryFields(JNIEnv *env, jobject lpObject, XtWidgetGeometry *lpXtwidgetgeometry, PXTWIDGETGEOMETRY_FID_CACHE lpXtwidgetgeometryFc);
+
+#endif /* INC_structs_H */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c
new file mode 100755
index 0000000000..0e58c2f576
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c
@@ -0,0 +1,7899 @@
+/**
+ * SWT OS natives implementation.
+ */
+
+/* #define PRINT_FAILED_RCODES */
+#define NDEBUG
+
+#include "globals.h"
+#include "structs.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_getSharedLibraryMajorVersionNumber
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "getSharedLibraryMajorVersionNumber\n");
+#endif
+ return SWT_LIBRARY_MAJOR_VERSION;
+}
+
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_getSharedLibraryMinorVersionNumber
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "getSharedLibraryMinorVersionNumber\n");
+#endif
+ return SWT_LIBRARY_MINOR_VERSION;
+}
+
+
+/*************************************************************************
+
+ Name : sleep_ms( unsigned int nmsecs)
+
+ Purpose : sleep for a given number of milli seconds
+ Parms : the number of milli seconds to sleep
+ Returns :
+
+*************************************************************************/
+/*
+void sleep_ms( unsigned int nmsecs)
+{
+ struct timeval tval;
+ tval.tv_sec = (nmsecs * 1000) / 1000000;
+ tval.tv_usec = (nmsecs * 1000) % 1000000;
+ select(0, NULL, NULL, NULL, &tval);
+}
+*/
+
+/* ------------------------------------- */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XInitThreads
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XInitThreads
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XInitThreads\n");
+#endif
+
+ return (jint) XInitThreads();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: OverrideShellWidgetClass
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_OverrideShellWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "OverrideShellWidgetClass\n");
+#endif
+ return (jint) (overrideShellWidgetClass);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: ShellWidgetClass
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_ShellWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "ShellWidgetClass\n");
+#endif
+ return (jint) (shellWidgetClass);
+}
+
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_TopLevelShellWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "TopLevelShellWidgetClass\n");
+#endif
+ return (jint) (topLevelShellWidgetClass);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: TransientShellWidgetClass
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_TransientShellWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "TransientShellWidgetClass\n");
+#endif
+
+ return (jint) (transientShellWidgetClass);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/motif/XButtonEvent;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__ILorg_eclipse_swt_internal_motif_XButtonEvent_2I
+ (JNIEnv *env, jclass that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *src1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_motif_XButtonEvent_2I\n");
+#endif
+ if (src) {
+ src1=&xEvent;
+ cacheXbuttoneventFids(env, src, &PGLOB(XbuttoneventFc));
+ getXbuttoneventFields(env, src, src1, &PGLOB(XbuttoneventFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/motif/XImage;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__ILorg_eclipse_swt_internal_motif_XImage_2I
+ (JNIEnv *env, jclass that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XImage image, *src1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_motif_XImage_2I\n");
+#endif
+
+ if (src) {
+ src1=&image;
+ cacheXimageFids(env, src, &PGLOB(XimageFc));
+ getXimageFields(env, src, src1, &PGLOB(XimageFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/motif/XmTextBlockRec;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__ILorg_eclipse_swt_internal_motif_XmTextBlockRec_2I
+ (JNIEnv *env, jclass that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmTextBlockRec xmtextblockrec, *src1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_motif_XmTextBlockRec_2I\n");
+#endif
+
+ if (src) {
+ src1=&xmtextblockrec;
+ cacheXmtextblockrecFids(env, src, &PGLOB(XmtextblockrecFc));
+ getXmtextblockrecFields(env, src, src1, &PGLOB(XmtextblockrecFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__ILorg_eclipse_swt_internal_motif_XmTextVerifyCallbackStruct_2I
+ (JNIEnv *env, jclass that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmTextVerifyCallbackStruct xmtextverifycallbackstruct, *src1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_motif_XmTextVerifyCallbackStruct_2I\n");
+#endif
+
+ if (src) {
+ src1=&xmtextverifycallbackstruct;
+ cacheXmtextverifycallbackstructFids(env, src, &PGLOB(XmtextverifycallbackstructFc));
+ getXmtextverifycallbackstructFields(env, src, src1, &PGLOB(XmtextverifycallbackstructFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__I_3BI
+ (JNIEnv *env, jclass that, jint dest, jbyteArray src, jint count)
+{
+ jbyte *src1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__I_3BI\n");
+#endif
+
+ /* don't do anything if src pointer is NULL */
+ if (src) {
+ src1 = (*env)->GetByteArrayElements(env, src, NULL);
+ memmove((void *)dest, (void *)src1, count);
+ (*env)->ReleaseByteArrayElements(env, src, src1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__I_3II
+ (JNIEnv *env, jclass that, jint dest, jintArray src, jint count)
+{
+ jint *src1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__I_3II\n");
+#endif
+
+ /* don't do anything if src pointer is NULL */
+ if (src) {
+ src1 = (*env)->GetIntArrayElements(env, src, NULL);
+ memmove((void *)dest, (void *)src1, count);
+ (*env)->ReleaseIntArrayElements(env, src, src1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/Visual;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_Visual_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ Visual visual, *lpxVisual=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_Visual_2II\n");
+#endif
+
+ memmove((void *)&visual, (void *)src, count);
+ if (dest) {
+ lpxVisual=&visual;
+ cacheVisualFids(env, dest, &PGLOB(VisualFc));
+ setVisualFields(env, dest, lpxVisual, &PGLOB(VisualFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XButtonEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XButtonEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XButtonEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXbuttoneventFids(env, dest, &PGLOB(XbuttoneventFc));
+ setXbuttoneventFields(env, dest, lpxEvent, &PGLOB(XbuttoneventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XCharStruct;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XCharStruct_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XCharStruct xCharstruct, *lpxCharstruct=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XCharStruct_2II\n");
+#endif
+
+ memmove((void *)&xCharstruct, (void *)src, count);
+ if (dest) {
+ lpxCharstruct=&xCharstruct;
+ cacheXcharstructFids(env, dest, &PGLOB(XcharstructFc));
+ setXcharstructFields(env, dest, lpxCharstruct, &PGLOB(XcharstructFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XConfigureEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XConfigureEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XConfigureEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXconfigureeventFids(env, dest, &PGLOB(XconfigureeventFc));
+ setXconfigureeventFields(env, dest, lpxEvent, &PGLOB(XconfigureeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XCrossingEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XCrossingEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XCrossingEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXcrossingeventFids(env, dest, &PGLOB(XcrossingeventFc));
+ setXcrossingeventFields(env, dest, lpxEvent, &PGLOB(XcrossingeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XExposeEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XExposeEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XExposeEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXexposeeventFids(env, dest, &PGLOB(XexposeeventFc));
+ setXexposeeventFields(env, dest, lpxEvent, &PGLOB(XexposeeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XFocusChangeEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XFocusChangeEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XFocusChangeEvent_2II\n");
+#endif
+
+ assert(count <= sizeof(XEvent));
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXfocuschangeeventFids(env, dest, &PGLOB(XfocuschangeeventFc));
+ setXfocuschangeeventFields(env, dest, lpxEvent, &PGLOB(XfocuschangeeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XFontStruct;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XFontStruct_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XFontStruct fontStruct, *lpxFontStruct=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XFontStruct_2II\n");
+#endif
+
+ memmove((void *)&fontStruct, (void *)src, count);
+ if (dest) {
+ lpxFontStruct=&fontStruct;
+ cacheXfontstructFids(env, dest, &PGLOB(XfontstructFc));
+ setXfontstructFields(env, dest, lpxFontStruct, &PGLOB(XfontstructFc));
+ }
+
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XImage;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XImage_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XImage image, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XImage_2II\n");
+#endif
+
+ memmove((void *)&image, (void *)src, count);
+ if (dest) {
+ dest1=&image;
+ cacheXimageFids(env, dest, &PGLOB(XimageFc));
+ setXimageFields(env, dest, dest1, &PGLOB(XimageFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XKeyEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XKeyEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XKeyEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXkeyeventFids(env, dest, &PGLOB(XkeyeventFc));
+ setXkeyeventFields(env, dest, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XKeyEvent;Lorg/eclipse/swt/internal/motif/XAnyEvent;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XKeyEvent_2Lorg_eclipse_swt_internal_motif_XAnyEvent_2I
+ (JNIEnv *env, jclass that, jobject dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent1, *src1=NULL, xEvent2, *dest1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XKeyEvent_2Lorg_eclipse_swt_internal_motif_XAnyEvent_2I\n");
+#endif
+ if (src) {
+ src1=&xEvent1;
+ cacheXanyeventFids(env, src, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, src, src1, &PGLOB(XanyeventFc));
+ }
+
+ memmove((void *)&xEvent2, (void *)src1, count);
+ if (dest) {
+ dest1=&xEvent2;
+ cacheXkeyeventFids(env, dest, &PGLOB(XkeyeventFc));
+ setXkeyeventFields(env, dest, dest1, &PGLOB(XkeyeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XMotionEvent;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XMotionEvent_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XMotionEvent_2II\n");
+#endif
+
+ memmove((void *)&xEvent, (void *)src, count);
+ if (dest) {
+ lpxEvent=&xEvent;
+ cacheXmotioneventFids(env, dest, &PGLOB(XmotioneventFc));
+ setXmotioneventFields(env, dest, lpxEvent, &PGLOB(XmotioneventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmAnyCallbackStruct;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmAnyCallbackStruct_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmAnyCallbackStruct xmanycallbackstruct, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmAnyCallbackStruct_2II\n");
+#endif
+
+ memmove((void *)&xmanycallbackstruct, (void *)src, count);
+ if (dest) {
+ dest1=&xmanycallbackstruct;
+ cacheXmanycallbackstructFids(env, dest, &PGLOB(XmanycallbackstructFc));
+ setXmanycallbackstructFields(env, dest, dest1, &PGLOB(XmanycallbackstructFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/motif/XmDragProcCallback;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__ILorg_eclipse_swt_internal_motif_XmDragProcCallback_2I
+ (JNIEnv *env, jclass that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmDragProcCallbackStruct xmdragproccallback, *src1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_motif_XmDragProcCallback_2I\n");
+#endif
+
+ if (src) {
+ src1=&xmdragproccallback;
+ cacheXmdragproccallbackFids(env, src, &PGLOB(XmdragproccallbackFc));
+ getXmdragproccallbackFields(env, src, src1, &PGLOB(XmdragproccallbackFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmDragProcCallback;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmDragProcCallback_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmDragProcCallbackStruct xmdragproccallback, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmDragProcCallback_2II\n");
+#endif
+
+ memmove((void *)&xmdragproccallback, (void *)src, count);
+ if (dest) {
+ dest1=&xmdragproccallback;
+ cacheXmdragproccallbackFids(env, dest, &PGLOB(XmdragproccallbackFc));
+ setXmdragproccallbackFields(env, dest, dest1, &PGLOB(XmdragproccallbackFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmDropProcCallback;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmDropProcCallback_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmDropProcCallbackStruct xmdropproccallback, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmDropProcCallback_2II\n");
+#endif
+
+ memmove((void *)&xmdropproccallback, (void *)src, count);
+ if (dest) {
+ dest1=&xmdropproccallback;
+ cacheXmdropproccallbackFids(env, dest, &PGLOB(XmdropproccallbackFc));
+ setXmdropproccallbackFields(env, dest, dest1, &PGLOB(XmdropproccallbackFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmDropFinishCallback;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmDropFinishCallback_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmDropFinishCallbackStruct xmdropfinishcallback, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmDropFinishCallback_2II\n");
+#endif
+
+ memmove((void *)&xmdropfinishcallback, (void *)src, count);
+ if (dest) {
+ dest1=&xmdropfinishcallback;
+ cacheXmdropfinishcallbackFids(env, dest, &PGLOB(XmdropfinishcallbackFc));
+ setXmdropfinishcallbackFields(env, dest, dest1, &PGLOB(XmdropfinishcallbackFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmTextBlockRec;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmTextBlockRec_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmTextBlockRec xmTextBlockRec, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmTextBlockRec_2II\n");
+#endif
+
+ memmove((void *)&xmTextBlockRec, (void *)src, count);
+ if (dest) {
+ dest1=&xmTextBlockRec;
+ cacheXmtextblockrecFids(env, dest, &PGLOB(XmtextblockrecFc));
+ setXmtextblockrecFields(env, dest, dest1, &PGLOB(XmtextblockrecFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__Lorg_eclipse_swt_internal_motif_XmTextVerifyCallbackStruct_2II
+ (JNIEnv *env, jclass that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ XmTextVerifyCallbackStruct xmtextverifycallbackstruct, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_motif_XmTextVerifyCallbackStruct_2II\n");
+#endif
+
+ memmove((void *)&xmtextverifycallbackstruct, (void *)src, count);
+ if (dest) {
+ dest1=&xmtextverifycallbackstruct;
+ cacheXmtextverifycallbackstructFids(env, dest, &PGLOB(XmtextverifycallbackstructFc));
+ setXmtextverifycallbackstructFields(env, dest, dest1, &PGLOB(XmtextverifycallbackstructFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: ([BII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove___3BII
+ (JNIEnv *env, jclass that, jbyteArray dest, jint src, jint count)
+{
+ jbyte *dest1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove___3BII\n");
+#endif
+
+ /* don't do anything if dest pointer is NULL */
+ if (dest) {
+ dest1 = (*env)->GetByteArrayElements(env, dest, NULL);
+ memmove((void *)dest1, (void *)src, count);
+ (*env)->ReleaseByteArrayElements(env, dest, dest1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: ([III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove___3III
+ (JNIEnv *env, jclass that, jintArray dest, jint src, jint count)
+{
+ jint *dest1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove___3III\n");
+#endif
+
+ /* don't do anything if dest pointer is NULL */
+ if (dest) {
+ dest1 = (*env)->GetIntArrayElements(env, dest, NULL);
+ memmove((void *)dest1, (void *)src, count);
+ (*env)->ReleaseIntArrayElements(env, dest, dest1, 0);
+ }
+}
+
+/* end of custom built crap */
+
+/* ------------------------------------------------------------------------- */
+
+/* the following map directly to X calls */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XAllocColor
+ * Signature: (IILorg/eclipse/swt/internal/motif/XColor;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XAllocColor
+ (JNIEnv *env, jclass that, jint display, jint colormap, jobject color)
+{
+ DECL_GLOB(pGlob)
+ XColor xColor, *lpColor=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XAllocColor\n");
+#endif
+
+ assert (color != 0);
+ if (color) {
+ lpColor = &xColor;
+ cacheXcolorFids(env, color, &PGLOB(XcolorFc));
+ getXcolorFields(env, color, lpColor, &PGLOB(XcolorFc));
+ }
+ rc = (jint) XAllocColor ((Display *)display, colormap, lpColor);
+
+#ifdef PRINT_FAILED_RCODES
+
+ if (rc == 0)
+ fprintf(stderr, "XAllocColor: call failed rc = %d\n", rc);
+#endif
+
+ if (color) {
+ setXcolorFields(env, color, lpColor, &PGLOB(XcolorFc));
+ }
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XBell
+ * Signature: (II)I
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XBell
+ (JNIEnv *env, jclass that, jint display, jint ms)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XBell\n");
+#endif
+ XBell ((Display *)display, ms);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XBitmapBitOrder
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XBitmapBitOrder
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XBitmapBitOrder\n");
+#endif
+ return (jint) XBitmapBitOrder((Display *) display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XBlackPixel
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XBlackPixel
+ (JNIEnv *env, jclass that, jint display, jint screen_number)
+{
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XBlackPixel\n");
+#endif
+ return (jint) XBlackPixel((Display *)display, screen_number);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XChangeGC
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XGCValues;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XChangeGC
+ (JNIEnv *env, jclass that, jint display, jint gc, jint valuemask, jobject values)
+{
+ DECL_GLOB(pGlob)
+ XGCValues xgcValues, *lpxgcValues=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XChangeGC\n");
+#endif
+
+ if (values) {
+ lpxgcValues = &xgcValues;
+ cacheXgcvaluesFids(env, values, &PGLOB(XgcvaluesFc));
+ getXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ rc = (jint) XChangeGC((Display *)display, (GC)gc, valuemask, lpxgcValues);
+
+ if (values) {
+ setXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XChangeWindowAttributes
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XSetWindowAttributes;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XChangeWindowAttributes
+ (JNIEnv *env, jclass that, jint display, jint window, jint mask, jobject attributes)
+{
+ DECL_GLOB(pGlob)
+ XSetWindowAttributes xSetWindowAttributes, *lpxSetWindowAttributes;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XChangeWindowAttributes\n");
+#endif
+
+ if (attributes) {
+ lpxSetWindowAttributes = &xSetWindowAttributes;
+ cacheXsetwindowattributesFids(env, attributes, &PGLOB(XsetwindowattributesFc));
+ getXsetwindowattributesFields(env, attributes, lpxSetWindowAttributes, &PGLOB(XsetwindowattributesFc));
+ }
+
+ XChangeWindowAttributes((Display *)display, window, mask, lpxSetWindowAttributes);
+ if (attributes) {
+ setXsetwindowattributesFields(env, attributes, lpxSetWindowAttributes, &PGLOB(XsetwindowattributesFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCheckMaskEvent
+ * Signature: (IILorg/eclipse/swt/internal/motif/XAnyEvent;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XCheckMaskEvent
+ (JNIEnv *env, jclass that, jint display, jint mask, jobject event)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCheckMaskEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ rc = (jboolean) XCheckMaskEvent((Display *)display, mask, lpxEvent);
+
+#ifdef PRINT_FAILED_RCODES
+
+ if (rc != True && rc != False)
+ fprintf(stderr, "XCheckMaskEvent: call failed rc = %d\n", rc);
+#endif
+
+ if (event) {
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCheckWindowEvent
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XAnyEvent;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XCheckWindowEvent
+ (JNIEnv *env, jclass that, jint display, jint window, jint mask, jobject event)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCheckWindowEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ rc = (jboolean)XCheckWindowEvent((Display *)display, window, mask, lpxEvent);
+
+#ifdef PRINT_FAILED_RCODES
+
+ if (rc != True && rc != False)
+ fprintf(stderr, "XCheckWindowEvent: call failed rc = %d\n", rc);
+#endif
+
+ if (event) {
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XClearArea
+ * Signature: (IIIIIIZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XClearArea
+ (JNIEnv *env, jclass that, jint display, jint window, jint x, jint y, jint width, jint height, jboolean exposures)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XClearArea\n");
+#endif
+ XClearArea((Display *)display, window, x, y, width, height, exposures);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XClipBox
+ * Signature: (ILorg/eclipse/swt/internal/motif/XRectangle;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XClipBox
+ (JNIEnv *env, jclass that, jint region, jobject rectangle)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XClipBox\n");
+#endif
+
+ if (rectangle) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, rectangle, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ XClipBox((Region)region, (XRectangle *)lpxRect);
+ if (rectangle) {
+ setXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCopyArea
+ * Signature: (IIIIIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XCopyArea
+ (JNIEnv *env, jclass that, jint display, jint src, jint dest, jint gc, jint src_x, jint src_y, jint width, jint height, jint dest_x, jint dest_y)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCopyArea\n");
+#endif
+ XCopyArea((Display *)display, src, dest, (GC)gc, src_x, src_y, width, height, dest_x, dest_y);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCopyPlane
+ * Signature: (IIIIIIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XCopyPlane
+ (JNIEnv *env, jclass that, jint display, jint src, jint dest, jint gc, jint src_x, jint src_y, jint width, jint height, jint dest_x, jint dest_y, jint plane)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCopyPlane\n");
+#endif
+ XCopyPlane((Display *)display, src, dest, (GC)gc, src_x, src_y, width, height, dest_x, dest_y, plane);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateBitmapFromData
+ * Signature: (II[BII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateBitmapFromData
+ (JNIEnv *env, jclass that, jint display, jint drawable, jbyteArray data, jint width, jint height)
+{
+ jbyte *data1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateBitmapFromData\n");
+#endif
+
+ if (data)
+ data1 = (*env)->GetByteArrayElements(env, data, NULL);
+
+ rc = (jint) XCreateBitmapFromData((Display *)display, drawable, (char *)data1, width, height);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XCreateBitmapFromData: call failed rc = %d\n", rc);
+#endif
+
+ if (data)
+ (*env)->ReleaseByteArrayElements(env, data, data1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateFontCursor
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateFontCursor
+ (JNIEnv *env, jclass that, jint display, jint shape)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateFontCursor\n");
+#endif
+ return (jint) XCreateFontCursor((Display *)display, shape);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateGC
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XGCValues;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateGC
+ (JNIEnv *env, jclass that, jint display, jint window, jint mask, jobject values)
+{
+ DECL_GLOB(pGlob)
+ XGCValues xgcValues, *lpxgcValues=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateGC\n");
+#endif
+
+ if (values) {
+ lpxgcValues = &xgcValues;
+ cacheXgcvaluesFids(env, values, &PGLOB(XgcvaluesFc));
+ getXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ rc = (jint) XCreateGC((Display *)display, window, mask, lpxgcValues);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XCreateGC: call failed rc = %d\n", rc);
+#endif
+
+ if (values) {
+ setXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateImage
+ * Signature: (IIIIIIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateImage
+ (JNIEnv *env, jclass that, jint display, jint visual, jint depth, jint format, jint offset, jint data, jint width, jint height, jint bitmap_pad, jint bytes_per_line)
+{
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateImage\n");
+#endif
+
+ rc = (jint) XCreateImage((Display *)display, (Visual *)visual, depth, format, offset, (char *)data, width, height, bitmap_pad, bytes_per_line);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XCreateImage: call failed rc = %d\n", rc);
+#endif
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreatePixmap
+ * Signature: (IIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreatePixmap
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint width, jint height, jint depth)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreatePixmap\n");
+#endif
+ return (jint) XCreatePixmap((Display *)display, drawable, width, height, depth);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreatePixmapCursor
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XColor;Lorg/eclipse/swt/internal/motif/XColor;II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreatePixmapCursor
+ (JNIEnv *env, jclass that, jint display, jint source, jint mask, jobject foreground_color, jobject background_color, jint x, jint y)
+{
+ DECL_GLOB(pGlob)
+ XColor background_color1, foreground_color1;
+ XColor *lp_background_color = NULL, *lp_foreground_color = NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreatePixmapCursor\n");
+#endif
+
+ assert(foreground_color != 0);
+ if (foreground_color) {
+ lp_foreground_color = &foreground_color1;
+ cacheXcolorFids(env, foreground_color, &PGLOB(XcolorFc));
+ getXcolorFields(env, foreground_color, lp_foreground_color, &PGLOB(XcolorFc));
+ }
+ if (background_color) {
+ lp_background_color = &background_color1;
+ cacheXcolorFids(env, background_color, &PGLOB(XcolorFc));
+ getXcolorFields(env, background_color, lp_background_color, &PGLOB(XcolorFc));
+ }
+
+ return (jint) XCreatePixmapCursor((Display *)display, (Pixmap)source, (Pixmap)mask, lp_foreground_color, lp_background_color, x, y);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateRegion
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateRegion
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateRegion\n");
+#endif
+ return (jint) XCreateRegion();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultColormap
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultColormap
+ (JNIEnv *env, jclass that, jint display, jint screen_number)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultColormap\n");
+#endif
+ return (jint) XDefaultColormap((Display *)display, screen_number);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultDepthOfScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultDepthOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultDepthOfScreen\n");
+#endif
+ return (jint) XDefaultDepthOfScreen((Screen *)screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultRootWindow
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultRootWindow
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultRootWindow\n");
+#endif
+ return (jint) XDefaultRootWindow((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultScreen
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultScreen\n");
+#endif
+ return (jint) XDefaultScreen((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultScreenOfDisplay
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultScreenOfDisplay
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultScreenOfDisplay\n");
+#endif
+ return (jint) XDefaultScreenOfDisplay((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultVisual
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultVisual
+ (JNIEnv *env, jclass that, jint display, jint screen_number)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultVisual\n");
+#endif
+ return (jint) XDefaultVisual((Display *)display, screen_number);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefineCursor
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefineCursor
+ (JNIEnv *env, jclass that, jint display, jint window, jint cursor)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefineCursor\n");
+#endif
+ XDefineCursor((Display *)display, window, cursor);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDestroyImage
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDestroyImage
+ (JNIEnv *env, jclass that, jint ximage)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDestroyImage\n");
+#endif
+ return (jint) XDestroyImage((XImage *)ximage);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDestroyRegion
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDestroyRegion
+ (JNIEnv *env, jclass that, jint region)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDestroyRegion\n");
+#endif
+ XDestroyRegion((Region)region);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDisplayHeight
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDisplayHeight
+ (JNIEnv *env, jclass that, jint display, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDisplayHeight\n");
+#endif
+ return (jint) XDisplayHeight((Display *)display, screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDisplayHeightMM
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDisplayHeightMM
+ (JNIEnv *env, jclass that, jint display, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDisplayHeightMM\n");
+#endif
+ return (jint) XDisplayHeightMM((Display *)display, screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDisplayWidth
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDisplayWidth
+ (JNIEnv *env, jclass that, jint display, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDisplayWidth\n");
+#endif
+ return (jint) XDisplayWidth((Display *)display, screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDisplayWidthMM
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDisplayWidthMM
+ (JNIEnv *env, jclass that, jint display, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDisplayWidthMM\n");
+#endif
+ return (jint) XDisplayWidthMM((Display *)display, screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDrawArc
+ * Signature: (IIIIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDrawArc
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint x1, jint y1, jint x2, jint y2, jint a1, jint a2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDrawArc\n");
+#endif
+ XDrawArc((Display *)display, drawable, (GC)gc, x1, y1, x2, y2, a1, a2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDrawLine
+ * Signature: (IIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDrawLine
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint x1, jint y1, jint x2, jint y2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDrawLine\n");
+#endif
+ XDrawLine((Display *)display, drawable, (GC)gc, x1, y1, x2, y2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDrawLines
+ * Signature: (III[SII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDrawLines
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jshortArray xPoints, jint nPoints, jint mode)
+{
+ jshort *xPoints1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDrawLines\n");
+#endif
+
+ if (xPoints)
+ xPoints1 = (*env)->GetShortArrayElements(env, xPoints, NULL);
+ XDrawLines((Display *)display, drawable, (GC)gc, (XPoint *)xPoints1, nPoints, mode);
+ if (xPoints)
+ (*env)->ReleaseShortArrayElements(env, xPoints, xPoints1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDrawRectangle
+ * Signature: (IIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDrawRectangle
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint x, jint y, jint width, jint height)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "\n");
+#endif
+ XDrawRectangle((Display *)display, drawable, (GC)gc, x, y, width, height);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XEmptyRegion
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XEmptyRegion
+ (JNIEnv *env, jclass that, jint region)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XEmptyRegion\n");
+#endif
+ return (jboolean) XEmptyRegion((Region)region);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XEqualRegion
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XEqualRegion
+ (JNIEnv *env, jclass that, jint region1, jint region2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XEqualRegion\n");
+#endif
+ return (jboolean) XEqualRegion((Region)region1, (Region)region2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFillArc
+ * Signature: (IIIIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFillArc
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint x1, jint y1, jint x2, jint y2, jint a1, jint a2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFillArc\n");
+#endif
+ XFillArc((Display *)display, drawable, (GC)gc, x1, y1, x2, y2, a1, a2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFillPolygon
+ * Signature: (III[SIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XFillPolygon
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jshortArray xPoints, jint nPoints, jint mode, jint style)
+{
+ jshort *xPoints1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFillPolygon\n");
+#endif
+ if (xPoints)
+ xPoints1 = (*env)->GetShortArrayElements(env, xPoints, NULL);
+ rc = XFillPolygon((Display *)display, drawable, (GC)gc, (XPoint *)xPoints1, nPoints, mode, style);
+ if (xPoints)
+ (*env)->ReleaseShortArrayElements(env, xPoints, xPoints1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFillRectangle
+ * Signature: (IIIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFillRectangle
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint x, jint y, jint width, jint height)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFillRectangle\n");
+#endif
+ XFillRectangle((Display *)display, drawable, (GC)gc, x, y, width, height);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFilterEvent
+ * Signature: (Lorg/eclipse/swt/internal/motif/XAnyEvent;I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XFilterEvent
+ (JNIEnv *env, jclass that, jobject event, jint window)
+{
+ DECL_GLOB(pGlob)
+ XEvent xanyevent, *event1;
+ jboolean rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFilterEvent\n");
+#endif
+ if (event) {
+ event1=&xanyevent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, event1, &PGLOB(XanyeventFc));
+ }
+ rc = (jboolean) XFilterEvent(event1, (Window)window);
+ if (event) {
+ setXanyeventFields(env, event, event1, &PGLOB(XanyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFlush
+ * Signature: (I)I
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFlush
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFlush\n");
+#endif
+ XFlush((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFontsOfFontSet
+ * Signature: (I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XFontsOfFontSet
+ (JNIEnv *env, jclass that, jint fontSet, jintArray fontStructs, jintArray fontNames)
+{
+ jint *fontStructs1=NULL,*fontNames1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFontsOfFontSet\n");
+#endif
+ if (fontStructs)
+ fontStructs1 = (*env)->GetIntArrayElements(env, fontStructs, NULL);
+ if (fontNames)
+ fontNames1 = (*env)->GetIntArrayElements(env, fontNames, NULL);
+
+ rc = (jint) XFontsOfFontSet((XFontSet)fontSet, (XFontStruct ***)fontStructs1, (char ***)fontNames1);
+
+ if (fontStructs)
+ (*env)->ReleaseIntArrayElements(env, fontStructs, fontStructs1, 0);
+ if (fontNames)
+ (*env)->ReleaseIntArrayElements(env, fontNames, fontNames1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFree
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XFree
+ (JNIEnv *env, jclass that, jint address)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFree\n");
+#endif
+ return (jint) XFree((char *)address);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFreeColors
+ * Signature: (II[III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XFreeColors
+ (JNIEnv *env, jclass that, jint display, jint colormap, jintArray pixels, jint npixels, jint planes)
+{
+ jint *pixels1=NULL;
+ jint rc;
+ jint intArr[2]={250, 250};
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFreeColors\n");
+#endif
+
+ assert(pixels != 0);
+ assert(npixels > 0);
+ assert(npixels < 20);
+
+ if (pixels) {
+ pixels1 = (jint *)&intArr;
+ (*env)->GetIntArrayRegion(env, pixels, 0, npixels, pixels1);
+ }
+
+ assert(*pixels1 >= 0);
+ assert(*pixels1 < 65536);
+ assert(*(pixels1+1) >= 0);
+ assert(*(pixels1+1) < 65536);
+
+ rc = (jint) XFreeColors((Display *)display, colormap, (unsigned long *)pixels1, npixels, planes);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XCreateGC: call failed rc = %d\n", rc);
+#endif
+
+ assert(rc > 0);
+
+ if (pixels) {
+ (*env)->SetIntArrayRegion(env, pixels, 0, npixels, pixels1);
+ }
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFreeCursor
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFreeCursor
+ (JNIEnv *env, jclass that, jint display, jint pixmap)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFreeCursor\n");
+#endif
+ XFreeCursor((Display *)display, pixmap);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFreeFontNames
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFreeFontNames
+ (JNIEnv *env, jclass that, jint list)
+{
+ XFreeFontNames((char **)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFreeGC
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFreeGC
+ (JNIEnv *env, jclass that, jint display, jint gc)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFreeGC\n");
+#endif
+ XFreeGC((Display *)display, (GC)gc);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XFreePixmap
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XFreePixmap
+ (JNIEnv *env, jclass that, jint display, jint pixmap)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XFreePixmap\n");
+#endif
+ XFreePixmap((Display *)display, pixmap);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetGCValues
+ * Signature: (IIILorg/eclipse/swt/internal/motif/XGCValues;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetGCValues
+ (JNIEnv *env, jclass that, jint display, jint gc, jint valuemask, jobject values)
+{
+ DECL_GLOB(pGlob)
+ XGCValues xgcValues, *lpxgcValues=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetGCValues\n");
+#endif
+
+ if (values) {
+ lpxgcValues = &xgcValues;
+ cacheXgcvaluesFids(env, values, &PGLOB(XgcvaluesFc));
+ getXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ rc = (jint) XGetGCValues((Display *)display, (GC)gc, valuemask, lpxgcValues);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XGetGCValues: call failed rc = %d\n", rc);
+#endif
+
+ if (values) {
+ setXgcvaluesFields(env, values, lpxgcValues, &PGLOB(XgcvaluesFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetGeometry
+ * Signature: (II[I[I[I[I[I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetGeometry
+ (JNIEnv *env, jclass that, jint display, jint drawable, jintArray root_return, jintArray x_return, jintArray y_return, jintArray width_return, jintArray height_return, jintArray border_width_return, jintArray depth_return)
+{
+ jint *root_return1=NULL, *x_return1=NULL, *y_return1=NULL, *width_return1=NULL, *height_return1=NULL, *border_width_return1=NULL, *depth_return1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetGeometry\n");
+#endif
+
+ if (root_return)
+ root_return1 = (*env)->GetIntArrayElements(env, root_return, NULL);
+ if (x_return)
+ x_return1 = (*env)->GetIntArrayElements(env, x_return, NULL);
+ if (y_return)
+ y_return1 = (*env)->GetIntArrayElements(env, y_return, NULL);
+ if (width_return)
+ width_return1 = (*env)->GetIntArrayElements(env, width_return, NULL);
+ if (height_return)
+ height_return1 = (*env)->GetIntArrayElements(env, height_return, NULL);
+ if (border_width_return)
+ border_width_return1 = (*env)->GetIntArrayElements(env, border_width_return, NULL);
+ if (depth_return)
+ depth_return1 = (*env)->GetIntArrayElements(env, depth_return, NULL);
+
+ rc = (jint) XGetGeometry((Display *)display, drawable, (Window *)root_return1, (int *)x_return1, (int *)y_return1, (unsigned int *)width_return1, (unsigned int *)height_return1, (unsigned int *)border_width_return1, (unsigned int *)depth_return1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XGetGeometry: call failed rc = %d\n", rc);
+#endif
+
+ if (root_return)
+ (*env)->ReleaseIntArrayElements(env, root_return, root_return1, 0);
+ if (x_return)
+ (*env)->ReleaseIntArrayElements(env, x_return, x_return1, 0);
+ if (y_return)
+ (*env)->ReleaseIntArrayElements(env, y_return, y_return1, 0);
+ if (width_return)
+ (*env)->ReleaseIntArrayElements(env, width_return, width_return1, 0);
+ if (height_return)
+ (*env)->ReleaseIntArrayElements(env, height_return, height_return1, 0);
+ if (border_width_return)
+ (*env)->ReleaseIntArrayElements(env, border_width_return, border_width_return1, 0);
+ if (depth_return)
+ (*env)->ReleaseIntArrayElements(env, depth_return, depth_return1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetImage
+ * Signature: (IIIIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetImage
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint x, jint y, jint width, jint height, jint plane_mask, jint format)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetImage\n");
+#endif
+ return (jint) XGetImage((Display *)display, (Drawable)drawable, x, y, width, height, plane_mask, format);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetInputFocus
+ * Signature: (I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetInputFocus
+ (JNIEnv *env, jclass that, jint display, jintArray window, jintArray revert)
+{
+ jint *window1, *revert1;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetInputFocus\n");
+#endif
+
+ if (window)
+ window1 = (*env)->GetIntArrayElements(env, window, NULL);
+ if (revert)
+ revert1 = (*env)->GetIntArrayElements(env, revert, NULL);
+ rc = (jint) XGetInputFocus((Display *)display, (Window *)window1, (int *)revert1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XGetInputFocus: call failed rc = %d\n", rc);
+#endif
+
+ if (window)
+ (*env)->ReleaseIntArrayElements(env, window, window1, 0);
+ if (revert)
+ (*env)->ReleaseIntArrayElements(env, revert, revert1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetWindowAttributes
+ * Signature: (IILorg/eclipse/swt/internal/motif/XWindowAttributes;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetWindowAttributes
+ (JNIEnv *env, jclass that, jint display, jint window, jobject attributes)
+{
+ DECL_GLOB(pGlob)
+ XWindowAttributes xWindowAttributes, *lpxWindowAttributes;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetWindowAttributes\n");
+#endif
+
+ if (attributes) {
+ lpxWindowAttributes = &xWindowAttributes;
+ cacheXwindowattributesFids(env, attributes, &PGLOB(XwindowattributesFc));
+ getXwindowattributesFields(env, attributes, lpxWindowAttributes, &PGLOB(XwindowattributesFc));
+ }
+
+ rc = (jboolean) XGetWindowAttributes((Display *)display, window, lpxWindowAttributes);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XGetWindowAttributes: call failed rc = %d\n", rc);
+#endif
+
+ if (attributes) {
+ setXwindowattributesFields(env, attributes, lpxWindowAttributes, &PGLOB(XwindowattributesFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGrabPointer
+ * Signature: (IIIIIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGrabPointer
+ (JNIEnv *env, jclass that, jint display, jint grabWindow, jint ownerEvents, jint eventMask,
+ jint PointerMode, jint KeyboardMode, jint confineToWindow, jint cursor, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGrabPointer\n");
+#endif
+ return (jint) XGrabPointer((Display *)display, grabWindow, ownerEvents, eventMask, PointerMode,
+ KeyboardMode, confineToWindow, cursor, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XKeysymToString
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XKeysymToString
+ (JNIEnv *env, jclass that, jint keysym)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XKeysymToString\n");
+#endif
+ return (jint) XKeysymToString(keysym);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XListFonts
+ * Signature: (I[BI[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XListFonts
+ (JNIEnv *env, jclass that, jint display, jbyteArray pattern, jint maxnames, jintArray actual_count_return)
+{
+ jbyte *pattern1 = NULL;
+ jint *actual_count_return1=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XListFonts\n");
+#endif
+ if (pattern)
+ pattern1 = (*env)->GetByteArrayElements(env, pattern, NULL);
+ if (actual_count_return)
+ actual_count_return1 = (*env)->GetIntArrayElements(env, actual_count_return, NULL);
+
+ rc = (jint) XListFonts((Display *)display, (char *)pattern1, maxnames, (int *)actual_count_return1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XListFonts: call failed rc = %d\n", rc);
+#endif
+
+ if (pattern)
+ (*env)->ReleaseByteArrayElements(env, pattern, pattern1, 0);
+ if (actual_count_return)
+ (*env)->ReleaseIntArrayElements(env, actual_count_return, actual_count_return1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XLookupString
+ * Signature: (Lorg/eclipse/swt/internal/motif/XKeyEvent;[BI[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XLookupString
+ (JNIEnv *env, jclass that, jobject keyEvent, jbyteArray string, jint size, jintArray keysym, jintArray status)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jint *keysym1=NULL, *status1=NULL;
+ jbyte *string1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XLookupString\n");
+#endif
+
+ if (keyEvent) {
+ lpxEvent = &xEvent;
+ cacheXkeyeventFids(env, keyEvent, &PGLOB(XkeyeventFc));
+ getXkeyeventFields(env, keyEvent, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ if (keysym)
+ keysym1 = (*env)->GetIntArrayElements(env, keysym, NULL);
+ if (status)
+ status1 = (*env)->GetIntArrayElements(env, status, NULL);
+ rc = (jint) XLookupString((XKeyEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (XComposeStatus *)status1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc < 0)
+ fprintf(stderr, "XLookupString: call failed rc = %d\n", rc);
+#endif
+
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ if (keysym)
+ (*env)->ReleaseIntArrayElements(env, keysym, keysym1, 0);
+ if (status)
+ (*env)->ReleaseIntArrayElements(env, status, status1, 0);
+
+ if (keyEvent) {
+ setXkeyeventFields(env, keyEvent, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XLowerWindow
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XLowerWindow
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XLowerWindow\n");
+#endif
+ return (jint) XLowerWindow((Display *)display, window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XPointInRegion
+ * Signature: (III)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XPointInRegion
+ (JNIEnv *env, jclass that, jint region, jint x, jint y)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XPointInRegion\n");
+#endif
+ return (jboolean) XPointInRegion((Region)region, x, y);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XPutImage
+ * Signature: (IIIIIIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XPutImage
+ (JNIEnv *env, jclass that, jint display, jint drawable, jint gc, jint image, jint srcX, jint srcY, jint destX, jint destY, jint width, jint height)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XPutImage\n");
+#endif
+ return (jint) XPutImage((Display *)display, drawable, (GC)gc, (XImage *)image, srcX, srcY, destX, destY, width, height);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XQueryColor
+ * Signature: (IILorg/eclipse/swt/internal/motif/XColor;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XQueryColor
+ (JNIEnv *env, jclass that, jint display, jint colormap, jobject color)
+{
+ DECL_GLOB(pGlob)
+ XColor xColor, *lpColor=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XQueryColor\n");
+#endif
+
+ if (color) {
+ lpColor = &xColor;
+ cacheXcolorFids(env, color, &PGLOB(XcolorFc));
+ getXcolorFields(env, color, lpColor, &PGLOB(XcolorFc));
+ }
+
+ rc = (jint) XQueryColor((Display *)display, colormap, lpColor);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XQueryColor: call failed rc = %d\n", rc);
+#endif
+
+ if (color) {
+ setXcolorFields(env, color, lpColor, &PGLOB(XcolorFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XQueryPointer
+ * Signature: (II[I[I[I[I[I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XQueryPointer
+ (JNIEnv *env, jclass that, jint display, jint window, jintArray root, jintArray child,
+ jintArray rootX, jintArray rootY, jintArray windowX, jintArray windowY, jintArray mask)
+{
+ jint *root1=NULL, *child1=NULL, *rootX1=NULL, *rootY1=NULL, *windowX1=NULL, *windowY1=NULL, *mask1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XQueryPointer\n");
+#endif
+
+ if (root)
+ root1 = (*env)->GetIntArrayElements(env, root, NULL);
+ if (child)
+ child1 = (*env)->GetIntArrayElements(env, child, NULL);
+ if (rootX)
+ rootX1 = (*env)->GetIntArrayElements(env, rootX, NULL);
+ if (rootY)
+ rootY1 = (*env)->GetIntArrayElements(env, rootY, NULL);
+ if (windowX)
+ windowX1 = (*env)->GetIntArrayElements(env, windowX, NULL);
+ if (windowY)
+ windowY1 = (*env)->GetIntArrayElements(env, windowY, NULL);
+ if (mask)
+ mask1 = (*env)->GetIntArrayElements(env, mask, NULL);
+
+ rc = (jint) XQueryPointer((Display *)display, window, (Window *)root1, (Window *)child1, (int *)rootX1, (int *)rootY1, (int *)windowX1, (int *)windowY1, (unsigned int *)mask1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XQueryPointer: call failed rc = %d\n", rc);
+#endif
+
+ if (root)
+ (*env)->ReleaseIntArrayElements(env, root, root1, 0);
+ if (child)
+ (*env)->ReleaseIntArrayElements(env, child, child1, 0);
+ if (rootX)
+ (*env)->ReleaseIntArrayElements(env, rootX, rootX1, 0);
+ if (rootY)
+ (*env)->ReleaseIntArrayElements(env, rootY, rootY1, 0);
+ if (windowX)
+ (*env)->ReleaseIntArrayElements(env, windowX, windowX1, 0);
+ if (windowY)
+ (*env)->ReleaseIntArrayElements(env, windowY, windowY1, 0);
+ if (mask)
+ (*env)->ReleaseIntArrayElements(env, mask, mask1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XQueryTree
+ * Signature: (II[I[I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XQueryTree
+ (JNIEnv *env, jclass that, jint display, jint window, jintArray root_return, jintArray parent_return, jintArray children_return, jintArray nChildren_return)
+{
+ jint *root_return1=NULL, *parent_return1=NULL, *children_return1=NULL, *nChildren_return1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XQueryTree\n");
+#endif
+
+ if (root_return)
+ root_return1 = (*env)->GetIntArrayElements(env, root_return, NULL);
+ if (parent_return)
+ parent_return1 = (*env)->GetIntArrayElements(env, parent_return, NULL);
+ if (children_return)
+ children_return1 = (*env)->GetIntArrayElements(env, children_return, NULL);
+ if (nChildren_return)
+ nChildren_return1 = (*env)->GetIntArrayElements(env, nChildren_return, NULL);
+
+ rc = (jint) XQueryTree((Display *)display, window, (Window *)root_return1, (Window *)parent_return1, (Window **)children_return1, (unsigned int *)nChildren_return1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XQueryTree: call failed rc = %d\n", rc);
+#endif
+
+ if (root_return)
+ (*env)->ReleaseIntArrayElements(env, root_return, root_return1, 0);
+ if (parent_return)
+ (*env)->ReleaseIntArrayElements(env, parent_return, parent_return1, 0);
+ if (children_return)
+ (*env)->ReleaseIntArrayElements(env, children_return, children_return1, 0);
+ if (nChildren_return)
+ (*env)->ReleaseIntArrayElements(env, nChildren_return, nChildren_return1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XRaiseWindow
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XRaiseWindow
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XRaiseWindow\n");
+#endif
+ return (jint) XRaiseWindow((Display *)display, window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XReconfigureWMWindow
+ * Signature: (IIIILorg/eclipse/swt/internal/motif/XWindowChanges;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XReconfigureWMWindow
+ (JNIEnv *env, jclass that, jint display, jint window, jint screen, jint valueMask, jobject values)
+{
+ DECL_GLOB(pGlob)
+ XWindowChanges xWindowChanges, *lpWindowChanges1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XReconfigureWMWindow\n");
+#endif
+
+ if (values) {
+ lpWindowChanges1 = &xWindowChanges;
+ cacheXwindowchangesFids(env, values, &PGLOB(XwindowchangesFc));
+ getXwindowchangesFields(env, values, lpWindowChanges1, &PGLOB(XwindowchangesFc));
+ }
+ rc = (jint) XReconfigureWMWindow((Display *)display, window, screen, valueMask, lpWindowChanges1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XReconfigureWMWindow: call failed rc = %d\n", rc);
+#endif
+
+ if (values) {
+ setXwindowchangesFields(env, values, lpWindowChanges1, &PGLOB(XwindowchangesFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XRectInRegion
+ * Signature: (IIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XRectInRegion
+ (JNIEnv *env, jclass that, jint region, jint x, jint y, jint width, jint height)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XRectInRegion\n");
+#endif
+ return (jint) XRectInRegion((Region)region, x, y, width, height);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetBackground
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetBackground
+ (JNIEnv *env, jclass that, jint display, jint gc, jint background)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetBackground\n");
+#endif
+ XSetBackground((Display *)display, (GC)gc, background);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetClipMask
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetClipMask
+ (JNIEnv *env, jclass that, jint display, jint gc, jint pixmap)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetClipMask\n");
+#endif
+ XSetClipMask((Display *)display, (GC)gc, pixmap);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetClipRectangles
+ * Signature: (IIIILorg/eclipse/swt/internal/motif/XRectangle;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetClipRectangles
+ (JNIEnv *env, jclass that, jint display, jint gc, jint clip_x_origin, jint clip_y_origin, jobject rectangle, jint n, jint ordering)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetClipRectangles\n");
+#endif
+
+ if (rectangle) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, rectangle, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ XSetClipRectangles((Display *)display, (GC)gc, clip_x_origin, clip_y_origin, lpxRect, n, ordering);
+ if (rectangle) {
+ setXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetDashes
+ * Signature: (III[BI)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetDashes
+ (JNIEnv *env, jclass that, jint display, jint gc, jint dash_offset, jbyteArray dash_list, jint n)
+{
+ jbyte *dash_list1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetDashes\n");
+#endif
+
+ if (dash_list)
+ dash_list1 = (*env)->GetByteArrayElements(env, dash_list, NULL);
+ rc = (jint) XSetDashes((Display *)display, (GC)gc, dash_offset, (char *)dash_list1, n);
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XSetDashes: call failed rc = %d\n", rc);
+#endif
+ if (dash_list)
+ (*env)->ReleaseByteArrayElements(env, dash_list, dash_list1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetErrorHandler
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetErrorHandler
+ (JNIEnv *env, jclass that, jint handler)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetErrorHandler\n");
+#endif
+ return (jint) XSetErrorHandler((XErrorHandler)handler);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetFillStyle
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetFillStyle
+ (JNIEnv *env, jclass that, jint display, jint gc, jint fill_style)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetFillStyle\n");
+#endif
+ XSetFillStyle((Display*)display, (GC)gc, fill_style);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetFont
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetFont
+ (JNIEnv *env, jclass that, jint display, jint gc, jint font)
+{
+ return (jint) XSetFont((Display *)display, (GC)gc, (Font)font);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetForeground
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetForeground
+ (JNIEnv *env, jclass that, jint display, jint gc, jint foreground)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetForeground\n");
+#endif
+ XSetForeground((Display *)display, (GC)gc, foreground);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetFunction
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetFunction
+ (JNIEnv *env, jclass that, jint display, jint gc, jint function)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetFunction\n");
+#endif
+ XSetFunction((Display *)display, (GC)gc, function);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetGraphicsExposures
+ * Signature: (IIZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetGraphicsExposures
+ (JNIEnv *env, jclass that, jint display, jint gc, jboolean graphics_exposures)
+{
+ XSetGraphicsExposures((Display *)display, (GC)gc, (Bool) graphics_exposures);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetInputFocus
+ * Signature: (IIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetInputFocus
+ (JNIEnv *env, jclass that, jint display, jint window, jint revert, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetInputFocus\n");
+#endif
+
+ return (jint) XSetInputFocus((Display *)display, window, revert, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetLineAttributes
+ * Signature: (IIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetLineAttributes
+ (JNIEnv *env, jclass that, jint display, jint gc, jint lineWidth, jint lineStyle, jint capStyle, jint joinStyle)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetLineAttributes\n");
+#endif
+ return (jint) XSetLineAttributes((Display *)display, (GC)gc, lineWidth, lineStyle, capStyle, joinStyle);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetRegion
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetRegion
+ (JNIEnv *env, jclass that, jint display, jint gc, jint region)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetRegion\n");
+#endif
+ XSetRegion((Display *)display, (GC)gc, (Region)region);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetStipple
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetStipple
+ (JNIEnv *env, jclass that, jint display, jint gc, jint pixmap)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetStipple\n");
+#endif
+ XSetStipple((Display*)display, (GC)gc, pixmap);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetSubwindowMode
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetSubwindowMode
+ (JNIEnv *env, jclass that, jint display, jint gc, jint subwindow_mode)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetSubwindowMode\n");
+#endif
+ XSetSubwindowMode((Display*)display, (GC)gc, subwindow_mode);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetWindowBorderWidth
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetWindowBorderWidth
+ (JNIEnv *env, jclass that, jint display, jint window, jint width)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetWindowBorderWidth\n");
+#endif
+ XSetWindowBorderWidth((Display *)display, window, width);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSubtractRegion
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSubtractRegion
+ (JNIEnv *env, jclass that, jint sra, jint srb, jint da_return)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSubtractRegion\n");
+#endif
+ XSubtractRegion((Region)sra, (Region)srb, (Region)da_return);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSync
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSync
+ (JNIEnv *env, jclass that, jint display, jboolean discard)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSync\n");
+#endif
+ XSync((Display *)display, (Bool)discard);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSynchronize
+ * Signature: (IZ)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSynchronize
+ (JNIEnv *env, jclass that, jint display, jboolean onoff)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSynchronize\n");
+#endif
+ return (jint) XSynchronize((Display *)display, (Bool)onoff);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XUndefineCursor
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XUndefineCursor
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XUndefineCursor\n");
+#endif
+ XUndefineCursor((Display *)display, window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XUngrabPointer
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XUngrabPointer
+ (JNIEnv *env, jclass that, jint display, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XUngrabPointer\n");
+#endif
+ return (jint) XUngrabPointer((Display *)display, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XUnionRectWithRegion
+ * Signature: (Lorg/eclipse/swt/internal/motif/XRectangle;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XUnionRectWithRegion
+ (JNIEnv *env, jclass that, jobject rectangle, jint src_region, jint dest_region)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XUnionRectWithRegion\n");
+#endif
+
+ if (rectangle) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, rectangle, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ XUnionRectWithRegion(lpxRect, (Region)src_region, (Region)dest_region);
+ if (rectangle) {
+ setXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XUnionRegion
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XUnionRegion
+ (JNIEnv *env, jclass that, jint sra, jint srb, jint dr_return)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XUnionRegion\n");
+#endif
+ XUnionRegion((Region)sra, (Region)srb, (Region)dr_return);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XWhitePixel
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XWhitePixel
+ (JNIEnv *env, jclass that, jint display, jint screenNum)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XWhitePixel\n");
+#endif
+ return (jint) XWhitePixel((Display *)display, screenNum);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XWithdrawWindow
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XWithdrawWindow
+ (JNIEnv *env, jclass that, jint display, jint window, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XWithdrawWindow\n");
+#endif
+ XWithdrawWindow((Display *)display, (Window)window, screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmAddWMProtocolCallback
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmAddWMProtocolCallback
+ (JNIEnv *env, jclass that, jint shell, jint protocol, jint callback, jint closure)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmAddWMProtocolCallback\n");
+#endif
+ XmAddWMProtocolCallback((Widget)shell, (Atom)protocol, (XtCallbackProc)callback, (XtPointer)closure);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmChangeColor
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmChangeColor
+ (JNIEnv *env, jclass that, jint widget, jint pixel)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmChangeColor\n");
+#endif
+ XmChangeColor((Widget)widget, pixel);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmComboBoxAddItem
+ * Signature: (IIIZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmComboBoxAddItem
+ (JNIEnv *env, jclass that, jint combo, jint xmString, jint position, jboolean unique)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmComboBoxAddItem\n");
+#endif
+ XmComboBoxAddItem((Widget)combo, (XmString) xmString, position, unique);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmComboBoxDeletePos
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmComboBoxDeletePos
+ (JNIEnv *env, jclass that, jint combo, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmComboBoxDeletePos\n");
+#endif
+ XmComboBoxDeletePos((Widget)combo, position);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmComboBoxSelectItem
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmComboBoxSelectItem
+ (JNIEnv *env, jclass that, jint combo, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmComboBoxSelectItem\n");
+#endif
+ XmComboBoxSelectItem((Widget)combo, (XmString) xmString);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateArrowButton
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateArrowButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jint *name1=NULL, *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateArrowButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetIntArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateArrowButton((Widget)parent, (char *)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateArrowButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseIntArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateCascadeButtonGadget
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateCascadeButtonGadget
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateCascadeButtonGadget\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateCascadeButtonGadget((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateCascadeButtonGadget: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateComboBox
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateComboBox
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateComboBox\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateComboBox((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateComboBox: call failed rc = %d\n", rc);
+#endif
+
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateDialogShell
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateDialogShell
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateDialogShell\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateDialogShell((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateDialogShell: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateDrawingArea
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateDrawingArea
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateDrawingArea\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateDrawingArea((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateDrawingArea: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateErrorDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateErrorDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateErrorDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateErrorDialog((struct _WidgetRec*)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateErrorDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateFileSelectionDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateFileSelectionDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateFileSelectionDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateFileSelectionDialog((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateFileSelectionDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateForm
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateForm
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateForm\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateForm((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateForm: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateFrame
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateFrame
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateFrame\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateFrame((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateFrame: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateInformationDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateInformationDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateInformationDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+
+ rc = (jint)XmCreateInformationDialog((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateInformationDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateLabel
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateLabel
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateLabel\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateLabel((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateLabel: call failed rc = %d\n", rc);
+#endif
+
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateList
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateList
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *arglist1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateList\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint) XmCreateList((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateList: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateMainWindow
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateMainWindow
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateMainWindow\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateMainWindow((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateMainWindow: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateMenuBar
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateMenuBar
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateMenuBar\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateMenuBar((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateMenuBar: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateMessageDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateMessageDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateMessageDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateMessageDialog((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateMessageDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreatePopupMenu
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreatePopupMenu
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreatePopupMenu\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreatePopupMenu((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreatePopupMenu: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method:
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreatePulldownMenu
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreatePulldownMenu\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreatePulldownMenu((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreatePulldownMenu: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreatePushButton
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreatePushButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1 = NULL;
+ jint *argList1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreatePushButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+
+ rc = (jint) XmCreatePushButton((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreatePushButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreatePushButtonGadget
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreatePushButtonGadget
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreatePushButtonGadget\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreatePushButtonGadget((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreatePushButtonGadget: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateQuestionDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateQuestionDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateQuestionDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateQuestionDialog((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateQuestionDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateScale
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateScale
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateScale\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+
+ rc = (jint) XmCreateScale((Widget)parent, (String)name1, (ArgList) arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateScale: call failed rc = %d\n", rc);
+#endif
+
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateScrollBar
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateScrollBar
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateScrollBar\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateScrollBar((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateScrollBar: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateScrolledList
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateScrolledList
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateScrolledList\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateScrolledList((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateScrolledList: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateScrolledText
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateScrolledText
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateScrolledText\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateScrolledText((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateScrolledText: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateSeparator
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateSeparator
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateSeparator\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateSeparator((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateSeparator: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateSeparatorGadget
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateSeparatorGadget
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateSeparatorGadget\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateSeparatorGadget((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateSeparatorGadget: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateTextField
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateTextField
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateTextField\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateTextField((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateTextField: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateToggleButton
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateToggleButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateToggleButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateToggleButton((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateToggleButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateToggleButtonGadget
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateToggleButtonGadget
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateToggleButtonGadget\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateToggleButtonGadget((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateToggleButtonGadget: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateWarningDialog
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateWarningDialog
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateWarningDialog\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ rc = (jint)XmCreateWarningDialog((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateWarningDialog: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDragCancel
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDragCancel
+ (JNIEnv *env, jclass that, jint dragcontext)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDragCancel\n");
+#endif
+
+ XmDragCancel((Widget)dragcontext);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDragStart
+ * Signature: (II[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDragStart
+ (JNIEnv *env, jclass that, jint widget, jobject event, jintArray arglist, jint argcount)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jint *arglist1;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDragStart\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ if (arglist) {
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ }
+ rc = (jint) XmDragStart((Widget)widget, (XEvent *)lpxEvent, (ArgList)arglist1, (Cardinal)argcount);
+ if (event) {
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ if (arglist) {
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropSiteRegister
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropSiteRegister
+ (JNIEnv *env, jclass that, jint widget, jintArray arglist, jint argcount)
+{
+ jint *arglist1;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropSiteRegister\n");
+#endif
+
+ if (arglist) {
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ }
+ XmDropSiteRegister((Widget)widget, (ArgList)arglist1, (Cardinal)argcount);
+ if (arglist) {
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropSiteRetrieve
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropSiteRetrieve
+ (JNIEnv *env, jclass that, jint widget, jintArray arglist, jint argcount)
+{
+ jint *arglist1;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropSiteRetrieve\n");
+#endif
+
+ if (arglist) {
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ }
+ XmDropSiteRetrieve((Widget)widget, (ArgList)arglist1, (Cardinal)argcount);
+ if (arglist) {
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropSiteUnregister
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropSiteUnregister
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropSiteUnregister\n");
+#endif
+ XmDropSiteUnregister((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropSiteUpdate
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropSiteUpdate
+ (JNIEnv *env, jclass that, jint widget, jintArray arglist, jint argcount)
+{
+ jint *arglist1;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropSiteUpdate\n");
+#endif
+
+ if (arglist) {
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ }
+ XmDropSiteUpdate((Widget)widget, (ArgList)arglist1, (Cardinal)argcount);
+ if (arglist) {
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropTransferAdd
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropTransferAdd
+ (JNIEnv *env, jclass that, jint drop_transfer, jintArray transfers, jint num_transfers)
+{
+ jint *transfers1;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropTransferAdd\n");
+#endif
+
+ if (transfers) {
+ transfers1 = (*env)->GetIntArrayElements(env, transfers, NULL);
+ }
+ XmDropTransferAdd((Widget)drop_transfer, (XmDropTransferEntryRec *)transfers1, (Cardinal)num_transfers);
+ if (transfers) {
+ (*env)->ReleaseIntArrayElements(env, transfers, transfers1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDropTransferStart
+ * Signature: (I[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDropTransferStart
+ (JNIEnv *env, jclass that, jint widget, jintArray arglist, jint argcount)
+{
+ jint *arglist1;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDropTransferStart\n");
+#endif
+
+ if (arglist) {
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+ }
+ rc = (jint) XmDropTransferStart((Widget)widget, (ArgList)arglist1, (Cardinal)argcount);
+ if (arglist) {
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFileSelectionBoxGetChild
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFileSelectionBoxGetChild
+ (JNIEnv *env, jclass that, jint widget, jint child)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFileSelectionBoxGetChild\n");
+#endif
+ return (jint) XmFileSelectionBoxGetChild((Widget)widget, child);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListAppendEntry
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListAppendEntry
+ (JNIEnv *env, jclass that, jint oldlist, jint entry)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListAppendEntry\n");
+#endif
+ return (jint) XmFontListAppendEntry((XmFontList)oldlist, (XmFontListEntry)entry);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListEntryFree
+ * Signature: ([I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListEntryFree
+ (JNIEnv *env, jclass that, jintArray entry)
+{
+ jint *entry1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListEntryFree\n");
+#endif
+
+ if (entry)
+ entry1 = (*env)->GetIntArrayElements(env, entry, NULL);
+ XmFontListEntryFree((XmFontListEntry *)entry1);
+ if (entry)
+ (*env)->ReleaseIntArrayElements(env, entry, entry1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListEntryGetFont
+ * Signature: (I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListEntryGetFont
+ (JNIEnv *env, jclass that, jint entry, jintArray type_return)
+{
+ jint *type_return1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListEntryGetFont\n");
+#endif
+
+ if (type_return)
+ type_return1 = (*env)->GetIntArrayElements(env, type_return, NULL);
+ rc = (jint) XmFontListEntryGetFont((XmFontListEntry)entry, (XmFontType *)type_return1);
+ if (type_return)
+ (*env)->ReleaseIntArrayElements(env, type_return, type_return1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListEntryLoad
+ * Signature: (I[BI[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListEntryLoad
+ (JNIEnv *env, jclass that, jint display, jbyteArray fontName, jint type, jbyteArray tag)
+{
+ char *fontName1=NULL, *tag1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListEntryLoad\n");
+#endif
+
+ if (fontName)
+ fontName1 = (char *)(*env)->GetByteArrayElements(env, fontName, NULL);
+ if (tag)
+ tag1 = (char *)(*env)->GetByteArrayElements(env, tag, NULL);
+ rc = (jint)XmFontListEntryLoad((Display *)display, fontName1, type, tag1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmFontListEntryLoad: call failed rc = %d\n", rc);
+#endif
+
+ if (fontName)
+ (*env)->ReleaseByteArrayElements(env, fontName, (jbyte *)fontName1, 0);
+ if (tag)
+ (*env)->ReleaseByteArrayElements(env, tag, (jbyte *)tag1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListFree
+ (JNIEnv *env, jclass that, jint list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListFree\n");
+#endif
+ XmFontListFree((XmFontList)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListFreeFontContext
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListFreeFontContext
+ (JNIEnv *env, jclass that, jint context)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListFreeFontContext\n");
+#endif
+ XmFontListFreeFontContext((XmFontContext)context);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListInitFontContext
+ * Signature: ([II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListInitFontContext
+ (JNIEnv *env, jclass that, jintArray context, jint fontlist)
+{
+ jint *context1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListInitFontContext\n");
+#endif
+
+ if (context)
+ context1 = (*env)->GetIntArrayElements(env, context, NULL);
+ rc = XmFontListInitFontContext((XmFontContext *)context1, (XmFontList)fontlist);
+ if (context)
+ (*env)->ReleaseIntArrayElements(env, context, context1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListNextEntry
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListNextEntry
+ (JNIEnv *env, jclass that, jint context)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListNextEntry\n");
+#endif
+ return (jint) XmFontListNextEntry((XmFontContext) context);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmFontListCopy
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmFontListCopy
+ (JNIEnv *env, jclass that, jint fontlist)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmFontListCopy\n");
+#endif
+ return (jint) XmFontListCopy((XmFontList) fontlist);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetAtomName
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetAtomName
+ (JNIEnv *env, jclass that, jint display, jint atom)
+{
+ return (jint) XmGetAtomName((Display *)display, (Atom)atom);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetFocusWidget
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetFocusWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmGetFocusWidget\n");
+#endif
+ return (jint) XmGetFocusWidget((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetXmDisplay
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetXmDisplay
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmGetXmDisplay\n");
+#endif
+ return (jint) XmGetXmDisplay((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetDragContext
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetDragContext
+ (JNIEnv *env, jclass that, jint widget, jint timestamp)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmGetDragContext\n");
+#endif
+ return (jint) XmGetDragContext((Widget)widget, (Time)timestamp);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImMbLookupString
+ * Signature: (ILorg/eclipse/swt/internal/motif/XKeyEvent;[BI[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImMbLookupString
+ (JNIEnv *env, jclass that, jint widget, jobject keyEvent, jbyteArray string, jint size, jintArray keysym, jintArray status)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jint *keysym1=NULL, *status1=NULL;
+ jbyte *string1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImMbLookupString\n");
+#endif
+
+ if (keyEvent) {
+ lpxEvent = &xEvent;
+ cacheXkeyeventFids(env, keyEvent, &PGLOB(XkeyeventFc));
+ getXkeyeventFields(env, keyEvent, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ if (keysym)
+ keysym1 = (*env)->GetIntArrayElements(env, keysym, NULL);
+ if (status)
+ status1 = (*env)->GetIntArrayElements(env, status, NULL);
+
+ rc = (jint)XmImMbLookupString((Widget)widget, (XKeyPressedEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (int *)status1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmImMbLookupString: call failed rc = %d\n", rc);
+#endif
+
+ if (keyEvent) {
+ setXkeyeventFields(env, keyEvent, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ if (keysym)
+ keysym1 = (*env)->GetIntArrayElements(env, keysym, NULL);
+ if (status)
+ (*env)->ReleaseIntArrayElements(env, status, status1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmInternAtom
+ * Signature: (I[BZ)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmInternAtom
+ (JNIEnv *env, jclass that, jint display, jbyteArray name, jboolean only_if_exists)
+{
+ jbyte *name1;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmInternAtom\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ rc = (jint) XmInternAtom((Display *)display, (String)name1, only_if_exists);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmInternAtom: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListAddItemUnselected
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListAddItemUnselected
+ (JNIEnv *env, jclass that, jint list, jint xmString, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListAddItemUnselected\n");
+#endif
+ XmListAddItemUnselected((Widget)list, (XmString)xmString, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeleteAllItems
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeleteAllItems
+ (JNIEnv *env, jclass that, jint list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeleteAllItems\n");
+#endif
+ XmListDeleteAllItems((Widget)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeleteItemsPos
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeleteItemsPos
+ (JNIEnv *env, jclass that, jint list, jint item_count, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeleteItemsPos\n");
+#endif
+ XmListDeleteItemsPos((Widget)list, item_count, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeletePos
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeletePos
+ (JNIEnv *env, jclass that, jint list, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeletePos\n");
+#endif
+ XmListDeletePos((Widget)list, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeletePositions
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeletePositions
+ (JNIEnv *env, jclass that, jint list, jintArray position_list, jint position_count)
+{
+ jint *position_list1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeletePositions\n");
+#endif
+
+ if (position_list)
+ position_list1 = (*env)->GetIntArrayElements(env, position_list, NULL);
+ XmListDeletePositions((Widget)list, (int *)position_list1, position_count);
+ if (position_list)
+ (*env)->ReleaseIntArrayElements(env, position_list, position_list1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeselectAllItems
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeselectAllItems
+ (JNIEnv *env, jclass that, jint list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeselectAllItems\n");
+#endif
+ XmListDeselectAllItems((Widget)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeselectPos
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeselectPos
+ (JNIEnv *env, jclass that, jint list, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeselectPos\n");
+#endif
+ XmListDeselectPos((Widget)list, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListGetKbdItemPos
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListGetKbdItemPos
+ (JNIEnv *env, jclass that, jint list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListGetKbdItemPos\n");
+#endif
+ return (jint)XmListGetKbdItemPos((Widget)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListGetSelectedPos
+ * Signature: (I[I[I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListGetSelectedPos
+ (JNIEnv *env, jclass that, jint list, jintArray positions, jintArray count)
+{
+ jint *positions1=NULL, *count1=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListGetSelectedPos\n");
+#endif
+
+ if (positions)
+ positions1 = (*env)->GetIntArrayElements(env, positions, NULL);
+ if (count)
+ count1 = (*env)->GetIntArrayElements(env, count, NULL);
+ rc = (jboolean)XmListGetSelectedPos((Widget)list, (int **)positions1, (int *)count1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc != True && rc != False)
+ fprintf(stderr, "XmListGetSelectedPos: call failed rc = %d\n", rc);
+#endif
+
+ if (positions)
+ (*env)->ReleaseIntArrayElements(env, positions, positions1, 0);
+ if (count)
+ (*env)->ReleaseIntArrayElements(env, count, count1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListItemPos
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListItemPos
+ (JNIEnv *env, jclass that, jint list, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListItemPos\n");
+#endif
+ return (jint)XmListItemPos((Widget)list, (XmString)xmString);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListPosSelected
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListPosSelected
+ (JNIEnv *env, jclass that, jint list, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListPosSelected\n");
+#endif
+ return (jboolean)XmListPosSelected((Widget)list, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListReplaceItemsPosUnselected
+ * Signature: (I[III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListReplaceItemsPosUnselected
+ (JNIEnv *env, jclass that, jint list, jintArray newItems, jint item_count, jint position)
+{
+ jint *newItems1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListReplaceItemsPosUnselected\n");
+#endif
+
+ if (newItems)
+ newItems1 = (*env)->GetIntArrayElements(env, newItems, NULL);
+ XmListReplaceItemsPosUnselected((Widget)list, (XmString *)newItems1, item_count, position);
+ if (newItems)
+ (*env)->ReleaseIntArrayElements(env, newItems, newItems1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListSelectPos
+ * Signature: (IIZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListSelectPos
+ (JNIEnv *env, jclass that, jint list, jint position, jboolean notify)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListSelectPos\n");
+#endif
+ XmListSelectPos((Widget)list, position, notify);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListSetKbdItemPos
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListSetKbdItemPos
+ (JNIEnv *env, jclass that, jint list, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListSetKbdItemPos\n");
+#endif
+ return (jboolean)XmListSetKbdItemPos((Widget)list, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListSetPos
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListSetPos
+ (JNIEnv *env, jclass that, jint list, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListSetPos\n");
+#endif
+ XmListSetPos((Widget)list, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListUpdateSelectedList
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListUpdateSelectedList
+ (JNIEnv *env, jclass that, jint list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListUpdateSelectedList\n");
+#endif
+ XmListUpdateSelectedList((Widget)list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmMainWindowSetAreas
+ * Signature: (IIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmMainWindowSetAreas
+ (JNIEnv *env, jclass that, jint widget, jint menu, jint command, jint hscroll, jint vscroll, jint wregion)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmMainWindowSetAreas\n");
+#endif
+ XmMainWindowSetAreas((Widget)widget, (Widget)menu, (Widget)command, (Widget)hscroll, (Widget)vscroll, (Widget)wregion);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmMenuShellWidgetClass
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmMenuShellWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmMenuShellWidgetClass\n");
+#endif
+ return (jint)xmMenuShellWidgetClass;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmMessageBoxGetChild
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmMessageBoxGetChild
+ (JNIEnv *env, jclass that, jint widget, jint child)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmMessageBoxGetChild\n");
+#endif
+ return (jint)XmMessageBoxGetChild((Widget)widget, child);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmProcessTraversal
+ * Signature: (II)
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmProcessTraversal
+ (JNIEnv *env, jclass that, jint widget, jint dir)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmProcessTraversal\n");
+#endif
+ return (jboolean) XmProcessTraversal((Widget)widget, dir);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmPushButtonWidgetClass
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmPushButtonWidgetClass
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmPushButtonWidgetClass\n");
+#endif
+ return (jint)xmPushButtonWidgetClass;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringCompare
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringCompare
+ (JNIEnv *env, jclass that, jint xmString1, jint xmString2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringCompare\n");
+#endif
+ return (jboolean) XmStringCompare((XmString)xmString1, (XmString)xmString2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringCreate
+ * Signature: ([B[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringCreate
+ (JNIEnv *env, jclass that, jbyteArray string, jbyteArray charset)
+{
+ jbyte *string1=NULL, *charset1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringCreate\n");
+#endif
+
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ if (charset)
+ charset1 = (*env)->GetByteArrayElements(env, charset, NULL);
+ rc = (jint) XmStringCreate((char *)string1, (char *)charset1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmStringCreate: call failed rc = %d\n", rc);
+#endif
+
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ if (charset)
+ (*env)->ReleaseByteArrayElements(env, charset, charset1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringCreateLocalized
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringCreateLocalized
+ (JNIEnv *env, jclass that, jbyteArray string)
+{
+ jbyte *string1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringCreateLocalized\n");
+#endif
+
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ rc = (jint)XmStringCreateLocalized((char *)string1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmStringCreateLocalized: call failed rc = %d\n", rc);
+#endif
+
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringCreateLtoR
+ * Signature: ([B[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringCreateLtoR
+ (JNIEnv *env, jclass that, jbyteArray string, jbyteArray charset)
+{
+ jbyte *string1=NULL, *charset1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringCreateLtoR\n");
+#endif
+
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ if (charset)
+ charset1 = (*env)->GetByteArrayElements(env, charset, NULL);
+ rc = (jint) XmStringCreateLtoR((char *)string1, (char *)charset1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmStringCreateLtoR: call failed rc = %d\n", rc);
+#endif
+
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ if (charset)
+ (*env)->ReleaseByteArrayElements(env, charset, charset1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringDraw
+ * Signature: (IIIIIIIIIILorg/eclipse/swt/internal/motif/XRectangle;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringDraw
+ (JNIEnv *env, jclass that, jint display, jint window, jint fontlist, jint xmString, jint gc, jint x, jint y, jint width, jint align, jint lay_dir, jobject clip)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "\n");
+#endif
+
+ if (clip) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, clip, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, clip, lpxRect, &PGLOB(XrectangleFc));
+ }
+ XmStringDraw((Display *)display, (Window)window, (XmFontList)fontlist, (XmString)xmString, (GC)gc, x, y, width, align, lay_dir, lpxRect);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringDrawImage
+ * Signature: (IIIIIIIIIILorg/eclipse/swt/internal/motif/XRectangle;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringDrawImage
+ (JNIEnv *env, jclass that, jint display, jint window, jint fontlist, jint xmString, jint gc, jint x, jint y, jint width, jint align, jint lay_dir, jobject clip)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringDrawImage\n");
+#endif
+
+ if (clip) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, clip, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, clip, lpxRect, &PGLOB(XrectangleFc));
+ }
+ XmStringDrawImage((Display *)display, window, (XmFontList)fontlist, (XmString)xmString, (GC)gc, x, y, width, align, lay_dir, lpxRect);
+ if (clip) {
+ setXrectangleFields(env, clip, lpxRect, &PGLOB(XrectangleFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringEmpty
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringEmpty
+ (JNIEnv *env, jclass that, jint s1)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringEmpty\n");
+#endif
+ return (jboolean) XmStringEmpty((XmString)s1);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringFree
+ (JNIEnv *env, jclass that, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringFree\n");
+#endif
+ XmStringFree((XmString)xmString);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringGetLtoR
+ * Signature: (I[B[I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringGetLtoR
+ (JNIEnv *env, jclass that, jint xmString, jbyteArray charset, jintArray text)
+{
+ jbyte *charset1=NULL;
+ jint *text1=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringGetLtoR\n");
+#endif
+
+ if (charset)
+ charset1 = (*env)->GetByteArrayElements(env, charset, NULL);
+ if (text)
+ text1 = (*env)->GetIntArrayElements(env, text, NULL);
+
+ rc = (jboolean) XmStringGetLtoR((XmString)xmString, (char *)charset1, (char **)text1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmStringGetLtoR: call failed rc = %d\n", rc);
+#endif
+
+ if (charset)
+ (*env)->ReleaseByteArrayElements(env, charset, charset1, 0);
+ if (text)
+ (*env)->ReleaseIntArrayElements(env, text, text1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringHeight
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringHeight
+ (JNIEnv *env, jclass that, jint fontlist, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringHeight\n");
+#endif
+ return (jint) XmStringHeight((XmFontList)fontlist, (XmString)xmString);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringWidth
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringWidth
+ (JNIEnv *env, jclass that, jint fontlist, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringWidth\n");
+#endif
+ return (jint) XmStringWidth((XmFontList)fontlist, (XmString)xmString);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextClearSelection
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextClearSelection
+ (JNIEnv *env, jclass that, jint widget, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextClearSelection\n");
+#endif
+ XmTextClearSelection((Widget)widget, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextCopy
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextCopy
+ (JNIEnv *env, jclass that, jint widget, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextCopy\n");
+#endif
+ return (jboolean)XmTextCopy((Widget)widget, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextCut
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextCut
+ (JNIEnv *env, jclass that, jint widget, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextCut\n");
+#endif
+ return (jboolean)XmTextCut((Widget)widget, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextDisableRedisplay
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextDisableRedisplay
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextDisableRedisplay\n");
+#endif
+ XmTextDisableRedisplay((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextEnableRedisplay
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextEnableRedisplay
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextEnableRedisplay\n");
+#endif
+ XmTextEnableRedisplay((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetInsertionPosition
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetInsertionPosition
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetInsertionPosition\n");
+#endif
+ return (jint) XmTextGetInsertionPosition((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetLastPosition
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetLastPosition
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetLastPosition\n");
+#endif
+ return (jint) XmTextGetLastPosition((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetMaxLength
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetMaxLength
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetMaxLength\n");
+#endif
+ return (jint) XmTextGetMaxLength((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetSelection
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetSelection
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetSelection\n");
+#endif
+ return (jint) XmTextGetSelection((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetSelectionPosition
+ * Signature: (I[I[I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetSelectionPosition
+ (JNIEnv *env, jclass that, jint widget, jintArray left, jintArray right)
+{
+ jint *left1=NULL,*right1=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetSelectionPosition\n");
+#endif
+
+ if (left)
+ left1 = (*env)->GetIntArrayElements(env, left, NULL);
+ if (right)
+ right1 = (*env)->GetIntArrayElements(env, right, NULL);
+ rc = (jboolean) XmTextGetSelectionPosition((Widget)widget, (XmTextPosition *)left1, (XmTextPosition *)right1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc != True && rc != False)
+ fprintf(stderr, "XmTextGetSelectionPosition: call failed rc = %d\n", rc);
+#endif
+
+ if (left)
+ (*env)->ReleaseIntArrayElements(env, left, left1, 0);
+ if (right)
+ (*env)->ReleaseIntArrayElements(env, right, right1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetString
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetString
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetString\n");
+#endif
+ return (jint) XmTextGetString((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetSubstring
+ * Signature: (IIII[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetSubstring
+ (JNIEnv *env, jclass that, jint widget, jint start, jint num_chars, jint buffer_size, jbyteArray buffer)
+{
+ jbyte *buffer1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetSubstring\n");
+#endif
+
+ if (buffer)
+ buffer1 = (*env)->GetByteArrayElements(env, buffer, NULL);
+ rc = (jint)XmTextGetSubstring((Widget)widget, start, num_chars, buffer_size, (char *)buffer1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmTextGetSubstring: call failed rc = %d\n", rc);
+#endif
+
+ if (buffer)
+ (*env)->ReleaseByteArrayElements(env, buffer, buffer1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextGetSubstringWcs
+ * Signature: (IIII[C)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextGetSubstringWcs
+ (JNIEnv *env, jclass that, jint widget, jint start, jint num_chars, jint buffer_size, jcharArray buffer)
+{
+ jchar *buffer1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextGetSubstringWcs\n");
+#endif
+
+ if (buffer)
+ buffer1 = (*env)->GetCharArrayElements(env, buffer, NULL);
+
+ rc = (jint)XmTextGetSubstringWcs((Widget) widget, (XmTextPosition) start, num_chars, buffer_size, (wchar_t *) buffer1);
+
+ if (buffer)
+ (*env)->ReleaseCharArrayElements(env, buffer, buffer1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextInsert
+ * Signature: (II[B)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextInsert
+ (JNIEnv *env, jclass that, jint widget, jint position, jbyteArray value)
+{
+ jbyte *value1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextInsert\n");
+#endif
+
+ if (value)
+ value1 = (*env)->GetByteArrayElements(env, value, NULL);
+ XmTextInsert((Widget)widget, position, (char *)value1);
+ if (value)
+ (*env)->ReleaseByteArrayElements(env, value, value1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextPaste
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextPaste
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextPaste\n");
+#endif
+ (jboolean) XmTextPaste((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextFieldPaste
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextFieldPaste
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextFieldPaste\n");
+#endif
+ (jboolean) XmTextFieldPaste((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextRemove
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextRemove
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextRemove\n");
+#endif
+ return (jboolean) XmTextRemove((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextPosToXY
+ * Signature: (II[S[S)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextPosToXY
+ (JNIEnv *env, jclass that, jint widget, jint position, jshortArray x, jshortArray y)
+{
+ jshort *x1=NULL, *y1=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextPosToXY\n");
+#endif
+
+ if (x)
+ x1 = (*env)->GetShortArrayElements(env, x, NULL);
+ if (y)
+ y1 = (*env)->GetShortArrayElements(env, y, NULL);
+ rc = (jboolean) XmTextPosToXY((Widget)widget, (XmTextPosition)position, (Position *)x1, (Position *)y1);
+ if (y)
+ (*env)->ReleaseShortArrayElements(env, y, y1, 0);
+ if (x)
+ (*env)->ReleaseShortArrayElements(env, x, x1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextReplace
+ * Signature: (III[B)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextReplace
+ (JNIEnv *env, jclass that, jint widget, jint from_pos, jint to_pos, jbyteArray value)
+{
+ jbyte *value1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextReplace\n");
+#endif
+
+ if (value)
+ value1 = (*env)->GetByteArrayElements(env, value, NULL);
+
+ XmTextReplace((Widget)widget, from_pos, to_pos, (char *)value1);
+
+ if (value)
+ (*env)->ReleaseByteArrayElements(env, value, value1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextScroll
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextScroll
+ (JNIEnv *env, jclass that, jint widget, jint lines)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextScroll\n");
+#endif
+ XmTextScroll((Widget)widget, lines);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetEditable
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetEditable
+ (JNIEnv *env, jclass that, jint widget, jboolean editable)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetEditable\n");
+#endif
+ XmTextSetEditable((Widget)widget, editable);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetHighlight
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetHighlight
+ (JNIEnv *env, jclass that, jint widget, jint left, jint right, jint mode)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetHighlight\n");
+#endif
+ XmTextSetHighlight((Widget)widget, left, right, mode);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetInsertionPosition
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetInsertionPosition
+ (JNIEnv *env, jclass that, jint widget, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetInsertionPosition\n");
+#endif
+ XmTextSetInsertionPosition((Widget)widget, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetMaxLength
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetMaxLength
+ (JNIEnv *env, jclass that, jint widget, jint max_length)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetMaxLength\n");
+#endif
+ XmTextSetMaxLength((Widget)widget, max_length);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetSelection
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetSelection
+ (JNIEnv *env, jclass that, jint widget, jint first, jint last, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetSelection\n");
+#endif
+ XmTextSetSelection((Widget)widget, first, last, time);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextSetString
+ * Signature: (I[B)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextSetString
+ (JNIEnv *env, jclass that, jint widget, jbyteArray value)
+{
+ jbyte *value1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextSetString\n");
+#endif
+
+ if (value)
+ value1 = (*env)->GetByteArrayElements(env, value, NULL);
+ XmTextSetString((Widget)widget, (char *)value1);
+ if (value)
+ (*env)->ReleaseByteArrayElements(env, value, value1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method:
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextShowPosition
+ (JNIEnv *env, jclass that, jint widget, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextShowPosition\n");
+#endif
+ XmTextShowPosition((Widget)widget, position);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmUpdateDisplay
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmUpdateDisplay
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmUpdateDisplay\n");
+#endif
+ XmUpdateDisplay((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmWidgetGetDisplayRect
+ * Signature: (ILorg/eclipse/swt/internal/motif/XRectangle;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmWidgetGetDisplayRect
+ (JNIEnv *env, jclass that, jint region, jobject rectangle)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmWidgetGetDisplayRect\n");
+#endif
+
+ if (rectangle) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, rectangle, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ rc = (jboolean) XmWidgetGetDisplayRect((Widget)region, (XRectangle *)lpxRect);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmWidgetGetDisplayRect: call failed rc = %d\n", rc);
+#endif
+
+ if (rectangle) {
+ setXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmbLookupString
+ * Signature: (ILorg/eclipse/swt/internal/motif/XInputEvent;[BI[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmbLookupString
+ (JNIEnv *env, jclass that, jint widget, jobject event, jbyteArray string, jint size, jintArray keysym, jintArray status)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jint *keysym1=NULL, *status1=NULL;
+ jbyte *string1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmbLookupString\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXkeyeventFids(env, event, &PGLOB(XkeyeventFc));
+ getXkeyeventFields(env, event, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+ if (string)
+ string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ if (keysym)
+ keysym1 = (*env)->GetIntArrayElements(env, keysym, NULL);
+ if (status)
+ status1 = (*env)->GetIntArrayElements(env, status, NULL);
+
+ rc = (jint)XmImMbLookupString((Widget)widget, (XKeyPressedEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (int *)status1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmImMbLookupString: call failed rc = %d\n", rc);
+#endif
+
+ if (event) {
+ setXkeyeventFields(env, event, lpxEvent, &PGLOB(XkeyeventFc));
+ }
+ if (string)
+ (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ if (keysym)
+ keysym1 = (*env)->GetIntArrayElements(env, keysym, NULL);
+ if (status)
+ (*env)->ReleaseIntArrayElements(env, status, status1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAddCallback
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAddCallback
+ (JNIEnv *env, jclass that, jint widget, jint callback_name, jint callback, jint client_data)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAddCallback\n");
+#endif
+ XtAddCallback((Widget)widget, (String)callback_name, (XtCallbackProc)callback, (XtPointer)client_data);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAddEventHandler
+ * Signature: (IIZII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAddEventHandler
+ (JNIEnv *env, jclass that, jint widget, jint event_mask, jboolean nonmaskable, jint proc, jint client_data)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAddEventHandler\n");
+#endif
+ XtAddEventHandler((Widget)widget, event_mask, nonmaskable, (XtEventHandler)proc, (XtPointer)client_data);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAddExposureToRegion
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAddExposureToRegion
+ (JNIEnv *env, jclass that, jint event, jint region)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAddExposureToRegion\n");
+#endif
+ XtAddExposureToRegion((XEvent *)event, (Region)region);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppAddTimeOut
+ * Signature: (IIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppAddTimeOut
+ (JNIEnv *env, jclass that, jint applicationContext, jint interval, jint procedure, jint clientData)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppAddTimeOut\n");
+#endif
+ return (jint) XtAppAddTimeOut((XtAppContext)applicationContext, interval, (XtTimerCallbackProc)procedure, (XtPointer)clientData);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppCreateShell
+ * Signature: ([B[BII[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppCreateShell
+ (JNIEnv *env, jclass that, jbyteArray appName, jbyteArray appClass, jint widgetClass,
+ jint display, jintArray argList, jint argCount)
+{
+ jbyte *appName1 = NULL;
+ jbyte *appClass1 = NULL;
+ jint *argList1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppCreateShell\n");
+#endif
+
+ if (appName)
+ appName1 = (*env)->GetByteArrayElements(env, appName, NULL);
+ if (appClass)
+ appClass1 = (*env)->GetByteArrayElements(env, appClass, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+
+/* fprintf(stderr, "XtAppCreateShell: appName1=%d appClass1=%d widgetClass=%d display=%d arglist1=%d argCount=%d\n",
+ appName1, appClass1, widgetClass, display, argList1, argCount);
+*/
+ rc = (jint) XtAppCreateShell((String)appName1, (String)appClass1, (WidgetClass)widgetClass, (Display *)display, (ArgList)argList1, argCount);
+
+/* fprintf(stderr, "After XtAppCreateShell: rc=%d\n", rc); */
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XtAppCreateShell: call failed rc = %d\n", rc);
+#endif
+
+ if (appName)
+ (*env)->ReleaseByteArrayElements(env, appName, appName1, 0);
+ if (appClass)
+ (*env)->ReleaseByteArrayElements(env, appClass, appClass1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppNextEvent
+ * Signature: (ILorg/eclipse/swt/internal/motif/XAnyEvent;)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppNextEvent
+ (JNIEnv *env, jclass that, jint appContext, jobject event)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppNextEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ XtAppNextEvent((XtAppContext)appContext, lpxEvent);
+
+#ifdef EVENT_TRACE
+ fprintf(stderr, "type = %d, serial = %d, send_event = %d, display = %x, window = %x \n",
+ xEvent.type, xEvent.xany.serial, xEvent.xany.send_event, xEvent.xany.display, xEvent.xany.window);
+#endif
+
+ if (event) {
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppPeekEvent
+ * Signature: (ILorg/eclipse/swt/internal/motif/XAnyEvent)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppPeekEvent
+ (JNIEnv *env, jclass that, jint appContext, jobject event)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jboolean rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppPeekEvent\n");
+#endif
+
+ rc = (jboolean) XtAppPeekEvent((XtAppContext)appContext, &xEvent);
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppPending
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppPending
+ (JNIEnv *env, jclass that, jint appContext)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppPending\n");
+#endif
+ return (jint) XtAppPending((XtAppContext)appContext);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppProcessEvent
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppProcessEvent
+ (JNIEnv *env, jclass that, jint appContext, jint inputMask)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppProcessEvent\n");
+#endif
+ XtAppProcessEvent((XtAppContext)appContext, inputMask);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppSetErrorHandler
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppSetErrorHandler
+ (JNIEnv *env, jclass that, jint app_context, jint handler)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppSetErrorHandler\n");
+#endif
+ return (jint) XtAppSetErrorHandler((XtAppContext)app_context, (XtErrorHandler)handler);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtAppSetWarningHandler
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtAppSetWarningHandler
+ (JNIEnv *env, jclass that, jint app_context, jint handler)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtAppSetWarningHandler\n");
+#endif
+ return (jint) XtAppSetWarningHandler((XtAppContext)app_context, (XtErrorHandler)handler);
+}
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtBuildEventMask
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtBuildEventMask
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtBuildEventMask\n");
+#endif
+ return (jint) XtBuildEventMask((Widget) widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCallActionProc
+ * Signature: (I[BLorg/eclipse/swt/internal/motif/XAnyEvent;[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCallActionProc
+ (JNIEnv *env, jclass that, jint widget, jbyteArray action, jobject event, jintArray params, jint num_params)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jbyte *action1=NULL;
+ jint *params1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCallActionProc\n");
+#endif
+ if (action)
+ action1 = (*env)->GetByteArrayElements(env, action, NULL);
+ if (params)
+ params1 = (*env)->GetIntArrayElements(env, params, NULL);
+
+ XtCallActionProc((Widget)widget, (String)action1, lpxEvent, (String *)params1, num_params);
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+
+ if (action)
+ (*env)->ReleaseByteArrayElements(env, action, action1, 0);
+ if (params)
+ (*env)->ReleaseIntArrayElements(env, params, params1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtClass
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtClass
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtClass\n");
+#endif
+ return (jint) XtClass((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtConfigureWidget
+ * Signature: (IIIIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtConfigureWidget
+ (JNIEnv *env, jclass that, jint widget, jint x, jint y, jint width, jint height, jint borderWidth)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtConfigureWidget\n");
+#endif
+ XtConfigureWidget((Widget)widget, x, y, width, height, borderWidth);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCreateApplicationContext
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCreateApplicationContext
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCreateApplicationContext\n");
+#endif
+ return (jint) XtCreateApplicationContext();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCreatePopupShell
+ * Signature: ([BII[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCreatePopupShell
+ (JNIEnv *env, jclass that, jbyteArray name, jint widgetClass, jint parent, jintArray argList, jint argCount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCreatePopupShell\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+
+ rc = (jint) XtCreatePopupShell((String)name1, (WidgetClass)widgetClass, (Widget)parent, (ArgList)argList1, argCount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XtCreatePopupShell: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtDestroyApplicationContext
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtDestroyApplicationContext
+ (JNIEnv *env, jclass that, jint appContext)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtDestroyApplicationContext\n");
+#endif
+ XtDestroyApplicationContext((XtAppContext)appContext);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtDestroyWidget
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtDestroyWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtDestroyWidget\n");
+#endif
+ XtDestroyWidget((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtDispatchEvent
+ * Signature: (Lorg/eclipse/swt/internal/motif/XAnyEvent;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtDispatchEvent
+ (JNIEnv *env, jclass that, jobject event)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtDispatchEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ #ifdef EVENT_TRACE
+ fprintf(stderr, "type = %d, serial = %d, send_event = %d, display = %x, window = %x \n",
+ xEvent.type, xEvent.xany.serial, xEvent.xany.send_event, xEvent.xany.display, xEvent.xany.window);
+ #endif
+ }
+ return (jboolean) XtDispatchEvent(lpxEvent);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtDisplay
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtDisplay
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtDisplay\n");
+#endif
+ return (jint) XtDisplay((Widget)widget);
+}
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtDisplayToApplicationContext
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtDisplayToApplicationContext
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtDisplayToApplicationContext\n");
+#endif
+ return (jint) XtDisplayToApplicationContext((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtFree
+ (JNIEnv *env, jclass that, jint ptr)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtFree\n");
+#endif
+ XtFree((char *)ptr);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtGetMultiClickTime
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtGetMultiClickTime
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtGetMultiClickTime\n");
+#endif
+ return (jint) XtGetMultiClickTime((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtGetValues
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtGetValues
+ (JNIEnv *env, jclass that, jint widget, jintArray argList, jint numArgs)
+{
+ jint *argList1=NULL;
+
+#ifdef LINUX
+ int values[numArgs];
+ int zeros[numArgs];
+ int i;
+#endif
+
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtGetValues\n");
+#endif
+
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+
+#ifdef LINUX
+ for (i = 0; i < numArgs; i++) {
+ zeros[i] = 0;
+ values[i] = 0;
+ if (argList1[i * 2 + 1] == 0) {
+ zeros[i] = 1;
+ argList1[i * 2 + 1] = (int)&values[i];
+ }
+ }
+#endif
+
+ XtGetValues((Widget)widget, (ArgList)argList1, numArgs);
+
+#ifdef LINUX
+ for (i = 0; i < numArgs; i++) {
+ if (zeros[i]) {
+ argList1[i * 2 + 1] = values[i];
+ }
+ }
+#endif
+
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsManaged
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsManaged
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsManaged\n");
+#endif
+ return (jboolean) XtIsManaged((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsRealized
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsRealized
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsRealized\n");
+#endif
+ return (jboolean) XtIsRealized((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsSubclass
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsSubclass
+ (JNIEnv *env, jclass that, jint widget, jint widgetClass)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsSubclass\n");
+#endif
+ return (jboolean) XtIsSubclass((Widget)widget, (WidgetClass)widgetClass);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsTopLevelShell
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsTopLevelShell
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsTopLevelShell\n");
+#endif
+ return (jboolean) XtIsTopLevelShell((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsWidget
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsWidget\n");
+#endif
+ return (jboolean)XtIsWidget((Widget)widget);
+
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtLastTimestampProcessed
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtLastTimestampProcessed
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtLastTimestampProcessed\n");
+#endif
+ return (jint)XtLastTimestampProcessed((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtMalloc
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtMalloc
+ (JNIEnv *env, jclass that, jint size)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtMalloc\n");
+#endif
+ return (jint) XtMalloc(size);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtManageChild
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtManageChild
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtManageChild\n");
+#endif
+ XtManageChild((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtMapWidget
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtMapWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtMapWidget\n");
+#endif
+ XtMapWidget((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtMoveWidget
+ * Signature: (III)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtMoveWidget
+ (JNIEnv *env, jclass that, jint widget, jint x, jint y)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtMoveWidget\n");
+#endif
+ XtMoveWidget((Widget)widget, x, y);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtOpenDisplay
+ * Signature: (I[B[B[BII[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtOpenDisplay
+ (JNIEnv *env, jclass that, jint xtAppContext, jbyteArray displayName, jbyteArray applicationName,
+ jbyteArray applicationClass, jint options, jint numOptions, jintArray argc, jint argv)
+{
+ jbyte *displayName1 = NULL;
+ jbyte *applicationName1 = NULL;
+ jbyte *applicationClass1 = NULL;
+ jint *argc1=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtOpenDisplay\n");
+#endif
+ if (displayName)
+ displayName1 = (*env)->GetByteArrayElements(env, displayName, NULL);
+ if (applicationName)
+ applicationName1 = (*env)->GetByteArrayElements(env, applicationName, NULL);
+ if (applicationClass)
+ applicationClass1 = (*env)->GetByteArrayElements(env, applicationClass, NULL);
+ if (argc)
+ argc1 = (*env)->GetIntArrayElements(env, argc, NULL);
+
+
+ rc = (jint) XtOpenDisplay((XtAppContext)xtAppContext, (String)displayName1, (String)applicationName1, (String)applicationClass1,
+ (XrmOptionDescRec *)options, numOptions, (int *)argc1, (char **)argv);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XtOpenDisplay: call failed rc = %d\n", rc);
+#endif
+
+ if (displayName)
+ (*env)->ReleaseByteArrayElements(env, displayName, displayName1, 0);
+ if (applicationName)
+ (*env)->ReleaseByteArrayElements(env, applicationName, applicationName1, 0);
+ if (applicationClass)
+ (*env)->ReleaseByteArrayElements(env, applicationClass, applicationClass1, 0);
+ if (argc)
+ (*env)->ReleaseIntArrayElements(env, argc, argc1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtParent
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtParent
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtParent\n");
+#endif
+ return (jint) XtParent((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtPopdown
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtPopdown
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtPopdown\n");
+#endif
+ XtPopdown((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtPopup
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtPopup
+ (JNIEnv *env, jclass that, jint widget, jint flags)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtPopup\n");
+#endif
+ XtPopup((Widget)widget, flags);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtQueryGeometry
+ * Signature: (ILorg/eclipse/swt/internal/motif/XtWidgetGeometryLorg/eclipse/swt/internal/motif/XtWidgetGeometry;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtQueryGeometry
+ (JNIEnv *env, jclass that, jint widget, jobject intended, jobject preferred_return)
+{
+ DECL_GLOB(pGlob)
+
+ XtWidgetGeometry intended1, preferred_return1, *lpIntended=NULL, *lpPreferred_return=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtQueryGeometry\n");
+#endif
+ lpPreferred_return = &preferred_return1;
+
+ /* The objects passed in here are both XtWidgetGeometry structures
+ ** If either or both are passed in, we only want to cache the fids once.
+ */
+ if (intended)
+ cacheXtwidgetgeometryFids(env, intended, &PGLOB(XtwidgetgeometryFc));
+ else if (preferred_return)
+ cacheXtwidgetgeometryFids(env, preferred_return, &PGLOB(XtwidgetgeometryFc));
+
+ if (intended) {
+ lpIntended = &intended1;
+ /* intended and preferred_return are the same class XtWidgetGeometry */
+ getXtwidgetgeometryFields(env, intended, lpIntended, &PGLOB(XtwidgetgeometryFc));
+ }
+ rc = (jint)XtQueryGeometry((Widget)widget, lpIntended, &preferred_return1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XtQueryGeometry: call failed rc = %d\n", rc);
+#endif
+
+ if (preferred_return) {
+ setXtwidgetgeometryFields(env, preferred_return, &preferred_return1, &PGLOB(XtwidgetgeometryFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtRealizeWidget
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtRealizeWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtRealizeWidget\n");
+#endif
+ XtRealizeWidget((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtRemoveTimeOut
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtRemoveTimeOut
+ (JNIEnv *env, jclass that, jint id)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtRemoveTimeOut\n");
+#endif
+ XtRemoveTimeOut(id);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtResizeWidget
+ * Signature: (IIII)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtResizeWidget
+ (JNIEnv *env, jclass that, jint widget, jint width, jint height, jint borderWidth)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtResizeWidget\n");
+#endif
+ XtResizeWidget((Widget)widget, width, height, borderWidth);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtResizeWindow
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtResizeWindow
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtResizeWindow\n");
+#endif
+ XtResizeWindow((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtSetLanguageProc
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtSetLanguageProc
+ (JNIEnv *env, jclass that, jint appContext, jint languageProc, jint pointer)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtSetLanguageProc\n");
+#endif
+ return (jint) XtSetLanguageProc((XtAppContext)appContext, (XtLanguageProc)languageProc, (XtPointer)pointer);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtSetMappedWhenManaged
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtSetMappedWhenManaged
+ (JNIEnv *env, jclass that, jint widget, jboolean flag)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtSetMappedWhenManaged\n");
+#endif
+ XtSetMappedWhenManaged((Widget)widget, flag);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtSetValues
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtSetValues
+ (JNIEnv *env, jclass that, jint widget, jintArray argList, jint numArgs)
+{
+ jint *argList1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtSetValues\n");
+#endif
+
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ XtSetValues((Widget)widget, (ArgList)argList1, numArgs);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtToolkitInitialize
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtToolkitInitialize
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtToolkitInitialize\n");
+#endif
+ XtToolkitInitialize();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtTranslateCoords
+ * Signature: (ISS[S[S)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtTranslateCoords
+ (JNIEnv *env, jclass that, jint widget, jshort x, jshort y, jshortArray root_x, jshortArray root_y)
+{
+ jshort *root_x1=NULL,*root_y1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtTranslateCoords\n");
+#endif
+ if (root_x)
+ root_x1 = (*env)->GetShortArrayElements(env, root_x, NULL);
+ if (root_y)
+ root_y1 = (*env)->GetShortArrayElements(env, root_y, NULL);
+ XtTranslateCoords((Widget)widget, x, y, root_x1, root_y1);
+ if (root_x)
+ (*env)->ReleaseShortArrayElements(env, root_x, root_x1, 0);
+ if (root_y)
+ (*env)->ReleaseShortArrayElements(env, root_y, root_y1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtUnmanageChild
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtUnmanageChild
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtUnmanageChild\n");
+#endif
+ XtUnmanageChild((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtUnmapWidget
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtUnmapWidget
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtUnmapWidget\n");
+#endif
+ XtUnmapWidget((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtWindow
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtWindow
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtWindow\n");
+#endif
+ return (jint) XtWindow((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtWindowToWidget
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtWindowToWidget
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtWindowToWidget\n");
+#endif
+ return (jint) XtWindowToWidget((Display *)display, window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: strlen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_strlen
+ (JNIEnv *env, jclass that, jint string)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "strlen\n");
+#endif
+ return (jint) strlen((char *)string);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardCopy
+ * Signature: (III[B[BII[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardCopy
+ (JNIEnv *env, jclass that, jint display, jint window, jint item_id, jbyteArray format_name, jbyteArray buffer, jint length, jint private_id, jintArray data_id)
+{
+ jbyte *format_name1 = NULL;
+ jbyte *buffer1 = NULL;
+ jint *data_id1 = NULL;
+ jint rc;
+
+ if (format_name)
+ format_name1 = (*env)->GetByteArrayElements(env, format_name, NULL);
+
+ if (buffer)
+ buffer1 = (*env)->GetByteArrayElements(env, buffer, NULL);
+
+ if (data_id)
+ data_id1 = (*env)->GetIntArrayElements(env, data_id, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardCopy\n");
+#endif
+
+ rc = (jint) XmClipboardCopy((Display *)display, (Window)window, (long)item_id, (char *)format_name1, (char *)buffer1, (unsigned long)length, private_id, (void *)data_id1);
+
+ if (format_name)
+ (*env)->ReleaseByteArrayElements(env, format_name, format_name1, 0);
+
+ if (buffer)
+ (*env)->ReleaseByteArrayElements(env, buffer, buffer1, 0);
+
+ if (data_id)
+ (*env)->ReleaseIntArrayElements(env, data_id, data_id1, 0);
+
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardEndCopy
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardEndCopy
+ (JNIEnv *env, jclass that, jint display, jint window, jint item_id)
+{
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardEndCopy\n");
+#endif
+
+ return (jint) XmClipboardEndCopy((Display *)display, (Window)window, (long)item_id );
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardStartCopy
+ * Signature: (IIIIII[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardStartCopy
+ (JNIEnv *env, jclass that, jint display, jint window, jint clip_label, jint timestamp, jint widget, jint callback, jintArray item_id)
+{
+ jint *item_id1 = NULL;
+ jint rc;
+
+ if (item_id)
+ item_id1 = (*env)->GetIntArrayElements(env, item_id, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardStartCopy\n");
+#endif
+
+ rc = (jint) XmClipboardStartCopy((Display *)display, (Window)window, (XmString)clip_label, timestamp, (Widget)widget, (XmCutPasteProc)callback, (long *)item_id1);
+
+ if (item_id)
+ (*env)->ReleaseIntArrayElements(env, item_id, item_id1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardInquireLength
+ * Signature: (II[B[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardInquireLength
+ (JNIEnv *env, jclass that, jint display, jint window, jbyteArray format_name, jintArray length)
+{
+ jbyte *format_name1 = NULL;
+ jint *length1 = NULL;
+ jint rc;
+
+ if (format_name)
+ format_name1 = (*env)->GetByteArrayElements(env, format_name, NULL);
+
+ if (length)
+ length1 = (*env)->GetIntArrayElements(env, length, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardInquireLength\n");
+#endif
+ rc = (jint) XmClipboardInquireLength((Display *)display, (Window)window, (char *)format_name1, (unsigned long *)length1);
+
+ if (format_name)
+ (*env)->ReleaseByteArrayElements(env, format_name, format_name1, 0);
+
+ if (length)
+ (*env)->ReleaseIntArrayElements(env, length, length1, 0);
+
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardInquireFormat
+ * Signature: (III[BI[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardInquireFormat
+ (JNIEnv *env, jclass that, jint display, jint window, int index, jbyteArray format_name_buf, int buffer_len, jintArray copied_len)
+{
+ jbyte *format_name_buf1 = NULL;
+ jint *copied_len1 = NULL;
+ jint rc;
+
+ if (format_name_buf)
+ format_name_buf1 = (*env)->GetByteArrayElements(env, format_name_buf, NULL);
+
+ if (copied_len)
+ copied_len1 = (*env)->GetIntArrayElements(env, copied_len, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardInquireFormat\n");
+#endif
+ rc = (jint) XmClipboardInquireFormat((Display *)display, (Window)window, index, (char *)format_name_buf1, buffer_len, (unsigned long *)copied_len1);
+
+ if (format_name_buf)
+ (*env)->ReleaseByteArrayElements(env, format_name_buf, format_name_buf1, 0);
+
+ if (copied_len)
+ (*env)->ReleaseIntArrayElements(env, copied_len, copied_len1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardInquireCount
+ * Signature: (II[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardInquireCount
+ (JNIEnv *env, jclass that, jint display, jint window, jintArray count, jintArray max_format_name_length)
+{
+ jint *count1 = NULL;
+ jint *max_format_name_length1 = NULL;
+ jint rc;
+
+ if (count)
+ count1 = (*env)->GetIntArrayElements(env, count, NULL);
+
+ if (max_format_name_length)
+ max_format_name_length1 = (*env)->GetIntArrayElements(env, max_format_name_length, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardInquireCount\n");
+#endif
+ rc = (jint) XmClipboardInquireCount((Display *)display, (Window)window, (int *)count1, (unsigned long *)max_format_name_length1);
+
+ if (count)
+ (*env)->ReleaseIntArrayElements(env, count, count1, 0);
+
+ if (max_format_name_length)
+ (*env)->ReleaseIntArrayElements(env, max_format_name_length, max_format_name_length1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardStartRetrieve
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardStartRetrieve
+ (JNIEnv *env, jclass that, jint display, jint window, jint timestamp)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardStartRetrieve\n");
+#endif
+ return (jint) XmClipboardStartRetrieve((Display *)display, (Window)window, timestamp);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardRetrieve
+ * Signature: (III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardRetrieve
+ (JNIEnv *env, jclass that, jint display, jint window, jbyteArray format_name, jbyteArray buffer, jint length, jintArray num_bytes, jintArray private_id)
+{
+ jbyte *format_name1 = NULL;
+ jbyte *buffer1 = NULL;
+ jint *num_bytes1 = NULL;
+ jint *private_id1 = NULL;
+ jint rc;
+
+ if (format_name)
+ format_name1 = (*env)->GetByteArrayElements(env, format_name, NULL);
+
+ if (buffer)
+ buffer1 = (*env)->GetByteArrayElements(env, buffer, NULL);
+
+ if (num_bytes)
+ num_bytes1 = (*env)->GetIntArrayElements(env, num_bytes, NULL);
+
+ if (private_id)
+ private_id1 = (*env)->GetIntArrayElements(env, private_id, NULL);
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardRetrieve\n");
+#endif
+
+ rc = (jint) XmClipboardRetrieve((Display *)display, (Window)window, (char *)format_name1, (char *)buffer1, (unsigned long)length, (unsigned long *)num_bytes1, (void *)private_id1);
+
+ if (format_name)
+ (*env)->ReleaseByteArrayElements(env, format_name, format_name1, 0);
+
+ if (buffer)
+ (*env)->ReleaseByteArrayElements(env, buffer, buffer1, 0);
+
+ if (num_bytes)
+ (*env)->ReleaseIntArrayElements(env, num_bytes, num_bytes1, 0);
+
+ if (private_id)
+ (*env)->ReleaseIntArrayElements(env, private_id, private_id1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmClipboardEndRetrieve
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardEndRetrieve
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmClipboardEndRetrieve\n");
+#endif
+ return (jint) XmClipboardEndRetrieve((Display *)display, (Window)window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpmReadFileToPixmap
+ * Signature: (II[B[I[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpmReadFileToPixmap
+ (JNIEnv *env, jclass that, jint display, jint drawable, jbyteArray fileName, jintArray pixmap_return, jintArray shapemask_return, jint attributes)
+{
+#ifdef XPM
+ jint rc;
+ jbyte *fileName1 = NULL;
+ jint *pixmap_return1 = NULL;
+ jint *shapemask_return1 = NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpmReadFileToPixmap\n");
+#endif
+ if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
+ if (pixmap_return) pixmap_return1 = (*env)->GetIntArrayElements(env, pixmap_return, NULL);
+ if (shapemask_return) shapemask_return1 = (*env)->GetIntArrayElements(env, shapemask_return, NULL);
+
+ rc = (jint) XpmReadFileToPixmap((Display *)display,
+ drawable,
+ fileName1,
+ (Pixmap*) pixmap_return1,
+ (Pixmap*) shapemask_return1,
+ attributes);
+
+ if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
+ if (pixmap_return) (*env)->ReleaseIntArrayElements(env, pixmap_return, pixmap_return1, 0);
+ if (shapemask_return) (*env)->ReleaseIntArrayElements(env, shapemask_return, shapemask_return1, 0);
+ return rc;
+#endif
+#ifndef XPM
+ return -1;
+#endif
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateDrawnButton
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateDrawnButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateDrawnButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+
+ rc = (jint)XmCreateDrawnButton((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateDrawnButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringGenerate
+ * Signature: ([B[BI[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringGenerate
+ (JNIEnv *env, jclass that, jbyteArray text, jbyteArray tag, jint type, jbyteArray rendition)
+{
+ jbyte *text1 = NULL;
+ jbyte *tag1 = NULL;
+ jbyte *rendition1 = NULL;
+ jint rc = 0;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringGenerate\n");
+#endif
+ if (text) text1 = (*env)->GetByteArrayElements(env, text, NULL);
+ if (tag) tag1 = (*env)->GetByteArrayElements(env, tag, NULL);
+ if (rendition) rendition1 = (*env)->GetByteArrayElements(env, rendition, NULL);
+
+ rc = (jint) XmStringGenerate((XtPointer) text1, (XmStringTag) tag1, type, (XmStringTag) rendition1);
+
+ if (text) (*env)->ReleaseByteArrayElements(env, text, text1, 0);
+ if (tag) (*env)->ReleaseByteArrayElements(env, tag, tag1, 0);
+ if (rendition) (*env)->ReleaseByteArrayElements(env, rendition, rendition1, 0);
+ return rc;
+}
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmRenderTableAddRenditions
+ * Signature: (I[III)I
+ */
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmRenderTableAddRenditions
+ (JNIEnv *env, jclass that, jint oldTable, jintArray renditions, jint renditionCount, jint mergeMode)
+{
+ jint *renditionArray = NULL;
+ jint renderTable = 0;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmRenderTableAddRenditions\n");
+#endif
+ if (renditions) renditionArray = (*env)->GetIntArrayElements(env, renditions, NULL);
+ renderTable = (int) XmRenderTableAddRenditions((XmRenderTable) oldTable, (XmRendition*) renditionArray, renditionCount, mergeMode);
+ if (renditions) (*env)->ReleaseIntArrayElements(env, renditions, renditionArray, 0);
+ return renderTable;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmRenderTableFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmRenderTableFree
+ (JNIEnv *env, jclass that, jint renderTable)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmRenderTableFree\n");
+#endif
+ XmRenderTableFree((XmRenderTable) renderTable);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmRenditionCreate
+ * Signature: (I[B[II)I
+ */
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmRenditionCreate
+ (JNIEnv *env, jclass that, jint widget, jbyteArray renditionTag, jintArray argList, jint argCount)
+{
+ jbyte *renditionTag1 = NULL;
+ jint *argList1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmRenditionCreate\n");
+#endif
+ if (renditionTag) renditionTag1 = (*env)->GetByteArrayElements(env, renditionTag, NULL);
+ if (argList) argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmRenditionCreate((Widget) widget, (XmStringTag) renditionTag1, (ArgList) argList1, argCount);
+ if (renditionTag) (*env)->ReleaseByteArrayElements(env, renditionTag, renditionTag1, 0);
+ if (argList) (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmRenditionFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmRenditionFree
+ (JNIEnv *env, jclass that, jint rendition)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmRenditionFree\n");
+#endif
+ XmRenditionFree((XmRendition) rendition);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTabCreate
+ * Signature: (IBBB[B)I
+ */
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabCreate
+ (JNIEnv *env, jclass that, jint value, jbyte units, jbyte offsetModel, jbyte alignment, jbyteArray decimal)
+{
+ jbyte *decimal1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTabCreate\n");
+#endif
+ if (decimal) decimal1 = (*env)->GetByteArrayElements(env, decimal, NULL);
+ rc = (jint) XmTabCreate(value, units, offsetModel, alignment, (char*) decimal1);
+ if (decimal) (*env)->ReleaseByteArrayElements(env, decimal, decimal1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTabFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabFree
+ (JNIEnv *env, jclass that, jint tab)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTabFree\n");
+#endif
+ XmTabFree((XmTab) tab);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTabListFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabListFree
+ (JNIEnv *env, jclass that, jint tabList)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTabListFree\n");
+#endif
+ XmTabListFree((XmTabList) tabList);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTabListInsertTabs
+ * Signature: (I[III)I
+ */
+JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabListInsertTabs
+ (JNIEnv *env, jclass that, jint oldList, jintArray tabs, jint tab_count, jint position)
+{
+ jint *tabs1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTabListInsertTabs\n");
+#endif
+ if (tabs) tabs1 = (*env)->GetIntArrayElements(env, tabs, NULL);
+ rc = (jint) XmTabListInsertTabs((XmTabList) oldList, (XmTab*) tabs1, tab_count, position);
+ if (tabs) (*env)->ReleaseIntArrayElements(env, tabs, tabs1, 0);
+ return rc;
+}
+
+
+/* ---- unused OS calls, kept here in case we use them later ---- */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XBlackPixel
+ * Signature: (II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XBlackPixel
+ (JNIEnv *env, jclass that, jint display, jint screenNum)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XBlackPixel\n");
+#endif
+ return (jint) XBlackPixel((Display *)display, screenNum);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XChangeActivePointerGrab
+ * Signature: (IIII)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XChangeActivePointerGrab
+ (JNIEnv *env, jclass that, jint display, jint eventMask, jint cursor, jint time)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XChangeActivePointerGrab\n");
+#endif
+ XChangeActivePointerGrab((Display *)display, eventMask, (Cursor)cursor, (Time)time);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultGC
+ * Signature: (II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultGC
+ (JNIEnv *env, jclass that, jint display, jint screen_number)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultGC\n");
+#endif
+ return (jint) XDefaultGC((Display *)display, screen_number);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XNoOp
+ * Signature: (I)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XNoOp
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XNoOp\n");
+#endif
+ XNoOp((Display *)display);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XRootWindowOfScreen
+ * Signature: (I)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XRootWindowOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XRootWindowOfScreen\n");
+#endif
+ return (jint) XRootWindowOfScreen((Screen *)screen);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSendEvent
+ * Signature: (Lorg/eclipse/swt/internal/motif/XAnyEvent;)Z
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSendEvent
+ (JNIEnv *env, jclass that, jint display, jint w, jboolean propagate, jint event_mask, jobject event)
+{
+ XEvent xEvent, *lpxEvent=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSendEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &XanyeventFc);
+ getXanyeventFields(env, event, lpxEvent, &XanyeventFc);
+ }
+ return (jint) XSendEvent((Display *)display, w, propagate, event_mask, lpxEvent);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateCascadeButton
+ * Signature: (I[B[II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateCascadeButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateCascadeButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateCascadeButton((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateCascadeButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateDrawnButton
+ * Signature: (I[B[II)I
+ */
+/*JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateDrawnButton
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateDrawnButton\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+
+ rc = (jint)XmCreateDrawnButton((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateDrawnButton: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}*/
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateRowColumn
+ * Signature: (I[B[II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateRowColumn
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray arglist, jint argcount)
+{
+ jint *arglist1=NULL;
+ jbyte *name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateRowColumn\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (arglist)
+ arglist1 = (*env)->GetIntArrayElements(env, arglist, NULL);
+
+ rc = (jint)XmCreateRowColumn((Widget)parent, (String)name1, (ArgList)arglist1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateRowColumn: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (arglist)
+ (*env)->ReleaseIntArrayElements(env, arglist, arglist1, 0);
+ return rc;
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmCreateScrolledWindow
+ * Signature: (I[B[II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmCreateScrolledWindow
+ (JNIEnv *env, jclass that, jint parent, jbyteArray name, jintArray argList, jint argcount)
+{
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmCreateScrolledWindow\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmCreateScrolledWindow((Widget)parent, (String)name1, (ArgList)argList1, argcount);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmCreateScrolledWindow: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmDestroyPixmap
+ * Signature: (II)Z
+ */
+/* JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDestroyPixmap
+ (JNIEnv *env, jclass that, jint screen, jint pixmap)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmDestroyPixmap\n");
+#endif
+ return (jboolean) XmDestroyPixmap((Screen *)screen, pixmap);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetPixmapByDepth
+ * Signature: (I[BIII)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetPixmapByDepth
+ (JNIEnv *env, jclass that, jint screen, jbyteArray image_name, jint foreground, jint background, jint depth)
+{
+ jbyte *image_name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmGetPixmapByDepth\n");
+#endif
+
+ if (image_name)
+ image_name1 = (*env)->GetByteArrayElements(env, image_name, NULL);
+
+ rc = (jint)XmGetPixmapByDepth((Screen *)screen, (char *)image_name1, foreground, background, depth);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XmGetPixmapByDepth: call failed rc = %d\n", rc);
+#endif
+
+ if (image_name)
+ (*env)->ReleaseByteArrayElements(env, image_name, image_name1, 0);
+ return rc;
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListAddItemsUnselected
+ * Signature: (IIII)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListAddItemsUnselected
+ (JNIEnv *env, jclass that, jint list, jint xmStringTable, jint item_count, jint position)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListAddItemsUnselected\n");
+#endif
+ XmListAddItemsUnselected((Widget)list, (XmString *)xmStringTable, item_count, position);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeleteItem
+ * Signature: (II)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeleteItem
+ (JNIEnv *env, jclass that, jint list, jint item)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeleteItem\n");
+#endif
+ XmListDeleteItem((Widget)list, (XmString)item);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListDeselectItem
+ * Signature: (II)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListDeselectItem
+ (JNIEnv *env, jclass that, jint list, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListDeselectItem\n");
+#endif
+ XmListDeselectItem((Widget)list, (XmString)xmString);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmListSelectItem
+ * Signature: (IIZ)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmListSelectItem
+ (JNIEnv *env, jclass that, jint list, jint xmString, jboolean notify)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmListSelectItem\n");
+#endif
+ XmListSelectItem((Widget)list, (XmString)xmString, notify);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringDrawUnderline
+ * Signature: (IIIIIIIIIILorg/eclipse/swt/internal/motif/XRectangle;I)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringDrawUnderline
+ (JNIEnv *env, jclass that, jint display, jint window, jint fontlist, jint xmString, jint gc, jint x, jint y, jint width, jint align, jint lay_dir, jobject clip, jint xmStringUnderline)
+{
+ XRectangle xRect, *lpxRect=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringDrawUnderline\n");
+#endif
+
+ if (clip) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, clip, &XrectangleFc);
+ getXrectangleFields(env, clip, lpxRect, &XrectangleFc);
+ }
+ XmStringDrawUnderline((Display *)display, window, (XmFontList)fontlist, (XmString)xmString, (GC)gc, x, y, width, align, lay_dir, lpxRect, (XmString)xmStringUnderline);
+ if (clip) {
+ setXrectangleFields(env, clip, lpxRect, &XrectangleFc);
+ }
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringLineCount
+ * Signature: (I)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringLineCount
+ (JNIEnv *env, jclass that, jint xmString)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringLineCount\n");
+#endif
+ return (jint) XmStringLineCount((XmString)xmString);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmTextRemove
+ * Signature: (I)Z
+ */
+/* JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTextRemove
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmTextRemove\n");
+#endif
+ return (jboolean) XmTextRemove((Widget)widget);
+}
+*/
+
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCloseDisplay
+ * Signature: (I)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCloseDisplay
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCloseDisplay\n");
+#endif
+ XtCloseDisplay((Display *)display);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCallActionProc
+ * Signature: (I[BLorg/eclipse/swt/internal/motif/XAnyEvent;[BI)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCallActionProc
+ (JNIEnv *env, jclass that, jint widget, jbyteArray action, jobject event, jbyteArray params, jint num_params)
+{
+ XEvent xEvent, *lpxEvent=NULL;
+ jbyte *action1, *params1;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCallActionProc\n");
+#endif
+ if (action)
+ action1 = (*env)->GetByteArrayElements(env, action, NULL);
+ if (params)
+ params1 = (*env)->GetByteArrayElements(env, params, NULL);
+
+ XtCallActionProc((Widget)widget, (String)action1, lpxEvent, (String *)params1, num_params);
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &XanyeventFc);
+ setXanyeventFields(env, event, lpxEvent, &XanyeventFc);
+ }
+
+ if (action)
+ (*env)->ReleaseByteArrayElements(env, action, action1, 0);
+ if (params)
+ (*env)->ReleaseByteArrayElements(env, params, params1, 0);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCloseDisplay
+ * Signature: (I)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCloseDisplay
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCloseDisplay\n");
+#endif
+ XtCloseDisplay((Display *)display);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtCreateWidget
+ * Signature: ([BII[II)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtCreateWidget
+ (JNIEnv *env, jclass that, jbyteArray name, jint widgetClass, jint parent, jintArray argList, jint argCount)
+{
+
+ jbyte *name1=NULL;
+ jint *argList1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtCreateWidget\n");
+#endif
+
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ if (argList)
+ argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XtCreateWidget((String)name1, (WidgetClass)widgetClass, (Widget)parent, (ArgList)argList1, argCount);
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XtCreateWidget: call failed rc = %d\n", rc);
+#endif
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ if (argList)
+ (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtRemoveCallback
+ * Signature: (IIII)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtRemoveCallback
+ (JNIEnv *env, jclass that, jint widget, jint callback_name, jint callback, jint client_data)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtRemoveCallback\n");
+#endif
+ XtRemoveCallback((Widget)widget, (char *)callback_name, (XtCallbackProc)callback, (XtPointer)client_data);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtRemoveEventHandler
+ * Signature: (IIZII)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtRemoveEventHandler
+ (JNIEnv *env, jclass that, jint widget, jint event_mask, jboolean nonmaskable, jint proc, jint client_data)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtRemoveEventHandler\n");
+#endif
+ XtRemoveEventHandler((Widget)widget, event_mask, nonmaskable, (XtEventHandler)proc, (XtPointer)client_data);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtScreen
+ * Signature: (I)I
+ */
+/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtScreen
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtScreen\n");
+#endif
+ return (jint) XtScreen((Widget)widget);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSelectInput
+ * Signature: (III)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSelectInput
+ (JNIEnv *env, jclass that, jint display, jint window, jint mask)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSelectInput\n");
+#endif
+ XSelectInput((Display *)display, (Window)window, mask);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtIsSensitive
+ * Signature: (I)Z
+ */
+/* JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtIsSensitive
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtIsSensitive\n");
+#endif
+ return (jboolean) XtIsSensitive((Widget)widget);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtSetSensitive
+ * Signature: (IZ)V
+ */
+/* JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtSetSensitive
+ (JNIEnv *env, jclass that, jint widget, jboolean sensitive)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtSetSensitive\n");
+#endif
+ XtSetSensitive((Widget)widget, sensitive);
+}
+*/
+
+/* ---- unused OS calls end here ---- */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmParseMappingCreate
+ * Signature: ([II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmParseMappingCreate
+ (JNIEnv *env, jclass that, jintArray argList, jint numArgs)
+{
+ jint *argList1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmParseMappingCreate\n");
+#endif
+ if (argList) argList1 = (*env)->GetIntArrayElements(env, argList, NULL);
+ rc = (jint) XmParseMappingCreate((ArgList)argList1, numArgs);
+ if (argList) (*env)->ReleaseIntArrayElements(env, argList, argList1, 0);
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmParseMappingFree
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmParseMappingFree
+ (JNIEnv *env, jclass that, jint parseMapping)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmParseMappingFree\n");
+#endif
+ XmParseMappingFree((XmParseMapping) parseMapping);
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmParseTableFree
+ * Signature: ([II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmParseTableFree
+ (JNIEnv *env, jclass that, jintArray parseTable, jint mappingCount)
+{
+ jint *parseTable1 = NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmParseTableFree\n");
+#endif
+ if (parseTable) {
+ parseTable1 = (*env)->GetIntArrayElements(env, parseTable, NULL);
+ XmParseTableFree((XmParseTable) parseTable1, mappingCount);
+ (*env)->ReleaseIntArrayElements(env, parseTable, parseTable1, 0);
+ }
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringComponentCreate
+ * Signature: (II[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringComponentCreate
+ (JNIEnv *env, jclass that, jint type, jint length, jbyteArray value)
+{
+ jbyte* value1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringComponentCreate\n");
+#endif
+ if (value) value1 = (*env)->GetByteArrayElements(env, value, NULL);
+ rc = (jint) XmStringComponentCreate(type, length, (XtPointer) value1);
+ if (value) (*env)->ReleaseByteArrayElements(env, value, value1, 0);
+
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringParseText
+ * Signature: ([BI[BI[III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringParseText
+ (JNIEnv *env, jclass that, jbyteArray text, jint textEnd, jbyteArray tag, jint tagType, jintArray parseTable, jint parseCount, jint callData)
+{
+ jbyte* text1 = NULL;
+ jbyte* tag1 = NULL;
+ jint* parseTable1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringParseText\n");
+#endif
+ if (text) text1 = (*env)->GetByteArrayElements(env, text, NULL);
+ if (tag) tag1 = (*env)->GetByteArrayElements(env, tag, NULL);
+ if (parseTable) parseTable1 = (*env)->GetIntArrayElements(env, parseTable, NULL);
+ rc = (jint) XmStringParseText(
+ (XtPointer) text1,
+ (XtPointer*) textEnd,
+ (XmStringTag) tag1,
+ tagType,
+ (XmParseTable) parseTable1,
+ parseCount,
+ (XtPointer) callData);
+ if (text) (*env)->ReleaseByteArrayElements(env, text, text1, 0);
+ if (tag) (*env)->ReleaseByteArrayElements(env, tag, tag1, 0);
+ if (parseTable) (*env)->ReleaseIntArrayElements(env, parseTable, parseTable1, 0);
+ return rc;
+}
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmStringUnparse
+ * Signature: (I[BII[III)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmStringUnparse
+ (JNIEnv *env, jclass that, jint xmString, jbyteArray tag, jint tagType, jint outputType, jintArray parseTable, jint parseCount, jint parseModel)
+{
+ jbyte* tag1 = NULL;
+ jint* parseTable1 = NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmStringUnparse\n");
+#endif
+ if (tag) tag1 = (*env)->GetByteArrayElements(env, tag, NULL);
+ if (parseTable) parseTable1 = (*env)->GetIntArrayElements(env, parseTable, NULL);
+ rc = (jint) XmStringUnparse((XmString) xmString,
+ (XmStringTag) tag1,
+ tagType,
+ outputType,
+ (XmParseTable) parseTable1,
+ parseCount,
+ parseModel);
+ if (tag) (*env)->ReleaseByteArrayElements(env, tag, tag1, 0);
+ if (parseTable) (*env)->ReleaseIntArrayElements(env, parseTable, parseTable1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtParseTranslationTable
+ * Signature: ([B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XtParseTranslationTable
+ (JNIEnv *env, jclass that, jbyteArray string)
+{
+ jint rc;
+ jbyte *string1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtParseTranslationTable\n");
+#endif
+ if (string) string1 = (*env)->GetByteArrayElements(env, string, NULL);
+ rc = (jint) XtParseTranslationTable((String) string1);
+ if (string) (*env)->ReleaseByteArrayElements(env, string, string1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtOverrideTranslations
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtOverrideTranslations
+ (JNIEnv *env, jclass that, jint w, jint translations)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtOverrideTranslations\n");
+#endif
+ XtOverrideTranslations((Widget) w, (XtTranslations) translations);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCheckIfEvent
+ * Signature: (ILorg/eclipse/swt/internal/motif/XAnyEvent;II)Z
+ */
+typedef Bool (*PredicateFunc)();
+
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XCheckIfEvent
+ (JNIEnv *env, jclass that, jint display, jobject event, jint predicate, jint arg)
+{
+ DECL_GLOB(pGlob)
+ XEvent xEvent, *lpxEvent=NULL;
+ jboolean rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCheckIfEvent\n");
+#endif
+
+ if (event) {
+ lpxEvent = &xEvent;
+ cacheXanyeventFids(env, event, &PGLOB(XanyeventFc));
+ getXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ rc = (jboolean)XCheckIfEvent((Display *)display, lpxEvent, (PredicateFunc) predicate, (void *) arg);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc != True && rc != False)
+ fprintf(stderr, "XCheckIfEvent: call failed rc = %d\n", rc);
+#endif
+
+ if (event) {
+ setXanyeventFields(env, event, lpxEvent, &PGLOB(XanyeventFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XtToolkitThreadInitialize
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XtToolkitThreadInitialize
+ (JNIEnv *env, jclass that)
+{
+ DECL_GLOB(pGlob)
+ /*
+ * WARNING: When running under VA/Java, XtToolkitThreadInitialize
+ * is not called because this hangs VA/Java and SWT.
+ */
+ if (pGlob->vajava) return;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtToolkitThreadInitialize\n");
+#endif
+ return (jboolean) XtToolkitThreadInitialize ();
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: Call
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_Call
+ (JNIEnv *env, jclass that, jint proc, jint arg0, jint arg1)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "Call\n");
+#endif
+ return (*((jint (*)(jint, jint))proc)) (arg0, arg1);
+}
+
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetErrorText
+ (JNIEnv *env, jclass that, jint display, jint code, jbyteArray buffer_return, jint length)
+{
+ jint rc;
+ jbyte *buffer_return1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XtParseTranslationTable\n");
+#endif
+ if (buffer_return) buffer_return1 = (*env)->GetByteArrayElements(env, buffer_return, NULL);
+ XGetErrorText ((Display *)display, code, buffer_return1, length);
+ if (buffer_return) (*env)->ReleaseByteArrayElements(env, buffer_return, buffer_return1, 0);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetIOErrorHandler
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetIOErrorHandler
+ (JNIEnv *env, jclass that, jint handler)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetIOErrorHandler\n");
+#endif
+ return (jint) XSetIOErrorHandler((XIOErrorHandler)handler);
+}
+
+/*
+ * ======== Start printing functions ========
+ */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpCreateContext
+ * Signature: (I[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpCreateContext
+ (JNIEnv *env, jclass that, jint display, jbyteArray printer_name)
+{
+ jbyte *printer_name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpCreateContext\n");
+#endif
+ if (printer_name)
+ printer_name1 = (*env)->GetByteArrayElements(env, printer_name, NULL);
+ rc = (jint) XpCreateContext((Display *)display, (char *)printer_name1);
+ if (printer_name)
+ (*env)->ReleaseByteArrayElements(env, printer_name, printer_name1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpGetPrinterList
+ * Signature: (I[B[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpGetPrinterList
+ (JNIEnv *env, jclass that, jint display, jbyteArray printer_name, jintArray list_count)
+{
+ jbyte *printer_name1=NULL;
+ jint *list_count1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpGetPrinterList\n");
+#endif
+ if (printer_name)
+ printer_name1 = (*env)->GetByteArrayElements(env, printer_name, NULL);
+ if (list_count)
+ list_count1 = (*env)->GetIntArrayElements(env, list_count, NULL);
+ rc = (jint) XpGetPrinterList((Display *)display, (char *)printer_name1, (int *)list_count1);
+ if (printer_name)
+ (*env)->ReleaseByteArrayElements(env, printer_name, printer_name1, 0);
+ if (list_count)
+ (*env)->ReleaseIntArrayElements(env, list_count, list_count1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpFreePrinterList
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpFreePrinterList
+ (JNIEnv *env, jclass that, jint printer_list)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpFreePrinterList\n");
+#endif
+ XpFreePrinterList((XPPrinterList)printer_list);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpGetAttributes
+ * Signature: (IIB)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpGetAttributes
+ (JNIEnv *env, jclass that, jint display, jint print_context, jbyte type)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpGetAttributes\n");
+#endif
+ return (jint) XpGetAttributes((Display *)display, (XPContext)print_context, (XPAttributes)type);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpGetOneAttribute
+ * Signature: (IIB[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpGetOneAttribute
+ (JNIEnv *env, jclass that, jint display, jint print_context, jbyte type, jbyteArray attribute_name)
+{
+ jbyte *attribute_name1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpGetOneAttribute\n");
+#endif
+ if (attribute_name)
+ attribute_name1 = (*env)->GetByteArrayElements(env, attribute_name, NULL);
+ rc = (jint) XpGetOneAttribute((Display *)display, (XPContext)print_context, (XPAttributes)type, (char *)attribute_name1);
+ if (attribute_name)
+ (*env)->ReleaseByteArrayElements(env, attribute_name, attribute_name1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpSetAttributes
+ * Signature: (IIB[BB)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpSetAttributes
+ (JNIEnv *env, jclass that, jint display, jint print_context, jbyte type, jbyteArray pool, jbyte replacement_rule)
+{
+ jbyte *pool1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpSetAttributes\n");
+#endif
+ if (pool)
+ pool1 = (*env)->GetByteArrayElements(env, pool, NULL);
+ XpSetAttributes((Display *)display, (XPContext)print_context, (XPAttributes)type, (char *)pool1, (XPAttrReplacement)replacement_rule);
+ if (pool)
+ (*env)->ReleaseByteArrayElements(env, pool, pool1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpSetContext
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpSetContext
+ (JNIEnv *env, jclass that, jint display, jint print_context)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpSetContext\n");
+#endif
+ XpSetContext((Display *)display, (XPContext)print_context);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpGetScreenOfContext
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpGetScreenOfContext
+ (JNIEnv *env, jclass that, jint display, jint print_context)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpGetScreenOfContext\n");
+#endif
+ return (jint) XpGetScreenOfContext((Display *)display, (XPContext)print_context);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpDestroyContext
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpDestroyContext
+ (JNIEnv *env, jclass that, jint display, jint print_context)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpDestroyContext\n");
+#endif
+ XpDestroyContext((Display *)display, (XPContext)print_context);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpGetPageDimensions
+ * Signature: (II[S[SLorg/eclipse/swt/internal/motif/XRectangle;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpGetPageDimensions
+ (JNIEnv *env, jclass that, jint display, jint print_context, jshortArray width, jshortArray height, jobject rectangle)
+{
+ DECL_GLOB(pGlob)
+ XRectangle xRect, *lpxRect=NULL;
+ jshort *width1=NULL, *height1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpGetPageDimensions\n");
+#endif
+
+ if (rectangle) {
+ lpxRect = &xRect;
+ cacheXrectangleFids(env, rectangle, &PGLOB(XrectangleFc));
+ getXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ if (width)
+ width1 = (*env)->GetShortArrayElements(env, width, NULL);
+ if (height)
+ height1 = (*env)->GetShortArrayElements(env, height, NULL);
+ rc = (jint) XpGetPageDimensions((Display *)display, (XPContext)print_context,
+ (unsigned short *)width1, (unsigned short *)height1, (XRectangle *)lpxRect);
+ if (rectangle) {
+ setXrectangleFields(env, rectangle, lpxRect, &PGLOB(XrectangleFc));
+ }
+ if (width)
+ (*env)->ReleaseShortArrayElements(env, width, width1, 0);
+ if (height)
+ (*env)->ReleaseShortArrayElements(env, height, height1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpStartJob
+ * Signature: (IB)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpStartJob
+ (JNIEnv *env, jclass that, jint display, jbyte save_data)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpStartJob\n");
+#endif
+ XpStartJob((Display *)display, (XPSaveData)save_data);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpStartPage
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpStartPage
+ (JNIEnv *env, jclass that, jint display, jint window)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpStartPage\n");
+#endif
+ XpStartPage((Display *)display, (Window)window);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpEndPage
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpEndPage
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpEndPage\n");
+#endif
+ XpEndPage((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpEndJob
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpEndJob
+ (JNIEnv *env, jclass that, jint display)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpEndJob\n");
+#endif
+ XpEndJob((Display *)display);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpCancelJob
+ * Signature: (IZ)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpCancelJob
+ (JNIEnv *env, jclass that, jint display, jboolean discard)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpCancelJob\n");
+#endif
+ XpCancelJob((Display *)display, discard);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultGCOfScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultGCOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultGCOfScreen\n");
+#endif
+ return (jint) XDefaultGCOfScreen((Screen *)screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDefaultColormapOfScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XDefaultColormapOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDefaultColormapOfScreen\n");
+#endif
+ return (jint) XDefaultColormapOfScreen((Screen *)screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XRootWindowOfScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XRootWindowOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XRootWindowOfScreen\n");
+#endif
+ return (jint) XRootWindowOfScreen((Screen *)screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XScreenNumberOfScreen
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XScreenNumberOfScreen
+ (JNIEnv *env, jclass that, jint screen)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XScreenNumberOfScreen\n");
+#endif
+ return (jint) XScreenNumberOfScreen((Screen *)screen);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateWindow
+ * Signature: (IIIIIIIIIIII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateWindow
+ (JNIEnv *env, jclass that, jint display, jint parent, jint x, jint y, jint width, jint height,
+ jint border_width, jint depth, jint class, jint visual, jint value_mask, jint attributes)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateWindow\n");
+#endif
+ return (jint) XCreateWindow((Display *)display, (Window)parent, x, y, width, height,
+ border_width, depth, class, (Visual *)visual, (long)value_mask, (XSetWindowAttributes *)attributes);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XDestroyWindow
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDestroyWindow
+ (JNIEnv *env, jclass that, jint display, jint w)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XDestroyWindow\n");
+#endif
+ XDestroyWindow((Display *)display, (Window)w);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpQueryVersion
+ * Signature: (I[S[S)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpQueryVersion
+ (JNIEnv *env, jclass that, jint display, jshortArray major_version, jshortArray minor_version)
+{
+ jshort *major_version1=NULL, *minor_version1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpQueryVersion\n");
+#endif
+
+ if (major_version)
+ major_version1 = (*env)->GetShortArrayElements(env, major_version, NULL);
+ if (minor_version)
+ minor_version1 = (*env)->GetShortArrayElements(env, minor_version, NULL);
+ rc = (jint) XpQueryVersion((Display *)display, (short *)major_version1, (short *)minor_version1);
+ if (major_version)
+ (*env)->ReleaseShortArrayElements(env, major_version, major_version1, 0);
+ if (minor_version)
+ (*env)->ReleaseShortArrayElements(env, minor_version, minor_version1, 0);
+
+ return rc;
+}
+
+/*
+ * ======== End printing functions ========
+ */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt-gnome0105.so b/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt-gnome0105.so
new file mode 100755
index 0000000000..3c3ba7ecda
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt-gnome0105.so
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt0105.so b/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt0105.so
new file mode 100755
index 0000000000..7b68c6d57a
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/libswt0105.so
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
new file mode 100755
index 0000000000..24b7b94242
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
@@ -0,0 +1,197 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Color {
+ /**
+ * The handle to the OS color resource.
+ * Warning: This field is platform dependent.
+ */
+ public XColor handle;
+
+ /**
+ * The device where this image was created.
+ */
+ Device device;
+
+Color() {
+}
+public Color (Device device, int red, int green, int blue) {
+ init(device, red, green, blue);
+}
+public Color (Device device, RGB rgb) {
+ if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, rgb.red, rgb.green, rgb.blue);
+}
+public void dispose() {
+ if (handle == null) return;
+ int xDisplay = device.xDisplay;
+ int pixel = handle.pixel;
+ if (device.colorRefCount != null) {
+ /* If this was the last reference, remove the color from the list */
+ if (--device.colorRefCount[pixel] == 0) {
+ device.xcolors[pixel] = null;
+ }
+ }
+ int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
+ OS.XFreeColors(xDisplay, colormap, new int[] { pixel }, 1, 0);
+ device = null;
+ handle = null;
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof Color)) return false;
+ Color color = (Color)object;
+ XColor xColor = color.handle;
+ return device == color.device && handle.red == xColor.red &&
+ handle.green == xColor.green && handle.blue == xColor.blue;
+}
+public int getBlue () {
+ return (handle.blue >> 8) & 0xFF;
+}
+public int getGreen () {
+ return (handle.green >> 8) & 0xFF;
+}
+public int getRed () {
+ return (handle.red >> 8) & 0xFF;
+}
+public RGB getRGB () {
+ return new RGB((handle.red >> 8) & 0xFF, (handle.green >> 8) & 0xFF, (handle.blue >> 8) & 0xFF);
+}
+public int hashCode () {
+ return handle.red ^ handle.green ^ handle.blue;
+}
+void init(Device device, int red, int green, int blue) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ if ((red > 255) || (red < 0) ||
+ (green > 255) || (green < 0) ||
+ (blue > 255) || (blue < 0)) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ XColor xColor = new XColor();
+ xColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8));
+ xColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8));
+ xColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8));
+ handle = xColor;
+ int xDisplay = device.xDisplay;
+ int screen = OS.XDefaultScreen(xDisplay);
+ int colormap = OS.XDefaultColormap(xDisplay, screen);
+ /* 1. Try to allocate the color */
+ if (OS.XAllocColor(xDisplay, colormap, xColor) != 0) {
+ if (device.colorRefCount != null) {
+ /* Make a copy of the color to put in the colors array */
+ XColor colorCopy = new XColor();
+ colorCopy.red = xColor.red;
+ colorCopy.green = xColor.green;
+ colorCopy.blue = xColor.blue;
+ colorCopy.pixel = xColor.pixel;
+ device.xcolors[colorCopy.pixel] = colorCopy;
+ device.colorRefCount[xColor.pixel]++;
+ }
+ return;
+ }
+ /**
+ * 2. Allocation failed. Query the entire colormap and
+ * find the closest match which can be allocated.
+ * This should never occur on a truecolor display.
+ */
+ Visual visual = new Visual();
+ OS.memmove(visual, OS.XDefaultVisual(xDisplay, screen), Visual.sizeof);
+ int mapEntries = visual.map_entries;
+ XColor[] queried = new XColor[mapEntries];
+ int[] distances = new int[mapEntries];
+ /**
+ * Query all colors in the colormap and calculate the distance
+ * from each to the desired color.
+ */
+ for (int i = 0; i < mapEntries; i++) {
+ XColor color = new XColor();
+ color.pixel = i;
+ queried[i] = color;
+ OS.XQueryColor(xDisplay, colormap, color);
+ int r = red - ((color.red >> 8) & 0xFF);
+ int g = green - ((color.green >> 8) & 0xFF);
+ int b = blue - ((color.blue >> 8) & 0xFF);
+ distances[i] = r*r + g*g + b*b;
+ }
+ /**
+ * Try to allocate closest matching queried color.
+ * The allocation can fail if the closest matching
+ * color is allocated privately, so go through them
+ * in order of increasing distance.
+ */
+ for (int i = 0; i < mapEntries; i++) {
+ int minDist = 0x30000;
+ int minIndex = 0;
+ for (int j = 0; j < mapEntries; j++) {
+ if (distances[j] < minDist) {
+ minDist = distances[j];
+ minIndex = j;
+ }
+ }
+ XColor queriedColor = queried[minIndex];
+ XColor osColor = new XColor();
+ osColor.red = queriedColor.red;
+ osColor.green = queriedColor.green;
+ osColor.blue = queriedColor.blue;
+ if (OS.XAllocColor(xDisplay, colormap, osColor) != 0) {
+ /* Allocation succeeded. Copy the fields into the handle */
+ xColor.red = osColor.red;
+ xColor.green = osColor.green;
+ xColor.blue = osColor.blue;
+ xColor.pixel = osColor.pixel;
+ if (device.colorRefCount != null) {
+ /* Put osColor in the colors array */
+ device.xcolors[osColor.pixel] = osColor;
+ device.colorRefCount[osColor.pixel]++;
+ }
+ return;
+ }
+ /* The allocation failed; matching color is allocated privately */
+ distances[minIndex] = 0x30000;
+ }
+ /**
+ * 3. Couldn't allocate any of the colors in the colormap.
+ * This means all colormap entries were allocated privately
+ * by other applications. Give up and allocate black.
+ */
+ XColor osColor = new XColor();
+ OS.XAllocColor(xDisplay, colormap, osColor);
+ /* Copy the fields into the handle */
+ xColor.red = osColor.red;
+ xColor.green = osColor.green;
+ xColor.blue = osColor.blue;
+ xColor.pixel = osColor.pixel;
+ if (device.colorRefCount != null) {
+ /* Put osColor in the colors array */
+ device.xcolors[osColor.pixel] = osColor;
+ device.colorRefCount[osColor.pixel]++;
+ }
+}
+public boolean isDisposed() {
+ return handle == null;
+}
+public static Color motif_new(Device device, XColor xColor) {
+ if (device == null) device = Device.getDevice();
+ Color color = new Color();
+ color.handle = xColor;
+ color.device = device;
+ return color;
+}
+/**
+ * Return a string representation of the Color.
+ *
+ * @return a string representation of the Color
+ */
+public String toString () {
+ return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java
new file mode 100755
index 0000000000..88490e9fc1
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java
@@ -0,0 +1,154 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Cursor {
+ /**
+ * The handle to the OS cursor resource.
+ * Warning: This field is platform dependent.
+ */
+ public int handle;
+
+ /**
+ * The device where this image was created.
+ */
+ Device device;
+
+Cursor () {
+}
+public Cursor (Device device, int style) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ int shape = 0;
+ switch (style) {
+ case SWT.CURSOR_ARROW: shape = OS.XC_left_ptr; break;
+ case SWT.CURSOR_WAIT: shape = OS.XC_watch; break;
+ case SWT.CURSOR_HAND: shape = OS.XC_hand2; break;
+ case SWT.CURSOR_CROSS: shape = OS.XC_cross; break;
+ case SWT.CURSOR_APPSTARTING: shape = OS.XC_watch; break;
+ case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break;
+ case SWT.CURSOR_SIZEALL: shape = OS.XC_diamond_cross; break;
+ case SWT.CURSOR_SIZENESW: shape = OS.XC_sizing; break;
+ case SWT.CURSOR_SIZENS: shape = OS.XC_double_arrow; break;
+ case SWT.CURSOR_SIZENWSE: shape = OS.XC_sizing; break;
+ case SWT.CURSOR_SIZEWE: shape = OS.XC_sb_h_double_arrow; break;
+ case SWT.CURSOR_SIZEN: shape = OS.XC_top_side; break;
+ case SWT.CURSOR_SIZES: shape = OS.XC_bottom_side; break;
+ case SWT.CURSOR_SIZEE: shape = OS.XC_right_side; break;
+ case SWT.CURSOR_SIZEW: shape = OS.XC_left_side; break;
+ case SWT.CURSOR_SIZENE: shape = OS.XC_top_right_corner; break;
+ case SWT.CURSOR_SIZESE: shape = OS.XC_bottom_right_corner; break;
+ case SWT.CURSOR_SIZESW: shape = OS.XC_bottom_left_corner; break;
+ case SWT.CURSOR_SIZENW: shape = OS.XC_top_left_corner; break;
+ case SWT.CURSOR_UPARROW: shape = OS.XC_sb_up_arrow; break;
+ case SWT.CURSOR_IBEAM: shape = OS.XC_xterm; break;
+ case SWT.CURSOR_NO: shape = OS.XC_X_cursor; break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.handle = OS.XCreateFontCursor(device.xDisplay, shape);
+}
+public Cursor (Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (mask == null) {
+ if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ mask = source.getTransparencyMask();
+ }
+ /* Check the bounds. Mask must be the same size as source */
+ if (mask.width != source.width || mask.height != source.height) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ /* Check depths */
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (source.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ /* Check the hotspots */
+ if (hotspotX >= source.width || hotspotX < 0 ||
+ hotspotY >= source.height || hotspotY < 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ /* Swap the bits if necessary */
+ byte[] sourceData = new byte[source.data.length];
+ byte[] maskData = new byte[mask.data.length];
+ /* Swap the bits in each byte */
+ byte[] data = source.data;
+ for (int i = 0; i < data.length; i++) {
+ byte s = data[i];
+ sourceData[i] = (byte)(((s & 0x80) >> 7) |
+ ((s & 0x40) >> 5) |
+ ((s & 0x20) >> 3) |
+ ((s & 0x10) >> 1) |
+ ((s & 0x08) << 1) |
+ ((s & 0x04) << 3) |
+ ((s & 0x02) << 5) |
+ ((s & 0x01) << 7));
+ sourceData[i] = (byte) ~sourceData[i];
+ }
+ data = mask.data;
+ for (int i = 0; i < data.length; i++) {
+ byte s = data[i];
+ maskData[i] = (byte)(((s & 0x80) >> 7) |
+ ((s & 0x40) >> 5) |
+ ((s & 0x20) >> 3) |
+ ((s & 0x10) >> 1) |
+ ((s & 0x08) << 1) |
+ ((s & 0x04) << 3) |
+ ((s & 0x02) << 5) |
+ ((s & 0x01) << 7));
+ maskData[i] = (byte) ~maskData[i];
+ }
+ int xDisplay = device.xDisplay;
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, source.width, source.height);
+ int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, source.width, source.height);
+ /* Get the colors */
+ int screenNum = OS.XDefaultScreen(xDisplay);
+ XColor foreground = new XColor();
+ foreground.pixel = OS.XBlackPixel(xDisplay, screenNum);
+ foreground.red = foreground.green = foreground.blue = 0;
+ XColor background = new XColor();
+ background.pixel = OS.XWhitePixel(xDisplay, screenNum);
+ background.red = background.green = background.blue = (short)0xFFFF;
+ /* Create the cursor */
+ handle = OS.XCreatePixmapCursor(xDisplay, maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY);
+ /* Dispose the pixmaps */
+ OS.XFreePixmap(xDisplay, sourcePixmap);
+ OS.XFreePixmap(xDisplay, maskPixmap);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+}
+public void dispose () {
+ if (handle != 0) OS.XFreeCursor(device.xDisplay, handle);
+ device = null;
+ handle = 0;
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof Cursor)) return false;
+ Cursor cursor = (Cursor)object;
+ return device == cursor.device && handle == cursor.handle;
+}
+public int hashCode () {
+ return handle;
+}
+public boolean isDisposed() {
+ return handle == 0;
+}
+public static Cursor motif_new(Device device, int handle) {
+ if (device == null) device = Device.getDevice();
+ Cursor cursor = new Cursor();
+ cursor.device = device;
+ cursor.handle = handle;
+ return cursor;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java
new file mode 100755
index 0000000000..39737ff830
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java
@@ -0,0 +1,434 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+
+public abstract class Device implements Drawable {
+ /**
+ * the handle to the X Display
+ * (Warning: This field is platform dependent)
+ */
+ public int xDisplay;
+
+ /* Arguments for XtOpenDisplay */
+ String display_name;
+ String application_name;
+ String application_class;
+
+ /* Debugging */
+ public static boolean DEBUG;
+ boolean debug = DEBUG;
+ public boolean tracking = DEBUG;
+ Error [] errors;
+ Object [] objects;
+
+ /* Colormap and reference count for this display */
+ XColor [] xcolors;
+ int [] colorRefCount;
+
+ /* System Colors */
+ Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
+ Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
+ Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
+
+ /* Warning and Error Handlers */
+ boolean warnings = true;
+ Callback xErrorCallback, xtWarningCallback, xIOErrorCallback, xtErrorCallback;
+ int xErrorProc, xtWarningProc, xIOErrorProc, xtErrorProc;
+ int xNullErrorProc, xtNullWarningProc, xNullIOErrorProc, xtNullErrorProc;
+
+ public static String XDefaultPrintServer = ":1";
+ static {
+ /* Read the default print server name from
+ * the XPRINTER environment variable.
+ */
+ XDefaultPrintServer = ":1";
+ }
+ protected static int xPrinter;
+
+public Device(DeviceData data) {
+ create (data);
+ init ();
+ if (data != null) {
+ display_name = data.display_name;
+ application_name = data.application_name;
+ application_class = data.application_class;
+ tracking = data.tracking;
+ debug = data.debug;
+ }
+ if (tracking) {
+ errors = new Error [128];
+ objects = new Object [128];
+ }
+}
+
+/**
+ * Temporary code.
+ */
+static Device getDevice () {
+ Device device = null;
+ try {
+ Class clazz = Class.forName ("org.eclipse.swt.widgets.Display");
+ java.lang.reflect.Method method = clazz.getMethod("getCurrent", new Class[0]);
+ device = (Device) method.invoke(clazz, new Object[0]);
+ if (device == null) {
+ method = clazz.getMethod("getDefault", new Class[0]);
+ device = (Device)method.invoke(clazz, new Object[0]);
+ }
+ } catch (Throwable e) {};
+ return device;
+}
+
+protected void checkDevice () {
+ if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
+}
+
+protected void create (DeviceData data) {
+}
+
+protected void destroy () {
+}
+
+public void dispose () {
+ if (isDisposed()) return;
+ checkDevice ();
+ release ();
+ destroy ();
+ xDisplay = 0;
+ if (tracking) {
+ objects = null;
+ errors = null;
+ }
+}
+
+void dispose_Object (Object object) {
+ for (int i=0; i<objects.length; i++) {
+ if (objects [i] == object) {
+ objects [i] = null;
+ errors [i] = null;
+ return;
+ }
+ }
+}
+
+public Rectangle getBounds () {
+ checkDevice ();
+ int screen = OS.XDefaultScreen (xDisplay);
+ int width = OS.XDisplayWidth (xDisplay, screen);
+ int height = OS.XDisplayHeight (xDisplay, screen);
+ return new Rectangle (0, 0, width, height);
+}
+
+public Rectangle getClientArea () {
+ return getBounds ();
+}
+
+public int getDepth () {
+ checkDevice ();
+ int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
+ return OS.XDefaultDepthOfScreen (xScreenPtr);
+}
+
+public DeviceData getDeviceData () {
+ checkDevice ();
+ DeviceData data = new DeviceData ();
+ data.display_name = display_name;
+ data.application_name = application_name;
+ data.application_class = application_class;
+ data.debug = debug;
+ data.tracking = tracking;
+ int count = 0, length = 0;
+ if (tracking) length = objects.length;
+ for (int i=0; i<length; i++) {
+ if (objects [i] != null) count++;
+ }
+ int index = 0;
+ data.objects = new Object [count];
+ data.errors = new Error [count];
+ for (int i=0; i<length; i++) {
+ if (objects [i] != null) {
+ data.objects [index] = objects [i];
+ data.errors [index] = errors [i];
+ index++;
+ }
+ }
+ return data;
+}
+
+public Point getDPI () {
+ checkDevice ();
+ int xScreenNum = OS.XDefaultScreen (xDisplay);
+ int width = OS.XDisplayWidth (xDisplay, xScreenNum);
+ int height = OS.XDisplayHeight (xDisplay, xScreenNum);
+ int mmX = OS.XDisplayWidthMM (xDisplay, xScreenNum);
+ int mmY = OS.XDisplayHeightMM (xDisplay, xScreenNum);
+ /* 0.03937 mm/inch */
+ double inchesX = mmX * 0.03937;
+ double inchesY = mmY * 0.03937;
+ int x = (int)((width / inchesX) + 0.5);
+ int y = (int)((height / inchesY) + 0.5);
+ return new Point (x, y);
+}
+
+public FontData [] getFontList (String faceName, boolean scalable) {
+ checkDevice ();
+ String xlfd;
+ if (faceName == null) {
+ xlfd = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
+ } else {
+ int dashIndex = faceName.indexOf('-');
+ if (dashIndex < 0) {
+ xlfd = "-*-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
+ } else {
+ xlfd = "-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
+ }
+ }
+ byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true);
+ int [] ret = new int [1];
+ int listPtr = OS.XListFonts (xDisplay, buffer1, 65535, ret);
+ int ptr = listPtr;
+ int [] intBuf = new int [1];
+ FontData [] fd = new FontData [ret [0]];
+ int fdIndex = 0;
+ for (int i = 0; i < ret [0]; i++) {
+ OS.memmove (intBuf, ptr, 4);
+ int charPtr = intBuf [0];
+ int length = OS.strlen (charPtr);
+ byte [] buffer2 = new byte [length];
+ OS.memmove (buffer2, charPtr, length);
+ char [] chars = Converter.mbcsToWcs (null, buffer2);
+ FontData data = FontData.motif_new (new String (chars));
+ boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0;
+ if (isScalable == scalable) {
+ fd [fdIndex++] = data;
+ }
+ ptr += 4;
+ }
+ OS.XFreeFontNames (listPtr);
+ if (fdIndex == ret [0]) return fd;
+ FontData [] result = new FontData [fdIndex];
+ System.arraycopy (fd, 0, result, 0, fdIndex);
+ return result;
+}
+
+public Color getSystemColor (int id) {
+ checkDevice ();
+ XColor xColor = null;
+ switch (id) {
+ case SWT.COLOR_BLACK: return COLOR_BLACK;
+ case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
+ case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
+ case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW;
+ case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE;
+ case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA;
+ case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN;
+ case SWT.COLOR_GRAY: return COLOR_GRAY;
+ case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY;
+ case SWT.COLOR_RED: return COLOR_RED;
+ case SWT.COLOR_GREEN: return COLOR_GREEN;
+ case SWT.COLOR_YELLOW: return COLOR_YELLOW;
+ case SWT.COLOR_BLUE: return COLOR_BLUE;
+ case SWT.COLOR_MAGENTA: return COLOR_MAGENTA;
+ case SWT.COLOR_CYAN: return COLOR_CYAN;
+ case SWT.COLOR_WHITE: return COLOR_WHITE;
+ }
+ if (xColor == null) return COLOR_BLACK;
+ return Color.motif_new (this, xColor);
+}
+
+public Font getSystemFont () {
+ checkDevice ();
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateLabel (shellHandle, null, null, 0);
+ int [] argList = {OS.XmNfontList, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ /**
+ * Feature in Motif. Querying the font list from the widget and
+ * then destroying the shell (and the widget) could cause the
+ * font list to be freed as well. The fix is to make a copy of
+ * the font list, then to free it when the display is disposed.
+ */
+ int labelFont = OS.XmFontListCopy (argList [1]);
+ OS.XtDestroyWidget (shellHandle);
+ return Font.motif_new (this, labelFont);
+}
+
+public boolean getWarnings () {
+ checkDevice ();
+ return warnings;
+}
+
+protected void init () {
+
+ /* Create the warning and error callbacks */
+ xErrorCallback = new Callback (this, "xErrorProc", 2);
+ xNullErrorProc = xErrorCallback.getAddress ();
+ if (xNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+ xtWarningCallback = new Callback (this, "xtWarningProc", 1);
+ xtNullWarningProc = xtWarningCallback.getAddress ();
+ if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+ xIOErrorCallback = new Callback (this, "xIOErrorProc", 1);
+ xNullIOErrorProc = xIOErrorCallback.getAddress ();
+ if (xNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+ xtErrorCallback = new Callback (this, "xtErrorProc", 1);
+ xtNullErrorProc = xtErrorCallback.getAddress ();
+ if (xtNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ /* Set the warning and error handlers */
+ if (debug) OS.XSynchronize (xDisplay, true);
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ xErrorProc = OS.XSetErrorHandler (xNullErrorProc);
+ if (!debug) OS.XSetErrorHandler (xErrorProc);
+ xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
+ if (!debug) OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
+ xIOErrorProc = OS.XSetIOErrorHandler (xNullIOErrorProc);
+ if (!debug) OS.XSetIOErrorHandler (xIOErrorProc);
+ xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc);
+ if (!debug) OS.XtAppSetErrorHandler (xtContext, xtErrorProc);
+
+ /* Only use palettes for <= 8 bpp default visual */
+ int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
+ int defaultDepth = OS.XDefaultDepthOfScreen (xScreenPtr);
+ if (defaultDepth <= 8) {
+ int numColors = 1 << defaultDepth;
+ colorRefCount = new int [numColors];
+ xcolors = new XColor [numColors];
+ }
+
+ /*
+ * The following colors are listed in the Windows
+ * Programmer's Reference as the colors in the default
+ * palette.
+ */
+ COLOR_BLACK = new Color (this, 0,0,0);
+ COLOR_DARK_RED = new Color (this, 0x80,0,0);
+ COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
+ COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
+ COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
+ COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
+ COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
+ COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
+ COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
+ COLOR_RED = new Color (this, 0xFF,0,0);
+ COLOR_GREEN = new Color (this, 0,0xFF,0);
+ COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
+ COLOR_BLUE = new Color (this, 0,0,0xFF);
+ COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
+ COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
+ COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
+}
+
+public abstract int internal_new_GC (GCData data);
+
+public abstract void internal_dispose_GC (int handle, GCData data);
+
+public boolean isDisposed () {
+ return xDisplay == 0;
+}
+
+void new_Object (Object object) {
+ for (int i=0; i<objects.length; i++) {
+ if (objects [i] == null) {
+ objects [i] = object;
+ errors [i] = new Error ();
+ return;
+ }
+ }
+ Object [] newObjects = new Object [objects.length + 128];
+ System.arraycopy (objects, 0, newObjects, 0, objects.length);
+ newObjects [objects.length] = object;
+ objects = newObjects;
+ Error [] newErrors = new Error [errors.length + 128];
+ System.arraycopy (errors, 0, newErrors, 0, errors.length);
+ newErrors [errors.length] = new Error ();
+ errors = newErrors;
+}
+
+protected void release () {
+ /*
+ * Free the palette. Note that this disposes all colors on
+ * the display that were allocated using the Color constructor.
+ */
+ if (xcolors != null) {
+ int xScreen = OS.XDefaultScreen (xDisplay);
+ int xColormap = OS.XDefaultColormap (xDisplay, xScreen);
+ int [] pixel = new int [1];
+ for (int i = 0; i < xcolors.length; i++) {
+ XColor color = xcolors [i];
+ if (color != null) {
+ pixel [0] = color.pixel;
+ while (colorRefCount [i] > 0) {
+ OS.XFreeColors (xDisplay, xColormap, pixel, 1, 0);
+ --colorRefCount [i];
+ }
+ }
+ }
+ }
+ xcolors = null;
+ colorRefCount = null;
+
+ COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW =
+ COLOR_DARK_BLUE = COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
+ COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
+
+ /* Release the warning and error callbacks */
+ xtWarningCallback.dispose (); xtWarningCallback = null;
+ xtWarningProc = 0;
+ xErrorCallback.dispose (); xErrorCallback = null;
+ xErrorProc = 0;
+ xtErrorCallback.dispose (); xtErrorCallback = null;
+ xtErrorProc = 0;
+ xIOErrorCallback.dispose (); xIOErrorCallback = null;
+ xIOErrorProc = 0;
+}
+
+public void setWarnings (boolean warnings) {
+ checkDevice ();
+ this.warnings = warnings;
+ if (debug) return;
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ if (warnings) {
+ OS.XSetErrorHandler (xErrorProc);
+ OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
+ } else {
+ OS.XSetErrorHandler (xNullErrorProc);
+ OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
+ }
+}
+
+int xErrorProc (int xDisplay, int xErrorEvent) {
+ if (debug) {
+ new SWTError ().printStackTrace ();
+ OS.Call (xErrorProc, xDisplay, xErrorEvent);
+ }
+ return 0;
+}
+
+int xIOErrorProc (int xDisplay) {
+ if (debug) {
+ new SWTError ().printStackTrace ();
+ OS.Call (xIOErrorProc, xDisplay, 0);
+ }
+ return 0;
+}
+
+int xtErrorProc (int message) {
+ if (debug) {
+ new SWTError ().printStackTrace ();
+ OS.Call (xtErrorProc, message, 0);
+ }
+ return 0;
+}
+
+int xtWarningProc (int message) {
+ if (debug) {
+ new SWTError ().printStackTrace ();
+ OS.Call (xtWarningProc, message, 0);
+ }
+ return 0;
+}
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java
new file mode 100755
index 0000000000..565fb06229
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java
@@ -0,0 +1,24 @@
+package org.eclipse.swt.graphics;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2001 All Rights Reserved
+ */
+
+public class DeviceData {
+ /*
+ * Motif only fields.
+ */
+ public String display_name;
+ public String application_name;
+ public String application_class;
+
+ /*
+ * Debug fields - may not be honoured
+ * on some SWT platforms.
+ */
+ public boolean debug;
+ public boolean tracking;
+ public Error [] errors;
+ public Object [] objects;
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java
new file mode 100755
index 0000000000..b979ea2d42
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java
@@ -0,0 +1,164 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Font {
+ /**
+ * The handle to the OS font resource.
+ * Warning: This field is platform dependent.
+ */
+ public int handle;
+
+ /**
+ * The device where this image was created.
+ */
+ Device device;
+
+Font () {
+}
+public Font (Device device, FontData fd) {
+ init(device, fd);
+}
+public Font (Device device, String fontFamily, int height, int style) {
+ if (fontFamily == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, new FontData(fontFamily, height, style));
+}
+public void dispose () {
+ if (handle != 0) OS.XmFontListFree (handle);
+ handle = 0;
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof Font)) return false;
+ Font font = (Font)object;
+ return device == font.device && handle == font.handle;
+}
+public FontData[] getFontData() {
+ int xDisplay = device.xDisplay;
+ /**
+ * Create a font context to iterate over each element in the font list.
+ * If a font context can not be created, return null.
+ */
+ int[] buffer = new int[1];
+ if (!OS.XmFontListInitFontContext(buffer, handle)) return null;
+ int context = buffer[0];
+ XFontStruct fontStruct = new XFontStruct();
+ int fontListEntry;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ String[] xlfds = new String[0];
+ /* Go through each entry in the font list */
+ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
+ if (buffer[0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove(fontStruct,fontPtr,20 * 4);
+ int propPtr = fontStruct.properties;
+ for (int i = 0; i < fontStruct.n_properties; i++) {
+ /* Reef through properties looking for XAFONT */
+ int[] prop = new int[2];
+ OS.memmove(prop, propPtr, 8);
+ if (prop[0] == OS.XA_FONT) {
+ /* Found it, prop[1] points to the string */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int length = OS.strlen(ptr);
+ byte[] nameBuf = new byte[length];
+ OS.memmove(nameBuf, ptr, length);
+ String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
+ /* Add the xlfd to the array */
+ String[] newXlfds = new String[xlfds.length + 1];
+ System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
+ newXlfds[newXlfds.length - 1] = xlfd;
+ xlfds = newXlfds;
+ OS.XtFree(ptr);
+ break;
+ }
+ propPtr += 8;
+ }
+ }
+ else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr);
+ int [] fontStructs = new int[nFonts];
+ OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4);
+ for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set.
+ OS.memmove(fontStruct,fontStructs[i],20 * 4);
+ int propPtr = fontStruct.properties;
+ for (int j = 0; j < fontStruct.n_properties; j++) {
+ // Reef through properties looking for XAFONT
+ int[] prop = new int[2];
+ OS.memmove(prop, propPtr, 8);
+ if (prop[0] == OS.XA_FONT) {
+ /* Found it, prop[1] points to the string */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int length = OS.strlen(ptr);
+ byte[] nameBuf = new byte[length];
+ OS.memmove(nameBuf, ptr, length);
+ String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
+ /* Add the xlfd to the array */
+ String[] newXlfds = new String[xlfds.length + 1];
+ System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
+ newXlfds[newXlfds.length - 1] = xlfd;
+ xlfds = newXlfds;
+ OS.XFree(ptr);
+ break;
+ }
+ propPtr += 8;
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ if (xlfds.length == 0) return null;
+ FontData[] fontData = new FontData[xlfds.length];
+ /* Construct each fontData out of the xlfd */
+ try {
+ for (int i = 0; i < xlfds.length; i++) {
+ fontData[i] = FontData.motif_new(xlfds[i]);
+ }
+ } catch (Exception e) {
+ /**
+ * Some font servers, for example, xfstt, do not pass
+ * reasonable font properties to the client, so we
+ * cannot construct a FontData for these. Return null.
+ */
+ return null;
+ }
+ return fontData;
+}
+public int hashCode () {
+ return handle;
+}
+void init (Device device, FontData fd) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ byte[] buffer = Converter.wcsToMbcs(null, fd.getXlfd(), true);
+ boolean warnings = device.getWarnings();
+ device.setWarnings(false);
+ int fontListEntry = OS.XmFontListEntryLoad(device.xDisplay, buffer, 0, OS.XmFONTLIST_DEFAULT_TAG);
+ device.setWarnings(warnings);
+ if (fontListEntry == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ handle = OS.XmFontListAppendEntry(0, fontListEntry);
+ OS.XmFontListEntryFree(new int[]{fontListEntry});
+}
+public boolean isDisposed() {
+ return handle == 0;
+}
+public static Font motif_new(Device device, int handle) {
+ if (device == null) device = Device.getDevice();
+ Font font = new Font();
+ font.device = device;
+ font.handle = handle;
+ return font;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java
new file mode 100755
index 0000000000..31494f022e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java
@@ -0,0 +1,321 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class FontData {
+ /**
+ * The company that produced the font
+ * Warning: This field is platform dependent.
+ */
+ public String foundry;
+ /**
+ * The common name of the font
+ * Warning: This field is platform dependent.
+ */
+ public String fontFamily;
+ /**
+ * The weight ("normal", "bold")
+ * Warning: This field is platform dependent.
+ */
+ public String weight;
+ /**
+ * The slant ("o" for oblique, "i" for italic)
+ * Warning: This field is platform dependent.
+ */
+ public String slant;
+ /**
+ * The set width of the font
+ * Warning: This field is platform dependent.
+ */
+ public String setWidth;
+ /**
+ * Additional font styles
+ * Warning: This field is platform dependent.
+ */
+ public String addStyle;
+ /**
+ * The height of the font in pixels
+ * Warning: This field is platform dependent.
+ */
+ public int pixels;
+ /**
+ * The height of the font in tenths of a point
+ * Warning: This field is platform dependent.
+ */
+ public int points;
+ /**
+ * The horizontal screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
+ */
+ public int horizontalResolution;
+ /**
+ * The vertical screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
+ */
+ public int verticalResolution;
+ /**
+ * The font spacing ("m" for monospace, "p" for proportional)
+ * Warning: This field is platform dependent.
+ */
+ public String spacing;
+ /**
+ * The average character width for the font
+ * Warning: This field is platform dependent.
+ */
+ public int averageWidth;
+ /**
+ * The ISO character set registry
+ * Warning: This field is platform dependent.
+ */
+ public String characterSetRegistry;
+ /**
+ * The ISO character set name
+ * Warning: This field is platform dependent.
+ */
+ public String characterSetName;
+public FontData () {
+}
+public FontData(String string) {
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int start = 0;
+ int end = string.indexOf('|');
+ if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ String version1 = string.substring(start, end);
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ String name = string.substring(start, end);
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int height = 0;
+ try {
+ height = Integer.parseInt(string.substring(start, end));
+ } catch (NumberFormatException e) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int style = 0;
+ try {
+ style = Integer.parseInt(string.substring(start, end));
+ } catch (NumberFormatException e) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) {
+ setName(name);
+ setHeight(height);
+ setStyle(style);
+ return;
+ }
+ String platform = string.substring(start, end);
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) {
+ setName(name);
+ setHeight(height);
+ setStyle(style);
+ return;
+ }
+ String version2 = string.substring(start, end);
+
+ if (platform.equals("MOTIF") && version2.equals("1")) {
+ start = end + 1;
+ end = string.length();
+ if (end == -1) {
+ setName(name);
+ setHeight(height);
+ setStyle(style);
+ return;
+ }
+ String xlfd = string.substring(start, end);
+ setXlfd(xlfd);
+ return;
+ }
+ setName(name);
+ setHeight(height);
+ setStyle(style);
+}
+public FontData (String name, int height, int style) {
+ if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (name != null) {
+ int dash = name.indexOf('-');
+ if (dash != -1) {
+ foundry = name.substring(0, dash);
+ fontFamily = name.substring(dash + 1);
+ } else {
+ fontFamily = name;
+ }
+ }
+ points = height * 10;
+ if ((style & SWT.BOLD) != 0)
+ weight = "bold";
+ else
+ weight = "medium";
+ if ((style & SWT.ITALIC) != 0)
+ slant = "i";
+ else
+ slant = "r";
+}
+public boolean equals (Object object) {
+ return (object == this) || ((object instanceof FontData) &&
+ getXlfd().equals(((FontData)object).getXlfd()));
+}
+public int getHeight() {
+ return points / 10;
+}
+public String getName() {
+ StringBuffer buffer = new StringBuffer();
+ if (foundry != null) {
+ buffer.append(foundry);
+ buffer.append("-");
+ }
+ if (fontFamily != null) buffer.append(fontFamily);
+ return buffer.toString();
+}
+public int getStyle() {
+ int style = 0;
+ if (weight.equals("bold"))
+ style |= SWT.BOLD;
+ if (slant.equals("i"))
+ style |= SWT.ITALIC;
+ return style;
+}
+String getXlfd() {
+ String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
+ s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*";
+
+ if (foundry != null) s1 = foundry;
+ if (fontFamily != null) s2 = fontFamily;
+ if (weight != null) s3 = weight;
+ if (slant != null) s4 = slant;
+ if (setWidth != null) s5 = setWidth;
+ if (addStyle != null) s6 = addStyle;
+ if (pixels != 0) s7 = Integer.toString(pixels);
+ if (points != 0) s8 = Integer.toString(points);
+ if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution);
+ if (verticalResolution != 0) s10 = Integer.toString(verticalResolution);
+ if (spacing != null) s11 = spacing;
+ if (averageWidth != 0) s12 = Integer.toString(averageWidth);
+ if (characterSetRegistry != null) s13 = characterSetRegistry;
+ if (characterSetName != null) s14 = characterSetName;
+
+ return "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
+ + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
+}
+public int hashCode () {
+ return getXlfd().hashCode();
+}
+public static FontData motif_new(String xlfd) {
+ FontData fontData = new FontData();
+ fontData.setXlfd(xlfd);
+ return fontData;
+}
+public void setHeight(int height) {
+ if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ points = height * 10;
+}
+public void setName(String name) {
+ if (name == null) {
+ foundry = fontFamily = null;
+ return;
+ }
+ int dash = name.indexOf('-');
+ if (dash != -1) {
+ foundry = name.substring(0, dash);
+ fontFamily = name.substring(dash + 1);
+ } else {
+ fontFamily = name;
+ }
+}
+public void setStyle(int style) {
+ if ((style & SWT.BOLD) == SWT.BOLD)
+ weight = "bold";
+ else
+ weight = "normal";
+ if ((style & SWT.ITALIC) == SWT.ITALIC)
+ slant = "i";
+ else
+ slant = "r";
+}
+void setXlfd(String xlfd) {
+ int start, stop;
+ start = 1;
+ stop = xlfd.indexOf ("-", start);
+ foundry = xlfd.substring(start, stop);
+ if (foundry.equals("*")) foundry = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ fontFamily = xlfd.substring(start, stop);
+ if (fontFamily.equals("*")) fontFamily = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ weight = xlfd.substring(start, stop);
+ if (weight.equals("*")) weight = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ slant = xlfd.substring(start, stop);
+ if (slant.equals("*")) slant = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ setWidth = xlfd.substring(start, stop);
+ if (setWidth.equals("*")) setWidth = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ addStyle = xlfd.substring(start, stop);
+ if (addStyle.equals("*")) addStyle = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ String s = xlfd.substring(start, stop);
+ if (!s.equals("") && !s.equals("*"))
+ pixels = Integer.parseInt(s);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ s = xlfd.substring(start, stop);
+ if (!s.equals("") && !s.equals("*"))
+ points = Integer.parseInt(s);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ s = xlfd.substring(start, stop);
+ if (!s.equals("") && !s.equals("*"))
+ horizontalResolution = Integer.parseInt(s);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ s = xlfd.substring(start, stop);
+ if (!s.equals("") && !s.equals("*"))
+ verticalResolution = Integer.parseInt(s);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ spacing = xlfd.substring(start, stop);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ s = xlfd.substring(start, stop);
+ if (!s.equals("") && !s.equals("*"))
+ averageWidth = Integer.parseInt(s);
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ characterSetRegistry = xlfd.substring(start, stop);
+ if (characterSetRegistry.equals("*")) characterSetRegistry = null;
+ start = stop + 1;
+ stop = xlfd.indexOf ("-", start);
+ characterSetName = xlfd.substring(start);
+ if (characterSetName.equals("*")) characterSetName = null;
+}
+public String toString() {
+ return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
+ "MOTIF|1|" + getXlfd();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java
new file mode 100755
index 0000000000..43d69ae41c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java
@@ -0,0 +1,47 @@
+package org.eclipse.swt.graphics;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class FontMetrics {
+ int ascent, descent, averageCharWidth, leading, height;
+FontMetrics() {
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof FontMetrics)) return false;
+ FontMetrics metrics = (FontMetrics)object;
+ return ascent == metrics.ascent && descent == metrics.descent &&
+ averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
+ height == metrics.height;
+}
+public int getAscent() {
+ return ascent;
+}
+public int getAverageCharWidth() {
+ return averageCharWidth;
+}
+public int getDescent() {
+ return descent;
+}
+public int getHeight() {
+ return height;
+}
+public int getLeading() {
+ return leading;
+}
+public int hashCode() {
+ return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
+}
+public static FontMetrics motif_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
+ FontMetrics fontMetrics = new FontMetrics();
+ fontMetrics.ascent = ascent;
+ fontMetrics.descent = descent;
+ fontMetrics.averageCharWidth = averageCharWidth;
+ fontMetrics.leading = leading;
+ fontMetrics.height = height;
+ return fontMetrics;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java
new file mode 100755
index 0000000000..b5dc6a73d8
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java
@@ -0,0 +1,1367 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class GC {
+ /**
+ * The handle to the OS GC resource.
+ * Warning: This field is platform dependent.
+ */
+ public int handle;
+
+ Drawable drawable;
+ GCData data;
+
+ static final byte[] _MOTIF_DEFAULT_LOCALE = Converter.wcsToMbcs(null, "_MOTIF_DEFAULT_LOCALE");
+
+GC() {
+}
+public GC (Drawable drawable) {
+ if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ GCData data = new GCData();
+ int xGC = drawable.internal_new_GC(data);
+ init(drawable, data, xGC);
+}
+
+public void copyArea(int x, int y, int width, int height, int destX, int destY) {
+ if (width <= 0 || height <= 0) return;
+ int deltaX = destX - x, deltaY = destY - y;
+ if (deltaX == 0 && deltaY == 0) return;
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ OS.XSetGraphicsExposures (xDisplay, handle, true);
+ OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY);
+ OS.XSetGraphicsExposures (xDisplay, handle, false);
+ boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
+ if (data.image != null) return;
+ if (disjoint) {
+ OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true);
+ } else {
+ if (deltaX != 0) {
+ int newX = destX - deltaX;
+ if (deltaX < 0) newX = destX + width;
+ OS.XClearArea (xDisplay, xDrawable, newX, y, Math.abs (deltaX), height, true);
+ }
+ if (deltaY != 0) {
+ int newY = destY - deltaY;
+ if (deltaY < 0) newY = destY + height;
+ OS.XClearArea (xDisplay, xDrawable, x, newY, width, Math.abs (deltaY), true);
+ }
+ }
+}
+public void copyArea(Image image, int x, int y) {
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (image.type != SWT.BITMAP) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ Rectangle rect = image.getBounds();
+ int xDisplay = data.display;
+ int xGC = OS.XCreateGC(xDisplay, image.pixmap, 0, null);
+ if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
+ OS.XCopyArea(xDisplay, data.drawable, image.pixmap, xGC, x, y, rect.width, rect.height, 0, 0);
+ OS.XFreeGC(xDisplay, xGC);
+}
+public void dispose () {
+ if (handle == 0) return;
+
+ /* Free resources */
+ int clipRgn = data.clipRgn;
+ if (clipRgn != 0) OS.XDestroyRegion(clipRgn);
+ Image image = data.image;
+ if (image != null) image.memGC = null;
+ int renderTable = data.renderTable;
+ if (renderTable != 0) OS.XmRenderTableFree(renderTable);
+
+ /* Dispose the GC */
+ drawable.internal_dispose_GC(handle, data);
+
+ data.display = data.drawable = data.colormap = data.fontList =
+ data.clipRgn = data.renderTable = 0;
+ drawable = null;
+ data.device = null;
+ data.image = null;
+ data = null;
+ handle = 0;
+}
+public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ if (width == 0 || height == 0 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ OS.XDrawArc(data.display,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
+}
+public void drawFocus (int x, int y, int width, int height) {
+ /*
+ * When the drawable is not a widget, the highlight
+ * color is zero.
+ */
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ int highlightColor = 0;
+ int widget = OS.XtWindowToWidget (xDisplay, xDrawable);
+ if (widget != 0) {
+ int [] argList = {OS.XmNhighlightColor, 0};
+ OS.XtGetValues (widget, argList, argList.length / 2);
+ highlightColor = argList [1];
+ }
+
+ /* Draw the focus rectangle */
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground, values);
+ OS.XSetForeground (xDisplay, handle, highlightColor);
+ OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1);
+ OS.XSetForeground (xDisplay, handle, values.foreground);
+}
+public void drawImage(Image image, int x, int y) {
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
+}
+public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
+ if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
+ if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
+}
+void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
+ int[] width = new int[1];
+ int[] height = new int[1];
+ int[] depth = new int[1];
+ int[] unused = new int[1];
+ OS.XGetGeometry(data.display, srcImage.pixmap, unused, unused, unused, width, height, unused, depth);
+ int imgWidth = width[0];
+ int imgHeight = height[0];
+ if (simple) {
+ srcWidth = destWidth = imgWidth;
+ srcHeight = destHeight = imgHeight;
+ } else {
+ simple = srcX == 0 && srcY == 0 &&
+ srcWidth == destWidth && destWidth == imgWidth &&
+ srcHeight == destHeight && destHeight == imgHeight;
+ if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ }
+ if (srcImage.alpha != -1 || srcImage.alphaData != null) {
+ drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
+ } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) {
+ drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
+ } else {
+ drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
+ }
+}
+void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
+ /* Simple cases */
+ if (srcImage.alpha == 0) return;
+ if (srcImage.alpha == 255) {
+ drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth);
+ return;
+ }
+
+ /* Check the clipping */
+ Rectangle rect = getClipping();
+ rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight));
+ if (rect.isEmpty()) return;
+
+ /* Optimization. Recalculate the src and dest rectangles so that
+ * only the clipping area is drawn.
+ */
+ rect.width = Math.max(rect.width, (int)Math.ceil(destWidth / (float)srcWidth));
+ rect.height = Math.max(rect.height, (int)Math.ceil(destHeight / (float)srcHeight));
+ int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth);
+ int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth);
+ int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight);
+ int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight);
+ destX = rect.x;
+ destY = rect.y;
+ destWidth = rect.width;
+ destHeight = rect.height;
+ srcX = sx1;
+ srcY = sy1;
+ srcWidth = sx2 - sx1;
+ srcHeight = sy2 - sy1;
+
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ int xDestImagePtr = 0, xSrcImagePtr = 0;
+ try {
+ /* Get the background pixels */
+ xDestImagePtr = OS.XGetImage(xDisplay, xDrawable, destX, destY, destWidth, destHeight, OS.AllPlanes, OS.ZPixmap);
+ if (xDestImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ XImage xDestImage = new XImage();
+ OS.memmove(xDestImage, xDestImagePtr, XImage.sizeof);
+ byte[] destData = new byte[xDestImage.bytes_per_line * xDestImage.height];
+ OS.memmove(destData, xDestImage.data, destData.length);
+
+ /* Get the foreground pixels */
+ xSrcImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
+ if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ XImage xSrcImage = new XImage();
+ OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
+ byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
+ OS.memmove(srcData, xSrcImage.data, srcData.length);
+
+ /* Compose the pixels */
+ int srcOrder = xSrcImage.byte_order == OS.MSBFirst ? ImageData.MSB_FIRST : ImageData.LSB_FIRST;
+ int destOrder = xDestImage.byte_order == OS.MSBFirst ? ImageData.MSB_FIRST : ImageData.LSB_FIRST;
+ if (xSrcImage.depth <= 8) {
+ XColor[] xcolors = data.device.xcolors;
+ if (xcolors == null) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
+ byte[] reds = new byte[xcolors.length];
+ byte[] greens = new byte[xcolors.length];
+ byte[] blues = new byte[xcolors.length];
+ for (int i = 0; i < xcolors.length; i++) {
+ XColor color = xcolors[i];
+ if (color == null) continue;
+ reds[i] = (byte)((color.red >> 8) & 0xFF);
+ greens[i] = (byte)((color.green >> 8) & 0xFF);
+ blues[i] = (byte)((color.blue >> 8) & 0xFF);
+ }
+ ImageData.blit(ImageData.BLIT_ALPHA,
+ srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, reds, greens, blues, srcImage.alpha, srcImage.alphaData, imgWidth,
+ destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, reds, greens, blues,
+ false, false);
+ } else {
+ ImageData.blit(ImageData.BLIT_ALPHA,
+ srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, xDestImage.red_mask, xDestImage.green_mask, xDestImage.blue_mask, srcImage.alpha, srcImage.alphaData, imgWidth,
+ destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xDestImage.red_mask, xDestImage.green_mask, xDestImage.blue_mask,
+ false, false);
+ }
+
+ /* Draw the composed pixels */
+ OS.memmove(xDestImage.data, destData, destData.length);
+ OS.XPutImage(xDisplay, xDrawable, handle, xDestImagePtr, 0, 0, destX, destY, destWidth, destHeight);
+ } finally {
+ if (xSrcImagePtr != 0) OS.XDestroyImage(xSrcImagePtr);
+ if (xDestImagePtr != 0) OS.XDestroyImage(xDestImagePtr);
+ }
+}
+void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ int colorPixmap = srcImage.pixmap;
+ /* Generate the mask if necessary. */
+ if (srcImage.transparentPixel != -1) srcImage.createMask();
+ int maskPixmap = srcImage.mask;
+ int foreground = 0x00000000;
+ if (!(simple || (srcWidth == destWidth && srcHeight == destHeight))) {
+ /* Stretch the color and mask*/
+ int xImagePtr = scalePixmap(xDisplay, colorPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+ int xMaskPtr = scalePixmap(xDisplay, maskPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+
+ /* Create color scaled pixmaps */
+ colorPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, depth);
+ int tempGC = OS.XCreateGC(xDisplay, colorPixmap, 0, null);
+ OS.XPutImage(xDisplay, colorPixmap, tempGC, xImagePtr, 0, 0, 0, 0, destWidth, destHeight);
+ OS.XDestroyImage(xImagePtr);
+ OS.XFreeGC(xDisplay, tempGC);
+
+ /* Create mask scaled pixmaps */
+ maskPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, 1);
+ tempGC = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
+ OS.XPutImage(xDisplay, maskPixmap, tempGC, xMaskPtr, 0, 0, 0, 0, destWidth, destHeight);
+ OS.XDestroyImage(xMaskPtr);
+ OS.XFreeGC(xDisplay, tempGC);
+
+ /* Change the source rectangle */
+ srcX = srcY = 0;
+ srcWidth = destWidth;
+ srcHeight = destHeight;
+
+ foreground = ~foreground;
+ }
+
+ /* Do the blts */
+ XGCValues values = new XGCValues();
+ OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS. GCBackground | OS.GCFunction, values);
+ OS.XSetFunction(xDisplay, handle, OS.GXxor);
+ OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
+ OS.XSetForeground(xDisplay, handle, foreground);
+ OS.XSetBackground(xDisplay, handle, ~foreground);
+ OS.XSetFunction(xDisplay, handle, OS.GXand);
+ OS.XCopyPlane(xDisplay, maskPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY, 1);
+ OS.XSetFunction(xDisplay, handle, OS.GXxor);
+ OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
+ OS.XSetForeground(xDisplay, handle, values.foreground);
+ OS.XSetBackground(xDisplay, handle, values.background);
+ OS.XSetFunction(xDisplay, handle, values.function);
+
+ /* Destroy scaled pixmaps */
+ if (srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap);
+ if (srcImage.mask != maskPixmap) OS.XFreePixmap(xDisplay, maskPixmap);
+ /* Destroy the image mask if the there is a GC created on the image */
+ if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
+}
+void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ /* Simple case: no stretching */
+ if ((srcWidth == destWidth) && (srcHeight == destHeight)) {
+ OS.XCopyArea(xDisplay, srcImage.pixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
+ return;
+ }
+
+ /* Streching case */
+ int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+ OS.XPutImage(xDisplay, xDrawable, handle, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
+ OS.XDestroyImage(xImagePtr);
+}
+static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
+ int xSrcImagePtr = OS.XGetImage(display, pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
+ if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ XImage xSrcImage = new XImage();
+ OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
+ byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
+ OS.memmove(srcData, xSrcImage.data, srcData.length);
+ int error = 0, xImagePtr = 0;
+ int visual = OS.XDefaultVisual(display, OS.XDefaultScreen(display));
+ switch (xSrcImage.bits_per_pixel) {
+ case 1: {
+ int bitOrder = xSrcImage.bitmap_bit_order == OS.MSBFirst ? ImageData.MSB_FIRST : ImageData.LSB_FIRST;
+ int bplX = ((destWidth + 7) / 8 + 3) & 0xFFFC;
+ int bufSize = bplX * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch1(srcData, xSrcImage.bytes_per_line, bitOrder, 0, 0, srcWidth, srcHeight, buf, bplX, bitOrder, 0, 0, destWidth, destHeight, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
+ if (xImagePtr == 0) break;
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ xImage.byte_order = OS.MSBFirst;
+ xImage.bitmap_unit = 8;
+ xImage.bitmap_bit_order = xSrcImage.bitmap_bit_order;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ break;
+ }
+ case 4: {
+ /* Untested */
+ int bplX = (destWidth + 3) & 0xFFFC;
+ int bufSize = bplX * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch4(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, bplX, 0, 0, destWidth, destHeight, null, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImagePtr = OS.XCreateImage(display, visual, 4, OS.ZPixmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
+ break;
+ }
+ case 8: {
+ int bplX = (destWidth + 3) & 0xFFFC;
+ int bufSize = bplX * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch8(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, bplX, 0, 0, destWidth, destHeight, null, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImagePtr = OS.XCreateImage(display, visual, 8, OS.ZPixmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
+ break;
+ }
+ case 16: {
+ xImagePtr = OS.XCreateImage(display, visual, 16, OS.ZPixmap, 0, 0, destWidth, destHeight, 32, 0);
+ if (xImagePtr == 0) break;
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ int bufSize = xImage.bytes_per_line * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch16(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImage.data = bufPtr;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ break;
+ }
+ case 24: {
+ xImagePtr = OS.XCreateImage(display, visual, 24, OS.ZPixmap, 0, 0, destWidth, destHeight, 32, 0);
+ if (xImagePtr == 0) break;
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ int bufSize = xImage.bytes_per_line * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch24(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImage.data = bufPtr;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ break;
+ }
+ case 32: {
+ xImagePtr = OS.XCreateImage(display, visual, 24, OS.ZPixmap, 0, 0, destWidth, destHeight, 32, 0);
+ if (xImagePtr == 0) break;
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ int bufSize = xImage.bytes_per_line * destHeight;
+ byte[] buf = new byte[bufSize];
+ ImageData.stretch32(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ int bufPtr = OS.XtMalloc(bufSize);
+ OS.memmove(bufPtr, buf, bufSize);
+ xImage.data = bufPtr;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ break;
+ }
+ default:
+ error = SWT.ERROR_UNSUPPORTED_DEPTH;
+ }
+ OS.XDestroyImage(xSrcImagePtr);
+ if (xImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (error != 0) {
+ if (xImagePtr != 0) OS.XDestroyImage(xImagePtr);
+ SWT.error(error);
+ }
+ return xImagePtr;
+}
+public void drawLine (int x1, int y1, int x2, int y2) {
+ OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2);
+}
+public void drawOval(int x, int y, int width, int height) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040);
+}
+public void drawPolygon(int[] pointArray) {
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+
+ // Motif does not have a native drawPolygon() call. Instead we ensure
+ // that the first and last points are the same and call drawPolyline().
+
+ int length = pointArray.length;
+
+ // Need at least 3 points to define the polygon. If 2 or fewer points
+ // passed in, it is either a line or point so just call drawPolyline().
+ // Check what happens when XOR is implemented. We may not be able to
+ // do this optimization.
+
+ if (length < 4) {
+ drawPolyline(pointArray);
+ return;
+ }
+
+ // If first and last points are the same, the polygon is already closed.
+ // Just call drawPolyline().
+ //
+ // Check what happens when XOR is implemented. We may not be able to
+ // do this optimization.
+
+ if (pointArray[0] == pointArray[length - 2] && (pointArray[1] == pointArray[length - 1])) {
+ drawPolyline(pointArray);
+ return;
+ }
+
+ // Grow the list of points by one element and make sure the first and last
+ // points are the same. This will close the polygon and we can use the
+ // drawPolyline() call.
+
+ int newPoints[] = new int[length + 2];
+ for (int i = 0; i < length ; i++)
+ newPoints[i] = pointArray[i];
+ newPoints[length] = pointArray[0];
+ newPoints[length + 1] = pointArray[1];
+
+ drawPolyline(newPoints);
+}
+public void drawPolyline(int[] pointArray) {
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ short[] xPoints = new short[pointArray.length];
+ for (int i = 0; i<pointArray.length;i++) {
+ xPoints[i] = (short) pointArray[i];
+ }
+ OS.XDrawLines(data.display,data.drawable,handle,xPoints,xPoints.length / 2, OS.CoordModeOrigin);
+}
+public void drawRectangle (int x, int y, int width, int height) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height);
+}
+public void drawRectangle (Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ drawRectangle (rect.x, rect.y, rect.width, rect.height);
+}
+public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
+
+ // X does not have a native for drawing round rectangles. Do the work in Java
+ // and use drawLine() drawArc() calls.
+
+ int nx = x;
+ int ny = y;
+ int nw = width;
+ int nh = height;
+ int naw = arcWidth;
+ int nah = arcHeight;
+
+ if (nw < 0) {
+ nw = 0 - nw;
+ nx = nx - nw;
+ }
+ if (nh < 0) {
+ nh = 0 - nh;
+ ny = ny -nh;
+ }
+ if (naw < 0)
+ naw = 0 - naw;
+ if (nah < 0)
+ nah = 0 - nah;
+
+ int naw2 = naw / 2;
+ int nah2 = nah / 2;
+
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ OS.XDrawArc(xDisplay,xDrawable,handle,nx,ny,naw,nah,5760,5760);
+ OS.XDrawArc(xDisplay,xDrawable,handle,nx,ny + nh - nah,naw,nah,11520,5760);
+ OS.XDrawArc(xDisplay,xDrawable,handle,nx + nw - naw, ny + nh - nah, naw, nah,17280,5760);
+ OS.XDrawArc(xDisplay,xDrawable,handle,nx + nw - naw, ny, naw, nah, 0, 5760);
+ OS.XDrawLine(xDisplay,xDrawable,handle,nx + naw2, ny, nx + nw - naw2, ny);
+ OS.XDrawLine(xDisplay,xDrawable,handle,nx,ny + nah2, nx, ny + nh - nah2);
+ OS.XDrawLine(xDisplay,xDrawable,handle,nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
+ OS.XDrawLine(xDisplay,xDrawable,handle,nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
+}
+public void drawString (String string, int x, int y) {
+ drawString(string, x, y, false);
+}
+/**
+ * Draws the given string, using this graphics context's
+ * current font and foreground color.
+ * No tab expansion or CR processing will be performed.
+ *
+ * @param string the string to be drawn.
+ * @param x the <i>x</i> coordinate.
+ * @param y the <i>y</i> coordinate.
+ * @param isTransparent if true, the background will be transparent.
+ */
+public void drawString (String string, int x, int y, boolean isTransparent) {
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreate (buffer, OS.XmFONTLIST_DEFAULT_TAG);
+ if (isTransparent) {
+ OS.XmStringDraw (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ } else {
+ OS.XmStringDrawImage (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ }
+// OS.XmStringDrawUnderline (display, drawable, fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0);
+ OS.XmStringFree (xmString);
+}
+void createRenderTable() {
+ int xDisplay = data.display;
+ int fontList = data.fontList;
+ /* Get the width of the tabs */
+ byte[] buffer = {(byte)' ', 0};
+ int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
+ int tabWidth = OS.XmStringWidth(fontList, xmString) * 8;
+ OS.XmStringFree(xmString);
+
+ /* Create the tab list */
+ int [] tabs = new int[16];
+ int tab = OS.XmTabCreate(tabWidth, (byte) OS.XmPIXELS, (byte) OS.XmRELATIVE, (byte) OS.XmALIGNMENT_BEGINNING, null);
+ for (int i = 0; i < tabs.length; i++) tabs[i] = tab;
+ int tabList = OS.XmTabListInsertTabs(0, tabs, tabs.length, 0);
+
+ /* Create a font context to iterate over the elements in the font list */
+ int[] fontBuffer = new int[1];
+ if (!OS.XmFontListInitFontContext(fontBuffer, fontList)) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ int context = fontBuffer[0], fontListEntry = 0;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ int[] renditions = new int[4]; int renditionCount = 0;
+
+ /* Create a rendition for each entry in the font list */
+ int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
+ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, fontBuffer);
+ int fontType = (fontBuffer [0] == 0) ? OS.XmFONT_IS_FONT : OS.XmFONT_IS_FONTSET;
+ if (fontPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int [] argList = {
+ OS.XmNtabList, tabList,
+ OS.XmNfont, fontPtr,
+ OS.XmNfontType, fontType,
+ };
+ int rendition = OS.XmRenditionCreate(shellHandle, _MOTIF_DEFAULT_LOCALE, argList, argList.length / 2);
+ renditions[renditionCount++] = rendition;
+ if (renditionCount == renditions.length) {
+ int[] newArray = new int[renditions.length + 4];
+ System.arraycopy(newArray, 0, renditions, 0, renditionCount);
+ renditions = newArray;
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ OS.XmTabFree(tab);
+ OS.XmTabListFree(tabList);
+ OS.XtDestroyWidget (shellHandle);
+
+ /* Create the render table from the renditions */
+ data.renderTable = OS.XmRenderTableAddRenditions(0, renditions, renditionCount, OS.XmMERGE_REPLACE);
+ for (int i = 0; i < renditionCount; i++) OS.XmRenditionFree(renditions[i]);
+}
+public void drawText (String string, int x, int y) {
+ drawText(string, x, y, false);
+}
+/**
+ * Draws the text given by the specified string, using this
+ * graphics context's current font and foreground color.
+ * The string will be formatted with tab expansion and CR processing.
+ *
+ * @param string the string to be drawn.
+ * @param x the <i>x</i> coordinate.
+ * @param y the <i>y</i> coordinate.
+ * @param isTransparent if true, the background will be transparent.
+ */
+public void drawText (String string, int x, int y, boolean isTransparent) {
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (data.renderTable == 0) createRenderTable();
+ int renderTable = data.renderTable;
+ byte [] textBuffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringGenerate(textBuffer, null, OS.XmCHARSET_TEXT, _MOTIF_DEFAULT_LOCALE);
+ if (isTransparent) {
+ OS.XmStringDraw (data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ } else {
+ OS.XmStringDrawImage (data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ }
+// OS.XmStringDrawUnderline (display, drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0);
+ OS.XmStringFree (xmString);
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof GC)) return false;
+ GC gc = (GC)object;
+ return data.device == gc.data.device && handle == gc.handle;
+}
+public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ if (width == 0 || height == 0 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (xDisplay, handle, values.background);
+ OS.XFillArc(xDisplay,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
+ OS.XSetForeground (xDisplay, handle, values.foreground);
+}
+public void fillOval (int x, int y, int width, int height) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ int display = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (display, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (display, handle, values.background);
+ OS.XFillArc (display, data.drawable, handle, x, y, width, height, 0, 23040);
+ OS.XSetForeground (display, handle, values.foreground);
+}
+public void fillPolygon(int[] pointArray) {
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ short[] xPoints = new short[pointArray.length];
+ for (int i = 0; i<pointArray.length;i++) {
+ xPoints[i] = (short) pointArray[i];
+ }
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (xDisplay, handle, values.background);
+ OS.XFillPolygon(xDisplay, data.drawable, handle,xPoints, xPoints.length / 2, OS.Convex, OS.CoordModeOrigin);
+ OS.XSetForeground (xDisplay, handle, values.foreground);
+}
+public void fillRectangle (int x, int y, int width, int height) {
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (xDisplay, handle, values.background);
+ OS.XFillRectangle (xDisplay, data.drawable, handle, x, y, width, height);
+ OS.XSetForeground (xDisplay, handle, values.foreground);
+}
+public void fillRectangle (Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (xDisplay, handle, values.background);
+ OS.XFillRectangle (xDisplay, data.drawable, handle, rect.x, rect.y, rect.width, rect.height);
+ OS.XSetForeground (xDisplay, handle, values.foreground);
+}
+public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ int nx = x;
+ int ny = y;
+ int nw = width;
+ int nh = height;
+ int naw = arcWidth;
+ int nah = arcHeight;
+
+ if (nw < 0) {
+ nw = 0 - nw;
+ nx = nx - nw;
+ }
+ if (nh < 0) {
+ nh = 0 - nh;
+ ny = ny -nh;
+ }
+ if (naw < 0)
+ naw = 0 - naw;
+ if (nah < 0)
+ nah = 0 - nah;
+
+ naw = naw < nw ? naw : nw;
+ nah = nah < nh ? nah : nh;
+
+ int naw2 = naw / 2;
+ int nah2 = nah / 2;
+
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground(xDisplay, handle, values.background);
+ OS.XFillArc(xDisplay,xDrawable,handle,nx,ny,naw,nah,5760,5760);
+ OS.XFillArc(xDisplay,xDrawable,handle,nx,ny + nh - nah,naw,nah,11520,5760);
+ OS.XFillArc(xDisplay,xDrawable,handle,nx + nw - naw, ny + nh - nah, naw, nah,17280,5760);
+ OS.XFillArc(xDisplay,xDrawable,handle,nx + nw - naw, ny, naw, nah, 0, 5760);
+ OS.XFillRectangle(xDisplay,xDrawable,handle,nx + naw2, ny, nw - naw, nh);
+ OS.XFillRectangle(xDisplay,xDrawable,handle,nx,ny + nah2, naw2, nh - nah);
+ OS.XFillRectangle(xDisplay,xDrawable,handle,nx + nw - (naw / 2), ny + nah2, naw2, nh -nah);
+ OS.XSetForeground(xDisplay, handle, values.foreground);
+}
+public int getAdvanceWidth(char ch) {
+ int fontList = data.fontList;
+ byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }, false);
+ int val = charBuffer[0] & 0xFF;
+ /* Create a font context to iterate over each element in the font list */
+ int[] buffer = new int[1];
+ if (!OS.XmFontListInitFontContext(buffer, fontList)) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer[0];
+ XFontStruct fontStruct = new XFontStruct();
+ XCharStruct charStruct = new XCharStruct();
+ int fontListEntry;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
+ if (buffer[0] == 0) {
+ OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
+ /* FontList contains a single font */
+ if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
+ /* Single byte fontStruct */
+ if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ } else {
+ /* Double byte fontStruct */
+ int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int row = 0;
+ if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
+ int col = charBuffer[0] - fontStruct.min_char_or_byte2;
+ if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ int offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ }
+ } else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int[nFonts];
+ OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
+ /* Go through each fontStruct in the font set */
+ for (int i = 0; i < nFonts; i++) {
+ OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
+ if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
+ /* Single byte fontStruct */
+ if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ } else {
+ /* Double byte fontStruct */
+ int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int row = 0;
+ if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
+ int col = charBuffer[0] - fontStruct.min_char_or_byte2;
+ if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ int offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ return 0;
+}
+public Color getBackground() {
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues();
+ if (OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values) == 0) {
+ // Check error case here. If a palette has been set we may be able
+ // to do a better job.
+ return null;
+ }
+ XColor xColor = new XColor();
+ xColor.pixel = values.background;
+ OS.XQueryColor(xDisplay,data.colormap,xColor);
+ return Color.motif_new(data.device, xColor);
+
+}
+public int getCharWidth(char ch) {
+ int fontList = data.fontList;
+ byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }, false);
+ int val = charBuffer[0] & 0xFF;
+ /* Create a font context to iterate over each element in the font list */
+ int[] buffer = new int[1];
+ if (!OS.XmFontListInitFontContext(buffer, fontList)) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer[0];
+ XFontStruct fontStruct = new XFontStruct();
+ XCharStruct charStruct = new XCharStruct();
+ int fontListEntry;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
+ if (buffer[0] == 0) {
+ OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
+ /* FontList contains a single font */
+ if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
+ /* Single byte fontStruct */
+ if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.lbearing;
+ }
+ }
+ } else {
+ /* Double byte fontStruct */
+ int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int row = 0;
+ if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
+ int col = charBuffer[0] - fontStruct.min_char_or_byte2;
+ if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ int offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.lbearing;
+ }
+ }
+ }
+ } else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int[nFonts];
+ OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
+ /* Go through each fontStruct in the font set */
+ for (int i = 0; i < nFonts; i++) {
+ OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
+ if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
+ /* Single byte fontStruct */
+ if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.lbearing;
+ }
+ }
+ } else {
+ /* Double byte fontStruct */
+ int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int row = 0;
+ if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
+ int col = charBuffer[0] - fontStruct.min_char_or_byte2;
+ if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
+ /* The font contains the character */
+ int offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.lbearing;
+ }
+ }
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ return 0;
+}
+public Rectangle getClipping() {
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ int[] unused = new int[1];
+ OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
+ return new Rectangle(0, 0, width[0], height[0]);
+ }
+ XRectangle rect = new XRectangle();
+ OS.XClipBox(clipRgn, rect);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+}
+public void getClipping(Region region) {
+ if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int hRegion = region.handle;
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ int[] unused = new int[1];
+ OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
+ OS.XSubtractRegion (hRegion, hRegion, hRegion);
+ XRectangle rect = new XRectangle();
+ rect.x = 0; rect.y = 0;
+ rect.width = (short)width[0]; rect.height = (short)height[0];
+ OS.XUnionRectWithRegion(rect, hRegion, hRegion);
+ return;
+ }
+ OS.XSubtractRegion (hRegion, hRegion, hRegion);
+ OS.XUnionRegion (clipRgn, hRegion, hRegion);
+}
+public Font getFont () {
+ return Font.motif_new(data.device, data.fontList);
+}
+int getFontHeight () {
+ int fontList = data.fontList;
+ /* Create a font context to iterate over each element in the font list */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, fontList)) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer [0];
+
+ /* Values discovering during iteration */
+ int height = 0;
+ XFontStruct fontStruct = new XFontStruct ();
+ int fontListEntry;
+ int [] fontStructPtr = new int [1];
+ int [] fontNamePtr = new int [1];
+
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
+ if (buffer [0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
+ int fontHeight = fontStruct.ascent + fontStruct.descent;
+ if (fontHeight > height) height = fontHeight;
+ } else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int [nFonts];
+ OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
+
+ /* Go through each fontStruct in the font set */
+ for (int i=0; i<nFonts; i++) {
+ OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
+ int fontHeight = fontStruct.ascent + fontStruct.descent;
+ if (fontHeight > height) height = fontHeight;
+ }
+ }
+ }
+
+ OS.XmFontListFreeFontContext (context);
+ return height;
+}
+public FontMetrics getFontMetrics() {
+ int xDisplay = data.display;
+ int fontList = data.fontList;
+ /* Create a font context to iterate over each element in the font list */
+ int[] buffer = new int[1];
+ if (!OS.XmFontListInitFontContext(buffer, fontList)) {
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer[0];
+ /* Values discovering during iteration */
+ int ascent = 0;
+ int descent = 0;
+ int averageCharWidth = 0, numAverageCharWidth = 0;
+ int leading = 0;
+ int height = 0;
+
+ XFontStruct fontStruct = new XFontStruct();
+ int fontListEntry;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
+ if (buffer[0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
+ ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
+ descent = descent > fontStruct.descent ? descent : fontStruct.descent;
+ int tmp = fontStruct.ascent + fontStruct.descent;
+ height = height > tmp ? height : tmp;
+ tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
+ leading = leading > tmp ? leading : tmp;
+ /* Calculate average character width */
+ int propPtr = fontStruct.properties;
+ for (int i = 0; i < fontStruct.n_properties; i++) {
+ /* Reef through properties looking for XAFONT */
+ int[] prop = new int[2];
+ OS.memmove(prop, propPtr, 8);
+ if (prop[0] == OS.XA_FONT) {
+ /* Found it, prop[1] points to the string */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int strPtr = ptr;
+ byte[] c = new byte[1];
+ OS.memmove(c, strPtr, 1);
+ while (c[0] != 0) {
+ stringBuffer.append((char)c[0]);
+ strPtr++;
+ OS.memmove(c, strPtr, 1);
+ }
+ String xlfd = stringBuffer.toString().toLowerCase();
+ int avg = FontData.motif_new(xlfd).averageWidth / 10;
+ OS.XtFree(ptr);
+ if (avg == 0) {
+ /**
+ * Not all fonts have average character width encoded
+ * in the xlfd. This one doesn't, so do it the hard
+ * way by averaging all the character widths.
+ */
+ int sum = 0, count = 0;
+ int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int perCharPtr = fontStruct.per_char;
+ XCharStruct struct = new XCharStruct();
+ for (int index = 0; index < cols; index++) {
+ OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
+ int w = struct.width;
+ if (w != 0) {
+ sum += w;
+ count++;
+ }
+ }
+ averageCharWidth += sum / count;
+ } else {
+ /* Average character width was in the xlfd */
+ averageCharWidth += avg;
+ }
+ numAverageCharWidth++;
+ break;
+ }
+ propPtr += 8;
+ }
+ }
+ else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int[nFonts];
+ OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
+ /* Go through each fontStruct in the font set */
+ for (int i = 0; i < nFonts; i++) {
+ OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
+ ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
+ descent = descent > fontStruct.descent ? descent : fontStruct.descent;
+ int tmp = fontStruct.ascent + fontStruct.descent;
+ height = height > tmp ? height : tmp;
+ tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
+ leading = leading > tmp ? leading : tmp;
+ /* Calculate average character width */
+ int propPtr = fontStruct.properties;
+ for (int j = 0; j < fontStruct.n_properties; j++) {
+ /* Reef through properties looking for XAFONT */
+ int[] prop = new int[2];
+ OS.memmove(prop, propPtr, 8);
+ if (prop[0] == OS.XA_FONT) {
+ /* Found it, prop[1] points to the string */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int strPtr = ptr;
+ byte[] c = new byte[1];
+ OS.memmove(c, strPtr, 1);
+ while (c[0] != 0) {
+ stringBuffer.append((char)c[0]);
+ strPtr++;
+ OS.memmove(c, strPtr, 1);
+ }
+ String xlfd = stringBuffer.toString().toLowerCase();
+ int avg = FontData.motif_new(xlfd).averageWidth / 10;
+ OS.XFree(ptr);
+ if (avg == 0) {
+ /**
+ * Not all fonts have average character width encoded
+ * in the xlfd. This one doesn't, so do it the hard
+ * way by averaging all the character widths.
+ */
+ int sum = 0, count = 0;
+ int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int perCharPtr = fontStruct.per_char;
+ XCharStruct struct = new XCharStruct();
+ for (int index = 0; index < cols; index++) {
+ OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
+ int w = struct.width;
+ if (w != 0) {
+ sum += w;
+ count++;
+ }
+ }
+ averageCharWidth += sum / count;
+ } else {
+ /* Average character width was in the xlfd */
+ averageCharWidth += avg;
+ }
+ numAverageCharWidth++;
+ break;
+ }
+ propPtr += 8;
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ return FontMetrics.motif_new(ascent, descent, averageCharWidth / numAverageCharWidth, leading, height);
+}
+public Color getForeground() {
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues();
+ if (OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values) == 0) {
+ // Check error case here. If a palette has been set we may be able
+ // to do a better job.
+ return null;
+ }
+ XColor xColor = new XColor();
+ xColor.pixel = values.foreground;
+ OS.XQueryColor(xDisplay,data.colormap,xColor);
+ return Color.motif_new(data.device, xColor);
+
+}
+public int getLineStyle() {
+ return data.lineStyle;
+}
+public int getLineWidth() {
+ XGCValues values = new XGCValues();
+ OS.XGetGCValues(data.display, handle, OS.GCLineWidth, values);
+ return values.line_width;
+}
+public boolean getXORMode() {
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (data.display, handle, OS.GCFunction, values);
+ return values.function == OS.GXxor;
+}
+public int hashCode () {
+ return handle;
+}
+void init(Drawable drawable, GCData data, int xGC) {
+ int xDisplay = data.display;
+ int foreground = data.foreground;
+ if (foreground != -1) OS.XSetForeground (xDisplay, xGC, foreground);
+ int background = data.background;
+ if (background != -1) OS.XSetBackground (xDisplay, xGC, background);
+ Image image = data.image;
+ if (image != null) {
+ image.memGC = this;
+ /*
+ * The transparent pixel mask might change when drawing on
+ * the image. Destroy it so that it is regenerated when
+ * necessary.
+ */
+ if (image.transparentPixel != -1) image.destroyMask();
+ }
+ this.drawable = drawable;
+ this.data = data;
+ handle = xGC;
+}
+public boolean isClipped() {
+ return data.clipRgn != 0;
+}
+public boolean isDisposed() {
+ return handle == 0;
+}
+public static GC motif_new(Drawable drawable, GCData data) {
+ GC gc = new GC();
+ int xGC = drawable.internal_new_GC(data);
+ gc.init(drawable, data, xGC);
+ return gc;
+}
+public void setBackground (Color color) {
+ if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ OS.XSetBackground(data.display, handle, color.handle.pixel);
+}
+public void setClipping (int x, int y, int width, int height) {
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ clipRgn = OS.XCreateRegion ();
+ } else {
+ OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
+ }
+ XRectangle rect = new XRectangle ();
+ rect.x = (short) x; rect.y = (short) y;
+ rect.width = (short) width; rect.height = (short) height;
+ OS.XSetClipRectangles (data.display, handle, 0, 0, rect, 1, OS.Unsorted);
+ OS.XUnionRectWithRegion(rect, clipRgn, clipRgn);
+}
+public void setClipping (Rectangle rect) {
+ if (rect == null) {
+ OS.XSetClipMask (data.display, handle, OS.None);
+ return;
+ }
+ setClipping (rect.x, rect.y, rect.width, rect.height);
+}
+public void setClipping (Region region) {
+ int clipRgn = data.clipRgn;
+ if (region == null) {
+ OS.XSetClipMask (data.display, handle, OS.None);
+ if (clipRgn != 0) {
+ OS.XDestroyRegion (clipRgn);
+ clipRgn = 0;
+ }
+ } else {
+ if (clipRgn == 0) {
+ clipRgn = OS.XCreateRegion ();
+ } else {
+ OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
+ }
+ OS.XUnionRegion (region.handle, clipRgn, clipRgn);
+ OS.XSetRegion (data.display, handle, region.handle);
+ }
+}
+public void setFont (Font font) {
+ if (font == null) font = data.device.getSystemFont ();
+ if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ data.fontList = font.handle;
+ if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
+ data.renderTable = 0;
+}
+public void setForeground (Color color) {
+ if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ OS.XSetForeground(data.display, handle, color.handle.pixel);
+}
+public void setLineStyle(int lineStyle) {
+ int xDisplay = data.display;
+ switch (lineStyle) {
+ case SWT.LINE_SOLID:
+ data.lineStyle = lineStyle;
+ OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineSolid, OS.CapButt, OS.JoinMiter);
+ return;
+ case SWT.LINE_DASH:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2},2);
+ break;
+ case SWT.LINE_DOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {3, 1},2);
+ break;
+ case SWT.LINE_DASHDOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1},4);
+ break;
+ case SWT.LINE_DASHDOTDOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1, 3, 1},6);
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ data.lineStyle = lineStyle;
+ OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter);
+
+}
+public void setLineWidth(int width) {
+ if (data.lineStyle == SWT.LINE_SOLID) {
+ OS.XSetLineAttributes(data.display, handle, width, OS.LineSolid, OS.CapButt, OS.JoinMiter);
+ } else {
+ OS.XSetLineAttributes(data.display, handle, width, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter);
+ }
+}
+public void setXORMode(boolean val) {
+ if (val)
+ OS.XSetFunction(data.display, handle, OS.GXxor);
+ else
+ OS.XSetFunction(data.display, handle, OS.GXcopy);
+}
+public Point stringExtent(String string) {
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (string.length () == 0) return new Point(0, getFontHeight());
+ byte[] buffer = Converter.wcsToMbcs(null, string, true);
+ int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
+ int fontList = data.fontList;
+ int width = OS.XmStringWidth(fontList, xmString);
+ int height = OS.XmStringHeight(fontList, xmString);
+ OS.XmStringFree(xmString);
+ return new Point(width, height);
+}
+public Point textExtent(String string) {
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (string.length () == 0) return new Point(0, getFontHeight());
+ byte [] textBuffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringGenerate(textBuffer, null, OS.XmCHARSET_TEXT, _MOTIF_DEFAULT_LOCALE);
+ if (data.renderTable == 0) createRenderTable();
+ int renderTable = data.renderTable;
+ int width = OS.XmStringWidth(renderTable, xmString);
+ int height = OS.XmStringHeight(renderTable, xmString);
+ OS.XmStringFree(xmString);
+ return new Point(width, height);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java
new file mode 100755
index 0000000000..410257e4af
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java
@@ -0,0 +1,17 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.*;
+
+public final class GCData {
+ public Device device;
+ public Image image;
+ public int display;
+ public int drawable;
+ public int foreground = -1;
+ public int background = -1;
+ public int fontList;
+ public int colormap;
+ public int clipRgn;
+ public int lineStyle = SWT.LINE_SOLID;
+ public int renderTable;
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
new file mode 100755
index 0000000000..6d43261abd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
@@ -0,0 +1,872 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import java.io.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Image implements Drawable {
+ /**
+ * Specifies whether the receiver is a bitmap or an icon.
+ * Values: SWT.BITMAP, SWT.ICON
+ */
+ public int type;
+
+ /**
+ * The handle to the OS pixmap resource.
+ * Warning: This field is platform dependent.
+ */
+ public int pixmap;
+
+ /**
+ * The handle to the OS mask resource.
+ * Warning: This field is platform dependent.
+ */
+ public int mask;
+
+ /**
+ * The device where this image was created.
+ */
+ Device device;
+
+ /**
+ * specifies the transparent pixel
+ * (Warning: This field is platform dependent)
+ */
+ int transparentPixel = -1;
+
+ /**
+ * The GC the image is currently selected in.
+ * Warning: This field is platform dependent.
+ */
+ GC memGC;
+
+ /**
+ * The alpha data of the image.
+ * Warning: This field is platform dependent.
+ */
+ byte[] alphaData;
+
+ /**
+ * The global alpha value to be used for every pixel.
+ * Warning: This field is platform dependent.
+ */
+ int alpha = -1;
+
+ /**
+ * Specifies the default scanline padding.
+ * Warning: This field is platform dependent.
+ */
+ static final int DEFAULT_SCANLINE_PAD = 4;
+
+Image() {
+}
+public Image(Device device, int width, int height) {
+ init(device, width, height);
+}
+public Image(Device device, Image srcImage, int flag) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int xDisplay = device.xDisplay;
+ this.type = srcImage.type;
+ this.mask = 0;
+ int[] unused = new int[1];
+ int[] w = new int[1];
+ int[] h = new int[1];
+ OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, w, h, unused, unused);
+ int width = w[0];
+ int height = h[0];
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ /* Don't create the mask here if flag is SWT.IMAGE_GRAY. See below.*/
+ if (flag != SWT.IMAGE_GRAY && srcImage.mask != 0) {
+ /* Generate the mask if necessary. */
+ if (srcImage.transparentPixel != -1) srcImage.createMask();
+ int mask = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
+ int gc = OS.XCreateGC(xDisplay, mask, 0, null);
+ OS.XCopyArea(xDisplay, srcImage.mask, mask, gc, 0, 0, width, height, 0, 0);
+ OS.XFreeGC(xDisplay, gc);
+ this.mask = mask;
+ /* Destroy the image mask if the there is a GC created on the image */
+ if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
+ }
+ switch (flag) {
+ case SWT.IMAGE_COPY:
+ int[] depth = new int[1];
+ OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, unused, unused, unused, depth);
+ int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth[0]);
+ int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
+ OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
+ OS.XFreeGC(xDisplay, gc);
+ this.pixmap = pixmap;
+ transparentPixel = srcImage.transparentPixel;
+ alpha = srcImage.alpha;
+ if (srcImage.alphaData != null) {
+ alphaData = new byte[srcImage.alphaData.length];
+ System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
+ }
+ return;
+ case SWT.IMAGE_DISABLE:
+ /* Get src image data */
+ XImage srcXImage = new XImage();
+ int srcXImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ OS.memmove(srcXImage, srcXImagePtr, XImage.sizeof);
+ byte[] srcData = new byte[srcXImage.bytes_per_line * srcXImage.height];
+ OS.memmove(srcData, srcXImage.data, srcData.length);
+ /* Create destination image */
+ int destPixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, srcXImage.depth);
+ XImage destXImage = new XImage();
+ int destXImagePtr = OS.XGetImage(xDisplay, drawable, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ OS.memmove(destXImage, destXImagePtr, XImage.sizeof);
+ byte[] destData = new byte[destXImage.bytes_per_line * destXImage.height];
+ /* Find the colors to map to */
+ Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
+ int zeroPixel = zeroColor.handle.pixel;
+ int onePixel = oneColor.handle.pixel;
+ switch (srcXImage.bits_per_pixel) {
+ case 1:
+ /**
+ * Nothing we can reasonably do here except copy
+ * the bitmap; we can't make it a higher color depth.
+ * Short-circuit the rest of the code and return.
+ */
+ gc = OS.XCreateGC(xDisplay, drawable, 0, null);
+ pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
+ OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
+ OS.XDestroyImage(srcXImagePtr);
+ OS.XDestroyImage(destXImagePtr);
+ OS.XFreeGC(xDisplay, gc);
+ return;
+ case 4:
+ SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
+ break;
+ case 8:
+ int index = 0;
+ int srcPixel, r, g, b;
+ XColor[] colors = new XColor[256];
+ int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
+ for (int y = 0; y < srcXImage.height; y++) {
+ for (int x = 0; x < srcXImage.bytes_per_line; x++) {
+ srcPixel = srcData[index + x] & 0xFF;
+ /* Get the RGB values of srcPixel */
+ if (colors[srcPixel] == null) {
+ XColor color = new XColor();
+ color.pixel = srcPixel;
+ OS.XQueryColor(xDisplay, colormap, color);
+ colors[srcPixel] = color;
+ }
+ XColor xColor = colors[srcPixel];
+ r = (xColor.red >> 8) & 0xFF;
+ g = (xColor.green >> 8) & 0xFF;
+ b = (xColor.blue >> 8) & 0xFF;
+ /* See if the rgb maps to 0 or 1 */
+ if ((r * r + g * g + b * b) < 98304) {
+ /* Map down to 0 */
+ destData[index + x] = (byte)zeroPixel;
+ } else {
+ /* Map up to 1 */
+ destData[index + x] = (byte)onePixel;
+ }
+ }
+ index += srcXImage.bytes_per_line;
+ }
+ break;
+ case 16:
+ index = 0;
+ /* Get masks */
+ Visual visual = new Visual();
+ int screenNum = OS.XDefaultScreen(xDisplay);
+ int visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
+ OS.memmove(visual, visualPtr, Visual.sizeof);
+ int redMask = visual.red_mask;
+ int greenMask = visual.green_mask;
+ int blueMask = visual.blue_mask;
+ /* Calculate mask shifts */
+ int[] shift = new int[1];
+ getOffsetForMask(16, redMask, srcXImage.byte_order, shift);
+ int rShift = 24 - shift[0];
+ getOffsetForMask(16, greenMask, srcXImage.byte_order, shift);
+ int gShift = 24 - shift[0];
+ getOffsetForMask(16, blueMask, srcXImage.byte_order, shift);
+ int bShift = 24 - shift[0];
+ byte zeroLow = (byte)(zeroPixel & 0xFF);
+ byte zeroHigh = (byte)((zeroPixel >> 8) & 0xFF);
+ byte oneLow = (byte)(onePixel & 0xFF);
+ byte oneHigh = (byte)((onePixel >> 8) & 0xFF);
+ for (int y = 0; y < srcXImage.height; y++) {
+ int xIndex = 0;
+ for (int x = 0; x < srcXImage.bytes_per_line; x += 2) {
+ srcPixel = ((srcData[index + xIndex + 1] & 0xFF) << 8) | (srcData[index + xIndex] & 0xFF);
+ r = (srcPixel & redMask) << rShift >> 16;
+ g = (srcPixel & greenMask) << gShift >> 16;
+ b = (srcPixel & blueMask) << bShift >> 16;
+ /* See if the rgb maps to 0 or 1 */
+ if ((r * r + g * g + b * b) < 98304) {
+ /* Map down to 0 */
+ destData[index + xIndex] = zeroLow;
+ destData[index + xIndex + 1] = zeroHigh;
+ } else {
+ /* Map up to 1 */
+ destData[index + xIndex] = oneLow;
+ destData[index + xIndex + 1] = oneHigh;
+ }
+ xIndex += srcXImage.bits_per_pixel / 8;
+ }
+ index += srcXImage.bytes_per_line;
+ }
+ break;
+ case 24:
+ case 32:
+ index = 0;
+ /* Get masks */
+ visual = new Visual();
+ screenNum = OS.XDefaultScreen(xDisplay);
+ visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
+ OS.memmove(visual, visualPtr, Visual.sizeof);
+ redMask = visual.red_mask;
+ greenMask = visual.green_mask;
+ blueMask = visual.blue_mask;
+ /* Calculate mask shifts */
+ shift = new int[1];
+ getOffsetForMask(srcXImage.bits_per_pixel, redMask, srcXImage.byte_order, shift);
+ rShift = shift[0];
+ getOffsetForMask(srcXImage.bits_per_pixel, greenMask, srcXImage.byte_order, shift);
+ gShift = shift[0];
+ getOffsetForMask(srcXImage.bits_per_pixel, blueMask, srcXImage.byte_order, shift);
+ bShift = shift[0];
+ byte zeroR = (byte)zeroColor.getRed();
+ byte zeroG = (byte)zeroColor.getGreen();
+ byte zeroB = (byte)zeroColor.getBlue();
+ byte oneR = (byte)oneColor.getRed();
+ byte oneG = (byte)oneColor.getGreen();
+ byte oneB = (byte)oneColor.getBlue();
+ for (int y = 0; y < srcXImage.height; y++) {
+ int xIndex = 0;
+ for (int x = 0; x < srcXImage.width; x++) {
+ r = srcData[index + xIndex + rShift] & 0xFF;
+ g = srcData[index + xIndex + gShift] & 0xFF;
+ b = srcData[index + xIndex + bShift] & 0xFF;
+ /* See if the rgb maps to 0 or 1 */
+ if ((r * r + g * g + b * b) < 98304) {
+ /* Map down to 0 */
+ destData[index + xIndex + rShift] = zeroR;
+ destData[index + xIndex + gShift] = zeroG;
+ destData[index + xIndex + bShift] = zeroB;
+ } else {
+ /* Map up to 1 */
+ destData[index + xIndex + rShift] = oneR;
+ destData[index + xIndex + gShift] = oneG;
+ destData[index + xIndex + bShift] = oneB;
+ }
+ xIndex += destXImage.bits_per_pixel / 8;
+ }
+ index += srcXImage.bytes_per_line;
+ }
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ }
+ OS.memmove(destXImage.data, destData, destData.length);
+ gc = OS.XCreateGC(xDisplay, destPixmap, 0, null);
+ OS.XPutImage(xDisplay, destPixmap, gc, destXImagePtr, 0, 0, 0, 0, width, height);
+ OS.XDestroyImage(destXImagePtr);
+ OS.XDestroyImage(srcXImagePtr);
+ OS.XFreeGC(xDisplay, gc);
+ this.pixmap = destPixmap;
+ return;
+ case SWT.IMAGE_GRAY:
+ ImageData data = srcImage.getImageData();
+ PaletteData palette = data.palette;
+ ImageData newData = data;
+ if (!palette.isDirect) {
+ /* Convert the palette entries to gray. */
+ RGB [] rgbs = palette.getRGBs();
+ for (int i=0; i<rgbs.length; i++) {
+ if (data.transparentPixel != i) {
+ RGB color = rgbs [i];
+ int red = color.red;
+ int green = color.green;
+ int blue = color.blue;
+ int intensity = (red+red+green+green+green+green+green+blue) >> 3;
+ color.red = color.green = color.blue = intensity;
+ }
+ }
+ newData.palette = new PaletteData(rgbs);
+ } else {
+ /* Create a 8 bit depth image data with a gray palette. */
+ RGB[] rgbs = new RGB[256];
+ for (int i=0; i<rgbs.length; i++) {
+ rgbs[i] = new RGB(i, i, i);
+ }
+ newData = new ImageData(width, height, 8, new PaletteData(rgbs));
+ newData.maskData = data.maskData;
+ newData.maskPad = data.maskPad;
+
+ /* Convert the pixels. */
+ int[] scanline = new int[width];
+ int redMask = palette.redMask;
+ int greenMask = palette.greenMask;
+ int blueMask = palette.blueMask;
+ int redShift = palette.redShift;
+ int greenShift = palette.greenShift;
+ int blueShift = palette.blueShift;
+ for (int y=0; y<height; y++) {
+ int offset = y * newData.bytesPerLine;
+ data.getPixels(0, y, width, scanline, 0);
+ for (int x=0; x<width; x++) {
+ int pixel = scanline[x];
+ int red = pixel & redMask;
+ red = (redShift < 0) ? red >>> -redShift : red << redShift;
+ int green = pixel & greenMask;
+ green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
+ int blue = pixel & blueMask;
+ blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
+ newData.data[offset++] =
+ (byte)((red+red+green+green+green+green+green+blue) >> 3);
+ }
+ }
+ }
+ init (device, newData);
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+}
+public Image(Device device, Rectangle bounds) {
+ if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ init(device, bounds.width, bounds.height);
+}
+public Image(Device device, ImageData image) {
+ init(device, image);
+}
+public Image(Device device, ImageData source, ImageData mask) {
+ if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (source.width != mask.width || source.height != mask.height) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
+ image.maskPad = mask.scanlinePad;
+ image.maskData = mask.data;
+ init(device, image);
+}
+public Image(Device device, InputStream stream) {
+ init(device, new ImageData(stream));
+}
+public Image(Device device, String filename) {
+ init(device, new ImageData(filename));
+}
+/**
+ * Create the receiver's mask if necessary.
+ */
+void createMask() {
+ if (mask != 0) return;
+ int xDisplay = device.xDisplay;
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
+ int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
+ ImageData maskImage = getImageData().getTransparencyMask();
+ int maskPixmap = OS.XCreatePixmap(xDisplay, drawable, maskImage.width, maskImage.height, 1);
+ XColor[] xcolors = device.xcolors;
+ int gc = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
+ int error = Image.putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, xcolors, null, maskPixmap, gc);
+ OS.XFreeGC(xDisplay, gc);
+ this.mask = maskPixmap;
+}
+public void dispose () {
+ if (pixmap == 0) return;
+ int xDisplay = device.xDisplay;
+ if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap);
+ if (mask != 0) OS.XFreePixmap (xDisplay, mask);
+ device = null;
+ memGC = null;
+ pixmap = mask = 0;
+}
+/**
+ * Destroy the receiver's mask if it exists.
+ */
+void destroyMask() {
+ if (mask == 0) return;
+ OS.XFreePixmap (device.xDisplay, mask);
+ mask = 0;
+}
+public boolean equals (Object object) {
+ if (object == this) return true;
+ if (!(object instanceof Image)) return false;
+ Image image = (Image)object;
+ return device == image.device && pixmap == image.pixmap &&
+ transparentPixel == image.transparentPixel &&
+ mask == image.mask;
+}
+public Color getBackground() {
+ if (transparentPixel == -1) return null;
+ XColor xColor = new XColor();
+ xColor.pixel = transparentPixel;
+ int xDisplay = device.xDisplay;
+ int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
+ OS.XQueryColor(xDisplay, colormap, xColor);
+ return Color.motif_new(device, xColor);
+}
+public Rectangle getBounds () {
+ if (pixmap == 0) return new Rectangle(0, 0, 0, 0);
+ int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1];
+ OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, width, height, unused, unused);
+ return new Rectangle(0, 0, width [0], height [0]);
+}
+public ImageData getImageData() {
+ Rectangle srcBounds = getBounds();
+ int width = srcBounds.width;
+ int height = srcBounds.height;
+ int xDisplay = device.xDisplay;
+ int xSrcImagePtr = OS.XGetImage(xDisplay, pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ XImage xSrcImage = new XImage();
+ OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
+ /* Calculate the palette depending on the display attributes */
+ PaletteData palette = null;
+ switch (xSrcImage.depth) {
+ case 1:
+ palette = new PaletteData(new RGB[] {
+ new RGB(0, 0, 0),
+ new RGB(255, 255, 255)
+ });
+ break;
+ case 4:
+ /**
+ * We currently don't run on a 4-bit server, so 4-bit images
+ * should not exist.
+ */
+ SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
+ case 8:
+ /* Use the RGBs from the display to make the palette */
+ XColor[] xcolors = device.xcolors;
+ RGB[] rgbs = new RGB[xcolors.length];
+ for (int i = 0; i < rgbs.length; i++) {
+ XColor xcolor = xcolors[i];
+ if (xcolor == null) rgbs[i] = new RGB(0, 0, 0);
+ else rgbs[i] = new RGB((xcolor.red >> 8) & 0xFF, (xcolor.green >> 8) & 0xFF, (xcolor.blue >> 8) & 0xFF);
+ }
+ palette = new PaletteData(rgbs);
+ break;
+ case 16:
+ /**
+ * For some reason, the XImage does not have the mask information.
+ * We must get it from the visual.
+ */
+ int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
+ Visual v = new Visual();
+ OS.memmove(v, visual, Visual.sizeof);
+ palette = new PaletteData(v.red_mask, v.green_mask, v.blue_mask);
+ break;
+ case 24:
+ /* We always create 24-bit ImageData with the following palette */
+ palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
+ break;
+ default:
+ SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
+ }
+ ImageData data = new ImageData(width, height, xSrcImage.depth, palette);
+ int length = xSrcImage.bytes_per_line * xSrcImage.height;
+ data.data = new byte[length];
+ OS.memmove(data.data, xSrcImage.data, length);
+ if (xSrcImage.bits_per_pixel == 32) {
+ /**
+ * If bits per pixel is 32, scale the data down to 24, since we do not
+ * support 32-bit images
+ */
+ byte[] oldData = data.data;
+ int bytesPerLine = (xSrcImage.width * xSrcImage.depth + 7) / 8;
+ bytesPerLine = (bytesPerLine + 3) / 4 * 4;
+ byte[] newData = new byte[bytesPerLine * xSrcImage.height];
+ int destIndex = 0;
+ int srcIndex = 0;
+ int rOffset = 0, gOffset = 1, bOffset = 2;
+ if (xSrcImage.byte_order == OS.MSBFirst) {
+ rOffset = 2; gOffset = 1; bOffset = 0;
+ }
+ for (int y = 0; y < height; y++) {
+ destIndex = y * bytesPerLine;
+ srcIndex = y * xSrcImage.bytes_per_line;
+ for (int x = 0; x < width; x++) {
+ newData[destIndex] = oldData[srcIndex + rOffset];
+ newData[destIndex + 1] = oldData[srcIndex + gOffset];
+ newData[destIndex + 2] = oldData[srcIndex + bOffset];
+ srcIndex += 4;
+ destIndex += 3;
+ }
+ }
+ data.data = newData;
+ }
+ if (transparentPixel == -1 && type == SWT.ICON && mask != 0) {
+ /* Get the icon data */
+ data.maskPad = 4;
+ int xMaskPtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ XImage xMask = new XImage();
+ OS.memmove(xMask, xMaskPtr, XImage.sizeof);
+ data.maskData = new byte[xMask.bytes_per_line * xMask.height];
+ OS.memmove(data.maskData, xMask.data, data.maskData.length);
+ OS.XDestroyImage(xMaskPtr);
+ /* Bit swap the mask data if necessary */
+ if (xMask.bitmap_bit_order == OS.LSBFirst) {
+ byte[] maskData = data.maskData;
+ for (int i = 0; i < maskData.length; i++) {
+ byte b = maskData[i];
+ maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) |
+ ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) |
+ ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7));
+ }
+ }
+ }
+ data.transparentPixel = transparentPixel;
+ data.alpha = alpha;
+ if (alpha == -1 && alphaData != null) {
+ data.alphaData = new byte[alphaData.length];
+ System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
+ }
+ OS.XDestroyImage(xSrcImagePtr);
+ return data;
+}
+/**
+ * Get the offset for the given mask.
+ *
+ * For 24 and 32-bit masks, the offset indicates which byte holds the
+ * data for the given mask (indexed from 0).
+ * For example, in 0x0000FF00, the byte offset is 1.
+ *
+ * For 16-bit masks, the offset indicates which bit holds the most significant
+ * data for the given mask (indexed from 1).
+ * For example, in 0x7E0, the bit offset is 11.
+ *
+ * The different semantics are necessary because 24- and 32-bit images
+ * have their color components aligned on byte boundaries, and 16-bit images
+ * do not.
+ */
+static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) {
+ if (bitspp % 8 != 0) {
+ return false;
+ }
+ switch (mask) {
+ /* 24-bit and 32-bit masks */
+ case 0x000000FF:
+ poff[0] = 0;
+ break;
+ case 0x0000FF00:
+ poff[0] = 1;
+ break;
+ case 0x00FF0000:
+ poff[0] = 2;
+ break;
+ case 0xFF000000:
+ poff[0] = 3;
+ break;
+ /* 16-bit masks */
+ case 0x001F:
+ poff[0] = 5;
+ break;
+ case 0x03E0:
+ poff[0] = 10;
+ break;
+ case 0x07E0:
+ poff[0] = 11;
+ break;
+ case 0x7C00:
+ poff[0] = 15;
+ break;
+ case 0xF800:
+ poff[0] = 16;
+ break;
+ default:
+ return false;
+ }
+ if (bitspp == 16) {
+ return true;
+ }
+ if (poff[0] >= bitspp / 8) {
+ return false;
+ }
+ if (byteOrder == OS.MSBFirst) {
+ poff[0] = (bitspp/8 - 1) - poff[0];
+ }
+ return true;
+}
+public int hashCode () {
+ return pixmap;
+}
+void init(Device device, int width, int height) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ /* Create the pixmap */
+ if (width <= 0 | height <= 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+
+ this.type = SWT.BITMAP;
+ int xDisplay = device.xDisplay;
+ int screen = OS.XDefaultScreenOfDisplay(xDisplay);
+ int depth = OS.XDefaultDepthOfScreen(screen);
+ int screenNum = OS.XDefaultScreen(xDisplay);
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int xGC = OS.XCreateGC(xDisplay, drawable, 0, null);
+ this.pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth);
+ /* Fill the bitmap with white */
+ OS.XSetForeground(xDisplay, xGC, OS.XWhitePixel(xDisplay, screenNum));
+ OS.XFillRectangle(xDisplay, pixmap, xGC, 0, 0, width, height);
+ OS.XFreeGC(xDisplay, xGC);
+}
+void init(Device device, ImageData image) {
+ if (device == null) device = Device.getDevice();
+ if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ this.device = device;
+ if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int xDisplay = device.xDisplay;
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
+ int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
+ int pixmap = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, screenDepth);
+ int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
+ int[] transPixel = null;
+ if (image.transparentPixel != -1) transPixel = new int[]{image.transparentPixel};
+ int error = putImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, xDisplay, visual, screenDepth, device.xcolors, transPixel, pixmap, gc);
+ OS.XFreeGC(xDisplay, gc);
+ if (error != 0) {
+ OS.XFreePixmap (xDisplay, pixmap);
+ SWT.error(error);
+ }
+ if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) {
+ if (image.transparentPixel != -1) transparentPixel = transPixel[0];
+ ImageData maskImage = image.getTransparencyMask();
+ int mask = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, 1);
+ gc = OS.XCreateGC(xDisplay, mask, 0, null);
+ error = putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, device.xcolors, null, mask, gc);
+ OS.XFreeGC(xDisplay, gc);
+ if (error != 0) {
+ OS.XFreePixmap (xDisplay, pixmap);
+ OS.XFreePixmap (xDisplay, mask);
+ SWT.error(error);
+ }
+ this.mask = mask;
+ if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
+ this.type = SWT.ICON;
+ } else {
+ this.type = SWT.BITMAP;
+ }
+ } else {
+ this.type = SWT.BITMAP;
+ this.mask = 0;
+ this.alpha = image.alpha;
+ if (image.alpha == -1 && image.alphaData != null) {
+ this.alphaData = new byte[image.alphaData.length];
+ System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
+ }
+ }
+ this.pixmap = pixmap;
+}
+public int internal_new_GC (GCData data) {
+ if (type != SWT.BITMAP || memGC != null) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int xDisplay = device.xDisplay;
+ int xGC = OS.XCreateGC (xDisplay, pixmap, 0, null);
+ if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
+ if (data != null) {
+ data.device = device;
+ data.display = xDisplay;
+ data.drawable = pixmap;
+ data.fontList = device.getSystemFont ().handle;
+ data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
+ data.image = this;
+ }
+ return xGC;
+}
+public void internal_dispose_GC (int gc, GCData data) {
+ int xDisplay = device.xDisplay;
+ OS.XFreeGC(xDisplay, gc);
+}
+public boolean isDisposed() {
+ return pixmap == 0;
+}
+public static Image motif_new(Device device, int type, int pixmap, int mask) {
+ if (device == null) device = Device.getDevice();
+ Image image = new Image();
+ image.device = device;
+ image.type = type;
+ image.pixmap = pixmap;
+ image.mask = mask;
+ return image;
+}
+/**
+ * Put a device-independent image of any depth into a drawable of any depth,
+ * stretching if necessary.
+ */
+static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int display, int visual, int screenDepth, XColor[] xcolors, int[] transparentPixel, int drawable, int gc) {
+ PaletteData palette = image.palette;
+ if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
+ ((image.depth == 16 || image.depth == 24) && palette.isDirect)))
+ return SWT.ERROR_UNSUPPORTED_DEPTH;
+
+ boolean flipX = destWidth < 0;
+ boolean flipY = destHeight < 0;
+ if (flipX) {
+ destWidth = -destWidth;
+ destX = destX - destWidth;
+ }
+ if (flipY) {
+ destHeight = -destHeight;
+ destY = destY - destHeight;
+ }
+ byte[] srcReds = null, srcGreens = null, srcBlues = null;
+ if (image.depth <= 8) {
+ int length = palette.getRGBs().length;
+ srcReds = new byte[length];
+ srcGreens = new byte[length];
+ srcBlues = new byte[length];
+ RGB[] rgbs = palette.getRGBs();
+ for (int i = 0; i < rgbs.length; i++) {
+ RGB rgb = rgbs[i];
+ if (rgb == null) continue;
+ srcReds[i] = (byte)rgb.red;
+ srcGreens[i] = (byte)rgb.green;
+ srcBlues[i] = (byte)rgb.blue;
+ }
+ }
+ byte[] destReds = null, destGreens = null, destBlues = null;
+ int destRedMask = 0, destGreenMask = 0, destBlueMask = 0;
+ if (screenDepth <= 8) {
+ if (xcolors == null) return SWT.ERROR_UNSUPPORTED_DEPTH;
+ destReds = new byte[xcolors.length];
+ destGreens = new byte[xcolors.length];
+ destBlues = new byte[xcolors.length];
+ for (int i = 0; i < xcolors.length; i++) {
+ XColor color = xcolors[i];
+ if (color == null) continue;
+ destReds[i] = (byte)((color.red >> 8) & 0xFF);
+ destGreens[i] = (byte)((color.green >> 8) & 0xFF);
+ destBlues[i] = (byte)((color.blue >> 8) & 0xFF);
+ }
+ } else {
+ Visual xVisual = new Visual();
+ OS.memmove(xVisual, visual, Visual.sizeof);
+ destRedMask = xVisual.red_mask;
+ destGreenMask = xVisual.green_mask;
+ destBlueMask = xVisual.blue_mask;
+ }
+ if (transparentPixel != null) {
+ RGB rgb = image.palette.getRGB(transparentPixel[0]);
+ transparentPixel[0] = ImageData.closestMatch(screenDepth, (byte)rgb.red, (byte)rgb.green, (byte)rgb.blue,
+ destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
+ }
+
+ /* Depth 1 */
+ if (image.depth == 1) {
+ int bplX = ((destWidth + 7) / 8 + 3) & 0xFFFC;
+ int bufSize = bplX * destHeight;
+ byte[] buf = new byte[bufSize];
+ int bufPtr = OS.XtMalloc(bufSize);
+ int xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
+ if (xImagePtr == 0) {
+ OS.XtFree(bufPtr);
+ return SWT.ERROR_NO_HANDLES;
+ }
+ int foreground = 0, background = 0;
+ if (srcReds.length > 1) {
+ foreground = ImageData.closestMatch(screenDepth, srcReds[1], srcGreens[1], srcBlues[1],
+ destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
+ }
+ if (srcReds.length > 0) {
+ background = ImageData.closestMatch(screenDepth, srcReds[0], srcGreens[0], srcBlues[0],
+ destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
+ }
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ xImage.byte_order = OS.MSBFirst;
+ xImage.bitmap_unit = 8;
+ xImage.bitmap_bit_order = OS.MSBFirst;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ int destOrder = ImageData.MSB_FIRST;
+ ImageData.stretch1(image.data, image.bytesPerLine, ImageData.MSB_FIRST, srcX, srcY, srcWidth, srcHeight,
+ buf, bplX, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, flipX, flipY);
+ OS.memmove(xImage.data, buf, bufSize);
+ XGCValues values = new XGCValues();
+ OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground(display, gc, foreground);
+ OS.XSetBackground(display, gc, background);
+ OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
+ OS.XSetForeground(display, gc, values.foreground);
+ OS.XSetBackground(display, gc, values.background);
+ OS.XDestroyImage(xImagePtr);
+ return 0;
+ }
+
+ /* Depths other than 1 */
+ int xImagePtr = OS.XCreateImage(display, visual, screenDepth, OS.ZPixmap, 0, 0, destWidth, destHeight, 32, 0);
+ if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES;
+ XImage xImage = new XImage();
+ OS.memmove(xImage, xImagePtr, XImage.sizeof);
+ int bufSize = xImage.bytes_per_line * destHeight;
+ byte[] buf = new byte[bufSize];
+ int bufPtr = OS.XtMalloc(bufSize);
+ xImage.data = bufPtr;
+ OS.memmove(xImagePtr, xImage, XImage.sizeof);
+ int srcOrder = image.depth == 16 ? ImageData.LSB_FIRST : ImageData.MSB_FIRST;
+ int destOrder = xImage.byte_order == OS.MSBFirst ? ImageData.MSB_FIRST : ImageData.LSB_FIRST;
+ if (image.depth > 8 && screenDepth > 8) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, -1, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
+ flipX, flipY);
+ } else if (image.depth <= 8 && screenDepth > 8) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, -1, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
+ flipX, flipY);
+ } else if (image.depth > 8 && screenDepth <= 8) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, -1, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
+ flipX, flipY);
+ } else if (image.depth <= 8 && screenDepth <= 8) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, -1, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
+ flipX, flipY);
+ }
+ OS.memmove(xImage.data, buf, bufSize);
+ OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
+ OS.XDestroyImage(xImagePtr);
+ return 0;
+}
+public void setBackground(Color color) {
+ if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (transparentPixel == -1) return;
+ /* Generate the mask if necessary. */
+ if (mask == 0) createMask();
+ Rectangle bounds = getBounds();
+ int[] unused = new int[1];
+ int[] depth = new int[1];
+ int xDisplay = device.xDisplay;
+ OS.XGetGeometry(xDisplay, pixmap, unused, unused, unused, unused, unused, unused, depth);
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int tempPixmap = OS.XCreatePixmap(xDisplay, drawable, bounds.width, bounds.height, depth[0]);
+ int xGC = OS.XCreateGC(xDisplay, tempPixmap, 0, null);
+ OS.XSetForeground(xDisplay, xGC, color.handle.pixel);
+ OS.XFillRectangle(xDisplay, tempPixmap, xGC, 0, 0, bounds.width, bounds.height);
+ OS.XSetClipMask(xDisplay, xGC, mask);
+ OS.XCopyArea(xDisplay, pixmap, tempPixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
+ OS.XSetClipMask(xDisplay, xGC, OS.None);
+ OS.XCopyArea(xDisplay, tempPixmap, pixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
+ OS.XFreePixmap(xDisplay, tempPixmap);
+ OS.XFreeGC(xDisplay, xGC);
+ /* Destroy the receiver's mask if the there is a GC created on it */
+ if (memGC != null) destroyMask();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java
new file mode 100755
index 0000000000..9558cca0cc
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java
@@ -0,0 +1,79 @@
+package org.eclipse.swt.graphics;
+
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Region {
+ /**
+ * The handle to the OS region resource.
+ * Warning: This field is platform dependent.
+ */
+ public int handle;
+public Region () {
+ handle = OS.XCreateRegion ();
+}
+Region (int handle) {
+ this.handle = handle;
+}
+public void add (Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ XRectangle xRect = new XRectangle();
+ xRect.x = (short)rect.x;
+ xRect.y = (short)rect.y;
+ xRect.width = (short)rect.width;
+ xRect.height = (short)rect.height;
+ OS.XUnionRectWithRegion(xRect, handle, handle);
+}
+public void add (Region region) {
+ if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ OS.XUnionRegion(handle, region.handle, handle);
+}
+public boolean contains (int x, int y) {
+ return OS.XPointInRegion(handle, x, y);
+}
+public boolean contains (Point pt) {
+ if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return contains(pt.x, pt.y);
+}
+public void dispose () {
+ if (handle != 0) OS.XDestroyRegion(handle);
+ handle = 0;
+}
+public boolean equals (Object object) {
+ if (this == object) return true;
+ if (!(object instanceof Region)) return false;
+ int xRegion = ((Region)object).handle;
+ if (handle == xRegion) return true;
+ if (xRegion == 0) return false;
+ return OS.XEqualRegion(handle, xRegion);
+}
+public Rectangle getBounds() {
+ XRectangle rect = new XRectangle();
+ OS.XClipBox(handle, rect);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+}
+public int hashCode () {
+ return handle;
+}
+public boolean intersects (int x, int y, int width, int height) {
+ return OS.XRectInRegion (handle, x, y, width, height) != OS.RectangleOut;
+}
+public boolean intersects (Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return intersects(rect.x, rect.y, rect.width, rect.height);
+}
+public boolean isDisposed() {
+ return handle == 0;
+}
+public boolean isEmpty () {
+ return OS.XEmptyRegion(handle);
+}
+public static Region motif_new(int handle) {
+ return new Region(handle);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java
new file mode 100755
index 0000000000..682f69081f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java
@@ -0,0 +1,71 @@
+package org.eclipse.swt.internal;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public final class Converter {
+ public static final byte [] NullByteArray = new byte [1];
+ public static final char [] NullCharArray = new char [1];
+ public static final byte [] EmptyByteArray = new byte [0];
+ public static final char [] EmptyCharArray = new char [0];
+public static String defaultCodePage () {
+ /*
+ | ptr cp |
+ DefaultCodePage == nil ifFalse: [^DefaultCodePage].
+ cp := ''. "$NON-NLS$"
+ (ptr := OSStringZ address: (NlLanginfo callWith: 49)) isNull
+ ifFalse: [cp := String copyFromOSMemory: ptr].
+ cp isEmpty ifFalse: [
+ IsSunOS ifTrue: [
+ (cp size > 3 and: [(cp copyFrom: 1 to: 3) = 'ISO'])
+ ifTrue: [cp := cp copyFrom: 4 to: cp size]].
+ ^DefaultCodePage := cp].
+ IsAIX ifTrue: [^DefaultCodePage := 'ISO8859-1'].
+ IsSunOS ifTrue: [^DefaultCodePage := '8859-1'].
+ ^DefaultCodePage := 'iso8859_1'
+ */
+ return null;
+}
+static boolean is7BitAscii (byte [] buffer) {
+ for (int i=0; i<buffer.length; i++) {
+ if ((buffer [i] & 0xFF) > 0x7F) return false;
+ }
+ return true;
+}
+static boolean is7BitAscii (char [] buffer) {
+ for (int i=0; i<buffer.length; i++) {
+ if (buffer [i] > 0x7F) return false;
+ }
+ return true;
+}
+public static char [] mbcsToWcs (String codePage, byte [] buffer) {
+ //SLOW AND BOGUS
+ return new String (buffer).toCharArray ();
+}
+/* TEMPORARY CODE */
+public static byte [] wcsToMbcs (String codePage, String string) {
+ return wcsToMbcs (codePage, string, false);
+}
+public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
+ //SLOW AND BOGUS
+ int count = string.length ();
+ if (terminate) count++;
+ char [] buffer = new char [count];
+ string.getChars (0, string.length (), buffer, 0);
+ return wcsToMbcs (codePage, buffer, false);
+}
+/* TEMPORARY CODE */
+public static byte [] wcsToMbcs (String codePage, char [] buffer) {
+ return wcsToMbcs (codePage, buffer, false);
+}
+public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
+ //SLOW AND BOGUS
+ if (!terminate) return new String (buffer).getBytes ();
+ byte [] buffer1 = new String (buffer).getBytes ();
+ byte [] buffer2 = new byte [buffer1.length + 1];
+ System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
+ return buffer2;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/GNOME.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/GNOME.java
new file mode 100755
index 0000000000..fe586144f2
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/GNOME.java
@@ -0,0 +1,18 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class GNOME extends OS {
+
+public static final native int g_get_home_dir();
+public static final native int gnome_datadir_file(byte[] fileName);
+public static final native void gnome_desktop_entry_free(int entry);
+public static final native int gnome_desktop_entry_load(byte[] fileName);
+public static final native int gnome_mime_get_value(byte[] mimeType, byte[] key);
+public static final native int gnome_mime_type(byte[] fileName);
+public static final native int gnome_pixmap_file(byte[] fileName);
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java
new file mode 100755
index 0000000000..af9a2fb618
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java
@@ -0,0 +1,54 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class KDE extends OS {
+
+public static final int KICON_SMALL = 0;
+
+public static final native int KApplication_new(int qcString);
+
+public static final native int KGlobal_iconLoader();
+
+public static final native int KIconLoader_iconPath(int receiver, int iconQString, int iconType, int canReturnNull);
+
+public static final native int KMimeType_findByURL(int kurl);
+public static final native int KMimeType_icon(int receiver, int unused1, int unused2);
+public static final native int KMimeType_name(int receiver);
+
+public static final native int KService_allServices();
+public static final native int KService_exec(int receiver);
+public static final native int KService_icon(int receiver);
+public static final native int KService_name(int receiver);
+public static final native int KService_serviceByName(int serviceName);
+public static final native int KService_type(int receiver);
+
+public static final native int KServiceTypeProfile_preferredService(int mimeTypeQString, int needApp);
+
+public static final native void KURL_delete(int receiver);
+
+public static final native int KURL_new(int qString);
+
+public static final native int KServiceList_begin(int receiver);
+public static final native int KServiceList_delete(int receiver);
+public static final native int KServiceList_end(int receiver);
+
+public static final native int QCString_data(int receiver);
+public static final native int QCString_delete(int receiver);
+public static final native int QCString_new(byte[] string);
+
+public static final native int QString_delete(int receiver);
+public static final native int QString_equals(int receiver, int object);
+public static final native int QString_new(byte[] string);
+public static final native int QString_utf8(int receiver);
+
+public static final native int KServiceListIterator_delete(int receiver);
+public static final native int KServiceListIterator_dereference(int receiver);
+public static final native void KServiceListIterator_increment(int receiver);
+public static final native int KServiceListIterator_new(int listBeginning);
+public static final native int KServiceListIterator_equals(int receiver, int object);
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java
new file mode 100755
index 0000000000..0aab013563
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java
@@ -0,0 +1,1250 @@
+package org.eclipse.swt.internal.motif;
+
+import org.eclipse.swt.internal.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class OS {
+
+ /* Load the SWT library. */
+ static {
+ Callback.loadLibrary ();
+ }
+
+ /* X/Xt/Xm Constants */
+ public static final byte [] XmFONTLIST_DEFAULT_TAG = {0x46, 0x4F, 0x4E, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x5F, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4C, 0x54, 0x5F, 0x54, 0x41, 0x47, 0x5F, 0x53, 0x54, 0x52, 0x49, 0x4E, 0x47, 0x0};
+ public static final int Above = 0;
+ public static final int AllPlanes = 0xFFFFFFFF;
+ public static final int AlreadyGrabbed = 1;
+// public static final int ArcChord = 0x0;
+// public static final int ArcPieSlice = 0x1;
+ public static final int Below = 1;
+// public static final int BottomIf = 3;
+ public static final int Button1Mask = (1<<8);
+// public static final int Button1MotionMask = 1 << 8;
+ public static final int Button2Mask = (1<<9);
+// public static final int Button2MotionMask = 1 << 9;
+ public static final int Button3Mask = (1<<10);
+// public static final int Button3MotionMask = 1 << 10;
+// public static final int Button4Mask = (1<<11);
+// public static final int Button4MotionMask = 1 << 11;
+// public static final int Button5Mask = (1<<12);
+// public static final int Button5MotionMask = 1 << 12;
+// public static final int ButtonMotionMask = 1 << 13;
+ public static final int ButtonPress = 4;
+ public static final int ButtonPressMask = 1 << 2;
+ public static final int ButtonRelease = 5;
+ public static final int ButtonReleaseMask = 1 << 3;
+ public static final int CapButt = 0x1;
+// public static final int CapNotLast = 0x0;
+// public static final int CapProjecting = 0x3;
+// public static final int CapRound = 0x2;
+// public static final int CenterGravity = 5;
+// public static final int CirculateNotify = 26;
+// public static final int CirculateRequest = 27;
+// public static final int ClientMessage = 33;
+// public static final int ClipByChildren = 0x0;
+// public static final int ColormapChangeMask = 1 << 23;
+// public static final int ColormapNotify = 32;
+// public static final int Complex = 0;
+ public static final int ConfigureNotify = 22;
+// public static final int ConfigureRequest = 23;
+ public static final int ControlMask = (1<<2);
+ public static final int Convex = 2;
+ public static final int CoordModeOrigin = 0x0;
+// public static final int CoordModePrevious = 0x1;
+// public static final int CreateNotify = 16;
+ public static final int CurrentTime = 0;
+// public static final int CWBackingPixel = 0x100;
+// public static final int CWBackingPlanes = 0x80;
+// public static final int CWBackingStore = 0x40;
+// public static final int CWBackPixel = 0x2;
+ public static final int CWBackPixmap = 0x1;
+ public static final int CWBitGravity = 0x10;
+// public static final int CWBorderPixel = 0x8;
+// public static final int CWBorderPixmap = 0x4;
+// public static final int CWBorderWidth = 0x10;
+// public static final int CWColormap = 0x2000;
+// public static final int CWCursor = 0x4000;
+ public static final int CWDontPropagate = 0x1000;
+ public static final int CWEventMask = 0x800;
+ public static final int CWHeight = 0x8;
+// public static final int CWOverrideRedirect = 0x200;
+// public static final int CWSaveUnder = 0x400;
+ public static final int CWSibling = 0x20;
+ public static final int CWStackMode = 0x40;
+ public static final int CWWidth = 0x4;
+// public static final int CWWinGravity = 0x20;
+// public static final int CWX = 0x1;
+// public static final int CWY = 0x2;
+// public static final int DestroyNotify = 17;
+// public static final int EastGravity = 6;
+// public static final int EnterNotify = 7;
+ public static final int EnterWindowMask = 1 << 4;
+// public static final int EvenOddRule = 0x0;
+ public static final int Expose = 12;
+ public static final int ExposureMask = 1 << 15;
+// public static final int FillOpaqueStippled = 0x3;
+// public static final int FillSolid = 0x0;
+ public static final int FillStippled = 0x2;
+// public static final int FillTiled = 0x1;
+ public static final int FocusChangeMask = 1 << 21;
+ public static final int FocusIn = 9;
+ public static final int FocusOut = 10;
+ public static final int ForgetGravity = 0;
+// public static final int GCArcMode = 0x400000;
+ public static final int GCBackground = 0x8;
+// public static final int GCCapStyle = 0x40;
+// public static final int GCClipMask = 0x80000;
+// public static final int GCClipXOrigin = 0x20000;
+// public static final int GCClipYOrigin = 0x40000;
+// public static final int GCDashList = 0x200000;
+// public static final int GCDashOffset = 0x100000;
+// public static final int GCFillRule = 0x200;
+// public static final int GCFillStyle = 0x100;
+// public static final int GCFont = 0x4000;
+ public static final int GCForeground = 0x4;
+ public static final int GCFunction = 0x1;
+// public static final int GCGraphicsExposures = 0x10000;
+// public static final int GCJoinStyle = 0x80;
+// public static final int GCLastBit = 0x16;
+// public static final int GCLineStyle = 0x20;
+ public static final int GCLineWidth = 0x10;
+// public static final int GCPlaneMask = 0x2;
+// public static final int GCStipple = 0x800;
+ public static final int GCSubwindowMode = 0x8000;
+// public static final int GCTile = 0x400;
+// public static final int GCTileStipXOrigin = 0x1000;
+// public static final int GCTileStipYOrigin = 0x2000;
+// public static final int GrabFrozen = 4;
+// public static final int GrabInvalidTime = 2;
+ public static final int GrabModeAsync = 1;
+// public static final int GrabModeSync = 0;
+// public static final int GrabNotViewable = 3;
+// public static final int GrabSuccess = 0;
+ public static final int GraphicsExpose = 13;
+// public static final int GravityNotify = 24;
+ public static final int GXand = 0x1;
+// public static final int GXandInverted = 0x4;
+// public static final int GXandReverse = 0x2;
+// public static final int GXclear = 0x0;
+ public static final int GXcopy = 0x3;
+// public static final int GXcopy = 0x3;
+// public static final int GXcopyInverted = 0xC;
+// public static final int GXequiv = 0x9;
+// public static final int GXinvert = 0xA;
+// public static final int GXnand = 0xE;
+// public static final int GXnoop = 0x5;
+// public static final int GXnor = 0x8;
+ public static final int GXor = 0x7;
+// public static final int GXorInverted = 0xD;
+// public static final int GXorReverse = 0xB;
+// public static final int GXset = 0xF;
+ public static final int GXxor = 0x6;
+ public static final int IncludeInferiors = 0x1;
+// public static final int IsUnmapped = 0x0;
+ public static final int IsUnviewable = 0x1;
+ public static final int IsViewable = 0x2;
+// public static final int JoinBevel = 0x2;
+ public static final int JoinMiter = 0x0;
+// public static final int JoinRound = 0x1;
+// public static final int KeymapNotify = 11;
+// public static final int KeymapStateMask = 1 << 14;
+ public static final int KeyPress = 2;
+ public static final int KeyPressMask = 1 << 0;
+// public static final int KeyRelease = 3;
+ public static final int KeyReleaseMask = 1 << 1;
+// public static final int LeaveNotify = 8;
+ public static final int LeaveWindowMask = 1 << 5;
+ public static final int LineDoubleDash = 0x2;
+// public static final int LineOnOffDash = 0x1;
+ public static final int LineSolid = 0x0;
+// public static final int LockMask = (1<<1);
+ public static final int LSBFirst = 0;
+ public static final int MapNotify = 19;
+// public static final int MappingNotify = 34;
+// public static final int MapRequest = 20;
+ public static final int Mod1Mask = (1<<3);
+// public static final int Mod2Mask = (1<<4);
+// public static final int Mod3Mask = (1<<5);
+// public static final int Mod4Mask = (1<<6);
+// public static final int Mod5Mask = (1<<7);
+ public static final int MotionNotify = 6;
+ public static final int MSBFirst = 1;
+// public static final int MWM_DECOR_ALL = 0x1;
+ public static final int MWM_DECOR_BORDER = 0x2;
+ public static final int MWM_DECOR_MAXIMIZE = 0x40;
+ public static final int MWM_DECOR_MENU = 0x10;
+ public static final int MWM_DECOR_MINIMIZE = 0x20;
+ public static final int MWM_DECOR_RESIZEH = 0x4;
+ public static final int MWM_DECOR_TITLE = 0x8;
+// public static final int MWM_FUNC_ALL = 0x1;
+// public static final int MWM_FUNC_CLOSE = 0x20;
+// public static final int MWM_FUNC_MAXIMIZE = 0x10;
+// public static final int MWM_FUNC_MINIMIZE = 0x8;
+// public static final int MWM_FUNC_MOVE = 0x4;
+// public static final int MWM_FUNC_RESIZE = 0x2;
+// public static final int MWM_HINTS_DECORATIONS = 0x2;
+// public static final int MWM_HINTS_FUNCTIONS = 0x1;
+// public static final int MWM_HINTS_INPUT_MODE = 0x4;
+// public static final int MWM_HINTS_STATUS = 0x8;
+// public static final int MWM_INFO_STARTUP_CUSTOM = 0x2;
+// public static final int MWM_INFO_STARTUP_STANDARD = 0x1;
+ public static final int MWM_INPUT_FULL_APPLICATION_MODAL = 0x3;
+ public static final int MWM_INPUT_MODELESS = 0x0;
+ public static final int MWM_INPUT_PRIMARY_APPLICATION_MODAL = 0x1;
+ public static final int MWM_INPUT_SYSTEM_MODAL = 0x2;
+// public static final int MWM_TEAR_OFF_WINDOW = 0x1;
+// public static final int NoEventMask = 0;
+// public static final int NoExpose = 14;
+// public static final int Nonconvex = 1;
+ public static final int None = 0;
+// public static final int NorthEastGravity = 3;
+// public static final int NorthGravity = 2;
+ public static final int NorthWestGravity = 1;
+// public static final int NorthWestGravity = 1;
+ public static final int NotifyAncestor = 0x0;
+// public static final int NotifyDetailNone = 0x7;
+// public static final int NotifyGrab = 0x1;
+// public static final int NotifyHint = 0x1;
+ public static final int NotifyInferior = 0x2;
+ public static final int NotifyNonlinear = 0x3;
+// public static final int NotifyNonlinearVirtual = 0x4;
+ public static final int NotifyNormal = 0x0;
+// public static final int NotifyPointer = 0x5;
+// public static final int NotifyPointerRoot = 0x6;
+// public static final int NotifyUngrab = 0x2;
+// public static final int NotifyVirtual = 0x1;
+// public static final int NotifyWhileGrabbed = 0x3;
+// public static final int Opposite = 4;
+// public static final int OwnerGrabButtonMask = 1 << 24;
+// public static final int PointerMotionHintMask = 1 << 7;
+ public static final int PointerMotionMask = 1 << 6;
+// public static final int PropertyChangeMask = 1 << 22;
+// public static final int PropertyNotify = 28;
+// public static final int RectangleIn = 0x1;
+ public static final int RectangleOut = 0x0;
+// public static final int RectanglePart = 0x2;
+ public static final int ReparentNotify = 21;
+ public static final int ResizeRedirectMask = 1 << 18;
+// public static final int ResizeRequest = 25;
+// public static final int RevertToNone = 0x0;
+ public static final int RevertToParent = 0x2;
+// public static final int RevertToPointerRoot = 0x1;
+// public static final int SelectionClear = 29;
+// public static final int SelectionNotify = 31;
+// public static final int SelectionRequest = 30;
+ public static final int ShiftMask = (1<<0);
+// public static final int SouthEastGravity = 9;
+// public static final int SouthGravity = 8;
+// public static final int SouthWestGravity = 7;
+// public static final int StaticGravity = 10;
+ public static final int StructureNotifyMask = 1 << 17;
+ public static final int SubstructureNotifyMask = 1 << 19;
+ public static final int SubstructureRedirectMask = 1 << 20;
+// public static final int TopIf = 2;
+ public static final int UnmapNotify = 18;
+ public static final int Unsorted = 0x0;
+// public static final int VisibilityChangeMask = 1 << 16;
+// public static final int VisibilityNotify = 15;
+// public static final int WestGravity = 4;
+// public static final int WindingRule = 0x1;
+ public static final int XA_FONT = 18;
+ public static final int XBufferOverflow = 0xFFFFFFFF;
+// public static final int XC_arrow = 2;
+// public static final int XC_based_arrow_down = 4;
+// public static final int XC_based_arrow_up = 6;
+// public static final int XC_boat = 8;
+// public static final int XC_bogosity= 10;
+ public static final int XC_bottom_left_corner = 12;
+ public static final int XC_bottom_right_corner = 14;
+ public static final int XC_bottom_side = 16;
+// public static final int XC_bottom_tee = 18;
+// public static final int XC_box_spiral = 20;
+// public static final int XC_center_ptr = 22;
+// public static final int XC_circle = 24;
+// public static final int XC_clock = 26;
+// public static final int XC_coffee_mug = 28;
+ public static final int XC_cross = 30;
+// public static final int XC_cross_reverse = 32;
+// public static final int XC_crosshair = 34;
+ public static final int XC_diamond_cross = 36;
+// public static final int XC_dot = 38;
+// public static final int XC_dotbox = 40;
+ public static final int XC_double_arrow = 42;
+// public static final int XC_draft_large = 44;
+// public static final int XC_draft_small = 46;
+// public static final int XC_draped_box = 48;
+// public static final int XC_exchange = 50;
+// public static final int XC_fleur = 52;
+// public static final int XC_gobbler = 54;
+// public static final int XC_gumby = 56;
+// public static final int XC_hand1 = 58;
+ public static final int XC_hand2 = 60;
+// public static final int XC_heart = 62;
+// public static final int XC_icon = 64;
+// public static final int XC_iron_cross = 66;
+ public static final int XC_left_ptr = 68;
+ public static final int XC_left_side = 70;
+// public static final int XC_left_tee = 72;
+// public static final int XC_leftbutton = 74;
+// public static final int XC_ll_angle = 76;
+// public static final int XC_lr_angle = 78;
+// public static final int XC_man = 80;
+// public static final int XC_middlebutton = 82;
+// public static final int XC_mouse = 84;
+// public static final int XC_num_glyphs = 154;
+// public static final int XC_pencil = 86;
+// public static final int XC_pirate = 88;
+// public static final int XC_plus = 90;
+ public static final int XC_question_arrow = 92;
+// public static final int XC_right_ptr = 94;
+ public static final int XC_right_side = 96;
+// public static final int XC_right_tee = 98;
+// public static final int XC_rightbutton = 100;
+// public static final int XC_rtl_logo = 102;
+// public static final int XC_sailboat = 104;
+// public static final int XC_sb_down_arrow = 106;
+ public static final int XC_sb_h_double_arrow = 108;
+// public static final int XC_sb_left_arrow = 110;
+// public static final int XC_sb_right_arrow = 112;
+ public static final int XC_sb_up_arrow = 114;
+ public static final int XC_sb_v_double_arrow = 116;
+// public static final int XC_shuttle = 118;
+ public static final int XC_sizing = 120;
+// public static final int XC_spider = 122;
+// public static final int XC_spraycan = 124;
+// public static final int XC_star = 126;
+// public static final int XC_target = 128;
+// public static final int XC_tcross = 130;
+// public static final int XC_top_left_arrow = 132;
+ public static final int XC_top_left_corner = 134;
+ public static final int XC_top_right_corner = 136;
+ public static final int XC_top_side = 138;
+// public static final int XC_top_tee = 140;
+// public static final int XC_trek = 142;
+// public static final int XC_ul_angle = 144;
+// public static final int XC_umbrella = 146;
+// public static final int XC_ur_angle = 148;
+ public static final int XC_watch = 150;
+ public static final int XC_X_cursor = 0;
+ public static final int XC_xterm = 152;
+ public static final int XK_Alt_L = 0xFFE9;
+ public static final int XK_Alt_R = 0xFFEA;
+ public static final int XK_Cancel = 0xFF69;
+ public static final int XK_Control_L = 0xFFE3;
+ public static final int XK_Control_R = 0xFFE4;
+// public static final int XK_Delete = 0xFFFF;
+ public static final int XK_Down = 0xFF54;
+ public static final int XK_End = 0xFF57;
+ public static final int XK_Escape = 0xFF1B;
+ public static final int XK_F1 = 0xFFBE;
+ public static final int XK_F10 = 0xFFC7;
+ public static final int XK_F11 = 0xFFC8;
+ public static final int XK_F12 = 0xFFC9;
+ public static final int XK_F2 = 0xFFBF;
+ public static final int XK_F3 = 0xFFC0;
+ public static final int XK_F4 = 0xFFC1;
+ public static final int XK_F5 = 0xFFC2;
+ public static final int XK_F6 = 0xFFC3;
+ public static final int XK_F7 = 0xFFC4;
+ public static final int XK_F8 = 0xFFC5;
+ public static final int XK_F9 = 0xFFC6;
+ public static final int XK_Home = 0xFF50;
+ public static final int XK_Insert = 0xFF63;
+// public static final int XK_KP_0 = 0xFFB0;
+// public static final int XK_KP_1 = 0xFFB1;
+// public static final int XK_KP_2 = 0xFFB2;
+// public static final int XK_KP_3 = 0xFFB3;
+// public static final int XK_KP_4 = 0xFFB4;
+// public static final int XK_KP_5 = 0xFFB5;
+// public static final int XK_KP_6 = 0xFFB6;
+// public static final int XK_KP_7 = 0xFFB7;
+// public static final int XK_KP_8 = 0xFFB8;
+// public static final int XK_KP_9 = 0xFFB9;
+// public static final int XK_KP_Add = 0xFFAB;
+// public static final int XK_KP_Decimal = 0xFFAE;
+// public static final int XK_KP_Divide = 0xFFAF;
+// public static final int XK_KP_Enter = 0xFF8D;
+// public static final int XK_KP_Multiply = 0xFFAA;
+// public static final int XK_KP_Subtract = 0xFFAD;
+ public static final int XK_Left = 0xFF51;
+ public static final int XK_Page_Down = 0xFF56;
+ public static final int XK_Page_Up = 0xFF55;
+ public static final int XK_Right = 0xFF53;
+ public static final int XK_Return = 0xFF0D;
+ public static final int XK_Shift_L = 0xFFE1;
+ public static final int XK_Shift_R = 0xFFE2;
+ public static final int XK_Tab = 0xFF09;
+ public static final int XK_Up = 0xFF52;
+// public static final int XLookupBoth = 0x4;
+// public static final int XLookupChars = 0x2;
+// public static final int XLookupKeySym = 0x3;
+// public static final int XLookupNone = 0x1;
+ public static final int XmALIGNMENT_BEGINNING = 0x0;
+ public static final int XmALIGNMENT_CENTER = 0x1;
+ public static final int XmALIGNMENT_END = 0x2;
+ public static final int XmARROW_DOWN = 0x1;
+ public static final int XmARROW_LEFT = 0x2;
+ public static final int XmARROW_RIGHT = 0x3;
+ public static final int XmARROW_UP = 0x0;
+// public static final int XmARROWS_END = 0x0;
+// public static final int XmAS_NEEDED = 0x1;
+// public static final int XmATTACH_CENTER = 0x8;
+// public static final int XmATTACH_EAST = 0x3;
+ public static final int XmATTACH_FORM = 0x1;
+// public static final int XmATTACH_HOT = 0x9;
+// public static final int XmATTACH_NONE = 0x0;
+// public static final int XmATTACH_NORTH = 0x1;
+// public static final int XmATTACH_NORTH_EAST = 0x2;
+// public static final int XmATTACH_NORTH_WEST = 0x0;
+// public static final int XmATTACH_OPPOSITE_FORM = 0x2;
+// public static final int XmATTACH_OPPOSITE_WIDGET = 0x4;
+// public static final int XmATTACH_POSITION = 0x5;
+// public static final int XmATTACH_SELF = 0x6;
+// public static final int XmATTACH_SOUTH = 0x5;
+// public static final int XmATTACH_SOUTH_EAST = 0x4;
+// public static final int XmATTACH_SOUTH_WEST = 0x6;
+// public static final int XmATTACH_WEST = 0x7;
+// public static final int XmATTACH_WIDGET = 0x3;
+ public static final int XmBLEND_ALL = 0x0;
+ public static final int XmBROWSE_SELECT = 0x3;
+ public static final int XmCHARSET_TEXT = 0x0;
+ public static final int XmClipboardFail = 0x0;
+ public static final int XmClipboardSuccess = 0x1;
+ public static final int XmClipboardLocked = 0x4;
+ public static final int XmClipboardNoData = 0x6;
+ public static final int XmCOMBO_BOX = 0x0;
+ public static final int XmCONSTANT = 0x1;
+ public static final int XmCOPY_FAILED = 0x0;
+// public static final int XmCOPY_SUCCEEDED = 0x1;
+ public static final int XmCOPY_TRUNCATED = 0x2;
+// public static final int XmCR_ACTIVATE = 0xA;
+// public static final int XmCR_APPLY = 0x22;
+// public static final int XmCR_ARM = 0xB;
+// public static final int XmCR_BROWSE_SELECT = 0x1A;
+// public static final int XmCR_CANCEL = 0x20;
+// public static final int XmCR_CASCADING = 0x1E;
+// public static final int XmCR_CLIPBOARD_DATA_DELETE = 0x1D;
+// public static final int XmCR_CLIPBOARD_DATA_REQUEST = 0x1C;
+// public static final int XmCR_COMMAND_CHANGED = 0x25;
+// public static final int XmCR_COMMAND_ENTERED = 0x24;
+// public static final int XmCR_CREATE = 0x2B;
+ public static final int XmCR_DECREMENT = 0x4;
+// public static final int XmCR_DEFAULT_ACTION = 0x1B;
+// public static final int XmCR_DISARM = 0xC;
+ public static final int XmCR_DRAG = 0x9;
+// public static final int XmCR_DRAGDROP_FINISH = 0x7;
+// public static final int XmCR_DRAG_MOTION = 0x2;
+// public static final int XmCR_DROP_FINISH = 0x6;
+// public static final int XmCR_DROP_MESSAGE = 0x4;
+// public static final int XmCR_DROP_SITE_ENTER = 0x3;
+ public static final int XmCR_DROP_SITE_ENTER_MESSAGE = 0x2;
+// public static final int XmCR_DROP_SITE_LEAVE = 0x4;
+ public static final int XmCR_DROP_SITE_LEAVE_MESSAGE = 0x1;
+ public static final int XmCR_DROP_SITE_MOTION_MESSAGE = 0x3;
+// public static final int XmCR_DROP_START = 0x5;
+// public static final int XmCR_EXECUTE = 0x16;
+// public static final int XmCR_EXPOSE = 0x26;
+// public static final int XmCR_EXTENDED_SELECT = 0x19;
+// public static final int XmCR_FOCUS = 0x12;
+// public static final int XmCR_GAIN_PRIMARY = 0x29;
+// public static final int XmCR_HELP = 0x1;
+ public static final int XmCR_INCREMENT = 0x3;
+// public static final int XmCR_INPUT = 0x28;
+// public static final int XmCR_LOSE_PRIMARY = 0x2A;
+// public static final int XmCR_LOSING_FOCUS = 0x13;
+// public static final int XmCR_MAP = 0x10;
+// public static final int XmCR_MODIFYING_TEXT_VALUE = 0x14;
+// public static final int XmCR_MOVING_INSERT_CURSOR = 0x15;
+// public static final int XmCR_MULTIPLE_SELECT = 0x18;
+// public static final int XmCR_NO_MATCH = 0x23;
+// public static final int XmCR_NONE = 0x0;
+// public static final int XmCR_OBSCURED_TRAVERSAL = 0x2E;
+// public static final int XmCR_OK = 0x1F;
+ public static final int XmCR_OPERATION_CHANGED = 0x8;
+ public static final int XmCR_PAGE_DECREMENT = 0x6;
+ public static final int XmCR_PAGE_INCREMENT = 0x5;
+// public static final int XmCR_PROTOCOLS = 0x2F;
+// public static final int XmCR_RESIZE = 0x27;
+// public static final int XmCR_SINGLE_SELECT = 0x17;
+// public static final int XmCR_TEAR_OFF_ACTIVATE = 0x2C;
+// public static final int XmCR_TEAR_OFF_DEACTIVATE = 0x2D;
+ public static final int XmCR_TO_BOTTOM = 0x8;
+// public static final int XmCR_TOP_LEVEL_ENTER = 0x0;
+// public static final int XmCR_TOP_LEVEL_LEAVE = 0x1;
+ public static final int XmCR_TO_TOP = 0x7;
+// public static final int XmCR_UNMAP = 0x11;
+ public static final int XmCR_VALUE_CHANGED = 0x2;
+// public static final int XmCR_WMPROTOCOLS = 0x1A0A;
+// public static final int XmDESTROY = 0x0;
+ public static final int XmDIALOG_APPLICATION_MODAL = 0x1;
+ public static final int XmDIALOG_APPLY_BUTTON = 0x1;
+ public static final int XmDIALOG_CANCEL_BUTTON = 0x2;
+// public static final int XmDIALOG_COMMAND = 0x3;
+// public static final int XmDIALOG_COMMAND_TEXT = 0xD;
+// public static final int XmDIALOG_DEFAULT_BUTTON = 0x3;
+// public static final int XmDIALOG_DIR_LIST = 0xF;
+// public static final int XmDIALOG_DIR_LIST_LABEL = 0x10;
+// public static final int XmDIALOG_ERROR = 0x1;
+// public static final int XmDIALOG_FILE_LIST = 0x8;
+// public static final int XmDIALOG_FILE_LIST_LABEL = 0x9;
+// public static final int XmDIALOG_FILE_SELECTION = 0x4;
+ public static final int XmDIALOG_FILTER_LABEL = 0x5;
+ public static final int XmDIALOG_FILTER_TEXT = 0x6;
+ public static final int XmDIALOG_FULL_APPLICATION_MODAL = 0x2;
+ public static final int XmDIALOG_HELP_BUTTON = 0x7;
+// public static final int XmDIALOG_HISTORY_LIST = 0x8;
+// public static final int XmDIALOG_INFORMATION = 0x2;
+ public static final int XmDIALOG_LIST = 0x8;
+ public static final int XmDIALOG_LIST_LABEL = 0x9;
+// public static final int XmDIALOG_MESSAGE = 0x3;
+ public static final int XmDIALOG_MESSAGE_LABEL = 0xA;
+ public static final int XmDIALOG_MODELESS = 0x0;
+// public static final int XmDIALOG_NONE = 0x0;
+ public static final int XmDIALOG_OK_BUTTON = 0x4;
+ public static final int XmDIALOG_PRIMARY_APPLICATION_MODAL = 0x1;
+// public static final int XmDIALOG_PROMPT = 0x1;
+// public static final int XmDIALOG_PROMPT_LABEL = 0xB;
+// public static final int XmDIALOG_QUESTION = 0x4;
+// public static final int XmDIALOG_SELECTION = 0x2;
+ public static final int XmDIALOG_SELECTION_LABEL = 0xB;
+// public static final int XmDIALOG_SEPARATOR = 0xE;
+// public static final int XmDIALOG_SYMBOL_LABEL = 0xC;
+ public static final int XmDIALOG_SYSTEM_MODAL = 0x3;
+// public static final int XmDIALOG_TEMPLATE = 0x0;
+ public static final int XmDIALOG_TEXT = 0xD;
+// public static final int XmDIALOG_VALUE_TEXT = 0xD;
+// public static final int XmDIALOG_WARNING = 0x5;
+// public static final int XmDIALOG_WORK_AREA = 0x0;
+// public static final int XmDIALOG_WORKING = 0x6;
+ public static final int XmDO_NOTHING = 0x2;
+// public static final int XmDOUBLE_DASHED_LINE = 0x4;
+// public static final int XmDOUBLE_LINE = 0x2;
+ public static final int XmDRAG_DYNAMIC = 5;
+ public static final byte XmDROP_COPY = (1 << 1);
+ public static final int XmDROP_DOWN_COMBO_BOX = 0x1;
+ public static final int XmDROP_DOWN_LIST = 0x2;
+ public static final byte XmDROP_LINK = (1 << 2);
+ public static final byte XmDROP_MOVE = (1 << 0);
+ public static final byte XmDROP_NOOP = 0;
+ public static final int XmDROP_SITE_ACTIVE = 0;
+ public static final int XmDROP_SITE_INVALID = 2;
+ public static final int XmDROP_SITE_VALID = 3;
+ public static final byte XmDROP = 0;
+ public static final int XmEXTENDED_SELECT = 0x2;
+ public static final int XmFONT_IS_FONT = 0x0;
+ public static final int XmFONT_IS_FONTSET = 0x1;
+// public static final int XmFRAME_GENERIC_CHILD = 0x0;
+ public static final int XmFRAME_TITLE_CHILD = 0x2;
+// public static final int XmFRAME_WORKAREA_CHILD = 0x1;
+ public static final int XmHIGHLIGHT_NORMAL = 0x0;
+// public static final int XmHIGHLIGHT_SECONDARY_SELECTED = 0x2;
+// public static final int XmHIGHLIGHT_SELECTED = 0x1;
+ public static final int XmHORIZONTAL = 0x2;
+ public static final int XmLAST_POSITION = -1;
+ public static final int XmMAX_ON_BOTTOM = 0x1;
+// public static final int XmMAX_ON_LEFT = 0x2;
+ public static final int XmMAX_ON_RIGHT = 0x3;
+ public static final int XmMAX_ON_TOP = 0x0;
+ public static final int XmMERGE_REPLACE = 0x1;
+ public static final int XmMULTI_LINE_EDIT = 0x0;
+ public static final int XmMULTIPLE_SELECT = 0x1;
+ public static final int XmN_OF_MANY = 0x1;
+ public static final int XmNONE = 0x0;
+// public static final int XmNUMERIC = 0x3;
+
+ /* char */
+ public static final int XmNalignment = malloc ("alignment");
+ public static final int XmNarrowDirection = malloc ("arrowDirection");
+ public static final int XmNblendModel = malloc ("blendModel");
+ public static final int XmNbottomAttachment = malloc ("bottomAttachment");
+ public static final int XmNchildType = malloc ("childType");
+ public static final int XmNcomboBoxType = malloc ("comboBoxType");
+ public static final int XmNdialogStyle = malloc ("dialogStyle");
+ public static final int XmNcursorPositionVisible = malloc ("cursorPositionVisible");
+ public static final int XmNdeleteResponse = malloc ("deleteResponse");
+ public static final int XmNdragInitiatorProtocolStyle = malloc ("dragInitiatorProtocolStyle");
+ public static final int XmNdragReceiverProtocolStyle = malloc ("dragReceiverProtocolStyle");
+ public static final int XmNdragOperations = malloc ("dragOperations");
+ public static final int XmNeditable = malloc ("editable");
+ public static final int XmNiconic = malloc ("iconic");
+ public static final int XmNlabelType = malloc ("labelType");
+ public static final int XmNleftAttachment = malloc ("leftAttachment");
+ public static final int XmNlistSizePolicy = malloc ("listSizePolicy");
+ public static final int XmNindicatorOn = malloc ("indicatorOn");
+ public static final int XmNindicatorType = malloc ("indicatorType");
+ public static final int XmNnoResize = malloc ("noResize");
+ public static final int XmNorientation = malloc ("orientation");
+ public static final int XmNprocessingDirection = malloc ("processingDirection");
+ public static final int XmNrecomputeSize = malloc ("recomputeSize");
+ public static final int XmNpushButtonEnabled = malloc ("pushButtonEnabled");
+ public static final int XmNresizable = malloc ("resizable");
+ public static final int XmNresizePolicy = malloc ("resizePolicy");
+ public static final int XmNrightAttachment = malloc ("rightAttachment");
+ public static final int XmNscrollHorizontal = malloc ("scrollHorizontal");
+ public static final int XmNscrollVertical = malloc ("scrollVertical");
+ public static final int XmNselectionPolicy = malloc ("selectionPolicy");
+ public static final int XmNsensitive = malloc ("sensitive");
+ public static final int XmNseparatorType = malloc ("separatorType");
+ public static final int XmNset = malloc ("set");
+ public static final int XmNshadowType = malloc ("shadowType");
+ public static final int XmNtraversalOn = malloc ("traversalOn");
+ public static final int XmNtopAttachment = malloc ("topAttachment");
+ public static final int XmNverifyBell = malloc ("verifyBell");
+ public static final int XmNwordWrap = malloc ("wordWrap");
+ public static final int XmNnavigationType = malloc ("navigationType");
+
+ /* short */
+ public static final int XmNarrowSize = malloc ("arrowSize");
+ public static final int XmNarrowSpacing = malloc ("arrowSpacing");
+ public static final int XmNborderWidth = malloc ("borderWidth");
+ public static final int XmNheight = malloc ("height");
+ public static final int XmNhighlightThickness = malloc ("highlightThickness");
+ public static final int XmNlistMarginHeight = malloc ("listMarginHeight");
+ public static final int XmNlistMarginWidth = malloc ("listMarginWidth");
+ public static final int XmNlistSpacing = malloc ("listSpacing");
+ public static final int XmNmarginBottom = malloc ("marginBottom");
+ public static final int XmNmarginHeight = malloc ("marginHeight");
+ public static final int XmNmarginLeft = malloc ("marginLeft");
+ public static final int XmNmarginRight = malloc ("marginRight");
+ public static final int XmNmarginTop = malloc ("marginTop");
+ public static final int XmNmarginWidth = malloc ("marginWidth");
+ public static final int XmNpositionIndex = malloc ("positionIndex");
+ public static final int XmNrows = malloc ("rows");
+ public static final int XmNshadowThickness = malloc ("shadowThickness");
+ public static final int XmNshowAsDefault = malloc ("showAsDefault");
+ public static final int XmNwidth = malloc ("width");
+ public static final int XmNx = malloc ("x");
+ public static final int XmNy = malloc ("y");
+
+ /* int */
+ public static final int XmNaccelerator = malloc ("accelerator");
+ public static final int XmNacceleratorText = malloc ("acceleratorText");
+ public static final int XmNactivateCallback = malloc ("activateCallback");
+ public static final int XmNarmCallback = malloc ("armCallback");
+ public static final int XmNbackground = malloc ("background");
+ public static final int XmNborderColor = malloc ("borderColor");
+ public static final int XmNbottomShadowColor = malloc ("bottomShadowColor");
+ public static final int XmNbrowseSelectionCallback = malloc ("browseSelectionCallback");
+ public static final int XmNcancelCallback = malloc ("cancelCallback");
+ public static final int XmNcancelLabelString = malloc ("cancelLabelString");
+ public static final int XmNcascadingCallback = malloc ("cascadingCallback");
+ public static final int XmNchildren = malloc ("children");
+ public static final int XmNclientData = malloc ("clientData");
+ public static final int XmNcolormap = malloc ("colormap");
+ public static final int XmNconvertProc = malloc ("convertProc");
+ public static final int XmNdecrementCallback = malloc ("decrementCallback");
+ public static final int XmNdefaultActionCallback = malloc ("defaultActionCallback");
+ public static final int XmNdefaultButtonShadowThickness = malloc ("defaultButtonShadowThickness");
+ public static final int XmNdialogTitle = malloc ("dialogTitle");
+ public static final int XmNdirectory = malloc ("directory");
+ public static final int XmNdirSpec = malloc ("dirSpec");
+ public static final int XmNdirMask = malloc ("dirMask");
+ public static final int XmNdragCallback = malloc ("dragCallback");
+ public static final int XmNdragDropFinishCallback = malloc ("dragDropFinishCallback");
+ public static final int XmNdragProc = malloc ("dragProc");
+ public static final int XmNdropFinishCallback = malloc ("dropFinishCallback");
+ public static final int XmNdropProc = malloc("dropProc");
+ public static final int XmNeditMode = malloc ("editMode");
+ public static final int XmNexportTargets = malloc ("exportTargets");
+ public static final int XmNexposeCallback = malloc ("exposeCallback");
+ public static final int XmNextendedSelectionCallback = malloc ("extendedSelectionCallback");
+ public static final int XmNfilterLabelString = malloc ("filterLabelString");
+ public static final int XmNfont = malloc ("font");
+ public static final int XmNfontList = malloc ("fontList");
+ public static final int XmNfontType = malloc ("fontType");
+ public static final int XmNforeground = malloc ("foreground");
+ public static final int XmNhelpCallback = malloc ("helpCallback");
+ public static final int XmNhelpLabelString = malloc ("helpLabelString");
+ public static final int XmNhighlightColor = malloc ("highlightColor");
+ public static final int XmNhorizontalScrollBar = malloc ("horizontalScrollBar");
+ public static final int XmNiconMask = malloc ("iconMask");
+ public static final int XmNiconPixmap = malloc ("iconPixmap");
+ public static final int XmNincrement = malloc ("increment");
+ public static final int XmNincrementCallback = malloc ("incrementCallback");
+ public static final int XmNitemCount = malloc ("itemCount");
+ public static final int XmNitems = malloc ("items");
+ public static final int XmNlabelInsensitivePixmap = malloc ("labelInsensitivePixmap");
+ public static final int XmNlabelPixmap = malloc ("labelPixmap");
+ public static final int XmNlabelString = malloc ("labelString");
+ public static final int XmNlist = malloc ("list");
+ public static final int XmNmapCallback = malloc ("mapCallback");
+ public static final int XmNmappedWhenManaged = malloc ("mappedWhenManaged");
+ public static final int XmNmaximum = malloc ("maximum");
+ public static final int XmNmenuBar = malloc ("menuBar");
+ public static final int XmNmessageString = malloc ("messageString");
+ public static final int XmNminimum = malloc ("minimum");
+ public static final int XmNmodifyVerifyCallback = malloc ("modifyVerifyCallback");
+ public static final int XmNmwmDecorations = malloc ("mwmDecorations");
+ public static final int XmNmwmInputMode = malloc ("mwmInputMode");
+ public static final int XmNnumChildren = malloc ("numChildren");
+ public static final int XmNnumDropTransfers = malloc ("numDropTransfers");
+ public static final int XmNnumExportTargets = malloc ("numExportTargets");
+ public static final int XmNnumImportTargets = malloc("numImportTargets");
+ public static final int XmNmnemonic = malloc ("mnemonic");
+ public static final int XmNimportTargets = malloc("importTargets");
+ public static final int XmNokCallback = malloc ("okCallback");
+ public static final int XmNokLabelString = malloc ("okLabelString");
+ public static final int XmNoperationCursorIcon = malloc ("operationCursorIcon");
+ public static final int XmNselectionCallback = malloc ("selectionCallback");
+ public static final int XmNsourceCursorIcon = malloc ("sourceCursorIcon");
+ public static final int XmNstateCursorIcon = malloc ("stateCursorIcon");
+ public static final int XmNsubstitute = malloc ("substitute");
+ public static final int XmNpageDecrementCallback = malloc ("pageDecrementCallback");
+ public static final int XmNpageIncrement = malloc ("pageIncrement");
+ public static final int XmNpageIncrementCallback = malloc ("pageIncrementCallback");
+ public static final int XmNpattern = malloc ("pattern");
+ public static final int XmNrenderTable = malloc ("renderTable");
+ public static final int XmNscaleMultiple = malloc ("scaleMultiple");
+ public static final int XmNselectedItemCount = malloc ("selectedItemCount");
+ public static final int XmNselectedItems = malloc ("selectedItems");
+ public static final int XmNselectedPosition = malloc ("selectedPosition");
+ public static final int XmNselectionArrayCount = malloc ("selectionArrayCount");
+ public static final int XmNsliderSize = malloc ("sliderSize");
+ public static final int XmNsubMenuId = malloc ("subMenuId");
+ public static final int XmNtabList = malloc ("tabList");
+ public static final int XmNtextField = malloc ("textField");
+ public static final int XmNtitle = malloc ("title");
+ public static final int XmNtitleString = malloc ("titleString");
+ public static final int XmNtoBottomCallback = malloc ("toBottomCallback");
+ public static final int XmNtoTopCallback = malloc ("toTopCallback");
+// public static final int XmNtopCharacter = malloc ("topCharacter");
+ public static final int XmNtopItemPosition = malloc ("topItemPosition");
+ public static final int XmNtopShadowColor = malloc ("topShadowColor");
+ public static final int XmNtransferProc = malloc ("transferProc");
+ public static final int XmNtransferStatus = malloc ("transferStatus");
+ public static final int XmNtroughColor = malloc ("troughColor");
+ public static final int XmNunmapCallback = malloc ("unmapCallback");
+ public static final int XmNuserData = malloc ("userData");
+ public static final int XmNvalue = malloc ("value");
+ public static final int XmNvalueChangedCallback = malloc ("valueChangedCallback");
+ public static final int XmNverticalScrollBar = malloc ("verticalScrollBar");
+ public static final int XmNvisibleItemCount = malloc ("visibleItemCount");
+ public static final int XmNdropTransfers = malloc ("dropTransfers");
+ public static final int XmNshowArrows = malloc ("showArrows");
+
+/* Unknown */
+ public static final int XmNdropSiteActivity = malloc("dropSiteActivity");
+ public static final int XmNdropSiteOperations = malloc("dropSiteOperations");
+ public static final int XmNdropSiteType = malloc("dropSiteType");
+
+ public static final int XmNO_LINE = 0x0;
+ public static final int XmONE_OF_MANY = 0x2;
+ public static final int XmOUTPUT_ALL = 0x0;
+ public static final int XmPIXELS = 0x0;
+ public static final int XmPIXMAP = 0x1;
+ public static final int XmRELATIVE = 0x1;
+// public static final int XmRESIZE_ANY = 0x2;
+// public static final int XmRESIZE_GROW = 0x1;
+// public static final int XmRESIZE_IF_POSSIBLE = 0x2;
+ public static final int XmRESIZE_NONE = 0x0;
+ public static final int XmSHADOW_ETCHED_IN = 0x5;
+// public static final int XmSHADOW_ETCHED_IN_DASH = 0x7;
+ public static final int XmSHADOW_ETCHED_OUT = 0x6;
+// public static final int XmSHADOW_ETCHED_OUT_DASH = 0x8;
+ public static final int XmSHADOW_IN = 0x7;
+ public static final int XmSHADOW_OUT = 0x8;
+// public static final int XmSINGLE_DASHED_LINE = 0x3;
+// public static final int XmSINGLE_LINE = 0x1;
+ public static final int XmSINGLE_LINE_EDIT = 0x1;
+// public static final int XmSINGLE_SELECT = 0x0;
+// public static final int XmSPIN_NEXT = 0x3E;
+// public static final int XmSPIN_PRIOR = 0x3F;
+// public static final int XmSTATIC = 0x0;
+ public static final int XmSTRING = 0x2;
+ public static final int XmSTRING_COMPONENT_SEPARATOR = 0x4;
+ public static final int XmSTRING_COMPONENT_TAB = 0xC;
+ public static final int XmTAB_GROUP = 0x1;
+ public static final int XmTRANSFER_FAILURE = 0;
+ public static final int XmTRAVERSE_CURRENT = 0x0;
+// public static final int XmTRAVERSE_DOWN = 0x7;
+// public static final int XmTRAVERSE_HOME = 0x3;
+// public static final int XmTRAVERSE_LEFT = 0x8;
+ public static final int XmTRAVERSE_NEXT = 0x1;
+ public static final int XmTRAVERSE_NEXT_TAB_GROUP = 0x4;
+ public static final int XmTRAVERSE_PREV = 0x2;
+ public static final int XmTRAVERSE_PREV_TAB_GROUP = 0x5;
+// public static final int XmTRAVERSE_RIGHT = 0x9;
+// public static final int XmTRAVERSE_UP = 0x6;
+// public static final int XmUNMAP = 0x1;
+ public static final int XmUNSPECIFIED_PIXMAP = 0x2;
+ public static final int XmVARIABLE = 0x0;
+ public static final int XmVERTICAL = 0x1;
+// public static final int XtCWQueryOnly = 128;
+// public static final int XtGeometryAlmost = 0x2;
+// public static final int XtGeometryDone = 0x3;
+// public static final int XtGeometryNo = 0x1;
+// public static final int XtGeometryYes = 0x0;
+// public static final int XtGrabExclusive = 0x2;
+ public static final int XtGrabNone = 0x0;
+// public static final int XtGrabNonexclusive = 0x1;
+// public static final int XtIMAll = 0x7;
+ public static final int XtIMAlternateInput = 0x4;
+ public static final int XtIMTimer = 0x2;
+ public static final int XtIMXEvent = 0x1;
+ public static final int XYBitmap = 0;
+// public static final int XYPixmap = 1;
+// public static final int YSorted = 0x1;
+// public static final int YXBanded = 0x3;
+// public static final int YXSorted = 0x2;
+ public static final int ZPixmap = 2;
+
+ /* Unused X Structs */
+ /*
+ public class XPoint {
+ public short x, y;
+ public static final int sizeof = 4;
+ }
+ */
+
+ /* Unused Natives */
+ /*
+ public static final native int XBlackPixel (int display, int screenNum);
+ public static final native void XChangeActivePointerGrab (int display, int eventMask, int cursor, int time);
+ public static final native int XDefaultGC (int display, int screen_number);
+ public static final native void XNoOp (int display);
+ public static final native int XRootWindowOfScreen (int screen);
+ public static final native int XSendEvent (int display, int w, boolean propagate, int event_mask, XAnyEvent event);
+ public static final native int XmCreateCascadeButton (int parent, byte [] name, int [] arglist, int argcount);
+ public static final native int XmCreateDrawnButton (int parent, byte [] name, int [] arglist, int argcount);
+ public static final native int XmCreateRowColumn (int parent, byte [] name, int [] arglist, int argcount);
+ public static final native int XmCreateScrolledWindow (int parent, byte [] name, int [] arglist, int argcount);
+ public static final native boolean XmDestroyPixmap (int screen, int pixmap);
+ public static final native int XmGetFocusWidget (int widget);
+ public static final native int XmGetPixmapByDepth (int screen, byte [] image_name, int foreground, int background, int depth);
+ public static final native void XmListAddItemsUnselected (int list, int xmStringTable, int item_count, int position);
+ public static final native void XmListDeleteItem (int list, int item);
+ public static final native void XmListDeselectItem (int list, int xmString);
+ public static final native void XmListSelectItem (int list, int xmString, boolean notify);
+ public static final native int XmPushButtonWidgetClass ();
+ public static final native void XmStringDrawUnderline (int display, int window, int fontlist, int xmString, int gc, int x, int y, int width, int align, int lay_dir, XRectangle clip, int xmStringUnderline);
+ public static final native int XmStringLineCount (int xmString);
+ public static final native boolean XmTextRemove (int widget);
+ public static final native int XtAppSetErrorHandler (int app_context, int handler);
+ public static final native int XtAppSetWarningHandler (int app_context, int handler);
+ public static final native void XtCallActionProc (int widget, byte [] action, XAnyEvent event, byte [] params, int num_params);
+ public static final native void XtCloseDisplay (int display);
+ public static final native int XtCreateWidget (byte [] name, int widgetClass, int parent, int [] argList, int argCount);
+ public static final native void XtRemoveCallback (int widget, int callback_name, int callback, int client_data);
+ public static final native void XtRemoveEventHandler (int widget, int event_mask, boolean nonmaskable, int proc, int client_data);
+ public static final native int XtScreen (int widget);
+ */
+public static final native int OverrideShellWidgetClass ();
+public static final native int ShellWidgetClass ();
+public static final native int TopLevelShellWidgetClass ();
+public static final native int TransientShellWidgetClass ();
+public static final native int XAllocColor (int display, int colormap, XColor color);
+public static final native void XBell (int display, int ms);
+public static final native int XBitmapBitOrder (int display);
+public static final native int XBlackPixel (int display, int screenNum);
+public static final native int XChangeActivePointerGrab(int display, int event_mask, int cursor, int time);
+public static final native int XChangeGC (int display, int gc, int valuemask, XGCValues values);
+public static final native void XChangeWindowAttributes (int display, int window, int mask, XSetWindowAttributes attributes);
+public static final native boolean XCheckMaskEvent (int display, int mask, XAnyEvent event);
+public static final native boolean XCheckWindowEvent (int display, int window, int mask, XAnyEvent event);
+public static final native void XClearArea (int display, int window, int x, int y, int width, int height, boolean exposures);
+public static final native void XClipBox (int region, XRectangle rectangle);
+public static final native void XCopyArea (int display, int src, int dest, int gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y);
+public static final native void XCopyPlane (int display, int src, int dest, int gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y, int plane);
+public static final native int XCreateBitmapFromData (int display, int drawable, byte [] data, int width, int height);
+public static final native int XCreateFontCursor (int display, int shape);
+public static final native int XCreateGC (int display, int window, int mask, XGCValues values);
+public static final native int XCreateImage (int display, int visual, int depth, int format, int offset, int data, int width, int height, int bitmap_pad, int bytes_per_line);
+public static final native int XCreatePixmap (int display, int drawable, int width, int height, int depth);
+public static final native int XCreatePixmapCursor (int display, int source, int mask, XColor foreground_color, XColor background_color, int x, int y);
+public static final native int XCreateRegion ();
+public static final native int XDefaultColormap (int display, int screen_number);
+public static final native int XDefaultDepthOfScreen (int screen);
+public static final native int XDefaultRootWindow (int display);
+public static final native int XDefaultScreen (int display);
+public static final native int XDefaultScreenOfDisplay (int display);
+public static final native int XDefaultVisual (int display, int screen_number);
+public static final native void XDefineCursor (int display, int window, int cursor);
+public static final native int XDestroyImage(int ximage);
+public static final native void XDestroyRegion (int region);
+public static final native int XDisplayHeight (int display, int screen);
+public static final native int XDisplayHeightMM (int display, int screen);
+public static final native int XDisplayWidth (int display, int screen);
+public static final native int XDisplayWidthMM (int display, int screen);
+public static final native void XDrawArc (int display, int drawable, int gc, int x1, int y1, int x2, int y2, int a1, int a2);
+public static final native void XDrawLine (int display, int drawable, int gc, int x1, int y1, int x2, int y2);
+public static final native void XDrawLines (int display, int drawable, int gc, short[] xPoints, int nPoints, int mode);
+public static final native void XDrawRectangle (int display, int drawable, int gc, int x, int y, int width, int height);
+public static final native boolean XEmptyRegion (int region);
+public static final native boolean XEqualRegion (int region1, int region2);
+public static final native void XFillArc (int display, int drawable, int gc, int x1, int y1, int x2, int y2, int a1, int a2);
+public static final native int XFillPolygon (int display, int drawable, int gc, short[] xPoints, int nPoints, int mode, int style);
+public static final native void XFillRectangle (int display, int drawable, int gc, int x, int y, int width, int height);
+public static final native boolean XFilterEvent (XAnyEvent event, int window);
+public static final native void XFlush (int display);
+public static final native int XFontsOfFontSet (int fontSet, int[] fontStructs, int[] fontNames);
+public static final native int XFree (int address);
+public static final native int XFreeColors (int display, int colormap, int [] pixels, int npixels, int planes);
+public static final native void XFreeCursor (int display, int pixmap);
+public static final native void XFreeFontNames(int list);
+public static final native void XFreeGC (int display, int gc);
+public static final native void XFreePixmap (int display, int pixmap);
+public static final native int XGetGCValues (int display, int gc, int valuemask, XGCValues values);
+public static final native int XGetGeometry (int display, int drawable, int [] root_return, int [] x_return, int [] y_return, int [] width_return, int [] height_return, int [] border_width_return, int [] depth_return);
+public static final native int XGetImage (int display, int drawable, int x, int y, int width, int height, int plane_mask, int format);
+public static final native int XGetInputFocus (int display, int [] window, int [] revert);
+public static final native boolean XGetWindowAttributes (int display, int window, XWindowAttributes attributes);
+public static final native int XGrabPointer (
+ int display,
+ int grabWindow,
+ int ownerEvents,
+ int eventMask,
+ int pointerMode,
+ int keyboardMode,
+ int confineToWindow,
+ int cursor,
+ int time);
+public static final native int XInitThreads ();
+public static final native int XKeysymToString (int keysym);
+public static final native int XListFonts(int display, byte[] pattern, int maxnames, int[] actual_count_return);
+public static final native int XLookupString (XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
+public static final native int XLowerWindow (int display, int window);
+public static final native boolean XPointInRegion (int region, int x, int y);
+public static final native int XPutImage (int display, int drawable, int gc, int image, int srcX, int srcY, int destX, int destY, int width, int height);
+public static final native int XQueryColor (int display, int colormap, XColor color);
+public static final native int XQueryPointer (
+ int display,
+ int window,
+ int [] root,
+ int [] child,
+ int [] rootX,
+ int [] rootY,
+ int [] windowX,
+ int [] windowY,
+ int [] mask);
+public static final native int XQueryTree (int display, int window, int [] root_return, int [] parent_return, int [] children_return, int [] nChildren_return);
+public static final native int XRaiseWindow (int display, int window);
+public static final native int XReconfigureWMWindow (int display, int window, int screen, int valueMask, XWindowChanges values);
+public static final native int XRectInRegion (int region, int x, int y, int width, int height);
+public static final native void XSetBackground (int display, int gc, int background);
+public static final native void XSetClipMask (int display, int gc, int pixmap);
+public static final native void XSetClipRectangles (int display, int gc, int clip_x_origin, int clip_y_origin, XRectangle rectangles, int n, int ordering);
+public static final native int XSetDashes (int display, int gc, int dash_offset, byte[] dash_list, int n);
+public static final native int XSetErrorHandler (int handler);
+public static final native void XSetFillStyle (int display, int gc, int fill_style);
+public static final native int XSetFont (int display, int gc, int font);
+public static final native void XSetForeground (int display, int gc, int foreground);
+public static final native void XSetFunction (int display, int gc, int function);
+public static final native void XSetGraphicsExposures (int display, int gc, boolean graphics_exposures);
+public static final native int XSetInputFocus (int display, int window, int revert, int time);
+public static final native int XSetLineAttributes (int display, int gc, int lineWidth, int lineStyle, int capStyle, int joinStyle);
+public static final native void XSetRegion (int display, int gc, int region);
+public static final native void XSetStipple (int display, int gc, int pixmap);
+public static final native void XSetSubwindowMode (int display, int gc, int subwindow_mode);
+public static final native void XSetWindowBorderWidth (int display, int window, int width);
+public static final native void XSubtractRegion (int sra, int srb, int dr_return);
+public static final native void XSync (int display, boolean discard);
+public static final native int XSynchronize (int display, boolean onoff);
+public static final native void XUndefineCursor (int display, int window);
+public static final native int XUngrabPointer (int display, int time);
+public static final native void XUnionRectWithRegion (XRectangle rectangle, int src_region, int dest_region_return);
+public static final native void XUnionRegion (int sra, int srb, int dr_return);
+public static final native int XWhitePixel (int display, int screenNum);
+public static final native void XWithdrawWindow (int display, int window, int screen);
+public static final native void XmAddWMProtocolCallback (int shell, int protocol, int callback, int closure);
+public static final native void XmChangeColor (int widget, int pixel);
+public static final native int XmClipboardCopy(int display, int window, int item_id, byte[] format_name, byte[] buffer, int length, int private_id, int[] data_id);
+public static final native int XmClipboardEndCopy(int display, int window, int item_id);
+public static final native int XmClipboardStartCopy(int display, int window, int clip_label, int timestamp, int widget, int callback, int[] item_id);
+public static final native int XmClipboardInquireLength(int display, int widget, byte[] format_name, int[] length);
+public static final native int XmClipboardInquireFormat(int display, int window, int index, byte[] format_name_buf, int buffer_len, int[]copied_len);
+public static final native int XmClipboardInquireCount(int display, int window, int[] count, int[] max_format_name_length);
+public static final native int XmClipboardStartRetrieve(int display, int window, int timestamp);
+public static final native int XmClipboardRetrieve(int display, int window, byte[] format_name, byte[] buffer, int length, int[] num_bytes, int[] private_id);
+public static final native int XmClipboardEndRetrieve(int display, int window);
+public static final native void XmComboBoxAddItem(int widget, int xmString, int position, boolean unique);
+public static final native void XmComboBoxDeletePos(int widget, int position);
+public static final native void XmComboBoxSelectItem(int widget, int xmString);
+public static final native int XmCreateArrowButton (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateCascadeButtonGadget (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateComboBox(int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateDialogShell (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateDrawingArea (int parent, byte [] name, int [] arglist, int argcount);
+//public static final native int XmCreateDrawnButton (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateErrorDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateFileSelectionDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateForm (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateFrame (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateInformationDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateLabel (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateList (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateMainWindow (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateMenuBar (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateMessageDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreatePopupMenu (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreatePulldownMenu (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreatePushButton (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreatePushButtonGadget (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateQuestionDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateScale (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateScrollBar (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateScrolledList (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateScrolledText (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateSeparator (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateSeparatorGadget (int parent, byte [] name, int [] arglist, int argcount);
+//public static final native int XmCreateSimpleSpinBox (int parent, byte [] name, int [] arglist, int argcount);
+//public static final native int XmCreateSpinBox (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateTextField (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateToggleButton (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateToggleButtonGadget (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XmCreateWarningDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native void XmDragCancel(int dragcontext);
+public static final native int XmDragStart(int widget, XAnyEvent event, int[] arglist, int argcount);
+public static final native void XmDropSiteRegister(int widget, int [] arglist, int argcount);
+public static final native void XmDropSiteUnregister(int widget);
+public static final native void XmDropSiteUpdate(int widget, int [] arglist, int argcount);
+public static final native void XmDropTransferAdd(int drop_transfer, int [] transfers, int num_transfers);
+public static final native int XmDropTransferStart(int widget, int [] arglist, int argcount);
+public static final native int XmFileSelectionBoxGetChild (int widget, int child);
+public static final native int XmFontListAppendEntry (int oldList, int entry);
+public static final native int XmFontListCopy (int fontlist);
+public static final native void XmFontListEntryFree (int[] entry);
+public static final native int XmFontListEntryGetFont (int entry, int[] type_return);
+public static final native int XmFontListEntryLoad (int display, byte [] fontName, int type, byte[] tag);
+public static final native void XmFontListFree (int list);
+public static final native void XmFontListFreeFontContext (int context);
+public static final native boolean XmFontListInitFontContext (int[] context,int fontList);
+public static final native int XmFontListNextEntry (int context);
+public static final native int XmGetAtomName (int display, int atom);
+public static final native int XmGetDragContext (int widget, int timestamp);
+public static final native int XmGetFocusWidget (int widget);
+public static final native int XmGetXmDisplay (int display);
+public static final native int XmImMbLookupString (int widget, XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
+public static final native int XmInternAtom (int display, byte [] name, boolean only_if_exists);
+public static final native void XmListAddItemUnselected (int list, int xmString, int position);
+public static final native void XmListDeleteAllItems (int list);
+public static final native void XmListDeleteItemsPos (int list, int item_count, int position);
+public static final native void XmListDeletePos (int list, int position);
+public static final native void XmListDeletePositions (int list, int [] position_list, int position_count);
+public static final native void XmListDeselectAllItems (int list);
+public static final native void XmListDeselectPos (int list, int position);
+public static final native int XmListGetKbdItemPos (int list);
+public static final native boolean XmListGetSelectedPos (int list, int [] positions, int [] count);
+public static final native int XmListItemPos (int list, int xmString);
+public static final native boolean XmListPosSelected (int list, int position);
+public static final native void XmListReplaceItemsPosUnselected (int list, int [] new_items, int item_count, int position);
+public static final native void XmListSelectPos (int list, int position, boolean notify);
+public static final native boolean XmListSetKbdItemPos (int list, int position);
+public static final native void XmListSetPos (int list, int position);
+public static final native void XmListUpdateSelectedList (int list);
+public static final native void XmMainWindowSetAreas (int widget, int menu, int command, int hscroll, int vscroll, int wregion);
+public static final native int XmMenuShellWidgetClass ();
+public static final native int XmMessageBoxGetChild (int widget, int child);
+public static final native int XmParseMappingCreate (int [] argList, int argCount);
+public static final native void XmParseMappingFree (int parseMapping);
+public static final native void XmParseTableFree (int [] parseTable, int mappingCount);
+public static final native boolean XmProcessTraversal (int widget, int dir);
+public static final native int XmRenderTableAddRenditions(int oldTable, int[] renditions, int renditionCount, int mergeMode);
+public static final native void XmRenderTableFree(int renderTable);
+public static final native int XmRenditionCreate(int widget, byte[] tag, int[] argList, int argCount);
+public static final native void XmRenditionFree(int rendition);
+public static final native boolean XmStringCompare (int xmString1, int xmString2);
+public static final native int XmStringComponentCreate (int type, int length, byte[] value);
+public static final native int XmStringCreate (byte [] string, byte [] charset);
+public static final native int XmStringCreateLocalized (byte [] string);
+public static final native int XmStringCreateLtoR (byte [] string, byte [] charset);
+public static final native void XmStringDraw (int display, int window, int renderTable, int xmString, int gc, int x, int y, int width, int align, int lay_dir, XRectangle clip);
+public static final native void XmStringDrawImage (int display, int window, int renderTable, int xmString, int gc, int x, int y, int width, int align, int lay_dir, XRectangle clip);
+public static final native boolean XmStringEmpty (int s1);
+public static final native void XmStringFree (int xmString);
+public static final native boolean XmStringGetLtoR (int xmString, byte [] charset, int [] text);
+public static final native int XmStringGenerate(byte[] text, byte[] tag, int type, byte[] rendition);
+public static final native int XmStringHeight (int fontList, int xmString);
+public static final native int XmStringParseText (byte[] text, int textEnd, byte [] tag, int tagType, int [] parseTable, int parseCount, int callData);
+public static final native int XmStringWidth (int fontList, int xmString);
+public static final native int XmStringUnparse (int xmString, byte [] tag, int tagType, int outputType, int [] parseTable, int parseCount, int parseModel);
+public static final native int XmTabCreate(int value, byte units, byte offsetModel, byte alignment, byte[] decimal);
+public static final native void XmTabFree(int tab);
+public static final native void XmTabListFree(int tabList);
+public static final native int XmTabListInsertTabs(int oldList, int[] tabs, int tab_count, int position);
+public static final native void XmTextClearSelection (int widget, int time);
+public static final native boolean XmTextCopy (int widget, int time);
+public static final native boolean XmTextCut (int widget, int time);
+public static final native void XmTextDisableRedisplay (int widget);
+public static final native void XmTextEnableRedisplay (int widget);
+public static final native int XmTextGetInsertionPosition (int widget);
+public static final native int XmTextGetLastPosition (int widget);
+public static final native int XmTextGetMaxLength (int widget);
+public static final native int XmTextGetSelection (int widget);
+public static final native boolean XmTextGetSelectionPosition (int widget, int [] left, int [] right);
+public static final native int XmTextGetString (int widget);
+public static final native int XmTextGetSubstring (int widget, int start, int num_chars, int buffer_size, byte [] buffer);
+public static final native int XmTextGetSubstringWcs (int widget, int start, int num_chars, int buffer_size, char [] buffer);
+public static final native void XmTextInsert (int widget, int position, byte [] value);
+public static final native boolean XmTextPaste (int widget);
+public static final native boolean XmTextPosToXY (int widget, int position, short [] x, short [] y);
+public static final native void XmTextReplace (int widget, int from_pos, int to_pos, byte [] value);
+public static final native void XmTextScroll (int widget, int lines);
+public static final native void XmTextSetEditable (int widget, boolean editable);
+public static final native void XmTextSetHighlight (int widget, int left, int right, int mode);
+public static final native void XmTextSetInsertionPosition (int widget, int position);
+public static final native void XmTextSetMaxLength (int widget, int max_length);
+public static final native void XmTextSetSelection (int widget, int first, int last, int time);
+public static final native void XmTextSetString (int widget, byte [] value);
+public static final native void XmTextShowPosition (int widget, int position);
+public static final native void XmUpdateDisplay (int widget);
+public static final native boolean XmWidgetGetDisplayRect (int region, XRectangle rectangle);
+public static final native int XmbLookupString (int ic, XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
+public static final native void XtAddCallback (int widget, int callback_name, int callback, int client_data);
+public static final native void XtAddEventHandler (int widget, int event_mask, boolean nonmaskable, int proc, int client_data);
+public static final native void XtAddExposureToRegion (int event, int region);
+public static final native int XtAppAddTimeOut (int app_context, int interval, int proc, int client_data);
+public static final native int XtAppCreateShell (
+ byte [] appName,
+ byte [] appClass,
+ int widgetClass,
+ int display,
+ int [] argList,
+ int argCount);
+public static final native void XtAppNextEvent (int appContext, XAnyEvent event);
+public static final native boolean XtAppPeekEvent (int appContext, XAnyEvent event);
+public static final native int XtAppPending (int appContext);
+public static final native void XtAppProcessEvent (int appContext, int inputMask);
+public static final native int XtAppSetErrorHandler (int app_context, int msg_handler);
+public static final native int XtAppSetWarningHandler (int app_context, int msg_handler);
+public static final native int XtBuildEventMask (int widget);
+public static final native void XtCallActionProc (int widget, byte [] action, XAnyEvent event, int [] params, int num_params);
+public static final native int XtClass (int widget);
+public static final native void XtConfigureWidget (int widget, int x, int y, int width, int height, int borderWidth);
+public static final native int XtCreateApplicationContext ();
+public static final native int XtCreatePopupShell (byte [] name, int widgetClass, int parent, int [] argList, int argCount);
+public static final native void XtDestroyApplicationContext (int appContext);
+public static final native void XtDestroyWidget (int widget);
+public static final native boolean XtDispatchEvent (XAnyEvent event);
+public static final native int XtDisplay (int widget);
+public static final native int XtDisplayToApplicationContext (int display);
+public static final native void XtFree (int ptr);
+public static final native int XtGetMultiClickTime (int display);
+public static final native void XtGetValues (int widget, int [] argList, int numArgs);
+public static final native boolean XtIsManaged (int widget);
+public static final native boolean XtIsRealized (int widget);
+public static final native boolean XtIsSubclass (int widget, int widgetClass);
+public static final native boolean XtIsTopLevelShell (int widget);
+public static final native boolean XtIsWidget (int widget);
+public static final native int XtLastTimestampProcessed (int display);
+public static final native int XtMalloc (int size);
+public static final native void XtManageChild (int widget);
+public static final native void XtMapWidget (int widget);
+public static final native void XtMoveWidget (int widget, int x, int y);
+public static final native int XtOpenDisplay (
+ int xtAppContext,
+ byte [] displayName,
+ byte [] applicationName,
+ byte [] applicationClass,
+ int options,
+ int numOptions,
+ int [] argc,
+ int argv);
+public static final native void XtOverrideTranslations (int w, int translations);
+public static final native int XtParent (int widget);
+public static final native int XtParseTranslationTable (byte [] string);
+public static final native void XtPopdown (int widget);
+public static final native void XtPopup (int widget, int flags);
+public static final native int XtQueryGeometry (int widget, XtWidgetGeometry intended, XtWidgetGeometry preferred_return);
+public static final native void XtRealizeWidget (int widget);
+public static final native void XtRemoveTimeOut (int id);
+public static final native void XtResizeWidget (int widget, int width, int height, int borderWidth);
+public static final native void XtResizeWindow (int widget);
+public static final native int XtSetLanguageProc (int appContext, int languageProc, int pointer);
+public static final native void XtSetMappedWhenManaged (int widget, boolean flag);
+public static final native void XtSetValues (int widget, int [] argList, int numArgs);
+public static final native void XtToolkitInitialize ();
+public static final native void XtTranslateCoords (int widget, short x, short y, short [] root_x, short [] root_y);
+public static final native void XtUnmanageChild (int widget);
+public static final native void XtUnmapWidget (int widget);
+public static final native int XtWindow (int widget);
+public static final native int XtWindowToWidget (int display, int widget);
+static int malloc(String name) {
+ int length = name.length();
+ int ptr = OS.XtMalloc (length + 1);
+ char [] unicode = new char [length];
+ name.getChars (0, length, unicode, 0);
+ byte[] buffer = new byte [length + 1];
+ for (int i = 0; i < length; i++) {
+ buffer[i] = (byte) unicode[i];
+ }
+ OS.memmove (ptr, buffer, length + 1);
+ return ptr;
+}
+public static final native void memmove (int dest, XImage src, int count);
+public static final native void memmove (int dest, XmDragProcCallback src, int count);
+public static final native void memmove (int dest, XmTextBlockRec src, int count);
+public static final native void memmove (int dest, XmTextVerifyCallbackStruct src, int count);
+public static final native void memmove (int dest, byte [] src, int count);
+public static final native void memmove (int dest, int [] src, int count);
+public static final native void memmove (Visual dest, int src, int count);
+public static final native void memmove (XButtonEvent dest, int src, int count);
+public static final native void memmove (XCharStruct dest, int src, int count);
+public static final native void memmove (XConfigureEvent dest, int src, int count);
+public static final native void memmove (XCrossingEvent dest, int src, int count);
+public static final native void memmove (XExposeEvent dest, int src, int count);
+public static final native void memmove (XFocusChangeEvent dest, int src, int count);
+public static final native void memmove (XFontStruct dest, int src, int count);
+public static final native void memmove (XImage dest, int src, int count);
+public static final native void memmove (XKeyEvent dest, int src, int count);
+public static final native void memmove (XKeyEvent dest, XAnyEvent src, int count);
+public static final native void memmove (XMotionEvent dest, int src, int count);
+public static final native void memmove (XmAnyCallbackStruct dest, int src, int count);
+public static final native void memmove (XmDragProcCallback dest, int src, int count);
+public static final native void memmove (XmDropFinishCallback dest, int src, int count);
+public static final native void memmove (XmDropProcCallback dest, int src, int count);
+public static final native void memmove (XmTextBlockRec dest, int src, int count);
+public static final native void memmove (XmTextVerifyCallbackStruct dest, int src, int count);
+public static final native void memmove (byte [] dest, int src, int count);
+public static final native void memmove (int [] dest, int src, int count);
+public static final native int strlen (int string);
+public static final native int XpmReadFileToPixmap(int display, int drawable, byte[] fileName, int[] pixmap_return, int[] shapemask_return, int attributes);
+public static final native int XmCreateDrawnButton (int parent, byte [] name, int [] arglist, int argcount);
+public static final native int XCheckIfEvent (int display, XAnyEvent event_return, int predicate, int arg);
+public static final native boolean XtToolkitThreadInitialize ();
+public static final native int Call (int proc, int arg1, int arg2);
+public static final native int XSetIOErrorHandler (int handler);
+public static final native boolean XmTextFieldPaste (int widget);
+
+/*
+ * ======== Start of printing constants and functions ========
+ */
+ public static final byte XPJobAttr = 1;
+ public static final byte XPDocAttr = 2;
+ public static final byte XPPrinterAttr = 4;
+ public static final byte XPAttrMerge = 2;
+ public static final byte XPSpool = 1;
+ public static final int CopyFromParent = 0;
+
+public static final native int XpCreateContext(int display, byte [] printer_name);
+public static final native int XpGetPrinterList(int display, byte [] printer_name, int [] list_count);
+public static final native void XpFreePrinterList(int printer_list);
+public static final native int XpGetAttributes(int display, int print_context, byte type);
+public static final native void XpSetAttributes(int display, int print_context, byte type, byte [] pool, byte replacement_rule);
+public static final native int XpGetOneAttribute(int display, int print_context, byte type, byte [] attribute_name);
+public static final native void XpSetContext(int display, int print_context);
+public static final native int XpGetScreenOfContext(int display, int print_context);
+public static final native void XpDestroyContext(int display, int print_context);
+public static final native int XpGetPageDimensions(int display, int print_context, short [] width, short [] height, XRectangle reproducible_area);
+public static final native void XpStartJob(int display, byte save_data);
+public static final native void XpStartPage(int display, int window);
+public static final native void XpEndPage(int display);
+public static final native void XpEndJob(int display);
+public static final native void XpCancelJob(int display, boolean discard);
+public static final native int XpQueryVersion(int display, short[] major_version, short[] minor_version);
+public static final native int XDefaultGCOfScreen(int screen);
+public static final native int XDefaultColormapOfScreen(int screen);
+public static final native int XRootWindowOfScreen(int screen);
+public static final native int XScreenNumberOfScreen(int screen);
+public static final native int XCreateWindow(int display, int parent, int x, int y, int width, int height,
+ int border_width, int depth, int clazz, int visual, long value_mask, int attributes);
+public static final native void XDestroyWindow(int display, int w);
+
+/*
+ * ======== End of printing constants and functions ========
+ */
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/Visual.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/Visual.java
new file mode 100755
index 0000000000..7b23c27be8
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/Visual.java
@@ -0,0 +1,16 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class Visual {
+ public int ext_data;
+ public int visualid;
+ public int c_class;
+ public int red_mask, green_mask, blue_mask;
+ public int bits_per_rgb;
+ public int map_entries;
+ public static final int sizeof = 32;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XAnyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XAnyEvent.java
new file mode 100755
index 0000000000..dd733286ee
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XAnyEvent.java
@@ -0,0 +1,11 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XAnyEvent extends XEvent {
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+ public int pad10, pad11, pad12, pad13, pad14, pad15, pad16, pad17, pad18;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XButtonEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XButtonEvent.java
new file mode 100755
index 0000000000..b8b8cb3a6c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XButtonEvent.java
@@ -0,0 +1,12 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XButtonEvent extends XInputEvent {
+ public int button; /* detail */
+ public int same_screen; /* same screen flag */
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCharStruct.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCharStruct.java
new file mode 100755
index 0000000000..bdec29c6db
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCharStruct.java
@@ -0,0 +1,16 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XCharStruct {
+ public short lbearing;
+ public short rbearing;
+ public short width;
+ public short ascent;
+ public short descent;
+ public short attributes;
+ public static final int sizeof = 12;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XColor.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XColor.java
new file mode 100755
index 0000000000..5f38a015be
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XColor.java
@@ -0,0 +1,14 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XColor {
+ public int pixel;
+ public short red, green, blue;
+ public byte flags;
+ public byte pad;
+ public static final int sizeof = 12;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XConfigureEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XConfigureEvent.java
new file mode 100755
index 0000000000..3842b9584e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XConfigureEvent.java
@@ -0,0 +1,16 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XConfigureEvent extends XEvent {
+ public int x, y;
+ public int width, height;
+ public int border_width;
+ public int above;
+ public int override_redirect;
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+ public int pad10, pad11;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCrossingEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCrossingEvent.java
new file mode 100755
index 0000000000..14605f9f88
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XCrossingEvent.java
@@ -0,0 +1,19 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XCrossingEvent extends XWindowEvent {
+ public int mode; /* NotifyNormal, NotifyGrab, NotifyUngrab */
+ public int detail;
+ /*
+ * NotifyAncestor, NotifyVirtual, NotifyInferior,
+ * NotifyNonlinear, NotifyNonlinearVirtual
+ */
+ public int same_screen; /* same screen flag */
+ public int focus; /* boolean focus */
+ public int state; /* key or button mask */
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XEvent.java
new file mode 100755
index 0000000000..11c539fdff
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XEvent.java
@@ -0,0 +1,15 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public abstract class XEvent {
+ public int type;
+ public int serial;
+ public int send_event;
+ public int display;
+ public int window;
+ public static final int sizeof = 96;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XExposeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XExposeEvent.java
new file mode 100755
index 0000000000..d6a470345f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XExposeEvent.java
@@ -0,0 +1,14 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XExposeEvent extends XEvent {
+ public int x, y;
+ public int width, height;
+ public int count;
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+ public int pad10, pad11, pad12, pad13;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFocusChangeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFocusChangeEvent.java
new file mode 100755
index 0000000000..b0073ad986
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFocusChangeEvent.java
@@ -0,0 +1,18 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XFocusChangeEvent extends XEvent {
+ public int mode; /* NotifyNormal, NotifyGrab, NotifyUngrab */
+ public int detail;
+ /*
+ * NotifyAncestor, NotifyVirtual, NotifyInferior,
+ * NotifyNonlinear,NotifyNonlinearVirtual, NotifyPointer,
+ * NotifyPointerRoot, NotifyDetailNone
+ */
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+ public int pad10, pad11, pad12, pad13, pad14, pad15, pad16;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFontStruct.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFontStruct.java
new file mode 100755
index 0000000000..5062f111ab
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XFontStruct.java
@@ -0,0 +1,36 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XFontStruct {
+ public int ext_data;
+ public int fid;
+ public int direction;
+ public int min_char_or_byte2;
+ public int max_char_or_byte2;
+ public int min_byte1;
+ public int max_byte1;
+ public int all_chars_exist;
+ public int default_char;
+ public int n_properties;
+ public int properties;
+ public short min_bounds_lbearing;
+ public short min_bounds_rbearing;
+ public short min_bounds_width;
+ public short min_bounds_ascent;
+ public short min_bounds_descent;
+ public short min_bounds_attributes;
+ public short max_bounds_lbearing;
+ public short max_bounds_rbearing;
+ public short max_bounds_width;
+ public short max_bounds_ascent;
+ public short max_bounds_descent;
+ public short max_bounds_attributes;
+ public int per_char;
+ public int ascent;
+ public int descent;
+ public static final int sizeof = 80;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XGCValues.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XGCValues.java
new file mode 100755
index 0000000000..eebdef85d6
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XGCValues.java
@@ -0,0 +1,33 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XGCValues {
+ public int function; /* logical operation */
+ public int plane_mask;/* plane mask */
+ public int foreground;/* foreground pixel */
+ public int background;/* background pixel */
+ public int line_width; /* line width */
+ public int line_style; /* LineSolid, LineOnOffDash, LineDoubleDash */
+ public int cap_style; /* CapNotLast, CapButt, CapRound, CapProjecting */
+ public int join_style; /* JoinMiter, JoinRound, JoinBevel */
+ public int fill_style; /* FillSolid, FillTiled, FillStippled, FillOpaeueStippled */
+ public int fill_rule; /* EvenOddRule, WindingRule */
+ public int arc_mode; /* ArcChord, ArcPieSlice */
+ public int tile; /* tile pixmap for tiling operations */
+ public int stipple; /* stipple 1 plane pixmap for stipping */
+ public int ts_x_origin; /* offset for tile or stipple operations */
+ public int ts_y_origin;
+ public int font; /* default text font for text operations */
+ public int subwindow_mode; /* ClipByChildren, IncludeInferiors */
+ public int graphics_exposures;/* boolean, should exposures be generated */
+ public int clip_x_origin; /* origin for clipping */
+ public int clip_y_origin;
+ public int clip_mask; /* bitmap clipping; other calls for rects */
+ public int dash_offset; /* patterned/dashed line information */
+ public byte dashes;
+ public static final int sizeof = 92;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XImage.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XImage.java
new file mode 100755
index 0000000000..691df05be9
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XImage.java
@@ -0,0 +1,25 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XImage {
+ public int width, height;
+ public int xoffset, format;
+ public int data;
+ public int byte_order, bitmap_unit, bitmap_bit_order, bitmap_pad;
+ public int depth, bytes_per_line, bits_per_pixel;
+ public int red_mask, green_mask, blue_mask;
+ public int obdata;
+// struct funcs {
+ public int create_image;
+ public int destroy_image;
+ public int get_pixel;
+ public int put_pixel;
+ public int sub_image;
+ public int add_pixel;
+// } f;
+ public static final int sizeof = 88;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XInputEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XInputEvent.java
new file mode 100755
index 0000000000..fde28843f7
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XInputEvent.java
@@ -0,0 +1,10 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public abstract class XInputEvent extends XWindowEvent {
+ public int state; /* key or button mask */
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XKeyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XKeyEvent.java
new file mode 100755
index 0000000000..1541cfe711
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XKeyEvent.java
@@ -0,0 +1,12 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XKeyEvent extends XInputEvent {
+ public int keycode; /* detail */
+ public int same_screen; /* same screen flag */
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XMotionEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XMotionEvent.java
new file mode 100755
index 0000000000..82428b47d4
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XMotionEvent.java
@@ -0,0 +1,12 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XMotionEvent extends XInputEvent {
+ public int is_hint; /* detail */
+ public int same_screen; /* same screen flag */
+ public int pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XRectangle.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XRectangle.java
new file mode 100755
index 0000000000..b8feffa676
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XRectangle.java
@@ -0,0 +1,14 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XRectangle {
+ public short x, y, width, height;
+ public static final int sizeof = 8;
+public String toString () {
+ return "XRectangle {" + x + ", " + y + ", " + width + ", " + height + "}";
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XSetWindowAttributes.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XSetWindowAttributes.java
new file mode 100755
index 0000000000..5f4d79350e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XSetWindowAttributes.java
@@ -0,0 +1,25 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XSetWindowAttributes {
+ public int background_pixmap; /* background or None or ParentRelative */
+ public int background_pixel; /* background pixel */
+ public int border_pixmap; /* border of the window */
+ public int border_pixel; /* border pixel value */
+ public int bit_gravity; /* one of bit gravity values */
+ public int win_gravity; /* one of the window gravity values */
+ public int backing_store; /* NotUseful, WhenMapped, Always */
+ public int backing_planes;/* planes to be preseved if possible */
+ public int backing_pixel;/* value to use in restoring planes */
+ public int save_under; /* should bits under be saved? (popups) */
+ public int event_mask; /* set of events that should be saved */
+ public int do_not_propagate_mask; /* set of events that should not propagate */
+ public int override_redirect; /* boolean value for override-redirect */
+ public int colormap; /* color map to be associated with window */
+ public int cursor; /* cursor to be displayed (or None) */
+ public static final int sizeof = 60;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowAttributes.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowAttributes.java
new file mode 100755
index 0000000000..11d1443999
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowAttributes.java
@@ -0,0 +1,31 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XWindowAttributes {
+ public int x, y; /* location of window */
+ public int width, height; /* width and height of window */
+ public int border_width; /* border width of window */
+ public int depth; /* depth of window */
+ public int visual; /* the associated visual structure */
+ public int root; /* root of screen containing window */
+ public int c_class; /* InputOutput, InputOnly*/
+ public int bit_gravity; /* one of bit gravity values */
+ public int win_gravity; /* one of the window gravity values */
+ public int backing_store; /* NotUseful, WhenMapped, Always */
+ public int backing_planes;/* planes to be preserved if possible */
+ public int backing_pixel;/* value to be used when restoring planes */
+ public int save_under; /* boolean, should bits under be saved? */
+ public int colormap; /* color map to be associated with window */
+ public int map_installed; /* boolean, is color map currently installed*/
+ public int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
+ public int all_event_masks; /* set of events all people have interest in*/
+ public int your_event_mask; /* my event mask */
+ public int do_not_propagate_mask; /* set of events that should not propagate */
+ public int override_redirect; /* boolean value for override-redirect */
+ public int screen; /* back pointer to correct screen */
+ public static final int sizeof = 92;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowChanges.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowChanges.java
new file mode 100755
index 0000000000..991383513c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowChanges.java
@@ -0,0 +1,15 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XWindowChanges {
+ public int x, y;
+ public int width, height;
+ public int border_width;
+ public int sibling;
+ public int stack_mode;
+ public static final int sizeof = 28;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowEvent.java
new file mode 100755
index 0000000000..5d229c0f57
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XWindowEvent.java
@@ -0,0 +1,14 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public abstract class XWindowEvent extends XEvent {
+ public int root; /* root window that the event occured on */
+ public int subwindow; /* child window */
+ public int time; /* milliseconds */
+ public int x, y; /* pointer x, y coordinates in event window */
+ public int x_root, y_root; /* coordinates relative to root */
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmAnyCallbackStruct.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmAnyCallbackStruct.java
new file mode 100755
index 0000000000..389e0d1fb1
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmAnyCallbackStruct.java
@@ -0,0 +1,12 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmAnyCallbackStruct {
+ public int reason; // 0
+ public int event; // 4
+ public static final int sizeof = 8;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDragProcCallback.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDragProcCallback.java
new file mode 100755
index 0000000000..6afd4717cd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDragProcCallback.java
@@ -0,0 +1,21 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmDragProcCallback {
+ public int reason; // the reason callback was called
+ public int event; // event structure that triggered callback
+ public int timeStamp; // timestamp of ;logical event
+ public int dragContext; // DragContext widget associated with operation
+ public short x; // x-coordinate of pointer
+ public short y; // y-coordinate of pointer
+ public byte dropSiteStatus; // valid or invalid
+ public byte operation; // current operation
+ public byte operations; // supported operations
+ public byte animate; // toolkit or receiver does animation
+
+ public static final int sizeof = 24;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropFinishCallback.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropFinishCallback.java
new file mode 100755
index 0000000000..07586efac3
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropFinishCallback.java
@@ -0,0 +1,19 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmDropFinishCallback {
+ public int reason; // the reason callback was called
+ public int event; // event structure that triggered callback
+ public int timeStamp; // time at which drop completed
+ public byte operation; // current operation
+ public byte operations; // supported operations
+ public byte dropSiteStatus; // valid, invalid or none
+ public byte dropAction; // drop, cancel, help or interrupt
+ public byte completionStatus; // success or failure
+
+ public static final int sizeof = 17;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropProcCallback.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropProcCallback.java
new file mode 100755
index 0000000000..f8e95ff1d0
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmDropProcCallback.java
@@ -0,0 +1,21 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmDropProcCallback {
+ public int reason; // the reason callback was called
+ public int event; // event structure that triggered callback
+ public int timeStamp; // timestamp of ;logical event
+ public int dragContext; // DragContext widget associated with operation
+ public short x; // x-coordinate of pointer
+ public short y; // y-coordinate of pointer
+ public byte dropSiteStatus; // valid or invalid
+ public byte operation; // current operation
+ public byte operations; // supported operations
+ public byte dropAction; // drop or help
+
+ public static final int sizeof = 24;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextBlockRec.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextBlockRec.java
new file mode 100755
index 0000000000..c508f8f420
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextBlockRec.java
@@ -0,0 +1,13 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmTextBlockRec {
+ public int ptr; // 0
+ public int length; // 4
+ public int format; // 8
+ public static final int sizeof = 12;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct.java
new file mode 100755
index 0000000000..8d5203cfa2
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XmTextVerifyCallbackStruct.java
@@ -0,0 +1,16 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XmTextVerifyCallbackStruct extends XmAnyCallbackStruct {
+ public byte doit; // 8
+ public int currInsert; // 12
+ public int newInsert; // 16
+ public int startPos; // 20
+ public int endPos; // 24
+ public int text; // 28
+ public static final int sizeof = 32;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XtWidgetGeometry.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XtWidgetGeometry.java
new file mode 100755
index 0000000000..661378fadc
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/XtWidgetGeometry.java
@@ -0,0 +1,15 @@
+package org.eclipse.swt.internal.motif;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public class XtWidgetGeometry {
+ public int request_mode;
+ public int x, y;
+ public int width, height, border_width;
+ public int sibling;
+ public int stack_mode;
+ public static final int sizeof = 24;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/AbstractTreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/AbstractTreeItem.java
new file mode 100755
index 0000000000..b23dff6c03
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/AbstractTreeItem.java
@@ -0,0 +1,318 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class stores and manages child items of a tree item.
+ * It provides protocol to query the index of an item relative
+ * to the root and to retrieve items by index.
+ * The TreeItem class implements this protocol for general
+ * tree items.
+ * TreeRoots provides a special implementation that allows the
+ * Tree class to treat trees with one root and with multiple
+ * roots equally.
+ */
+abstract class AbstractTreeItem extends SelectableItem {
+ private Vector children;
+ private boolean isExpanded = false;
+ // number of children.
+ // includes all expanded items down to the leafs.
+ private int visibleItemCount = 0;
+
+/**
+ * Create a new instance of the receiver.
+ * @param parent - widget the receiver belongs to
+ * @param swtStyle - widget style. see Widget class for details
+ */
+AbstractTreeItem(Tree parent, int swtStyle) {
+ super(parent, swtStyle);
+}
+/**
+ * Insert 'item' in the list of child items. Notify the
+ * parent about the new item.
+ * @param 'item' - the item that should be added to the
+ * receiver's children.
+ * @param index - position that 'item' will be inserted at
+ * in the receiver.
+ */
+void add(TreeItem item, int index) {
+ Vector items = getChildren();
+ int visibleIndex = getVisibleIndex();
+
+ if (index < 0 || index > items.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ if (item.isRoot()) {
+ visibleIndex = index;
+ }
+ else
+ if (isExpanded == false) {
+ visibleIndex = -1;
+ }
+ if (visibleIndex != -1) {
+ if (index > 0) {
+ TreeItem previousChild = (TreeItem) getChildren().elementAt(index - 1);
+ visibleIndex = previousChild.getVisibleIndex() + previousChild.getVisibleItemCount() + 1;
+ }
+ else {
+ visibleIndex = getVisibleIndex() + 1;
+ }
+ }
+ getSelectableParent().addingItem(item, visibleIndex);
+ item.setIndex(index);
+ resetChildIndices(index, true);
+ items.insertElementAt(item, index);
+ if (isExpanded == true) {
+ visibleItemCount++;
+ calculateVisibleItemCountParent();
+ }
+ getSelectableParent().addedItem(item, visibleIndex);
+}
+/**
+ * Set whether the receiver is expanded or not.
+ * If the receiver is expanded its child items are visible.
+ * @param expanded -
+ * true=the receiver is expanded, making its child items visible.
+ * false=the receiver is collapsed, making its child items invisible
+ */
+void internalSetExpanded(boolean expanded) {
+ isExpanded = expanded;
+ calculateVisibleItemCount();
+}
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+abstract void calculateVisibleItemCount();
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+abstract void calculateVisibleItemCountParent();
+/**
+ * Deselect the receiver and all children
+ */
+void deselectAll() {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ setSelected(false);
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ treeItem.deselectAll();
+ }
+}
+/**
+ * Destroy all children of the receiver
+ */
+void disposeItem() {
+ Vector children = getChildren();
+ AbstractTreeItem child;
+ while (children.size() > 0) { // TreeItem objects are removed from vector during dispose
+ child = (AbstractTreeItem) children.firstElement();
+ child.dispose();
+ }
+ doDispose();
+ super.disposeItem();
+}
+/**
+ * Subclasses should free resources here
+ */
+void doDispose() {
+ setChildren(null);
+ visibleItemCount = 0;
+}
+/**
+ * Answer the Vector containing the child items of the receiver.
+ */
+Vector getChildren() {
+ if (children == null) {
+ children = new Vector(4);
+ }
+ return children;
+}
+/**
+ * Answer whether the receiver is expanded or not.
+ * If the receiver is expanded its children are visible.
+ * @return
+ * true - the receiver is expanded, making its children visible
+ * false - the receiver is collapsed, making its children invisible
+ */
+public boolean getExpanded() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return isExpanded;
+}
+/**
+ * Answer the number of children.
+ */
+public int getItemCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getChildren().size();
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * If 'anIndex' is the global index of the expanded item 'anItem'
+ * then the following expressions are true:
+ * 'anItem == theRoot.getVisibleItem(anIndex)' and
+ * 'anIndex == anItem.getVisibleIndex()'
+ * @return
+ * The index of the receiver relative to the first root item.
+ * Answer -1 if the receiver is not visible (because the parent
+ * is collapsed).
+ */
+abstract int getVisibleIndex();
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+abstract int getVisibleIndex(int childIndex);
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the receiver's parent's
+ * client area.
+ */
+abstract TreeItem getVisibleItem(int searchIndex);
+/**
+ * Answer the number of expanded children, direct and indirect.
+ */
+int getVisibleItemCount() {
+ return visibleItemCount;
+}
+/**
+ * Returns the expanded state. Circumvent widget/thread check
+ * for performance. For non-API callers only.
+ */
+boolean internalGetExpanded() {
+ return isExpanded;
+}
+/**
+ * Answer whether the receiver is a leaf item.
+ * An item is a leaf when it has no child items.
+ * @return
+ * true - receiver is a leaf item
+ * false - receiver is not a leaf item.
+ */
+boolean isLeaf() {
+ return (getChildren().size() == 0);
+}
+/**
+ * Answer whether the receiver is a root item.
+ * The receiver is a root item when it doesn't have a parent item.
+ * @return
+ * true - the receiver is a root item.
+ * false - the receiver is not a root item.
+ */
+boolean isRoot() {
+ return false;
+}
+/**
+ * Remove 'child' from the receiver.
+ * Notify the parent widget only if it is not being disposed itself.
+ */
+void removeItem(SelectableItem child) {
+ Vector children = getChildren();
+ SelectableItemWidget parent = getSelectableParent();
+ int childIndex = children.indexOf(child);
+
+ if (childIndex != -1) {
+ if (((Tree) parent).isRemovingAll() == true) {
+ children.removeElementAt(childIndex); // just remove the item from the list if the whole tree is being disposed
+ if (isExpanded == true) {
+ visibleItemCount--;
+ calculateVisibleItemCountParent();
+ }
+ }
+ else {
+ parent.removingItem(child);
+ children.removeElementAt(childIndex);
+ if (isExpanded == true) {
+ visibleItemCount--;
+ calculateVisibleItemCountParent();
+ }
+ resetChildIndices(childIndex, false); // mark child index dirty
+ parent.removedItem(child);
+ }
+ }
+}
+/**
+ * Allow subclasses to reset any cached data.
+ * Called for all children of the receiver.
+ */
+void reset() {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ treeItem.reset();
+ }
+}
+/**
+ * Mark all child indices dirty starting with the child at
+ * 'startIndex'. This causes getIndex to recalculate the index.
+ * @param startIndex - index in the list of children at which
+ * and after which the indices are reset.
+ */
+void resetChildIndices(int startIndex, boolean addItem) {
+ Vector children = getChildren();
+ TreeItem child;
+ int increment = addItem ? 1 : 0;
+
+ for (int i = startIndex; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ child.setIndex(i + increment); // mark child index dirty
+ }
+}
+/**
+ * Select the receiver and all children.
+ * Return a Vector containing all the items that have been selected
+ * (and that have not been selected before).
+ */
+Vector selectAll(Vector selectedItems) {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ if (isSelected() == false) {
+ selectedItems.addElement(this);
+ setSelected(true);
+ getSelectableParent().redrawSelection(this);
+ }
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ selectedItems = treeItem.selectAll(selectedItems);
+ }
+ return selectedItems;
+}
+/**
+ * Set the Array containing the receiver's child items to 'children'.
+ */
+void setChildren(Vector children) {
+ this.children = children;
+}
+
+void setVisibleItemCount(int count) {
+ visibleItemCount = count;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java
new file mode 100755
index 0000000000..93b8ec8dbc
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java
@@ -0,0 +1,631 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* The button class represents a selectable user interface object
+* that issues notificiation when pressed and released.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class Button extends Control {
+ Image image, bitmap, disabled;
+ static final byte [] ARM_AND_ACTIVATE;
+ static {
+ String name = "ArmAndActivate";
+ int length = name.length();
+ char [] unicode = new char [length];
+ name.getChars (0, length, unicode, 0);
+ byte [] buffer = new byte [length + 1];
+ for (int i = 0; i < length; i++) {
+ buffer[i] = (byte) unicode[i];
+ }
+ ARM_AND_ACTIVATE = buffer;
+ }
+/**
+* Creates a new instance of the widget.
+*/
+public Button (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
+ if ((style & SWT.PUSH) != 0) {
+ return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
+ return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
+ }
+ if ((style & SWT.ARROW) != 0) {
+ return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
+ }
+ return style;
+}
+void click () {
+ OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, new XAnyEvent (), null, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ if ((style & SWT.ARROW) != 0) {
+ Display display = getDisplay ();
+ width += display.scrolledMarginX;
+ height += display.scrolledMarginY;
+ return new Point (width, height);
+ }
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ result.request_mode = OS.CWWidth | OS.CWHeight;
+ int [] argList2 = {OS.XmNrecomputeSize, 1};
+ OS.XtSetValues(handle, argList2, argList2.length / 2);
+ OS.XtQueryGeometry (handle, null, result);
+ int [] argList3 = {OS.XmNrecomputeSize, 0};
+ OS.XtSetValues(handle, argList3, argList3.length / 2);
+ width += result.width;
+ height += result.height;
+ /**
+ * Feature in Motif. If a button's labelType is XmSTRING but it
+ * has no label set into it yet, recomputing the size will
+ * not take into account the height of the font, as we would
+ * like it to. Take care of this case.
+ */
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmSTRING) {
+ int [] argList1 = {OS.XmNlabelString, 0};
+ OS.XtGetValues (handle, argList1, argList1.length / 2);
+ int xmString = argList1 [1];
+ if (OS.XmStringEmpty (xmString)) height += getFontHeight ();
+ }
+ if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
+ int [] argList4 = new int [] {OS.XmNmarginLeft, 0, OS.XmNmarginRight, 0, OS.XmNmarginTop, 0, OS.XmNmarginBottom, 0};
+ OS.XtGetValues (handle, argList4, argList4.length / 2);
+ if (wHint != SWT.DEFAULT) width = wHint + argList4 [1] + argList4 [3] + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + argList4 [5] + argList4 [7] + (border * 2);
+ }
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
+
+ /* ARROW button */
+ if ((style & SWT.ARROW) != 0) {
+ int alignment = OS.XmARROW_UP;
+ if ((style & SWT.UP) != 0) alignment = OS.XmARROW_UP;
+ if ((style & SWT.DOWN) != 0) alignment = OS.XmARROW_DOWN;
+ if ((style & SWT.LEFT) != 0) alignment = OS.XmARROW_LEFT;
+ if ((style & SWT.RIGHT) != 0) alignment = OS.XmARROW_RIGHT;
+ int [] argList = {
+ OS.XmNtraversalOn, 0,
+ OS.XmNarrowDirection, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreateArrowButton (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & SWT.FLAT) != 0) {
+ int [] argList1 = {OS.XmNshadowThickness, 1};
+ OS.XtSetValues (handle, argList1, argList1.length / 2);
+ }
+ return;
+ }
+
+ /* Compute alignment */
+ int alignment = OS.XmALIGNMENT_BEGINNING;
+ if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
+ if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
+
+ /* TOGGLE button */
+ if ((style & SWT.TOGGLE) != 0) {
+ /*
+ * Bug in Motif. When XmNindicatorOn is set to false,
+ * Motif doesn't reset the shadow thickness to give a
+ * push button look. The fix is to set the shadow
+ * thickness when ever this resource is changed.
+ */
+ int [] argList = {
+ OS.XmNrecomputeSize, 0,
+ OS.XmNindicatorOn, 0,
+ OS.XmNshadowThickness, (style & SWT.FLAT) != 0 ? 1 : 2,
+ OS.XmNalignment, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreateToggleButton (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+
+ /* CHECK or RADIO button */
+ if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ /*
+ * Bug in Motif. For some reason, a toggle button
+ * with XmNindicatorType XmONE_OF_MANY must have this
+ * value set at creation or the highlight color will
+ * not be correct. The fix is to set these values
+ * on create.
+ */
+ int indicatorType = OS.XmONE_OF_MANY;
+ if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY;
+ int [] argList = {
+ OS.XmNrecomputeSize, 0,
+ OS.XmNindicatorType, indicatorType,
+ OS.XmNalignment, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreateToggleButton (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+
+ /* PUSH button */
+ int [] argList = {
+ OS.XmNrecomputeSize, 0,
+ OS.XmNalignment, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreatePushButton (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & SWT.FLAT) != 0) {
+ int [] argList1 = {OS.XmNshadowThickness, 1};
+ OS.XtSetValues (handle, argList1, argList1.length / 2);
+ }
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ if ((style & SWT.PUSH) == 0) return;
+ if (getShell ().parent == null) return;
+ int [] argList = new int [] {OS.XmNdefaultButtonShadowThickness, 1};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+int defaultBackground () {
+ return getDisplay ().buttonBackground;
+}
+int defaultFont () {
+ return getDisplay ().buttonFont;
+}
+int defaultForeground () {
+ return getDisplay ().buttonForeground;
+}
+/**
+* Gets the alignment.
+* <p>
+* This method returns the aligment of the button.
+* If the button is an ARROW, the value indicates
+* the direction of the arrow.
+* <p>
+* LEFT, RIGHT, UP, DOWN - when the button is an ARROW button.<br>
+* LEFT, RIGHT, CENTER - when the button is any other style.
+*
+* @return the button alignment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getAlignment () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.ARROW) != 0) {
+ int [] argList = {OS.XmNarrowDirection, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int direction = argList [1];
+ if (direction == OS.XmARROW_UP) return SWT.UP;
+ if (direction == OS.XmARROW_DOWN) return SWT.DOWN;
+ if (direction == OS.XmARROW_LEFT) return SWT.LEFT;
+ if (direction == OS.XmARROW_RIGHT) return SWT.RIGHT;
+ return SWT.UP;
+ }
+ int [] argList = {OS.XmNalignment, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int alignment = argList [1];
+ if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
+ if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
+ if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
+ return SWT.CENTER;
+}
+boolean getDefault () {
+ if ((style & SWT.PUSH) == 0) return false;
+ int [] argList = {OS.XmNshowAsDefault, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the widget image.
+* <p>
+* @return the widget image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getImage () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return image;
+}
+String getNameText () {
+ return getText ();
+}
+/**
+* Gets the selection.
+* <p>
+* This method gets the widget selection state for a
+* widgets with the style CHECK, RADIO or TOGGLE. It
+* returns false for widgets that do not have one of
+* these styles.
+* true or false - for CHECK, RADIO or TOGGLE.
+* false - for all other widget styles
+*
+* @return the selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
+ int [] argList = {OS.XmNset, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the widget text.
+* <p>
+* This method returns the button label. The label may
+* include the mnemonic character but must not contain line
+* delimiters.
+*
+* @return the button text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.ARROW) != 0) return "";
+ int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int xmString = argList [1], mnemonic = argList [3];
+ if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
+ char [] result = null;
+ int address = OS.XmStringUnparse (
+ xmString,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address != 0) {
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result = Converter.mbcsToWcs (null, buffer);
+ }
+ if (xmString != 0) OS.XmStringFree (xmString);
+ int count = 0;
+ if (mnemonic != 0) count++;
+ for (int i=0; i<result.length-1; i++)
+ if (result [i] == Mnemonic) count++;
+ char [] newResult = result;
+ if ((count != 0) || (mnemonic != 0)) {
+ newResult = new char [result.length + count];
+ int i = 0, j = 0;
+ while (i < result.length) {
+ if ((mnemonic != 0) && (result [i] == mnemonic)) {
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ mnemonic = 0;
+ }
+ if ((newResult [j++] = result [i++]) == Mnemonic)
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ }
+ }
+ return new String (newResult);
+}
+void hookEvents () {
+ super.hookEvents ();
+ int callback = OS.XmNactivateCallback;
+ int windowProc = getDisplay ().windowProc;
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) callback = OS.XmNvalueChangedCallback;
+ OS.XtAddCallback (handle, callback, windowProc, SWT.Selection);
+}
+boolean mnemonicHit () {
+ if (!setFocus ()) return false;
+ click ();
+ return true;
+}
+boolean mnemonicMatch (char key) {
+ char mnemonic = findMnemonic (getText ());
+ if (mnemonic == '\0') return false;
+ return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
+}
+int processFocusIn () {
+ super.processFocusIn ();
+ if ((style & SWT.PUSH) == 0) return 0;
+ getShell ().setDefaultButton (this, false);
+ return 0;
+}
+int processFocusOut () {
+ super.processFocusOut ();
+ if ((style & SWT.PUSH) == 0) return 0;
+ if (getDefault ()) {
+ getShell ().setDefaultButton (null, false);
+ }
+ return 0;
+}
+int processSelection (int callData) {
+ if ((style & SWT.RADIO) != 0) {
+ if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) selectRadio ();
+ }
+ return super.processSelection (callData);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ int [] argList = {
+ OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
+ OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (bitmap != null) bitmap.dispose ();
+ if (disabled != null) disabled.dispose ();
+ image = bitmap = disabled = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+void selectRadio () {
+ Control [] children = parent._getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (this != child && child instanceof Button) {
+ Button button = (Button) child;
+ if ((button.getStyle () & SWT.RADIO) != 0) {
+ if (button.getSelection ()) {
+ button.setSelection (false);
+ button.postEvent (SWT.Selection);
+ }
+ }
+ }
+ }
+ setSelection (true);
+}
+/**
+* Sets the alignment.
+* <p>
+* This method sets the aligment of the button.
+* If the button is an ARROW, the value indicated
+* the direction of the arrow.
+*
+* @param alignment the button alignment or the direction
+* of the arrow if the button is an ARROW
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setAlignment (int alignment) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.ARROW) != 0) {
+ int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP};
+ if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP;
+ if ((alignment & SWT.DOWN) != 0) argList [1] = OS.XmARROW_DOWN;
+ if ((alignment & SWT.LEFT) != 0) argList [1] = OS.XmARROW_LEFT;
+ if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmARROW_RIGHT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ return;
+ }
+ if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
+ int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
+ if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
+ if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmPIXMAP) setBitmap (image);
+}
+void setBitmap (Image image) {
+ int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
+ int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
+ if (bitmap != null) bitmap.dispose ();
+ if (disabled != null) disabled.dispose ();
+ bitmap = disabled = null;
+ if (image != null) {
+ Display display = getDisplay ();
+ switch (image.type) {
+ case SWT.BITMAP:
+ labelPixmap = image.pixmap;
+ disabled = new Image (display, image, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ case SWT.ICON:
+ Rectangle rect = image.getBounds ();
+ bitmap = new Image (display, rect.width, rect.height);
+ GC gc = new GC (bitmap);
+ gc.setBackground (getBackground ());
+ gc.fillRectangle (rect);
+ gc.drawImage (image, 0, 0);
+ gc.dispose ();
+ labelPixmap = bitmap.pixmap;
+ disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ default:
+ error (SWT.ERROR_NOT_IMPLEMENTED);
+ }
+ }
+ int [] argList = {
+ OS.XmNlabelType, OS.XmPIXMAP,
+ OS.XmNlabelPixmap, labelPixmap,
+ OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+void setDefault (boolean value) {
+ if ((style & SWT.PUSH) == 0) return;
+ if (getShell ().parent == null) return;
+ int [] argList = {OS.XmNshowAsDefault, (value ? 1 : 0)};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the widget image.
+* <p>
+* @param image the widget image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setBitmap (this.image = image);
+}
+/**
+* Sets the selection.
+* <p>
+* This method Sets the widget selection state for a
+* widgets with the style CHECK, RADIO or TOGGLE. It
+* returns false for widgets that do not have one of
+* these styles.
+*
+* @param selected the new selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (boolean selected) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
+ int [] argList = {OS.XmNset, selected ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the widget text.
+* <p>
+* This method sets the button label. The label may include
+* the mnemonic character but must not contain line delimiters.
+*
+* @param string the desired label of the button
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.ARROW) != 0) return;
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int i=0, j=0, mnemonic=0;
+ while (i < text.length) {
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ while (j < text.length) text [j++] = 0;
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ int xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ int [] argList = {
+ OS.XmNlabelType, OS.XmSTRING,
+ OS.XmNlabelString, xmString,
+ OS.XmNmnemonic, mnemonic,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (xmString != 0) OS.XmStringFree (xmString);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java
new file mode 100755
index 0000000000..6a6d902ecd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java
@@ -0,0 +1,212 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The canvas class implements a drawing area for
+* arbitrary graphics.
+*
+* Styles
+*
+* NO_BACKGROUND,
+* NO_FOCUS,
+* MERGE_EXPOSES,
+* RESIZE_REDRAW
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/* Class Definition */
+public class Canvas extends Composite {
+ Caret caret;
+
+Canvas () {
+ /* Do nothing */
+}
+/**
+* Create a Canvas.
+*
+* PARAMTERS
+*
+* parent a composite widget (cannot be null)
+* style the bitwise OR'ing of widget styles
+*
+* REMARKS
+*
+* This method creates a child widget using style bits
+* to select a particular look or set of properties.
+*
+**/
+public Canvas (Composite parent, int style) {
+ super (parent, style);
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ fontList = defaultFont ();
+}
+/**
+* Get the current caret.
+*
+* REMARKS
+*
+* This method gets the current caret for the window.
+* The current caret is automatically hidden and shown
+* by the window when:
+*
+* - during expose and resize
+* - when focus is gained or lost
+* - when an the window is scrolled
+*
+**/
+public Caret getCaret () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return caret;
+}
+
+int processFocusIn () {
+ int result = super.processFocusIn ();
+ if (caret != null) caret.setFocus ();
+ return result;
+}
+int processFocusOut () {
+ int result = super.processFocusOut ();
+ if (caret != null) caret.killFocus ();
+ return result;
+}
+
+int processPaint (int callData) {
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ int result = super.processPaint (callData);
+ if (isFocus) caret.setFocus ();
+ return result;
+}
+
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ super.redrawWidget (x, y, width, height, all);
+ if (isFocus) caret.setFocus ();
+}
+
+void releaseWidget () {
+ if (caret != null) {
+ caret.releaseWidget ();
+ caret.releaseHandle ();
+ }
+ caret = null;
+ super.releaseWidget();
+}
+
+public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (width <= 0 || height <= 0) return;
+ int deltaX = destX - x, deltaY = destY - y;
+ if (deltaX == 0 && deltaY == 0) return;
+ if (!isVisible ()) return;
+
+ /* Hide the caret */
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+
+ /* Flush outstanding exposes */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ XAnyEvent xEvent = new XAnyEvent ();
+ OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
+ while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
+ OS.XtDispatchEvent (xEvent);
+ }
+
+ /* Scroll the window */
+ int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
+ OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY);
+ OS.XFreeGC (xDisplay, xGC);
+ boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
+ if (disjoint) {
+ OS.XClearArea (xDisplay, xWindow, x, y, width, height, true);
+ } else {
+ if (deltaX != 0) {
+ int newX = destX - deltaX;
+ if (deltaX < 0) newX = destX + width;
+ OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true);
+ }
+ if (deltaY != 0) {
+ int newY = destY - deltaY;
+ if (deltaY < 0) newY = destY + height;
+ OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true);
+ }
+ }
+
+ /* Show the caret */
+ if (isFocus) caret.setFocus ();
+}
+public void setBounds (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ super.setBounds (x, y, width, height);
+ if (isFocus) caret.setFocus ();
+}
+/**
+* Set the current caret.
+*
+* PARAMTERS
+*
+* caret - the new caret or null
+*
+* REMARKS
+*
+* This method sets the current caret for the window.
+* The current caret is automatically hidden and shown
+* by the window when:
+*
+* - during expose and resize
+* - when focus is gained or lost
+* - when an the window is scrolled
+*
+**/
+public void setCaret (Caret caret) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Caret newCaret = caret;
+ Caret oldCaret = this.caret;
+ this.caret = newCaret;
+ if (hasFocus ()) {
+ if (oldCaret != null) oldCaret.killFocus ();
+ if (newCaret != null) newCaret.setFocus ();
+ }
+}
+
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ super.setLocation (x, y);
+ if (isFocus) caret.setFocus ();
+}
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ super.setSize (width, height);
+ if (isFocus) caret.setFocus ();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java
new file mode 100755
index 0000000000..818e4d53cd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java
@@ -0,0 +1,402 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+* The caret class implements an i-beam that is
+* typically used as the insertion point for text.
+*/
+
+/* Class Definition */
+public /*final*/ class Caret extends Widget {
+ Canvas parent;
+ int x, y, width, height;
+ boolean moved, resized;
+ boolean isVisible, isShowing;
+ int blinkRate = 500;
+/**
+* Creates a new instance of the widget.
+*/
+public Caret (Canvas parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ createWidget (0);
+}
+boolean blinkCaret () {
+ if (!isVisible) return true;
+ if (!isShowing) return showCaret ();
+ if (blinkRate == 0) return true;
+ return hideCaret ();
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ isVisible = true;
+ if (parent.getCaret () == null) {
+ parent.setCaret (this);
+ }
+}
+boolean drawCaret () {
+ if (parent == null) return false;
+ if (parent.isDisposed ()) return false;
+ int handle = parent.handle;
+ int window = OS.XtWindow (handle);
+ if (window == 0) return false;
+ int xDisplay = OS.XtDisplay (handle);
+ int gc = OS.XCreateGC (xDisplay, window, 0, null);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int foreground = argList [1];
+ int background = argList [3];
+ int color = foreground ^ background;
+ OS.XSetFunction (xDisplay, gc, OS.GXxor);
+ OS.XSetForeground (xDisplay, gc, color);
+ int nWidth = width;
+ if (nWidth <= 0) nWidth = 2;
+ OS.XFillRectangle (xDisplay, window, gc, x, y, nWidth, height);
+ OS.XFreeGC (xDisplay, gc);
+ return true;
+}
+/**
+* Gets the widget bounds.
+* <p>
+* @return a rectangle that is the widget bounds.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Rectangle getBounds () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return new Rectangle (x, y, width, height);
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+* Gets the widget font.
+* <p>
+* @return the widget font
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Font getFont () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getFont ();
+}
+/**
+* Gets the widget location.
+* <p>
+* @return the widget location
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point getLocation () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return new Point (x, y);
+}
+/**
+* Gets the parent.
+* <p>
+* @return the parent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Canvas getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the widget size.
+* <p>
+* @return the widget size
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point getSize () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return new Point (width, height);
+}
+/**
+* Gets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @return visible the visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return isVisible;
+}
+boolean hideCaret () {
+ Display display = getDisplay ();
+ if (display.currentCaret != this) return false;
+ if (!isShowing) return true;
+ isShowing = false;
+ return drawCaret ();
+}
+/**
+* Gets the visibility status.
+* <p>
+* This method returns the visibility status of the
+* widget in the widget hierarchy. If the parent is not
+* visible or some other condition makes the widget not
+* visible, this method will return false.
+*
+* @return the actual visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return isVisible && parent.isVisible () && parent.hasFocus ();
+}
+boolean isFocusCaret () {
+ Display display = getDisplay ();
+ return this == display.currentCaret;
+}
+void killFocus () {
+ Display display = getDisplay ();
+ if (display.currentCaret != this) return;
+ if (isVisible) hideCaret ();
+ display.setCurrentCaret (null);
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (this == parent.getCaret ()) parent.setCaret (null);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ Display display = getDisplay ();
+ if (display.currentCaret == this) {
+ if (isVisible) hideCaret ();
+ display.setCurrentCaret (null);
+ }
+ parent = null;
+}
+/**
+* Sets the widget bounds.
+* <p>
+* @param x the new x coordinate
+* @param y the new y coordinate
+* @param width the new widget width
+* @param height the new widget height
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setBounds (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean samePosition, sameExtent, showing;
+ samePosition = (this.x == x) && (this.y == y);
+ sameExtent = (this.width == width) && (this.height == height);
+ if ((samePosition) && (sameExtent)) return;
+ if (isShowing) hideCaret ();
+ this.x = x; this.y = y;
+ this.width = width; this.height = height;
+ if (sameExtent) {
+ moved = true;
+ if (isVisible ()) {
+ moved = false;
+ //IsDBLocale ifTrue: [
+ //widget == nil ifFalse: [widget updateCaret]].
+ }
+ } else {
+ resized = true;
+ if (isVisible ()) {
+ moved = false;
+ //IsDBLocale ifTrue: [
+ //widget == nil ifFalse: [widget updateCaret]].
+ resized = false;
+ }
+ }
+ if (isShowing) showCaret ();
+}
+/**
+* Set the widget bounds.
+*
+* @param rect the new bounding rectangle
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when rect is null
+*/
+public void setBounds (Rectangle rect) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setBounds (rect.x, rect.y, rect.width, rect.height);
+}
+void setFocus () {
+ Display display = getDisplay ();
+ if (display.currentCaret == this) return;
+ display.setCurrentCaret (this);
+ if (isVisible) showCaret ();
+}
+/**
+* Sets the widget font.
+* <p>
+* When new font is null, the font reverts
+* to the default system font for the widget.
+*
+* @param font the new font (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setFont (Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+/**
+* Sets the widget location.
+* <p>
+* @param x the new x position.
+* @param y the new y position.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setBounds (x, y, width, height);
+}
+/**
+* Sets the widget location.
+* <p>
+* @param location the new location
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when location is null
+*/
+public void setLocation (Point location) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setLocation (location.x, location.y);
+}
+/**
+* Sets the widget size.
+* <p>
+* @param x the new width
+* @param y the new height
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setBounds (x, y, width, height);
+}
+/**
+* Sets the widget size.
+* <p>
+* @param size the widget size
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when size is null
+*/
+public void setSize (Point size) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setSize (size.x, size.y);
+}
+/**
+* Sets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @param visible the new visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (visible == isVisible) return;
+ if (isVisible = visible) {
+ showCaret ();
+ } else {
+ hideCaret ();
+ }
+}
+boolean showCaret () {
+ if (getDisplay ().currentCaret != this) return false;
+ if (isShowing) return true;
+ isShowing = true;
+ return drawCaret ();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java
new file mode 100755
index 0000000000..a57ccd7cda
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java
@@ -0,0 +1,525 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+
+/**
+ * A color dialog allows the user to select a color
+ * from all available colors in the current pallette
+ */
+public /*final*/ class ColorDialog extends Dialog {
+ private static final int DEPTH_4 = 0; // index for COLOR_SWATCH_EXTENTS
+ private static final int DEPTH_8 = 1; // index for COLOR_SWATCH_EXTENTS
+ private static final int COLOR_SWATCH_EXTENTS[] = {40, 10}; // extents of the squares drawn to display a
+ // color out of 4 bit and 8 bit color depth
+ private static final int COLOR_SWATCH_BORDER = 1; // border between each color pad
+
+ private Shell shell; // the dialog shell
+ private Canvas colorsCanvas;
+ private Label sampleLabel;
+ private Canvas sampleCanvas;
+ private Label selectionLabel;
+ private Canvas selectionCanvas;
+ private Button ok;
+ private Button cancel;
+
+ private boolean okSelected; // true if the dialog was hidden
+ // because the ok button was selected
+ private RGB dialogResult;
+ private int colorDepth; // color depth of the display
+ private int colorSwatchExtent; // the size of on square used
+ // to display one color
+ private Color colorGrid[][]; // the colors displayed in the dialog
+
+public ColorDialog(Shell parent) {
+ this(parent, SWT.NULL);
+}
+public ColorDialog(Shell parent, int style) {
+ super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
+}
+
+void createChildren() {
+ Shell dialog = getDialogShell();
+ GridData gridData = new GridData();
+ GridLayout layout = new GridLayout();
+ final int ButtonHeight = 30;
+ final int ColorChooserWidth = COLOR_SWATCH_EXTENTS[DEPTH_8] * 32 - COLOR_SWATCH_BORDER; // extent of one color field multiplied with number of fields in a row
+ final int ColorChooserHeight = COLOR_SWATCH_EXTENTS[DEPTH_8] * 8 - COLOR_SWATCH_BORDER; // extent of one color field multiplied with number of rows
+
+ layout.numColumns = 3;
+ layout.marginWidth = 15;
+ layout.marginHeight = 15;
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 2;
+ dialog.setLayout(layout);
+
+ // row one
+ colorsCanvas = new Canvas(dialog, SWT.BORDER);
+ gridData.widthHint = ColorChooserWidth;
+ gridData.heightHint = ColorChooserHeight;
+ gridData.verticalSpan = 2;
+ gridData.horizontalSpan = 2;
+ colorsCanvas.setLayoutData(gridData);
+
+ // create ok and cancel buttons (row two and three)
+ createOkCancel();
+
+ // row three - empty row
+ Label fillLabel = new Label(dialog, SWT.NULL);
+ gridData = new GridData();
+ gridData.heightHint = 5;
+ gridData.horizontalSpan = layout.numColumns;
+ fillLabel.setLayoutData(gridData);
+
+ // row four - setup group box with sample text and canvas
+ createSampleGroup(ColorChooserWidth);
+ createSelectionGroup();
+}
+void createSampleGroup(int colorChooserWidth) {
+ Shell dialog = getDialogShell();
+ Group sampleGroup = new Group(dialog, SWT.NULL);
+ GridData gridData = new GridData();
+ GridLayout layout = new GridLayout();
+ int sampleGroupWidth;
+
+ sampleGroup.setText("Sample");
+ gridData.horizontalAlignment = GridData.FILL;
+ sampleGroup.setLayoutData(gridData);
+ sampleGroup.setLayout(layout);
+ sampleGroupWidth = (colorChooserWidth - layout.marginWidth * 4 - layout.horizontalSpacing * 4) / 2;
+
+ sampleLabel = new Label(sampleGroup, SWT.CENTER | SWT.BORDER);
+ sampleLabel.setAlignment(SWT.CENTER);
+ sampleLabel.setText("A Sample Text");
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.widthHint = sampleGroupWidth;
+ sampleLabel.setLayoutData(gridData);
+
+ sampleCanvas = new Canvas(sampleGroup, SWT.BORDER);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.heightHint = 15;
+ gridData.widthHint = sampleGroupWidth;
+ sampleCanvas.setLayoutData(gridData);
+}
+void createSelectionGroup() {
+ Shell dialog = getDialogShell();
+ Group selectionGroup = new Group(dialog, SWT.NULL);
+ GridData gridData = new GridData();
+ GridLayout layout = new GridLayout();
+
+ selectionGroup.setText("Selection");
+ gridData.horizontalAlignment = GridData.FILL;
+ selectionGroup.setLayoutData(gridData);
+ selectionGroup.setLayout(layout);
+
+ selectionLabel = new Label(selectionGroup, SWT.CENTER | SWT.BORDER);
+ selectionLabel.setAlignment(SWT.CENTER);
+ selectionLabel.setText("Current Selection");
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ selectionLabel.setLayoutData(gridData);
+
+ selectionCanvas = new Canvas(selectionGroup, SWT.BORDER);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.heightHint = 15;
+ selectionCanvas.setLayoutData(gridData);
+}
+void disposeColors() {
+ for (int row = 0; row < colorGrid.length; row++) {
+ for (int column = 0; column < colorGrid[row].length; column++) {
+ colorGrid[row][column].dispose();
+ }
+ }
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+void drawColor(int xIndex, int yIndex, Color color, GC gc) {
+ int colorSwatchExtent = getColorSwatchExtent();
+ int colorExtent = colorSwatchExtent - COLOR_SWATCH_BORDER;
+
+ gc.setBackground(color);
+ gc.fillRectangle(
+ xIndex * colorSwatchExtent, yIndex * colorSwatchExtent,
+ colorExtent, colorExtent);
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Canvas getColorCanvas() {
+ return colorsCanvas;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+int getColorDepth() {
+ return colorDepth;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Color [][] getColorGrid() {
+ return colorGrid;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+int getColorSwatchExtent() {
+ return colorSwatchExtent;
+}
+public RGB getRGB() {
+ return dialogResult;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Canvas getSampleCanvas() {
+ return sampleCanvas;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Label getSampleText() {
+ return sampleLabel;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Canvas getSelectionCanvas() {
+ return selectionCanvas;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+Label getSelectionText() {
+ return selectionLabel;
+}
+void handleEvents(Event event) {
+ Color selectionColor;
+
+ if (event.type == SWT.Paint) {
+ paint(event);
+ }
+ else
+ if (event.type == SWT.MouseDown) {
+ mouseDown(event);
+ }
+ else
+ if (event.type == SWT.MouseMove) {
+ mouseMove(event);
+ }
+ else
+ if (event.type == SWT.Selection) {
+ if (event.widget == getOKButton()) {
+ setOkSelected(true);
+ getDialogShell().setVisible(false);
+ }
+ else
+ if (event.widget == getCancelButton()) {
+ setOkSelected(false);
+ getDialogShell().setVisible(false);
+ }
+ }
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+void initialize4BitColors() {
+ Display display = getDialogShell().getDisplay();
+
+ colorGrid[0][0] = new Color(display, 0, 0, 0);
+ colorGrid[0][1] = new Color(display, 255, 255, 255);
+ colorGrid[1][0] = new Color(display, 128, 128, 128);
+ colorGrid[1][1] = new Color(display, 192, 192, 192);
+
+ colorGrid[2][0] = new Color(display, 0, 0, 128);
+ colorGrid[2][1] = new Color(display, 0, 0, 255);
+ colorGrid[3][0] = new Color(display, 0, 128, 128);
+ colorGrid[3][1] = new Color(display, 0, 255, 255);
+
+ colorGrid[4][0] = new Color(display, 0, 128, 0);
+ colorGrid[4][1] = new Color(display, 0, 255, 0);
+ colorGrid[5][0] = new Color(display, 128, 128, 0);
+ colorGrid[5][1] = new Color(display, 255, 255, 0);
+
+ colorGrid[6][0] = new Color(display, 128, 0, 0);
+ colorGrid[6][1] = new Color(display, 255, 0, 0);
+ colorGrid[7][0] = new Color(display, 128, 0, 128);
+ colorGrid[7][1] = new Color(display, 255, 0, 255);
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+void initialize8BitColors() {
+ Display display = getDialogShell().getDisplay();
+ int numColumns = colorGrid.length;
+ int numRows = colorGrid[0].length;
+ int iterationStep = 51;
+ int row = 0;
+ int column = 0;
+ int red;
+ int green;
+ int blue;
+
+ for (red = 0; red <= 255; red += iterationStep) {
+ for (blue = 0; blue <= 255; blue += iterationStep) {
+ if (blue == iterationStep && column < 20) { // hack to evenly distribute 256 colors on 32 columns
+ blue += iterationStep;
+ }
+ for (green = 0; green <= 255; green += iterationStep) {
+ if (row == 2 || row == 5) { // hack to evenly distribute 256 colors on 8 rows
+ colorGrid[column][row++] = new Color(display, red, green - iterationStep / 2, blue);
+ }
+ if (row == numRows) {
+ row = 0;
+ column++;
+ }
+ colorGrid[column][row++] = new Color(display, red, green, blue);
+ }
+ }
+ }
+}
+void initializeWidgets() {
+ Display display = getDialogShell().getDisplay();
+ Color selectionColor;
+ RGB rgb = getRGB();
+
+ if (rgb != null) {
+ selectionColor = new Color(display, rgb);
+ getSelectionCanvas().setBackground(selectionColor);
+ getSelectionText().setBackground(selectionColor);
+ selectionColor.dispose();
+ }
+ setColorDepth(display.getDepth());
+}
+void installListeners() {
+ Canvas colorCanvas = getColorCanvas();
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {handleEvents(event);}
+ };
+
+ getOKButton().addListener(SWT.Selection, listener);
+ getCancelButton().addListener(SWT.Selection, listener);
+ colorCanvas.addListener(SWT.Paint, listener);
+ colorCanvas.addListener(SWT.MouseDown, listener);
+ colorCanvas.addListener(SWT.MouseMove, listener);
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/19/99 7:13:21 PM)
+ */
+void mouseDown(Event event) {
+ int swatchExtent = getColorSwatchExtent();
+ Color colorGrid[][] = getColorGrid();
+ Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent];
+
+ getSelectionCanvas().setBackground(color);
+ getSelectionText().setBackground(color);
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/19/99 7:13:21 PM)
+ */
+void mouseMove(Event event) {
+ int swatchExtent = getColorSwatchExtent();
+ Color colorGrid[][] = getColorGrid();
+ Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent];
+
+ getSampleCanvas().setBackground(color);
+ getSampleText().setBackground(color);
+}
+public RGB open() {
+ Color selectionColor;
+ RGB dialogResult = null;
+ Shell dialog = new Shell(getParent(), getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
+
+ setDialogShell(dialog);
+ createChildren();
+ installListeners();
+ openModal();
+ if (isOkSelected() == true) {
+ selectionColor = getSelectionCanvas().getBackground();
+ dialogResult = new RGB(
+ selectionColor.getRed(),
+ selectionColor.getGreen(),
+ selectionColor.getBlue());
+ setRGB(dialogResult);
+ }
+ disposeColors();
+ // Fix for 1G5NLY7
+ if (dialog.isDisposed() == false) {
+ dialog.dispose();
+ }
+ return dialogResult;
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+void paint(Event event) {
+ Color colorGrid[][] = getColorGrid();
+
+ for (int column = 0; column < colorGrid.length; column++) {
+ for (int row = 0; row < colorGrid[0].length; row++) {
+ drawColor(column, row, colorGrid[column][row], event.gc);
+ }
+ }
+}
+/**
+ * Insert the method's description here.
+ * Creation date: (7/6/99 5:07:09 PM)
+ */
+void setColorDepth(int bits) {
+ colorDepth = bits;
+ if (bits == 4) {
+ colorSwatchExtent = COLOR_SWATCH_EXTENTS[DEPTH_4];
+ colorGrid = new Color[8][2];
+ initialize4BitColors();
+ }
+ else {
+ colorSwatchExtent = COLOR_SWATCH_EXTENTS[DEPTH_8];
+ colorGrid = new Color[32][8];
+ initialize8BitColors();
+ }
+}
+/**
+ *
+ */
+public void setRGB(RGB rgb) {
+ dialogResult = rgb;
+}
+/**
+ * Create the widgets of the dialog.
+ */
+void createOkCancel() {
+ Shell dialog = getDialogShell();
+ GridData gridData;
+
+ ok = new Button(dialog, SWT.PUSH);
+ ok.setText("OK");
+ dialog.setDefaultButton(ok);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.widthHint = 70;
+ ok.setLayoutData(gridData);
+
+ cancel = new Button(dialog, SWT.PUSH);
+ cancel.setText("Cancel");
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ cancel.setLayoutData(gridData);
+}
+/**
+ * Answer the cancel button
+ */
+Button getCancelButton() {
+ return cancel;
+}
+
+/**
+ * Answer the dialog shell.
+ */
+Shell getDialogShell() {
+ return shell;
+}
+/**
+ * Answer the ok button.
+ */
+Button getOKButton() {
+ return ok;
+}
+
+
+/**
+ * Insert the method's description here.
+ * Creation date: (08/05/99 12:34:43)
+ * @return boolean
+ */
+boolean isOkSelected() {
+ return okSelected;
+}
+/**
+ * Open the receiver and set its size to the size calculated by
+ * the layout manager.
+ */
+void openDialog() {
+ Shell dialog = getDialogShell();
+ Point pt;
+ Rectangle displayRect;
+ int widthLimit;
+
+ // Start everything off by setting the shell size to its computed size.
+ pt = dialog.computeSize(-1, -1, false);
+
+ // Ensure that the width of the shell fits the display.
+ displayRect = dialog.getDisplay().getBounds();
+ widthLimit = displayRect.width * 7 / 8;
+ if (pt.x > widthLimit) {
+ pt = dialog.computeSize (widthLimit, -1, false);
+ }
+ dialog.setBounds (0, 0, pt.x, pt.y);
+ dialog.setText(getText());
+ // Open the window.
+ dialog.open();
+}
+/**
+ * Initialize the widgets of the receiver, open the dialog
+ * and block the method until the dialog is closed by the user.
+ */
+void openModal() {
+ Shell dialog = getDialogShell();
+ Display display = dialog.getDisplay();
+
+ initializeWidgets();
+ setRGB(null);
+ openDialog();
+ while (dialog.isDisposed() == false && dialog.getVisible() == true) {
+ if (display.readAndDispatch() == false) {
+ display.sleep();
+ }
+ }
+}
+
+
+/**
+ * Insert the method's description here.
+ * Creation date: (08/05/99 12:34:43)
+ * @param newOkSelected boolean
+ */
+void setOkSelected(boolean newOkSelected) {
+ okSelected = newOkSelected;
+}
+/**
+ * Set the shell used as the dialog window.
+ */
+void setDialogShell(Shell shell) {
+ this.shell = shell;
+}
+
+
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java
new file mode 100755
index 0000000000..7ff8aa18ec
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java
@@ -0,0 +1,1196 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The combo class represents a selectable user interface object
+* that combines a text field and a list and issues notificiation
+* when an item is selected from the list.
+*
+* Styles
+*
+* SIMPLE,
+* DROP_DOWN,
+* READ_ONLY,
+*
+* Events
+*
+* Selection
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/* Class Definition */
+public /*final*/ class Combo extends Composite {
+ public static int LIMIT;
+
+ /*
+ * These values can be different on different platforms.
+ * Therefore they are not initialized in the declaration
+ * to stop the compiler from inlining.
+ */
+ static {
+ LIMIT = 0x7FFFFFFF;
+ }
+
+/**
+* Creates a new instance of the widget.
+*/
+public Combo (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds an item.
+* <p>
+* The item is placed at the end of the list.
+* Indexing is zero based.
+*
+* This operation can fail when the item cannot
+* be added in the OS.
+*
+* @param string the new item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the operation fails in the OS
+*/
+public void add (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.XmComboBoxAddItem(handle, xmString, -1, false);
+ OS.XmStringFree (xmString);
+}
+/**
+* Adds an item at an index.
+* <p>
+* The item is placed at an index in the list.
+* Indexing is zero based.
+*
+* This operation will fail when the index is
+* out of range or the item cannot be added in
+* the OS.
+*
+* @param string the new item
+* @param index the index for the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when the string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the item cannot be added
+*/
+public void add (String string, int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+
+ /*
+ * Feature in Motif. When an index is out of range,
+ * the list widget adds the item at the end. This
+ * behavior is not wrong but it is unwanted. The
+ * fix is to check the range before adding the item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index <= argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.XmComboBoxAddItem(handle, xmString, index + 1, false);
+ OS.XmStringFree (xmString);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addModifyListener (ModifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Modify, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ /*
+ * Feature in Windows. It is not possible to create
+ * a combo box that has a border using Windows style
+ * bits. All combo boxes draw their own border and
+ * do not use the standard Windows border styles.
+ * Therefore, no matter what style bits are specified,
+ * clear the BORDER bits so that the SWT style will
+ * match the Windows widget.
+ *
+ * The Windows behavior is currently implemented on
+ * all platforms.
+ */
+ style &= ~SWT.BORDER;
+
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
+ style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
+ if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
+ return style;
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+* Clears the current selection.
+* <p>
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void clearSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XmTextClearSelection (argList[1], OS.XtLastTimestampProcessed (xDisplay));
+}
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {
+ OS.XmNlist, 0,
+ OS.XmNtextField, 0,
+ OS.XmNitemCount, 0,
+ OS.XmNmarginWidth, 0,
+ OS.XmNshadowThickness, 0,
+ OS.XmNhighlightThickness, 0,
+ OS.XmNarrowSize, 0,
+ OS.XmNarrowSpacing, 0,
+ };
+ OS.XtGetValues(handle, argList, argList.length / 2);
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ result.request_mode = OS.CWWidth;
+ OS.XtQueryGeometry (argList[1], null, result);
+ int width = result.width, height = getTextHeight();
+ int[] argList2 = {OS.XmNmarginWidth, 0, OS.XmNshadowThickness, 0};
+ OS.XtGetValues(argList[3], argList2, argList2.length / 2);
+ if ((style & SWT.READ_ONLY) == 0) width += (2 * argList[7]);
+ if ((style & SWT.DROP_DOWN) != 0) {
+ width += argList[13] + argList[15];
+ } else {
+ int itemCount = (argList[5] == 0) ? 5 : argList[5];
+ height += (getItemHeight () * itemCount);
+ }
+ width += (2 * argList[9])
+ + (2 * argList[11])
+ + (2 * argList2[1])
+ + (2 * argList2[3]);
+ if (argList[5] == 0) width = DEFAULT_WIDTH;
+ if (hHint != SWT.DEFAULT) height = hHint;
+ if (wHint != SWT.DEFAULT) width = wHint;
+ Rectangle rect = computeTrim (0, 0, width, height);
+ return new Point (rect.width, rect.height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+
+ /*
+ * Feature in Motif. When items are added or removed
+ * from a combo, it may request and be granted, a new
+ * preferred size. This behavior is unwanted. The fix
+ * is to create a parent for the list that will disallow
+ * geometry requests.
+ */
+ formHandle = OS.XmCreateForm (parent.handle, null, null, 0);
+ if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int comboBoxType = OS.XmDROP_DOWN_COMBO_BOX;
+ if ((style & SWT.SIMPLE) != 0) {
+ comboBoxType = OS.XmCOMBO_BOX;
+ } else if ((style & SWT.READ_ONLY) != 0) {
+ comboBoxType = OS.XmDROP_DOWN_LIST;
+ }
+ int [] argList = {
+ OS.XmNcomboBoxType, comboBoxType,
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ OS.XmNresizable, 0,
+ };
+ handle = OS.XmCreateComboBox (formHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+/**
+* Deselects an item.
+* <p>
+* If the item at an index is selected, it is
+* deselected. If the item at an index is not
+* selected, it remains deselected. Indices
+* that are out of range are ignored. Indexing
+* is zero based.
+*
+* @param index the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselect (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) return;
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ if (OS.XmListPosSelected (argList[3], index + 1)) {
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (argList[1], new byte[1]);
+ OS.XmTextSetInsertionPosition (argList[1], 0);
+ display.setWarnings (warnings);
+ OS.XmListDeselectAllItems (argList[3]);
+ }
+}
+/**
+* Deselects all items.
+* <p>
+*
+* If an item is selected, it is deselected.
+* If an item is not selected, it remains unselected.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselectAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (argList[1], new byte[1]);
+ OS.XmTextSetInsertionPosition (argList[1], 0);
+ display.setWarnings(warnings);
+ OS.XmListDeselectAllItems (argList[3]);
+}
+
+
+/**
+* Gets an item at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be queried from
+* the OS.
+*
+* @param index the index of the item
+* @return the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+*/
+public String getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int ptr = argList [3] + (index * 4);
+ int [] buffer1 = new int [1];
+ OS.memmove (buffer1, ptr, 4);
+ ptr = buffer1 [0];
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ return decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+}
+/**
+* Gets the number of items.
+* <p>
+* This operation will fail if the number of
+* items could not be queried from the OS.
+*
+* @return the number of items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_COUNT)
+* when the operation fails
+*/
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the height of one item.
+* <p>
+* This operation will fail if the height of
+* one item could not be queried from the OS.
+*
+* @return the height of one item in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM_HEIGHT)
+* when the operation fails
+*/
+public int getItemHeight () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] listHandleArgs = {OS.XmNlist, 0};
+ OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2);
+ int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0};
+ OS.XtGetValues (listHandleArgs[1], argList, argList.length / 2);
+ int spacing = argList [1], highlight = argList [3];
+ /* Result is from empirical analysis on Linux and AIX */
+ return getFontHeight () + spacing + (2 * highlight);
+}
+/**
+* Gets the items.
+* <p>
+* This operation will fail if the items cannot
+* be queried from the OS.
+*
+* @return the items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+*/
+public String [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int items = argList [1], itemCount = argList [3];
+ int [] buffer1 = new int [1];
+ String [] result = new String [itemCount];
+ for (int i = 0; i < itemCount; i++) {
+ OS.memmove (buffer1, items, 4);
+ int ptr = buffer1 [0];
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result[i] = decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+ items += 4;
+ }
+ return result;
+}
+/**
+* Gets the selection.
+* <p>
+* @return a point representing the selection start and end
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] start = new int [1], end = new int [1];
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XmTextGetSelectionPosition (argList[1], start, end);
+ if (start [0] == end [0]) {
+ start [0] = end [0] = OS.XmTextGetInsertionPosition (argList[1]);
+ }
+ return new Point (start [0], end [0]);
+}
+/**
+* Gets the index of the selected item.
+* <p>
+* Indexing is zero based.
+* If no item is selected -1 is returned.
+*
+* @return the index of the selected item.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelectionIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ int [] argList = {OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ int index = OS.XmListGetKbdItemPos (argList[1]);
+ if (OS.XmListPosSelected (argList[1], index)) return index - 1;
+ int [] count = new int [1], positions = new int [1];
+ if (!OS.XmListGetSelectedPos (argList[1], positions, count)) return -1;
+ if (count [0] == 0) return -1;
+ int address = positions [0];
+ int [] indices = new int [1];
+ OS.memmove (indices, address, 4);
+ OS.XtFree (address);
+ return indices [0] - 1;
+}
+/**
+* Gets the widget text.
+* <p>
+* If the widget has no text, an empty string is returned.
+*
+* @return the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ int ptr = OS.XmTextGetString (argList[1]);
+ if (ptr == 0) return "";
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ return decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+}
+/**
+* Gets the height of the combo's text field.
+* <p>
+* The operation will fail if the height cannot
+* be queried from the OS.
+
+* @return the height of the combo's text field.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ERROR_CANNOT_GET_ITEM_HEIGHT)
+* when the operation fails
+*/
+public int getTextHeight () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if ((style & SWT.DROP_DOWN) != 0) {
+ /*
+ * Bug in MOTIF. For some reason, XtQueryGeometry ()
+ * returns the wrong height when the combo is not realized.
+ * The fix is to force the combo to be realized by forcing
+ * the shell to be realized.
+ */
+ if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ result.request_mode = OS.CWHeight;
+ OS.XtQueryGeometry (handle, null, result);
+ return result.height;
+ } else {
+ /* Calculate text field height. */
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int [] argList2 = {OS.XmNmarginHeight, 0};
+ OS.XtGetValues (argList[1], argList2, argList2.length / 2);
+ int height = getFontHeight ();
+ XRectangle rect = new XRectangle ();
+ OS.XmWidgetGetDisplayRect (argList[1], rect);
+ height += (rect.y * 2) + (2 * argList2[1]);
+
+ /* Add in combo box margins. */
+ int [] argList3 = {OS.XmNmarginHeight, 0, OS.XmNshadowThickness, 0, OS.XmNhighlightThickness, 0};
+ OS.XtGetValues(handle, argList3, argList3.length / 2);
+ height += (2 * argList3[1]) + (2 * argList3[3]) + (2 * argList3[5]);
+
+ return height;
+ }
+}
+/**
+* Gets the text limit.
+* <p>
+* @return the text limit
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTextLimit () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return OS.XmTextGetMaxLength (argList[1]);
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNselectionCallback, windowProc, SWT.Selection);
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, SWT.DefaultSelection);
+ OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, SWT.Modify);
+}
+/**
+* Gets the index of an item.
+* <p>
+* The list is searched starting at 0 until an
+* item is found that is equal to the search item.
+* If no item is found, -1 is returned. Indexing
+* is zero based.
+*
+* @param string the search item
+* @return the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) return -1;
+
+ int [] argList = {OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ int index = OS.XmListItemPos (argList[1], xmString);
+ OS.XmStringFree (xmString);
+ return index - 1;
+}
+/**
+* Gets the index of an item.
+* <p>
+* The widget is searched starting at start including
+* the end position until an item is found that
+* is equal to the search itenm. If no item is
+* found, -1 is returned. Indexing is zero based.
+*
+* @param string the search item
+* @param index the starting position
+* @return the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string, int start) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int items = argList [1], itemCount = argList [3];
+ if (!((0 <= start) && (start < itemCount))) return -1;
+ byte [] buffer1 = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer1);
+ if (xmString == 0) return -1;
+ int index = start;
+ items += start * 4;
+ int [] buffer2 = new int [1];
+ while (index < itemCount) {
+ OS.memmove (buffer2, items, 4);
+ if (OS.XmStringCompare (buffer2 [0], xmString)) break;
+ items += 4; index++;
+ }
+ OS.XmStringFree (xmString);
+ if (index == itemCount) return -1;
+ return index;
+}
+/**
+* Removes an item at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param index the index of the item
+* @return the selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+ /*
+ * Feature in Motif. An index out of range handled
+ * correctly by the list widget but causes an unwanted
+ * Xm Warning. The fix is to check the range before
+ * deleting an item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ OS.XmComboBoxDeletePos (handle, index + 1);
+}
+/**
+* Removes a range of items.
+* <p>
+* Indexing is zero based. The range of items
+* is from the start index up to and including
+* the end index.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (start > end) return;
+ /*
+ * Feature in Motif. An index out of range handled
+ * correctly by the list widget but causes an unwanted
+ * Xm Warning. The fix is to check the range before
+ * deleting an item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= start && start < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ int newEnd = Math.min (end, argList [1] - 1);
+ for (int i = start; i <= newEnd; i++) {
+ OS.XmComboBoxDeletePos (handle, start + 1);
+ }
+ if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
+}
+void register () {
+ super.register ();
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ WidgetTable.put(argList[1], this);
+}
+/**
+* Removes an item.
+* <p>
+* This operation will fail when the item
+* could not be removed from the OS.
+*
+* @param string the search item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
+
+ int [] argList = {OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int index = OS.XmListItemPos (argList[1], xmString);
+
+ OS.XmStringFree (xmString);
+ if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
+ OS.XmComboBoxDeletePos (handle, index);
+}
+/**
+* Removes all items.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void removeAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (argList[1], new byte[1]);
+ OS.XmTextSetInsertionPosition (argList[1], 0);
+ display.setWarnings(warnings);
+ OS.XmListDeselectAllItems (argList[3]);
+
+ for (int i = 0; i < argList[5]; i++) {
+ OS.XmComboBoxDeletePos(handle, 1);
+ }
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeModifyListener (ModifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Modify, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener (SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection,listener);
+}
+/**
+* Selects an item.
+* <p>
+* If the item at an index is not selected, it is
+* selected. Indices that are out of
+* range are ignored. Indexing is zero based.
+*
+* @param index the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void select (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) {
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (argList[1], new byte[1]);
+ OS.XmTextSetInsertionPosition (argList[1], 0);
+ display.setWarnings (warnings);
+ OS.XmListDeselectAllItems (argList[3]);
+ } else {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ int [] argList2 = {OS.XmNselectedPosition, index};
+ OS.XtSetValues(handle, argList2, argList2.length / 2);
+ }
+}
+/**
+* Sets the widget bounds.
+*/
+public void setBounds (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
+ super.setBounds (x, y, width, newHeight);
+}
+/**
+* Sets the text of an item.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be changed in
+* the OS.
+*
+* @param index the index for the item
+* @param string the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when items is null
+* @exception SWTError(ERROR_ITEM_NOT_MODIFIED)
+* when the operation fails
+*/
+public void setItem (int index, String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+ int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [3])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ boolean isSelected = OS.XmListPosSelected (argList[1], index + 1);
+ OS.XmListReplaceItemsPosUnselected (argList[1], new int [] {xmString}, 1, index + 1);
+ if (isSelected) OS.XmListSelectPos (argList[1], index + 1, false);
+ OS.XmStringFree (xmString);
+}
+/**
+* Sets all items.
+* <p>
+* @param items the array of items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when items is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the operation fails
+*/
+public void setItems (String [] items) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ if (items.length == 0) {
+ removeAll();
+ return;
+ }
+
+ int index = 0;
+ int [] table = new int [items.length];
+ while (index < items.length) {
+ String string = items [index];
+ if (string == null) break;
+ byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) break;
+ table [index++] = xmString;
+ }
+ int ptr = OS.XtMalloc (index * 4);
+ OS.memmove (ptr, table, index * 4);
+ int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
+ OS.XtFree (ptr);
+ if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
+}
+/**
+* Sets the new selection.
+* <p>
+* @param selection point representing the start and the end of the new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when selection is null
+*/
+public void setSelection (Point selection) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ /* Clear the highlight before setting the selection. */
+ int position = OS.XmTextGetLastPosition (argList[1]);
+
+ /*
+ * Bug in MOTIF. XmTextSetSelection () fails to set the
+ * selection when the receiver is not realized. The fix
+ * is to force the receiver to be realized by forcing the
+ * shell to be realized. If the receiver is realized before
+ * the shell, MOTIF fails to draw the text widget and issues
+ * lots of X BadDrawable errors.
+ */
+ if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
+
+ /* Set the selection. */
+ int xDisplay = OS.XtDisplay (argList[1]);
+ if (xDisplay == 0) return;
+ int nStart = Math.min (Math.max (Math.min (selection.x, selection.y), 0), position);
+ int nEnd = Math.min (Math.max (Math.max (selection.x, selection.y), 0), position);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetSelection (argList[1], nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
+
+ /* Force the i-beam to follow the highlight/selection. */
+ OS.XmTextSetInsertionPosition (argList[1], nEnd);
+ display.setWarnings(warnings);
+}
+/**
+* Sets the widget size.
+*/
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight () : height;
+ super.setSize (width, newHeight);
+}
+/**
+* Sets the widget text
+* <p>
+* @param string the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ if ((style & SWT.READ_ONLY) == 0) {
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) return;
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int index = OS.XmListItemPos (argList[3], xmString);
+ if (index > 0) {
+ /* The list contains the item. */
+ OS.XmComboBoxSelectItem(handle, xmString);
+ } else {
+ /* The list does not contain the item. */
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (argList[1], buffer);
+ OS.XmTextSetInsertionPosition (argList[1], 0);
+ display.setWarnings(warnings);
+ }
+ OS.XmStringFree (xmString);
+ /*
+ * Bug in Linux. When the widget is multi-line
+ * it does not send a Modify to notify the application
+ * that the text has changed. The fix is to send the event.
+ */
+ if (IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
+ }
+}
+/**
+* Sets the text limit
+* <p>
+* @param limit new text limit
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_BE_ZERO)
+* when limit is 0
+*/
+public void setTextLimit (int limit) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XmTextSetMaxLength (argList[1], limit);
+}
+
+void deregister () {
+ super.deregister ();
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ WidgetTable.remove (argList[1]);
+}
+
+/**
+ * Bug in Motif.
+ * Empty strings in the combo will cause GPFs if a) they
+ * are the only items in the combo or b) if they are
+ * included in an array which is set as the value of the
+ * combo's items resource. To protect against these GPFs,
+ * make sure that no empty strings are added to the combo.
+ * The solution is to add a space to empty strings or
+ * strings which are all spaces. This space is removed
+ * when answering the text of items which are all spaces.
+ */
+String encodeString(String string) {
+ for (int i = 0; i < string.length(); i++) {
+ if (string.charAt(i) != ' ') {
+ return string;
+ }
+ }
+ return string + ' ';
+}
+/**
+ * Bug in Motif.
+ * Empty strings in the combo will cause GPFs if a) they
+ * are the only items in the combo or b) if they are
+ * included in an array which is set as the value of the
+ * combo's items resource. To protect against these GPFs,
+ * make sure that no empty strings are added to the combo.
+ * The solution is to add a space to empty strings or
+ * strings which include only spaces. A space is removed
+ * when answering the text of items which are all spaces.
+ */
+String decodeString(String string) {
+ if (string.length() == 0) return string;
+
+ for (int i = 0; i < string.length(); i++) {
+ if (string.charAt(i) != ' ') {
+ return string;
+ }
+ }
+ return string.substring(0, string.length() - 1);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
new file mode 100755
index 0000000000..5177c3bccd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
@@ -0,0 +1,439 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The composite class represents a user interface object
+* that contains other widgets.
+*
+* Styles
+*
+* H_SCROLL, V_SCROLL
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/* Class Definition */
+public class Composite extends Scrollable {
+ Layout layout;
+ int damagedRegion;
+
+Composite () {
+ /* Do nothing */
+}
+public Composite (Composite parent, int style) {
+ super (parent, style);
+}
+Control [] _getChildren () {
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return new Control [0];
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ Control [] children = new Control [count];
+ int i = 0, j = 0;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle != 0) {
+ Widget widget = WidgetTable.get (handle);
+ if (widget != null && widget != this) {
+ if (widget instanceof Control) {
+ children [j++] = (Control) widget;
+ }
+ }
+ }
+ i++;
+ }
+ if (i == j) return children;
+ Control [] newChildren = new Control [j];
+ System.arraycopy (children, 0, newChildren, 0, j);
+ return newChildren;
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Point size;
+ if (layout != null) {
+ if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } else {
+ size = new Point (wHint, hHint);
+ }
+ } else {
+ size = minimumSize ();
+ }
+ if (size.x == 0) size.x = DEFAULT_WIDTH;
+ if (size.y == 0) size.y = DEFAULT_HEIGHT;
+ if (wHint != SWT.DEFAULT) size.x = wHint;
+ if (hHint != SWT.DEFAULT) size.y = hHint;
+ Rectangle trim = computeTrim (0, 0, size.x, size.y);
+ return new Point (trim.width, trim.height);
+}
+protected void checkSubclass () {
+ /* Do nothing - Subclassing is allowed */
+}
+void createHandle (int index) {
+ state |= HANDLE | CANVAS;
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
+ int border = (style & SWT.BORDER) != 0 ? 1 : 0;
+ int [] argList = {
+ OS.XmNborderWidth, border,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ Display display = getDisplay ();
+ OS.XtOverrideTranslations (handle, display.tabTranslations);
+ OS.XtOverrideTranslations (handle, display.arrowTranslations);
+ } else {
+ createScrolledHandle (parent.handle);
+ }
+}
+void createScrolledHandle (int topHandle) {
+ scrolledHandle = OS.XmCreateMainWindow (topHandle, null, null, 0);
+ if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
+ int [] argList1 = {
+ OS.XmNmarginWidth, 3,
+ OS.XmNmarginHeight, 3,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNshadowType, OS.XmSHADOW_IN,
+ OS.XmNshadowThickness, 2,
+ };
+ formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2);
+ if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int [] argList2 = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ OS.XmNresizable, 0,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
+ } else {
+ int [] argList = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList, argList.length / 2);
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ Display display = getDisplay ();
+ OS.XtOverrideTranslations (handle, display.tabTranslations);
+ OS.XtOverrideTranslations (handle, display.arrowTranslations);
+}
+int defaultBackground () {
+ return getDisplay ().compositeBackground;
+}
+int defaultForeground () {
+ return getDisplay ().compositeForeground;
+}
+public boolean forceFocus () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Control [] children = _getChildren ();
+ int [] traversals = new int [children.length];
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ for (int i=0; i<children.length; i++) {
+ OS.XtGetValues (children [i].handle, argList, argList.length / 2);
+ traversals [i] = argList [1];
+ argList [1] = 0;
+ OS.XtSetValues (children [i].handle, argList, argList.length / 2);
+ }
+ boolean result = super.forceFocus ();
+ for (int i=0; i<children.length; i++) {
+ argList [1] = traversals [i];
+ OS.XtSetValues (children [i].handle, argList, argList.length / 2);
+ }
+ return result;
+}
+public Control [] getChildren () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return _getChildren ();
+}
+int getChildrenCount () {
+ // BOGUS - could count non-registered children or gadgets
+ int [] argList = {OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+public Layout getLayout () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return layout;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ if ((state & CANVAS) != 0) {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddEventHandler (handle, 0, true, windowProc, -1);
+ }
+}
+
+/**
+* Lays out the children.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void layout () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ layout (true);
+}
+public void layout (boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (layout == null) return;
+ int count = getChildrenCount ();
+ if (count == 0) return;
+ layout.layout (this, changed);
+}
+Point minimumSize () {
+ Control [] children = _getChildren ();
+ int width = 0, height = 0;
+ for (int i=0; i<children.length; i++) {
+ Rectangle rect = children [i].getBounds ();
+ width = Math.max (width, rect.x + rect.width);
+ height = Math.max (height, rect.y + rect.height);
+ }
+ return new Point (width, height);
+}
+void moveAbove (int handle1, int handle2) {
+ if (handle1 == handle2) return;
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return;
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ if (handle2 == 0) handle2 = handles [0];
+ int i = 0, index1 = -1, index2 = -1;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle == handle1) index1 = i;
+ if (handle == handle2) index2 = i;
+ if (index1 != -1 && index2 != -1) break;
+ i++;
+ }
+ if (index1 == -1 || index2 == -1) return;
+ if (index1 == index2) return;
+ if (index1 < index2) {
+ System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1);
+ handles [index2 - 1] = handle1;
+ } else {
+ System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2);
+ handles [index2] = handle1;
+ }
+ OS.memmove (ptr, handles, count * 4);
+}
+void moveBelow (int handle1, int handle2) {
+ if (handle1 == handle2) return;
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return;
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ if (handle2 == 0) handle2 = handles [count - 1];
+ int i = 0, index1 = -1, index2 = -1;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle == handle1) index1 = i;
+ if (handle == handle2) index2 = i;
+ if (index1 != -1 && index2 != -1) break;
+ i++;
+ }
+ if (index1 == -1 || index2 == -1) return;
+ if (index1 == index2) return;
+ if (index1 < index2) {
+ System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1);
+ handles [index2] = handle1;
+ } else {
+ System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1);
+ handles [index2 + 1] = handle1;
+ }
+ OS.memmove (ptr, handles, count * 4);
+}
+
+int processNonMaskable (int callData) {
+ if ((state & CANVAS) != 0) {
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, callData, XExposeEvent.sizeof);
+ if (xEvent.type == OS.GraphicsExpose) processPaint (callData);
+ }
+ return 0;
+}
+int processPaint (int callData) {
+ if ((state & CANVAS) == 0) {
+ return super.processPaint (callData);
+ }
+ if (!hooks (SWT.Paint)) return 0;
+ if ((style & SWT.NO_MERGE_PAINTS) != 0) {
+ return super.processPaint (callData);
+ }
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, callData, XExposeEvent.sizeof);
+ int exposeCount = xEvent.count;
+ if (damagedRegion == 0 && exposeCount == 0) {
+ XAnyEvent event = new XAnyEvent ();
+ Display display = getDisplay ();
+ display.exposeCount = 0;
+ int checkExposeProc = display.checkExposeProc;
+ OS.XCheckIfEvent (xEvent.display, event, checkExposeProc, xEvent.window);
+ if (display.exposeCount == 0) return super.processPaint (callData);
+ exposeCount = display.exposeCount;
+ }
+ if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
+ OS.XtAddExposureToRegion (callData, damagedRegion);
+ if (exposeCount != 0) return 0;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ Event event = new Event ();
+ GC gc = event.gc = new GC (this);
+ OS.XSetRegion (xDisplay, gc.handle, damagedRegion);
+ XRectangle rect = new XRectangle ();
+ OS.XClipBox (damagedRegion, rect);
+ OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+ event.time = OS.XtLastTimestampProcessed (xDisplay);
+ event.x = rect.x; event.y = rect.y;
+ event.width = rect.width; event.height = rect.height;
+ sendEvent (SWT.Paint, event);
+ gc.dispose ();
+ event.gc = null;
+ return 0;
+}
+
+void propagateChildren (boolean enabled) {
+ super.propagateChildren (enabled);
+ Control [] children = _getChildren ();
+ for (int i = 0; i < children.length; i++) {
+ Control child = children [i];
+ if (child.getEnabled ()) {
+ child.propagateChildren (enabled);
+ }
+ }
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ children [i].realizeChildren ();
+ }
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ int flags = 0;
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ if ((style & SWT.NO_BACKGROUND) != 0) {
+ flags |= OS.CWBackPixmap;
+ attributes.background_pixmap = OS.None;
+ }
+ if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
+ flags |= OS.CWBitGravity;
+ attributes.bit_gravity = OS.ForgetGravity;
+ }
+ if (flags != 0) {
+ OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes);
+ }
+ }
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ if (!all) return;
+ Control [] children = _getChildren ();
+ for (int i = 0; i < children.length; i++) {
+ Control child = children [i];
+ Point location = child.getClientLocation ();
+ child.redrawWidget (x - location.x, y - location.y, width, height, all);
+ }
+}
+void releaseChildren () {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (!child.isDisposed ()) {
+ child.releaseWidget ();
+ child.releaseHandle ();
+ }
+ }
+}
+void releaseWidget () {
+ releaseChildren ();
+ super.releaseWidget ();
+ layout = null;
+ if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) != 0) {
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.background_pixmap = OS.None;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes);
+ }
+ }
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ if (layout != null) layout (false);
+}
+public void setLayout (Layout layout) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.layout = layout;
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ if (layout != null) layout (false);
+}
+int traversalCode () {
+ if ((state & CANVAS) != 0 && hooks (SWT.KeyDown)) return 0;
+ return super.traversalCode ();
+}
+boolean traverseMnemonic (char key) {
+ if (super.traverseMnemonic (key)) return true;
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.traverseMnemonic (key)) return true;
+ }
+ return false;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
new file mode 100755
index 0000000000..c1a7ed8a6f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
@@ -0,0 +1,1813 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The widget class is the abstract superclass of all
+* user interface objects. All widgets can be created,
+* disposed and support events.
+*
+* Styles
+*
+* BORDER
+* CLIP_CHILDREN, CLIP_SIBLINGS
+*
+* Events
+*
+* KeyDown, KeyUp,
+* MouseDown, MouseUp, MouseMove,
+* DoubleClick,
+* Paint,
+* Move, Resize,
+* FocusIn, FocusOut,
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
+/* Class Definition */
+public abstract class Control extends Widget implements Drawable {
+ Composite parent;
+ int fontList;
+ Menu menu;
+ String toolTipText;
+ Object layoutData;
+Control () {
+ /* Do nothing */
+}
+public Control (Composite parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ createWidget (0);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addControlListener(ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Resize,typedListener);
+ addListener (SWT.Move,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addFocusListener(FocusListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.FocusIn,typedListener);
+ addListener(SWT.FocusOut,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Help, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addKeyListener(KeyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.KeyUp,typedListener);
+ addListener(SWT.KeyDown,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addMouseListener(MouseListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.MouseDown,typedListener);
+ addListener(SWT.MouseUp,typedListener);
+ addListener(SWT.MouseDoubleClick,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* <li>ERROR_NULL_ARGUMENT when listener is null</li>
+* </ul>
+*/
+public void addMouseTrackListener (MouseTrackListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.MouseEnter,typedListener);
+ addListener (SWT.MouseExit,typedListener);
+ addListener (SWT.MouseHover,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addMouseMoveListener(MouseMoveListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.MouseMove,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addPaintListener(PaintListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.Paint,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* <li>ERROR_NULL_ARGUMENT when listener is null</li>
+* </ul>
+*/
+public void addTraverseListener (TraverseListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Traverse,typedListener);
+}
+public Point computeSize (int wHint, int hHint) {
+ return computeSize (wHint, hHint, true);
+}
+/**
+* Computes the preferred size.
+* <p>
+* @param wHint the width hint (can be SWT.DEFAULT)
+* @param hHint the height hint (can be SWT.DEFAULT)
+* @param changed the changed hint (for layouts)
+* @return the preferred size of the widget.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = DEFAULT_WIDTH;
+ int height = DEFAULT_HEIGHT;
+ if (wHint != SWT.DEFAULT) width = wHint;
+ if (hHint != SWT.DEFAULT) height = hHint;
+ int border = getBorderWidth ();
+ width += border * 2;
+ height += border * 2;
+ return new Point (width, height);
+}
+
+void createWidget (int index) {
+ super.createWidget (index);
+ setZOrder ();
+ realizeChildren ();
+}
+int defaultBackground () {
+ return getDisplay ().defaultBackground;
+}
+int defaultFont () {
+ return getDisplay ().defaultFontList;
+}
+int defaultForeground () {
+ return getDisplay ().defaultForeground;
+}
+void enableHandle (boolean enabled, int widgetHandle) {
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+}
+void enableWidget (boolean enabled) {
+ enableHandle (enabled, handle);
+}
+char findMnemonic (String string) {
+ int index = 0;
+ int length = string.length ();
+ do {
+ while ((index < length) && (string.charAt (index) != Mnemonic)) index++;
+ if (++index >= length) return '\0';
+ if (string.charAt (index) != Mnemonic) return string.charAt (index);
+ index++;
+ } while (index < length);
+ return '\0';
+}
+int fontHandle () {
+ return handle;
+}
+public boolean forceFocus () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Decorations shell = menuShell ();
+ shell.setSavedFocus (this);
+ shell.bringToTop ();
+ return OS.XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
+}
+public Color getBackground () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return Color.motif_new (getDisplay (), getXColor (getBackgroundPixel ()));
+}
+int getBackgroundPixel () {
+ int [] argList = {OS.XmNbackground, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+public int getBorderWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ return argList [1];
+}
+public Rectangle getBounds () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ int borders = argList [9] * 2;
+ return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders);
+}
+Point getClientLocation () {
+ short [] handle_x = new short [1], handle_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y);
+ short [] topHandle_x = new short [1], topHandle_y = new short [1];
+ OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y);
+ return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]);
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (topHandle (), argList, argList.length / 2);
+ return argList [1] != 0;
+}
+public Font getFont () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return Font.motif_new (getDisplay (), getFontList ());
+}
+
+int getFontAscent () {
+ int fontList = getFontList ();
+
+ /* Create a font context to iterate over each element in the font list */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, fontList)) {
+ error (SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer [0];
+
+ /* Values discovering during iteration */
+ int ascent = 0;
+ XFontStruct fontStruct = new XFontStruct ();
+ int fontListEntry;
+ int [] fontStructPtr = new int [1];
+ int [] fontNamePtr = new int [1];
+
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
+ if (buffer [0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
+ int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ if (fontAscent > ascent) ascent = fontAscent;
+ } else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int [nFonts];
+ OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
+
+ /* Go through each fontStruct in the font set */
+ for (int i=0; i<nFonts; i++) {
+ OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
+ int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ if (fontAscent > ascent) ascent = fontAscent;
+ }
+ }
+ }
+
+ OS.XmFontListFreeFontContext (context);
+ return ascent;
+}
+
+int getFontHeight () {
+ int fontList = getFontList ();
+
+ /* Create a font context to iterate over each element in the font list */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, fontList)) {
+ error (SWT.ERROR_NO_HANDLES);
+ }
+ int context = buffer [0];
+
+ /* Values discovering during iteration */
+ int height = 0;
+ XFontStruct fontStruct = new XFontStruct ();
+ int fontListEntry;
+ int [] fontStructPtr = new int [1];
+ int [] fontNamePtr = new int [1];
+
+ /* Go through each entry in the font list. */
+ while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
+ int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
+ if (buffer [0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
+ int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
+ int fontHeight = fontAscent + fontDescent;
+ if (fontHeight > height) height = fontHeight;
+ } else {
+ /* FontList contains a fontSet */
+ int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
+ int [] fontStructs = new int [nFonts];
+ OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
+
+ /* Go through each fontStruct in the font set */
+ for (int i=0; i<nFonts; i++) {
+ OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
+ int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
+ int fontHeight = fontAscent + fontDescent;
+ if (fontHeight > height) height = fontHeight;
+ }
+ }
+ }
+
+ OS.XmFontListFreeFontContext (context);
+ return height;
+}
+int getFontList () {
+ int fontHandle = fontHandle ();
+ int [] argList = {OS.XmNfontList, 0};
+ OS.XtGetValues (fontHandle, argList, argList.length / 2);
+ if (argList [1] != 0) return argList [1];
+ if (fontList == 0) fontList = defaultFont ();
+ return fontList;
+}
+public Color getForeground () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return Color.motif_new (getDisplay (), getXColor (getForegroundPixel ()));
+}
+int getForegroundPixel () {
+ int [] argList = {OS.XmNforeground, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+public Object getLayoutData () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return layoutData;
+}
+public Point getLocation () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ return new Point ((short) argList [1], (short) argList [3]);
+}
+public Menu getMenu () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return menu;
+}
+public Composite getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+Control [] getPath () {
+ int count = 0;
+ Shell shell = getShell ();
+ Control control = this;
+ while (control != shell) {
+ count++;
+ control = control.parent;
+ }
+ control = this;
+ Control [] result = new Control [count];
+ while (control != shell) {
+ result [--count] = control;
+ control = control.parent;
+ }
+ return result;
+}
+public Shell getShell () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getShell ();
+}
+public Point getSize () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ int borders = argList [5] * 2;
+ return new Point (argList [1] + borders, argList [3] + borders);
+}
+/**
+* Gets the tool tip text.
+* <p>
+* @return the tool tip text.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getToolTipText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return toolTipText;
+}
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNmappedWhenManaged, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+XColor getXColor (int pixel) {
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return null;
+ int [] argList = {OS.XmNcolormap, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int colormap = argList [1];
+ if (colormap == 0) return null;
+ XColor color = new XColor ();
+ color.pixel = pixel;
+ OS.XQueryColor (display, colormap, color);
+ return color;
+}
+boolean hasFocus () {
+ return this == getDisplay ().getFocusControl ();
+}
+void hookEvents () {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, SWT.KeyDown);
+ OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, SWT.KeyUp);
+ OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, SWT.MouseDown);
+ OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, SWT.MouseUp);
+ OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, SWT.MouseMove);
+ OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, SWT.MouseEnter);
+ OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, SWT.MouseExit);
+ OS.XtAddEventHandler (handle, OS.ExposureMask, false, windowProc, SWT.Paint);
+ OS.XtAddEventHandler (handle, OS.FocusChangeMask, false, windowProc, SWT.FocusIn);
+ OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, SWT.Help);
+}
+int inputContext () {
+ return getShell ().inputContext ();
+}
+public int internal_new_GC (GCData data) {
+ if (!OS.XtIsRealized (handle)) {
+ int xtParent = handle;
+ while ((OS.XtParent (xtParent) != 0) && !OS.XtIsSubclass (xtParent, OS.ShellWidgetClass ())) {
+ xtParent = OS.XtParent (xtParent);
+ }
+ OS.XtRealizeWidget (xtParent);
+ }
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
+ if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ OS.XSetGraphicsExposures (xDisplay, xGC, false);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNcolormap, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (data != null) {
+ data.device = getDisplay ();
+ data.display = xDisplay;
+ data.drawable = xWindow;
+ data.foreground = argList [1];
+ data.background = argList [3];
+ data.fontList = getFontList ();
+ data.colormap = argList [5];
+ }
+ return xGC;
+}
+public void internal_dispose_GC (int xGC, GCData data) {
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ OS.XFreeGC (xDisplay, xGC);
+}
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getEnabled () && parent.isEnabled ();
+}
+public boolean isFocusControl () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return hasFocus ();
+}
+public boolean isReparentable () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return false;
+}
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getVisible () && parent.isVisible ();
+}
+void manageChildren () {
+ OS.XtSetMappedWhenManaged (handle, false);
+ OS.XtManageChild (handle);
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XtResizeWidget (handle, 1, 1, argList [1]);
+ OS.XtSetMappedWhenManaged (handle, true);
+}
+Decorations menuShell () {
+ return parent.menuShell ();
+}
+boolean mnemonicHit () {
+ return false;
+}
+boolean mnemonicMatch (char key) {
+ return false;
+}
+public void moveAbove (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setZOrder (control, true);
+}
+public void moveBelow (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setZOrder (control, false);
+}
+/**
+* Packs the widget.
+* <p>
+* Packing a widget causes it to be resized to the
+* preferred size for the widget. For a composite,
+* this involves computing the preferred size from
+* the layout.
+*
+* @see Control#computeSize(int, int)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void pack () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ pack (true);
+}
+/**
+* Packs the widget.
+* <p>
+* Packing a widget causes it to be resized to the
+* preferred size for the widget. For a composite,
+* this involves computing the preferred size from
+* the layout.
+*
+* @param changed the changed hint (for layouts)
+*
+* @see Control#computeSize(int, int)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void pack (boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
+}
+int processDefaultSelection (int callData) {
+ postEvent (SWT.DefaultSelection);
+ return 0;
+}
+int processFocusIn () {
+ sendEvent (SWT.FocusIn);
+// IsDBLocale ifTrue: [self killImeFocus].
+ return 0;
+}
+int processFocusOut () {
+ sendEvent (SWT.FocusOut);
+// IsDBLocale ifTrue: [self killImeFocus].
+ return 0;
+}
+int processHelp (int callData) {
+ sendHelpEvent (callData);
+ return 0;
+}
+int processKeyDown (int callData) {
+ XKeyEvent xEvent = new XKeyEvent ();
+ OS.memmove (xEvent, callData, XKeyEvent.sizeof);
+ sendKeyEvent (SWT.KeyDown, xEvent);
+ return 0;
+}
+int processKeyUp (int callData) {
+ XKeyEvent xEvent = new XKeyEvent ();
+ OS.memmove (xEvent, callData, XKeyEvent.sizeof);
+ sendKeyEvent (SWT.KeyUp, xEvent);
+ return 0;
+}
+int processModify (int callData) {
+ sendEvent (SWT.Modify);
+ return 0;
+}
+int processMouseDown (int callData) {
+ getDisplay ().hideToolTip ();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent.state, xEvent);
+ if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
+ sendEvent (SWT.DragDetect);
+ }
+ if (xEvent.button == 3 && menu != null) {
+ OS.XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
+ menu.setVisible (true);
+ }
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay != 0) {
+ Display display = getDisplay ();
+ int clickTime = OS.XtGetMultiClickTime (xDisplay);
+ int lastTime = display.lastTime, eventTime = xEvent.time;
+ int lastButton = display.lastButton, eventButton = xEvent.button;
+ if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
+ sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent.state, xEvent);
+ }
+ if (eventTime == 0) eventTime = 1;
+ display.lastTime = eventTime;
+ display.lastButton = eventButton;
+ }
+ return 0;
+}
+int processMouseEnter (int callData) {
+ XCrossingEvent xEvent = new XCrossingEvent ();
+ OS.memmove (xEvent, callData, XCrossingEvent.sizeof);
+ if (xEvent.mode != OS.NotifyNormal) return 0;
+ if (xEvent.subwindow != 0) return 0;
+ Event event = new Event ();
+ event.x = xEvent.x;
+ event.y = xEvent.y;
+ postEvent (SWT.MouseEnter, event);
+ return 0;
+}
+int processMouseMove (int callData) {
+ Display display = getDisplay ();
+ display.addMouseHoverTimeOut (handle);
+ XMotionEvent xEvent = new XMotionEvent ();
+ OS.memmove (xEvent, callData, XMotionEvent.sizeof);
+ sendMouseEvent (SWT.MouseMove, 0, xEvent.state, xEvent);
+ return 0;
+}
+int processMouseExit (int callData) {
+ Display display = getDisplay ();
+ display.removeMouseHoverTimeOut ();
+ display.hideToolTip ();
+
+ XCrossingEvent xEvent = new XCrossingEvent ();
+ OS.memmove (xEvent, callData, XCrossingEvent.sizeof);
+ if (xEvent.mode != OS.NotifyNormal) return 0;
+ if (xEvent.subwindow != 0) return 0;
+ Event event = new Event ();
+ event.x = xEvent.x;
+ event.y = xEvent.y;
+ postEvent (SWT.MouseExit, event);
+ return 0;
+}
+int processMouseUp (int callData) {
+ getDisplay ().hideToolTip ();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent.state, xEvent);
+ return 0;
+}
+int processPaint (int callData) {
+ if (!hooks (SWT.Paint)) return 0;
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, callData, XExposeEvent.sizeof);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ Event event = new Event ();
+ event.count = xEvent.count;
+ event.time = OS.XtLastTimestampProcessed (xDisplay);
+ event.x = xEvent.x; event.y = xEvent.y;
+ event.width = xEvent.width; event.height = xEvent.height;
+ GC gc = event.gc = new GC (this);
+ XRectangle rect = new XRectangle ();
+ rect.x = (short) xEvent.x; rect.y = (short) xEvent.y;
+ rect.width = (short) xEvent.width; rect.height = (short) xEvent.height;
+ OS.XSetClipRectangles (xDisplay, gc.handle, 0, 0, rect, 1, OS.Unsorted);
+ sendEvent (SWT.Paint, event);
+ if (!gc.isDisposed ()) gc.dispose ();
+ event.gc = null;
+ return 0;
+}
+int processSelection (int callData) {
+ postEvent (SWT.Selection);
+ return 0;
+}
+int processSetFocus (int callData) {
+
+ /* Get the focus change event */
+ XFocusChangeEvent xEvent = new XFocusChangeEvent ();
+ OS.memmove (xEvent, callData, XFocusChangeEvent.sizeof);
+
+ /* Ignore focus changes caused by grabbing and ungrabing. */
+ if (xEvent.mode != OS.NotifyNormal) return 0;
+
+ /* Only process focus callbacks between windows. */
+ if (xEvent.detail != OS.NotifyAncestor &&
+ xEvent.detail != OS.NotifyInferior &&
+ xEvent.detail != OS.NotifyNonlinear) return 0;
+
+ /*
+ * Ignore focus change events when the window getting or losing
+ * focus is a menu. Because XmGetFocusWidget() does not answer
+ * the menu shell (it answers the menu parent), it is necessary
+ * to use XGetInputFocus() to get the real X focus window.
+ */
+ int xDisplay = xEvent.display;
+ if (xDisplay == 0) return 0;
+ int [] unused = new int [1], xWindow = new int [1];
+ OS.XGetInputFocus (xDisplay, xWindow, unused);
+ if (xWindow [0] != 0) {
+ int widget = OS.XtWindowToWidget (xDisplay, xWindow [0]);
+ if (widget != 0 && OS.XtClass (widget) == OS.XmMenuShellWidgetClass ()) return 0;
+ }
+
+ /* Process the focus change for the widget. */
+ if (xEvent.type == OS.FocusIn) {
+ int result = processFocusIn ();
+ int index = 0;
+ Shell shell = getShell ();
+ Control [] focusIn = getPath ();
+ Control lastFocus = shell.lastFocus;
+ if (lastFocus != null) {
+ if (!lastFocus.isDisposed ()) {
+ Control [] focusOut = lastFocus.getPath ();
+ int length = Math.min (focusIn.length, focusOut.length);
+ while (index < length) {
+ if (focusIn [index] != focusOut [index]) break;
+ index++;
+ }
+ for (int i=focusOut.length-1; i>=index; --i) {
+ focusOut [i].sendEvent (SWT.Deactivate);
+ }
+ }
+ shell.lastFocus = null;
+ }
+ for (int i=focusIn.length-1; i>=index; --i) {
+ focusIn [i].sendEvent (SWT.Activate);
+ }
+ return result;
+ }
+ if (xEvent.type == OS.FocusOut) {
+ int result = processFocusOut ();
+ Shell shell = getShell ();
+ shell.lastFocus = this;
+ Display display = getDisplay ();
+ Control focusControl = display.getFocusControl ();
+ if (focusControl == null || shell != focusControl.getShell ()) {
+ Control [] focusOut = getPath ();
+ for (int i=focusOut.length-1; i>=0; --i) {
+ focusOut [i].sendEvent (SWT.Deactivate);
+ }
+ shell.lastFocus = null;
+ }
+ return result;
+ }
+ return 0;
+}
+void propagateChildren (boolean enabled) {
+ propagateWidget (enabled);
+}
+void propagateHandle (boolean enabled, int widgetHandle) {
+ int xDisplay = OS.XtDisplay (widgetHandle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (widgetHandle);
+ if (xWindow == 0) return;
+ int event_mask = OS.XtBuildEventMask (widgetHandle);
+ int do_not_propagate_mask = OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask;
+ if (!enabled) {
+ event_mask &= ~do_not_propagate_mask;
+ do_not_propagate_mask = 0;
+ }
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.event_mask = event_mask;
+ attributes.do_not_propagate_mask = do_not_propagate_mask;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWDontPropagate | OS.CWEventMask, attributes);
+ int [] argList = {OS.XmNtraversalOn, enabled ? 1 : 0};
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+}
+void propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+}
+void realizeChildren () {
+ if (!isEnabled ()) propagateWidget (false);
+}
+public void redraw () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ redrawWidget (0, 0, 0, 0, false);
+}
+public void redraw (int x, int y, int width, int height, boolean all) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (x == 0 && y == 0 && width == 0 && height == 0) return;
+ redrawWidget (x, y, width, height, all);
+}
+void redrawHandle (int x, int y, int width, int height, int widgetHandle) {
+ int display = OS.XtDisplay (widgetHandle);
+ if (display == 0) return;
+ int window = OS.XtWindow (widgetHandle);
+ if (window == 0) return;
+ int [] argList = {OS.XmNborderWidth, 0, OS.XmNborderColor, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ if (argList [1] != 0) {
+ /* Force the border to repaint by setting the color */
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+ }
+ OS.XClearArea (display, window, x, y, width, height, true);
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ redrawHandle (x, y, width, height, handle);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ Display display = getDisplay ();
+ display.releaseToolTipHandle (handle);
+ toolTipText = null;
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ menu = null;
+/*
+ "Release the IME."
+ self isMenu ifFalse: [
+ handle xtIsWidget ifTrue: [
+ handle xmImUnregister.
+
+ "Bug in X. On Solaris only, destroying the window that has IME focus causes
+ a segment fault. The fix is to set focus to the IME client window (typically
+ the shell) when the receiver is being destroyed. Destroying the shell window
+ does not have the problem. Note that this fix is not necessary on AIX."
+ (xIC := self inputContext) == nil ifFalse: [
+ (window := handle xtWindow) isNull ifFalse: [
+ xIC xGetICValues: XNFocusWindow with: (buffer := ByteArray new: 4) with: 0.
+ (buffer uint32At: 0) = window asInteger ifTrue: [
+ xIC xGetICValues: XNClientWindow with: (buffer := ByteArray new: 4) with: 0.
+ xIC
+ xUnsetICFocus;
+ xSetICValues: XNFocusWindow with: (buffer uint32At: 0) with: 0;
+ xSetICFocus]]]]].
+*/
+ parent = null;
+ layoutData = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeControlListener (ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Move, listener);
+ eventTable.unhook (SWT.Resize, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeFocusListener(FocusListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.FocusIn, listener);
+ eventTable.unhook(SWT.FocusOut, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Help, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeKeyListener(KeyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.KeyUp, listener);
+ eventTable.unhook(SWT.KeyDown, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeMouseListener(MouseListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.MouseDown, listener);
+ eventTable.unhook(SWT.MouseUp, listener);
+ eventTable.unhook(SWT.MouseDoubleClick, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeMouseMoveListener(MouseMoveListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.MouseMove, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* <li>ERROR_NULL_ARGUMENT when listener is null</li>
+* </ul>
+*/
+public void removeMouseTrackListener(MouseTrackListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.MouseEnter, listener);
+ eventTable.unhook (SWT.MouseExit, listener);
+ eventTable.unhook (SWT.MouseHover, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removePaintListener(PaintListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Paint, listener);
+}/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* <li>ERROR_NULL_ARGUMENT when listener is null</li>
+* </ul>
+*/
+public void removeTraverseListener(TraverseListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Traverse, listener);
+}
+void sendHelpEvent (int callData) {
+ Control control = this;
+ while (control != null) {
+ if (control.hooks (SWT.Help)) {
+ control.postEvent (SWT.Help);
+ return;
+ }
+ control = control.parent;
+ }
+}
+void sendKeyEvent (int type, XKeyEvent xEvent) {
+
+ /* Look up the keysym and character(s) */
+ byte [] buffer;
+ boolean isVirtual = false;
+ int [] keysym = new int [1], status = new int [1];
+ if (xEvent.keycode != 0) {
+ buffer = new byte [1];
+ isVirtual = OS.XLookupString (xEvent, buffer, buffer.length, keysym, status) == 0;
+ } else {
+ int size = 0;
+ buffer = new byte [2];
+ int xIC = inputContext ();
+ if (xIC == 0) {
+ size = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, keysym, status);
+ if (status [0] == OS.XBufferOverflow) {
+ buffer = new byte [size];
+ size = OS.XmImMbLookupString (handle, xEvent, buffer, size, keysym, status);
+ }
+ } else {
+ size = OS.XmbLookupString (xIC, xEvent, buffer, buffer.length, keysym, status);
+ if (status [0] == OS.XBufferOverflow) {
+ buffer = new byte [size];
+ size = OS.XmbLookupString (xIC, xEvent, buffer, size, keysym, status);
+ }
+ }
+ if (size == 0) return;
+ }
+
+ /*
+ * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
+ * translated correctly by XLookupString(). They are mapped
+ * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
+ * look for these values explicitly and correct them.
+ */
+ if (IsSunOS) {
+ if ((keysym [0] == 0x1005FF10) || (keysym [0] == 0x1005FF11)) {
+ if (keysym [0] == 0x1005FF10) keysym [0] = OS.XK_F11;
+ if (keysym [0] == 0x1005FF11) keysym [0] = OS.XK_F12;
+ }
+ }
+
+ /*
+ * Bug in MOTIF. On Solaris only, their is garbage in the
+ * high 16-bits for Keysyms such as XK_Down. Since Keysyms
+ * must be 16-bits to fit into a Character, mask away the
+ * high 16-bits on all platforms.
+ */
+ keysym [0] &= 0xFFFF;
+
+ /* Convert from MBCS to UNICODE and send the event */
+ char [] result = Converter.mbcsToWcs (null, buffer);
+ for (int i=0; i<result.length; i++) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.character = result [i];
+ if (isVirtual) event.keyCode = Display.translateKey (keysym [0]);
+ if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
+ if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
+ if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
+ if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ postEvent (type, event);
+ }
+}
+void sendMouseEvent (int type, int button, int mask, XWindowEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.button = button;
+ event.x = xEvent.x; event.y = xEvent.y;
+ if ((mask & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
+ if ((mask & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
+ if ((mask & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
+ if ((mask & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((mask & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((mask & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ postEvent (type, event);
+}
+public void setBackground (Color color) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (color == null) {
+ setBackgroundPixel (defaultBackground ());
+ } else {
+ if (color.isDisposed ()) return;
+ setBackgroundPixel (color.handle.pixel);
+ }
+}
+void setBackgroundPixel (int pixel) {
+ int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XmChangeColor (handle, pixel);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+public void setBounds (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ int topHandle = topHandle ();
+ int [] argList = {
+ OS.XmNx, 0, /* 1 */
+ OS.XmNy, 0, /* 3 */
+ OS.XmNwidth, 0, /* 5 */
+ OS.XmNheight, 0, /* 7 */
+ OS.XmNborderWidth, 0, /* 9 */
+ };
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ int newWidth = Math.max (width - (argList [9] * 2), 1);
+ int newHeight = Math.max (height - (argList [9] * 2), 1);
+ boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]);
+ boolean sameExtent = (newWidth == argList [5]) && (newHeight == argList [7]);
+ if (sameOrigin && sameExtent) return;
+ OS.XtConfigureWidget (topHandle, x, y, newWidth, newHeight, argList [9]);
+ if (!sameOrigin) sendEvent (SWT.Move);
+ if (!sameExtent) sendEvent (SWT.Resize);
+}
+public void setBounds (Rectangle rect) {
+ if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setBounds (rect.x, rect.y, rect.width, rect.height);
+}
+public void setCapture (boolean capture) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ if (capture) {
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ OS.XGrabPointer (
+ display,
+ window,
+ 0,
+ OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
+ OS.GrabModeAsync,
+ OS.GrabModeAsync,
+ OS.None,
+ OS.None,
+ OS.CurrentTime);
+ } else {
+ OS.XUngrabPointer (display, OS.CurrentTime);
+ }
+}
+public void setCursor (Cursor cursor) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) {
+ if (OS.XtIsRealized (handle)) return;
+ Shell shell = this.getShell ();
+ shell.realizeWidget ();
+ window = OS.XtWindow (handle);
+ if (window == 0) return;
+ }
+ if (cursor == null) {
+ OS.XUndefineCursor (display, window);
+ } else {
+ int xCursor = cursor.handle;
+ OS.XDefineCursor (display, window, xCursor);
+ OS.XFlush (display);
+ }
+}
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ enableWidget (enabled);
+ if (!enabled || (isEnabled () && enabled)) {
+ propagateChildren (enabled);
+ }
+}
+public boolean setFocus () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Decorations shell = menuShell ();
+ shell.setSavedFocus (this);
+ shell.bringToTop ();
+ return OS.XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
+}
+public void setFont (Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int fontList = 0;
+ if (font != null) fontList = font.handle;
+ if (fontList == 0) fontList = defaultFont ();
+ setFontList (fontList);
+}
+void setFontList (int fontList) {
+ this.fontList = fontList;
+
+ /*
+ * Feature in Motif. Setting the font in a widget
+ * can cause the widget to automatically resize in
+ * the OS. This behavior is unwanted. The fix is
+ * to force the widget to resize to original size
+ * after every font change.
+ */
+ int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList1, argList1.length / 2);
+
+ /* Set the font list */
+ int fontHandle = fontHandle ();
+ int [] argList2 = {OS.XmNfontList, fontList};
+ OS.XtSetValues (fontHandle, argList2, argList2.length / 2);
+
+ /* Restore the widget size */
+ OS.XtSetValues (handle, argList1, argList1.length / 2);
+}
+public void setForeground (Color color) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (color == null) {
+ setForegroundPixel (defaultForeground ());
+ } else {
+ if (color.isDisposed ()) return;
+ setForegroundPixel (color.handle.pixel);
+ }
+}
+void setForegroundPixel (int pixel) {
+ int [] argList = {OS.XmNforeground, pixel};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
+}
+void setGrabCursor (int cursor) {
+ /* | window attributes eventMask grabMask |
+ handle xtIsWidget ifFalse: [^self].
+ (window := handle xtWindow) isNull ifTrue: [^self].
+ attributes := OSXWindowAttributesPtr new.
+ XDisplay
+ xGetWindowAttributes: window
+ windowAttributesReturn: attributes.
+ grabMask := ((((((((((ButtonPressMask bitOr: ButtonReleaseMask) bitOr:
+ EnterWindowMask) bitOr: LeaveWindowMask) bitOr: PointerMotionMask) bitOr:
+ PointerMotionHintMask) bitOr: Button1MotionMask) bitOr: Button2MotionMask) bitOr:
+ Button3MotionMask) bitOr: Button4MotionMask) bitOr: Button5MotionMask) bitOr: ButtonMotionMask.
+ eventMask := attributes yourEventMask bitAnd: grabMask.
+ XDisplay xChangeActivePointerGrab: eventMask cursor: aCursor time: CurrentTime.
+ */
+}
+void setKeyState (Event event, XKeyEvent xEvent) {
+ if (xEvent.keycode != 0) {
+ event.time = xEvent.time;
+ byte [] buffer1 = new byte [1];
+ int [] keysym = new int [1], status = new int [1];
+ if (OS.XLookupString (xEvent, buffer1, buffer1.length, keysym, status) == 0) {
+ event.keyCode = Display.translateKey (keysym [0] & 0xFFFF);
+ } else {
+ event.character = (char) buffer1 [0];
+ }
+ if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
+ if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
+ if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
+ if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ }
+}
+public void setLayoutData (Object layoutData) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.layoutData = layoutData;
+}
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]);
+ if (sameOrigin) return;
+ OS.XtMoveWidget (topHandle, x, y);
+ if (!sameOrigin) sendEvent (SWT.Move);
+}
+public void setLocation (Point location) {
+ if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setLocation (location.x, location.y);
+}
+/**
+* Sets the pop up menu.
+* <p>
+* Every window has a optional pop up menu that is
+* displayed when the user requests a popup menu for
+* the window. The sequence of key strokes/button
+* presses/button releases that is used to request
+* a pop up menu is platform specific.
+*
+* @param menu the new pop up menu
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_MENU_NOT_POP_UP)
+* when the menu is not a POP_UP
+* @exception SWTError(ERROR_NO_COMMON_PARENT)
+* when the menu is not in the same widget tree
+*/
+public void setMenu (Menu menu) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (menu != null) {
+ if ((menu.style & SWT.POP_UP) == 0) {
+ error (SWT.ERROR_MENU_NOT_POP_UP);
+ }
+ if (menu.parent != menuShell ()) {
+ error (SWT.ERROR_INVALID_PARENT);
+ }
+ }
+ this.menu = menu;
+}
+
+/**
+ * Changes the parent of the widget to be the one provided if
+ * the underlying operating system supports this feature.
+ * Answers true if the parent is successfully changed.
+ *
+ * @param parent Composite
+ * the new parent for the control.
+ * @return boolean
+ * true if parent is changed and false otherwise.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean setParent (Composite parent) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return false;
+}
+
+public void setRedraw (boolean redraw) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ int newWidth = Math.max (width - (argList [5] * 2), 1);
+ int newHeight = Math.max (height - (argList [5] * 2), 1);
+ boolean sameExtent = (newWidth == argList [1]) && (newHeight == argList [3]);
+ if (sameExtent) return;
+ OS.XtResizeWidget (topHandle, newWidth, newHeight, argList [5]);
+ if (!sameExtent) sendEvent (SWT.Resize);
+}
+public void setSize (Point size) {
+ if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setSize (size.x, size.y);
+}
+/**
+* Sets the tool tip text.
+* <p>
+* @param string the new tool tip text (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setToolTipText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ toolTipText = string;
+}
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNmappedWhenManaged, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ if ((argList [1] != 0) == visible) return;
+ OS.XtSetMappedWhenManaged (topHandle, visible);
+ sendEvent (visible ? SWT.Show : SWT.Hide);
+}
+void setZOrder () {
+ /*
+ * Feature in MOTIF. When a widget is created before the
+ * parent has been realized, the widget is created behind
+ * all siblings in the Z-order. When a widget is created
+ * after the parent parent has been realized, it is created
+ * in front of all siblings. This is not incorrect but is
+ * unexpected. The fix is to force all widgets to always
+ * be created behind their siblings.
+ */
+ int topHandle = topHandle ();
+ if (OS.XtIsRealized (topHandle)) {
+ int window = OS.XtWindow (topHandle);
+ if (window != 0) {
+ int display = OS.XtDisplay (topHandle);
+ if (display != 0) OS.XLowerWindow (display, window);
+ }
+ }
+}
+void setZOrder (Control control, boolean above) {
+ /*
+ * Feature in Xt. We cannot use XtMakeGeometryRequest() to
+ * restack widgets because this call can fail under certain
+ * conditions. For example, XtMakeGeometryRequest() answers
+ * XtGeometryNo when attempting to bring a child widget that
+ * is larger than the parent widget to the front. The fix
+ * is to use X calls instead.
+ */
+ int topHandle1 = topHandle ();
+ int display = OS.XtDisplay (topHandle1);
+ if (display == 0) return;
+ if (!OS.XtIsRealized (topHandle1)) {
+ Shell shell = this.getShell ();
+ shell.realizeWidget ();
+ }
+ int window1 = OS.XtWindow (topHandle1);
+ if (window1 == 0) return;
+ if (control == null) {
+ if (above) {
+ OS.XRaiseWindow (display, window1);
+ if (parent != null) parent.moveAbove (topHandle1, 0);
+ } else {
+ OS.XLowerWindow (display, window1);
+ if (parent != null) parent.moveBelow (topHandle1, 0);
+ }
+ return;
+ }
+ int topHandle2 = control.topHandle ();
+ if (display != OS.XtDisplay (topHandle2)) return;
+ if (!OS.XtIsRealized (topHandle2)) {
+ Shell shell = control.getShell ();
+ shell.realizeWidget ();
+ }
+ int window2 = OS.XtWindow (topHandle2);
+ if (window2 == 0) return;
+ XWindowChanges struct = new XWindowChanges ();
+ struct.sibling = window2;
+ struct.stack_mode = above ? OS.Above : OS.Below;
+ /*
+ * Feature in X. If the receiver is a top level, XConfigureWindow ()
+ * will fail (with a BadMatch error) for top level shells because top
+ * level shells are reparented by the window manager and do not share
+ * the same X window parent. This is the correct behavior but it is
+ * unexpected. The fix is to use XReconfigureWMWindow () instead.
+ * When the receiver is not a top level shell, XReconfigureWMWindow ()
+ * behaves the same as XConfigureWindow ().
+ */
+ int screen = OS.XDefaultScreen (display);
+ int flags = OS.CWStackMode | OS.CWSibling;
+ OS.XReconfigureWMWindow (display, window1, screen, flags, struct);
+ if (above) {
+ if (parent != null) parent.moveAbove (topHandle1, topHandle2);
+ } else {
+ if (parent != null) parent.moveBelow (topHandle1, topHandle2);
+ }
+}
+public Point toControl (Point point) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
+ return new Point (point.x - root_x [0], point.y - root_y [0]);
+}
+public Point toDisplay (Point point) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) point.x, (short) point.y, root_x, root_y);
+ return new Point (root_x [0], root_y [0]);
+}
+boolean translateMnemonic (int aKey, XKeyEvent xEvent) {
+ if (xEvent.state != OS.Mod1Mask) {
+ if (xEvent.state != 0 || !(this instanceof Button)) {
+ return false;
+ }
+ }
+ Decorations shell = menuShell ();
+ if (!shell.isVisible () || !shell.isEnabled ()) return false;
+ char ch = mbcsToWcs ((char) aKey);
+ return ch != 0 && shell.traverseMnemonic (ch);
+}
+boolean translateTraversal (int key, XKeyEvent xEvent) {
+ int detail = 0;
+ switch (key) {
+ case OS.XK_Escape:
+ case OS.XK_Cancel:
+ Shell shell = getShell ();
+ if (shell.parent == null) return false;
+ if (!shell.isVisible () || !shell.isEnabled ()) return false;
+ detail = SWT.TRAVERSE_ESCAPE;
+ break;
+ case OS.XK_Return:
+ Button button = menuShell ().getDefaultButton ();
+ if (button == null || button.isDisposed ()) return false;
+ if (!button.isVisible () || !button.isEnabled ()) return false;
+ detail = SWT.TRAVERSE_RETURN;
+ break;
+ case OS.XK_Tab:
+ detail = SWT.TRAVERSE_TAB_PREVIOUS;
+ boolean next = (xEvent.state & OS.ShiftMask) == 0;
+ if (next && ((xEvent.state & OS.ControlMask) != 0)) return false;
+ if (next) detail = SWT.TRAVERSE_TAB_NEXT;
+ break;
+ case OS.XK_Up:
+ case OS.XK_Left:
+ detail = SWT.TRAVERSE_ARROW_PREVIOUS;
+ break;
+ case OS.XK_Down:
+ case OS.XK_Right:
+ detail = SWT.TRAVERSE_ARROW_NEXT;
+ break;
+ default:
+ return false;
+ }
+ boolean doit = (detail & traversalCode ()) != 0;
+ if (hooks (SWT.Traverse)) {
+ Event event = new Event();
+ event.doit = doit;
+ event.detail = detail;
+ setKeyState (event, xEvent);
+ sendEvent (SWT.Traverse, event);
+ doit = event.doit;
+ detail = event.detail;
+ }
+ /*
+ * NOTE: The native widgets handle tab and arrow key traversal
+ * so it is not necessary to traverse these keys. A canvas widget
+ * has no native traversal by definition so it is necessary to
+ * traverse all keys.
+ */
+ if (doit) {
+ int flags = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_ESCAPE;
+ if ((detail & flags) != 0 || (state & CANVAS) != 0) {
+ return traverse (detail);
+ }
+ }
+ return false;
+}
+int traversalCode () {
+ int code = SWT.TRAVERSE_ESCAPE | SWT.TRAVERSE_RETURN;
+ int [] argList = {OS.XmNnavigationType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmNONE) {
+ code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
+ } else {
+ code |= SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS;
+ }
+ return code;
+}
+boolean traverseMnemonic (char key) {
+ if (!isVisible () || !isEnabled ()) return false;
+ return mnemonicMatch (key) && mnemonicHit ();
+}
+/**
+* Traverse the widget.
+* <p>
+* @param traversal the type of traversal.
+* @return true if the traversal succeeded
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* </ul>
+*/
+public boolean traverse (int traversal) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (!isFocusControl () && !setFocus ()) return false;
+ switch (traversal) {
+ case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
+ case SWT.TRAVERSE_RETURN: return traverseReturn ();
+ case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
+ case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
+ case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
+ case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
+ }
+ return false;
+}
+boolean traverseEscape () {
+ Shell shell = getShell ();
+ if (shell.parent == null) return false;
+ if (!shell.isVisible () || !shell.isEnabled ()) return false;
+ shell.close ();
+ return true;
+}
+boolean traverseGroup (boolean next) {
+ return OS.XmProcessTraversal (handle, next ? OS.XmTRAVERSE_NEXT_TAB_GROUP : OS.XmTRAVERSE_PREV_TAB_GROUP);
+}
+boolean traverseItem (boolean next) {
+ return OS.XmProcessTraversal (handle, next ? OS.XmTRAVERSE_NEXT : OS.XmTRAVERSE_PREV);
+}
+boolean traverseReturn () {
+ Button button = menuShell ().getDefaultButton ();
+ if (button == null || button.isDisposed ()) return false;
+ if (!button.isVisible () || !button.isEnabled ()) return false;
+ button.click ();
+ return true;
+}
+public void update () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ XAnyEvent event = new XAnyEvent ();
+ OS.XSync (display, false); OS.XSync (display, false);
+ while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) {
+ OS.XtDispatchEvent (event);
+ }
+}
+int processMouseHover (int id) {
+ Display display = getDisplay();
+ Event event = new Event();
+ Point local = toControl(display.getCursorLocation());
+ event.x = local.x; event.y = local.y;
+ postEvent (SWT.MouseHover, event);
+ display.showToolTip(handle, toolTipText);
+ return 0;
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java
new file mode 100755
index 0000000000..236e238b8e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java
@@ -0,0 +1,544 @@
+package org.eclipse.swt.widgets;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * WebSphere Studio Workbench
+ * (c) Copyright IBM Corp 2000
+ */
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+public /*final*/ class CoolBar extends Composite {
+ Vector rows;
+ Cursor hoverCursor;
+ Cursor dragCursor;
+ static final int ROW_SPACING = 2;
+
+public CoolBar (Composite parent, int style) {
+ super (parent, style);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = wHint, height = hHint;
+ if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
+ if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
+ Point extent = layout (width, false);
+ if (wHint != SWT.DEFAULT) extent.x = wHint;
+ if (hHint != SWT.DEFAULT) extent.y = hHint;
+ return extent;
+}
+public CoolItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ if (row.size() > index) {
+ return (CoolItem) row.elementAt(index);
+ } else {
+ index -= row.size();
+ }
+ }
+ error (SWT.ERROR_INVALID_RANGE);
+ return null;
+}
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int itemCount = 0;
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ itemCount += row.size();
+ }
+ return itemCount;
+}
+public CoolItem [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ CoolItem [] result = new CoolItem [getItemCount()];
+ int index = 0;
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ result[index] = (CoolItem) row.elementAt(j);
+ index++;
+ }
+ }
+ return result;
+}
+int getRowHeight (int rowIndex) {
+ Vector row = (Vector) rows.elementAt(rowIndex);
+ int height = 0;
+ for (int i = 0; i < row.size(); i++) {
+ CoolItem item = (CoolItem) row.elementAt(i);
+ int itemHeight = item.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
+ height = Math.max(height, itemHeight);
+ }
+ return height;
+}
+int getRowIndex (CoolItem item) {
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem next = (CoolItem) row.elementAt(j);
+ if (next.equals(item)) return i;
+ }
+ }
+ return -1;
+}
+Vector getRow (CoolItem item) {
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem next = (CoolItem) row.elementAt(j);
+ if (next.equals(item)) return row;
+ }
+ }
+ return null;
+}
+void hookEvents () {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddEventHandler (handle, OS.ExposureMask, false, windowProc, SWT.Paint);
+}
+public int indexOf (CoolItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int answer = 0;
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem next = (CoolItem) row.elementAt(j);
+ if (next.equals(item)) {
+ return answer;
+ } else {
+ answer++;
+ }
+ }
+ }
+ return -1;
+}
+/**
+ * Insert the item into the row. Adjust the x and width values
+ * appropriately.
+ */
+void insertItemIntoRow(CoolItem item, Vector row, int x_root, int rowY) {
+ if (row.size() == 0) {
+ Point size = item.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ item.setBounds(0, rowY, getSize().x, size.y);
+ row.addElement(item);
+ return;
+ }
+
+ int x = x_root - toDisplay(new Point(0, 0)).x;
+
+ /* Find the insertion index and add the item. */
+ int index = 0;
+ for (int i = 0; i < row.size(); i++) {
+ CoolItem next = (CoolItem) row.elementAt(i);
+ if (x < next.getBounds().x) break;
+ index++;
+ }
+ row.insertElementAt(item, index);
+
+ /* Adjust the width of the item to the left. */
+ if (index > 0) {
+ CoolItem left = (CoolItem) row.elementAt(index - 1);
+ Rectangle leftBounds = left.getBounds();
+ int newWidth = x - leftBounds.x;
+ if (newWidth < CoolItem.MINIMUM_WIDTH) {
+ x += CoolItem.MINIMUM_WIDTH - newWidth;
+ newWidth = CoolItem.MINIMUM_WIDTH;
+ }
+ left.setBounds(leftBounds.x, leftBounds.y, newWidth, leftBounds.height);
+ }
+
+ /* Set the item's bounds. */
+ int width = 0;
+ if (index < row.size() - 1) {
+ CoolItem right = (CoolItem) row.elementAt(index + 1);
+ width = right.getBounds().x - x;
+ if (width < CoolItem.MINIMUM_WIDTH) {
+ moveRight(right, CoolItem.MINIMUM_WIDTH - width);
+ width = CoolItem.MINIMUM_WIDTH;
+ }
+ } else {
+ width = getBounds().width - x;
+ }
+ item.setBounds(x, rowY, width, item.getBounds().height);
+}
+void createItem (CoolItem item, int index) {
+ int itemCount = getItemCount();
+ if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
+ item.createWidget (index);
+ item.id = itemCount;
+ if (index < itemCount) {
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ if (row.size() > index) {
+ row.insertElementAt(item, index);
+ return;
+ } else {
+ index -= row.size();
+ }
+ }
+ } else {
+ Vector lastRow = (Vector) rows.lastElement();
+ lastRow.addElement(item);
+ }
+}
+void createWidget (int index) {
+ rows = new Vector(5);
+ super.createWidget (index);
+ rows.addElement(new Vector(10));
+ hoverCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEWE);
+ dragCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEALL);
+}
+void releaseWidget () {
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem item = (CoolItem) row.elementAt(j);
+ if (!item.isDisposed ()) {
+ item.releaseWidget ();
+ item.releaseHandle ();
+ }
+ }
+ }
+ rows = null;
+ if (hoverCursor != null) hoverCursor.dispose();
+ if (dragCursor != null) dragCursor.dispose();
+ super.releaseWidget ();
+}
+void moveDown(CoolItem item, int x_root) {
+ int oldRowIndex = getRowIndex(item);
+ Vector oldRowItems = (Vector) rows.elementAt(oldRowIndex);
+ if (oldRowIndex == rows.size() - 1 && oldRowItems.size() == 1) {
+ /* This is the only item in the bottom row, don't move it. */
+ return;
+ }
+
+ int newRowIndex = (oldRowItems.size() == 1) ? oldRowIndex : oldRowIndex + 1;
+ removeItemFromRow(item, oldRowItems);
+
+ int newRowY = ROW_SPACING;
+ for (int i = 0; i < newRowIndex; i++) {
+ newRowY += getRowHeight(i) + ROW_SPACING;
+ }
+
+ if (newRowIndex == rows.size()) {
+ /* Create a new bottom row for the item. */
+ Vector newRow = new Vector(10);
+ insertItemIntoRow(item, newRow, x_root, newRowY);
+ rows.add(newRow);
+ adjustItemHeights(oldRowIndex);
+ return;
+ }
+
+ Vector newRowItems = (Vector) rows.elementAt(newRowIndex);
+ insertItemIntoRow(item, newRowItems, x_root, newRowY);
+ adjustItemHeights(oldRowIndex);
+}
+void moveLeft(CoolItem item, int pixels) {
+ Vector row = getRow(item);
+ int index = row.indexOf(item);
+ if (index == 0) return;
+ Rectangle bounds = item.getBounds();
+ int min = index * CoolItem.MINIMUM_WIDTH;
+ int x = Math.max(min, bounds.x - pixels);
+ CoolItem left = (CoolItem) row.elementAt(index - 1);
+ Rectangle leftBounds = left.getBounds();
+ if (leftBounds.x + CoolItem.MINIMUM_WIDTH >= x) {
+ int shift = leftBounds.x + CoolItem.MINIMUM_WIDTH - x;
+ moveLeft(left, shift);
+ leftBounds = left.getBounds();
+ }
+ int leftWidth = Math.max(CoolItem.MINIMUM_WIDTH, leftBounds.width - pixels);
+ left.setBounds(leftBounds.x, leftBounds.y, leftWidth, leftBounds.height);
+ int width = bounds.width + (bounds.x - x);
+ item.setBounds(x, bounds.y, width, bounds.height);
+}
+void moveRight(CoolItem item, int pixels) {
+ Vector row = getRow(item);
+ int index = row.indexOf(item);
+ if (index == 0) return;
+ Rectangle bounds = item.getBounds();
+ int minSpaceOnRight = (row.size() - index) * CoolItem.MINIMUM_WIDTH;
+ int max = getBounds().width - minSpaceOnRight;
+ int x = Math.min(max, bounds.x + pixels);
+ int width = 0;
+ if (index + 1 == row.size()) {
+ width = getBounds().width - x;
+ } else {
+ CoolItem right = (CoolItem) row.elementAt(index + 1);
+ Rectangle rightBounds = right.getBounds();
+ if (x + CoolItem.MINIMUM_WIDTH >= rightBounds.x) {
+ int shift = x + CoolItem.MINIMUM_WIDTH - rightBounds.x;
+ moveRight(right, shift);
+ rightBounds = right.getBounds();
+ }
+ width = rightBounds.x - x;
+ }
+ item.setBounds(x, bounds.y, width, bounds.height);
+ CoolItem left = (CoolItem) row.elementAt(index - 1);
+ Rectangle leftBounds = left.getBounds();
+ int leftWidth = x - leftBounds.x;
+ left.setBounds(leftBounds.x, leftBounds.y, leftWidth, leftBounds.height);
+}
+void moveUp(CoolItem item, int x_root) {
+ int oldRowIndex = getRowIndex(item);
+ Vector oldRowItems = (Vector) rows.elementAt(oldRowIndex);
+ if (oldRowIndex == 0 && oldRowItems.size() == 1) {
+ /* This is the only item in the top row, don't move it. */
+ return;
+ }
+
+ removeItemFromRow(item, oldRowItems);
+ int newRowIndex = oldRowIndex - 1;
+ int newRowY = ROW_SPACING;
+ for (int i = 0; i < newRowIndex; i++) {
+ newRowY += getRowHeight(i) + ROW_SPACING;
+ }
+
+ if (oldRowIndex == 0) {
+ /* Create a new top row for the item. */
+ Vector newRow = new Vector(10);
+ insertItemIntoRow(item, newRow, x_root, newRowY);
+ rows.add(0, newRow);
+ adjustItemHeights(0);
+ return;
+ }
+
+ Vector newRowItems = (Vector) rows.elementAt(newRowIndex);
+ insertItemIntoRow(item, newRowItems, x_root, newRowY);
+ adjustItemHeights(newRowIndex);
+}
+int processPaint (int callData) {
+ if (rows.size() == 0) return 0;
+ GC gc = new GC(this);
+ Display display = getDisplay();
+ int y = getRowHeight(0) + ROW_SPACING;
+ int stopX = getBounds().width;
+ Color shadowColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color highlightColor = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ for (int i = 1; i < rows.size(); i++) {
+ gc.setForeground(shadowColor);
+ gc.drawLine(0, y, stopX, y);
+ gc.setForeground(highlightColor);
+ gc.drawLine(0, y + 1, stopX, y + 1);
+ y += getRowHeight(i) + ROW_SPACING;
+ }
+ gc.dispose();
+ return 0;
+}
+/**
+ * Remove the item from the row. Adjust the x and width values
+ * appropriately.
+ */
+void removeItemFromRow(CoolItem item, Vector row) {
+ int index = row.indexOf(item);
+ row.removeElementAt(index);
+ if (row.size() == 0) {
+ rows.removeElement(row);
+ return;
+ }
+ if (index == 0) {
+ CoolItem first = (CoolItem) row.elementAt(0);
+ Rectangle bounds = first.getBounds();
+ int width = bounds.x + bounds.width;
+ first.setBounds(0, bounds.y, width, bounds.height);
+ } else {
+ CoolItem previous = (CoolItem) row.elementAt(index - 1);
+ Rectangle bounds = previous.getBounds();
+ int width = bounds.width + item.getSize().x;
+ previous.setBounds(bounds.x, bounds.y, width, bounds.height);
+ }
+}
+/**
+ * Update the children to reflect a change in y values.
+ */
+void adjustItemHeights(int startIndex) {
+ int y = ROW_SPACING;
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ int rowHeight = getRowHeight(i);
+ if (i >= startIndex) {
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem child = (CoolItem) row.elementAt(j);
+ Rectangle bounds = child.getBounds();
+ if (bounds.y != y || bounds.height != rowHeight) {
+ child.setBounds(bounds.x, y, bounds.width, rowHeight);
+ if (bounds.height != rowHeight) child.redraw();
+ }
+ }
+ }
+ y += ROW_SPACING + rowHeight;
+ }
+ Point size = getSize();
+ if (size.y != y) super.setSize(size.x, y);
+}
+/**
+ * The row has been assigned a new width. Grow or
+ * shrink the row's items as necessary.
+ */
+void adjustItemWidths (Vector row, int width) {
+ CoolItem last = (CoolItem) row.lastElement();
+ Rectangle bounds = last.getBounds();
+ int rowWidth = bounds.x + bounds.width;
+ if (width == rowWidth) return;
+ if (width > rowWidth || width > bounds.x + CoolItem.MINIMUM_WIDTH) {
+ last.setBounds(bounds.x, bounds.y, width - bounds.x, bounds.height);
+ return;
+ }
+ /* Shifting the last item ensures that all hidden items
+ to its left are made visible as well.*/
+ last.setBounds(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height);
+ moveLeft(last, bounds.x - width + CoolItem.MINIMUM_WIDTH);
+}
+Point layout (int width, boolean resize) {
+ int y = ROW_SPACING, maxWidth = 0;
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ int x = 0, rowHeight = getRowHeight(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem child = (CoolItem) row.elementAt(j);
+ int childWidth = child.getSize().x;
+ if (resize) child.setBounds(x, y, childWidth, rowHeight);
+ x += childWidth;
+ }
+ maxWidth = Math.max(maxWidth, x);
+ if (resize) adjustItemWidths(row, width);
+ y += ROW_SPACING + rowHeight;
+ }
+ return new Point(maxWidth, y);
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ CoolItem[] items = getItems();
+ for (int i = 0; i < items.length; i++) {
+ int window = OS.XtWindow (items[i].handle);
+ if (window != 0) {
+ int display = OS.XtDisplay (items[i].handle);
+ if (display != 0) OS.XLowerWindow (display, window);
+ }
+ }
+ layout(getSize().x, true);
+}
+void relayout() {
+ Point size = layout(getSize().x, true);
+ super.setSize(size.x, size.y);
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ layout(width, true);
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ layout (width, true);
+}
+CoolItem getChild (int id) {
+ for (int i = 0; i < rows.size(); i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ for (int j = 0; j < row.size(); j++) {
+ CoolItem child = (CoolItem) row.elementAt(j);
+ if (child.id == id) return child;
+ }
+ }
+ return null;
+}
+public int[] getItemOrder () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ CoolItem[] items = getItems();
+ int[] ids = new int[items.length];
+ for (int i = 0; i < items.length; i++) {
+ ids[i] = items[i].id;
+ }
+ return ids;
+}
+void setItemOrder (int[] itemOrder) {
+ if (itemOrder == null) error(SWT.ERROR_NULL_ARGUMENT);
+ CoolItem[] items = getItems();
+ if (itemOrder.length != items.length) error(SWT.ERROR_INVALID_ARGUMENT);
+ Vector row = new Vector(items.length);
+ for (int i = 0; i < itemOrder.length; i++) {
+ CoolItem child = getChild(itemOrder[i]);
+ if (child == null) error(SWT.ERROR_INVALID_ARGUMENT);
+ row.addElement(child);
+ }
+ rows = new Vector(1);
+ rows.addElement(row);
+}
+public Point[] getItemSizes () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ CoolItem[] items = getItems();
+ Point[] sizes = new Point[items.length];
+ for (int i = 0; i < items.length; i++) {
+ sizes[i] = items[i].getSize();
+ }
+ return sizes;
+}
+void setItemSizes (Point[] sizes) {
+ if (sizes == null) error(SWT.ERROR_NULL_ARGUMENT);
+ CoolItem[] items = getItems();
+ if (sizes.length != items.length) error(SWT.ERROR_INVALID_ARGUMENT);
+ for (int i = 0; i < items.length; i++) {
+ Rectangle bounds = items[i].getBounds();
+ items[i].setBounds(bounds.x, bounds.y, sizes[i].x, sizes[i].y);
+ }
+}
+public int[] getWrapIndices () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int[] data = new int[rows.size() - 1];
+ int itemIndex = 0;
+ for (int i = 0; i < rows.size() - 1; i++) {
+ Vector row = (Vector) rows.elementAt(i);
+ itemIndex += row.size();
+ data[i] = itemIndex;
+ }
+ return data;
+}
+public void setWrapIndices (int[] data) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (data == null) error(SWT.ERROR_NULL_ARGUMENT);
+ CoolItem[] items = getItems();
+ rows = new Vector(5);
+ int itemIndex = 0;
+ for (int i = 0; i < data.length; i++) {
+ int nextWrap = data[i];
+ Vector row = new Vector(10);
+ while (itemIndex < nextWrap) {
+ row.addElement(items[itemIndex]);
+ itemIndex++;
+ }
+ rows.addElement(row);
+ }
+ Vector row = new Vector(10);
+ while (itemIndex < items.length) {
+ row.addElement(items[itemIndex]);
+ itemIndex++;
+ }
+ rows.addElement(row);
+ relayout();
+}
+public void setItemLayout (int[] itemOrder, int[] wrapIndices, Point[] sizes) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setItemOrder(itemOrder);
+ setWrapIndices(wrapIndices);
+ setItemSizes(sizes);
+ relayout();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java
new file mode 100755
index 0000000000..5340a39911
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java
@@ -0,0 +1,296 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.motif.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+public /*final*/ class CoolItem extends Item {
+ Control control;
+ CoolBar parent;
+ boolean dragging;
+ int mouseXOffset;
+ int preferredWidth = -1;
+ int preferredHeight = -1;
+ int id;
+
+ static final int MARGIN_WIDTH = 4;
+ static final int MARGIN_HEIGHT = 2;
+ static final int DEFAULT_HEIGHT = (2 * MARGIN_HEIGHT) + 28;
+ static final int GRABBER_WIDTH = 2;
+ static final int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
+
+public CoolItem (CoolBar parent, int style) {
+ super(parent, style);
+ this.parent = parent;
+ parent.createItem (this, parent.getItemCount ());
+}
+public CoolItem (CoolBar parent, int style, int index) {
+ super(parent, style);
+ this.parent = parent;
+ parent.createItem (this, index);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Point computeSize (int wHint, int hHint) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (preferredWidth > -1) return new Point(preferredWidth, preferredHeight);
+ int width = MINIMUM_WIDTH;
+ int height = DEFAULT_HEIGHT;
+ if (wHint != SWT.DEFAULT) width = wHint + MINIMUM_WIDTH + MARGIN_WIDTH;
+ if (hHint != SWT.DEFAULT) height = hHint + (2 + MARGIN_HEIGHT);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int [] argList = {
+ OS.XmNwidth, MINIMUM_WIDTH,
+ OS.XmNheight, DEFAULT_HEIGHT,
+ OS.XmNpositionIndex, index,
+ OS.XmNtraversalOn, 0,
+ };
+ handle = OS.XmCreateDrawingArea(parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+public Rectangle getBounds () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]);
+}
+public Control getControl () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return control;
+}
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+Rectangle getGrabberArea () {
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return new Rectangle(0, 0, MINIMUM_WIDTH, argList[1]);
+}
+public CoolBar getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+Point getSize () {
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return new Point (argList [1], argList [3]);
+}
+void hookEvents () {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddEventHandler (handle, OS.ExposureMask, false, windowProc, SWT.Paint);
+ OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, SWT.MouseDown);
+ OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, SWT.MouseUp);
+ OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, SWT.MouseMove);
+ OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, SWT.MouseExit);
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+int processMouseDown (int callData) {
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ if (getGrabberArea().contains(xEvent.x, xEvent.y)) {
+ dragging = true;
+ mouseXOffset = xEvent.x;
+ parent.setCursor(parent.dragCursor);
+ }
+ return 0;
+}
+int processMouseExit (int callData) {
+ if (!dragging) parent.setCursor(null);
+ return 0;
+}
+int processMouseMove (int callData) {
+ XMotionEvent xEvent = new XMotionEvent ();
+ OS.memmove (xEvent, callData, XMotionEvent.sizeof);
+ if (dragging) {
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int left_root = xEvent.x_root - mouseXOffset;
+ if (xEvent.y < 0) {
+ parent.moveUp(this, left_root);
+ return 0;
+ }
+ if (xEvent.y > argList[1]){
+ parent.moveDown(this, left_root);
+ return 0;
+ }
+ int delta = Math.abs(xEvent.x - mouseXOffset);
+ if (xEvent.x < mouseXOffset) {
+ parent.moveLeft(this, delta);
+ return 0;
+ }
+ if (xEvent.x > mouseXOffset) {
+ parent.moveRight(this, delta);
+ return 0;
+ }
+ return 0;
+ }
+ if (getGrabberArea().contains(xEvent.x, xEvent.y)) {
+ parent.setCursor(parent.hoverCursor);
+ } else {
+ parent.setCursor(null);
+ }
+ return 0;
+}
+int processMouseUp (int callData) {
+ dragging = false;
+ parent.setCursor(parent.hoverCursor);
+ return 0;
+}
+int processPaint (int callData) {
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return 0;
+ int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
+
+ Display display = getDisplay();
+ int shadowPixel = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).handle.pixel;
+ int highlightPixel = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW).handle.pixel;
+ int lightShadowPixel = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW).handle.pixel;
+
+ int[] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int height = argList[1];
+ int grabberHeight = height - (2 * MARGIN_HEIGHT);
+
+ /* Draw separator. */
+ OS.XSetForeground(xDisplay, xGC, shadowPixel);
+ OS.XDrawLine (xDisplay, xWindow, xGC, 0, 0, 0, height);
+ OS.XSetForeground(xDisplay, xGC, highlightPixel);
+ OS.XDrawLine (xDisplay, xWindow, xGC, 1, 0, 1, height);
+
+ /* Draw grabber. */
+ OS.XSetForeground(xDisplay, xGC, highlightPixel);
+ OS.XSetBackground(xDisplay, xGC, lightShadowPixel);
+ OS.XFillRectangle(xDisplay, xWindow, xGC, MARGIN_WIDTH, MARGIN_HEIGHT, GRABBER_WIDTH, grabberHeight);
+ OS.XSetForeground(xDisplay, xGC, shadowPixel);
+ int right = MARGIN_WIDTH + GRABBER_WIDTH;
+ int bottom = MARGIN_HEIGHT + grabberHeight;
+ OS.XDrawLine (xDisplay, xWindow, xGC, right, MARGIN_HEIGHT, right, bottom);
+ OS.XDrawLine (xDisplay, xWindow, xGC, MARGIN_WIDTH, bottom, right, bottom);
+
+ OS.XFreeGC(xDisplay, xGC);
+ return 0;
+}
+public void setControl (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (control != null && control.parent != parent) {
+ error (SWT.ERROR_INVALID_PARENT);
+ }
+ Control oldControl = this.control;
+ if (oldControl != null) oldControl.setVisible(false);
+ this.control = control;
+ if (control != null && !control.isDisposed ()) {
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int controlY = ((short) argList[3]) + MARGIN_HEIGHT;
+ control.setBounds (
+ ((short) argList [1]) + MINIMUM_WIDTH,
+ controlY,
+ argList [5] - MINIMUM_WIDTH - MARGIN_WIDTH,
+ argList [7] - (2 * MARGIN_HEIGHT));
+
+ if (OS.XtIsRealized (handle)) {
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ OS.XLowerWindow (display, window);
+ }
+ control.setVisible(true);
+ }
+}
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ width = Math.max (width, MINIMUM_WIDTH);
+ height = Math.max (height, DEFAULT_HEIGHT);
+ OS.XtResizeWidget (handle, width, height, 0);
+ if (control != null) {
+ int controlWidth = width - MINIMUM_WIDTH - MARGIN_WIDTH;
+ int controlHeight = height - (2 * MARGIN_HEIGHT);
+ control.setSize(controlWidth, controlHeight);
+ }
+ parent.relayout();
+}
+int getControlOffset(int height) {
+ return ((height - control.getSize().y - (2 * MARGIN_HEIGHT)) / 2) + MARGIN_HEIGHT;
+}
+void redraw() {
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ OS.XClearArea (display, window, 0, 0, 0, 0, true);
+}
+void setLocation (int x, int y) {
+ OS.XtMoveWidget (handle, x, y);
+ if (control != null) {
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int controlY = y + getControlOffset(argList[1]);
+ control.setLocation(x + MINIMUM_WIDTH, controlY);
+ }
+}
+public void setSize (Point size) {
+ if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setSize (size.x, size.y);
+}
+void setBounds (int x, int y, int width, int height) {
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1);
+ OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0);
+ if (control != null) {
+ int controlY = y + getControlOffset(newHeight);
+ control.setBounds(
+ x + MINIMUM_WIDTH,
+ controlY,
+ newWidth - MINIMUM_WIDTH - MARGIN_WIDTH,
+ control.getSize().y);
+ }
+}
+public Point getPreferredSize () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return new Point(preferredWidth, preferredHeight);
+}
+public void setPreferredSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ preferredWidth = Math.max (width, MINIMUM_WIDTH);
+ preferredHeight = Math.max (height, DEFAULT_HEIGHT);
+ OS.XtResizeWidget (handle, preferredWidth, preferredHeight, 0);
+ if (control != null) {
+ int controlWidth = preferredWidth - MINIMUM_WIDTH - MARGIN_WIDTH;
+ int controlHeight = preferredHeight - (2 * MARGIN_HEIGHT);
+ control.setSize(controlWidth, controlHeight);
+ }
+}
+public void setPreferredSize (Point size) {
+ setPreferredSize(size.x, size.y);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java
new file mode 100755
index 0000000000..27a9612f8a
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java
@@ -0,0 +1,324 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The decorations class implements a widget that
+* looks and behaves like a shell, but has the same
+* properties as a child widget.
+*
+* Styles
+*
+* NO_TRIM,
+* BORDER, RESIZE,
+* TITLE, MENU, MIN, MAX
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/* Class Definition */
+public class Decorations extends Canvas {
+ String label;
+ Image image;
+ int dialogHandle;
+ boolean minimized, maximized;
+ Menu menuBar;
+ Menu [] menus;
+ Control savedFocus;
+ Button defaultButton, saveDefault;
+Decorations () {
+ /* Do nothing */
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Decorations (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+void add (Menu menu) {
+ if (menus == null) menus = new Menu [4];
+ for (int i=0; i<menus.length; i++) {
+ if (menus [i] == null) {
+ menus [i] = menu;
+ return;
+ }
+ }
+ Menu [] newMenus = new Menu [menus.length + 4];
+ newMenus [menus.length] = menu;
+ System.arraycopy (menus, 0, newMenus, 0, menus.length);
+ menus = newMenus;
+}
+void bringToTop () {
+ /*
+ * Feature in X. Calling XSetInputFocus() when the
+ * widget is not viewable causes an X bad match error.
+ * The fix is to call XSetInputFocus() when the widget
+ * is viewable.
+ */
+ if (minimized) return;
+ if (!isVisible ()) return;
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ OS.XSetInputFocus (display, window, OS.RevertToParent, OS.CurrentTime);
+}
+static int checkStyle (int style) {
+ if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
+ style |= SWT.TITLE;
+ }
+ return style;
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle trim = super.computeTrim (x, y, width, height);
+ if (menuBar != null) {
+ XtWidgetGeometry request = new XtWidgetGeometry ();
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ request.request_mode = OS.CWWidth;
+ request.width = trim.width;
+ OS.XtQueryGeometry (menuBar.handle, request, result);
+ trim.height += result.height;
+ }
+ return trim;
+}
+void createHandle (int index) {
+ state |= HANDLE | CANVAS;
+ createScrolledHandle (parent.handle);
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ label = "";
+}
+int dialogHandle () {
+ if (dialogHandle != 0) return dialogHandle;
+ return dialogHandle = OS.XmCreateDialogShell (handle, null, null, 0);
+}
+public Button getDefaultButton () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return defaultButton;
+}
+/**
+* Gets the image.
+* <p>
+* @return the image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getImage () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return image;
+}
+public boolean getMaximized () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return maximized;
+}
+public Menu getMenuBar () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return menuBar;
+}
+public boolean getMinimized () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return minimized;
+}
+String getNameText () {
+ return getText ();
+}
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return label;
+}
+Decorations menuShell () {
+ return this;
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ int [] argList = {OS.XmNmenuBar, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ if (argList [1] != 0) propagateHandle (enabled, argList [1]);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ dialogHandle = 0;
+}
+void releaseWidget () {
+ if (menus != null) {
+ for (int i=0; i<menus.length; i++) {
+ Menu menu = menus [i];
+ if (menu != null && !menu.isDisposed ()) {
+ menu.releaseWidget ();
+ menu.releaseHandle ();
+ }
+ }
+ }
+ menuBar = null;
+ menus = null;
+ super.releaseWidget ();
+ defaultButton = saveDefault = null;
+ label = null;
+}
+void remove (Menu menu) {
+ if (menus == null) return;
+ for (int i=0; i<menus.length; i++) {
+ if (menus [i] == menu) {
+ menus [i] = null;
+ return;
+ }
+ }
+}
+public void setDefaultButton (Button button) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setDefaultButton (button, true);
+}
+void setDefaultButton (Button button, boolean save) {
+ if (button == null) {
+ if (defaultButton == saveDefault) return;
+ } else {
+ if ((button.style & SWT.PUSH) == 0) return;
+ if (button == defaultButton) return;
+ }
+ if (defaultButton != null) {
+ if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
+ }
+ if ((defaultButton = button) == null) defaultButton = saveDefault;
+ if (defaultButton != null) {
+ if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
+ }
+ if (save || saveDefault == null) saveDefault = defaultButton;
+ if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
+}
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ switch (image.type) {
+ case SWT.BITMAP:
+ pixmap = image.pixmap;
+ break;
+ case SWT.ICON:
+ pixmap = image.pixmap;
+ mask = image.mask;
+ break;
+ default:
+ error (SWT.ERROR_INVALID_IMAGE);
+ }
+ }
+ this.image = image;
+ int [] argList = {
+ OS.XmNiconPixmap, pixmap,
+ OS.XmNiconMask, mask,
+ };
+ int topHandle = topHandle ();
+ OS.XtSetValues (topHandle, argList, argList.length / 2);
+}
+public void setMaximized (boolean maximized) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.maximized = maximized;
+}
+public void setMenuBar (Menu menu) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (menuBar == menu) return;
+ if (menu != null) {
+ if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
+ if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
+ }
+
+ /* Ensure the new menu bar is correctly enabled */
+ if (menuBar != null) {
+ if (!isEnabled () && menuBar.getEnabled ()) {
+ propagateHandle (true, menuBar.handle);
+ }
+ }
+ if (menu != null) {
+ if (!isEnabled ()) {
+ propagateHandle (false, menu.handle);
+ }
+ }
+
+ /*
+ * Bug in Motif. When a XmMainWindowSetAreas () is used
+ * to replace an existing menu, both menus must be managed
+ * before the call to XmMainWindowSetAreas () or the new
+ * menu will not be layed out properly.
+ */
+ int newHandle = (menu != null) ? menu.handle : 0;
+ int oldHandle = (menuBar != null) ? menuBar.handle : 0;
+ menuBar = menu;
+ int hHandle = (horizontalBar != null) ? horizontalBar.handle : 0;
+ int vHandle = (verticalBar != null) ? verticalBar.handle : 0;
+ if (newHandle != 0) {
+ OS.XtSetMappedWhenManaged (newHandle, false);
+ OS.XtManageChild (newHandle);
+ }
+ int clientHandle = (formHandle != 0) ? formHandle : handle;
+ OS.XmMainWindowSetAreas (scrolledHandle, newHandle, 0, hHandle, vHandle, clientHandle);
+ if (oldHandle != 0) OS.XtUnmanageChild (oldHandle);
+ if (newHandle != 0) {
+ OS.XtSetMappedWhenManaged (newHandle, true);
+ }
+
+ /*
+ * Bug in Motif. When a menu bar is removed after the
+ * main window has been realized, the main window does
+ * not layout the new menu bar or the work window.
+ * The fix is to force a layout by temporarily resizing
+ * the main window.
+ */
+ if (newHandle == 0 && OS.XtIsRealized (scrolledHandle)) {
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
+ OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
+ }
+}
+public void setMinimized (boolean minimized) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.minimized = minimized;
+}
+void setSavedFocus (Control control) {
+ if (this == control) return;
+ savedFocus = control;
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ label = string;
+}
+public void setVisible (boolean visible) {
+ super.setVisible (visible);
+ if (!visible) return;
+ if (savedFocus != null && !savedFocus.isDisposed ()) {
+ savedFocus.setFocus ();
+ }
+ savedFocus = null;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java
new file mode 100755
index 0000000000..28048caa14
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java
@@ -0,0 +1,220 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/**
+* A DirectoryDialog allows the user to navigate
+* the file and select a directory.
+*/
+
+/* Class Definition */
+public /*final*/ class DirectoryDialog extends Dialog {
+ String filterPath = "";
+ boolean cancel = true;
+ String message = "";
+public DirectoryDialog (Shell parent) {
+ this (parent, SWT.PRIMARY_MODAL);
+}
+public DirectoryDialog (Shell parent, int style) {
+ super (parent, style);
+}
+int activate (int widget, int client, int call) {
+ cancel = client == OS.XmDIALOG_CANCEL_BUTTON;
+ OS.XtUnmanageChild (widget);
+ return 0;
+}
+public String getFilterPath () {
+ return filterPath;
+}
+public String getMessage () {
+ return message;
+}
+public String open () {
+
+ /* Get the parent */
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int display = appContext.xDisplay;
+ int parentHandle = appContext.shellHandle;
+ if ((parent != null) && (parent.getDisplay () == appContext))
+ parentHandle = parent.shellHandle;
+ /* Compute the dialog title */
+ /*
+ * Feature in Motif. It is not possible to set a shell
+ * title to an empty string. The fix is to set the title
+ * to be a single space.
+ */
+ String string = title;
+ if (string.length () == 0) string = " ";
+ byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
+ int xmStringPtr1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ /* Compute the filter */
+ byte [] buffer2 = Converter.wcsToMbcs (null, "*", true);
+ int xmStringPtr2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Compute the filter path */
+ if (filterPath == null) filterPath = "";
+ byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
+ int xmStringPtr3 = OS.XmStringParseText (
+ buffer3,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ byte [] buffer7 = Converter.wcsToMbcs (null, "Selection", true);
+ int xmStringPtr4 = OS.XmStringParseText (
+ buffer7,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ /* Create the dialog */
+ int [] argList1 = {
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
+ OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
+ OS.XmNdialogTitle, xmStringPtr1,
+ OS.XmNpattern, xmStringPtr2,
+ OS.XmNdirectory, xmStringPtr3,
+ OS.XmNfilterLabelString, xmStringPtr4
+ };
+ /*
+ * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
+ * will not accept NULL for the widget name. This works fine on the other
+ * Motif platforms and in the other XmCreate calls on Linux. The fix is
+ * to pass in a NULL terminated string, not a NULL pointer.
+ */
+ byte [] name = new byte [] {0};
+ int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
+ int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
+ if (child != 0) OS.XtUnmanageChild (child);
+ child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
+ if (child != 0) {
+ int parent2 = OS.XtParent(child);
+ if (parent2 !=0) OS.XtUnmanageChild (parent2);
+ }
+ child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST_LABEL);
+ if (child != 0) OS.XtUnmanageChild (child);
+ child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT);
+ if (child != 0) OS.XtUnmanageChild (child);
+ child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_SELECTION_LABEL);
+ if (child != 0) OS.XtUnmanageChild (child);
+ OS.XmStringFree (xmStringPtr1);
+ OS.XmStringFree (xmStringPtr2);
+ OS.XmStringFree (xmStringPtr3);
+ OS.XmStringFree (xmStringPtr4);
+
+ // Add label widget for message text.
+ byte [] buffer4 = Converter.wcsToMbcs (null, message, true);
+ int [] parseTable = Display.getDefault ().parseTable;
+ int xmString1 = OS.XmStringParseText (
+ buffer4,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ parseTable,
+ parseTable.length,
+ 0);
+ int [] argList = {
+ OS.XmNlabelType, OS.XmSTRING,
+ OS.XmNlabelString, xmString1
+ };
+ int textArea = OS.XmCreateLabel(dialog, name, argList, argList.length/2);
+ OS.XtManageChild(textArea);
+
+ /* Hook the callbacks. */
+ Callback callback = new Callback (this, "activate", 3);
+ int address = callback.getAddress ();
+ OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
+ OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
+
+ /* Open the dialog and dispatch events. */
+ cancel = true;
+ OS.XtManageChild (dialog);
+
+//BOGUS - should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch ()) appContext.sleep ();
+
+ /* Set the new path, file name and filter. */
+ String directoryPath="";
+ if (!cancel) {
+ int [] argList2 = {OS.XmNdirMask, 0};
+ OS.XtGetValues (dialog, argList2, argList2.length / 2);
+ int xmString3 = argList2 [1];
+ int ptr = OS.XmStringUnparse (
+ xmString3,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (ptr != 0) {
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ directoryPath = new String (Converter.mbcsToWcs (null, buffer));
+ }
+ OS.XmStringFree (xmString3);
+ int length = directoryPath.length ();
+ if (length != 0) {
+ if (directoryPath.charAt (length -1) == '/') {
+ directoryPath = directoryPath.substring (0, length - 1);
+ } else {
+ if (length > 1 && directoryPath.charAt (length - 2) == '/' && directoryPath.charAt (length - 1) == '*') {
+ directoryPath = directoryPath.substring (0, length - 2);
+ }
+ }
+ }
+ }
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ callback.dispose ();
+
+// (shell == nil or: [shell isDestroyed not]) ifTrue: [dialog xtDestroyWidget].
+// OSWidget updateDisplay.
+// entryPoint unbind.
+
+ if (cancel) return null;
+ return directoryPath;
+}
+public void setFilterPath (String string) {
+ filterPath = string;
+}
+public void setMessage (String string) {
+ message = string;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
new file mode 100755
index 0000000000..a842c12ea9
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
@@ -0,0 +1,1401 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* A display is the class used to represent a group of widgets
+* that are all running in a single thread. Display's implement
+* event dispatching and a synchronous/asynchronous communication
+* mechanism to allow widgets in this thread to be accessed from
+* another thread.
+*
+* A typical application will use multiple threads, but only
+* one display, and therefore only one thread that can directly
+* access widgets. Other threads are typically used to compute
+* a value and communuicate the result to the widget thread.
+* Often, the widget thread will present a user interface that
+* allows the user to cancel or restart a computation. When a
+* computation is performed in the widget thread, events for
+* that thread are not dispatch because the widget thread is
+* doing the compuation, not dispatching the events. In this
+* case, widgets in the thread will not redraw and will not be
+* selectable by the user. On some platforms, the entire user
+* interface for every running program becomes locked. For
+* this reason, it is advisable to run only short computations
+* in the widget thread.
+*
+*
+**/
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+public class Display extends Device {
+
+ /* Motif Only Public Fields */
+ public XAnyEvent xEvent = new XAnyEvent ();
+
+ /* Windows, Events and Callbacks */
+ Callback windowCallback;
+ int windowProc, shellHandle;
+ static boolean XtInitialized;
+ static String APP_NAME = "SWT";
+ byte [] displayName, appName, appClass;
+ Event [] eventQueue;
+
+ /* Default Fonts, Colors, Insets, Widths and Heights. */
+ int defaultFont, defaultFontList;
+ int listFont, textFont, buttonFont, labelFont;
+ int dialogBackground, dialogForeground;
+ int buttonBackground, buttonForeground, buttonShadowThickness;
+ int compositeBackground, compositeForeground;
+ int compositeTopShadow, compositeBottomShadow, compositeBorder;
+ int listBackground, listForeground, textBackground, textForeground;
+ int labelBackground, labelForeground, scrollBarBackground, scrollBarForeground;
+ int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY;
+ int defaultBackground, defaultForeground;
+ int textHighlightThickness;
+
+ /* System Colors */
+ XColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW;
+ XColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_BORDER;
+ XColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT;
+ Color COLOR_INFO_BACKGROUND;
+
+ /* Initial Guesses for Shell Trimmings. */
+ int borderTrimWidth = 4, borderTrimHeight = 4;
+ int resizeTrimWidth = 6, resizeTrimHeight = 6;
+ int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28;
+ int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29;
+ int titleTrimWidth = 0, titleTrimHeight = 23;
+
+ /* Sync/Async Widget Communication */
+ Synchronizer synchronizer = new Synchronizer (this);
+ Thread thread = Thread.currentThread ();
+
+ /* Display Shutdown */
+ Runnable [] disposeList;
+
+ /* Timers */
+ int [] timerIDs;
+ Runnable [] timerList;
+ Callback timerCallback;
+ int timerProc;
+
+ /* Key Mappings. */
+ static int [] [] KeyTable = {
+
+ /* Keyboard and Mouse Masks */
+ {OS.XK_Alt_L, SWT.ALT},
+ {OS.XK_Alt_R, SWT.ALT},
+ {OS.XK_Shift_L, SWT.SHIFT},
+ {OS.XK_Shift_R, SWT.SHIFT},
+ {OS.XK_Control_L, SWT.CONTROL},
+ {OS.XK_Control_R, SWT.CONTROL},
+
+// {OS.VK_LBUTTON, SWT.BUTTON1},
+// {OS.VK_MBUTTON, SWT.BUTTON3},
+// {OS.VK_RBUTTON, SWT.BUTTON2},
+
+ /* Non-Numeric Keypad Constants */
+ {OS.XK_Up, SWT.ARROW_UP},
+ {OS.XK_Down, SWT.ARROW_DOWN},
+ {OS.XK_Left, SWT.ARROW_LEFT},
+ {OS.XK_Right, SWT.ARROW_RIGHT},
+ {OS.XK_Page_Up, SWT.PAGE_UP},
+ {OS.XK_Page_Down, SWT.PAGE_DOWN},
+ {OS.XK_Home, SWT.HOME},
+ {OS.XK_End, SWT.END},
+ {OS.XK_Insert, SWT.INSERT},
+// {OS.XK_Delete, SWT.DELETE},
+
+ /* Functions Keys */
+ {OS.XK_F1, SWT.F1},
+ {OS.XK_F2, SWT.F2},
+ {OS.XK_F3, SWT.F3},
+ {OS.XK_F4, SWT.F4},
+ {OS.XK_F5, SWT.F5},
+ {OS.XK_F6, SWT.F6},
+ {OS.XK_F7, SWT.F7},
+ {OS.XK_F8, SWT.F8},
+ {OS.XK_F9, SWT.F9},
+ {OS.XK_F10, SWT.F10},
+ {OS.XK_F11, SWT.F11},
+ {OS.XK_F12, SWT.F12},
+
+ /* Numeric Keypad Constants */
+ /*
+ {OS.XK_KP_Add, SWT.KP_PLUS},
+ {OS.XK_KP_Subtract, SWT.KP_MINUS},
+ {OS.XK_KP_Multiply, SWT.KP_TIMES},
+ {OS.XK_KP_Divide, SWT.KP_DIVIDE},
+ {OS.XK_KP_Decimal, SWT.KP_PERIOD},
+ {OS.XK_KP_Enter, SWT.KP_ENTER},
+ {OS.XK_KP_0, SWT.KP_0},
+ {OS.XK_KP_1, SWT.KP_1},
+ {OS.XK_KP_2, SWT.KP_2},
+ {OS.XK_KP_3, SWT.KP_3},
+ {OS.XK_KP_4, SWT.KP_4},
+ {OS.XK_KP_5, SWT.KP_5},
+ {OS.XK_KP_6, SWT.KP_6},
+ {OS.XK_KP_7, SWT.KP_7},
+ {OS.XK_KP_8, SWT.KP_8},
+ {OS.XK_KP_9, SWT.KP_9},
+ */
+ };
+
+ /* Multiple Displays. */
+ static Display Default;
+ static Display [] Displays = new Display [4];
+
+ /* Double Click */
+ int lastTime, lastButton;
+
+ /* Current caret */
+ Caret currentCaret;
+ Callback caretCallback;
+ int caretID, caretProc;
+
+ /* Workaround for GP when disposing a display */
+ static boolean DisplayDisposed;
+
+ /* Package name */
+ static final String PACKAGE_NAME;
+ static {
+ String name = Display.class.getName ();
+ int index = name.lastIndexOf ('.');
+ PACKAGE_NAME = name.substring (0, index + 1);
+ }
+
+ /* Mouse Hover */
+ Callback mouseHoverCallback;
+ int mouseHoverID, mouseHoverProc;
+ int mouseHoverHandle, toolTipHandle;
+
+ /* Parse Tables */
+ int [] parseTable;
+ int crPointer, tabPointer;
+
+ /* Xt Translations */
+ int arrowTranslations, tabTranslations;
+
+ /* Check Expose Proc */
+ Callback checkExposeCallback;
+ int checkExposeProc;
+ int exposeCount;
+
+ /* Sleeping */
+ int sleepID;
+ Callback sleepCallback;
+ int sleepProc;
+
+ /* Display Data */
+ Object data;
+ String [] keys;
+ Object [] values;
+
+public Display () {
+ this (null);
+}
+public Display (DeviceData data) {
+ super (checkNull (data));
+}
+static DeviceData checkNull (DeviceData data) {
+ if (data == null) data = new DeviceData ();
+ if (data.application_name == null) {
+ data.application_name = APP_NAME;
+ }
+ if (data.application_class == null) {
+ data.application_class = APP_NAME;
+ }
+ return data;
+}
+protected void checkDevice () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+}
+void addMouseHoverTimeOut (int handle) {
+ if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle);
+ mouseHoverHandle = handle;
+}
+public void asyncExec (Runnable runnable) {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ synchronizer.asyncExec (runnable);
+}
+public void beep () {
+ checkDevice ();
+ OS.XBell (xDisplay, 100);
+ OS.XFlush (xDisplay);
+}
+int caretProc (int clientData, int id) {
+ caretID = 0;
+ if (currentCaret == null) return 0;
+ if (currentCaret.blinkCaret ()) {
+ int blinkRate = currentCaret.blinkRate;
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
+ } else {
+ currentCaret = null;
+ }
+ return 0;
+}
+int checkExposeProc (int display, int event, int window) {
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, event, XExposeEvent.sizeof);
+ if (xEvent.window == window) {
+ if (xEvent.type == OS.Expose || xEvent.type == OS.GraphicsExpose) {
+ exposeCount++;
+ }
+ }
+ return 0;
+}
+synchronized void checkDisplay () {
+ for (int i=0; i<Displays.length; i++) {
+ if (Displays [i] != null && Displays [i].thread == thread) {
+ error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ }
+}
+protected void checkSubclass () {
+ if (!Display.isValidClass (getClass ())) {
+ error (SWT.ERROR_INVALID_SUBCLASS);
+ }
+}
+protected void create (DeviceData data) {
+ checkSubclass ();
+ checkDisplay ();
+ createDisplay (data);
+ register ();
+ if (Default == null) Default = this;
+}
+void createDisplay (DeviceData data) {
+
+ /* Initialize X and Xt */
+ synchronized (Display.class) {
+ if (!XtInitialized) {
+ OS.XInitThreads ();
+ OS.XtToolkitThreadInitialize ();
+ OS.XtToolkitInitialize ();
+
+ /* Bug in XpExtention. If XInitThreads is called before
+ * any Xp functions then XpCheckExtInit hangs. The workaround
+ * is to create the printer display before calling XInitThreads.
+ */
+// int xtContext = OS.XtCreateApplicationContext ();
+// byte[] buffer = Converter.wcsToMbcs ( null, Device.XDefaultPrintServer, true );
+// xPrinter = OS.XtOpenDisplay (xtContext, buffer, null, null, 0, 0, new int [] {0}, 0);
+// if (xPrinter != 0) {
+// OS.XpQueryVersion (xPrinter, new short [1], new short [1]);
+// }
+// //OS.XInitThreads ();
+ }
+ XtInitialized = true;
+ }
+
+ /* Create the AppContext */
+ int [] argc = new int [] {0};
+ int xtContext = OS.XtCreateApplicationContext ();
+ OS.XtSetLanguageProc (xtContext, 0, 0);
+
+ /* Compute the display name, application name and class */
+ String display_name = null;
+ String application_name = APP_NAME;
+ String application_class = APP_NAME;
+ if (data != null) {
+ if (data.display_name != null) display_name = data.display_name;
+ if (data.application_name != null) application_name = data.application_name;
+ if (data.application_class != null) application_class = data.application_class;
+ }
+ if (display_name != null) displayName = Converter.wcsToMbcs (null, display_name, true);
+ if (application_name != null) appName = Converter.wcsToMbcs (null, application_name, true);
+ if (application_class != null) appClass = Converter.wcsToMbcs (null, application_class, true);
+
+ /* Create the XDisplay */
+ xDisplay = OS.XtOpenDisplay (xtContext, displayName, appName, appClass, 0, 0, argc, 0);
+ DisplayDisposed = false;
+}
+synchronized void deregister () {
+ for (int i=0; i<Displays.length; i++) {
+ if (this == Displays [i]) Displays [i] = null;
+ }
+}
+protected void destroy () {
+ if (this == Default) Default = null;
+ deregister ();
+ destroyDisplay ();
+}
+void destroyDisplay () {
+ /*
+ * Destroy AppContext (this destroys the display)
+ */
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ OS.XtDestroyApplicationContext (xtContext);
+ DisplayDisposed = true;
+}
+public void disposeExec (Runnable runnable) {
+ checkDevice ();
+ if (disposeList == null) disposeList = new Runnable [4];
+ for (int i=0; i<disposeList.length; i++) {
+ if (disposeList [i] == null) {
+ disposeList [i] = runnable;
+ return;
+ }
+ }
+ Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
+ System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
+ newDisposeList [disposeList.length] = runnable;
+ disposeList = newDisposeList;
+}
+void error (int code) {
+ SWT.error(code);
+}
+boolean filterEvent (XAnyEvent event) {
+
+ /* Check the event and find the widget */
+ if (event.type != OS.KeyPress) return false;
+ if (OS.XFilterEvent(event, OS.None)) return true;
+ XKeyEvent keyEvent = new XKeyEvent ();
+
+ /* Move the any event into the key event */
+ OS.memmove (keyEvent, event, XAnyEvent.sizeof);
+ if (keyEvent.keycode == 0) return false;
+ int xWindow = keyEvent.window;
+ if (xWindow == 0) return false;
+ int handle = OS.XtWindowToWidget (xDisplay, xWindow);
+ if (handle == 0) return false;
+ handle = OS.XmGetFocusWidget (handle);
+ if (handle == 0) return false;
+ Widget widget = WidgetTable.get (handle);
+ if (widget == null) return false;
+ if (!(widget instanceof Control)) return false;
+ Control control = (Control) widget;
+
+ /* Get the unaffected character and keysym */
+ int oldState = keyEvent.state;
+ keyEvent.state = 0;
+ byte [] buffer1 = new byte [4];
+ int [] buffer2 = new int [1];
+ int key = 0;
+ if (OS.XLookupString (keyEvent, buffer1, 1, buffer2, null) != 0) {
+ key = buffer1 [0] & 0xFF;
+ }
+ int keysym = buffer2 [0] & 0xFFFF;
+ keyEvent.state = oldState;
+
+ /* Check for a mnemonic key */
+ if (key != 0) {
+ if (control.translateMnemonic (key, keyEvent)) return true;
+ }
+
+ /* Check for a traversal key */
+ if (keysym == 0) return false;
+ if (keysym == OS.XK_Escape || keysym == OS.XK_Cancel ||
+ keysym == OS.XK_Tab || keysym == OS.XK_Return ||
+ keysym == OS.XK_Up || keysym == OS.XK_Down ||
+ keysym == OS.XK_Left || keysym == OS.XK_Right) {
+ if (control.translateTraversal (keysym, keyEvent)) return true;
+ }
+
+ /* Answer false because the event was not processed */
+ return false;
+}
+public Widget findWidget (int handle) {
+ checkDevice ();
+ return WidgetTable.get (handle);
+}
+public Shell getActiveShell () {
+ checkDevice ();
+ Control control = getFocusControl ();
+ if (control == null) return null;
+ return control.getShell ();
+}
+public static synchronized Display getCurrent () {
+ return findDisplay (Thread.currentThread ());
+}
+public static synchronized Display findDisplay (Thread thread) {
+ for (int i=0; i<Displays.length; i++) {
+ Display display = Displays [i];
+ if (display != null && display.thread == thread) {
+ return display;
+ }
+ }
+ return null;
+}
+public Control getCursorControl () {
+ checkDevice ();
+ int [] unused = new int [1], buffer = new int [1];
+ int xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
+ do {
+ if (OS.XQueryPointer (
+ xDisplay, xParent, unused, buffer,
+ unused, unused, unused, unused, unused) == 0) return null;
+ if ((xWindow = buffer [0]) != 0) xParent = xWindow;
+ } while (xWindow != 0);
+ int handle = OS.XtWindowToWidget (xDisplay, xParent);
+ if (handle == 0) return null;
+ do {
+ Widget widget = WidgetTable.get (handle);
+ if (widget != null && widget instanceof Control) {
+ Control control = (Control) widget;
+ if (control.getEnabled ()) return control;
+ }
+ } while ((handle = OS.XtParent (handle)) != 0);
+ return null;
+}
+public Point getCursorLocation () {
+ checkDevice ();
+ int window = OS.XDefaultRootWindow (xDisplay);
+ int [] rootX = new int [1];
+ int [] rootY = new int [1];
+ int [] unused = new int [1];
+ OS.XQueryPointer(xDisplay, window, unused, unused, rootX, rootY, unused, unused, unused);
+ return new Point (rootX [0], rootY [0]);
+}
+public static synchronized Display getDefault () {
+ if (Default == null) Default = new Display ();
+ return Default;
+}
+public Object getData (String key) {
+ checkDevice ();
+ if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (keys == null) return null;
+ for (int i=0; i<keys.length; i++) {
+ if (keys [i].equals (key)) return values [i];
+ }
+ return null;
+}
+public Object getData () {
+ checkDevice ();
+ return data;
+}
+public int getDoubleClickTime () {
+ checkDevice ();
+ return OS.XtGetMultiClickTime (xDisplay);
+}
+public Control getFocusControl () {
+ checkDevice ();
+ int [] buffer1 = new int [1], buffer2 = new int [1];
+ OS.XGetInputFocus (xDisplay, buffer1, buffer2);
+ int xWindow = buffer1 [0];
+ if (xWindow == 0) return null;
+ int handle = OS.XtWindowToWidget (xDisplay, xWindow);
+ if (handle == 0) return null;
+ handle = OS.XmGetFocusWidget (handle);
+ if (handle == 0) return null;
+ do {
+ Widget widget = WidgetTable.get (handle);
+ if (widget != null && widget instanceof Control) {
+ Control window = (Control) widget;
+ if (window.getEnabled ()) return window;
+ }
+ } while ((handle = OS.XtParent (handle)) != 0);
+ return null;
+}
+public int getIconDepth () {
+ return getDepth ();
+}
+public Shell [] getShells () {
+ checkDevice ();
+ /*
+ * NOTE: Need to check that the shells that belong
+ * to another display have not been disposed by the
+ * other display's thread as the shells list is being
+ * processed.
+ */
+ int count = 0;
+ Shell [] shells = WidgetTable.shells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed () && this == shell.getDisplay ()) {
+ count++;
+ }
+ }
+ if (count == shells.length) return shells;
+ int index = 0;
+ Shell [] result = new Shell [count];
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed () && this == shell.getDisplay ()) {
+ result [index++] = shell;
+ }
+ }
+ return result;
+}
+/**
+ * Returns the thread that has invoked <code>syncExec</code>
+ * or <code>asyncExec</code>, or null if no such runnable is
+ * currently being invoked by the user-interface thread.
+ *
+ * @return the receiver's sync/async-interface thread
+ */
+public Thread getSyncThread () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ return synchronizer.syncThread;
+}
+/**
+* Get a system color
+*
+* RETURNS
+*
+* A color that corresponds to a system color.
+*
+* REMARKS
+*
+* This method returns the color corresponding to a
+* system color constant. All system color constants
+* begin with the prefix COLOR_.
+*
+**/
+public Color getSystemColor (int id) {
+ checkDevice ();
+ XColor xColor = null;
+ switch (id) {
+ case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
+ case SWT.COLOR_INFO_BACKGROUND: return COLOR_INFO_BACKGROUND;
+ case SWT.COLOR_TITLE_FOREGROUND: return super.getSystemColor (SWT.COLOR_WHITE);
+ case SWT.COLOR_TITLE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_BLUE);
+ case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_BLUE);
+ case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
+ case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_GRAY);
+ case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_GRAY);
+ case SWT.COLOR_WIDGET_DARK_SHADOW: xColor = COLOR_WIDGET_DARK_SHADOW; break;
+ case SWT.COLOR_WIDGET_NORMAL_SHADOW: xColor = COLOR_WIDGET_NORMAL_SHADOW; break;
+ case SWT.COLOR_WIDGET_LIGHT_SHADOW: xColor = COLOR_WIDGET_LIGHT_SHADOW; break;
+ case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: xColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break;
+ case SWT.COLOR_WIDGET_BACKGROUND: xColor = COLOR_WIDGET_BACKGROUND; break;
+ case SWT.COLOR_WIDGET_FOREGROUND:
+ case SWT.COLOR_WIDGET_BORDER: xColor = COLOR_WIDGET_BORDER; break;
+ case SWT.COLOR_LIST_FOREGROUND: xColor = COLOR_LIST_FOREGROUND; break;
+ case SWT.COLOR_LIST_BACKGROUND: xColor = COLOR_LIST_BACKGROUND; break;
+ case SWT.COLOR_LIST_SELECTION: xColor = COLOR_LIST_SELECTION; break;
+ case SWT.COLOR_LIST_SELECTION_TEXT: xColor = COLOR_LIST_SELECTION_TEXT; break;
+ default:
+ return super.getSystemColor (id);
+ }
+ if (xColor == null) return super.getSystemColor (SWT.COLOR_BLACK);
+ return Color.motif_new (this, xColor);
+}
+public Font getSystemFont () {
+ checkDevice ();
+ return Font.motif_new (this, defaultFontList);
+}
+public Thread getThread () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ return thread;
+}
+void hideToolTip () {
+ if (toolTipHandle != 0) {
+ int shellHandle = OS.XtParent(toolTipHandle);
+ OS.XtDestroyWidget(shellHandle);
+ }
+ toolTipHandle = 0;
+}
+protected void init () {
+ super.init ();
+ initializeDisplay ();
+ initializeButton ();
+ initializeComposite ();
+ initializeDialog ();
+ initializeLabel ();
+ initializeList ();
+ initializeScrollBar ();
+ initializeText ();
+ initializeSystemColors ();
+ initializeDefaults ();
+ initializeParseTable ();
+ initializeTranslations ();
+}
+void initializeButton () {
+
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+
+ /* Get the push button information */
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreatePushButton (shellHandle, null, null, 0);
+ OS.XtManageChild (widgetHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {
+ OS.XmNforeground, 0, /* 1 */
+ OS.XmNbackground, 0, /* 3 */
+ OS.XmNshadowThickness, 0, /* 5 */
+ OS.XmNfontList, 0, /* 7 */
+ };
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ buttonForeground = argList [1]; buttonBackground = argList [3];
+ buttonShadowThickness = argList [5];
+ /**
+ * Feature in Motif. Querying the font list from the widget and
+ * then destroying the shell (and the widget) could cause the
+ * font list to be freed as well. The fix is to make a copy of
+ * the font list, then to free it when the display is disposed.
+ */
+ buttonFont = OS.XmFontListCopy (argList [7]);
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeComposite () {
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ int shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ int scrolledHandle = OS.XmCreateMainWindow (shellHandle, null, null, 0);
+ int [] argList1 = {OS.XmNorientation, OS.XmHORIZONTAL};
+ int hScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList1, argList1.length / 2);
+ OS.XtManageChild (hScrollHandle);
+ int [] argList2 = {OS.XmNorientation, OS.XmVERTICAL};
+ int vScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList2, argList2.length / 2);
+ OS.XtManageChild (vScrollHandle);
+ OS.XtManageChild (scrolledHandle);
+ int [] argList5 = {
+ OS.XmNmarginWidth, 3,
+ OS.XmNmarginHeight, 3,
+ };
+ int formHandle = OS.XmCreateForm (scrolledHandle, null, argList5, argList5.length / 2);
+ OS.XtManageChild (formHandle);
+ int [] argList6 = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ };
+ int widgetHandle = OS.XmCreateDrawingArea (formHandle, null, argList6, argList6.length / 2);
+ OS.XtManageChild (widgetHandle);
+ OS.XmMainWindowSetAreas (scrolledHandle, 0, 0, hScrollHandle, vScrollHandle, formHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ int screen = OS.XDefaultScreen (xDisplay);
+ OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, screen), OS.XDisplayHeight (xDisplay, screen), 0);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (scrolledHandle, argList3, argList3.length / 2);
+ int [] argList8 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (formHandle, argList8, argList8.length / 2);
+ int [] argList4 = {
+ OS.XmNx, 0, /* 1 */
+ OS.XmNy, 0, /* 3 */
+ OS.XmNwidth, 0, /* 5 */
+ OS.XmNheight, 0, /* 7 */
+ OS.XmNforeground, 0, /* 9 */
+ OS.XmNbackground, 0, /* 11 */
+ OS.XmNtopShadowColor, 0, /* 13 */
+ OS.XmNbottomShadowColor, 0, /* 15 */
+ OS.XmNborderColor, 0, /* 17 */
+ };
+ OS.XtGetValues (widgetHandle, argList4, argList4.length / 2);
+ scrolledInsetX = argList4 [1] + argList8 [1];
+ scrolledInsetY = argList4 [3] + argList8 [3];
+ scrolledMarginX = argList3 [1] - argList8 [1] - argList4 [1] - argList4 [5];
+ scrolledMarginY = argList3 [3] - argList8 [3] - argList4 [3] - argList4 [7];
+ compositeForeground = argList4 [9]; compositeBackground = argList4 [11];
+ compositeTopShadow = argList4 [13]; compositeBottomShadow = argList4 [15];
+ compositeBorder = argList4 [17];
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeDefaults () {
+ defaultFontList = labelFont;
+ defaultForeground = compositeForeground;
+ defaultBackground = compositeBackground;
+
+ /**
+ * Initialize the default font id to the first
+ * font in the default font list
+ */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, defaultFontList)) {
+ return;
+ }
+ int context = buffer [0];
+ XFontStruct fontStruct = new XFontStruct ();
+ int [] fontStructPtr = new int [1];
+ int [] fontNamePtr = new int [1];
+
+ /* Take the first entry from the font list */
+ int fontListEntry = OS.XmFontListNextEntry (context);
+ int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
+ if (buffer [0] == 0) {
+ /* FontList contains a single font */
+ OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
+ defaultFont = fontStruct.fid;
+ } else {
+ /* FontList contains a fontSet */
+ /* Take the first font in the font set */
+ int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
+ if (nFonts > 0) {
+ int [] fontStructs = new int [1];
+ OS.memmove (fontStructs, fontStructPtr [0], 4);
+ OS.memmove (fontStruct, fontStructs [0], XFontStruct.sizeof);
+ defaultFont = fontStruct.fid;
+ }
+ }
+ OS.XmFontListFreeFontContext (context);
+}
+void initializeDialog () {
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateDialogShell (shellHandle, null, null, 0);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ dialogForeground = argList [1]; dialogBackground = argList [3];
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeDisplay () {
+
+ /* Create the callbacks */
+ windowCallback = new Callback (this, "windowProc", 4);
+ windowProc = windowCallback.getAddress ();
+ if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ timerCallback = new Callback (this, "timerProc", 2);
+ timerProc = timerCallback.getAddress ();
+ if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ caretCallback = new Callback (this, "caretProc", 2);
+ caretProc = caretCallback.getAddress ();
+ if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ mouseHoverCallback = new Callback (this, "mouseHoverProc", 2);
+ mouseHoverProc = mouseHoverCallback.getAddress ();
+ if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ checkExposeCallback = new Callback (this, "checkExposeProc", 3);
+ checkExposeProc = checkExposeCallback.getAddress ();
+ if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ sleepCallback = new Callback (this, "sleepProc", 2);
+ sleepProc = sleepCallback.getAddress ();
+ if (sleepProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ /*
+ * Use dynamic Drag and Drop Protocol styles.
+ * Preregistered protocol is not supported.
+ */
+ int xmDisplay = OS.XmGetXmDisplay (xDisplay);
+ int [] args = new int [] {
+ OS.XmNdragInitiatorProtocolStyle, OS.XmDRAG_DYNAMIC,
+ OS.XmNdragReceiverProtocolStyle, OS.XmDRAG_DYNAMIC,
+ };
+ OS.XtSetValues (xmDisplay, args, args.length / 2);
+
+ /* Create the hidden Override shell parent */
+ int xScreen = OS.XDefaultScreen (xDisplay);
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, xScreen), OS.XDisplayHeight (xDisplay, xScreen), 0);
+ OS.XtRealizeWidget (shellHandle);
+
+ /*
+ * Bug in MOTIF. For some reason, calls to XmGetPixmap ()
+ * and XmGetPixmapByDepth fail to find the pixmap unless at
+ * least one message box has been created. The fix is to
+ * create and destroy a message box.
+ */
+// int dialog = OS.XmCreateInformationDialog (shellHandle, null, null, 0);
+// OS.XtDestroyWidget (dialog);
+}
+void initializeLabel () {
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateLabel (shellHandle, null, null, 0);
+ OS.XtManageChild (widgetHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ labelForeground = argList [1]; labelBackground = argList [3];
+ /**
+ * Feature in Motif. Querying the font list from the widget and
+ * then destroying the shell (and the widget) could cause the
+ * font list to be freed as well. The fix is to make a copy of
+ * the font list, then to free it when the display is disposed.
+ */
+ labelFont = OS.XmFontListCopy (argList [5]);
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeList () {
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateScrolledList (shellHandle, null, null, 0);
+ OS.XtManageChild (widgetHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ listForeground = argList [1];
+ listBackground = argList [3];
+ /**
+ * Feature in Motif. Querying the font list from the widget and
+ * then destroying the shell (and the widget) could cause the
+ * font list to be freed as well. The fix is to make a copy of
+ * the font list, then to free it when the display is disposed.
+ */
+ listFont = OS.XmFontListCopy (argList [5]);
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeParseTable () {
+ byte[] tabBuffer = {(byte) '\t', 0};
+ tabPointer = OS.XtMalloc (tabBuffer.length);
+ OS.memmove (tabPointer, tabBuffer, tabBuffer.length);
+ int tabString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_TAB, 0, null);
+ int [] argList = {
+ OS.XmNpattern, tabPointer,
+ OS.XmNsubstitute, tabString,
+ };
+ int tabMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
+ OS.XmStringFree(tabString);
+
+ byte[] crBuffer = {(byte) '\n', 0};
+ crPointer = OS.XtMalloc (crBuffer.length);
+ OS.memmove (crPointer, crBuffer, crBuffer.length);
+ int crString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_SEPARATOR, 0, null);
+ argList = new int[] {
+ OS.XmNpattern, crPointer,
+ OS.XmNsubstitute, crString,
+ };
+ int crMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
+ OS.XmStringFree(crString);
+
+ parseTable = new int[2];
+ parseTable[0] = tabMapping;
+ parseTable[1] = crMapping;
+}
+void initializeScrollBar () {
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateScrollBar (shellHandle, null, null, 0);
+ OS.XtManageChild (widgetHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ scrollBarForeground = argList [1]; scrollBarBackground = argList [3];
+ OS.XtDestroyWidget (shellHandle);
+}
+void initializeSystemColors () {
+ int [] argList = {OS.XmNcolormap, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ int colormap = argList [1];
+
+ COLOR_WIDGET_DARK_SHADOW = new XColor();
+ COLOR_WIDGET_DARK_SHADOW.pixel = compositeBottomShadow;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_DARK_SHADOW);
+
+ COLOR_WIDGET_NORMAL_SHADOW = new XColor();
+ COLOR_WIDGET_NORMAL_SHADOW.pixel = compositeBottomShadow;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_NORMAL_SHADOW);
+
+ COLOR_WIDGET_LIGHT_SHADOW = new XColor();
+ COLOR_WIDGET_LIGHT_SHADOW.pixel = compositeTopShadow;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_LIGHT_SHADOW);
+
+ COLOR_WIDGET_HIGHLIGHT_SHADOW = new XColor();
+ COLOR_WIDGET_HIGHLIGHT_SHADOW.pixel = compositeTopShadow;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_HIGHLIGHT_SHADOW);
+
+ COLOR_WIDGET_BACKGROUND = new XColor();
+ COLOR_WIDGET_BACKGROUND.pixel = compositeBackground;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BACKGROUND);
+
+ COLOR_WIDGET_BORDER = new XColor();
+ COLOR_WIDGET_BORDER.pixel = compositeBorder;
+ OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BORDER);
+
+ COLOR_LIST_FOREGROUND = new XColor();
+ COLOR_LIST_FOREGROUND.pixel = listForeground;
+ OS.XQueryColor (xDisplay, colormap, COLOR_LIST_FOREGROUND);
+
+ COLOR_LIST_BACKGROUND = new XColor();
+ COLOR_LIST_BACKGROUND.pixel = listBackground;
+ OS.XQueryColor (xDisplay, colormap, COLOR_LIST_BACKGROUND);
+
+ COLOR_LIST_SELECTION = new XColor();
+ COLOR_LIST_SELECTION.pixel = listForeground;
+ OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION);
+
+ COLOR_LIST_SELECTION_TEXT = new XColor();
+ COLOR_LIST_SELECTION_TEXT.pixel = listBackground;
+ OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION_TEXT);
+
+ COLOR_INFO_BACKGROUND = new Color (this, 0xFF, 0xFF, 0xE1);
+}
+void initializeText () {
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreateScrolledText (shellHandle, null, null, 0);
+ OS.XtManageChild (widgetHandle);
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ OS.XtRealizeWidget (shellHandle);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNhighlightThickness, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ textForeground = argList [1]; textBackground = argList [3];
+ textHighlightThickness = argList[7];
+ /**
+ * Feature in Motif. Querying the font list from the widget and
+ * then destroying the shell (and the widget) could cause the
+ * font list to be freed as well. The fix is to make a copy of
+ * the font list, then to free it when the display is disposed.
+ */
+ textFont = OS.XmFontListCopy (argList [5]);
+ OS.XtDestroyWidget (shellHandle);
+
+}
+void initializeTranslations () {
+ byte [] buffer1 = Converter.wcsToMbcs (null, "<Key>osfUp:\n<Key>osfDown:\n<Key>osfLeft:\n<Key>osfRight:\0");
+ arrowTranslations = OS.XtParseTranslationTable (buffer1);
+ byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0");
+ tabTranslations = OS.XtParseTranslationTable (buffer2);
+// byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>\0");
+// overrideDragTranslations = OS.XtParseTranslationTable (buffer3);
+}
+public int internal_new_GC (GCData data) {
+ int xDrawable = OS.XDefaultRootWindow (xDisplay);
+ int xGC = OS.XCreateGC (xDisplay, xDrawable, 0, null);
+ if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
+ OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
+ if (data != null) {
+ data.device = this;
+ data.display = xDisplay;
+ data.drawable = xDrawable;
+ data.fontList = defaultFontList;
+ data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
+ }
+ return xGC;
+}
+public void internal_dispose_GC (int gc, GCData data) {
+ OS.XFreeGC(xDisplay, gc);
+}
+boolean isValidThread () {
+ return thread == Thread.currentThread ();
+}
+static boolean isValidClass (Class clazz) {
+ String name = clazz.getName ();
+ int index = name.lastIndexOf ('.');
+ return name.substring (0, index + 1).equals (PACKAGE_NAME);
+}
+int mouseHoverProc (int handle, int id) {
+ mouseHoverID = mouseHoverHandle = 0;
+ Widget widget = WidgetTable.get (handle);
+ if (widget == null) return 0;
+ return widget.processMouseHover(id);
+}
+void postEvent (Event event) {
+ /*
+ * Place the event at the end of the event queue.
+ * This code is always called in the Display's
+ * thread so it must be re-enterant but does not
+ * need to be synchronized.
+ */
+ if (eventQueue == null) eventQueue = new Event [4];
+ int index = 0;
+ int length = eventQueue.length;
+ while (index < length) {
+ if (eventQueue [index] == null) break;
+ index++;
+ }
+ if (index == length) {
+ Event [] newQueue = new Event [length + 4];
+ System.arraycopy (eventQueue, 0, newQueue, 0, length);
+ eventQueue = newQueue;
+ }
+ eventQueue [index] = event;
+}
+public boolean readAndDispatch () {
+ checkDevice ();
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ int status = OS.XtAppPending (xtContext);
+ if (status != 0) {
+ if ((status & OS.XtIMTimer) != 0) {
+ OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
+ runAsyncMessages ();
+ }
+ if ((status & OS.XtIMAlternateInput) != 0) {
+ OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput);
+ }
+ if ((status & OS.XtIMXEvent) != 0) {
+ OS.XtAppNextEvent (xtContext, xEvent);
+ if (filterEvent (xEvent)) return false;
+ OS.XtDispatchEvent (xEvent);
+ }
+ runDeferredEvents ();
+ return true;
+ }
+ return runAsyncMessages ();
+}
+synchronized void register () {
+ for (int i=0; i<Displays.length; i++) {
+ if (Displays [i] == null) {
+ Displays [i] = this;
+ return;
+ }
+ }
+ Display [] newDisplays = new Display [Displays.length + 4];
+ System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
+ newDisplays [Displays.length] = this;
+ Displays = newDisplays;
+}
+protected void release () {
+ super.release ();
+
+ /* Release shells */
+ Shell [] shells = WidgetTable.shells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed ()) {
+ if (this == shell.getDisplay ()) shell.dispose ();
+ }
+ }
+ while (readAndDispatch ()) {};
+
+ /* Run dispose list */
+ if (disposeList != null) {
+ for (int i=0; i<disposeList.length; i++) {
+ if (disposeList [i] != null) disposeList [i].run ();
+ }
+ }
+ disposeList = null;
+
+ /* Release synchronizer */
+ synchronizer.releaseSynchronizer ();
+ synchronizer = null;
+ releaseDisplay ();
+}
+void releaseDisplay () {
+ /* Dispose the caret callback */
+ if (caretID != 0) OS.XtRemoveTimeOut (caretID);
+ caretID = caretProc = 0;
+ caretCallback.dispose ();
+ caretCallback = null;
+
+ /* Dispose the timer callback */
+ if (timerIDs != null) {
+ for (int i=0; i<=timerIDs.length; i++) {
+ OS.XtRemoveTimeOut (timerIDs [i]);
+ }
+ }
+ timerIDs = null;
+ timerList = null;
+ timerProc = 0;
+ timerCallback.dispose ();
+ timerCallback = null;
+
+ /* Dispose the mouse hover callback */
+ if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
+ mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0;
+ mouseHoverCallback.dispose ();
+ mouseHoverCallback = null;
+
+ /* Dispose the sleep callback */
+ if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
+ sleepID = sleepProc = 0;
+ sleepCallback.dispose ();
+ sleepCallback = null;
+
+ /* Dispose window and expose callbacks */
+ windowCallback.dispose (); windowCallback = null;
+ checkExposeCallback.dispose (); checkExposeCallback = null;
+ checkExposeProc = 0;
+
+ /* Free the font lists */
+ if (buttonFont != 0) OS.XmFontListFree (buttonFont);
+ if (labelFont != 0) OS.XmFontListFree (labelFont);
+ if (textFont != 0) OS.XmFontListFree (textFont);
+ if (listFont != 0) OS.XmFontListFree (listFont);
+ listFont = textFont = labelFont = buttonFont = 0;
+ defaultFontList = defaultFont = 0;
+
+ /* Free the parse table */
+ OS.XtFree(tabPointer);
+ OS.XtFree(crPointer);
+ OS.XmParseTableFree(parseTable, parseTable.length);
+ parseTable = null;
+
+ /* Free the translations (no documentation describes how to do this) */
+ //OS.XtFree (arrowTranslations);
+ //OS.XtFree (tabTranslations);
+
+ /* Destroy the hidden Override shell parent */
+ if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
+ shellHandle = 0;
+
+ /* Release references */
+ thread = null;
+ xEvent = null;
+ buttonBackground = buttonForeground = 0;
+ defaultBackground = defaultForeground = 0;
+ COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW =
+ COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER =
+ COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = null;
+ COLOR_INFO_BACKGROUND = null;
+}
+void releaseToolTipHandle (int handle) {
+ if (mouseHoverHandle == handle) removeMouseHoverTimeOut ();
+ if (toolTipHandle != 0) {
+ int shellHandle = OS.XtParent(toolTipHandle);
+ int shellParent = OS.XtParent(shellHandle);
+ if (handle == shellParent) {
+ toolTipHandle = 0;
+ }
+ }
+}
+void removeMouseHoverTimeOut () {
+ if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
+ mouseHoverID = mouseHoverHandle = 0;
+}
+boolean runAsyncMessages () {
+ return synchronizer.runAsyncMessages ();
+}
+boolean runDeferredEvents () {
+ /*
+ * Run deferred events. This code is always
+ * called in the Display's thread so it must
+ * be re-enterant need not be synchronized.
+ */
+ while (eventQueue != null) {
+
+ /* Take an event off the queue */
+ Event event = eventQueue [0];
+ if (event == null) break;
+ int length = eventQueue.length;
+ System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
+ eventQueue [length] = null;
+
+ /* Run the event */
+ Widget widget = event.widget;
+ if (widget != null && !widget.isDisposed ()) {
+ Widget item = event.item;
+ if (item == null || !item.isDisposed ()) {
+ widget.notifyListeners (event.type, event);
+ }
+ }
+
+ /*
+ * At this point, the event queue could
+ * be null due to a recursive invokation
+ * when running the event.
+ */
+ }
+
+ /* Clear the queue */
+ eventQueue = null;
+ return true;
+}
+public static void setAppName (String name) {
+ APP_NAME = name;
+}
+void setCurrentCaret (Caret caret) {
+ if (caretID != 0) OS.XtRemoveTimeOut (caretID);
+ caretID = 0;
+ currentCaret = caret;
+ if (currentCaret != null) {
+ int blinkRate = currentCaret.blinkRate;
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
+ }
+}
+public void setData (String key, Object value) {
+ checkDevice ();
+ if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ /* Remove the key/value pair */
+ if (value == null) {
+ if (keys == null) return;
+ int index = 0;
+ while (index < keys.length && !keys [index].equals (key)) index++;
+ if (index == keys.length) return;
+ if (keys.length == 1) {
+ keys = null;
+ values = null;
+ } else {
+ String [] newKeys = new String [keys.length - 1];
+ Object [] newValues = new Object [values.length - 1];
+ System.arraycopy (keys, 0, newKeys, 0, index);
+ System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
+ System.arraycopy (values, 0, newValues, 0, index);
+ System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
+ keys = newKeys;
+ values = newValues;
+ }
+ return;
+ }
+
+ /* Add the key/value pair */
+ if (keys == null) {
+ keys = new String [] {key};
+ values = new Object [] {value};
+ return;
+ }
+ for (int i=0; i<keys.length; i++) {
+ if (keys [i].equals (key)) {
+ values [i] = value;
+ return;
+ }
+ }
+ String [] newKeys = new String [keys.length + 1];
+ Object [] newValues = new Object [values.length + 1];
+ System.arraycopy (keys, 0, newKeys, 0, keys.length);
+ System.arraycopy (values, 0, newValues, 0, values.length);
+ newKeys [keys.length] = key;
+ newValues [values.length] = value;
+ keys = newKeys;
+ values = newValues;
+}
+public void setData (Object data) {
+ checkDevice ();
+ this.data = data;
+}
+public void setSynchronizer (Synchronizer synchronizer) {
+ checkDevice ();
+ if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (this.synchronizer != null) {
+ this.synchronizer.runAsyncMessages();
+ }
+ this.synchronizer = synchronizer;
+}
+void showToolTip (int handle, String toolTipText) {
+ if (toolTipText == null || toolTipText.length() == 0 || toolTipHandle != 0) {
+ return;
+ }
+
+ /* Create the tooltip widgets. */
+ int widgetClass = OS.OverrideShellWidgetClass ();
+ int [] argList = {OS.XmNmwmDecorations, 0, OS.XmNborderWidth, 1};
+ int shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList, argList.length / 2);
+ toolTipHandle = OS.XmCreateLabel(shellHandle, null, null, 0);
+
+ /* Set the tooltip foreground and background. */
+ Color infoForeground = getSystemColor(SWT.COLOR_INFO_FOREGROUND);
+ Color infoBackground = getSystemColor(SWT.COLOR_INFO_BACKGROUND);
+ int foregroundPixel = (infoForeground == null) ? defaultForeground : infoForeground.handle.pixel;
+ int backgroundPixel = (infoBackground == null) ? defaultBackground : infoBackground.handle.pixel;
+ int [] argList2 = {OS.XmNforeground, foregroundPixel, OS.XmNbackground, backgroundPixel};
+ OS.XtSetValues (toolTipHandle, argList2, argList2.length / 2);
+ OS.XtManageChild(toolTipHandle);
+
+ /* Set the tooltip label string. */
+ byte [] buffer = Converter.wcsToMbcs (null, toolTipText, true);
+ int xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList3 = {OS.XmNlabelString, xmString};
+ OS.XtSetValues (toolTipHandle, argList3, argList3.length / 2);
+ if (xmString != 0) OS.XmStringFree (xmString);
+
+ /* Position and popup the tooltip. */
+ int xWindow = OS.XDefaultRootWindow (xDisplay);
+ int [] rootX = new int [1], rootY = new int [1], unused = new int [1];
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, unused);
+
+ /*
+ * Feature in X. There is no way to query the size of a cursor.
+ * The fix is to use the default cursor size which is 16x16.
+ */
+ int x = rootX [0] + 16, y = rootY [0] + 16;
+ OS.XtMoveWidget (shellHandle, x, y);
+ OS.XtPopup (shellHandle, OS.XtGrabNone);
+}
+public boolean sleep () {
+ checkDevice ();
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ /*
+ * Bug in Motif. For some reason, when a time out
+ * is added from another thread while the display
+ * thread inside of a call-in, it fails to wake up
+ * the display event thread. The fix is to limit
+ * the maximum time spent waiting for an event.
+ */
+ sleepID = OS.XtAppAddTimeOut (xtContext, 50, sleepProc, 0);
+ boolean result = OS.XtAppPeekEvent (xtContext, xEvent);
+ if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
+ sleepID = 0;
+ return result;
+}
+int sleepProc (int index, int id) {
+ sleepID = 0;
+ return 0;
+}
+public void syncExec (Runnable runnable) {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ synchronizer.syncExec (runnable);
+}
+public void timerExec (int milliseconds, Runnable runnable) {
+ checkDevice ();
+ if (timerList == null) timerList = new Runnable [4];
+ if (timerIDs == null) timerIDs = new int [4];
+ int index = 0;
+ while (index < timerList.length) {
+ if (timerList [index] == null) break;
+ index++;
+ }
+ if (index == timerList.length) {
+ Runnable [] newTimerList = new Runnable [timerList.length + 4];
+ System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
+ timerList = newTimerList;
+ int [] newTimerIDs = new int [timerIDs.length + 4];
+ System.arraycopy (timerIDs, 0, newTimerIDs, 0, timerIDs.length);
+ timerIDs = newTimerIDs;
+ }
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ int timerID = OS.XtAppAddTimeOut (xtContext, milliseconds, timerProc, index);
+ if (timerID != 0) {
+ timerIDs [index] = timerID;
+ timerList [index] = runnable;
+ }
+}
+int timerProc (int index, int id) {
+ if (timerList == null) return 0;
+ if (0 <= index && index < timerList.length) {
+ Runnable runnable = timerList [index];
+ timerList [index] = null;
+ timerIDs [index] = 0;
+ if (runnable != null) runnable.run ();
+ }
+ return 0;
+}
+static int translateKey (int key) {
+ for (int i=0; i<KeyTable.length; i++) {
+ if (KeyTable [i] [0] == key) return KeyTable [i] [1];
+ }
+ return 0;
+}
+static int untranslateKey (int key) {
+ for (int i=0; i<KeyTable.length; i++) {
+ if (KeyTable [i] [1] == key) return KeyTable [i] [0];
+ }
+ return 0;
+}
+public void update () {
+ checkDevice ();
+ XAnyEvent event = new XAnyEvent ();
+ int mask = OS.ExposureMask | OS.ResizeRedirectMask |
+ OS.StructureNotifyMask | OS.SubstructureNotifyMask |
+ OS.SubstructureRedirectMask;
+ OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
+ while (OS.XCheckMaskEvent (xDisplay, mask, event)) OS.XtDispatchEvent (event);
+}
+public void wake () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ if (OS.XtAppPending (xtContext) == 0) OS.XtAppAddTimeOut (xtContext, 0, 0, 0);
+}
+int windowProc (int handle, int clientData, int callData, int unused) {
+ Widget widget = WidgetTable.get (handle);
+ if (widget == null) return 0;
+ return widget.processEvent (clientData, callData);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java
new file mode 100755
index 0000000000..0b7a79abb5
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java
@@ -0,0 +1,254 @@
+package org.eclipse.swt.widgets;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * SWT - The Simple Widget Toolkit,
+ * (c) Copyright IBM Corp 1998, 1999.
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+
+/**
+ * A file dialog allows the user to navigate the file
+ * system and select a file name or type in a new name.
+ * The file name is not verified for correctness.
+ *
+ */
+public /*final*/ class FileDialog extends Dialog {
+ String [] filterNames = new String [0];
+ String [] filterExtensions = new String [0];
+ String filterPath = "";
+ String fullPath = "";
+ String fileName = "";
+ boolean cancel = true;
+ static final String FILTER = "*";
+
+public FileDialog (Shell parent) {
+ this (parent, SWT.PRIMARY_MODAL);
+}
+public FileDialog (Shell parent, int style) {
+ super (parent, style);
+}
+int activate (int widget, int client, int call) {
+ cancel = client == OS.XmDIALOG_CANCEL_BUTTON;
+ OS.XtUnmanageChild (widget);
+ return 0;
+}
+public String getFileName () {
+ return fileName;
+}
+public String [] getFileNames () {
+ return new String [] {fileName};
+}
+public String [] getFilterExtensions () {
+ return filterExtensions;
+}
+public String [] getFilterNames () {
+ return filterNames;
+}
+public String getFilterPath () {
+ return filterPath;
+}
+public String open () {
+
+ /* Get the parent */
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int display = appContext.xDisplay;
+ int parentHandle = appContext.shellHandle;
+ if ((parent != null) && (parent.getDisplay () == appContext))
+ parentHandle = parent.shellHandle;
+
+ /* Compute the dialog title */
+ /*
+ * Feature in Motif. It is not possible to set a shell
+ * title to an empty string. The fix is to set the title
+ * to be a single space.
+ */
+ String string = title;
+ if (string.length () == 0) string = " ";
+ byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
+ int xmStringPtr1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Compute the filter */
+ String mask = FILTER;
+ if (filterExtensions == null) filterExtensions = new String [0];
+ if (filterNames == null) filterNames = new String [0];
+ if (filterExtensions.length != 0) {
+ /* Motif does not support multiple filters, so ignore them
+ * if there are more than one, or if there is a ; separator.
+ */
+ if (filterExtensions.length == 1) {
+ String filter = filterExtensions [0];
+ if (filter.indexOf (';', 0) == -1) mask = filter;
+ }
+ }
+ byte [] buffer2 = Converter.wcsToMbcs (null, mask, true);
+ int xmStringPtr2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Compute the filter path */
+ if (filterPath == null) filterPath = "";
+ byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
+ int xmStringPtr3 = OS.XmStringParseText (
+ buffer3,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Create the dialog */
+ int [] argList1 = {
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
+ OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
+ OS.XmNdialogTitle, xmStringPtr1,
+ OS.XmNpattern, xmStringPtr2,
+ OS.XmNdirectory, xmStringPtr3,
+ };
+ /*
+ * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
+ * will not accept NULL for the widget name. This works fine on the other
+ * Motif platforms and in the other XmCreate calls on Linux. The fix is
+ * to pass in a NULL terminated string, not a NULL pointer.
+ */
+ byte [] name = new byte [] {0};
+ int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
+ int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
+ if (child != 0) OS.XtUnmanageChild (child);
+ OS.XmStringFree (xmStringPtr1);
+ OS.XmStringFree (xmStringPtr2);
+ OS.XmStringFree (xmStringPtr3);
+/*
+ string := OSWidget xmStringAt: XmNdirectory handle: dialog.
+ OSWidget xmStringAt: XmNdirSpec put: string, fileName handle: dialog.
+
+ "Select the matching file in the list and scroll to show it."
+ child := dialog xmFileSelectionBoxGetChild: XmDIALOGLIST.
+ child isNull ifFalse: [
+ string := OSWidget xmStringAt: XmNdirSpec handle: dialog.
+ string := PlatformConverter wcsToMbcs: 0 buffer: string.
+ xmString := OSXmString xmStringCreateLocalized: string asPSZ.
+ child
+ xmListSelectItem: xmString notify: false;
+ xmListSetItem: xmString.
+ xmString xmStringFree.
+
+ "Bug in Solaris. For some reason, the horizontal scroll bar in the dialog
+ list refuses to be displayed. This stops the dialog list from scrolling
+ horizontally and displaying the file names. This does not happen on other
+ Motif platforms. The fix is to force the horizontal scroll bar to be displayed
+ by explicitly setting the scroll bar display policy."
+ OSWidget resourceAt: XmNscrollBarDisplayPolicy put: XmSTATIC handle: child].
+*/
+
+ /* Hook the callbacks. */
+ Callback callback = new Callback (this, "activate", 3);
+ int address = callback.getAddress ();
+ OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
+ OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
+
+ /* Open the dialog and dispatch events. */
+ cancel = true;
+/*
+ shell == nil ifFalse: [
+ shell minimized ifTrue: [shell minimized: false]].
+*/
+ OS.XtManageChild (dialog);
+
+//BOGUS - should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch ()) appContext.sleep ();
+
+ /* Set the new path, file name and filter. */
+ fullPath = "";
+ if (!cancel) {
+ filterPath = fullPath = "";
+ int [] argList2 = {OS.XmNdirectory, 0, OS.XmNdirSpec, 0};
+ OS.XtGetValues (dialog, argList2, argList2.length / 2);
+ int xmString3 = argList2 [1];
+ int ptr = OS.XmStringUnparse (
+ xmString3,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (ptr != 0) {
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ filterPath = new String (Converter.mbcsToWcs (null, buffer));
+ }
+ OS.XmStringFree (xmString3);
+ int xmString4 = argList2 [3];
+ ptr = OS.XmStringUnparse (
+ xmString4,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (ptr != 0) {
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ fullPath = new String (Converter.mbcsToWcs (null, buffer));
+ }
+ OS.XmStringFree (xmString4);
+ int length = filterPath.length ();
+ if ((length != 0) && (filterPath.charAt (length - 1) == '/')) {
+ filterPath = filterPath.substring (0, length - 1);
+ int index = fullPath.length () - 1;
+ while ((index >= 0) && (fullPath.charAt (index) != '/')) --index;
+ fileName = fullPath.substring (index, fullPath.length ());
+ }
+ }
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ callback.dispose ();
+
+// (shell == nil or: [shell isDestroyed not]) ifTrue: [dialog xtDestroyWidget].
+// OSWidget updateDisplay.
+// entryPoint unbind.
+
+ if (cancel) return null;
+ return fullPath;
+}
+public void setFileName (String string) {
+ fileName = string;
+}
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
+public void setFilterNames (String [] names) {
+ filterNames = names;
+}
+public void setFilterPath (String string) {
+ filterPath = string;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java
new file mode 100755
index 0000000000..cbc3f4532a
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java
@@ -0,0 +1,870 @@
+package org.eclipse.swt.widgets;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * SWT - The Simple Widget Toolkit,
+ * (c) Copyright IBM Corp 1998, 1999.
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import java.text.*;
+import java.util.*;
+
+/**
+ * A FontDialog allows the user to select a font
+ * from all available fonts in the system.
+ */
+public /*final*/ class FontDialog extends Dialog {
+ private static final String TEXT_SAMPLE = "AaBbYyZz";
+ private static final String TEXT_FONT_NOT_LOADED = "Could not load selected font"; // text used in place of sample text when the selected font could not be loaded
+
+ private Shell shell; // the dialog shell
+ private Combo characterSet;
+ private Combo faceName;
+ private Combo fontSize;
+ private Combo fontStyle;
+ private Combo extendedStyle;
+ private Label sampleLabel;
+ private Button ok;
+ private Button cancel;
+
+ private boolean okSelected; // true if the dialog was hidden
+ // because the ok button was selected
+ private FontData dialogResult;
+ private Hashtable characterSets = new Hashtable(); // maps character sets to a hashtable
+ // that maps the fonts in that
+ // character set to FontStyles objects
+ private FontData initialSelection; // can be set by the programmer and
+ private Font sampleFont; // the sample font for the font data selected by the user.
+ // Used to correctly clean up allocated fonts
+ // will be used to initialize the font
+ // combo boxes when the dialog is opened
+/**
+ * Create a new instance of the receiver with 'parent' as
+ * its parent shell.
+ * @param parent - the parent shell. May be null
+ */
+public FontDialog(Shell parent) {
+ this(parent, SWT.NULL);
+}
+/**
+ * Create a new instance of the receiver with 'parent' as
+ * its parent shell using 'style' as the widget style.
+ * @param parent - the parent shell. May be null
+ * @param style - style bits used to create the receiver.
+ * See class definition for details
+ */
+public FontDialog(Shell parent, int style) {
+ super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
+}
+/**
+ * Add the fonts found in 'fonts' to the list of fonts.
+ * Fonts are stored by character set and face name. For each character
+ * set/face name combination there is one FontExtStyles object that
+ * captures the different extended styles and the sizes and styles
+ * available for that extended style.
+ */
+void addFonts(FontData fonts[]) {
+ FontData font;
+ String faceName;
+ String characterSet;
+ Hashtable characterSets = getFonts();
+ Hashtable faceNames;
+ FontExtStyles fontExtStyles;
+
+ for (int i = 0; i < fonts.length; i++) {
+ font = fonts[i];
+ characterSet = getTranslatedCharSet(font);
+ faceNames = (Hashtable) characterSets.get(characterSet);
+ faceName = getTranslatedFaceName(font);
+ if (faceNames == null) {
+ faceNames = new Hashtable();
+ characterSets.put(characterSet, faceNames);
+ }
+ fontExtStyles = (FontExtStyles) faceNames.get(faceName);
+ if (fontExtStyles == null) {
+ fontExtStyles = new FontExtStyles(font.getName()); // use original face name for FontExtStyles
+ faceNames.put(faceName, fontExtStyles);
+ }
+ fontExtStyles.add(font);
+ }
+ setFonts(characterSets);
+}
+/**
+ * Create the widgets of the dialog.
+ */
+void createChildren() {
+ Shell dialog = getDialogShell();
+ Label characterSetLabel = new Label(dialog, SWT.NULL);
+ Label faceNameLabel = new Label(dialog, SWT.NULL);
+ Label extendedStyleLabel = new Label(dialog, SWT.NULL);
+ Label fontSizeLabel;
+ Label fontStyleLabel;
+ Label fillLabel;
+ Group sampleGroup;
+ GridData gridData;
+ GridLayout layout = new GridLayout();
+ final int ColumnOneWidth = 200;
+ final int ColumnTwoWidth = 150;
+ final int ColumnThreeWidth = 100;
+
+ layout.numColumns = 4;
+ layout.marginWidth = 15;
+ layout.marginHeight = 15;
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 2;
+ dialog.setLayout(layout);
+
+ // row one
+ characterSetLabel.setText("Character set:");
+ faceNameLabel.setText("Font:");
+ extendedStyleLabel.setText("Extended style:");
+
+ new Label(dialog, SWT.NULL);
+
+ // row two
+ characterSet = new Combo(dialog, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData();
+ gridData.widthHint = ColumnOneWidth;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 2;
+ characterSet.setData(new Integer(-1));
+ characterSet.setLayoutData(gridData);
+
+ faceName = new Combo(dialog, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData();
+ gridData.widthHint = ColumnTwoWidth;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 2;
+ gridData.verticalAlignment = GridData.FILL;
+ faceName.setData(new Integer(-1));
+ faceName.setLayoutData(gridData);
+
+ extendedStyle = new Combo(dialog, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData();
+ gridData.widthHint = ColumnThreeWidth;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 2;
+ gridData.verticalAlignment = GridData.FILL;
+ extendedStyle.setData(new Integer(-1));
+ extendedStyle.setLayoutData(gridData);
+
+ // create ok and cancel buttons (row two and three)
+ createOkCancel();
+
+ // row four
+ createEmptyRow();
+
+ // row five
+ fontSizeLabel = new Label(dialog, SWT.NULL);
+ fontSizeLabel.setText("Size:");
+ fontStyleLabel = new Label(dialog, SWT.NULL);
+ fontStyleLabel.setText("Style:");
+
+ fillLabel = new Label(dialog, SWT.NULL);
+ gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ fillLabel.setLayoutData(gridData);
+
+ // row six
+ fontSize = new Combo(dialog, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.heightHint = 110;
+ fontSize.setData(new Integer(-1));
+ fontSize.setLayoutData(gridData);
+
+ fontStyle = new Combo(dialog, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ fontStyle.setData(new Integer(-1));
+ fontStyle.setLayoutData(gridData);
+
+ fillLabel = new Label(dialog, SWT.NULL);
+ gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ fillLabel.setLayoutData(gridData);
+
+ // row seven
+ createEmptyRow();
+
+ // row eight
+ sampleGroup = new Group(dialog, SWT.NULL);
+ sampleGroup.setText("Sample");
+ gridData = new GridData();
+ gridData.heightHint = 70;
+ gridData.horizontalSpan = 3;
+ gridData.horizontalAlignment = GridData.FILL;
+ sampleGroup.setLayoutData(gridData);
+
+ // setup group box with sample text
+ layout = new GridLayout();
+ layout.marginWidth = 10;
+ layout.marginHeight = 10;
+ sampleGroup.setLayout(layout);
+
+ sampleLabel = new Label(sampleGroup, SWT.CENTER);
+ sampleLabel.setText(TEXT_SAMPLE);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ sampleLabel.setLayoutData(gridData);
+
+ dialog.setSize(445, 410);
+}
+/**
+ * Answer the combo used to display all available character sets.
+ */
+Combo getCharacterSetCombo() {
+ return characterSet;
+}
+/**
+ * Answer the combo used to display all extended styles of
+ * the selected font.
+ */
+Combo getExtStyleCombo() {
+ return extendedStyle;
+}
+/**
+ * Answer the combo used to display the face names of the
+ * fonts in the selected character set.
+ */
+Combo getFaceNameCombo() {
+ return faceName;
+}
+/**
+ * Answer the FontData for the selected font.
+ * Answer null if no font was selected and the dialog was cancelled.
+ */
+public FontData getFontData() {
+ return dialogResult;
+}
+/**
+ * Answer the collection of fonts that are displayed by the
+ * receiver.
+ * See the class definition for an explanation of the structure
+ * of the returned Hashtable.
+ */
+Hashtable getFonts() {
+ return characterSets;
+}
+/**
+ * Return the sample font created from the selected font metrics.
+ * This font is set into the sampleLabel.
+ */
+Font getSampleFont() {
+ return sampleFont;
+}
+/**
+ * Answer the label used to display a sample of the selected font.
+ */
+Label getSampleLabel() {
+ return sampleLabel;
+}
+/**
+ * Answer the selected character set in the format used to load
+ * fonts.
+ */
+String getSelectedCharSet() {
+ String translatedCharSet = getCharacterSetCombo().getText();
+ String platformCharSet;
+ int characterSetIndex = translatedCharSet.indexOf("(");
+
+ if (characterSetIndex == -1) {
+ platformCharSet = translatedCharSet;
+ }
+ else {
+ platformCharSet = translatedCharSet.substring(
+ characterSetIndex + 1, translatedCharSet.length()-1);
+ }
+ return platformCharSet;
+}
+/**
+ * Answer the selected face name in the format used to load
+ * fonts.
+ */
+String getSelectedFaceName() {
+ String translatedFaceName = getFaceNameCombo().getText();
+ String platformFaceName;
+ int foundryIndex = translatedFaceName.indexOf("(");
+
+ if (foundryIndex == -1) { // if this is true, the face name is not selected from the list
+ platformFaceName = translatedFaceName;
+ }
+ else {
+ platformFaceName = translatedFaceName.substring(
+ 0, translatedFaceName.indexOf(" ("));
+ }
+ return platformFaceName;
+}
+/**
+ * Answer the selected font foundry in the format used to load
+ * fonts.
+ */
+String getSelectedFoundry() {
+ String translatedFaceName = getFaceNameCombo().getText();
+ String foundry = new String();
+ int foundryIndex = translatedFaceName.indexOf("(");
+
+ if (foundryIndex != -1) {
+ foundry = translatedFaceName.substring(
+ foundryIndex + 1, translatedFaceName.length()-1);
+ }
+ return foundry;
+}
+/**
+ * Answer a FontData object that can be used to load the selected
+ * font.
+ */
+FontData getSelectionFontData() {
+ String fontSize = getSizeCombo().getText();
+ String style = getStyleCombo().getText();
+ String extStyle = getExtStyleCombo().getText();
+ int styleBits = SWT.NULL;
+ Integer fontSizeInt = null;
+ FontData fontData;
+
+ if (style.indexOf(FontExtStyles.BOLD) != -1) {
+ styleBits |= SWT.BOLD;
+ }
+ if (style.indexOf(FontExtStyles.ITALIC) != -1) {
+ styleBits |= SWT.ITALIC;
+ }
+ try {
+ fontSizeInt = Integer.valueOf(fontSize);
+ }
+ catch (NumberFormatException exception) {}
+ if (fontSizeInt != null) {
+ fontData = new FontData(
+ getSelectedFaceName(),
+ fontSizeInt.intValue(),
+ styleBits);
+ }
+ else {
+ fontData = new FontData();
+ fontData.setName(getSelectedFaceName());
+ fontData.setStyle(styleBits);
+ }
+ if (extStyle.length() > 0) {
+ fontData.addStyle = extStyle;
+ }
+ fontData.characterSetRegistry = getSelectedCharSet();
+ fontData.foundry = getSelectedFoundry();
+ return fontData;
+}
+/**
+ * Answer the combo box used to display the available sizes of
+ * the selected font.
+ */
+Combo getSizeCombo() {
+ return fontSize;
+}
+/**
+ * Answer the combo box used to display the available styles of
+ * the selected font.
+ */
+Combo getStyleCombo() {
+ return fontStyle;
+}
+/**
+ * Answer the character set found in 'fontData' prefixed
+ * with a string explaining the character set.
+ */
+String getTranslatedCharSet(FontData fontData) {
+ String characterSet = fontData.characterSetRegistry;
+ String translatedCharSet = null;
+
+ if (characterSet.startsWith("iso8859") == true) {
+ translatedCharSet = "Western";
+ }
+ else
+ if (characterSet.startsWith("iso646") == true) {
+ translatedCharSet = "ASCII";
+ }
+ else
+ if (characterSet.startsWith("ucs") == true) {
+ translatedCharSet = "Unicode";
+ }
+ else
+ if (characterSet.startsWith("jis") == true) {
+ translatedCharSet = "Japanese";
+ }
+ else
+ if (characterSet.startsWith("gb") == true) {
+ translatedCharSet = "Simplified Chinese";
+ }
+ else
+ if (characterSet.startsWith("cns") == true) {
+ translatedCharSet = "Traditional Chinese";
+ }
+ else
+ if (characterSet.startsWith("ks") == true) {
+ translatedCharSet = "Korean";
+ }
+ if (translatedCharSet != null) {
+ translatedCharSet += " (" + characterSet + ')';
+ }
+ else {
+ translatedCharSet = characterSet;
+ }
+ return translatedCharSet;
+}
+/**
+ * Answer the face name as specified in FontData.familyName followed by
+ * the foundry set in parantheses if available.
+ * We display the face name first so that the list box sorts the fonts by
+ * face name, not by foundry. Users generally want to select fonts based
+ * on the face name and not by foundry. Once they've found the desired
+ * face name in the list they can compare the font variations from
+ * different foundries if available.
+ */
+String getTranslatedFaceName(FontData fontData) {
+ StringBuffer faceNameBuffer;
+
+ if (fontData.foundry != null && fontData.foundry.length() > 0) {
+ faceNameBuffer = new StringBuffer(fontData.fontFamily);
+ faceNameBuffer.append(" (");
+ faceNameBuffer.append(fontData.foundry);
+ faceNameBuffer.append(')');
+ }
+ else {
+ faceNameBuffer = new StringBuffer(fontData.getName());
+ }
+ return faceNameBuffer.toString();
+}
+/**
+ * Handle the events the receiver is listening to.
+ * Combo selections cause the downstream combos to be initialized
+ * with font data and the sample text to be updated.
+ */
+void handleEvents(Event event) {
+ int oldSelectionIndex;
+ int newSelectionIndex;
+
+ if (event.widget instanceof Combo) {
+ oldSelectionIndex = ((Integer) event.widget.getData()).intValue();
+ newSelectionIndex = ((Combo) event.widget).getSelectionIndex();
+ // work around broken getSelectionIndex
+ newSelectionIndex = ((Combo) event.widget).indexOf(((Combo) event.widget).getText());
+ event.widget.setData(new Integer(newSelectionIndex));
+ if (newSelectionIndex != oldSelectionIndex) {
+ if (event.widget == getCharacterSetCombo()) {
+ initFaceNameCombo();
+ }
+ else
+ if (event.widget == getFaceNameCombo()) {
+ initExtStyleCombo();
+ }
+ else
+ if (event.widget == getExtStyleCombo()) {
+ initFontDataCombos();
+ }
+ }
+ updateSample();
+ }
+ else
+ if (event.widget == getOKButton()) {
+ setOkSelected(true);
+ getDialogShell().setVisible(false);
+ }
+ else
+ if (event.widget == getCancelButton()) {
+ setOkSelected(false);
+ getDialogShell().setVisible(false);
+ }
+}
+/**
+ * Initialize the extended styles combo with the extended styles
+ * available for the selected font.
+ * Downstream combos are initialized as well (style and size).
+ */
+void initExtStyleCombo() {
+ String characterSet = getCharacterSetCombo().getText();
+ String faceName = getFaceNameCombo().getText();
+ Hashtable faceNames = (Hashtable) getFonts().get(characterSet);
+ FontExtStyles fontExtStyles = (FontExtStyles) faceNames.get(faceName);
+ Combo extStyleCombo = getExtStyleCombo();
+
+ setItemsSorted(extStyleCombo, fontExtStyles.getExtStyles());
+ extStyleCombo.select(0);
+ initFontDataCombos();
+}
+/**
+ * Initialize the face name combo box with all font names
+ * available in the selected character set.
+ * Downstream combos are initialized as well (extended style).
+ */
+void initFaceNameCombo() {
+ Hashtable faceNames = (Hashtable) getFonts().get(getCharacterSetCombo().getText());
+ Combo faceNameCombo = getFaceNameCombo();
+
+ faceNameCombo.removeAll();
+ setItemsSorted(faceNameCombo, faceNames);
+// faceNameCombo.select(0);
+// initExtStyleCombo();
+}
+/**
+ * Initialize the styles and size combos with the styles and sizes
+ * the selected font is available in.
+ */
+void initFontDataCombos() {
+ String characterSet = getCharacterSetCombo().getText();
+ String faceName = getFaceNameCombo().getText();
+ Hashtable faceNames = (Hashtable) getFonts().get(characterSet);
+ FontExtStyles fontStyles = (FontExtStyles) faceNames.get(faceName);
+
+ initSizeCombo(fontStyles);
+ initStyleCombo(fontStyles);
+}
+/**
+ * Initialize the size combo with the sizes the selected font
+ * is available in.
+ * If the selected font is scalable a selection of preset sizes
+ * is used.
+ */
+void initSizeCombo(FontExtStyles fontExtStyles) {
+ Vector sizes = null;
+ Integer size;
+ Combo sizeCombo = getSizeCombo();
+ String sizeStrings[] = {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"};
+ int selectionIndex = -1;
+ final int SelectionSize = 14;
+
+ sizeCombo.removeAll();
+ if (fontExtStyles.isScalable() == true) {
+ sizeCombo.setItems(sizeStrings);
+ selectionIndex = 4;
+ }
+ else {
+ sizes = fontExtStyles.getSizes(getExtStyleCombo().getText());
+ for (int i = 0; i < sizes.size(); i++) {
+ size = (Integer) sizes.elementAt(i);
+ sizeCombo.add(size.toString());
+ if (size.intValue() >= SelectionSize && selectionIndex == -1) {
+ selectionIndex = i;
+ }
+ }
+ }
+ if (selectionIndex == -1) {
+ selectionIndex = sizes.size() - 1; // select largest height if there's no font
+ // size that is at least as high as SelectionSize
+ }
+ sizeCombo.select(selectionIndex);
+}
+/**
+ * Initialize the styles combo with the styles the selected font
+ * is available in.
+ */
+void initStyleCombo(FontExtStyles fontExtStyles) {
+ Vector styleVector = fontExtStyles.getStyles(getExtStyleCombo().getText());
+ Enumeration styleEnum = styleVector.elements();
+ Combo styleCombo = getStyleCombo();
+ int selectionIndex = styleVector.indexOf(FontExtStyles.MEDIUM);
+ String style;
+
+ styleCombo.removeAll();
+ while (styleEnum.hasMoreElements() == true) {
+ style = (String) styleEnum.nextElement();
+ styleCombo.add(style);
+ }
+ if (selectionIndex == -1) {
+ selectionIndex = 0;
+ }
+ styleCombo.select(selectionIndex);
+}
+
+/**
+ * Initialize the widgets of the receiver with the data of
+ * all installed fonts.
+ * If the user specified a default font preselect that font in
+ * the combo boxes.
+ */
+void initializeWidgets() {
+ Combo characterSetCombo = getCharacterSetCombo();
+ Display display = getDialogShell().getDisplay();
+ FontData initialFontData = getFontData();
+ Font initialFont;
+
+ addFonts(display.getFontList(null, false)); // get all fonts availabe on the current display
+ addFonts(display.getFontList(null, true));
+ setItemsSorted(characterSetCombo, getFonts());
+
+ if (initialFontData != null) {
+ initialFont = new Font(display, initialFontData); // verify that the initial font data is a valid font
+ setFontCombos(initialFont.getFontData()[0]);
+ initialFont.dispose();
+ updateSample();
+ }
+}
+/**
+ * Register the receiver to receive events.
+ */
+void installListeners() {
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {handleEvents(event);}
+ };
+
+ getOKButton().addListener(SWT.Selection, listener);
+ getCancelButton().addListener(SWT.Selection, listener);
+ getCharacterSetCombo().addListener(SWT.Selection, listener);
+ getFaceNameCombo().addListener(SWT.Selection, listener);
+ getSizeCombo().addListener(SWT.Selection, listener);
+ getStyleCombo().addListener(SWT.Selection, listener);
+ getExtStyleCombo().addListener(SWT.Selection, listener);
+}
+/**
+ * Initialize the widgets of the receiver, open the dialog
+ * and block the method until the dialog is closed by the user.
+ */
+public FontData open() {
+ FontData dialogResult = null;
+ Font sampleFont;
+ Shell dialog = new Shell(getParent(), getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
+
+ setDialogShell(dialog);
+ createChildren();
+ installListeners();
+ openModal();
+ if (isOkSelected() == true) {
+ dialogResult = getSelectionFontData();
+ setFontData(dialogResult);
+ }
+ // Fix for 1FRTJZV
+ sampleFont = getSampleFont();
+ if (sampleFont != null) {
+ sampleFont.dispose();
+ }
+ // Fix for 1G5NLY7
+ if (dialog.isDisposed() == false) {
+ dialog.dispose();
+ }
+ return dialogResult;
+}
+/**
+ * Initialize the combo boxes with the data of the preselected
+ * font specified by the user.
+ */
+void setFontCombos(FontData fontData) {
+ String characterSet = getTranslatedCharSet(fontData);
+ String faceName = getTranslatedFaceName(fontData);
+ Hashtable faceNames = (Hashtable) getFonts().get(characterSet);
+ FontExtStyles fontStyles = (FontExtStyles) faceNames.get(faceName);
+ String value;
+
+ getCharacterSetCombo().setText(characterSet);
+ initFaceNameCombo();
+
+ getFaceNameCombo().setText(faceName);
+ initExtStyleCombo();
+
+ getExtStyleCombo().setText(fontData.addStyle);
+ initSizeCombo(fontStyles);
+
+ value = Integer.toString(fontData.getHeight());
+ getSizeCombo().setText(value);
+ initStyleCombo(fontStyles);
+
+ value = FontExtStyles.getStyleString(fontData.getStyle());
+ getStyleCombo().setText(value);
+}
+/**
+ * Set the preselected font of the receiver to 'fontData'.
+ */
+public void setFontData(FontData fontData) {
+ dialogResult = fontData;
+}
+/**
+ * Set the fonts that are displayed by the receiver to 'fonts'.
+ */
+void setFonts(Hashtable fonts) {
+ characterSets = fonts;
+}
+/**
+ * Set the contents of 'combo' to the keys of 'items'.
+ * Keys are sorted in ascending order first and have to be Strings.
+ */
+void setItemsSorted(Combo combo, Hashtable items) {
+ Enumeration itemKeys = items.keys();
+ String item;
+ String sortedItems[] = new String[items.size()];
+ int index = 0;
+
+ while (itemKeys.hasMoreElements() == true) {
+ sortedItems[index++] = (String) itemKeys.nextElement();
+ }
+ sort(sortedItems);
+ combo.setItems(sortedItems);
+}
+/**
+ * Set the sample font created from the selected font metrics
+ * to 'newSampleFont'.
+ * This font is set into the sampleLabel.
+ */
+void setSampleFont(Font newSampleFont) {
+ // only dispose fonts we created. See 1FRTK1M for details.
+ if (sampleFont != null) {
+ sampleFont.dispose();
+ }
+ sampleFont = newSampleFont;
+ getSampleLabel().setFont(sampleFont);
+}
+/**
+ * Sort 'items' in ascending order.
+ */
+void sort(String items[]) {
+ Collator collator = Collator.getInstance();
+
+ /* Shell Sort from K&R, pg 108 */
+ int length = items.length;
+ for (int gap = length/2; gap > 0; gap /= 2) {
+ for (int i = gap; i < length; i++) {
+ for (int j = i-gap; j >= 0; j -= gap) {
+ if (collator.compare(items[j], items[j+gap]) > 0) {
+ String swap = items[j];
+ items[j] = items[j+gap];
+ items[j+gap] = swap;
+ }
+ }
+ }
+ }
+}
+/**
+ * Set the font of the sample text to the selected font.
+ * Display an error in place of the sample text if the selected
+ * font could not be loaded.
+ */
+void updateSample() {
+ Display display = getDialogShell().getDisplay();
+ FontData selectionFontData = getSelectionFontData();
+ Font sampleFont;
+
+ // sampleFont may not be the same as the one specified in selectionFontData.
+ // This happens when selectionFontData specifies a font alias. In that case,
+ // Font loads the real font. See 1FG3UWX for details.
+ sampleFont = new Font(display, selectionFontData);
+ setSampleFont(sampleFont);
+}
+/**
+ * Fill one row in the grid layout with empty widgets.
+ * Used to achieve a bigger vertical spacing between separate
+ * groups of widgets (ie. new rows of Text/Combo combinations).
+ */
+void createEmptyRow() {
+ Shell dialog = getDialogShell();
+ Label fillLabel = new Label(dialog, SWT.NULL);
+ GridData gridData = new GridData();
+
+ gridData.heightHint = 5;
+ gridData.horizontalSpan = ((GridLayout) dialog.getLayout()).numColumns;
+ fillLabel.setLayoutData(gridData);
+}
+/**
+ * Create the widgets of the dialog.
+ */
+void createOkCancel() {
+ Shell dialog = getDialogShell();
+ GridData gridData;
+
+ ok = new Button(dialog, SWT.PUSH);
+ ok.setText("OK");
+ dialog.setDefaultButton(ok);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.widthHint = 70;
+ ok.setLayoutData(gridData);
+
+ cancel = new Button(dialog, SWT.PUSH);
+ cancel.setText("Cancel");
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ cancel.setLayoutData(gridData);
+}
+/**
+ * Answer the cancel button
+ */
+Button getCancelButton() {
+ return cancel;
+}
+
+/**
+ * Answer the dialog shell.
+ */
+Shell getDialogShell() {
+ return shell;
+}
+/**
+ * Answer the ok button.
+ */
+Button getOKButton() {
+ return ok;
+}
+
+/**
+ * Insert the method's description here.
+ * Creation date: (08/05/99 12:34:43)
+ * @return boolean
+ */
+boolean isOkSelected() {
+ return okSelected;
+}
+/**
+ * Open the receiver and set its size to the size calculated by
+ * the layout manager.
+ */
+void openDialog() {
+ Shell dialog = getDialogShell();
+ Point pt;
+ Rectangle displayRect;
+ int widthLimit;
+
+ // Start everything off by setting the shell size to its computed size.
+ pt = dialog.computeSize(-1, -1, false);
+
+ // Ensure that the width of the shell fits the display.
+ displayRect = dialog.getDisplay().getBounds();
+ widthLimit = displayRect.width * 7 / 8;
+ if (pt.x > widthLimit) {
+ pt = dialog.computeSize (widthLimit, -1, false);
+ }
+ dialog.setBounds (0, 0, pt.x, pt.y);
+ dialog.setText(getText());
+ // Open the window.
+ dialog.open();
+}
+/**
+ * Initialize the widgets of the receiver, open the dialog
+ * and block the method until the dialog is closed by the user.
+ */
+void openModal() {
+ Shell dialog = getDialogShell();
+ Display display = dialog.getDisplay();
+
+ initializeWidgets();
+ setFontData(null);
+ openDialog();
+ while (dialog.isDisposed() == false && dialog.getVisible() == true) {
+ if (display.readAndDispatch() == false) {
+ display.sleep();
+ }
+ }
+}
+/**
+ * Set whether the dialog was closed by selecting the ok button.
+ */
+void setOkSelected(boolean newOkSelected) {
+ okSelected = newOkSelected;
+}
+/**
+ * Set the shell used as the dialog window.
+ */
+void setDialogShell(Shell shell) {
+ this.shell = shell;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyle.java
new file mode 100755
index 0000000000..aa9305d0c9
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyle.java
@@ -0,0 +1,91 @@
+package org.eclipse.swt.widgets;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * SWT - The Simple Widget Toolkit,
+ * (c) Copyright IBM Corp 1998, 1999.
+ */
+
+import java.util.*;
+
+/**
+ * This class stores the sizes and styles for a font extended style.
+ * A font on X can have different styles and sizes depending on the
+ * extended style of a font.
+ */
+class FontExtStyle {
+ private Vector sizes;
+ private Vector styles;
+/**
+ * Create a new instance of the receiver
+ */
+FontExtStyle() {
+ sizes = new Vector();
+ styles = new Vector();
+}
+/**
+ * Add size to the existing sizes of the receiver.
+ * Insert in ascending sort order.
+ */
+void addSize(int size) {
+ Vector sizes = getSizes();
+ Integer sizeInteger;
+ Integer newSizeInteger = new Integer(size);
+
+ if (sizes.contains(newSizeInteger) == false) {
+ for (int i = 0; i < sizes.size(); i++) {
+ sizeInteger = (Integer) sizes.elementAt(i);
+ if (sizeInteger.intValue() > size) {
+ sizes.insertElementAt(newSizeInteger, i);
+ return;
+ }
+ }
+ sizes.addElement(newSizeInteger);
+ }
+}
+/**
+ * Add the 'style' to the list of styles.
+ * Styles are sorted in the order "medium", "medium italic", "bold",
+ * "bold italic"
+ * @param style - the font style. Can be "medium", "medium italic",
+ * "bold", "bold italic"
+ */
+void addStyle(String style) {
+ Vector styles = getStyles();
+ String existingStyle;
+
+ if (styles.contains(style) == true) {
+ return;
+ }
+ // "medium" always goes to top of list
+ if (style.equals(FontExtStyles.MEDIUM) == true) {
+ styles.insertElementAt(style, 0);
+ }
+ else {
+ // order is: "medium" "medium italic" "bold" "bold italic"
+ for (int i = 0; i < styles.size(); i++) {
+ existingStyle = (String) styles.elementAt(i);
+ if (existingStyle.startsWith(FontExtStyles.BOLD) == true &&
+ (style.startsWith(FontExtStyles.MEDIUM) == true ||
+ style.equals(FontExtStyles.BOLD) == true)) {
+ styles.insertElementAt(style, i);
+ return;
+ }
+ }
+ styles.addElement(style);
+ }
+}
+/**
+ * Answer the sizes that are available for the existing font.
+ * Vector is empty if the font is scalable.
+ */
+Vector getSizes() {
+ return sizes;
+}
+/**
+ * Answer the styles that are available for this extended style.
+ */
+Vector getStyles() {
+ return styles;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyles.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyles.java
new file mode 100755
index 0000000000..30fa605f6f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontExtStyles.java
@@ -0,0 +1,133 @@
+package org.eclipse.swt.widgets;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * SWT - The Simple Widget Toolkit,
+ * (c) Copyright IBM Corp 1998, 1999.
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/**
+ * This class stores the extended styles that are available for a
+ * font as well as the sizes and styles that are available for each
+ * extended styles.
+ */
+class FontExtStyles {
+ final static String MEDIUM = "medium";
+ final static String BOLD = "bold";
+ final static String ITALIC = "italic";
+
+ private String faceName;
+ private boolean isScalable = false;
+ private Hashtable extStyles = new Hashtable(); // keys are extended styles,
+ // values a Vector with the
+ // corresponding sizes or null
+ // if the font is scalable
+/**
+ * Create a new instance of the receiver for the font with the
+ * name 'faceName'.
+ */
+FontExtStyles(String faceName) {
+ this.faceName = faceName;
+}
+/**
+ * Add the extended style, style and size data of 'fontData'
+ * to the receiver.
+ * The face name in 'fontData' has to match the face name of
+ * the receiver.
+ */
+void add(FontData fontData) {
+ Hashtable extStyles = getExtStyles();
+ FontExtStyle extStyle;
+ Integer height;
+ String style;
+
+ if (fontData.getName().equals(getFaceName()) == false) {
+ return;
+ }
+ extStyle = (FontExtStyle) extStyles.get(fontData.addStyle);
+ if (extStyle == null) {
+ extStyle = new FontExtStyle();
+ extStyles.put(fontData.addStyle, extStyle);
+ }
+ if (fontData.getHeight() == 0) {
+ setScalable(true);
+ }
+ else { // add the font size if the font is not scalable
+ extStyle.addSize(fontData.getHeight());
+ }
+ // add the style
+ style = getStyleString(fontData.getStyle());
+ extStyle.addStyle(style);
+}
+/**
+ * Answer the extended styles stored by the receiver.
+ * See the class definition for an explanation of the returned
+ * data structure.
+ */
+Hashtable getExtStyles() {
+ return extStyles;
+}
+/**
+ * Answer the face name of the receiver.
+ * The extended styles are stored for this face name.
+ */
+String getFaceName() {
+ return faceName;
+}
+/**
+ * Answer the font sizes of the receiver for the extended style
+ * identified by 'extStyle'.
+ * @return the font sizes of the receiver for the extended style
+ * identified by 'extStyle'.
+ * Empty collection if isScalable() answers true.
+ */
+Vector getSizes(String extStyle) {
+ return ((FontExtStyle) getExtStyles().get(extStyle)).getSizes();
+}
+/**
+ * Answer the string displayed for 'style'
+ * @param style - the font style. Can be SWT.BOLD, SWT.ITALIC
+ * or both combined with logical OR.
+ */
+static String getStyleString(int style) {
+ String styleString;
+
+ if ((style & SWT.BOLD) != 0) {
+ styleString = BOLD;
+ }
+ else {
+ styleString = MEDIUM;
+ }
+ if ((style & SWT.ITALIC) != 0) {
+ styleString += ' ' + ITALIC;
+ }
+ return styleString;
+}
+/**
+ * Answer the font styles of the receiver for the extended style
+ * identified by 'extStyle'.
+ */
+Vector getStyles(String extStyle) {
+ return ((FontExtStyle) getExtStyles().get(extStyle)).getStyles();
+}
+/**
+ * Answer whether the receiver is scalable or not.
+ * @return true=receiver is scalable. false=receiver is not
+ * scalable. It stores all available font sizes.
+ */
+boolean isScalable() {
+ return isScalable;
+}
+/**
+ * Set whether the receiveris scalable..
+ * @param newIsScalable - true=receiver is scalable.
+ * false=receiver is not scalable. It stores all available font sizes.
+ */
+void setScalable(boolean newIsScalable) {
+ isScalable = newIsScalable;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java
new file mode 100755
index 0000000000..f68d4fc4d0
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java
@@ -0,0 +1,246 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+
+/**
+* The group class implements an etched border with that
+* is typically used to group radio buttons. A group can
+* have an optional label.
+* <p>
+* <b>Styles</b><br>
+* <dd>SHADOW_IN, SHADOW_OUT,<br>
+* <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT<br>
+* <br>
+*/
+
+/* Class Definition */
+public /*final*/ class Group extends Composite {
+ int labelHandle;
+/**
+* Creates a new instance of the widget.
+*/
+public Group (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int trimX, trimY, trimWidth, trimHeight;
+ int [] argList = {
+ OS.XmNwidth, 0,
+ OS.XmNheight, 0,
+ OS.XmNshadowThickness, 0,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int thickness = argList [5];
+ int marginWidth = argList [7];
+ int marginHeight = argList [9];
+ trimX = x - marginWidth + thickness;
+ trimY = y - marginHeight + thickness;
+ trimWidth = width + ((marginWidth + thickness) * 2);
+ trimHeight = height + ((marginHeight + thickness) * 2);
+ if (OS.XtIsManaged (labelHandle)) {
+ int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
+ OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
+ int labelHeight = ((short) argList2 [1]) + argList2 [3];
+ trimY = y - labelHeight;
+ trimHeight = height + labelHeight + (marginHeight + thickness);
+ }
+ return new Rectangle (trimX, trimY, trimWidth, trimHeight);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+
+ /*
+ * Feature in Motif. When a widget is managed or unmanaged,
+ * it may request and be granted, a new size in the OS. This
+ * behavior is unwanted. The fix is to create a parent for
+ * the list that will disallow geometry requests.
+ */
+ int border = (style & SWT.BORDER) != 0 ? 1 : 0;
+ int [] argList1 = {OS.XmNborderWidth, border};
+ formHandle = OS.XmCreateForm (parent.handle, null, argList1, argList1.length / 2);
+ if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int [] argList2 = {
+ OS.XmNshadowType, shadowType (),
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ OS.XmNresizable, 0,
+ };
+ handle = OS.XmCreateFrame (formHandle, null, argList2, argList2.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ int [] argList3 = {OS.XmNchildType, OS.XmFRAME_TITLE_CHILD};
+ labelHandle = OS.XmCreateLabel (handle, null, argList3, argList3.length / 2);
+ if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ /*
+ * Bug in Motif. For some reason, if a form has not been realized,
+ * calling XtResizeWidget () on the form does not lay out properly.
+ * The fix is to force the widget to be realized by forcing the shell
+ * to be realized.
+ */
+ getShell ().realizeWidget ();
+}
+void enableWidget (boolean enabled) {
+ super.enableWidget (enabled);
+ enableHandle (enabled, labelHandle);
+}
+int fontHandle () {
+ return labelHandle;
+}
+/**
+* Gets the client area.
+*/
+public Rectangle getClientArea () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {
+ OS.XmNwidth, 0,
+ OS.XmNheight, 0,
+ OS.XmNshadowThickness, 0,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int thickness = argList [5];
+ int marginWidth = argList [7];
+ int marginHeight = argList [9];
+ int x = marginWidth + thickness;
+ int y = marginHeight + thickness;
+ int width = argList [1] - ((marginWidth + thickness) * 2) - 1;
+ int height = argList [3] - ((marginHeight + thickness) * 2) - 1;
+ if (OS.XtIsManaged (labelHandle)) {
+ int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
+ OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
+ y = ((short) argList2 [1]) + argList2 [3];
+ height = argList [3] - y - (marginHeight + thickness) - 1;
+ }
+ return new Rectangle (x, y, width, height);
+}
+/**
+* Gets the widget text.
+* <p>
+* @return the text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNlabelString, 0};
+ OS.XtGetValues (labelHandle, argList, 1);
+ int xmString = argList [1];
+ int address = OS.XmStringUnparse (
+ xmString,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) return "";
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ OS.XmStringFree (xmString);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+boolean mnemonicHit () {
+ return setFocus ();
+}
+boolean mnemonicMatch (char key) {
+ char mnemonic = findMnemonic (getText ());
+ if (mnemonic == '\0') return false;
+ return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ propagateHandle (enabled, labelHandle);
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
+ short [] label_x = new short [1], label_y = new short [1];
+ OS.XtTranslateCoords (labelHandle, (short) 0, (short) 0, label_x, label_y);
+ redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, labelHandle);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ labelHandle = 0;
+}
+/**
+* Sets the widget text.
+* <p>
+* @param string the string
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList = {OS.XmNlabelString, xmString};
+ OS.XtSetValues (labelHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmString);
+ if (string.length () == 0) {
+ OS.XtUnmanageChild (labelHandle);
+ } else {
+ OS.XtManageChild (labelHandle);
+ }
+}
+int shadowType () {
+ if ((style & SWT.SHADOW_IN) != 0) return OS.XmSHADOW_IN;
+ if ((style & SWT.SHADOW_OUT) != 0) return OS.XmSHADOW_OUT;
+ if ((style & SWT.SHADOW_ETCHED_IN) != 0) return OS.XmSHADOW_ETCHED_IN;
+ if ((style & SWT.SHADOW_ETCHED_OUT) != 0) return OS.XmSHADOW_ETCHED_OUT;
+ return OS.XmSHADOW_ETCHED_IN;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Header.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Header.java
new file mode 100755
index 0000000000..0c2e37f0b6
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Header.java
@@ -0,0 +1,336 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * A header draws one or more header items. Each item may have a text
+ * label. Each item is identified by an index and can be resized.
+ */
+class Header extends Canvas {
+ private static final int DEFAULT_WIDTH = 64; // used in computeSize if width could not be calculated
+ private static final int DEFAULT_HEIGHT = 64; // used in computeSize if height could not be calculated
+ private static final int VERTICAL_MARGIN = 4; // space added to the height of the header label
+ private static final int TEXT_Y_OFFSET = 2; // space between the header label and the lower header boundary
+ private static final int DEFAULT_ITEM_WIDTH = 9; // default width of a header item
+ private static final int TEXT_MARGIN = 6; // space in front and behind header text
+ private static final int SHADOW_WIDTH = 2; // width of the right side header shadow
+/**
+ * Create a Header widget as a child of 'parent'.
+ * @param parent - the parent of the new instance
+ */
+Header(Table parent) {
+ super(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_FOCUS);
+
+ addListener(SWT.Paint, new Listener() {
+ public void handleEvent(Event event) {paint(event);}
+ });
+ setHeaderHeight();
+}
+/**
+ * Answer the size of the receiver needed to display all items.
+ */
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = 0;
+ int height = 0;
+
+ for (int i = 0; i < getItemCount(); i++) {
+ width += getBounds(i).width;
+ if (height == 0) {
+ height = getBounds(i).height;
+ }
+ }
+ if (width == 0) {
+ width = DEFAULT_WIDTH;
+ }
+ if (height == 0) {
+ height = DEFAULT_HEIGHT;
+ }
+ if (wHint != SWT.DEFAULT) {
+ width = wHint;
+ }
+ if (hHint != SWT.DEFAULT) {
+ height = hHint;
+ }
+ return new Point(width, height);
+}
+/**
+ * Draw the bright shadow on the upper and left sides of a header item.
+ * @param gc - GC to draw on
+ * @param itemIndex - specifies the item to draw
+ */
+void drawHighlightShadow(GC gc, int itemIndex) {
+ Rectangle bounds = getBounds(itemIndex);
+ Color oldForeground = getForeground();
+
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
+ // draw top horizontal line
+ gc.drawLine(bounds.x, bounds.y, bounds.x + bounds.width - 1, bounds.y);
+ // draw left vertical line
+ gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);
+ gc.setForeground(oldForeground);
+}
+/**
+ * Draw the dark shadow on the lower and right side of a header item.
+ * @param gc - GC to draw on
+ * @param itemIndex - specifies the item to draw
+ */
+void drawLowlightShadows(GC gc, int itemIndex) {
+ Rectangle bounds = getBounds(itemIndex);
+ Point bottomShadowStart = new Point(bounds.x + 1, bounds.height - 2);
+ Point bottomShadowStop = new Point(bottomShadowStart.x + bounds.width - 2, bottomShadowStart.y);
+ Point rightShadowStart = null;
+ Point rightShadowStop = null;
+ Display display = getDisplay();
+ Color oldForeground = getForeground();
+
+ // light inner shadow
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
+ gc.drawLine(
+ bottomShadowStart.x, bottomShadowStart.y,
+ bottomShadowStop.x, bottomShadowStop.y);
+ if(itemIndex != TableColumn.FILL) {
+ rightShadowStart = new Point(bounds.x + bounds.width - 2, bounds.y + 1);
+ rightShadowStop = new Point(rightShadowStart.x, bounds.height - 2);
+ gc.drawLine(
+ rightShadowStart.x, rightShadowStart.y,
+ rightShadowStop.x, rightShadowStop.y);
+ }
+ // dark outer shadow
+ bottomShadowStart.x--;
+ bottomShadowStart.y++;
+ bottomShadowStop.y++;
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
+ gc.drawLine(
+ bottomShadowStart.x, bottomShadowStart.y,
+ bottomShadowStop.x, bottomShadowStop.y);
+ if(itemIndex != TableColumn.FILL) {
+ rightShadowStart.x++;
+ rightShadowStart.y--;
+ rightShadowStop.y++;
+ rightShadowStop.x++;
+ gc.drawLine(
+ rightShadowStart.x, rightShadowStart.y,
+ rightShadowStop.x, rightShadowStop.y);
+ }
+ gc.setForeground(oldForeground);
+}
+/**
+ * Draw the item text of the item identified by 'itemIndex'.
+ * @param gc - GC to draw on
+ * @param itemIndex - specifies the item to draw
+ */
+void drawText(GC gc, int itemIndex) {
+ String label = getText(gc, itemIndex);
+ Point textExtent;
+ Rectangle bounds = getBounds(itemIndex);
+ int yPosition;
+ int xPosition = 0;
+ int alignment;
+
+ if (label != null) {
+ alignment = ((Table) getParent()).internalGetColumn(itemIndex).getAlignment();
+ textExtent = gc.stringExtent(label);
+ yPosition = bounds.height - textExtent.y - TEXT_Y_OFFSET;
+
+ if ((alignment & SWT.CENTER) != 0) {
+ xPosition = (bounds.width - textExtent.x) / 2;
+ }
+ else
+ if ((alignment & SWT.RIGHT) != 0) {
+ xPosition = bounds.width - textExtent.x - TEXT_MARGIN;
+ }
+ xPosition = Math.max(TEXT_MARGIN, xPosition);
+ xPosition += bounds.x;
+ gc.drawString(label, xPosition, yPosition);
+ }
+}
+/**
+ * Answer the bounding rectangle of the item identified by 'itemIndex'.
+ * @param itemIndex - specifies the item whose bounding rectangle
+ * should be returned.
+ * @return the bouding rectangle of the item identified by 'itemIndex'.
+ */
+Rectangle getBounds(int itemIndex) {
+ Rectangle bounds = null;
+ int itemCount = getItemCount();
+ Table parent = (Table) getParent();
+
+ if (itemIndex >= 0 && itemIndex < itemCount) {
+ bounds = parent.internalGetColumn(itemIndex).getBounds();
+ bounds.y = 0;
+ bounds.height = getBounds().height;
+ }
+ else
+ if (itemIndex == TableColumn.FILL) {
+ if (itemCount > 0) {
+ bounds = parent.internalGetColumn(itemCount - 1).getBounds();
+ bounds.x += bounds.width;
+ }
+ else {
+ bounds = new Rectangle(0, 0, 0, 0);
+ }
+ bounds.width = Math.max(0, getBounds().width - bounds.x);
+ bounds.y = 0;
+ bounds.height = getBounds().height;
+ }
+ return bounds;
+}
+/**
+ * Answer the number of items in the receiver.
+ */
+int getItemCount() {
+ return ((Table) getParent()).internalGetColumnCount();
+}
+/**
+ * Answer the maximum label width that fits into the item identified by
+ * 'itemIndex'.
+ */
+int getMaxLabelWidth(int itemIndex) {
+ return getBounds(itemIndex).width - 2 * TEXT_MARGIN;
+}
+/**
+ * Answer the width required to display the complete label of the header
+ * item at position 'index'.
+ * @param index - position of the header item whose preferred width should
+ * be returned.
+ */
+int getPreferredWidth(int index) {
+ Table parent = (Table) getParent();
+ String text = getText(index);
+ int headerWidth = 0;
+
+ if (text != null) {
+ headerWidth = parent.getTextWidth(text) + 2 * TEXT_MARGIN + 1;
+ }
+ return headerWidth;
+}
+/**
+ * Answer the label of the item identified by 'itemIndex'.
+ */
+String getText(int itemIndex) {
+ String itemLabel = null;
+
+ if (itemIndex >= 0 && itemIndex < getItemCount()) {
+ itemLabel = ((Table) getParent()).internalGetColumn(itemIndex).getText();
+ }
+ return itemLabel;
+}
+/**
+ * Answer the text that is going to be drawn in the header item
+ * identified by 'itemIndex'. This may be truncated to fit the item
+ * width.
+ * @param gc - GC to use for measuring the label width.
+ * @param itemIndex - specifies the item whose label should be returned.
+ */
+String getText(GC gc, int itemIndex) {
+ String label = getText(itemIndex);
+ int maxWidth;
+
+ if (label != null) {
+ maxWidth = getMaxLabelWidth(itemIndex);
+ label = ((Table) getParent()).trimItemText(label, maxWidth, gc);
+ }
+ return label;
+}
+/**
+ * Draw the header item identified by 'itemIndex'.
+ * @param gc - GC to draw on
+ * @param itemIndex - item that should be drawn
+ */
+void paint(GC gc, int itemIndex) {
+ Rectangle bounds = getBounds(itemIndex);
+
+ // draw header background
+ gc.fillRectangle(bounds.x, bounds.y + 1, bounds.width, bounds.height - 3);
+ if (itemIndex != TableColumn.FILL) {
+ drawText(gc, itemIndex);
+ }
+ drawHighlightShadow(gc, itemIndex);
+ drawLowlightShadows(gc, itemIndex);
+}
+/**
+ * Draw all header items.
+ * @param event - Paint event triggering the drawing operation.
+ */
+void paint(Event event) {
+ int labelCount = getItemCount();
+
+ for (int i = 0; i < labelCount; i++) {
+ paint(event.gc, i);
+ }
+ paint(event.gc, TableColumn.FILL); // paint empty fill item behind last item
+}
+/**
+ * Redraw the item identified by 'itemIndex'.
+ * @param itemIndex - specifies the header item that should be redrawn
+ */
+void redraw(int itemIndex) {
+ Rectangle bounds = getBounds(itemIndex);
+
+ if (bounds != null) {
+ redraw(bounds.x, 0, bounds.width, bounds.height, false);
+ }
+}
+
+/**
+ * Set a new font. Recalculate the header height and redraw the header.
+ */
+public void setFont(Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (font == null || font.equals(getFont()) == true) {
+ return;
+ }
+ super.setFont(font);
+ setHeaderHeight();
+ redraw();
+}
+/**
+ * Calculate and store the height of the receiver.
+ */
+void setHeaderHeight() {
+ GC gc = new GC(this);
+ Rectangle bounds = getBounds();
+
+ bounds.height = gc.stringExtent("aString").y + VERTICAL_MARGIN;
+ setBounds(bounds);
+ gc.dispose();
+}
+/**
+ * The width of the header item at position 'itemIndex' is about to change.
+ * Adjust the width of the header. Scroll and redraw all header items
+ * starting behind the item identified by 'itemIndex'.
+ * @param itemIndex - specifies the item after which the redraw
+ * should begin.
+ * @param widthDiff - the width change of the item.
+ * > 0 = item width increased. < 0 = item width decreased
+ */
+void widthChange(int itemIndex, int widthDiff) {
+ Rectangle bounds = getBounds(itemIndex);
+ Rectangle headerBounds = getBounds();
+
+ if (bounds != null) {
+ if (itemIndex != TableColumn.FILL) { // ignore the fill column header item - there's nothing to redraw anyway
+ scroll(
+ bounds.x + bounds.width + widthDiff, 0, // destination x, y
+ bounds.x + bounds.width, 0, // source x, y
+ headerBounds.width + widthDiff, headerBounds.height, false);
+ redraw(bounds.x, 0, bounds.width, bounds.height, false);
+ }
+ }
+ headerBounds.width += widthDiff;
+ setBounds(headerBounds);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java
new file mode 100755
index 0000000000..0bb0d5548a
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java
@@ -0,0 +1,408 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+* A label is a non-selectable user interface object
+* that represents displays a static value.
+*
+* <b>Styles</b><br>
+* <dd>SEPARATOR, HORIZONTAL, VERTICAL, SHADOW_IN, SHADOW_OUT<br>
+*/
+
+/* Class Definition */
+public /*final*/ class Label extends Control {
+ Image image, bitmap, disabled;
+/**
+* Creates a new instance of the widget.
+*/
+public Label (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ if ((style & SWT.SEPARATOR) != 0) return style;
+ return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ if ((style & SWT.SEPARATOR) != 0) {
+ if ((style & SWT.HORIZONTAL) != 0) {
+ width += DEFAULT_WIDTH; height += 3;
+ } else {
+ width += 3; height += DEFAULT_HEIGHT;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+ }
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ result.request_mode = OS.CWWidth | OS.CWHeight;
+ int [] argList2 = {OS.XmNrecomputeSize, 1};
+ OS.XtSetValues(handle, argList2, argList2.length / 2);
+ OS.XtQueryGeometry (handle, null, result);
+ int [] argList3 = {OS.XmNrecomputeSize, 0};
+ OS.XtSetValues(handle, argList3, argList3.length / 2);
+ width += result.width;
+ height += result.height;
+ /**
+ * Feature in Motif. If a button's labelType is XmSTRING but it
+ * has no label set into it yet, recomputing the size will
+ * not take into account the height of the font, as we would
+ * like it to. Take care of this case.
+ */
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmSTRING) {
+ int [] argList1 = {OS.XmNlabelString, 0};
+ OS.XtGetValues (handle, argList1, argList1.length / 2);
+ int xmString = argList1 [1];
+ if (OS.XmStringEmpty (xmString)) {
+ height += getFontHeight ();
+ width = 0;
+ }
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
+ if ((style & SWT.SEPARATOR) != 0) {
+ int separatorType = separatorType ();
+ int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.XmHORIZONTAL : OS.XmVERTICAL;
+ int [] argList = {
+ OS.XmNborderWidth, borderWidth,
+ OS.XmNorientation, orientation,
+ OS.XmNseparatorType, separatorType,
+ };
+ handle = OS.XmCreateSeparator (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+ int alignment = OS.XmALIGNMENT_BEGINNING;
+ if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
+ if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
+ int [] argList = {
+ OS.XmNrecomputeSize, 0,
+ OS.XmNalignment, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreateLabel (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+int defaultBackground () {
+ return getDisplay ().labelBackground;
+}
+int defaultFont () {
+ return getDisplay ().labelFont;
+}
+int defaultForeground () {
+ return getDisplay ().labelForeground;
+}
+/**
+* Gets the alignment.
+* <p>
+* @return the alignment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getAlignment () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
+ int [] argList = {OS.XmNalignment, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int alignment = argList [1];
+ if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
+ if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
+ if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
+ return SWT.LEFT;
+}
+/**
+* Gets the widget image.
+* <p>
+* @return the widget image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getImage () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return image;
+}
+String getNameText () {
+ return getText ();
+}
+/**
+* Gets the widget text.
+* <p>
+* @return the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) != 0) return "";
+ int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int xmString = argList [1], mnemonic = argList [3];
+ if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
+ char [] result = null;
+ int [] parseTable = getDisplay ().parseTable;
+ int address = OS.XmStringUnparse (
+ xmString,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ parseTable,
+ parseTable.length,
+ OS.XmOUTPUT_ALL);
+ if (address != 0) {
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result = Converter.mbcsToWcs (null, buffer);
+ }
+ if (xmString != 0) OS.XmStringFree (xmString);
+ int count = 0;
+ if (mnemonic != 0) count++;
+ for (int i=0; i<result.length-1; i++)
+ if (result [i] == Mnemonic) count++;
+ char [] newResult = result;
+ if ((count != 0) || (mnemonic != 0)) {
+ newResult = new char [result.length + count];
+ int i = 0, j = 0;
+ while (i < result.length) {
+ if ((mnemonic != 0) && (result [i] == mnemonic)) {
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ mnemonic = 0;
+ }
+ if ((newResult [j++] = result [i++]) == Mnemonic)
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ }
+ }
+ return new String (newResult);
+}
+boolean getWrap () {
+ return false;
+}
+boolean mnemonicHit () {
+ Composite control = this.parent;
+ while (control != null) {
+ Control [] children = control._getChildren ();
+ int index = 0;
+ while (index < children.length) {
+ if (children [index] == this) break;
+ index++;
+ }
+ index++;
+ if (index < children.length) {
+ if (children [index].setFocus ()) return true;
+ }
+ control = control.parent;
+ }
+ return false;
+}
+boolean mnemonicMatch (char key) {
+ char mnemonic = findMnemonic (getText ());
+ if (mnemonic == '\0') return false;
+ return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
+}
+void propagateHandle (boolean enabled, int widgetHandle) {
+ super.propagateHandle (enabled, widgetHandle);
+ /*
+ * Labels never participate in focus traversal when
+ * either enabled or disabled.
+ */
+ if (enabled) {
+ int [] argList = {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+ }
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ int [] argList = {
+ OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
+ OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (bitmap != null) bitmap.dispose ();
+ if (disabled != null) disabled.dispose ();
+ image = bitmap = disabled = null;
+}
+int separatorType () {
+ if ((style & (SWT.SHADOW_IN)) != 0) return OS.XmSHADOW_ETCHED_IN;
+ if ((style & (SWT.SHADOW_OUT)) != 0) return OS.XmSHADOW_ETCHED_OUT;
+ return OS.XmSHADOW_ETCHED_IN;
+}
+/**
+* Sets the alignment.
+* <p>
+* @param aligment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setAlignment (int alignment) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
+ if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
+ if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmPIXMAP) setBitmap (image);
+}
+void setBitmap (Image image) {
+ int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
+ int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
+ if (bitmap != null) bitmap.dispose ();
+ if (disabled != null) disabled.dispose ();
+ bitmap = disabled = null;
+ if (image != null) {
+ Display display = getDisplay ();
+ switch (image.type) {
+ case SWT.BITMAP:
+ labelPixmap = image.pixmap;
+ disabled = new Image (display, image, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ case SWT.ICON:
+ Rectangle rect = image.getBounds ();
+ bitmap = new Image (display, rect.width, rect.height);
+ GC gc = new GC (bitmap);
+ gc.setBackground (getBackground ());
+ gc.fillRectangle (rect);
+ gc.drawImage (image, 0, 0);
+ gc.dispose ();
+ labelPixmap = bitmap.pixmap;
+ disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ default:
+ error (SWT.ERROR_NOT_IMPLEMENTED);
+ }
+ }
+ int [] argList = {
+ OS.XmNlabelType, OS.XmPIXMAP,
+ OS.XmNlabelPixmap, labelPixmap,
+ OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the widget image.
+* <p>
+* @param image the widget image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setBitmap (this.image = image);
+}
+/**
+* Set the widget text.
+*
+* PARAMETERS
+*
+* string - the new label for the widget
+*
+* REMARKS
+*
+* This method sets the widget label. The label may include
+* the mnemonic characters and line delimiters.
+*
+**/
+/**
+* Sets the widget text.
+* <p>
+* @param string the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int i=0, j=0, mnemonic=0;
+ while (i < text.length) {
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ while (j < text.length) text [j++] = 0;
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ int [] parseTable = getDisplay ().parseTable;
+ int xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ parseTable,
+ parseTable.length,
+ 0);
+ if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ int [] argList = {
+ OS.XmNlabelType, OS.XmSTRING,
+ OS.XmNlabelString, xmString,
+ OS.XmNmnemonic, mnemonic,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (xmString != 0) OS.XmStringFree (xmString);
+}
+void setWrap (boolean wrap) {
+ // NOT DONE
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java
new file mode 100755
index 0000000000..9d77400dc8
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java
@@ -0,0 +1,1584 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+
+/**
+* The list class represents a selectable user interface object
+* that display a list of items and issues notificiation when an
+* item is selected from the list. A list may be single or multi
+* select.
+* <p>
+* <b>Styles</b><br>
+* <dd>SINGLE, MULTI,<br>
+* <dd>H_SCROLL, V_SCROLL<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+* <dd>DoubleSelection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class List extends Scrollable {
+ int rows, columns;
+/**
+* Creates a new instance of the widget.
+*/
+public List (Composite parent, int style) {
+ /**
+ * Feature in Motif. It is not possible to create
+ * scrolled list that will never show the vertical
+ * scroll bar. Therefore, not matter what style
+ * bits are specified, set the V_SCROLL bits to
+ * match the widget Motif creates.
+ */
+ super (parent, checkStyle (style | SWT.V_SCROLL));
+}
+/**
+* Adds an item.
+* <p>
+* The item is placed at the end of the list.
+* Indexing is zero based.
+*
+* This operation can fail when the item cannot
+* be added in the OS.
+*
+* @param string the new item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the operation fails in the OS
+*/
+public void add (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.XmListAddItemUnselected (handle, xmString, 0);
+ OS.XmStringFree (xmString);
+}
+/**
+* Adds an item at an index.
+* <p>
+* The item is placed at an index in the list.
+* Indexing is zero based.
+*
+* This operation will fail when the index is
+* out of range or the item cannot be added in
+* the OS.
+*
+* @param string the new item
+* @param index the index for the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when the string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the item cannot be added
+*/
+public void add (String string, int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+ /*
+ * Feature in Motif. When an index is out of range,
+ * the list widget adds the item at the end. This
+ * behavior is not wrong but it is unwanted. The
+ * fix is to check the range before adding the item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index <= argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.XmListAddItemUnselected (handle, xmString, index + 1);
+ OS.XmStringFree (xmString);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ result.request_mode = OS.CWWidth;
+ OS.XtQueryGeometry (handle, null, result);
+ int width = result.width, height = 0;
+ if (wHint != SWT.DEFAULT) width = wHint;
+ if (hHint != SWT.DEFAULT) height = hHint;
+ if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) {
+ int count = rows;
+ if (count == 0) {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ count = argList [1];
+ }
+ if (hHint == SWT.DEFAULT) {
+ if (count == 0) {
+ height = DEFAULT_HEIGHT;
+ } else {
+ height = getItemHeight () * count;
+ }
+ }
+ if (wHint == SWT.DEFAULT && count == 0) {
+ width = DEFAULT_WIDTH;
+ }
+ }
+ Rectangle rect = computeTrim (0, 0, width, height);
+ return new Point (rect.width, rect.height);
+}
+/**
+* Computes the trim.
+*/
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Display display = getDisplay ();
+ int border = getBorderWidth ();
+ int trimX = x - border;
+ int trimY = y - border;
+ int trimWidth = width + (border * 2);
+ int trimHeight = height + (border * 2);
+ if (horizontalBar != null) {
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (horizontalBar.handle, argList, argList.length / 2);
+ /**
+ * Motif adds four pixels between the bottom of the
+ * list and the horizontal scroll bar. Add those now.
+ */
+ trimHeight += argList [1] + 4;
+ trimY -= display.scrolledInsetY;
+ if (verticalBar != null) {
+ trimX -= display.scrolledInsetX;
+ }
+ }
+ if (verticalBar != null) {
+ int [] argList = {OS.XmNwidth, 0};
+ OS.XtGetValues (verticalBar.handle, argList, argList.length / 2);
+ trimWidth += argList [1];
+ trimX -= display.scrolledInsetX;
+ if (horizontalBar != null) {
+ trimY -= display.scrolledInsetY;
+ }
+ }
+ int [] argList = {
+ OS.XmNhighlightThickness, 0, /* 1 */
+ OS.XmNshadowThickness, 0, /* 3 */
+ OS.XmNlistMarginWidth, 0, /* 5 */
+ OS.XmNlistMarginHeight, 0 /* 7 */
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int thickness = argList [1] + (argList [3] * 2);
+ trimWidth += thickness + argList [5] + 1;
+ trimHeight += thickness + argList [7] + 1;
+ trimX -= argList [1] + argList [3] + argList [5];
+ trimY -= argList [1] + argList [3] + argList [7];
+ return new Rectangle (trimX, trimY, trimWidth, trimHeight);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+
+ /*
+ * Feature in Motif. When items are added or removed
+ * from a list, it may request and be granted, a new
+ * preferred size. This behavior is unwanted. The fix
+ * is to create a parent for the list that will disallow
+ * geometry requests.
+ */
+ formHandle = OS.XmCreateForm (parent.handle, null, null, 0);
+ if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int selectionPolicy = OS.XmBROWSE_SELECT, listSizePolicy = OS.XmCONSTANT;
+ if ((style & SWT.MULTI) != 0) {
+ selectionPolicy = OS.XmEXTENDED_SELECT;
+ if ((style & SWT.SIMPLE) != 0) selectionPolicy = OS.XmMULTIPLE_SELECT;
+ }
+ if ((style & SWT.H_SCROLL) == 0) listSizePolicy = OS.XmVARIABLE;
+ int [] argList = {
+ OS.XmNlistSizePolicy, listSizePolicy,
+ OS.XmNselectionPolicy, selectionPolicy,
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ OS.XmNresizable, 0,
+// OS.XmNmatchBehavior, OS.XmNONE,
+ };
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
+ handle = OS.XmCreateList (formHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ } else {
+ handle = OS.XmCreateScrolledList (formHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ scrolledHandle = OS.XtParent (handle);
+ }
+}
+ScrollBar createScrollBar (int type) {
+ return createStandardBar (type);
+}
+int defaultBackground () {
+ return getDisplay ().listBackground;
+}
+int defaultFont () {
+ return getDisplay ().listFont;
+}
+int defaultForeground () {
+ return getDisplay ().listForeground;
+}
+/**
+* Deselects an item.
+* <p>
+* If the item at an index is selected, it is
+* deselected. If the item at an index is not
+* selected, it remains deselected. Indices
+* that are out of range are ignored. Indexing
+* is zero based.
+*
+* @param index the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselect (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Note: We rely on the fact that XmListDeselectPos ()
+ * fails silently when the indices are out of range.
+ */
+ if (index != -1) OS.XmListDeselectPos (handle, index + 1);
+}
+/**
+* Deselects a range of items.
+* <p>
+* If the item at an index is selected, it is
+* deselected. If the item at an index is not
+* selected, it remains deselected. Indices
+* that are out of range are ignored.
+*
+* Indexing is zero based. The range of items
+* is from the start index up to and including
+* the end index.
+
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselect (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (start > end) return;
+ /*
+ * Note: We rely on the fact that XmListDeselectPos ()
+ * fails silently when the indices are out of range.
+ */
+ for (int i=start; i<=end; i++) {
+ int index = i + 1;
+ if (index != 0) OS.XmListDeselectPos (handle, index);
+ }
+}
+/**
+* Deselects items.
+* <p>
+* If the item at an index is selected, it is
+* deselected. If the item at an index is not
+* selected, it remains deselected. Indices
+* that are out of range are ignored. Indexing
+* is zero based.
+*
+* @param indices the indices of the items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when the indices are null
+*/
+public void deselect (int [] indices) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ /*
+ * Note: We rely on the fact that XmListDeselectPos ()
+ * fails silently when the indices are out of range.
+ */
+ for (int i=0; i<indices.length; i++) {
+ int index = indices [i] + 1;
+ if (index != 0) OS.XmListDeselectPos (handle, index);
+ }
+}
+/**
+* Deselects all items.
+* <p>
+*
+* If an item is selected, it is deselected.
+* If an item is not selected, it remains unselected.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselectAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ OS.XmListDeselectAllItems (handle);
+}
+public int getFocusIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XmListGetKbdItemPos (handle) - 1;
+}
+/**
+* Gets an item at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be queried from
+* the OS.
+*
+* @param index the index of the item
+* @return the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+*/
+public String getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int ptr = argList [3] + (index * 4);
+ int [] buffer1 = new int [1];
+ OS.memmove (buffer1, ptr, 4);
+ ptr = buffer1 [0];
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+/**
+* Gets the number of items.
+* <p>
+* This operation will fail if the number of
+* items could not be queried from the OS.
+*
+* @return the number of items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_COUNT)
+* when the operation fails
+*/
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the height of one item.
+* <p>
+* This operation will fail if the height of
+* one item could not be queried from the OS.
+*
+* @return the height of one item in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM_HEIGHT)
+* when the operation fails
+*/
+public int getItemHeight () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {
+ OS.XmNlistSpacing, 0,
+ OS.XmNhighlightThickness, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int spacing = argList [1], highlight = argList [3];
+
+ /* Result is from empirical analysis on Linux and AIX */
+ return getFontHeight () + spacing + highlight + 1;
+}
+/**
+* Gets the items.
+* <p>
+* This operation will fail if the items cannot
+* be queried from the OS.
+*
+* @return the items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+*/
+public String [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int items = argList [1], itemCount = argList [3];
+ int [] buffer1 = new int [1];
+ String [] result = new String [itemCount];
+ for (int i=0; i<itemCount; i++) {
+ OS.memmove (buffer1, items, 4);
+ int ptr = buffer1 [0];
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result[i] = new String (Converter.mbcsToWcs (null, buffer));
+ items += 4;
+ }
+ return result;
+}
+/**
+* Gets the selected items.
+* <p>
+* This operation will fail if the selected
+* items cannot be queried from the OS.
+*
+* @return the selected items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+* @exception SWTError(ERROR_CANNOT_GET_SELECTION)
+* when the operation fails
+*/
+public String [] getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int items = argList [1], itemCount = argList [3];
+ int [] buffer1 = new int [1];
+ String [] result = new String [itemCount];
+ for (int i=0; i<itemCount; i++) {
+ OS.memmove (buffer1, items, 4);
+ int ptr = buffer1 [0];
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result[i] = new String (Converter.mbcsToWcs (null, buffer));
+ items += 4;
+ }
+ return result;
+}
+/**
+* Gets the number of selected items.
+* <p>
+* This operation will fail if the number of selected
+* items cannot be queried from the OS.
+*
+* @return the number of selected items in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_COUNT)
+* when the operation fails
+*/
+public int getSelectionCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNselectedItemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the index of the selected item.
+* <p>
+* Indexing is zero based.
+*
+* When the list is single-select, the index of
+* the selected item is returned or -1 if no item
+* is selected.
+*
+* When the list is multi-select, the index of
+* a selected item that contains the focus
+* rectangle or the index of the first selected
+* item is return. If no item is selected, -1
+* is returned.
+*
+* This operation will fail if the selected
+* index cannot be queried from the OS.
+*
+* @return the index of the selected item.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_SELECTION)
+* when the operation fails
+*/
+public int getSelectionIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = OS.XmListGetKbdItemPos (handle);
+ if (OS.XmListPosSelected (handle, index)) return index - 1;
+ int [] count = new int [1], positions = new int [1];
+ if (!OS.XmListGetSelectedPos (handle, positions, count)) return -1;
+ if (count [0] == 0) return -1;
+ int address = positions [0];
+ int [] indices = new int [1];
+ OS.memmove (indices, address, 4);
+ OS.XtFree (address);
+ return indices [0] - 1;
+}
+/**
+* Gets the indices of the selected items.
+* <p>
+* Indexing is zero based.
+*
+* If no item is selected, an array is returned.
+*
+* This operation will fail if the selected
+* indices cannot be queried from the OS.
+*
+* @return the indices of the selected items.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_SELECTION)
+* when the operation fails
+*/
+public int [] getSelectionIndices () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] count = new int [1], positions = new int [1];
+ OS.XmListGetSelectedPos (handle, positions, count);
+ int [] result = new int [count [0]];
+ OS.memmove (result, positions [0], count [0] * 4);
+ if (positions [0] != 0) OS.XtFree (positions [0]);
+ for (int i=0; i<result.length; i++) --result [i];
+ return result;
+}
+/**
+* Gets the top index.
+* <p>
+* The top index is the index of the item that
+* is currently at the top of the widget. The
+* top index changes when the widget is scrolled.
+* Indexing is zero based.
+*
+* @return the index of the top item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTopIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNtopItemPosition, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] - 1;
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, SWT.DefaultSelection);
+}
+/**
+* Gets the index of an item.
+* <p>
+* The list is searched starting at 0 until an
+* item is found that is equal to the search item.
+* If no item is found, -1 is returned. Indexing
+* is zero based.
+*
+* @param string the search item
+* @return the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) return -1;
+ int index = OS.XmListItemPos (handle, xmString);
+ OS.XmStringFree (xmString);
+ return index - 1;
+}
+/**
+* Gets the index of an item.
+* <p>
+* The list is searched starting at and including
+* the start position until an item is found that
+* is equal to the search itenm. If no item is
+* found, -1 is returned. Indexing is zero based.
+*
+* @param string the search item
+* @param index the starting position
+* @return the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string, int start) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int items = argList [1], itemCount = argList [3];
+ if (!((0 <= start) && (start < itemCount))) return -1;
+ byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer1);
+ if (xmString == 0) return -1;
+ int index = start;
+ items += start * 4;
+ int [] buffer2 = new int [1];
+ while (index < itemCount) {
+ OS.memmove (buffer2, items, 4);
+ if (OS.XmStringCompare (buffer2 [0], xmString)) break;
+ items += 4; index++;
+ }
+ OS.XmStringFree (xmString);
+ if (index == itemCount) return -1;
+ return index;
+}
+/**
+* Determines if an item is selected.
+* <p>
+* Indexing is zero based.
+*
+* @param index the index of the item
+* @return the selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isSelected (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) return false;
+ return OS.XmListPosSelected (handle, index + 1);
+}
+/**
+* Removes an item at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param index the index of the item
+* @return the selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+ /*
+ * Feature in Motif. An index out of range handled
+ * correctly by the list widget but causes an unwanted
+ * Xm Warning. The fix is to check the range before
+ * deleting an item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ OS.XmListDeletePos (handle, index + 1);
+}
+/**
+* Removes a range of items.
+* <p>
+* Indexing is zero based. The range of items
+* is from the start index up to and including
+* the end index.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (start > end) return;
+ int count = end - start + 1;
+ /*
+ * Feature in Motif. An index out of range handled
+ * correctly by the list widget but causes an unwanted
+ * Xm Warning. The fix is to check the range before
+ * deleting an item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= start && start < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ OS.XmListDeleteItemsPos (handle, count, start + 1);
+ if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
+}
+/**
+* Removes an item.
+* <p>
+* This operation will fail when the item
+* could not be removed from the OS.
+*
+* @param string the search item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ int index = OS.XmListItemPos (handle, xmString);
+ OS.XmStringFree (xmString);
+ if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
+ OS.XmListDeletePos (handle, index);
+}
+/**
+* Removes items.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param indices the indices of the items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when the indices are null
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int [] indices) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ /*
+ * Feature in Motif. An index out of range handled
+ * correctly by the list widget but causes an unwanted
+ * Xm Warning. The fix is to check the range before
+ * deleting an item.
+ */
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int length = 0, count = argList [1];
+ int [] newIndices = new int [indices.length];
+ for (int i=0; i<indices.length; i++) {
+ int index = indices [i];
+ if (!(0 <= index && index < count)) break;
+ newIndices [length++] = index + 1;
+ }
+ OS.XmListDeletePositions (handle, newIndices, length);
+ if (length < indices.length) error (SWT.ERROR_INVALID_RANGE);
+}
+/**
+* Removes all items.
+* <p>
+* This operation will fail when an item
+* could not be removed in the OS.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void removeAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ OS.XmListDeselectAllItems (handle);
+ OS.XmListDeleteAllItems (handle);
+ /*
+ * Bug in AIX. When all list items are deleted
+ * from a scrolled list that is currently showing a
+ * horizontal scroll bar, the horizontal scroll bar
+ * is hidden, but the list does not grow to take up
+ * the space once occupied by the bar. The fix is
+ * of force a resize of the list.
+ */
+ if ((style & SWT.H_SCROLL) != 0) OS.XtResizeWindow (handle);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Selects an item.
+* <p>
+* If the item at an index is not selected, it is
+* selected. If the item at an index is selected,
+* it remains selected. Indices that are out of
+* range are ignored. Indexing is zero based.
+*
+* @param index the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void select (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (index == -1) return;
+ if (OS.XmListPosSelected (handle, index + 1)) return;
+ /*
+ * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
+ * in a XmEXTENDED_SELECT list widget will add the index to the selected
+ * indices. The observed behavior does not match the spec. The fix is
+ * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
+ * and then switch it back because XmListSelectPost () works as specified
+ * for XmMULTIPLE_SELECT list widgets.
+ */
+ int [] argList = {OS.XmNselectionPolicy, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int oldPolicy = argList [1];
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmMULTIPLE_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ /*
+ * Note: We rely on the fact that XmListSelectPos ()
+ * fails silently when the indices are out of range.
+ */
+ OS.XmListSelectPos (handle, index + 1, false);
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmEXTENDED_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+* Selects a range of items.
+* <p>
+* If the item at an index is not selected, it is
+* selected. If the item at an index is selected,
+* it remains selected. Indices that are out of
+* range are ignored.
+*
+* Indexing is zero based. The range of items
+* is from the start index up to and including
+* the end index.
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void select (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (start > end) return;
+ if ((style & SWT.SINGLE) != 0) {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int index = Math.min (argList[1] - 1, end) + 1;
+ if (index != 0 && index >= start) OS.XmListSelectPos (handle, index, false);
+ return;
+ }
+ /*
+ * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
+ * in a XmEXTENDED_SELECT list widget will add the index to the selected
+ * indices. The observed behavior does not match the spec. The fix is
+ * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
+ * and then switch it back because XmListSelectPos () works as specified
+ * for XmMULTIPLE_SELECT list widgets.
+ */
+ int [] argList = {OS.XmNselectionPolicy, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int oldPolicy = argList [1];
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmMULTIPLE_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ /*
+ * Note: We rely on the fact that XmListSelectPos ()
+ * fails silently when the indices are out of range.
+ */
+ for (int i=start; i<=end; i++) {
+ int index = i + 1;
+ if ((index != 0) && !OS.XmListPosSelected (handle, index)) {
+ OS.XmListSelectPos (handle, index, false);
+ }
+ }
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmEXTENDED_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+* Selects items.
+* <p>
+* If the item at an index is not selected, it is
+* selected. If the item at an index is selected,
+* it remains selected. Indices that are out of
+* range are ignored. Indexing is zero based.
+*
+* @param indices the indices of the items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when the indices are null
+*/
+public void select (int [] indices) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SINGLE) != 0) {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int count = argList [1];
+ for (int i = 0; i < indices.length; i++) {
+ int index = indices [i];
+ if (0 <= index && index < count) {
+ select (index);
+ return;
+ }
+ }
+ return;
+ }
+ /*
+ * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
+ * in a XmEXTENDED_SELECT list widget will add the index to the selected
+ * indices. The observed behavior does not match the spec. The fix is
+ * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
+ * and then switch it back because XmListSelectPos () works as specified
+ * for XmMULTIPLE_SELECT list widgets.
+ */
+ int [] argList = {OS.XmNselectionPolicy, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int oldPolicy = argList [1];
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmMULTIPLE_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ /*
+ * Note: We rely on the fact that XmListSelectPos ()
+ * fails silently when the indices are out of range.
+ */
+ for (int i=0; i<indices.length; i++) {
+ int index = indices [i] + 1;
+ if ((index != 0) && !OS.XmListPosSelected (handle, index)) {
+ OS.XmListSelectPos (handle, index, false);
+ }
+ }
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmEXTENDED_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+void select (String [] items) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] table = new int [items.length];
+ for (int i=0; i<items.length; i++) {
+ String string = items [i];
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ table [i] = xmString;
+ }
+ int ptr = OS.XtMalloc (items.length * 4);
+ OS.memmove (ptr, table, items.length * 4);
+ int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, table.length};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ for (int i=0; i<table.length; i++) OS.XmStringFree (table [i]);
+ OS.XtFree (ptr);
+ OS.XmListUpdateSelectedList (handle);
+}
+/**
+* Selects all items.
+* <p>
+* If an item is not selected, it is selected.
+* If an item is selected, it remains selected.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void selectAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SINGLE) != 0) return;
+ /*
+ * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
+ * in a XmEXTENDED_SELECT list widget will add the index to the selected
+ * indices. The observed behavior does not match the spec. The fix is
+ * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
+ * and then switch it back because XmListSelectPos () works as specified
+ * for XmMULTIPLE_SELECT list widgets.
+ */
+ int [] argList = {OS.XmNselectionPolicy, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int oldPolicy = argList [1];
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmMULTIPLE_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ for (int i=0; i<argList[3]; i++) {
+ int index = i + 1;
+ if (!OS.XmListPosSelected (handle, index)) {
+ OS.XmListSelectPos (handle, index, false);
+ }
+ }
+ if (oldPolicy == OS.XmEXTENDED_SELECT) {
+ argList [1] = OS.XmEXTENDED_SELECT;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+* Sets the bounds.
+*/
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ /*
+ * Bug in AIX. When the receiver has a vertical scroll bar
+ * that is currently not visible and no horizontal scroll bar
+ * and is resized to be smaller in both the width and height
+ * and goes from the state where the width of the longest item
+ * is smaller than the width of the list to the state where the
+ * width of the longest item is longer than the width of the
+ * list, the list hides the vertical scroll bar and leaves a
+ * blank space where it should be. This often happens when a
+ * shell containing a list that matches the above criteria is
+ * maximized and then restored. This is just one of a number
+ * of repeatable cases where the scrolled window hides the
+ * scroll bars but does not resize the list. The fix is to
+ * detect these cases and force the scroll bars to be layed
+ * out properly by growing and then shrinking the scrolled
+ * window.
+ */
+// fixHScroll := hScroll ~~ nil and: [
+// hScroll isVisible not and: [
+// height ~~ (self dimensionAt: XmNheight)]].
+// fixVScroll := vScroll ~~ nil and: [
+// vScroll isVisible not and: [
+// width ~~ (self dimensionAt: XmNwidth)]].
+// (fixHScroll or: [fixVScroll]) ifFalse: [^self].
+
+ /* Grow and shrink the scrolled window by one pixel */
+ if (scrolledHandle == 0) return;
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
+ OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
+}
+void setFocusIndex (int index) {
+ OS.XmListSetKbdItemPos (handle, index + 1);
+}
+/**
+* Sets the text of an item.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be changed in
+* the OS.
+*
+* @param index the index for the item
+* @param string the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when items is null
+* @exception SWTError(ERROR_ITEM_NOT_MODIFIED)
+* when the operation fails
+*/
+public void setItem (int index, String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (index == -1) error (SWT.ERROR_INVALID_RANGE);
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (!(0 <= index && index < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ boolean isSelected = OS.XmListPosSelected (handle, index + 1);
+ OS.XmListReplaceItemsPosUnselected (handle, new int [] {xmString}, 1, index + 1);
+ if (isSelected) OS.XmListSelectPos (handle, index + 1, false);
+ OS.XmStringFree (xmString);
+}
+/**
+* Sets all items.
+* <p>
+* The previous selection is cleared.
+* The previous items are deleted.
+* The new items are added.
+* The top index is set to 0.
+*
+* @param items the array of items
+*
+* This operation will fail when an item is null
+* or could not be added in the OS.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when items is null
+*/
+public void setItems (String [] items) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ /*
+ * Bug in AIX. When all list items are replaced
+ * in a scrolled list that is currently showing a
+ * horizontal scroll bar, the horizontal scroll bar
+ * is hidden, but the list does not grow to take up
+ * the space once occupied by the bar. The fix is
+ * of force the horizontal bar to be recomputed by
+ * removing all items and resizing the list.
+ */
+ OS.XmListSetPos (handle, 0);
+ OS.XmListDeselectAllItems (handle);
+ if ((style & SWT.H_SCROLL) != 0) {
+ OS.XmListDeleteAllItems (handle);
+ }
+ int index = 0;
+ int [] table = new int [items.length];
+ while (index < items.length) {
+ String string = items [index];
+ if (string == null) break;
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString == 0) break;
+ table [index++] = xmString;
+ }
+ int ptr = OS.XtMalloc (index * 4);
+ OS.memmove (ptr, table, index * 4);
+ int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
+ OS.XtFree (ptr);
+ /*
+ * Bug in Motif. Resize the list to work around
+ * the horizontal scroll bar display bug described
+ * above.
+ */
+ if ((style & SWT.H_SCROLL) != 0) {
+ OS.XtResizeWindow (handle);
+ }
+ if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
+}
+/**
+* Sets the selection.
+* <p>
+* The previous selection is cleared
+* before new items are selected.
+*
+* @see List#deselectAll()
+* @see List#select(int)
+*
+* @param index the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int index) {
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (index);
+}
+/**
+* Sets the selection.
+* <p>
+* The previous selection is cleared
+* before new items are selected.
+*
+* @see List#deselectAll()
+* @see List#select(int, int)
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int start, int end) {
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (start, end);
+}
+/**
+* Sets the selection.
+* <p>
+* The previous selection is cleared
+* before new items are selected.
+*
+* @see List#deselectAll()
+* @see List#select(int [])
+*
+* @param indices the indices of the items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection(int[] indices) {
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (indices);
+}
+/**
+* Sets the selection.
+* <p>
+* The previous selection is cleared
+* before new items are selected.
+*
+* @see List#deselectAll()
+* @see List#select(int [])
+*
+* @param items the array of items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when items is null
+*/
+public void setSelection (String [] items) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SINGLE) != 0) {
+ for (int i=items.length-1; i>=0; --i) {
+ String string = items [i];
+ if (string != null) {
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString != 0) {
+ int index = OS.XmListItemPos (handle, xmString);
+ if (index != 0) OS.XmListSelectPos (handle, index, false);
+ OS.XmStringFree (xmString);
+ if ((index != 0) && OS.XmListPosSelected (handle, index)) return;
+ }
+ }
+ }
+ OS.XmListDeselectAllItems (handle);
+ return;
+ }
+ OS.XmListDeselectAllItems (handle);
+ int length = 0;
+ int [] table = new int [items.length];
+ for (int i=0; i<items.length; i++) {
+ String string = items [i];
+ if (string != null) {
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmString = OS.XmStringCreateLocalized (buffer);
+ if (xmString != 0) table [length++] = xmString;
+ }
+ }
+ int ptr = OS.XtMalloc (length * 4);
+ OS.memmove (ptr, table, length * 4);
+ int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, length};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ for (int i=0; i<length; i++) OS.XmStringFree (table [i]);
+ OS.XtFree (ptr);
+ OS.XmListUpdateSelectedList (handle);
+}
+/**
+* Sets the size.
+*/
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ /*
+ * Bug in AIX. When the receiver has a vertical scroll bar
+ * that is currently not visible and no horizontal scroll bar
+ * and is resized to be smaller in both the width and height
+ * and goes from the state where the width of the longest item
+ * is smaller than the width of the list to the state where the
+ * width of the longest item is longer than the width of the
+ * list, the list hides the vertical scroll bar and leaves a
+ * blank space where it should be. This often happens when a
+ * shell containing a list that matches the above criteria is
+ * maximized and then restored. This is just one of a number
+ * of repeatable cases where the scrolled window hides the
+ * scroll bars but does not resize the list. The fix is to
+ * detect these cases and force the scroll bars to be layed
+ * out properly by growing and then shrinking the scrolled
+ * window.
+ */
+// fixHScroll := hScroll ~~ nil and: [
+// hScroll isVisible not and: [
+// height ~~ (self dimensionAt: XmNheight)]].
+// fixVScroll := vScroll ~~ nil and: [
+// vScroll isVisible not and: [
+// width ~~ (self dimensionAt: XmNwidth)]].
+// (fixHScroll or: [fixVScroll]) ifFalse: [^self].
+
+ /* Grow and shrink the scrolled window by one pixel */
+ if (scrolledHandle == 0) return;
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
+ OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
+}
+/**
+* Sets the top index.
+* <p>
+* The top index is the index of the item that
+* is currently at the top of the widget. The
+* top index changes when the widget is scrolled.
+* Indexing starts from zero.
+*
+* @param index the new top index
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setTopIndex (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNitemCount, 0, OS.XmNvisibleItemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int newIndex = Math.max (1, Math.min (index + 1, argList [1]));
+ int lastIndex = Math.max (1, argList [1] - argList [3] + 1);
+ if (newIndex > lastIndex) newIndex = lastIndex;
+ OS.XmListSetPos (handle, newIndex);
+}
+/**
+* Shows the selection.
+* <p>
+* If there is no selection or the selection
+* is already visible, this method does nothing.
+* If the selection is scrolled out of view,
+* the top index of the widget is changed such
+* that selection becomes visible.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void showSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] buffer = new int [1], positions = new int [1];
+ if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return;
+ if (buffer [0] == 0) return;
+ int address = positions [0];
+ int [] indices = new int [1];
+ OS.memmove (indices, address, 4);
+ OS.XtFree (address);
+ int index = indices [0];
+ int [] argList = {
+ OS.XmNtopItemPosition, 0,
+ OS.XmNvisibleItemCount, 0,
+ OS.XmNitemCount, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int topIndex = argList [1], visibleCount = argList [3], count = argList [5];
+ int bottomIndex = Math.min (topIndex + visibleCount - 1, count);
+ if ((topIndex <= index) && (index <= bottomIndex)) return;
+ int lastIndex = Math.max (1, count - visibleCount + 1);
+ int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex);
+ OS.XmListSetPos (handle, newTop);
+}
+int topHandle () {
+ /*
+ * Normally, when a composite has both a form handle
+ * and a scrolled handle, the scrolled handle is the
+ * parent of the form handle. In the case of a list,
+ * both handles are present but the form handle is
+ * parent of the scrolled handle and therefore is
+ * the top handle of the list.
+ */
+ return formHandle;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java
new file mode 100755
index 0000000000..31a4ce5f15
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java
@@ -0,0 +1,648 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A menu is a user interface object contains selectable
+* menu items.
+* <p>
+* <b>Styles</b><br>
+* <dd>BAR, DROP_DOWN, POP_UP<br>
+*/
+
+/* Class Definition */
+public /*final*/ class Menu extends Widget {
+ boolean hasLocation;
+ MenuItem cascade, defaultItem;
+ Decorations parent;
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Control parent) {
+ this (checkNull(parent).getShell (), SWT.POP_UP);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Decorations parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ createWidget (0);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Menu parentMenu) {
+ this (checkNull(parentMenu).parent, SWT.DROP_DOWN);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (MenuItem parentItem) {
+ this (checkNull(parentItem).parent);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Help, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addMenuListener(MenuListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.Hide,typedListener);
+ addListener(SWT.Show,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
+}
+static Control checkNull (Control control) {
+ if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return control;
+}
+static Menu checkNull (Menu menu) {
+ if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return menu;
+}
+static MenuItem checkNull (MenuItem item) {
+ if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return item;
+}
+void createHandle (int index) {
+ state |= HANDLE;
+
+ /*
+ * Bug in Motif. For some reason, creating a menu after any application context
+ * and shell have been destroyed will segment fault unless a new application
+ * context and shell have been created in the current thread. The fix is to
+ * detect this case and create and destroy a temporary application context and
+ * shell.
+ */
+ int xDisplay = 0, shellHandle = 0;
+ if (Display.DisplayDisposed) {
+ int [] argc = new int [] {0};
+ int xtContext = OS.XtCreateApplicationContext ();
+ xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0);
+ shellHandle = OS.XtAppCreateShell (null, null, OS.TopLevelShellWidgetClass (), xDisplay, null, 0);
+ }
+
+ /* BAR menu */
+ if ((style & SWT.BAR) != 0) {
+ int parentHandle = parent.scrolledHandle;
+ handle = OS.XmCreateMenuBar (parentHandle, null, null, 0);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+
+ /* POPUP and PULLDOWN menus */
+
+ /*
+ * Bug in Motif. When an existing popup menu is destroyed just
+ * before creating a new popup menu and the new menu is managed,
+ * the cursor changes to the menu cursor but the new menu is not
+ * displayed. Also, Motif fails to show a popup menu when the
+ * mouse is released. Both problems stem from the fact that the
+ * popup menu is in the widget tree of a visible shell. The fix
+ * is to create all popup menus as children of a hidden dialog
+ * shell. Menus created this way are automatically destroyed
+ * when the shell is destroyed.
+ */
+ if ((style & SWT.POP_UP) != 0) {
+ int parentHandle = parent.dialogHandle ();
+ handle = OS.XmCreatePopupMenu (parentHandle, new byte [1], null, 0);
+ } else {
+ /*
+ * Bug in Linux. For some reason, when the parent of the pulldown
+ * menu is not the main window handle, XtDestroyWidget() occasionally
+ * segment faults when the shell is destroyed. The fix is to ensure
+ * that the parent is the main window.
+ */
+ int parentHandle = parent.scrolledHandle;
+ handle = OS.XmCreatePulldownMenu (parentHandle, new byte [1], null, 0);
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+
+ /* Workaround for bug in Motif */
+ if (Display.DisplayDisposed) {
+ if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
+ if (xDisplay != 0) {
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ OS.XtDestroyApplicationContext (xtContext);
+ }
+ }
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ parent.add (this);
+}
+/**
+* Gets the default item.
+* <p>
+*
+* @return the default menu item.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public MenuItem getDefaultItem () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return defaultItem;
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+* Gets the enabled state.
+* <p>
+* @return the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets an item at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be queried from
+* the OS.
+*
+* @param index the index of the item
+* @return the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_ITEM)
+* when the operation fails
+*/
+public MenuItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ int [] handles = new int [argList [3]];
+ OS.memmove (handles, argList [1], argList[3] * 4);
+ int i = 0, count = 0;
+ while (i < argList [3]) {
+ if (OS.XtIsManaged (handles [i])) {
+ if (index == count) break;
+ count++;
+ }
+ i++;
+ }
+ if (index != count) error (SWT.ERROR_INVALID_RANGE);
+ Widget widget = WidgetTable.get (handles [i]);
+ if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM);
+ return (MenuItem) widget;
+}
+/**
+* Gets the number of items.
+* <p>
+* @return the number of items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == 0 || argList [3] == 0) return 0;
+ int [] handles = new int [argList [3]];
+ OS.memmove (handles, argList [1], argList [3] * 4);
+ int count = 0;
+ for (int i=0; i<argList [3]; i++) {
+ if (OS.XtIsManaged (handles [i])) count++;
+ }
+ return count;
+}
+/**
+* Gets the items.
+* <p>
+* @return items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public MenuItem [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return new MenuItem [0];
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ MenuItem [] items = new MenuItem [count];
+ int i = 0, j = 0;
+ while (i < count) {
+ Widget item = WidgetTable.get (handles [i]);
+ if (item != null) items [j++] = (MenuItem) item;
+ i++;
+ }
+ if (i == j) return items;
+ MenuItem [] newItems = new MenuItem [j];
+ System.arraycopy (items, 0, newItems, 0, j);
+ return newItems;
+}
+String getNameText () {
+ String result = "";
+ MenuItem [] items = getItems ();
+ int length = items.length;
+ if (length > 0) {
+ for (int i=0; i<length-1; i++) {
+ result = result + items [i].getNameText() + ", ";
+ }
+ result = result + items [length-1].getNameText ();
+ }
+ return result;
+}
+/**
+* Gets the parent.
+* <p>
+* @return the parent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Decorations getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the parent item.
+* <p>
+* @return the parent item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public MenuItem getParentItem () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return cascade;
+}
+/**
+* Gets the parent menu.
+* <p>
+* @return the parent menu
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Menu getParentMenu () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (cascade != null) return cascade.parent;
+ return null;
+}
+/**
+* Gets the shell.
+* <p>
+* @return the shell
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Shell getShell () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getShell ();
+}
+/**
+* Gets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @return visible the visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XtIsManaged (handle);
+}
+void hookEvents () {
+ int windowProc = parent.getShell ().getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, SWT.Help);
+ OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, SWT.Show);
+ OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, SWT.Hide);
+}
+/**
+* Gets the index of an item.
+* <p>
+* The list is searched starting at 0 until an
+* item is found that is equal to the search item.
+* If no item is found, -1 is returned. Indexing
+* is zero based.
+*
+* @param item the search item
+* @return the index of the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (MenuItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int [] handles = new int [argList [3]];
+ OS.memmove (handles, argList [1], handles.length * 4);
+ int index = 0;
+ for (int i=0; i<handles.length; i++) {
+ if (OS.XtIsManaged (handles [i])) {
+ if (handles [i] == item.handle) return index;
+ index++;
+ }
+ }
+ return -1;
+}
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Menu parentMenu = getParentMenu ();
+ if (parentMenu == null) return getEnabled ();
+ return getEnabled () && parentMenu.isEnabled ();
+}
+/**
+* Gets the visibility status.
+* <p>
+* This method returns the visibility status of the
+* widget in the widget hierarchy. If the parent is not
+* visible or some other condition makes the widget not
+* visible, this method will return false.
+*
+* @return the actual visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getVisible ();
+}
+int processHelp (int callData) {
+ sendHelpEvent (callData);
+ return 0;
+}
+int processHide (int callData) {
+ sendEvent (SWT.Hide);
+ return 0;
+}
+int processShow (int callData) {
+ /*
+ * SWT.Selection events are posted to allow stepping
+ * in the VA/Java debugger. SWT.Show events are
+ * sent to ensure that application event handler
+ * code runs before the menu is displayed. This
+ * means that SWT.Show events would normally occur
+ * before SWT.Selection events. While this is not
+ * strictly incorrect, applications often use the
+ * SWT.Selection event to update the state of menu
+ * items and would like the ordering of events to
+ * be the other way around.
+ *
+ * The fix is to run the deferred events before
+ * the menu is shown. This means that stepping
+ * through a selection event that was caused by
+ * a popup menu will fail in VA/Java.
+ */
+ Display display = getDisplay ();
+ display.runDeferredEvents ();
+ sendEvent (SWT.Show);
+ return 0;
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.setMenu (null);
+ if (((style & SWT.BAR) != 0) && (this == parent.menuBar)) parent.setMenuBar (null);
+}
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) {
+ item.releaseWidget ();
+ item.releaseHandle ();
+ }
+ }
+ super.releaseWidget ();
+ if (parent != null) parent.remove (this);
+ parent = null;
+ cascade = defaultItem = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Help, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeMenuListener(MenuListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Hide, listener);
+ eventTable.unhook(SWT.Show, listener);
+}
+void sendHelpEvent (int callData) {
+ if (hooks (SWT.Help)) {
+ postEvent (SWT.Help);
+ return;
+ }
+ parent.sendHelpEvent (callData);
+}
+/**
+* Sets the default item.
+* <p>
+* @param item the default menu item (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setDefaultItem (MenuItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ defaultItem = item;
+}
+/**
+* Sets the enabled state.
+* <p>
+* @param enabled the new value of the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
+ int [] argList = {OS.XmNx, x, OS.XmNy, y};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ hasLocation = true;
+}
+/**
+* Sets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @param visible the new visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
+ if (visible) {
+ if (!hasLocation) {
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XDefaultRootWindow (xDisplay);
+ if (xWindow == 0) return;
+ int [] unused = new int [1];
+ int [] rootX = new int [1], rootY = new int [1];
+ if (OS.XQueryPointer (
+ xDisplay, xWindow, unused, unused,
+ rootX, rootY,
+ unused, unused, unused) == 0) return;
+ int [] argList = {OS.XmNx, rootX [0], OS.XmNy, rootY [0]};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ OS.XtManageChild (handle);
+ } else {
+ OS.XtUnmanageChild (handle);
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
new file mode 100755
index 0000000000..23ff61753d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
@@ -0,0 +1,705 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A menu item is a selectable user interface object
+* that issues notificiation when pressed and released.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>CASCADE, CHECK, PUSH, RADIO, SEPARATOR<br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class MenuItem extends Item {
+ int accelerator;
+ Menu parent, menu;
+/**
+* Creates a new instance of the widget.
+*/
+public MenuItem (Menu parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ createWidget (OS.XmLAST_POSITION);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public MenuItem (Menu parent, int style, int index) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ if (index == OS.XmLAST_POSITION) error (SWT.ERROR_INVALID_RANGE);
+ createWidget (index);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addArmListener (ArmListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Arm, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Help, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int parentHandle = parent.handle;
+ int [] argList1 = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (parentHandle, argList1, argList1.length / 2);
+ if (index != OS.XmLAST_POSITION && argList1 [1] != 0) {
+ int [] handles = new int [argList1 [3]];
+ OS.memmove (handles, argList1 [1], argList1 [3] * 4);
+ int i = 0, count = 0;
+ while (i < argList1 [3]) {
+ if (OS.XtIsManaged (handles [i])) {
+ if (index == count) break;
+ count++;
+ }
+ i++;
+ }
+ if (index != count) error (SWT.ERROR_INVALID_RANGE);
+ index = i;
+ }
+ if ((style & SWT.SEPARATOR) != 0) {
+ int [] argList = {
+ OS.XmNorientation, (parent.style & SWT.BAR) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL,
+ OS.XmNpositionIndex, index,
+ };
+ handle = OS.XmCreateSeparatorGadget (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+ int [] argList = {OS.XmNpositionIndex, index};
+ if ((style & SWT.PUSH) != 0) {
+ handle = OS.XmCreatePushButtonGadget (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ handle = OS.XmCreateToggleButtonGadget (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+ handle = OS.XmCreateCascadeButtonGadget (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+void destroyWidget () {
+ /*
+ * Feature in Motif. When a popup menu item
+ * is destroyed, the menu does not recompute
+ * the menu size until the next time the menu
+ * is managed. This means that the user can
+ * watch the menu get updated as new items are
+ * added and old ones deleted. The fix is to
+ * unmanaged the item before destroying it to
+ * force the menu to recompute the menu size.
+ */
+ OS.XtUnmanageChild (handle);
+ super.destroyWidget ();
+}
+/**
+* Gets the accelerator.
+* <p>
+* This method gets the widget accelerator. An accelerator
+* is the bit-wise OR of zero or more modifier masks and a key.
+* Examples: SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2.
+*
+* @param accelerator the accelerator
+*
+* @return the accelerator
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getAccelerator () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return accelerator;
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+* Gets the enabled state.
+* <p>
+* A disabled widget is typically not selectable from
+* the user interface and draws with an inactive or
+* grayed look.
+*
+* @return a boolean that is the enabled state of the widget.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the menu.
+* <p>
+* For a cascade menu item, the menu is a pulldown menu
+* that is displayed when the user selects the cascade item.
+* For a window, the menu is always a popup menu, that is
+* displayed when the user requests a popup menu for the
+* window. The sequence of key strokes or button presses
+* that requests a menu is platform specific.
+*
+* @return the menu
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Menu getMenu () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return menu;
+}
+String getNameText () {
+ if ((style & SWT.SEPARATOR) != 0) return "|";
+ return super.getNameText ();
+}
+/**
+* Gets the parent.
+* <p>
+* @return the parent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Menu getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the selection state.
+* <p>
+* This method gets the widget selection state for a
+* widgets with the style CHECK or RADIO. It
+* returns false for widgets that do not have one of
+* these styles.
+* true or false - for CHECK or RADIO.
+* false - for all other widget styles
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
+ int [] argList = {OS.XmNset, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Get the button text.
+*
+* RETURNS
+*
+* A String that is the label of the button.
+*
+* REMARKS
+*
+* This method returns the button label. The label may
+* include the mnemonic character but must not contain line
+* delimiters.
+*
+**/
+String getText2 () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.ARROW) != 0) return "";
+ int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0, OS.XmNacceleratorText, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int xmString1 = argList [1], mnemonic = argList [3], xmString2 = argList [5];
+ if (xmString1 == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
+ char [] result = null;
+ int address = OS.XmStringUnparse (
+ xmString1,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address != 0) {
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result = Converter.mbcsToWcs (null, buffer);
+ }
+ String accelText = "";
+ if (xmString1 != 0) OS.XmStringFree (xmString1);
+ if (xmString2 != 0) {
+ address = OS.XmStringUnparse (
+ xmString2,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address != 0) {
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ accelText = '\t' + new String (Converter.mbcsToWcs (null, buffer));
+ }
+ }
+ if (xmString2 != 0) OS.XmStringFree (xmString2);
+ if (result == null) return accelText;
+ int count = 0;
+ if (mnemonic != 0) count++;
+ for (int i=0; i<result.length-1; i++)
+ if (result [i] == Mnemonic) count++;
+ char [] newResult = result;
+ if ((count != 0) || (mnemonic != 0)) {
+ newResult = new char [result.length + count];
+ int i = 0, j = 0;
+ while (i < result.length) {
+ if ((mnemonic != 0) && (result [i] == mnemonic)) {
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ mnemonic = 0;
+ }
+ if ((newResult [j++] = result [i++]) == Mnemonic)
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ }
+ }
+ return new String (newResult) + accelText;
+}
+void hookEvents () {
+ if ((style & SWT.SEPARATOR) != 0) return;
+ int windowProc = parent.getShell ().getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, SWT.Help);
+ if ((style & SWT.CASCADE) != 0) {
+ OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, SWT.Arm);
+ OS.XtAddCallback (handle, OS.XmNcascadingCallback, windowProc, SWT.Arm);
+ } else {
+ OS.XtAddCallback (handle, OS.XmNarmCallback, windowProc, SWT.Arm);
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
+ } else {
+ OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, SWT.Selection);
+ }
+}
+/**
+* Gets the enabled state.
+* <p>
+* This method gets the enabled state of the widget
+* in the widget hierarchy. When an ancestor of the
+* widget is disabled, the enabled state of the widget
+* in the widget hierarchy is disabled regardless of
+* the actual enabled state of the widget.
+*
+* @param enabled a boolean that is the enabled state.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isEnabled () {
+ return getEnabled ();
+}
+String keysymName (int keysym) {
+ if (keysym == 8) return "BackSpace";
+ if (keysym == 13) return "Return";
+ if (keysym == 27) return "Escape";
+ if (keysym == 127) return "Delete";
+ if (33 <= keysym && keysym <= 126) {
+ return new String (new char [] {(char) keysym});
+ }
+ /**
+ * Note that XKeysymToString returns a value in a static
+ * area which must not be modified or freed.
+ */
+ int ptr = OS.XKeysymToString (keysym);
+ if (ptr == 0) return "";
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, buffer.length);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+int processArm (int callData) {
+ postEvent (SWT.Arm);
+ return 0;
+}
+int processHelp (int callData) {
+ if (hooks (SWT.Help)) {
+ postEvent (SWT.Help);
+ return 0;
+ }
+ parent.sendHelpEvent (callData);
+ return 0;
+}
+int processSelection (int callData) {
+ postEvent (SWT.Selection);
+ return 0;
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (menu != null) menu.dispose ();
+ menu = null;
+}
+void releaseWidget () {
+ if (menu != null && !menu.isDisposed()) {
+ menu.releaseWidget ();
+ menu.releaseHandle ();
+ }
+ menu = null;
+ super.releaseWidget ();
+ accelerator = 0;
+ if (this == parent.defaultItem) {
+ parent.defaultItem = null;
+ }
+ parent = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeArmListener (ArmListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Arm, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Help, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Sets the accelerator.
+*/
+public void setAccelerator (int accelerator) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.accelerator = accelerator;
+ int ptr = 0;
+ if (accelerator != 0) {
+ String ctrl, alt, shift;
+ ctrl = alt = shift = "";
+ if ((accelerator & SWT.ALT) != 0) alt = "Meta ";
+ if ((accelerator & SWT.SHIFT) != 0) shift = "Shift ";
+ if ((accelerator & SWT.CTRL) != 0) ctrl = "Ctrl ";
+ int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
+ int newKey = Display.untranslateKey (keysym);
+ if (newKey != 0) {
+ keysym = newKey;
+ } else {
+ keysym = wcsToMbcs ((char) keysym);
+ }
+ String key = "<Key>" + keysymName (keysym);
+ byte [] buffer = Converter.wcsToMbcs (null, ctrl + alt + shift + key, true);
+ ptr = OS.XtMalloc (buffer.length);
+ if (ptr != 0) OS.memmove (ptr, buffer, buffer.length);
+ }
+ int [] argList = {OS.XmNaccelerator, ptr};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (ptr != 0) OS.XtFree (ptr);
+}
+/**
+* Sets the enabled state.
+* <p>
+* A disabled widget is typically not selectable from
+* the user interface and draws with an inactive or
+* grayed look.
+*
+* @param enabled the new value of the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the menu.
+* <p>
+* For a cascade menu item, the menu is a pulldown menu
+* that is displayed when the user selects the cascade item.
+* For a window, the menu is always a popup menu, that is
+* displayed when the user requests a popup menu for the
+* window. The sequence of key strokes or button presses
+* that requests a menu is platform specific.
+*
+* @param menu the menu
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMenu (Menu menu) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ /* Check to make sure the new menu is valid */
+ if ((style & SWT.CASCADE) == 0) {
+ error (SWT.ERROR_MENUITEM_NOT_CASCADE);
+ }
+ if (menu != null) {
+ if ((menu.style & SWT.DROP_DOWN) == 0) {
+ error (SWT.ERROR_MENU_NOT_DROP_DOWN);
+ }
+ if (menu.parent != parent.parent) {
+ error (SWT.ERROR_INVALID_PARENT);
+ }
+ }
+
+ /* Assign the new menu */
+ Menu oldMenu = this.menu;
+ if (oldMenu == menu) return;
+ if (oldMenu != null) oldMenu.cascade = null;
+ this.menu = menu;
+ int menuHandle = 0;
+
+ /* Set the new menu in the OS */
+ if (menu != null) {
+ menu.cascade = this;
+ menuHandle = menu.handle;
+ }
+ int [] argList = {OS.XmNsubMenuId, menuHandle};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the selection state.
+* <p>
+* This method sets the widget selection state for a
+* widgets with the style CHECK or RADIO. It
+* returns false for widgets that do not have one of
+* these styles.
+*
+* @param selected the new selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (boolean selected) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
+ int [] argList = {OS.XmNset, selected ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the widget text.
+* <p>
+* @param string the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return;
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ boolean accel = false;
+ int i=0, j=0, mnemonic=0;
+ while (i < text.length) {
+ if (text [i] == '\t') {accel = true; break;};
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ byte [] buffer2;
+ if (accel && ++i < text.length) {
+ char [] accelText = new char [text.length - i];
+ System.arraycopy (text, i, accelText, 0, accelText.length);
+ buffer2 = Converter.wcsToMbcs (null, accelText, true);
+ } else {
+ buffer2 = new byte [1];
+ }
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ while (j < text.length) text [j++] = 0;
+ byte [] buffer1 = Converter.wcsToMbcs (null, text, true);
+ int xmString1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ int [] argList = {
+ OS.XmNlabelType, OS.XmSTRING,
+ OS.XmNlabelString, xmString1,
+ OS.XmNmnemonic, mnemonic,
+ OS.XmNacceleratorText, xmString2,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ if (xmString1 != 0) OS.XmStringFree (xmString1);
+ if (xmString2 != 0) OS.XmStringFree (xmString2);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java
new file mode 100755
index 0000000000..2f06dd4927
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java
@@ -0,0 +1,319 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* A message box is used to inform or warn the
+* the user that a particular situation has occurred.
+*
+* Styles
+*
+* ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING,
+* OK, OK_CANCEL, YES_NO, YES_NO_CANCEL
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+
+/* Class Definition */
+public /*final*/ class MessageBox extends Dialog {
+ int button;
+ String message = "";
+public MessageBox (Shell parent) {
+ this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
+}
+public MessageBox (Shell parent, int style) {
+ super (parent, checkStyle (style));
+}
+int activate (int widget, int client, int call) {
+ OS.XtUnmanageChild (widget);
+ button = client;
+ return 0;
+}
+static int checkStyle (int style) {
+ if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL;
+ int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
+ int bits = style & mask;
+ if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
+ if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
+ if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
+ style = (style & ~mask) | SWT.OK;
+ return style;
+}
+int createHandle (int parentHandle, int [] argList) {
+ if ((style & SWT.ICON_ERROR) != 0) return OS.XmCreateErrorDialog (parentHandle, null, argList, argList.length / 2);
+ if ((style & SWT.ICON_INFORMATION) != 0) return OS.XmCreateInformationDialog (parentHandle, null, argList, argList.length / 2);
+ if ((style & SWT.ICON_QUESTION) != 0) return OS.XmCreateQuestionDialog (parentHandle, null, argList, argList.length / 2);
+ if ((style & SWT.ICON_WARNING) != 0) return OS.XmCreateWarningDialog (parentHandle, null, argList, argList.length / 2);
+ return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2);
+}
+public String getMessage () {
+ return message;
+}
+public int open () {
+
+ /* Create the dialog.*/
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int display = appContext.xDisplay;
+ int parentHandle = appContext.shellHandle;
+ if (parent != null && parent.getDisplay () == appContext)
+ parentHandle = parent.shellHandle;
+
+ /* Compute the dialog title */
+ /*
+ * Feature in Motif. It is not possible to set a shell
+ * title to an empty string. The fix is to set the title
+ * to be a single space.
+ */
+ String string = title;
+ if (string.length () == 0) string = " ";
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int xmStringPtr = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ /*
+ * Feature in Motif. The modal values are only hints
+ * to the window manager. For example Enlightenment treats all modes
+ * as SWT.APPLICATION_MODAL. The generic Motif
+ * Window Manager honours all modes.
+ */
+ int dialogStyle = OS.XmDIALOG_MODELESS;
+ if ((style & SWT.PRIMARY_MODAL) != 0) dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
+ if ((style & SWT.APPLICATION_MODAL) != 0) dialogStyle = OS.XmDIALOG_FULL_APPLICATION_MODAL;
+ if ((style & SWT.SYSTEM_MODAL) != 0) dialogStyle = OS.XmDIALOG_SYSTEM_MODAL;
+ if (parent != null && dialogStyle == OS.XmDIALOG_MODELESS) {
+ dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
+ }
+ int [] argList = {
+ OS.XmNnoResize, 1,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, dialogStyle,
+ OS.XmNdialogTitle, xmStringPtr,
+ };
+ int dialog = createHandle (parentHandle, argList);
+ OS.XmStringFree (xmStringPtr);
+ setMessage (dialog);
+ setButtons (dialog);
+
+ /* Hook the callbacks. */
+ Callback callback = new Callback (this, "activate", 3);
+ int address = callback.getAddress ();
+ OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
+ OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
+ OS.XtAddCallback (dialog, OS.XmNhelpCallback, address, OS.XmDIALOG_HELP_BUTTON);
+
+ /* Open the dialog and dispatch events. */
+/*
+ shell == nil ifFalse: [
+ shell minimized ifTrue: [shell minimized: false]].
+*/
+ OS.XtManageChild (dialog);
+
+//BOGUS - should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch()) appContext.sleep ();
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ callback.dispose ();
+
+// (shell == nil or: [shell isDestroyed not]) ifTrue: [dialog xtDestroyWidget].
+// OSWidget updateDisplay.
+// entryPoint unbind.
+
+ if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
+ if (button == OS.XmDIALOG_OK_BUTTON) return SWT.YES;
+ if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.NO;
+ return SWT.CANCEL;
+ };
+ if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
+ return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.YES : SWT.NO;
+ }
+ if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
+ return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.OK : SWT.CANCEL;
+ }
+ if ((style & SWT.OK) == SWT.OK) return SWT.OK;
+ if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
+ return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.RETRY : SWT.CANCEL;
+ }
+ if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
+ if (button == OS.XmDIALOG_OK_BUTTON) return SWT.ABORT;
+ if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.RETRY;
+ return SWT.IGNORE;
+ }
+ return SWT.CANCEL;
+}
+void setButtons (int dialogHandle) {
+
+ /* Get the button children */
+ int ok = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_OK_BUTTON);
+ int cancel = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_CANCEL_BUTTON);
+ int help = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_HELP_BUTTON);
+ OS.XtUnmanageChild (help);
+
+ /* Set the button labels */
+ if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) return;
+ if ((style & SWT.OK) == SWT.OK) {
+ OS.XtUnmanageChild (cancel);
+ return;
+ }
+ if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
+ OS.XtManageChild (help);
+ byte [] buffer1 = Converter.wcsToMbcs (null, "Yes", true);
+ int xmString1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer2 = Converter.wcsToMbcs (null, "No", true);
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer3 = Converter.wcsToMbcs (null, "Cancel", true);
+ int xmString3 = OS.XmStringParseText (
+ buffer3,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
+ OS.XtSetValues (dialogHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
+ return;
+ }
+ if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
+ byte [] buffer1 = Converter.wcsToMbcs (null, "Yes", true);
+ int xmString1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer2 = Converter.wcsToMbcs (null, "No", true);
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
+ OS.XtSetValues (dialogHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
+ return;
+ }
+ if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
+ byte [] buffer1 = Converter.wcsToMbcs (null, "Retry", true);
+ int xmString1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer2 = Converter.wcsToMbcs (null, "Cancel", true);
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
+ OS.XtSetValues (dialogHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
+ return;
+ }
+ if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
+ OS.XtManageChild (help);
+ byte [] buffer1 = Converter.wcsToMbcs (null, "Abort", true);
+ int xmString1 = OS.XmStringParseText (
+ buffer1,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer2 = Converter.wcsToMbcs (null, "Retry", true);
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ byte [] buffer3 = Converter.wcsToMbcs (null, "Ignore", true);
+ int xmString3 = OS.XmStringParseText (
+ buffer3,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
+ OS.XtSetValues (dialogHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
+ return;
+ }
+}
+void setMessage (int dialogHandle) {
+ String text = message;
+ int label = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_MESSAGE_LABEL);
+ if (label != 0) {
+// (fontList := OSWidget resourceAt: XmNfontList handle: widget) == 0 ifFalse: [
+// text := OSWidget wrapText: message font: fontList width: DisplayWidth * 3 // 5]].
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ int [] parseTable = Display.getDefault ().parseTable;
+ int xmStringPtr = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ parseTable,
+ parseTable.length,
+ 0);
+ int [] argList = {OS.XmNmessageString, xmStringPtr};
+ OS.XtSetValues (dialogHandle, argList, argList.length / 2);
+ OS.XmStringFree (xmStringPtr);
+}
+public void setMessage (String string) {
+ message = string;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
new file mode 100755
index 0000000000..eb1a6cdbec
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
@@ -0,0 +1,262 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+* A progress bar is an unselectable user interface object
+* that is used to display progress in the form of a bar graph.
+*
+* <b>Styles</b><br>
+* <dd>HORIZONTAL, VERTICAL<br>
+*/
+
+/* Class Definition */
+public /*final*/ class ProgressBar extends Control {
+/**
+* Creates a new instance of the widget.
+*/
+public ProgressBar (Composite parent, int style) {
+ /**
+ * Feature in Motif. If you set the progress bar's value to 0,
+ * the thumb does not disappear. In order to make this happen,
+ * we hide the widget when the value is set to zero by changing
+ * its colors to render it invisible, which means that it
+ * would not visible unless a border is present. The fix is to
+ * always ensure that there is a border, which will be drawn
+ * even when the value is 0.
+ */
+ super (parent, checkStyle (style | SWT.BORDER));
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ Display display = getDisplay ();
+ int hScroll = display.scrolledMarginX;
+ int vScroll = display.scrolledMarginY;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ width += hScroll * 10;
+ height += vScroll;
+ } else {
+ width += hScroll;
+ height += vScroll * 10;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int backgroundPixel = defaultBackground ();
+ int [] argList1 = {
+ OS.XmNshowArrows, 0,
+ OS.XmNsliderSize, 1,
+ OS.XmNtraversalOn, 0,
+ OS.XmNtroughColor, backgroundPixel,
+ OS.XmNtopShadowColor, backgroundPixel,
+ OS.XmNbottomShadowColor, backgroundPixel,
+ OS.XmNshadowThickness, 1,
+ OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
+ OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
+ OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_TOP,
+ };
+ handle = OS.XmCreateScrollBar (parent.handle, null, argList1, argList1.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+/**
+* Gets the maximum.
+* <p>
+* @return maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMaximum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNmaximum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the minimum.
+* <p>
+* @return minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMinimum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNminimum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the selection.
+* <p>
+* @return the selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {
+ OS.XmNminimum, 0,
+ OS.XmNsliderSize, 0,
+ OS.XmNbackground, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int minimum = argList [1];
+ int sliderSize = argList [3];
+ int backGround = argList [5];
+ if (sliderSize == 1 && backGround == defaultBackground()) sliderSize = 0;
+ return minimum + sliderSize;
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int event_mask = OS.XtBuildEventMask (handle);
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.event_mask = event_mask & ~OS.ButtonPressMask;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWEventMask, attributes);
+}
+/**
+* Sets the maximum.
+* <p>
+* @param maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMaximum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the minimum
+* <p>
+* @param minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMinimum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {
+ OS.XmNminimum, 0,
+ OS.XmNmaximum, 0,
+ OS.XmNsliderSize, 0,
+ OS.XmNvalue, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int minimum = argList [1];
+ int maximum = argList [3];
+ int sliderSize = argList [5];
+
+ if (value >= maximum) return;
+ int selection = sliderSize + minimum;
+ if (value > selection) selection = value;
+ argList [1] = value;
+ argList [7] = value;
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+ setThumb(selection - value);
+}
+/**
+* Sets the selection.
+* <p>
+* @param value new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {
+ OS.XmNminimum, 0,
+ OS.XmNmaximum, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int minimum = argList [1];
+ int maximum = argList [3];
+
+ int selection = value;
+ if (selection < minimum) selection = minimum;
+ if (selection > maximum) selection = maximum;
+ setThumb(selection - minimum);
+}
+void setThumb (int sliderSize) {
+ Display display = getDisplay ();
+ int backgroundPixel = defaultBackground ();
+ int [] argList1 = new int [] {OS.XmNbackground, 0};
+ OS.XtGetValues (handle, argList1, argList1.length / 2);
+ if (sliderSize == 0) {
+ if (argList1 [1] != backgroundPixel) {
+ OS.XmChangeColor (handle, backgroundPixel);
+ }
+ } else {
+ if (argList1 [1] != display.listForeground) {
+ OS.XmChangeColor (handle, display.listForeground);
+ }
+ }
+ int [] argList2 = new int [] {
+ OS.XmNsliderSize, (sliderSize == 0) ? 1 : sliderSize,
+ OS.XmNtroughColor, backgroundPixel,
+ OS.XmNtopShadowColor, backgroundPixel,
+ OS.XmNbottomShadowColor, backgroundPixel,
+ };
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList2, argList2.length / 2);
+ display.setWarnings (warnings);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java
new file mode 100755
index 0000000000..66fcca5ba0
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java
@@ -0,0 +1,227 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A sash is a selectable user interface object
+* that allows the user to drag a rubber banded
+* outline of the sash within the parent window.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>HORIZONTAL,VERTICAL<br>
+*/
+
+/* Class Definition */
+public /*final*/ class Sash extends Control {
+ boolean dragging;
+ int startX, startY, lastX, lastY;
+ int cursor;
+/**
+* Creates a new instance of the widget.
+*/
+public Sash (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ width += DEFAULT_WIDTH; height += 3;
+ } else {
+ width += 3; height += DEFAULT_HEIGHT;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int border = (style & SWT.BORDER) != 0 ? 1 : 0;
+ int [] argList = {
+ OS.XmNborderWidth, border,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ };
+ handle = OS.XmCreateDrawingArea (parent.handle, null, argList, argList.length / 2);
+}
+void drawBand (int x, int y, int width, int height) {
+ int display = OS.XtDisplay (parent.handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (parent.handle);
+ if (window == 0) return;
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (parent.handle, argList, argList.length / 2);
+ int color = argList [1] ^ argList [3];
+ byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
+ int stipplePixmap = OS.XCreateBitmapFromData (display, window, bits, 8, 8);
+ int gc = OS.XCreateGC (display, window, 0, null);
+ OS.XSetForeground (display, gc, color);
+ OS.XSetStipple (display, gc, stipplePixmap);
+ OS.XSetSubwindowMode (display, gc, OS.IncludeInferiors);
+ OS.XSetFillStyle (display, gc, OS.FillStippled);
+ OS.XSetFunction (display, gc, OS.GXxor);
+ OS.XFillRectangle (display, window, gc, x, y, width, height);
+ OS.XFreePixmap (display, stipplePixmap);
+ OS.XFreeGC (display, gc);
+}
+int processMouseDown (int callData) {
+ super.processMouseDown (callData);
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ if (xEvent.button != 1) return 0;
+ startX = xEvent.x; startY = xEvent.y;
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int border = argList [9], width = argList [5] + (border * 2), height = argList [7] + (border * 2);
+ lastX = ((short) argList [1]) - border; lastY = ((short) argList [3]) - border;
+ Event event = new Event ();
+ event.detail = SWT.DRAG;
+ event.time = xEvent.time;
+ event.x = lastX; event.y = lastY;
+ event.width = width; event.height = height;
+ sendEvent (SWT.Selection, event);
+ if (event.doit) {
+ dragging = true;
+ OS.XmUpdateDisplay (handle);
+ drawBand (lastX = event.x, lastY = event.y, width, height);
+ }
+ return 0;
+}
+int processMouseMove (int callData) {
+ super.processMouseMove (callData);
+ XMotionEvent xEvent = new XMotionEvent ();
+ OS.memmove (xEvent, callData, XMotionEvent.sizeof);
+ if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return 0;
+ int [] argList1 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList1, argList1.length / 2);
+ int border = argList1 [9], x = ((short) argList1 [1]) - border, y = ((short) argList1 [3]) - border;
+ int width = argList1 [5] + (border * 2), height = argList1 [7] + (border * 2);
+ int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (parent.handle, argList2, argList2.length / 2);
+ int parentBorder = argList2 [5];
+ int parentWidth = argList2 [1] + (parentBorder * 2);
+ int parentHeight = argList2 [3] + (parentBorder * 2);
+ int newX = lastX, newY = lastY;
+ if ((style & SWT.VERTICAL) != 0) {
+ newX = Math.min (Math.max (0, xEvent.x + x - startX - parentBorder), parentWidth - width);
+ } else {
+ newY = Math.min (Math.max (0, xEvent.y + y - startY - parentBorder), parentHeight - height);
+ }
+ if (newX == lastX && newY == lastY) return 0;
+ drawBand (lastX, lastY, width, height);
+ Event event = new Event ();
+ event.detail = SWT.DRAG;
+ event.time = xEvent.time;
+ event.x = newX; event.y = newY;
+ event.width = width; event.height = height;
+ sendEvent (SWT.Selection, event);
+ if (event.doit) {
+ lastX = event.x; lastY = event.y;
+ OS.XmUpdateDisplay (handle);
+ drawBand (lastX, lastY, width, height);
+ }
+ return 0;
+}
+int processMouseUp (int callData) {
+ super.processMouseUp (callData);
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ if (xEvent.button != 1) return 0;
+ if (!dragging) return 0;
+ dragging = false;
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int border = argList [5];
+ int width = argList [1] + (border * 2), height = argList [3] + (border * 2);
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.x = lastX; event.y = lastY;
+ event.width = width; event.height = height;
+ drawBand (lastX, lastY, width, height);
+ sendEvent (SWT.Selection, event);
+ return 0;
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ cursor = OS.XCreateFontCursor (display, OS.XC_sb_v_double_arrow);
+ } else {
+ cursor = OS.XCreateFontCursor (display, OS.XC_sb_h_double_arrow);
+ }
+ OS.XDefineCursor (display, window, cursor);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ if (cursor != 0) {
+ int display = OS.XtDisplay (handle);
+ if (display != 0) OS.XFreeCursor (display, cursor);
+ }
+ cursor = 0;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java
new file mode 100755
index 0000000000..583ba89eba
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java
@@ -0,0 +1,300 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+* A scale is a selectable user interface object
+* that represents a range of continuous numeric values.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>HORIZONTAL,VERTICAL<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Selection<br
+*/
+
+/* Class Definition */
+public /*final*/ class Scale extends Control {
+/**
+* Creates a new instance of the widget.
+*/
+public Scale (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ Display display = getDisplay ();
+ int hScroll = display.scrolledMarginX;
+ int vScroll = display.scrolledMarginY;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ width += hScroll * 10;
+ height += vScroll;
+ } else {
+ width += hScroll;
+ height += vScroll * 10;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int [] argList = {
+ OS.XmNtitleString, 0,
+ OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
+ OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
+ OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_BOTTOM,
+ };
+ handle = OS.XmCreateScale (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+/**
+* Gets the increment.
+* <p>
+* @return the increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return 1;
+}
+/**
+* Gets the maximum.
+* <p>
+* @return the maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMaximum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNmaximum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the minimum.
+* <p>
+* @return the minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMinimum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNminimum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the page increment.
+* <p>
+* @return the page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getPageIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNscaleMultiple, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the selection.
+* <p>
+* @return the selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNvalue, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Sets the increment value.
+* <p>
+* @param increment the new increment value
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setIncrement (int increment) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+/**
+* Sets the maximum.
+* <p>
+* @param maximum the new maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMaximum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the minimum.
+* <p>
+* @param minimum the new minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMinimum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNminimum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the page increment.
+* <p>
+* @param pageIncrement the new page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setPageIncrement (int pageIncrement) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (pageIncrement < 1) return;
+ int [] argList = {OS.XmNscaleMultiple, pageIncrement};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the selection.
+* <p>
+* @param selection the new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int selection) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (selection < 0) return;
+ int [] argList = {OS.XmNvalue, selection};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java
new file mode 100755
index 0000000000..1ef0f41558
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java
@@ -0,0 +1,558 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A scroll bar is a selectable user interface object
+* that represents a range of continuous numeric values.
+* Typically these values are used to represent lines of
+* text in a list or text widget.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>HORIZONTAL, VERTICAL<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class ScrollBar extends Widget {
+ Scrollable parent;
+ScrollBar () {
+ /* Do Nothing */
+}
+ScrollBar (Scrollable parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ createWidget (0);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int [] argList = {
+ OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
+ OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
+ };
+ handle = OS.XmCreateScrollBar (parent.scrolledHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Scrollable parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+* Gets the enabled state.
+* <p>
+* @return the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the increment.
+* <p>
+* @return the increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNincrement, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the maximum.
+* <p>
+* @return the maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMaximum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNmaximum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the minimum.
+* <p>
+* @return the minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMinimum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNminimum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the page increment.
+* <p>
+* @return the page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getPageIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNpageIncrement, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the parent.
+* <p>
+* @return the parent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Scrollable getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the selection.
+* <p>
+* @return the selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNvalue, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the scroll bar size.
+* <p>
+* @return the scroll bar size
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* </ul>
+*/
+public Point getSize () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int borders = argList [5] * 2;
+ return new Point (argList [1] + borders, argList [3] + borders);
+}
+/**
+* Gets the thumb.
+* <p>
+* @return the thumb value
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getThumb () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsliderSize, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @return visible the visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XtIsManaged (handle);
+}
+void hookEvents () {
+ int windowProc = parent.getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, SWT.Selection);
+}
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getEnabled () && parent.isEnabled ();
+}
+/**
+* Gets the visibility status.
+* <p>
+* This method returns the visibility status of the
+* widget in the widget hierarchy. If the parent is not
+* visible or some other condition makes the widget not
+* visible, this method will return false.
+*
+* @return the actual visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getVisible () && parent.isVisible ();
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+int processSelection (int callData) {
+ XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
+ OS.memmove (struct, callData, XmAnyCallbackStruct.sizeof);
+ Event event = new Event ();
+ switch (struct.reason) {
+ case OS.XmCR_DRAG: event.detail = SWT.DRAG; break;
+ /*
+ * Do not set the detail field to SWT.DRAG
+ * to indicate that the dragging has ended.
+ */
+// case OS.XmCR_VALUE_CHANGED: break;
+ case OS.XmCR_TO_TOP: event.detail = SWT.HOME; break;
+ case OS.XmCR_TO_BOTTOM: event.detail = SWT.END; break;
+ case OS.XmCR_DECREMENT: event.detail = SWT.ARROW_UP; break;
+ case OS.XmCR_INCREMENT: event.detail = SWT.ARROW_DOWN; break;
+ case OS.XmCR_PAGE_DECREMENT: event.detail = SWT.PAGE_UP; break;
+ case OS.XmCR_PAGE_INCREMENT: event.detail = SWT.PAGE_DOWN; break;
+ }
+ sendEvent (SWT.Selection, event);
+ return 0;
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (parent.horizontalBar == this) parent.horizontalBar = null;
+ if (parent.verticalBar == this) parent.verticalBar = null;
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Sets the enabled state.
+* <p>
+* @param enabled the new value of the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the increment.
+* <p>
+* @param value the new increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setIncrement (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNincrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the maximum.
+* <p>
+* @param value the new maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMaximum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the minimum.
+* <p>
+* @param value the new minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMinimum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {
+ OS.XmNminimum, 0,
+ OS.XmNmaximum, 0,
+ OS.XmNsliderSize, 0,
+ };
+ /*
+ * Feature in Motif. For some reason, when minimium
+ * is set to be greater than or equal to maximum, Motif
+ * does not set the minimum. Instead, the value is
+ * changed and the minimum stays the same. This behavior
+ * differs from setting the maximum where the slider size
+ * is always decreased to make room for the new maximum.
+ * The fix is to decrease the slider to make room for
+ * the new minimum.
+ */
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [3] - value - argList [5] < 0) {
+ argList [5] = argList [3] - value;
+ }
+ argList [1] = value;
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the page increment.
+* <p>
+* @param value the new page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setPageIncrement (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNpageIncrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the selection.
+* <p>
+* @param value the new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int selection) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (selection < 0) return;
+ int [] argList = {OS.XmNvalue, selection};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the thumb.
+* <p>
+* @param value the new thumb value
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setThumb (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNsliderSize, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (selection < 0) return;
+ if (minimum < 0) return;
+ if (maximum < 0) return;
+ if (thumb < 1) return;
+ if (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] argList = {
+ OS.XmNvalue, selection,
+ OS.XmNminimum, minimum,
+ OS.XmNmaximum, maximum,
+ OS.XmNsliderSize, thumb,
+ OS.XmNincrement, increment,
+ OS.XmNpageIncrement, pageIncrement,
+ };
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the visibility state.
+* <p>
+* If the parent is not visible or some other condition
+* makes the widget not visible, the widget can still be
+* considered visible even though it may not actually be
+* showing.
+*
+* @param visible the new visibility state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Feature in Motif. Hiding or showing a scroll bar
+ * can cause the widget to automatically resize in
+ * the OS. This behavior is unwanted. The fix is
+ * to force the widget to resize to original size.
+ */
+ int scrolledHandle = parent.scrolledHandle;
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+
+ /* Hide or show the scroll bar */
+ if (visible) {
+ OS.XtManageChild (handle);
+ } else {
+ OS.XtUnmanageChild (handle);
+ }
+
+ /* Restore the size */
+ OS.XtSetValues (scrolledHandle, argList, argList.length / 2);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java
new file mode 100755
index 0000000000..7915cca806
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java
@@ -0,0 +1,217 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+public abstract class Scrollable extends Control {
+ int scrolledHandle, formHandle;
+ ScrollBar horizontalBar, verticalBar;
+Scrollable () {
+ /* Do nothing */
+}
+public Scrollable (Composite parent, int style) {
+ super (parent, style);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int trimX = x - border, trimY = y - border;
+ int trimWidth = width + (border * 2), trimHeight = height + (border * 2);
+ boolean hasHBar = (horizontalBar != null) && (horizontalBar.getVisible ());
+ boolean hasVBar = (verticalBar != null) && (verticalBar.getVisible ());
+ if (hasHBar) {
+ Display display = getDisplay ();
+ trimY -= display.scrolledInsetY;
+ trimHeight += display.scrolledInsetY + display.scrolledMarginY;
+ if (!hasVBar) {
+ trimX -= display.scrolledInsetX;
+ trimWidth += display.scrolledInsetX * 2;
+ trimHeight -= display.scrolledInsetY * 2;
+ }
+ }
+ if (hasVBar) {
+ Display display = getDisplay ();
+ trimX -= display.scrolledInsetX;
+ trimWidth += display.scrolledInsetX + display.scrolledMarginX;
+ if (!hasHBar) {
+ trimY -= display.scrolledInsetY;
+ trimHeight += display.scrolledInsetY * 2;
+ trimWidth -= display.scrolledInsetX * 2;
+ }
+ }
+ return new Rectangle (trimX, trimY, trimWidth, trimHeight);
+}
+ScrollBar createScrollBar (int type) {
+ return new ScrollBar (this, type);
+}
+ScrollBar createStandardBar (int style) {
+ if (scrolledHandle == 0) return null;
+ ScrollBar bar = new ScrollBar ();
+ bar.parent = this;
+ bar.style = style;
+ bar.state |= HANDLE;
+ int [] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ if (style == SWT.H_SCROLL) bar.handle = argList [1];
+ if (style == SWT.V_SCROLL) bar.handle = argList [3];
+ bar.hookEvents ();
+ bar.register ();
+ return bar;
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
+ if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
+}
+void deregister () {
+ super.deregister ();
+ if (formHandle != 0) WidgetTable.remove (formHandle);
+ if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
+}
+void enableWidget (boolean enabled) {
+ super.enableWidget (enabled);
+ if (formHandle != 0) enableHandle (enabled, formHandle);
+ if (scrolledHandle != 0) {
+ enableHandle (enabled, scrolledHandle);
+ int [] argList = {
+ OS.XmNhorizontalScrollBar, 0,
+ OS.XmNverticalScrollBar, 0,
+ };
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ if (argList [1] != 0) enableHandle (enabled, argList [1]);
+ if (argList [3] != 0) enableHandle (enabled, argList [3]);
+ }
+}
+public Rectangle getClientArea () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return new Rectangle (0, 0, argList [1], argList [3]);
+}
+public ScrollBar getHorizontalBar () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return horizontalBar;
+}
+public ScrollBar getVerticalBar () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return verticalBar;
+}
+void manageChildren () {
+ if (scrolledHandle != 0) {
+ OS.XtSetMappedWhenManaged (scrolledHandle, false);
+ OS.XtManageChild (scrolledHandle);
+ }
+ if (formHandle != 0) {
+ OS.XtSetMappedWhenManaged (formHandle, false);
+ OS.XtManageChild (formHandle);
+ }
+ super.manageChildren ();
+ if (formHandle != 0) {
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (formHandle, argList, argList.length / 2);
+ OS.XtResizeWidget (formHandle, 1, 1, argList [1]);
+ OS.XtSetMappedWhenManaged (formHandle, true);
+ }
+ if (scrolledHandle != 0) {
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ OS.XtResizeWidget (scrolledHandle, 1, 1, argList [1]);
+ OS.XtSetMappedWhenManaged (scrolledHandle, true);
+ }
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ if (formHandle != 0) propagateHandle (enabled, formHandle);
+ if (scrolledHandle != 0) {
+ propagateHandle (enabled, scrolledHandle);
+ int [] argList = {
+ OS.XmNhorizontalScrollBar, 0,
+ OS.XmNverticalScrollBar, 0,
+ };
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ if (argList [1] != 0) propagateHandle (enabled, argList [1]);
+ if (argList [3] != 0) propagateHandle (enabled, argList [3]);
+ }
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ /*
+ * Uncomment this code to force the window trimmings to redraw.
+ */
+// if (formHandle == 0 && scrolledHandle == 0) return;
+// short [] root_x = new short [1], root_y = new short [1];
+// OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
+// if (formHandle != 0) {
+// short [] form_x = new short [1], form_y = new short [1];
+// OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, form_x, form_y);
+// redrawHandle (root_x [0] - form_x [0], root_y [0] - form_y [0], width, height, formHandle);
+// }
+// if (scrolledHandle != 0) {
+// short [] scrolled_x = new short [1], scrolled_y = new short [1];
+// OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y);
+// redrawHandle (root_x [0] - scrolled_x [0], root_y [0] - scrolled_y [0], width, height, scrolledHandle);
+// if (horizontalBar != null && horizontalBar.getVisible ()) {
+// int horizontalHandle = horizontalBar.handle;
+// short [] hscroll_x = new short [1], hscroll_y = new short [1];
+// OS.XtTranslateCoords (horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y);
+// redrawHandle (root_x [0] - hscroll_x [0], root_y [0] - hscroll_y [0], width, height, horizontalHandle);
+// }
+// if (verticalBar != null && verticalBar.getVisible ()) {
+// int verticalHandle = verticalBar.handle;
+// short [] vscroll_x = new short [1], vscroll_y = new short [1];
+// OS.XtTranslateCoords (verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y);
+// redrawHandle (root_x [0] - vscroll_x [0], root_y [0] - vscroll_y [0], width, height, verticalHandle);
+// }
+// }
+}
+void register () {
+ super.register ();
+ if (formHandle != 0) WidgetTable.put (formHandle, this);
+ if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ scrolledHandle = formHandle = 0;
+}
+void releaseWidget () {
+ if (horizontalBar != null) {
+ horizontalBar.releaseWidget ();
+ horizontalBar.releaseHandle ();
+ }
+ if (verticalBar != null) {
+ verticalBar.releaseWidget ();
+ verticalBar.releaseHandle ();
+ }
+ horizontalBar = verticalBar = null;
+ super.releaseWidget ();
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ if (scrolledHandle != 0) {
+ int [] argList1 = {
+ OS.XmNhorizontalScrollBar, 0,
+ OS.XmNverticalScrollBar, 0,
+ };
+ OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
+ if (argList1 [1] != 0) OS.XmChangeColor (argList1 [1], pixel);
+ if (argList1 [3] != 0) OS.XmChangeColor (argList1 [3], pixel);
+ }
+}
+int topHandle () {
+ if (scrolledHandle != 0) return scrolledHandle;
+ if (formHandle != 0) return formHandle;
+ return handle;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItem.java
new file mode 100755
index 0000000000..7b590263a7
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItem.java
@@ -0,0 +1,320 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class implements common behavior of TreeItem and TableItem.
+ */
+abstract class SelectableItem extends Item {
+ protected static final int CHECKBOX_PADDING = 1; // Space behind check box, before item image or text
+
+ private SelectableItemWidget parent; // parent widget of the receiver
+ private boolean isSelected = false; // item selection state
+ private boolean isChecked = false; // item checked state. Can be one of checked and unchecked
+ private boolean isGrayed = false; // item grayed state. The gray state is combined with the
+ // checked state to create gray checked and gray unchecked.
+/**
+ * Create a new instance of the receiver.
+ * @param parent - widget the receiver is created in
+ * @param style - widget style. see Widget class for details
+ */
+SelectableItem(SelectableItemWidget parent, int style) {
+ super(parent, style);
+ setParent(parent);
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event event) {disposeItem();}});
+}
+/**
+ * Subclasses should free resources here
+ */
+void disposeItem() {
+ setParent(null);
+}
+/**
+ * Draw the check box of the receiver at 'position' using 'gc'.
+ * @param gc - GC to draw on.
+ * @param destinationPosition - position on the GC to draw at.
+ * @return Answer the position where drawing stopped.
+ */
+Point drawCheckbox(GC gc, Point position) {
+ SelectableItemWidget parent = getSelectableParent();
+ Image image;
+ Point imageExtent;
+ Rectangle imageBounds;
+ int imageOffset;
+ int xInset;
+ int yInset;
+
+ if (getGrayed() == true) {
+ image = parent.getGrayUncheckedImage();
+ }
+ else {
+ image = parent.getUncheckedImage();
+ }
+ if (image != null) {
+ imageExtent = parent.getCheckBoxExtent();
+ imageOffset = (parent.getItemHeight() - imageExtent.y) / 2;
+ gc.drawImage(image, position.x, position.y + imageOffset);
+ if (getChecked() == true) {
+ image = parent.getCheckMarkImage();
+ imageBounds = image.getBounds();
+ xInset = (imageExtent.x - imageBounds.width) / 2;
+ yInset = (imageExtent.y - imageBounds.height) / 2;
+ gc.drawImage(image, position.x + xInset, position.y + imageOffset + yInset);
+ }
+ position.x += imageExtent.x;
+ }
+ position.x += CHECKBOX_PADDING; // leave extra space behind check box
+ return position;
+}
+void drawInsertMark(GC gc, Point position) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+ final int markerWidth = getInsertMarkWidth();
+ int insertMarkYOffset = 0;
+
+ if (selectionExtent == null) {
+ return;
+ }
+ if (parent.isInsertAfter()) {
+ insertMarkYOffset = selectionExtent.y - markerWidth;
+ }
+ gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ gc.fillRectangle(position.x, position.y + insertMarkYOffset, selectionExtent.x, markerWidth);
+ gc.setBackground(parent.getBackground());
+}
+/**
+ * Answer the bounding rectangle of the item check box.
+ * All points within this rectangle hit the check box.
+ */
+Rectangle getCheckboxBounds() {
+ SelectableItemWidget parent = getSelectableParent();
+ Point checkBoxExtent;
+ int redrawPosition;
+ Rectangle checkboxBounds = new Rectangle(0, 0, 0, 0);
+
+ if (isCheckable() == true) {
+ checkboxBounds.x = getCheckboxXPosition();
+ redrawPosition = parent.getRedrawY(this);
+ if (redrawPosition != -1) {
+ checkboxBounds.y = redrawPosition;
+ }
+ checkBoxExtent = parent.getCheckBoxExtent();
+ checkboxBounds.width = checkBoxExtent.x;
+ checkboxBounds.height = checkBoxExtent.y;
+ checkboxBounds.y += (parent.getItemHeight() - checkBoxExtent.y) / 2;
+ }
+ return checkboxBounds;
+}
+/**
+ * Answer the x position of the item check box
+ */
+abstract int getCheckboxXPosition();
+/**
+ * Return whether or not the receiver is checked.
+ * Always return false if the parent of the receiver does not
+ * have the CHECK style.
+ */
+public boolean getChecked() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean checked = false;
+
+ if (isCheckable() == true) {
+ checked = isChecked;
+ }
+ return checked;
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ SelectableItemWidget parent = getSelectableParent();
+
+ if (parent == null) {
+ error(SWT.ERROR_WIDGET_DISPOSED);
+ }
+ return parent.getDisplay();
+}
+
+/**
+ * Gets the grayed state.
+ * <p>
+ * @return the item grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean getGrayed () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ boolean grayed = false;
+
+ if (isCheckable() == true) {
+ grayed = isGrayed;
+ }
+ return grayed;
+}
+/**
+ * Return the width in pixels of the line drawn to indicate the
+ * drop insert position during a drag and drop operation.
+ */
+int getInsertMarkWidth() {
+ return 2;
+}
+/**
+ * Answer the parent widget of the receiver.
+ */
+SelectableItemWidget getSelectableParent() {
+ return parent;
+}
+/**
+ * Answer the background color to use for drawing the
+ * selection rectangle.
+ */
+Color getSelectionBackgroundColor() {
+ Display display = getSelectableParent().getDisplay();
+
+ return display.getSystemColor(SWT.COLOR_LIST_SELECTION);
+}
+/**
+ * Return the size of the rectangle drawn to indicate the
+ * selected state of the receiver.
+ */
+abstract Point getSelectionExtent();
+/**
+ * Answer the foreground color to use for drawing the
+ * selection rectangle.
+ */
+Color getSelectionForegroundColor() {
+ Display display = getSelectableParent().getDisplay();
+
+ return display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
+}
+/**
+ * Return the x position of the selection rectangle
+ */
+abstract int getSelectionX();
+/**
+ * Answer whether 'posiiton' is inside the item check box.
+ * @return
+ * true - item check box hit
+ * false - item check box not hit
+ */
+boolean isCheckHit(Point position) {
+ boolean isCheckHit = false;
+
+ if (isCheckable() == true) {
+ isCheckHit = getCheckboxBounds().contains(position);
+ }
+ return isCheckHit;
+}
+/**
+ * Return whether or not the receiver has a check box and can
+ * be checked.
+ */
+boolean isCheckable() {
+ return (getSelectableParent().getStyle() & SWT.CHECK) != 0;
+}
+/**
+ * Answer whether the receiver is selected.
+ * @return
+ * true - the receiver is selected
+ * false - the receiver is not selected
+ */
+boolean isSelected() {
+ return isSelected;
+}
+/**
+ * Redraw the insert mark
+ * @param yPosition - y position in the receiver's client area
+ * where the item should be drawn.
+ */
+void redrawInsertMark(int yPosition) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+ int redrawHeight = getInsertMarkWidth();
+
+ if (selectionExtent != null) {
+ parent.redraw(getSelectionX(), yPosition, selectionExtent.x, redrawHeight, false);
+ parent.redraw(getSelectionX(), yPosition + selectionExtent.y - redrawHeight, selectionExtent.x, redrawHeight, false);
+ }
+}
+/**
+ * Redraw the selection
+ * @param yPosition - y position in the receiver's client area
+ * where the item should be drawn.
+ */
+void redrawSelection(int yPosition) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent != null) {
+ parent.redraw(getSelectionX(), yPosition, selectionExtent.x, selectionExtent.y, false);
+ }
+}
+/**
+ * Set the checked state to 'checked' if the parent of the
+ * receiver has the CHECK style.
+ */
+public void setChecked(boolean checked) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItemWidget parent = getSelectableParent();
+ Rectangle redrawRectangle = getCheckboxBounds();
+
+ if (isCheckable() == true && isChecked != checked) {
+ isChecked = checked;
+ parent.redraw(
+ redrawRectangle.x, redrawRectangle.y,
+ redrawRectangle.width, redrawRectangle.height, false);
+ }
+}
+
+/**
+ * Sets the grayed state.
+ * <p>
+ * @param grayed the new grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public void setGrayed (boolean grayed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItemWidget parent = getSelectableParent();
+ Rectangle redrawRectangle = getCheckboxBounds();
+
+ if (isCheckable() == true && isGrayed != grayed) {
+ isGrayed = grayed;
+ parent.redraw(
+ redrawRectangle.x, redrawRectangle.y,
+ redrawRectangle.width, redrawRectangle.height, false);
+ }
+}
+
+/**
+ * Set the receiver's parent widget to 'parent'.
+ */
+void setParent(SelectableItemWidget parent) {
+ this.parent = parent;
+}
+/**
+ * Set whether the receiver is selected.
+ * @param selected - true=the receiver is selected
+ * false=the receiver is not selected
+ */
+void setSelected(boolean selected) {
+ isSelected = selected;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItemWidget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItemWidget.java
new file mode 100755
index 0000000000..0eda6178f2
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/SelectableItemWidget.java
@@ -0,0 +1,2027 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.io.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class is intended for widgets that display data of
+ * type Item. It provides a framework for scrolling and
+ * handles the screen refresh required when adding and
+ * removing items.
+ */
+abstract class SelectableItemWidget extends Composite {
+ private static final int DEFAULT_WIDTH = 64; // used in computeSize if width could not be calculated
+ private static final int DEFAULT_HEIGHT = 64; // used in computeSize if height could not be calculated
+ private static final int HORIZONTAL_SCROLL_INCREMENT = 5; // number of pixel the tree is moved
+ // during horizontal line scrolling
+ private static ImageData UncheckedImageData; // deselected check box image data. used to create an image at run time
+ private static ImageData GrayUncheckedImageData; // grayed deselected check box image data. used to create an image at run time
+ private static ImageData CheckMarkImageData; // check mark image data for check box. used to create an image at run time
+ static {
+ initializeImageData();
+ }
+
+ private int topIndex = 0; // index of the first visible item
+ private int itemHeight = 0; // height of a table item
+ private Point itemImageExtent = null; // size of the item images. Null unless an image is set for any item
+ private int textHeight = -1;
+ private int contentWidth = 0; // width of the widget data (ie. table rows/tree items)
+ private int horizontalOffset = 0;
+ private Vector selectedItems; // indices of the selected items
+ private SelectableItem lastSelectedItem; // item that was selected last
+ private SelectableItem lastFocusItem; // item that had the focus last. Always equals lastSelectedItem
+ // for mouse selection but may differ for keyboard selection
+ private SelectableItem insertItem; // item that draws the insert marker to indicate the drop location in a drag and drop operation
+ private boolean isInsertAfter; // indicates where the insert marker is rendered, at the top or bottom of 'insertItem'
+ private boolean isCtrlSelection = false; // the most recently selected item was
+ // selected using the Ctrl modifier key
+ private boolean isRemovingAll = false; // true=all items are removed. Used to optimize screen updates and to control item selection on dispose.
+ private boolean hasFocus; // workaround for 1FMITIE
+ private Image uncheckedImage; // deselected check box
+ private Image grayUncheckedImage; // grayed check box
+ private Image checkMarkImage; // check mark for selected check box
+ private Point checkBoxExtent = null; // width, height of the item check box
+ private Listener listener; // event listener used for all events. Events are dispatched
+ // to handler methods in handleEvents(Event)
+ private int drawCount = 0; // used to reimplement setRedraw(boolean)
+/**
+ * Create a new instance of ScrollableItemWidget.
+ * @param parent - the parent window of the new instance
+ * @param style - window style for the new instance
+ */
+SelectableItemWidget(Composite parent, int style) {
+ super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
+ initialize();
+}
+/**
+ * The SelectableItem 'item' has been added to the tree.
+ * Calculate the vertical scroll bar.
+ * Update the screen to display the new item.
+ * @param item - item that has been added to the receiver.
+ */
+void addedItem(SelectableItem item, int index) {
+ calculateVerticalScrollbar();
+ if (getLastFocus() == null) { // if no item has the focus
+ setLastFocus(item, true); // set focus to new (must be first) item
+ }
+}
+/**
+ * The SelectableItem 'item' is about to be added to the tree.
+ * @param item - item that is about to be added to the receiver.
+ */
+void addingItem(SelectableItem item, int index) {
+ if (index >= 0 && index <= getBottomIndex()) {
+ scrollVerticalAddingItem(index);
+ }
+}
+/**
+ * Set the scroll range of the horizontal scroll bar.
+ * Resize the scroll bar if the scroll range maximum
+ * has changed.
+ */
+void calculateHorizontalScrollbar() {
+ int newMaximum = getContentWidth();
+ ScrollBar horizontalBar = getHorizontalBar();
+
+ if (horizontalBar.getMaximum() != newMaximum) {
+ // The call to setMaximum is ignored if newMaximum is 0.
+ // Therefore we can not rely on getMaximum to subsequently return the number of
+ // items in the receiver. We always have to use getVisibleItemCount().
+ // Never rely on getMaximum to return what you set. It may not accept the
+ // value you set. Even if you use a valid value now the implementation may change
+ // later. That's what caused 1FRLOSG.
+ horizontalBar.setMaximum(newMaximum);
+ if (getVerticalBar().getVisible() == false) { // remove these lines
+ horizontalBar.setMaximum(newMaximum); // when PR 1FIG5CG
+ } // is fixed
+ resizeHorizontalScrollbar();
+ }
+}
+/**
+ * Calculate the height of items in the receiver.
+ * Only the image height is calculated if an item height
+ * has already been calculated. Do nothing if both the item
+ * height and the image height have already been calculated
+ */
+void calculateItemHeight(SelectableItem item) {
+ GC gc;
+ String itemText;
+ int itemHeight = -1;
+
+ if (itemImageExtent != null && textHeight != -1) {
+ return;
+ }
+ itemText = item.getText();
+ if (itemText != null && textHeight == -1) {
+ gc = new GC(this);
+ itemHeight = gc.stringExtent(itemText).y;
+ textHeight = itemHeight;
+ gc.dispose();
+ }
+ if (itemImageExtent == null) {
+ itemImageExtent = getImageExtent(item);
+ if (itemImageExtent != null) {
+ if (itemImageExtent.y > textHeight) {
+ itemHeight = itemImageExtent.y;
+ }
+ else {
+ itemHeight = textHeight;
+ }
+ }
+ }
+ itemHeight += getItemPadding(); // make sure that there is empty space below the image/text
+ if (itemHeight > getItemHeight()) { // only set new item height if it's higher because new,
+ setItemHeight(itemHeight); // smaller item height may not include an icon
+ }
+}
+/**
+ * Calculate the range of items that need to be selected given
+ * the clicked item identified by 'hitItemIndex'
+ * @param hitItemIndex - item that was clicked and that the new
+ * selection range will be based on. This index is relative to
+ * the top index.
+ */
+int [] calculateShiftSelectionRange(int hitItemIndex) {
+ int selectionRange[] = new int[] {-1, -1};
+ SelectableItem closestItem = null;
+ SelectableItem selectedItem;
+ Enumeration selectedItems = getSelectionVector().elements();
+
+ while (selectedItems.hasMoreElements() == true) {
+ selectedItem = (SelectableItem) selectedItems.nextElement();
+ if (closestItem == null) {
+ closestItem = selectedItem;
+ }
+ else
+ if (Math.abs(hitItemIndex - getVisibleIndex(selectedItem)) <
+ Math.abs(hitItemIndex - getVisibleIndex(closestItem))) {
+ closestItem = selectedItem;
+ }
+ }
+ if (closestItem == null) { // no item selected
+ closestItem = getLastSelection(); // item selected last may still have the focus
+ }
+ if (closestItem != null) {
+ selectionRange[0] = getVisibleIndex(closestItem);
+ selectionRange[1] = hitItemIndex;
+ }
+ return selectionRange;
+}
+/**
+ * Set the scroll range of the vertical scroll bar.
+ * Resize the scroll bar if the scroll range maximum
+ * has changed.
+ */
+void calculateVerticalScrollbar() {
+ int newMaximum = getVisibleItemCount();
+ ScrollBar verticalBar = getVerticalBar();
+
+ // The call to setMaximum is ignored if newMaximum is 0.
+ // Therefore we can not rely on getMaximum to subsequently return the number of
+ // items in the receiver. We always have to use getVisibleItemCount().
+ // Never rely on getMaximum to return what you set. It may not accept the
+ // value you set. Even if you use a valid value now the implementation may change
+ // later. That's what caused 1FRLOSG.
+ verticalBar.setMaximum(newMaximum);
+ if (getHorizontalBar().getVisible() == false) { // remove these lines
+ verticalBar.setMaximum(newMaximum); // when PR 1FIG5CG
+ } // is fixed
+ resizeVerticalScrollbar();
+}
+
+/**
+ * Answer the size of the receiver needed to display all items.
+ * The length of the longest item in the receiver is used for the
+ * width.
+ */
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = getContentWidth();
+ int height = getItemCount() * getItemHeight();
+ int style = getStyle();
+ int scrollBarWidth = computeTrim(0, 0, 0, 0).width;
+
+ if (width == 0) {
+ width = DEFAULT_WIDTH;
+ }
+ if (height == 0) {
+ height = DEFAULT_HEIGHT;
+ }
+ if (wHint != SWT.DEFAULT) {
+ width = wHint;
+ }
+ if (hHint != SWT.DEFAULT) {
+ height = hHint;
+ }
+ if ((getStyle() & SWT.V_SCROLL) != 0) {
+ width += scrollBarWidth;
+ }
+ if ((getStyle() & SWT.H_SCROLL) != 0) {
+ height += scrollBarWidth;
+ }
+ return new Point(width, height);
+}
+/**
+ * Do a ctrl+shift selection meaning the ctrl and shift keys
+ * were pressed when the mouse click on an item occurred.
+ * If an already selected item was clicked the focus is moved to
+ * that item.
+ * If the previous selection was a ctrl or ctrl+shift selection
+ * the range between the last selected item and the clicked item
+ * is selected.
+ * Otherwise a regular shift selection is performed.
+ * @param hitItem - specifies the clicked item
+ * @param hitItemIndex - specifies the index of the clicked item
+ * relative to the first item.
+ */
+void ctrlShiftSelect(SelectableItem hitItem, int hitItemIndex) {
+ int fromIndex = -1;
+ int toIndex = -1;
+ int lastSelectionIndex = -1;
+ int selectionRange[];
+ SelectableItem lastSelection = getLastSelection();
+
+ if (lastSelection != null) {
+ lastSelectionIndex = getVisibleIndex(lastSelection);
+ }
+ if ((getSelectionVector().contains(hitItem) == true) && // clicked an already selected item?
+ (hitItemIndex != lastSelectionIndex)) { // and click was not on last selected item?
+ setLastSelection(hitItem, true); // set last selection which also sets the focus
+ }
+ else
+ if (isCtrlSelection() == true) { // was last selection ctrl/ctrl+shift selection?
+ fromIndex = lastSelectionIndex; // select from last selection
+ toIndex = hitItemIndex;
+ }
+ else { // clicked outside existing selection range
+ selectionRange = calculateShiftSelectionRange(hitItemIndex);
+ fromIndex = selectionRange[0];
+ toIndex = selectionRange[1];
+ }
+ if (fromIndex != -1 && toIndex != -1) {
+ selectRange(fromIndex, toIndex);
+ }
+}
+/**
+ * Deselect 'item'.
+ * @param item - item that should be deselected
+ */
+void deselect(SelectableItem item) {
+ Vector selectedItems = getSelectionVector();
+
+ if ((item != null) && (item.isSelected() == true)) {
+ item.setSelected(false);
+ redrawSelection(item);
+ selectedItems.removeElement(item);
+ }
+}
+/**
+ * Deselect all item except 'keepSelected'.
+ * @param keepSelected - item that should remain selected
+ */
+void deselectAllExcept(SelectableItem keepSelected) {
+ Vector selectedItems = getSelectionVector();
+ Vector deselectedItems = new Vector(selectedItems.size());
+ Enumeration elements = selectedItems.elements();
+ SelectableItem item;
+
+ // deselect and repaint previously selected items
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ if (item.isSelected() == true && item != keepSelected) {
+ item.setSelected(false);
+ // always redraw the selection, even if item is redrawn again
+ // in setLastSelection. Fixes 1G0GQ8W
+ redrawSelection(item);
+ deselectedItems.addElement(item);
+ }
+ }
+ elements = deselectedItems.elements();
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ selectedItems.removeElement(item);
+ }
+ setLastSelection(keepSelected, false);
+}
+/**
+ * Deselect all items except those in 'keepSelected'.
+ * @param keepSelected - items that should remain selected
+ */
+void deselectAllExcept(Vector keepSelected) {
+ Vector selectedItems = getSelectionVector();
+ Vector deselectedItems = new Vector(selectedItems.size());
+ Enumeration elements = selectedItems.elements();
+ SelectableItem item;
+
+ // deselect and repaint previously selected items
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ if (item.isSelected() == true && keepSelected.contains(item) == false) {
+ item.setSelected(false);
+ // always redraw the selection, even if item is redrawn again
+ // in setLastSelection. Fixes 1G0GQ8W
+ redrawSelection(item);
+ deselectedItems.addElement(item);
+ }
+ }
+ elements = deselectedItems.elements();
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ selectedItems.removeElement(item);
+ }
+ if (keepSelected.size() > 0) {
+ setLastSelection((SelectableItem) keepSelected.firstElement(), false);
+ }
+}
+/**
+ * Deselect 'item'. Notify listeners.
+ * @param item - item that should be deselected
+ */
+void deselectNotify(SelectableItem item) {
+ Event event = new Event();
+
+ if (item.isSelected() == true) {
+ deselect(item);
+ setLastSelection(item, true);
+ update(); // looks better when event notification takes long to return
+ }
+ event.item = item;
+ notifyListeners(SWT.Selection, event);
+}
+/**
+ * Deselect all items starting at and including 'fromIndex'
+ * stopping at and including 'toIndex'.
+ * @param fromIndex - index relative to the first item where
+ * deselection should start. Deselecion includes 'fromIndex'.
+ * @param toIndex - index relative to the first item where
+ * deselection should stop. Deselecion includes 'toIndex'.
+ */
+void deselectRange(int fromIndex, int toIndex) {
+ if (fromIndex > toIndex) {
+ for (int i = toIndex; i <= fromIndex; i++) {
+ deselect(getVisibleItem(i));
+ }
+ }
+ else
+ if (fromIndex < toIndex) {
+ for (int i = toIndex; i >= fromIndex; i--) {
+ deselect(getVisibleItem(i));
+ }
+ }
+ setLastSelection(getVisibleItem(fromIndex), true);
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection down one item
+ * Ctrl Keep old selection, move input focus down one item
+ * Shift Extend selection by one item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowDown(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+
+ if (focusItemIndex < (getVisibleItemCount() - 1)) { // - 1 because indices are 0 based
+ focusItemIndex++;
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Scroll receiver to the left
+ * Ctrl See None above
+ * Shift See None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowLeft(int keyMask) {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int scrollSelection = horizontalBar.getSelection();
+ int scrollAmount;
+
+ if (horizontalBar.getVisible() == false) {
+ return;
+ }
+ scrollAmount = Math.min(HORIZONTAL_SCROLL_INCREMENT, scrollSelection);
+ horizontalBar.setSelection(scrollSelection - scrollAmount);
+ setHorizontalOffset(horizontalBar.getSelection() * -1);
+}
+/**
+ * Modifier Key Action
+ * None Scroll receiver to the right
+ * Ctrl See None above
+ * Shift See None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowRight(int keyMask) {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int scrollSelection = horizontalBar.getSelection();
+ int scrollAmount;
+
+ if (horizontalBar.getVisible() == false) {
+ return;
+ }
+ scrollAmount = Math.min( // scroll by the smaller of
+ HORIZONTAL_SCROLL_INCREMENT, // the scroll increment
+ horizontalBar.getMaximum() // and the remaining scroll range
+ - horizontalBar.getPageIncrement()
+ - scrollSelection);
+ horizontalBar.setSelection(scrollSelection + scrollAmount);
+ setHorizontalOffset(horizontalBar.getSelection() * -1);
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection up one item
+ * Ctrl Keep old selection, move input focus up one item
+ * Shift Extend selection by one item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowUp(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+
+ if (focusItemIndex > 0) {
+ focusItemIndex--;
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Perform a selection operation on the item check box.
+ * @param item - the item that was clicked
+ */
+void doCheckItem(SelectableItem item) {
+ Event event = new Event();
+
+ item.setChecked(!item.getChecked());
+ event.item = item;
+ event.detail = SWT.CHECK;
+ notifyListeners(SWT.Selection, event);
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ setRemovingAll(true);
+ getSelectionVector().removeAllElements();
+ lastFocusItem = null;
+ lastSelectedItem = null;
+ if (uncheckedImage != null) {
+ uncheckedImage.dispose();
+ }
+ if (grayUncheckedImage != null) {
+ grayUncheckedImage.dispose();
+ }
+ if (checkMarkImage != null) {
+ checkMarkImage.dispose();
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection to the
+ * last item
+ * Ctrl Keep old selection, move input focus to the
+ * last item
+ * Shift Extend selection to the last item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doEnd(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+ int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
+
+ if (focusItemIndex < lastItemIndex) {
+ newFocus = getVisibleItem(lastItemIndex);
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, lastItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection to the
+ * first item
+ * Ctrl Keep old selection, move input focus to the
+ * first item
+ * Shift Extend selection to the first item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doHome(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int firstItemIndex = 0;
+
+ if (getVisibleIndex(lastFocus) > firstItemIndex) {
+ newFocus = getVisibleItem(firstItemIndex);
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, firstItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Perform a mouse select action according to the key state
+ * mask in 'eventStateMask'.
+ * Key state mask is ignored when receiver has the single selection
+ * style.
+ * @param item - the item that was clicked
+ * @param itemIndex - the index of the clicked item relative
+ * to the first item of the receiver
+ * @param eventStateMask - the key state mask of the mouse event
+ * @param button - the mouse button that was pressed
+ */
+void doMouseSelect(SelectableItem item, int itemIndex, int eventStateMask, int button) {
+ if (((eventStateMask & SWT.CTRL) != 0) &&
+ ((eventStateMask & SWT.SHIFT) != 0) &&
+ (isMultiSelect() == true)) {
+ if (getSelectionVector().size() == 0) { // no old selection?
+ selectNotify(item); // do standard CTRL selection
+ }
+ else {
+ ctrlShiftSelect(item, itemIndex);
+ }
+ setCtrlSelection(true);
+ }
+ else
+ if (((eventStateMask & SWT.SHIFT) != 0) && (isMultiSelect() == true)) {
+ shiftSelect(item, itemIndex);
+ setCtrlSelection(false);
+ }
+ else
+ if (((eventStateMask & SWT.CTRL) != 0) && (isMultiSelect() == true)) {
+ toggleSelectionNotify(item);
+ setCtrlSelection(true);
+ }
+ else
+ if (button != 3 || item.isSelected() == false) {
+ // only select the item (and deselect all others) if the mouse click is
+ // not a button 3 click or if a previously unselected item was clicked.
+ // Fixes 1G97L65
+ deselectAllExcept(item);
+ selectNotify(item);
+ setCtrlSelection(false);
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection one page down
+ * Ctrl Keep old selection, move input focus one page down
+ * Shift Extend selection one page down
+ * One page is the number of items that can be displayed in the
+ * receiver's canvas without truncating the last item.
+ * The selection is set to the last item if there is no full page
+ * of items left.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doPageDown(int keyMask) {
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(getLastFocus());
+ int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
+ int visibleItemCount;
+
+ if (focusItemIndex < lastItemIndex) {
+ visibleItemCount = getItemCountWhole();
+ focusItemIndex = Math.min(
+ lastItemIndex,
+ focusItemIndex + (visibleItemCount - 1));
+ newFocus = getVisibleItem(focusItemIndex);
+ if (newFocus == null) {
+ return;
+ }
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection one page up
+ * Ctrl Keep old selection, move input focus one page up
+ * Shift Extend selection one page up
+ * One page is the number of items that can be displayed in the
+ * receiver's canvas without truncating the last item.
+ * The selection is set to the first item if there is no full page
+ * of items left.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doPageUp(int keyMask) {
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(getLastFocus());
+ int visibleItemCount;
+
+ if (focusItemIndex > 0) {
+ visibleItemCount = getItemCountWhole();
+ focusItemIndex = Math.max(
+ 0,
+ focusItemIndex - (visibleItemCount - 1));
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.CTRL && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.SHIFT && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * Ctrl Keep old selection, toggle selection of the item
+ * that has the input focus
+ * Shift Extend selection to the item that has the input
+ * focus
+ * Ctrl & Shift Set selection to the item that has input focus
+ * Do nothing if receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+
+void doSpace(int keyMask) {
+ SelectableItem item = getLastFocus();
+ int itemIndex = getVisibleIndex(item);
+
+ if (keyMask == SWT.NULL && item.isSelected() == false) { // do simple space select in SINGLE and MULTI mode
+ deselectAllExcept(item);
+ selectNotify(item);
+ return;
+ }
+ if (isMultiSelect() == false || item == null) {
+ return;
+ }
+ if (keyMask == SWT.CTRL) {
+ toggleSelectionNotify(item);
+ }
+ else
+ if (((keyMask & SWT.CTRL) != 0) && ((keyMask & SWT.SHIFT) != 0)) {
+ deselectAllExcept(item);
+ selectNotify(item);
+ }
+ else
+ if (keyMask == SWT.SHIFT) {
+ shiftSelect(item, itemIndex);
+ }
+}
+/**
+ * Make sure that free space at the bottom of the receiver is
+ * occupied.
+ * There will be new space available below the last item when the
+ * receiver's height is increased. In this case the receiver
+ * is scrolled down to occupy the new space.if the top item is
+ * not the first item of the receiver.
+ */
+void claimBottomFreeSpace() {
+ int clientAreaItemCount = getItemCountWhole();
+ int topIndex = getTopIndex();
+ int newTopIndex;
+ int lastItemIndex = getVisibleItemCount() - topIndex;
+
+ if ((topIndex > 0) &&
+ (lastItemIndex > 0) &&
+ (lastItemIndex < clientAreaItemCount)) {
+ newTopIndex = Math.max(0, topIndex-(clientAreaItemCount-lastItemIndex));
+ setTopIndex(newTopIndex, true);
+ }
+}
+/**
+ * Make sure that free space at the right side of the receiver is
+ * occupied.
+ * There will be new space available at the right side of the receiver
+ * when the receiver's width is increased. In this case the receiver
+ * is scrolled to the right to occupy the new space.if possible.
+ */
+void claimRightFreeSpace() {
+ int clientAreaWidth = getClientArea().width;
+ int newHorizontalOffset = clientAreaWidth - getContentWidth();
+
+ if (newHorizontalOffset - getHorizontalOffset() > 0) { // item is no longer drawn past the right border of the client area
+ newHorizontalOffset = Math.min(0, newHorizontalOffset); // align the right end of the item with the right border of the
+ setHorizontalOffset(newHorizontalOffset); // client area (window is scrolled right)
+ }
+}
+/** Not used right now. Replace focusIn/focusOut with this method once
+ * Display.getFocusWindow returns the new focus window on FocusOut event
+ * (see 1FMITIE)
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusChange(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusIn(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ // Workaround for 1FMITIE
+ hasFocus = true;
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+ // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
+ update();
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusOut(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ // Workaround for 1FMITIE
+ hasFocus = false;
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+ // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
+ update();
+}
+/**
+ * Answer the index of the last item position in the receiver's
+ * client area.
+ * @return 0-based index of the last item position in the tree's
+ * client area.
+ */
+int getBottomIndex() {
+ return getTopIndex() + getItemCountTruncated(getClientArea());
+}
+/**
+ * Answer the size of the check box image.
+ * The calculation is cached and assumes that the images for
+ * the checked and unchecked state are the same size.
+ */
+Point getCheckBoxExtent() {
+ Image checkedImage;
+ Rectangle imageBounds;
+
+ if (checkBoxExtent == null) {
+ checkedImage = getUncheckedImage();
+ if (checkedImage != null) {
+ imageBounds = checkedImage.getBounds();
+ checkBoxExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ else {
+ checkBoxExtent = new Point(0, 0);
+ }
+ }
+ return checkBoxExtent;
+}
+/**
+ * Answer the image for the selected check box
+ * Answer null if the image couldn't be loaded.
+ */
+Image getCheckMarkImage() {
+ InputStream resourceStream;
+
+ if (checkMarkImage == null) {
+ checkMarkImage = new Image(getDisplay(), CheckMarkImageData);
+ }
+ return checkMarkImage;
+}
+/**
+ * Answer the width of the receiver's content.
+ * Needs to be set by subclasses.
+ */
+int getContentWidth() {
+ return contentWidth;
+}
+/**
+ * Answer the horizontal drawing offset used for scrolling.
+ * This is < 0 if the receiver has been scrolled to the left,
+ * > 0 if the receiver has been scrolled to the right and 0
+ * if the receiver has not been scrolled.
+ */
+int getHorizontalOffset() {
+ return horizontalOffset;
+}
+
+/**
+ * Answer the size of item images. Calculated during the item
+ * height calculation.
+ */
+Point getImageExtent() {
+ return itemImageExtent;
+}
+/**
+ * Answer the image extent of 'item'. Overridden by subclasses.
+ */
+Point getImageExtent(SelectableItem item) {
+ Image image = item.getImage();
+ Rectangle imageBounds;
+ Point imageExtent = null;
+
+ if (image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+abstract int getIndex(SelectableItem item);
+/**
+ * Answer the first and last index of items that can be displayed in
+ * the area defined by 'clipRectangle'. This includes partial items.
+ * @return
+ * Array -
+ * First element is the index of the first item in 'clipRectangle'.
+ * Second element is the index of the last item in 'clipRectangle'.
+ */
+int[] getIndexRange(Rectangle clipRectangle) {
+ int visibleRange[] = new int[] {0, 0};
+
+ visibleRange[0] = clipRectangle.y / getItemHeight();
+ visibleRange[1] =
+ visibleRange[0] +
+ getItemCountTruncated(clipRectangle) - 1; // - 1 because item index is 0 based
+ return visibleRange;
+}
+/**
+ * Return the item that draws the marker indicating the insert location
+ * in a drag and drop operation
+ */
+SelectableItem getInsertItem() {
+ return insertItem;
+}
+/**
+ * Answer the number of items in the receiver.
+ */
+public abstract int getItemCount();
+/**
+ * Answer the number of items that can be displayed in 'rectangle'.
+ * The result includes partially visible items.
+ */
+int getItemCountTruncated(Rectangle rectangle) {
+ int itemHeight = getItemHeight();
+ int itemCount = 0;
+ int startIndex;
+
+ startIndex = rectangle.y / itemHeight;
+ itemCount = (int) Math.ceil(((float) rectangle.y + rectangle.height) / itemHeight)-startIndex;
+ return itemCount;
+}
+/**
+ * Answer the number of items that can be displayed in the client
+ * area of the receiver.
+ * The result only includes items that completely fit into the
+ * client area.
+ */
+int getItemCountWhole() {
+ return getClientArea().height / getItemHeight();
+}
+/**
+ * Answer the height of an item in the receiver.
+ * The item height is the greater of the item icon height and
+ * text height of the first item that has text or an image
+ * respectively.
+ * Calculate a default item height based on the font height if
+ * no item height has been calculated yet.
+ */
+public int getItemHeight() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ GC gc;
+ if (itemHeight == 0) {
+ gc = new GC(this);
+ itemHeight = gc.stringExtent("String").y + getItemPadding(); // initial item height=font height + item spacing
+ // use real font height here when available in SWT, instead of GC.textExtent
+ gc.dispose();
+ }
+ return itemHeight;
+}
+/**
+ * Answer the number of pixels that should be added to the item height.
+ */
+int getItemPadding() {
+ return 2 + getDisplay().textHighlightThickness;
+}
+/**
+ * Answer the item that most recently received the input focus.
+ */
+SelectableItem getLastFocus() {
+ return lastFocusItem;
+}
+/**
+ * Answer the item that was selected most recently.
+ */
+SelectableItem getLastSelection() {
+ return lastSelectedItem;
+}
+/**
+ * Answer the event listener used for all events. Events are
+ * dispatched to handler methods in handleEvents(Event).
+ * This scheme saves a lot of inner classes.
+ */
+Listener getListener() {
+ return listener;
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is not an item of the receiver
+ */
+int getRedrawY(SelectableItem item) {
+ int redrawIndex = getVisibleIndex(item);
+ int redrawY = -1;
+
+ if (redrawIndex != -1) {
+ redrawY = (redrawIndex - getTopIndex()) * getItemHeight();
+ }
+ return redrawY;
+}
+/**
+ * Answer the number of selected items in the receiver.
+ */
+public int getSelectionCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getSelectionVector().size();
+}
+/**
+ * Answer the selected items of the receiver.
+ * @return The selected items of the receiver stored in a Vector.
+ * Returned Vector is empty if no items are selected.
+ */
+Vector getSelectionVector() {
+ return selectedItems;
+}
+/**
+ * Answer the width of 'text' in pixel.
+ * Answer 0 if 'text' is null.
+ */
+int getTextWidth(String text) {
+ int textWidth = 0;
+ GC gc;
+
+ if (text != null) {
+ gc = new GC(this);
+ textWidth = gc.stringExtent(text).x;
+ gc.dispose();
+ }
+ return textWidth;
+}
+/**
+ * Answer the index of the first visible item in the receiver's
+ * client area.
+ * @return 0-based index of the first visible item in the
+ * receiver's client area.
+ */
+int getTopIndex() {
+ return topIndex;
+}
+/**
+ * Answer the image for the deselected check box.
+ */
+Image getUncheckedImage() {
+ InputStream resourceStream;
+
+ if (uncheckedImage == null) {
+ uncheckedImage = new Image(getDisplay(), UncheckedImageData);
+ }
+ return uncheckedImage;
+}
+
+/**
+ * Answer the image for the grayed eck box.
+ */
+Image getGrayUncheckedImage() {
+ InputStream resourceStream;
+
+ if (grayUncheckedImage == null) {
+ grayUncheckedImage = new Image(getDisplay(), GrayUncheckedImageData);
+ }
+ return grayUncheckedImage;
+}
+
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Normally, every item of the receiver is visible.
+ */
+abstract int getVisibleIndex(SelectableItem item);
+/**
+ * Answer the SelectableItem located at 'itemIndex' in the
+ * receiver.
+ * @param itemIndex - location of the SelectableItem object
+ * to return
+ */
+abstract SelectableItem getVisibleItem(int itemIndex);
+/**
+ * Answer the number of visible items of the receiver.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Normally every item of the receiver is visible.
+ */
+int getVisibleItemCount() {
+ return getItemCount();
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+abstract int getVisibleRedrawY(SelectableItem item);
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.Dispose:
+ doDispose();
+ break;
+ case SWT.KeyDown:
+ keyDown(event);
+ break;
+ case SWT.Resize:
+ resize(event);
+ break;
+ case SWT.Selection:
+ if (event.widget == getVerticalBar()) {
+ scrollVertical(event);
+ }
+ else
+ if (event.widget == getHorizontalBar()) {
+ scrollHorizontal(event);
+ }
+ break;
+ case SWT.FocusOut:
+ focusOut(event);
+ break;
+ case SWT.FocusIn:
+ focusIn(event);
+ break;
+ }
+}
+
+
+
+/**
+ * Answer whether 'item' has the input focus.
+ */
+boolean hasFocus(SelectableItem item) {
+ return (isFocusControl() && item == getLastFocus());
+}
+/**
+ * Initialize the receiver. Add event listeners and set widget
+ * colors.
+ */
+void initialize() {
+ Display display = getDisplay();
+ ScrollBar horizontalBar = getHorizontalBar();
+ ScrollBar verticalBar = getVerticalBar();
+
+ // listener may be needed by overridden installListeners()
+ listener = new Listener() {
+ public void handleEvent(Event event) {handleEvents(event);}
+ };
+ setSelectionVector(new Vector());
+ installListeners();
+ calculateVerticalScrollbar();
+ calculateHorizontalScrollbar();
+ horizontalBar.setMinimum(0);
+ verticalBar.setMinimum(0);
+ horizontalBar.setIncrement(HORIZONTAL_SCROLL_INCREMENT);
+ setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
+ setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+}
+/**
+ * Initialize the ImageData used for the checked/unchecked images.
+ */
+static void initializeImageData() {
+ PaletteData uncheckedPalette = new PaletteData(
+ new RGB[] {new RGB(128, 128, 128), new RGB(255, 255, 255)});
+ PaletteData grayUncheckedPalette = new PaletteData(
+ new RGB[] {new RGB(128, 128, 128), new RGB(192, 192, 192)});
+ PaletteData checkMarkPalette = new PaletteData(
+ new RGB[] {new RGB(0, 0, 0), new RGB(252, 3, 251)});
+ byte[] checkbox = new byte[] {0, 0, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 0, 0};
+
+ // Each pixel is represented by one bit in the byte data.
+ // The bit references the palette position (0 or 1). Each pixel row of an image is padded to one byte.
+ // Arguments: width, height, depth, palette, scanline padding, data
+ UncheckedImageData = new ImageData(11, 11, 1, uncheckedPalette, 2, checkbox);
+ GrayUncheckedImageData = new ImageData(11, 11, 1, grayUncheckedPalette, 2, checkbox);
+ CheckMarkImageData = new ImageData(7, 7, 1, checkMarkPalette, 1, new byte[] {-4, -8, 112, 34, 6, -114, -34});
+ CheckMarkImageData.transparentPixel = 1;
+}
+/**
+ * Add event listeners to the tree widget and its scroll bars.
+ */
+void installListeners() {
+ Listener listener = getListener();
+
+ addListener(SWT.Dispose, listener);
+ addListener(SWT.Resize, listener);
+ addListener(SWT.KeyDown, listener);
+ addListener(SWT.FocusOut, listener);
+ addListener(SWT.FocusIn, listener);
+
+ getVerticalBar().addListener(SWT.Selection, listener);
+ getHorizontalBar().addListener(SWT.Selection, listener);
+}
+/**
+ * Answer whether the currently selected items were selected
+ * using the ctrl key.
+ */
+boolean isCtrlSelection() {
+ return isCtrlSelection;
+}
+/**
+ * Answer true if all items in the widget are disposed.
+ * Used to optimize item disposal. Prevents unnecessary screen
+ * updates.
+ */
+boolean isRemovingAll() {
+ return isRemovingAll;
+}
+/**
+ * Answer whether the receiver has the input focus.
+ * Workaround for 1FMITIE
+ */
+public boolean isFocusControl() {
+ return hasFocus;
+}
+/**
+ * Return whether the drop insert position is before or after the
+ * item set using motif_setInsertMark.
+ * @return
+ * true=insert position is after the insert item
+ * false=insert position is before the insert item
+ */
+boolean isInsertAfter() {
+ return isInsertAfter;
+}
+/**
+ * Answer whether the receiver has the MULTI selection style set.
+ * @return
+ * true = receiver is in multiple selection mode.
+ * false = receiver is in single selection mode.
+ */
+boolean isMultiSelect() {
+ return ((getStyle() & SWT.MULTI) != 0);
+}
+/**
+ * The item identified by 'changedItem' has changed.
+ * Calculate the item height based on the new item data (it might
+ * now have an image which could also be the first image in the
+ * receiver)
+ * Redraw the whole window if the item height has changed. Otherwise
+ * redraw only the changed item or part of it depending on the
+ * 'repaintStartX' and 'repaintWidth' parameters.
+ * @param changedItem - the item that has changed
+ * @param repaintStartX - x position of the item redraw.
+ * @param repaintWidth - width of the item redraw.
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ int yPosition;
+ int itemHeight;
+ int oldItemHeight = getItemHeight();
+ Point oldImageExtent = getImageExtent();
+
+ calculateItemHeight(changedItem); // make sure that the item height is recalculated
+ // no redraw necessary if redraw width is 0 or item is not visible
+ if (repaintWidth == 0 || (yPosition = getVisibleRedrawY(changedItem)) == -1) {
+ return;
+ } // if changedItem is the first item with image.
+ itemHeight = getItemHeight();
+ if ((oldItemHeight == itemHeight) && // only redraw changed item if the item height and
+ (oldImageExtent == getImageExtent())) { // image size has not changed. The latter will only change once,
+ // from null to a value-so it's safe to test using !=
+ // redrawing outside the client area redraws the widget border on Motif.
+ // adjust the redraw width if necessary. Workaround for 1G4TQRW
+ repaintWidth = Math.min(repaintWidth, getClientArea().width - repaintStartX);
+ if (repaintWidth > 0) {
+ redraw(repaintStartX, yPosition, repaintWidth, itemHeight, true);
+ }
+ }
+ else {
+ redraw(); // redraw all items if the item height has changed
+ }
+}
+/**
+ * A key was pressed. Call the appropriate handler method.
+ * @param event - the key event
+ */
+void keyDown(Event event) {
+ boolean isCtrlSelection = isCtrlSelection();
+
+ if (event.stateMask != SWT.CTRL) {
+ isCtrlSelection = false;
+ }
+ switch (event.keyCode) {
+ case SWT.ARROW_UP:
+ doArrowUp(event.stateMask);
+ break;
+ case SWT.ARROW_DOWN:
+ doArrowDown(event.stateMask);
+ break;
+ case SWT.ARROW_LEFT:
+ doArrowLeft(event.stateMask);
+ break;
+ case SWT.ARROW_RIGHT:
+ doArrowRight(event.stateMask);
+ break;
+ case SWT.PAGE_UP:
+ doPageUp(event.stateMask);
+ break;
+ case SWT.PAGE_DOWN:
+ doPageDown(event.stateMask);
+ break;
+ case SWT.HOME:
+ doHome(event.stateMask);
+ break;
+ case SWT.END:
+ doEnd(event.stateMask);
+ break;
+ default: // no selection occurred, keep previous
+ isCtrlSelection = isCtrlSelection(); // selection type information
+ }
+ if (event.character == ' ') {
+ doSpace(event.stateMask);
+ isCtrlSelection = (event.stateMask == SWT.CTRL);
+ }
+ setCtrlSelection(isCtrlSelection);
+}
+/**
+ * Sets the drop insert item.
+ * The drop insert item has a visual hint to show where a dragged item
+ * will be inserted when dropped on the tree.
+ * <p>
+ * @param item the insert item
+ * @param after true places the insert mark below 'item'. false places
+ * the insert mark above 'item'.
+ */
+void motif_setInsertMark(SelectableItem item, boolean after) {
+ SelectableItem currentItem = getInsertItem();
+ int redrawY;
+
+ setInsertItem(item);
+ setInsertAfter(after);
+ if (currentItem != null) {
+ redrawY = getVisibleRedrawY(currentItem);
+ if (redrawY != -1) {
+ currentItem.redrawInsertMark(redrawY);
+ }
+ }
+ if (item != null) {
+ redrawY = getVisibleRedrawY(item);
+ if (redrawY != -1) {
+ item.redrawInsertMark(redrawY);
+ }
+ }
+}
+
+
+/**
+ * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
+ * set to false.
+ */
+public void redraw () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (drawCount == 0) {
+ super.redraw();
+ }
+}
+/**
+ * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
+ * set to false.
+ */
+public void redraw (int x, int y, int width, int height, boolean all) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (drawCount == 0) {
+ super.redraw(x, y, width, height, all);
+ }
+}
+
+/**
+ * Redraw the selection of 'item'
+ * @param item - SelectableItem that should have the selection redrawn.
+ */
+void redrawSelection(SelectableItem item) {
+ int redrawPosition = getVisibleRedrawY(item);
+
+ if (redrawPosition != -1) {
+ item.redrawSelection(redrawPosition);
+ }
+}
+/**
+ * 'item' has been removed from the receiver.
+ * Update the display and the scroll bars.
+ */
+void removedItem(SelectableItem item) {
+ claimBottomFreeSpace();
+ calculateVerticalScrollbar();
+ if (getItemCount() == 0) {
+ reset();
+ }
+}
+/**
+ * 'item' is about to be removed from the tree.
+ * Move the selection/input focus if 'item' is selected or has the
+ * input focus,
+ * @param item - item that is about to be removed from the tree.
+ */
+void removingItem(SelectableItem item) {
+ SelectableItem nextFocusItem = null;
+ int itemIndex = getVisibleIndex(item);
+ int itemCount = getVisibleItemCount();
+
+ // deselect item and remove from selection
+ if (item.isSelected() == true) {
+ getSelectionVector().removeElement(item);
+ }
+ if (item == getLastFocus() && itemCount > 1) {
+ // select previous item if removed item is bottom item
+ // otherwise select next item. Fixes 1GA6L85
+ if (itemIndex == itemCount - 1) {
+ nextFocusItem = getVisibleItem(itemIndex - 1);
+ }
+ else {
+ nextFocusItem = getVisibleItem(itemIndex + 1);
+ }
+ setLastFocus(nextFocusItem, true);
+ }
+ // ignore items below widget client area
+ if (itemIndex != -1 && itemIndex <= getBottomIndex()) {
+ scrollVerticalRemovedItem(itemIndex);
+ }
+}
+/**
+ * Reset state that is dependent on or calculated from the state
+ * of the receiver.
+ */
+void reset() {
+ setSelectionVector(new Vector());
+ setTopIndexNoScroll(0, true);
+ lastSelectedItem = null;
+ lastFocusItem = null;
+ resetItemData();
+}
+/**
+ * Reset state that is dependent on or calculated from the items
+ * of the receiver.
+ */
+void resetItemData() {
+ setHorizontalOffset(0);
+ setItemHeight(0);
+ itemImageExtent = null;
+ textHeight = -1;
+ claimRightFreeSpace();
+}
+/**
+ * The receiver has been resized. Update the scroll bars and
+ * make sure that new space is being occupied by items.
+ */
+void resize(Event event) {
+ int horizontalPageSize = getHorizontalBar().getPageIncrement();
+
+ resizeHorizontalScrollbar();
+ resizeVerticalScrollbar();
+ if (getClientArea().width > horizontalPageSize) { // window resized wider? - Do this check here
+ claimRightFreeSpace(); // because claimRightFreeSpace is called elsewhere.
+ }
+ claimBottomFreeSpace();
+}
+/**
+ * Display the horizontal scroll bar if items are drawn off
+ * screen. Update the page size.
+ */
+void resizeHorizontalScrollbar() {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int clientAreaWidth = getClientArea().width;
+
+ if (clientAreaWidth < getContentWidth()) {
+ if (horizontalBar.getVisible() == false) {
+ horizontalBar.setVisible(true);
+ horizontalBar.setSelection(0);
+ }
+ }
+ else
+ if (horizontalBar.getVisible() == true) {
+ horizontalBar.setVisible(false);
+ }
+ horizontalBar.setThumb(clientAreaWidth);
+ horizontalBar.setPageIncrement(clientAreaWidth);
+}
+/**
+ * Display the vertical scroll bar if items are drawn off screen.
+ * Update the page size.
+ */
+void resizeVerticalScrollbar() {
+ int clientAreaItemCount = getItemCountWhole();
+ ScrollBar verticalBar = getVerticalBar();
+
+ if (clientAreaItemCount == 0) {
+ return;
+ }
+ if (clientAreaItemCount < getVisibleItemCount()) {
+ if (verticalBar.getVisible() == false) {
+ verticalBar.setVisible(true);
+ }
+ // Only set the page size to something smaller than the scroll
+ // range maximum. Otherwise the scroll selection will be reset.
+ verticalBar.setPageIncrement(clientAreaItemCount);
+ verticalBar.setThumb(clientAreaItemCount);
+ }
+ else
+ if (verticalBar.getVisible() == true) {
+ verticalBar.setVisible(false);
+ }
+}
+/**
+ * Scroll the rectangle specified by x, y, width, height to the destination
+ * position. Do nothing if redraw is set to false using setRedraw().
+ *
+ * @param destX - destination x position of the scrolled rectangle
+ * @param destY - destination y position of the scrolled rectangle
+ * @param x - x location of the upper left corner of the scroll rectangle
+ * @param y - y location of the upper left corner of the scroll rectangle
+ * @param width - width of the scroll rectangle
+ * @param height - height of the scroll rectangle
+ * @param all - not used. Used to be true=scroll children intersecting the
+ * scroll rectangle.
+ */
+void scroll(int destX, int destY, int x, int y, int width, int height, boolean all) {
+ if (drawCount == 0) {
+ update();
+ GC gc = new GC(this);
+ gc.copyArea(x, y, width, height, destX, destY);
+ gc.dispose();
+ }
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * numPixel > 0 = scroll to left. numPixel < 0 = scroll to right
+ */
+abstract void scrollHorizontal(int numPixel);
+/**
+ * The position of the horizontal scroll bar has been modified
+ * by the user.
+ * Adjust the horizontal offset to trigger a horizontal scroll.
+ * @param event-the scroll event
+ */
+void scrollHorizontal(Event event) {
+ setHorizontalOffset(getHorizontalBar().getSelection() * -1);
+}
+/**
+ * Scroll 'item' into the receiver's client area if necessary.
+ * @param item - the item that should be scrolled.
+ */
+void scrollShowItem(SelectableItem item) {
+ int itemIndexFromTop = getIndex(item) - getTopIndex();
+ int clientAreaWholeItemCount = getItemCountWhole();
+ int scrollAmount = 0;
+
+ if (itemIndexFromTop >= clientAreaWholeItemCount) { // show item below visible items?
+ scrollAmount = itemIndexFromTop;
+ if (clientAreaWholeItemCount > 0) { // will be 0 if showItem is called and receiver hasn't been displayed yet
+ scrollAmount -= clientAreaWholeItemCount - 1;
+ }
+ }
+ else
+ if (itemIndexFromTop < 0) { // show item above visible items?
+ scrollAmount = itemIndexFromTop;
+ }
+ setTopIndex(getTopIndex() + scrollAmount, true);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+abstract void scrollVertical(int scrollIndexCount);
+/**
+ * The position of the horizontal scroll bar has been modified
+ * by the user.
+ * Adjust the index of the top item to trigger a vertical scroll.
+ * @param event-the scroll event
+ */
+void scrollVertical(Event event) {
+ setTopIndex(getVerticalBar().getSelection(), false);
+}
+/**
+ * Scroll items down to make space for a new item added to
+ * the receiver at position 'index'.
+ * @param index - position at which space for one new item
+ * should be made. This index is relative to the first item
+ * of the receiver.
+ */
+void scrollVerticalAddingItem(int index) {
+ Rectangle clientArea = getClientArea();
+ int itemHeight = getItemHeight();
+ int sourceY = Math.max(0, (index - getTopIndex()) * itemHeight); // need to scroll in visible area
+
+ scroll(
+ 0, sourceY + itemHeight, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll the items below the item at position 'index' up
+ * so that they cover the removed item.
+ * @param index - index of the removed item
+ */
+void scrollVerticalRemovedItem(int index) {
+ Rectangle clientArea = getClientArea();
+ int itemHeight = getItemHeight();
+ int destinationY = Math.max(0, (index - getTopIndex()) * itemHeight);
+
+ scroll(
+ 0, destinationY, // destination x, y
+ 0, destinationY + itemHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Select 'item' if it is not selected.
+ * @param item - item that should be selected
+ */
+void select(SelectableItem item) {
+ Vector selectedItems = getSelectionVector();
+
+ if (item != null && item.isSelected() == false && isRemovingAll() == false) {
+ item.setSelected(true);
+ redrawSelection(item);
+ selectedItems.addElement(item);
+ }
+}
+/**
+ * Select 'item' if it is not selected. Send a Selection event
+ * if the selection was changed.
+ * @param item - item that should be selected
+ */
+void selectNotify(SelectableItem item) {
+ Event event;
+
+ if (isRemovingAll() == false) {
+ if (item.isSelected() == false) {
+ select(item);
+ setLastSelection(item, true);
+ update(); // looks better when event notification takes long to return
+ }
+ event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Selection, event);
+ }
+}
+/**
+ * Select all items of the receiver starting at 'fromIndex'
+ * and including 'toIndex'.
+ */
+void selectRange(int fromIndex, int toIndex) {
+ if (fromIndex > toIndex) {
+ for (int i = fromIndex; i > toIndex; i--) {
+ select(getVisibleItem(i));
+ }
+ }
+ else {
+ for (int i = fromIndex; i < toIndex; i++) {
+ select(getVisibleItem(i));
+ }
+ }
+ selectNotify(getVisibleItem(toIndex)); // select last item, notifying listeners
+}
+/**
+ * Set the width of the receiver's contents to 'newWidth'.
+ * Content width is used to calculate the horizontal scrollbar.
+ */
+void setContentWidth(int newWidth) {
+ ScrollBar horizontalBar;
+ boolean scrollBarVisible;
+
+ if (contentWidth != newWidth) {
+ horizontalBar = getHorizontalBar();
+ scrollBarVisible = horizontalBar.getVisible();
+ contentWidth = newWidth;
+ calculateHorizontalScrollbar();
+ if (scrollBarVisible != horizontalBar.getVisible()) {
+ resizeVerticalScrollbar(); // the vertical scroll bar needs to be resized if the horizontal
+ } // scroll bar was hidden or made visible during recalculation
+ }
+}
+/**
+ * Set whether the currently selected items were selected using the
+ * ctrl key.
+ * @param isCtrlSelection -
+ * true = currently selected items were selected using the ctrl key.
+ * false = currently selected items were not selected using the
+ * ctrl key.
+ */
+void setCtrlSelection(boolean isCtrlSelection) {
+ this.isCtrlSelection = isCtrlSelection;
+}
+/**
+ * The font is changing. Reset the text height to force a
+ * recalculation during itemChanged().
+ */
+public void setFont(Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setFont(font);
+ textHeight = -1;
+}
+/**
+ * Set the horizontal drawing offset to 'offset'.
+ * Scroll the receiver's contents according to the offset change.
+ * @param offset - value < 0 = widget contents is drawn left of the client area.
+ */
+void setHorizontalOffset(int offset) {
+ int offsetChange = offset - horizontalOffset;
+
+ if (offsetChange != 0) {
+ scrollHorizontal(offsetChange);
+ horizontalOffset = offset;
+ }
+}
+
+/**
+ * Set whether the drop insert position is before or after the
+ * item set using motif_setInsertMark.
+ * @param after true=insert position is after the insert item
+ * false=insert position is before the insert item
+ */
+void setInsertAfter(boolean after) {
+ isInsertAfter = after;
+}
+
+/**
+ * Set the item that draws the marker indicating the insert location
+ * in a drag and drop operation.
+ * @param item the item that draws the insert marker
+ */
+void setInsertItem(SelectableItem item) {
+ insertItem = item;
+}
+/**
+ * Set the height of the receiver's items to 'height'.
+ */
+void setItemHeight(int height) {
+ itemHeight = height;
+}
+/**
+ * Set the item that most recently received the input focus
+ * to 'focusItem'. Redraw both, the item that lost focus
+ * and the one that received focus.
+ * @param focusItem - the item that most recently received
+ * the input focus
+ * @param showItem true=new focus item, if any, should be scrolled
+ * into view. false=don't scroll
+ */
+void setLastFocus(SelectableItem focusItem, boolean showItem) {
+ SelectableItem oldFocusItem = lastFocusItem;
+
+ if (focusItem != lastFocusItem) {
+ lastFocusItem = focusItem;
+ if (oldFocusItem != null) {
+ redrawSelection(oldFocusItem);
+ }
+ if (lastFocusItem != null && isFocusControl() == true) {
+ redrawSelection(lastFocusItem);
+ }
+ }
+ if (focusItem != null && showItem == true) {
+ showSelectableItem(focusItem);
+ }
+}
+/**
+ * Set the item that was selected most recently to 'selectedItem'.
+ * Set the input focus to that item.
+ * @param selectedItem - the item that was selected most recently
+ * @param showItem true=new focus item, if any, should be scrolled
+ * into view. false=don't scroll
+ */
+void setLastSelection(SelectableItem selectedItem, boolean showItem) {
+ if (selectedItem == null) { // always store the item selected last
+ return;
+ }
+ setLastFocus(selectedItem, showItem);
+ lastSelectedItem = selectedItem;
+}
+/**
+ * Sets the redraw flag.
+ * @param redraw -
+ * true = redraw and scroll operations are performed normally
+ * false = redraw and scroll operations are ignored
+ */
+public void setRedraw (boolean redraw) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (redraw) {
+ if (--drawCount == 0) redraw();
+ } else {
+ drawCount++;
+ }
+}
+/**
+ * Set whether all items in the widget are disposed.
+ * Used to optimize item disposal. Prevents unnecessary screen
+ * updates.
+ * @param removingAll
+ * true=all items are removed.
+ * false=normal state, no items or not all items are removed.
+ */
+void setRemovingAll(boolean removingAll) {
+ isRemovingAll = removingAll;
+}
+/**
+ * Select the items stored in 'selectionItems'.
+ * A SWT.Selection event is not going to be sent.
+ * @param selectionItems - Array containing the items that should
+ * be selected
+ */
+void setSelectableSelection(SelectableItem selectionItems[]) {
+ SelectableItem item = null;
+ int selectionCount = selectionItems.length;
+ Vector keepSelected;
+
+ if (isMultiSelect() == false && selectionCount > 1) {
+ selectionCount = 1;
+ }
+ keepSelected = new Vector(selectionItems.length);
+ for (int i = 0; i < selectionCount; i++) {
+ if (selectionItems[i] != null) {
+ keepSelected.addElement(selectionItems[i]);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ // select in the same order as all the other selection and deslection methods.
+ // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
+ // selections of the items, causing flash.
+ for (int i = selectionCount - 1; i >= 0; i--) {
+ item = selectionItems[i];
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, true);
+ }
+}
+/**
+ * Set the vector used to store the selected items of the receiver
+ * to 'newVector'.
+ * @param newVector - the vector used to store the selected items
+ * of the receiver
+ */
+void setSelectionVector(Vector newVector) {
+ selectedItems = newVector;
+}
+/**
+ * Scroll the item at 'index' to the top.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndex(int index, boolean adjustScrollbar) {
+ int indexDiff = index-topIndex;
+
+ if (indexDiff != 0) {
+ scrollVertical(indexDiff);
+ setTopIndexNoScroll(index, adjustScrollbar);
+ }
+}
+/**
+ * Set the index of the first visible item in the receiver's client
+ * area to 'index'.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
+ topIndex = index;
+ if (adjustScrollbar == true) {
+ getVerticalBar().setSelection(index);
+ }
+}
+/**
+ * The shift key was pressed when the mouse click on an item
+ * occurred. Do a shift selection. If an already selected item was
+ * clicked the selection is expanded/reduced to that item
+ * @param hitItem - specifies the clicked item
+ * @param hitItemIndex - specifies the index of the clicked item
+ * relative to the first item.
+ */
+void shiftSelect(SelectableItem hitItem, int hitItemIndex) {
+ int fromIndex = -1;
+ int toIndex = -1;
+ int lastSelectionIndex = -1;
+ int selectionRange[];
+ SelectableItem lastSelection = getLastSelection();
+
+ if (lastSelection != null) {
+ lastSelectionIndex = getVisibleIndex(lastSelection);
+ }
+ if (isCtrlSelection() == true) { // was last selection ctrl selection?
+ deselectAllExcept(lastSelection);
+ fromIndex = lastSelectionIndex; // select from last selection
+ toIndex = hitItemIndex;
+ }
+ else
+ if (getSelectionVector().contains(hitItem) == true) { // clicked an item already selected?
+ deselectRange(hitItemIndex, lastSelectionIndex); // reduce selection
+ }
+ else { // clicked outside existing selection range
+ selectionRange = calculateShiftSelectionRange(hitItemIndex);
+ fromIndex = selectionRange[0];
+ toIndex = selectionRange[1];
+ }
+ if (hitItemIndex == lastSelectionIndex) { // was click on last selected item?
+ return;
+ }
+ if (fromIndex == -1 || toIndex == -1) { // are there previously selected items?
+ toggleSelectionNotify(hitItem); // do a single select.
+ }
+ else {
+ if (((lastSelectionIndex < fromIndex) && (hitItemIndex > fromIndex)) || // does selection reverse direction?
+ ((lastSelectionIndex > fromIndex) && (hitItemIndex < fromIndex))) {
+ deselectAllExcept((SelectableItem) null); // remove old selection
+ }
+ selectRange(fromIndex, toIndex);
+ }
+}
+/**
+ * Make 'item' visible by scrolling it into the receiver's client
+ * area if necessary.
+ * @param item - the item that should be made visible to the user.
+ */
+void showSelectableItem(SelectableItem item) {
+ if (item.getSelectableParent() != this) {
+ return;
+ }
+ scrollShowItem(item);
+ scrollShowItem(item); // second call makes sure that the item is still visible
+ // even if the first scroll caused the horizontal scroll
+ // to be displayed and the item to be hidden again.
+}
+/**
+ * Show the selection. If there is no selection or the
+ * selection is already visible, this method does nothing.
+ * If the selection is not visible, the top index of the
+ * widget is changed such that the selection becomes visible.
+ */
+public void showSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector selection = getSelectionVector();
+ SelectableItem selectionItem;
+
+ if (selection.size() > 0) {
+ selectionItem = (SelectableItem) selection.firstElement();
+ showSelectableItem(selectionItem);
+ }
+}
+/**
+ * Sorts the specified range in the array.
+ *
+ * @param array the SelectableItem array to be sorted
+ * @param start the start index to sort
+ * @param end the last + 1 index to sort
+ */
+void sort(SelectableItem[] array, int start, int end) {
+ int middle = (start + end) / 2;
+ if (start + 1 < middle) sort(array, start, middle);
+ if (middle + 1 < end) sort(array, middle, end);
+ if (start + 1 >= end) return; // this case can only happen when this method is called by the user
+ if (getVisibleIndex(array[middle-1]) <= getVisibleIndex(array[middle])) return;
+ if (start + 2 == end) {
+ SelectableItem temp = array[start];
+ array[start] = array[middle];
+ array[middle] = temp;
+ return;
+ }
+ int i1 = start, i2 = middle, i3 = 0;
+ SelectableItem[] merge = new SelectableItem[end - start];
+ while (i1 < middle && i2 < end) {
+ merge[i3++] = getVisibleIndex(array[i1]) <= getVisibleIndex(array[i2]) ?
+ array[i1++] : array[i2++];
+ }
+ if (i1 < middle) System.arraycopy(array, i1, merge, i3, middle - i1);
+ System.arraycopy(merge, 0, array, start, i2 - start);
+}
+/**
+ * Toggle the selection of 'item'.
+ * @param item - item that should be selected/deselected
+ */
+void toggleSelectionNotify(SelectableItem item) {
+ if (item.isSelected() == true) {
+ deselectNotify(item);
+ }
+ else {
+ selectNotify(item);
+ }
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java
new file mode 100755
index 0000000000..00c268acf0
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java
@@ -0,0 +1,865 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The shell class implements a top level window
+* and dialog windows.
+*
+* Styles
+*
+* ON_TOP
+* DBCS
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/* Class Definition */
+public /*final*/ class Shell extends Decorations {
+ Display display;
+ int shellHandle;
+ boolean reparented, realized;
+ int oldX, oldY, oldWidth, oldHeight;
+ Control lastFocus;
+/**
+* Creates a widget.
+*/
+public Shell () {
+ this ((Display) null);
+}
+/**
+* Creates a widget.
+*/
+public Shell (int style) {
+ this ((Display) null, style);
+}
+/**
+* Creates a widget.
+*/
+public Shell (Display display) {
+ this (display, SWT.SHELL_TRIM);
+}
+/**
+* Creates a widget.
+* <p>
+* This method creates a top level shell widget on a
+* display using style bits to select a particular look
+* or set of properties.
+*
+* @param display the Display (or null for the default)
+* @param style the bitwise OR'ing of widget styles
+*
+* @exception SWTError(ERROR_ERROR_INVALID_PARENT)
+* when the parent is invalid
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+*/
+public Shell (Display display, int style) {
+ this (display, null, style, 0);
+}
+Shell (Display display, Shell parent, int style, int handle) {
+ super ();
+ if (display == null) display = Display.getCurrent ();
+ if (display == null) display = Display.getDefault ();
+ if (!display.isValidThread ()) {
+ error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ this.style = checkStyle (style);
+ this.parent = parent;
+ this.display = display;
+ this.handle = handle;
+ createWidget (0);
+}
+/**
+* Creates a widget.
+*/
+public Shell (Shell parent) {
+ this (parent, SWT.DIALOG_TRIM);
+}
+/**
+* Creates a widget.
+*/
+public Shell (Shell parent, int style) {
+ this (parent != null ? parent.getDisplay () : null, parent, style, 0);
+}
+
+static int checkStyle (int style) {
+ style = Decorations.checkStyle (style);
+ int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
+ int bits = style & ~mask;
+ if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
+ if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
+ if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
+ return bits;
+}
+
+public static Shell motif_new (Display display, int handle) {
+ return new Shell (display, null, SWT.NO_TRIM, handle);
+}
+
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addShellListener(ShellListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener(SWT.Activate,typedListener);
+ addListener(SWT.Close,typedListener);
+ addListener(SWT.Deactivate,typedListener);
+ addListener(SWT.Iconify,typedListener);
+ addListener(SWT.Deiconify,typedListener);
+}
+void adjustTrim () {
+ if ((style & SWT.ON_TOP) != 0) return;
+
+ /* Query the trim insets */
+ int shellWindow = OS.XtWindow (shellHandle);
+ if (shellWindow == 0) return;
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay == 0) return;
+
+ /* Find the direct child of the root window */
+ int [] unused = new int [1];
+ int [] rootWindow = new int [1];
+ int [] parent = new int [1];
+ int [] ptr = new int [1];
+ int trimWindow = shellWindow;
+ OS.XQueryTree (xDisplay, trimWindow, rootWindow, parent, ptr, unused);
+ if (ptr [0] != 0) OS.XFree (ptr [0]);
+ if (parent [0] == 0) return;
+ while (parent [0] != rootWindow [0]) {
+ trimWindow = parent [0];
+ OS.XQueryTree (xDisplay, trimWindow, unused, parent, ptr, unused);
+ if (ptr [0] != 0) OS.XFree (ptr [0]);
+ if (parent [0] == 0) return;
+ }
+
+ /**
+ * Translate the coordinates of the shell window to the
+ * coordinates of the direct child of the root window
+ */
+ if (shellWindow == trimWindow) return;
+
+ /* Query the border width of the direct child of the root window */
+ int [] trimBorder = new int [1];
+ int [] trimWidth = new int [1];
+ int [] trimHeight = new int [1];
+ OS.XGetGeometry (xDisplay, trimWindow, unused, unused, unused, trimWidth, trimHeight, trimBorder, unused);
+
+ /* Query the border width of the direct child of the shell window */
+ int [] shellBorder = new int [1];
+ int [] shellWidth = new int [1];
+ int [] shellHeight = new int [1];
+ OS.XGetGeometry (xDisplay, shellWindow, unused, unused, unused, shellWidth, shellHeight, shellBorder, unused);
+
+ /* Calculate the trim */
+ int width = (trimWidth [0] + (trimBorder [0] * 2)) - (shellWidth [0] + (shellBorder [0] * 2));
+ int height = (trimHeight [0] + (trimBorder [0] * 2)) - (shellHeight [0] + (shellBorder [0] * 2));
+
+ /* Update the trim guesses to match the query */
+ boolean hasTitle = false, hasResize = false, hasBorder = false;
+ if ((style & SWT.NO_TRIM) == 0) {
+ hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
+ hasResize = (style & SWT.RESIZE) != 0;
+ hasBorder = (style & SWT.BORDER) != 0;
+ }
+ if (hasTitle) {
+ if (hasResize) {
+ display.titleResizeTrimWidth = width;
+ display.titleResizeTrimHeight = height;
+ return;
+ }
+ if (hasBorder) {
+ display.titleBorderTrimWidth = width;
+ display.titleBorderTrimHeight = height;
+ return;
+ }
+ display.titleTrimWidth = width;
+ display.titleTrimHeight = height;
+ return;
+ }
+ if (hasResize) {
+ display.resizeTrimWidth = width;
+ display.resizeTrimHeight = height;
+ return;
+ }
+ if (hasBorder) {
+ display.borderTrimWidth = width;
+ display.borderTrimHeight = height;
+ return;
+ }
+}
+public void close () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ closeWidget ();
+}
+void closeWidget () {
+ if (!isEnabled ()) return;
+ Control widget = parent;
+ while (widget != null && !(widget.getShell ().isModal ())) {
+ widget = widget.parent;
+ }
+ if (widget == null) {
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (shell != this && shell.isModal () && shell.isVisible ()) {
+ shell.bringToTop ();
+ return;
+ }
+ }
+ }
+ Event event = new Event ();
+ sendEvent (SWT.Close, event);
+ if (event.doit && !isDisposed ()) dispose ();
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle trim = super.computeTrim (x, y, width, height);
+ int trimWidth = trimWidth (), trimHeight = trimHeight ();
+ trim.x -= trimWidth / 2; trim.y -= trimHeight - (trimWidth / 2);
+ trim.width += trimWidth; trim.height += trimHeight;
+ return trim;
+}
+void createHandle (int index) {
+ state |= HANDLE | CANVAS;
+ int decorations = 0;
+ if ((style & SWT.NO_TRIM) == 0) {
+ if ((style & SWT.MIN) != 0) decorations |= OS.MWM_DECOR_MINIMIZE;
+ if ((style & SWT.MAX) != 0) decorations |= OS.MWM_DECOR_MAXIMIZE;
+ if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_RESIZEH;
+ if ((style & SWT.BORDER) != 0) decorations |= OS.MWM_DECOR_BORDER;
+ if ((style & SWT.MENU) != 0) decorations |= OS.MWM_DECOR_MENU;
+ if ((style & SWT.TITLE) != 0) decorations |= OS.MWM_DECOR_TITLE;
+ /*
+ * Feature in Motif. Under some Window Managers (Sawmill), in order
+ * to get any border at all from the window manager it is necessary
+ * to set MWM_DECOR_BORDER. The fix is to force these bits when any
+ * kind of border is requested.
+ */
+ if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_BORDER;
+ }
+
+ /*
+ * Note: Motif treats the modal values as hints to the Window Manager.
+ * For example, Enlightenment treats all modes except for SWT.MODELESS
+ * as SWT.APPLICATION_MODAL. The Motif Window Manager honours all modes.
+ */
+ int inputMode = OS.MWM_INPUT_MODELESS;
+ if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.MWM_INPUT_PRIMARY_APPLICATION_MODAL;
+ if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.MWM_INPUT_FULL_APPLICATION_MODAL;
+ if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.MWM_INPUT_SYSTEM_MODAL;
+
+ /*
+ * Bug in Motif. For some reason, if the title string
+ * length is not a multiple of 4, Motif occasionally
+ * draws garbage after the last character in the title.
+ * The fix is to pad the title.
+ */
+ byte [] buffer = {(byte)' ', 0, 0, 0};
+ int ptr = OS.XtMalloc (buffer.length);
+ OS.memmove (ptr, buffer, buffer.length);
+ int [] argList = {
+ OS.XmNmwmInputMode, inputMode,
+ OS.XmNmwmDecorations, decorations,
+ OS.XmNtitle, ptr,
+ };
+ byte [] appClass = display.appClass;
+ if (parent == null && (style & SWT.ON_TOP) == 0) {
+ int xDisplay = display.xDisplay;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+ shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList, argList.length / 2);
+ } else {
+ int widgetClass = OS.TransientShellWidgetClass ();
+ if ((style & SWT.ON_TOP) != 0) widgetClass = OS.OverrideShellWidgetClass ();
+ int parentHandle = display.shellHandle;
+ if (parent != null) parentHandle = parent.handle;
+ shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList, argList.length / 2);
+ }
+ OS.XtFree (ptr);
+ if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
+
+ /* Create scrolled handle */
+ createScrolledHandle (shellHandle);
+
+ /*
+ * Feature in Motif. There is no way to get the single pixel
+ * border surrounding a TopLevelShell or a TransientShell.
+ * Also, attempts to set a border on either the shell handle
+ * or the main window handle fail. The fix is to set the border
+ * on the client area.
+ */
+ if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) {
+ int [] argList1 = {OS.XmNborderWidth, 1};
+ OS.XtSetValues (handle, argList1, argList1.length / 2);
+ }
+}
+void deregister () {
+ super.deregister ();
+ WidgetTable.remove (shellHandle);
+}
+void destroyWidget () {
+ /*
+ * Hide the shell before calling XtDestroyWidget ()
+ * so that the shell will disappear without having
+ * to dispatch events. Otherwise, the user will be
+ * able to interact with the trimmings between the
+ * time that the shell is destroyed and the next
+ * event is dispatched.
+ */
+ if (OS.XtIsRealized (shellHandle)) {
+ if (OS.XtIsTopLevelShell (shellHandle)) {
+ OS.XtUnmapWidget (shellHandle);
+ } else {
+ OS.XtPopdown (shellHandle);
+ }
+ }
+ super.destroyWidget ();
+}
+
+public void dispose () {
+ /*
+ * This code is intentionally commented. On some
+ * platforms, the owner window is repainted right
+ * away when the dialog window exits. This behavior
+ * is currently unspecified.
+ */
+// /*
+// * Note: It is valid to attempt to dispose a widget
+// * more than once. If this happens, fail silently.
+// */
+// if (!isValidWidget ()) return;
+// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+// Display oldDisplay = display;
+ super.dispose ();
+// if (oldDisplay != null) oldDisplay.update ();
+}
+void enableWidget (boolean enabled) {
+ super.enableWidget (enabled);
+ enableHandle (enabled, shellHandle);
+}
+public int getBorderWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ return argList [1];
+}
+public Rectangle getBounds () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ int border = argList [5];
+ int trimWidth = trimWidth (), trimHeight = trimHeight ();
+ int width = argList [1] + trimWidth + (border * 2);
+ int height = argList [3] + trimHeight + (border * 2);
+ return new Rectangle (root_x [0], root_y [0], width, height);
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return display;
+}
+public int getImeInputMode () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return SWT.NONE;
+}
+public Point getLocation () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
+ return new Point (root_x [0], root_y [0]);
+}
+public Shell getShell () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return this;
+}
+/**
+* Get dialogs shells.
+* <p>
+* @return the dialog shells
+*
+* @exception SWTError(ERROR_ERROR_INVALID_PARENT)
+* when the parent is invalid
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+*/
+public Shell [] getShells () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int count = 0;
+ Shell [] shells = display.getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Control shell = shells [i];
+ do {
+ shell = shell.parent;
+ } while (shell != null && shell != this);
+ if (shell == this) count++;
+ }
+ int index = 0;
+ Shell [] result = new Shell [count];
+ for (int i=0; i<shells.length; i++) {
+ Control shell = shells [i];
+ do {
+ shell = shell.parent;
+ } while (shell != null && shell != this);
+ if (shell == this) {
+ result [index++] = shells [i];
+ }
+ }
+ return result;
+}
+public Point getSize () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ int border = argList [5];
+ int trimWidth = trimWidth (), trimHeight = trimHeight ();
+ int width = argList [1] + trimWidth + (border * 2);
+ int height = argList [3] + trimHeight + (border * 2);
+ return new Point (width, height);
+}
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (!OS.XtIsRealized (handle)) return false;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return false;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return false;
+ XWindowAttributes attributes = new XWindowAttributes ();
+ OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
+ if (attributes.map_state == OS.IsViewable) return true;
+ int [] argList = {OS.XmNmappedWhenManaged, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ return minimized && attributes.map_state == OS.IsUnviewable && argList [1] != 0;
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = display.windowProc;
+ OS.XtAddEventHandler (shellHandle, OS.StructureNotifyMask, false, windowProc, SWT.Resize);
+ if ((style & SWT.ON_TOP) != 0) return;
+ OS.XtAddEventHandler (shellHandle, OS.FocusChangeMask, false, windowProc, SWT.FocusIn);
+ int [] argList = {OS.XmNdeleteResponse, OS.XmDO_NOTHING};
+ OS.XtSetValues (shellHandle, argList, argList.length / 2);
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay != 0) {
+ byte [] WM_DETELE_WINDOW = Converter.wcsToMbcs (null, "WM_DELETE_WINDOW\0", false);
+ int atom = OS.XmInternAtom (xDisplay, WM_DETELE_WINDOW, false);
+ OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, SWT.Dispose);
+ }
+}
+int inputContext () {
+ //NOT DONE
+ return 0;
+}
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getEnabled ();
+}
+boolean isModal () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNmwmInputMode, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ return (argList [1] != -1 && argList [1] != OS.MWM_INPUT_MODELESS);
+}
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getVisible ();
+}
+void manageChildren () {
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ super.manageChildren ();
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay == 0) return;
+ int width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
+ int height = OS.XDisplayHeight (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
+ OS.XtResizeWidget (shellHandle, width, height, 0);
+}
+public void open () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ setVisible (true);
+}
+int processDispose (int callData) {
+ closeWidget ();
+ return 0;
+}
+
+int processResize (int callData) {
+ XConfigureEvent xEvent = new XConfigureEvent ();
+ OS.memmove (xEvent, callData, XConfigureEvent.sizeof);
+ switch (xEvent.type) {
+ case OS.ReparentNotify: {
+ if (reparented) return 0;
+ reparented = true;
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ xEvent.x = root_x [0]; xEvent.y = root_y [0];
+ xEvent.width = argList [1]; xEvent.height = argList [3];
+ // fall through
+ }
+ case OS.ConfigureNotify:
+ if (!reparented) return 0;
+ if (oldX != xEvent.x || oldY != xEvent.y) sendEvent (SWT.Move);
+ if (oldWidth != xEvent.width || oldHeight != xEvent.height) {
+ sendEvent (SWT.Resize);
+ if (layout != null) layout (false);
+ }
+ if (xEvent.x != 0) oldX = xEvent.x;
+ if (xEvent.y != 0) oldY = xEvent.y;
+ oldWidth = xEvent.width;
+ oldHeight = xEvent.height;
+ return 0;
+ case OS.UnmapNotify:
+ int [] argList = {OS.XmNmappedWhenManaged, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ if (argList [1] != 0) {
+ minimized = true;
+ sendEvent (SWT.Iconify);
+ }
+ return 0;
+ case OS.MapNotify:
+ if (minimized) {
+ minimized = false;
+ sendEvent (SWT.Deiconify);
+ }
+ return 0;
+ }
+ return 0;
+}
+
+int processSetFocus (int callData) {
+ XFocusChangeEvent xEvent = new XFocusChangeEvent ();
+ OS.memmove (xEvent, callData, XFocusChangeEvent.sizeof);
+ int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
+ if (handle != shellHandle) return super.processSetFocus (callData);
+ if (xEvent.mode != OS.NotifyNormal) return 0;
+ if (xEvent.detail != OS.NotifyNonlinear) return 0;
+ switch (xEvent.type) {
+ case OS.FocusIn:
+ postEvent (SWT.Activate);
+ break;
+ case OS.FocusOut:
+ postEvent (SWT.Deactivate);
+ break;
+ }
+ return 0;
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ propagateHandle (enabled, shellHandle);
+}
+void realizeWidget () {
+ if (realized) return;
+ OS.XtRealizeWidget (shellHandle);
+ realizeChildren ();
+ realized = true;
+}
+void register () {
+ super.register ();
+ WidgetTable.put (shellHandle, this);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ shellHandle = 0;
+}
+void releaseShells () {
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed ()) {
+ shell.releaseWidget ();
+ shell.releaseHandle ();
+ }
+ }
+}
+void releaseWidget () {
+ releaseShells ();
+ super.releaseWidget ();
+ display = null;
+ lastFocus = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeShellListener(ShellListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Activate, listener);
+ eventTable.unhook(SWT.Close, listener);
+ eventTable.unhook(SWT.Deactivate, listener);
+ eventTable.unhook(SWT.Iconify,listener);
+ eventTable.unhook(SWT.Deiconify,listener);
+}
+void saveBounds () {
+ if (!reparented) return;
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ int trimWidth = trimWidth (), trimHeight = trimHeight ();
+ oldX = root_x [0] - trimWidth; oldY = root_y [0] - trimHeight;
+ oldWidth = argList [1]; oldHeight = argList [3];
+}
+public void setBounds (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ saveBounds ();
+ int newWidth = Math.max (width - trimWidth (), 1);
+ int newHeight = Math.max (height - trimHeight (), 1);
+ if (!reparented) {
+ super.setBounds (x, y, newWidth, newHeight);
+ return;
+ }
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ OS.XtConfigureWidget (shellHandle, x, y, newWidth, newHeight, 0);
+ if (isFocus) caret.setFocus ();
+}
+public void setImeInputMode (int mode) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ saveBounds ();
+ if (!reparented) {
+ super.setLocation(x, y);
+ return;
+ }
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ OS.XtMoveWidget (shellHandle, x, y);
+ if (isFocus) caret.setFocus ();
+}
+public void setMinimized (boolean minimized) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ /*
+ * Bug in MOTIF. For some reason, the receiver does not keep the
+ * value of the XmNiconic resource up to date when the user minimizes
+ * and restores the window. As a result, a window that is minimized
+ * by the user and then restored by the programmer is not restored.
+ * This happens because the XmNiconic resource is unchanged when the
+ * window is minimized by the user and subsequent attempts to set the
+ * resource fail because the new value of the resource is the same as
+ * the old value. The fix is to force XmNiconic to be up to date
+ * before setting the desired value.
+ */
+ int [] argList = {OS.XmNiconic, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ if ((argList [1] != 0) != this.minimized) {
+ argList [1] = this.minimized ? 1 : 0;
+ OS.XtSetValues (shellHandle, argList, argList.length / 2);
+ }
+
+ /* Minimize or restore the shell */
+ argList [1] = (this.minimized = minimized) ? 1 : 0;
+ OS.XtSetValues (shellHandle, argList, argList.length / 2);
+
+ /* Force the XWindowAttributes to be up to date */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay != 0) OS.XSync (xDisplay, false);
+}
+
+public void setSize (int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ saveBounds ();
+ int newWidth = Math.max (width - trimWidth (), 1);
+ int newHeight = Math.max (height - trimHeight (), 1);
+ if (!reparented) {
+ super.setSize(newWidth, newHeight);
+ return;
+ }
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ OS.XtResizeWidget (shellHandle, newWidth, newHeight, 0);
+ if (isFocus) caret.setFocus ();
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+
+ /*
+ * Feature in Motif. It is not possible to set a shell
+ * title to an empty string. The fix is to set the title
+ * to be a single space.
+ */
+ if (string.length () == 0) string = " ";
+ byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
+ int length = buffer1.length - 1;
+
+ /*
+ * Bug in Motif. For some reason, if the title string
+ * length is not a multiple of 4, Motif occasionally
+ * draws garbage after the last character in the title.
+ * The fix is to pad the title.
+ */
+ byte [] buffer2 = buffer1;
+ if ((length % 4) != 0) {
+ buffer2 = new byte [(length + 3) / 4 * 4];
+ System.arraycopy (buffer1, 0, buffer2, 0, length);
+ }
+
+ /* Set the title for the shell */
+ int ptr = OS.XtMalloc (buffer2.length + 1);
+ OS.memmove (ptr, buffer2, buffer2.length);
+ int [] argList = {OS.XmNtitle, ptr};
+ OS.XtSetValues (shellHandle, argList, argList.length / 2);
+ OS.XtFree (ptr);
+}
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ realizeWidget ();
+
+ /* Show the shell */
+ if (visible) {
+
+ /* Map the widget */
+ OS.XtSetMappedWhenManaged (shellHandle, true);
+ if (OS.XtIsTopLevelShell (shellHandle)) {
+ OS.XtMapWidget (shellHandle);
+ } else {
+ OS.XtPopup (shellHandle, OS.XtGrabNone);
+ }
+
+ /*
+ * Force the shell to be fully exposed before returning.
+ * This ensures that the shell coordinates are correct
+ * when queried directly after showing the shell.
+ */
+ do {
+ display.update ();
+ } while (!isVisible ());
+ adjustTrim ();
+
+ /* Set the saved focus widget */
+ if (savedFocus != null && !savedFocus.isDisposed ()) {
+ savedFocus.setFocus ();
+ }
+ savedFocus = null;
+
+ sendEvent (SWT.Show);
+ return;
+ }
+
+ /* Hide the shell */
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ if (OS.XtIsTopLevelShell (shellHandle)) {
+ OS.XtUnmapWidget (shellHandle);
+ } else {
+ OS.XtPopdown (shellHandle);
+ }
+
+ /* If the shell is iconified, hide the icon */
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (shellHandle);
+ if (xWindow == 0) return;
+ OS.XWithdrawWindow (xDisplay, xWindow, OS.XDefaultScreen (xDisplay));
+
+ sendEvent (SWT.Hide);
+}
+int topHandle () {
+ return shellHandle;
+}
+int trimHeight () {
+ if ((style & SWT.NO_TRIM) != 0) return 0;
+ boolean hasTitle = false, hasResize = false, hasBorder = false;
+ hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
+ hasResize = (style & SWT.RESIZE) != 0;
+ hasBorder = (style & SWT.BORDER) != 0;
+ if (hasTitle) {
+ if (hasResize) return display.titleResizeTrimHeight;
+ if (hasBorder) return display.titleBorderTrimHeight;
+ return display.titleTrimHeight;
+ }
+ if (hasResize) return display.resizeTrimHeight;
+ if (hasBorder) return display.borderTrimHeight;
+ return 0;
+}
+int trimWidth () {
+ if ((style & SWT.NO_TRIM) != 0) return 0;
+ boolean hasTitle = false, hasResize = false, hasBorder = false;
+ hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
+ hasResize = (style & SWT.RESIZE) != 0;
+ hasBorder = (style & SWT.BORDER) != 0;
+ if (hasTitle) {
+ if (hasResize) return display.titleResizeTrimWidth;
+ if (hasBorder) return display.titleBorderTrimWidth;
+ return display.titleTrimWidth;
+ }
+ if (hasResize) return display.resizeTrimWidth;
+ if (hasBorder) return display.borderTrimWidth;
+ return 0;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java
new file mode 100755
index 0000000000..e72a8c2593
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java
@@ -0,0 +1,406 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+* A slider is a selectable user interface object
+* that represents a continuous range of numeric values.
+*
+* <b>Styles</b><br>
+* <dd>HORIZONTAL, VERTICAL<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class Slider extends Control {
+/**
+* Creates a new instance of the widget.
+*/
+public Slider (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
+ Display display = getDisplay ();
+ int hScroll = display.scrolledMarginX;
+ int vScroll = display.scrolledMarginY;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ width += hScroll * 10;
+ height += vScroll;
+ } else {
+ width += hScroll;
+ height += vScroll * 10;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int [] argList = {
+ OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
+ OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
+ };
+ handle = OS.XmCreateScrollBar (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+/**
+* Gets the increment.
+* <p>
+* @return the increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNincrement, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the maximum.
+* <p>
+* @return the maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMaximum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNmaximum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the minimum.
+* <p>
+* @return the minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getMinimum () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNminimum, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the page increment.
+* <p>
+* @return the page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getPageIncrement () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNpageIncrement, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the selection.
+* <p>
+* @return the selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNvalue, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+* Gets the thumb.
+* <p>
+* @return the thumb value
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getThumb () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsliderSize, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, SWT.Selection);
+ OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, SWT.Selection);
+}
+int processSelection (int callData) {
+ XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
+ OS.memmove (struct, callData, XmAnyCallbackStruct.sizeof);
+ Event event = new Event ();
+ switch (struct.reason) {
+ case OS.XmCR_DRAG: event.detail = SWT.DRAG; break;
+ /*
+ * Do not set the detail field to SWT.DRAG
+ * to indicate that the dragging has ended.
+ */
+// case OS.XmCR_VALUE_CHANGED: break;
+ case OS.XmCR_TO_TOP: event.detail = SWT.HOME; break;
+ case OS.XmCR_TO_BOTTOM: event.detail = SWT.END; break;
+ case OS.XmCR_DECREMENT: event.detail = SWT.ARROW_UP; break;
+ case OS.XmCR_INCREMENT: event.detail = SWT.ARROW_DOWN; break;
+ case OS.XmCR_PAGE_DECREMENT: event.detail = SWT.PAGE_UP; break;
+ case OS.XmCR_PAGE_INCREMENT: event.detail = SWT.PAGE_DOWN; break;
+ }
+ sendEvent (SWT.Selection, event);
+ return 0;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Sets the increment.
+* <p>
+* @param value the new increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setIncrement (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNincrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the maximum.
+* <p>
+* @param value the new maximum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMaximum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the minimum.
+* <p>
+* @param value the new minimum
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setMinimum (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {
+ OS.XmNminimum, 0,
+ OS.XmNmaximum, 0,
+ OS.XmNsliderSize, 0,
+ };
+ /*
+ * Feature in Motif. For some reason, when minimium
+ * is set to be greater than or equal to maximum, Motif
+ * does not set the minimum. Instead, the value is
+ * changed and the minimum stays the same. This behavior
+ * differs from setting the maximum where the slider size
+ * is always decreased to make room for the new maximum.
+ * The fix is to decrease the slider to make room for
+ * the new minimum.
+ */
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [3] - value - argList [5] < 0) {
+ argList [5] = argList [3] - value;
+ }
+ argList [1] = value;
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the page increment.
+* <p>
+* @param value the new page increment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setPageIncrement (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNpageIncrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the selection.
+* <p>
+* @param value the new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 0) return;
+ int [] argList = {OS.XmNvalue, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the thumb.
+* <p>
+* @param value the new thumb
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setThumb (int value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (value < 1) return;
+ int [] argList = {OS.XmNsliderSize, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (selection < 0) return;
+ if (minimum < 0) return;
+ if (maximum < 0) return;
+ if (thumb < 1) return;
+ if (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] argList = {
+ OS.XmNvalue, selection,
+ OS.XmNminimum, minimum,
+ OS.XmNmaximum, maximum,
+ OS.XmNsliderSize, thumb,
+ OS.XmNincrement, increment,
+ OS.XmNpageIncrement, pageIncrement,
+ };
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabFolder.java
new file mode 100755
index 0000000000..ea02526d3d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabFolder.java
@@ -0,0 +1,885 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class emulates a windows TabFolder by using portable
+ * graphics and widgets.
+ */
+public /*final*/ class TabFolder extends Composite {
+ TabItem items[];
+ int selectedIndex = -1;
+ int xClient, yClient;
+ int imageHeight = -1; // all images have the height of the first image ever set
+ int topTabIndex = 0; // index of the first visible tab. Used for tab scrolling
+ boolean scrollButtonDown = false; // true=one of the scroll buttons is being pushed
+ boolean inDispose = false;
+
+ // internal constants
+ static final int SCROLL_BUTTON_SIZE = 20; // width/height of the scroll button used for scrolling tab items
+ static final int CLIENT_MARGIN_WIDTH = 2; // distance between widget border and client rect
+ static final int SELECTED_TAB_TOP_EXPANSION = 2; // amount we expand the selected tab on top
+ static final int SELECTED_TAB_HORIZONTAL_EXPANSION = 2; // amount we expand so it overlays to left and right
+/**
+ * Construct a TabFolder with the specified parent and style.
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @param swtStyle int
+ */
+public TabFolder(Composite parent, int style) {
+ super(parent, checkStyle (style));
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {handleEvents(event);}
+ };
+ addListener (SWT.Dispose, listener);
+ addListener (SWT.MouseDown, listener);
+ addListener (SWT.MouseUp, listener);
+ addListener (SWT.Paint, listener);
+ addListener (SWT.Resize, listener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ typedListener = new TypedListener(listener);
+ addListener(SWT.Selection, typedListener);
+ addListener(SWT.DefaultSelection, typedListener);
+}
+static int checkStyle (int style) {
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
+ int height = 0;
+
+ if (items != null && items.length > 0) {
+ TabItem lastItem = items[items.length-1];
+ width = Math.max (width, lastItem.x + lastItem.width);
+ }
+ Point size;
+ Layout layout = getLayout();
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } else {
+ size = minimumSize ();
+ }
+ if (size.x == 0) size.x = DEFAULT_WIDTH;
+ if (size.y == 0) size.y = DEFAULT_HEIGHT;
+ if (wHint != SWT.DEFAULT) size.x = wHint;
+ if (hHint != SWT.DEFAULT) size.y = hHint;
+ width = Math.max (width, size.x);
+ height = Math.max (height, size.y);
+ Rectangle trim = computeTrim (0, 0, width, height);
+ return new Point (trim.width, trim.height);
+}
+/**
+ * Answer the bounds of the trimmings when the client area is defined by
+ * 'x', 'y', 'width' and 'height'.
+ */
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int border = getBorderWidth ();
+ int trimX = x - border - CLIENT_MARGIN_WIDTH - TabItem.SHADOW_WIDTH;
+ int trimY = y - border - CLIENT_MARGIN_WIDTH - TabItem.SHADOW_WIDTH;
+ int tabHeight = 0;
+ if (items != null && items.length > 0) {
+ TabItem item = items [0];
+ tabHeight = item.y + item.height; // only use height of the first item because all items should be the same height
+ }
+ int trimWidth = width + border * 2 + CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
+ int trimHeight = height + tabHeight + border * 2 + CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
+ return new Rectangle (trimX, trimY - tabHeight, trimWidth, trimHeight);
+}
+/**
+ * Create the specified item at 'index'.
+ */
+void createChild (TabItem item, int index) {
+ boolean isTabScrolling = isTabScrolling();
+
+ if (!(0 <= index && index <= getItemCount ())) error (SWT.ERROR_INVALID_RANGE);
+ item.parent = this;
+ if (items == null) {
+ items = new TabItem[1];
+ items[0] = item;
+ } else {
+ // grow by one and rearrange the array.
+ TabItem[] newItems = new TabItem [items.length + 1];
+ System.arraycopy(items, 0, newItems, 0, index);
+ newItems[index] = item;
+ System.arraycopy(items, index, newItems, index + 1, items.length - index);
+ items = newItems;
+ if (selectedIndex >= index) selectedIndex ++;
+ }
+ layoutItems();
+ redrawTabs();
+ // redraw scroll buttons if they just became visible
+ // fixes 1G5X1QL
+ if (isTabScrolling() != isTabScrolling && isTabScrolling == false) {
+ redrawScrollButtons();
+ }
+ if (getItemCount() == 1) {
+ // select the first added item and send a selection event.
+ // fixes 1GAP79N
+ setSelectionNotify(0);
+ }
+}
+/**
+ * Destroy the specified item.
+ */
+void destroyChild (TabItem item) {
+ int index = indexOf(item);
+ if (index == -1) return; // should trigger an error?
+ if (items.length == 1) {
+ items = null;
+ selectedIndex = -1;
+ topTabIndex = 0;
+ if (!inDispose){
+ Control control = item.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ redraw();
+ }
+ } else {
+ // shrink by one and rearrange the array.
+ TabItem[] newItems = new TabItem [items.length - 1];
+ System.arraycopy(items, 0, newItems, 0, index);
+ System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
+ items = newItems;
+
+ // move the selection if this item is selected
+ if (selectedIndex == index) {
+ if (!inDispose) {
+ Control control = item.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ selectedIndex = -1;
+ setSelectionNotify(Math.max(0, index - 1));
+ }
+ } else if (selectedIndex > index) {
+ selectedIndex--;
+ }
+ if (topTabIndex == items.length) {
+ --topTabIndex;
+ }
+ }
+ // Make sure that the first tab is visible if scroll buttons are no longer drawn.
+ // Fixes 1FXW5DV
+ if (topTabIndex > 0 && !isTabScrolling()) {
+ topTabIndex = 0;
+ }
+ if (!inDispose) {
+ layoutItems();
+ redrawTabs();
+ }
+}
+/**
+ * Dispose the items of the receiver
+ */
+void doDispose() {
+ inDispose = true;
+ // items array is resized during TabItem.dispose
+ // it is set to null if the last item is removed
+ while (items != null) {
+ if (items[items.length-1] != null) {
+ items[items.length-1].dispose();
+ }
+ }
+}
+/**
+ * Draw an arrow like that used in Button with SWT.ARROW style.
+ * @param gc - GC to draw on
+ * @param xPos - x position the underlying button is drawn at
+ * @param yPos - y position the underlying button is drawn at
+ * @param size - size of the underlying button
+ * @param left - true=arrow is facing left. false=arrow is facing right
+ */
+void drawArrow(GC gc, int xPos, int yPos, int size, boolean left) {
+ int arrowWidth = size / 4;
+ int arrow[] = new int[6];
+
+ if (!left) arrowWidth *= -1;
+ // start polygon lines with vertical line which is always the same
+ arrow[0] = xPos + (size + arrowWidth) / 2;
+ arrow[1] = yPos + size / 4;
+ arrow[2] = arrow[0];
+ arrow[3] = arrow[1] + size / 2;
+
+ arrow[4] = arrow[0] - arrowWidth;
+ arrow[5] = yPos + size / 2;
+
+ gc.setBackground(getForeground());
+ gc.fillPolygon(arrow);
+ gc.setBackground(getBackground());
+}
+/**
+ * Draw a border around the receiver.
+ */
+void drawBorder(Event event) {
+ GC gc = event.gc;
+ Rectangle clientArea = getClientArea();
+ int wClient = clientArea.width;
+ int hClient = clientArea.height;
+ int x, y, x1, y1;
+ final Color HighlightShadow = getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ final Color LightShadow = getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
+
+ // Draw the left line
+ gc.setForeground(HighlightShadow);
+ gc.drawLine((x = xClient - CLIENT_MARGIN_WIDTH),
+ yClient + hClient + CLIENT_MARGIN_WIDTH,
+ x,
+ (y = yClient - CLIENT_MARGIN_WIDTH) + 1);
+ // Second, darker, line right of the previous line.
+ // Necessary to workaround color constant differences on Windows/Motif
+ gc.setForeground(LightShadow);
+ gc.drawLine(x + 1, yClient + hClient + CLIENT_MARGIN_WIDTH, x + 1, y + 1);
+ gc.setForeground(HighlightShadow);
+
+ // Draw the upper line in two chunks so we don't overwrite the selected tab
+ if (selectedIndex == -1) {
+ gc.setForeground(LightShadow);
+ gc.drawLine(x + 1, y + 1, xClient + wClient + CLIENT_MARGIN_WIDTH, y + 1);
+ } else {
+ TabItem item = items[selectedIndex];
+ gc.setForeground(LightShadow);
+ if (selectedIndex > 0) {
+ gc.drawLine(x + 1, y + 1, item.x - 1 + CLIENT_MARGIN_WIDTH, y + 1);
+ }
+ gc.drawLine(item.x + item.width, y + 1, xClient + wClient + CLIENT_MARGIN_WIDTH, y + 1);
+ }
+
+ // Draw the right and bottom black lines
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
+ gc.drawLine((x = xClient - CLIENT_MARGIN_WIDTH),
+ (y = yClient + hClient + CLIENT_MARGIN_WIDTH),
+ (x1 = xClient + wClient + CLIENT_MARGIN_WIDTH),
+ y);
+ gc.drawLine(x1, y, x1, (y1 = yClient - CLIENT_MARGIN_WIDTH + 1));
+ x1--;
+ x++;
+ y--;
+ y1++;
+
+
+ // There is a dark gray line above the bottom back line
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
+ gc.drawLine(x, y, x1, y);
+ // On the right there is a dark gray line, left of the black one
+ gc.drawLine(x1, y-1, x1, y1);
+
+ // restore the foreground color.
+ gc.setForeground(getForeground());
+}
+/**
+ * Draw a plain push button
+ * @param gc - GC to draw on
+ * @param xPos - x position the button is drawn at
+ * @param yPos - y position the button is drawn at
+ * @param size - size of the button
+ */
+void drawPlainButton(GC gc, int xPos, int yPos, int size) {
+ Color rightBottomColor = getForeground();
+ Color leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color rightBottomInnerColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
+ Color leftTopInnerColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
+ int upper = yPos;
+ int left = xPos;
+ int lower = yPos + size - 1;
+ int right = xPos + size - 1;
+
+ if (scrollButtonDown) { // draw the button in the pressed down state?
+ rightBottomColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
+ leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
+ rightBottomInnerColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ leftTopInnerColor = getForeground();
+ }
+ gc.fillRectangle(left, upper, right - left, lower - upper);
+ // draw right, bottom line in foreground color
+ gc.setForeground(rightBottomColor);
+ gc.drawLine(right, upper, right, lower);
+ gc.drawLine(left, lower, right, lower);
+
+ // draw left, top line in normal shadow (default light gray)
+ gc.setForeground(leftTopColor);
+ gc.drawLine(left, upper, left, lower - 1);
+ gc.drawLine(left, upper, right - 1, upper);
+
+ upper++;
+ left++;
+ lower--;
+ right--;
+ // draw right, bottom line in dark shadow (default dark gray)
+ gc.setForeground(rightBottomInnerColor);
+ gc.drawLine(right, upper, right, lower);
+ gc.drawLine(left, lower, right, lower);
+
+ // draw left, top line in high light shadow (default off white)
+ gc.setForeground(leftTopInnerColor);
+ gc.drawLine(left, upper, left, lower - 1);
+ gc.drawLine(left, upper, right - 1, upper);
+ gc.setForeground(getForeground());
+}
+/**
+ * Draw the buttons used to scroll tab items
+ */
+void drawScrollButtons(Event event) {
+ Rectangle buttonArea = getScrollButtonArea();
+ int buttonSize = buttonArea.width / 2;
+
+ drawPlainButton(event.gc, buttonArea.x, buttonArea.y, buttonSize);
+ drawPlainButton(event.gc, buttonArea.x + buttonSize, buttonArea.y, buttonSize);
+ if (scrollButtonDown) {
+ drawArrow(event.gc, buttonArea.x, buttonArea.y, buttonSize, true);
+ drawArrow(event.gc, buttonArea.x + buttonSize + 1, buttonArea.y, buttonSize + 1, false);
+ }
+ else {
+ drawArrow(event.gc, buttonArea.x - 1, buttonArea.y - 1, buttonSize, true);
+ drawArrow(event.gc, buttonArea.x + buttonSize, buttonArea.y - 1, buttonSize, false);
+ }
+}
+
+/**
+ * Make sure that the first tab is visible if scroll buttons are no
+ * longer drawn.
+ */
+void ensureRightFreeSpaceUsed() {
+ if (topTabIndex > 0 && !isTabScrolling()) {
+ topTabIndex = 0;
+ layoutItems();
+ redrawTabs();
+ }
+}
+
+/**
+ * If the tab at 'tabIndex' is not visible or partially covered by the tab
+ * scroll buttons and there is enough space to completely show the tab,
+ * the tab is scrolled to the left to make it fully visible.
+ */
+void ensureVisible(int tabIndex) {
+ if (items == null || tabIndex < 0 || tabIndex >= items.length) return;
+
+ TabItem tabItem = items[tabIndex];
+ int tabStopX = tabItem.x + tabItem.width;
+ if (isTabScrolling() && tabStopX >= getScrollButtonArea().x && tabIndex != topTabIndex) {
+ scrollRight();
+ }
+}
+/**
+ * Return the client area of the rectangle (in local coordinates).
+ */
+public Rectangle getClientArea() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle clientArea = super.getClientArea();
+
+ if (yClient == 0) { // position not calculated yet
+ layoutItems(); // calculate tab folder bounds as soon as there is tab data to use.
+ }
+ clientArea.x = xClient;
+ clientArea.y = yClient;
+ clientArea.width -= xClient + CLIENT_MARGIN_WIDTH + 1;
+ clientArea.height -= yClient + CLIENT_MARGIN_WIDTH + 1;
+ return clientArea;
+}
+/**
+ * Return the height of item images. All images are scaled to
+ * the height of the first image.
+ */
+int getImageHeight() {
+ return imageHeight;
+}
+/**
+ * Return the tab that is located at the specified index.
+ */
+public TabItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (!(0 <= index && index < getItemCount())) error(SWT.ERROR_INVALID_RANGE);
+ return items [index];
+}
+/**
+ * Return the number of tabs in the folder.
+ */
+public int getItemCount(){
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (items == null)
+ return 0;
+ else return items.length;
+}
+/**
+ * Return the tab items.
+ */
+public TabItem [] getItems() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (items == null) return new TabItem[0];
+ TabItem[] tabItems = new TabItem [items.length];
+ System.arraycopy(items, 0, tabItems, 0, items.length);
+ return tabItems;
+}
+/**
+ * Answer the area where the two scroll buttons are drawn.
+ */
+Rectangle getScrollButtonArea() {
+ return new Rectangle(
+ super.getClientArea().width - SCROLL_BUTTON_SIZE * 2, SELECTED_TAB_TOP_EXPANSION,
+ SCROLL_BUTTON_SIZE * 2, SCROLL_BUTTON_SIZE);
+}
+/**
+ * Return the selected tab item, or an empty array if there
+ * is no selection.
+ */
+public TabItem [] getSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (selectedIndex == -1) return new TabItem [0];
+ return new TabItem [] {items[selectedIndex]};
+}
+/**
+ * Return the index of the selected tab item, or -1 if there
+ * is no selection.
+ */
+public int getSelectionIndex() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return selectedIndex;
+}
+/**
+ * Handle the events that I have hooked on the canvas.
+ */
+void handleEvents (Event event){
+ switch (event.type) {
+ case SWT.Dispose:
+ doDispose();
+ break;
+ case SWT.Paint:
+ paint(event);
+ break;
+ case SWT.Resize:
+ resize();
+ break;
+ case SWT.MouseDown:
+ mouseDown(event);
+ break;
+ case SWT.MouseUp:
+ mouseUp(event);
+ break;
+ default:
+ break;
+ }
+}
+/**
+ * Return the index of the specified tab or -1 if the tab is not
+ * in the receiver.
+ */
+public int indexOf(TabItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (item == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (items != null) {
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == item) return i;
+ }
+ }
+ return -1;
+}
+/**
+ * Answer true when the left scroll button was clicked with mouse button 1.
+ */
+boolean isLeftButtonHit(Event event) {
+ Rectangle buttonArea = getScrollButtonArea();
+
+ buttonArea.width /= 2;
+ return isTabScrolling() && event.button == 1 && buttonArea.contains(event.x, event.y);
+}
+/**
+ * Answer true when the right scroll button was clicked with mouse button 1.
+ */
+boolean isRightButtonHit(Event event) {
+ Rectangle buttonArea = getScrollButtonArea();
+ int buttonSize = buttonArea.width / 2;
+
+ buttonArea.x += buttonSize;
+ buttonArea.width = buttonSize;
+ return isTabScrolling() && event.button == 1 && buttonArea.contains(event.x, event.y);
+}
+/**
+ * Answer true if not all tabs can be visible in the receive
+ * thus requiring the scroll buttons to be visible.
+ */
+boolean isTabScrolling() {
+ boolean isVisible = false;
+
+ if (items != null && items.length > 0) {
+ TabItem tabItem = items[items.length-1];
+ int tabStopX = tabItem.x + tabItem.width;
+ tabItem = items[0];
+ if (tabStopX - tabItem.x > super.getClientArea().width) {
+ isVisible = true; // not all tabs fit in the client area
+ }
+ }
+ return isVisible;
+}
+/**
+ * 'item' has changed. Store the image size if this is the
+ * first item with an image.
+ */
+void itemChanged(TabItem item) {
+ Image itemImage = item.getImage();
+ boolean isTabScrolling = isTabScrolling();
+
+ if (imageHeight == -1 && itemImage != null) {
+ imageHeight = itemImage.getBounds().height;
+ }
+ layoutItems();
+ redrawTabs();
+ // redraw scroll buttons if they just became visible
+ // fixes 1G5X1QL
+ if (isTabScrolling() != isTabScrolling && isTabScrolling == false) {
+ redrawScrollButtons();
+ }
+}
+/**
+ * Layout the items and store the client area size.
+ */
+void layoutItems() {
+ int x = SELECTED_TAB_HORIZONTAL_EXPANSION;
+ int y = SELECTED_TAB_TOP_EXPANSION;
+ int tabHeight = 0;
+
+ if (items != null) {
+ GC gc = new GC(this);
+ for (int i=topTabIndex - 1; i>=0; i--) { // if the first visible tab is not the first tab
+ TabItem tab = items[i];
+ tab.width = tab.preferredWidth(gc);
+ tab.height = tab.preferredHeight(gc);
+ x -= tab.width; // layout tab items from right to left thus making them invisible
+ tab.x = x;
+ tab.y = y;
+ if (tab.height > tabHeight) tabHeight = tab.height;
+ }
+ x = SELECTED_TAB_HORIZONTAL_EXPANSION;
+ for (int i=topTabIndex; i<items.length; i++) { // continue laying out remaining, visible items left to right
+ TabItem tab = items[i];
+ tab.x = x;
+ tab.y = y;
+ tab.width = tab.preferredWidth(gc);
+ tab.height = tab.preferredHeight(gc);
+ x = x + tab.width;
+ if (tab.height > tabHeight) tabHeight = tab.height;
+ }
+ gc.dispose();
+ }
+ xClient = CLIENT_MARGIN_WIDTH;
+ yClient = CLIENT_MARGIN_WIDTH + tabHeight;
+ TabItem selection[] = getSelection();
+ if (selection.length > 0)
+ selection[0].expand(SELECTED_TAB_HORIZONTAL_EXPANSION, SELECTED_TAB_TOP_EXPANSION, SELECTED_TAB_HORIZONTAL_EXPANSION, 0);
+}
+/**
+ * A mouse button was pressed down.
+ * If one of the tab scroll buttons was hit, scroll in the appropriate
+ * direction.
+ * If a tab was hit select the tab.
+ */
+void mouseDown(Event event) {
+ if (items == null) return;
+ if (isLeftButtonHit(event)) {
+ scrollButtonDown = true;
+ redrawHitButton(event);
+ scrollLeft();
+ }
+ else
+ if (isRightButtonHit(event)) {
+ scrollButtonDown = true;
+ redrawHitButton(event);
+ scrollRight();
+ }
+ else {
+ for (int i=0; i<items.length; i++) {
+ if (items[i].getBounds().contains(new Point(event.x, event.y))) {
+ setSelectionNotify(i);
+ return;
+ }
+ }
+ }
+}
+/**
+ * A mouse button was released.
+ */
+void mouseUp(Event event) {
+ if (scrollButtonDown && event.button == 1) {
+ scrollButtonDown = false;
+ redrawHitButton(event);
+ }
+}
+/**
+ * Paint the receiver.
+ */
+void paint(Event event) {
+ // Draw the unselected tabs first.
+ for (int i=0; i<getItemCount(); i++) {
+ if (i != selectedIndex && event.getBounds().intersects(items[i].getBounds())) {
+ items[i].paint(event.gc, false);
+ }
+ }
+ drawBorder(event);
+ // Selected tab comes last since selected tabs overlay adjacent tabs
+ // and the border
+ if (selectedIndex != -1) {
+ items[selectedIndex].paint(event.gc, true);
+ }
+ if (isTabScrolling()) drawScrollButtons(event);
+}
+/**
+ * Redraw the area of the receiver specified by x, y, width, height.
+ * Don't redraw the scroll buttons to avoid flashing.
+ */
+void redraw (int x, int y, int width, int height) {
+ Rectangle buttonArea = getScrollButtonArea();
+ boolean fixScrollButtons = false;
+
+ if (isTabScrolling()) {
+ if (x > buttonArea.x) {
+ x = buttonArea.x;
+ fixScrollButtons = true;
+ }
+ if (x + width > buttonArea.x) {
+ width = buttonArea.x - x;
+ fixScrollButtons = true;
+ }
+ }
+ redraw(x, y, width, height, false);
+ if (fixScrollButtons) {
+ redraw(buttonArea.x, 0, buttonArea.width, buttonArea.y, false); // redraw space above scroll buttons
+ if (buttonArea.height < getClientArea().y) {
+ int redrawY = buttonArea.y + buttonArea.height;
+ redraw(
+ buttonArea.x, redrawY,
+ buttonArea.width, getClientArea().y - redrawY, false); // redraw space below scroll buttons
+ }
+ }
+}
+/**
+ * Redraw the scroll button that was pressed down
+ */
+void redrawHitButton(Event event) {
+ Rectangle scrollButtonArea = getScrollButtonArea();
+ int scrollButtonWidth = scrollButtonArea.width / 2;
+
+ if (isLeftButtonHit(event)) {
+ redraw(
+ scrollButtonArea.x, scrollButtonArea.y,
+ scrollButtonWidth, scrollButtonArea.height, false);
+ }
+ else
+ if (isRightButtonHit(event)) {
+ redraw(
+ scrollButtonArea.x + scrollButtonWidth, scrollButtonArea.y,
+ scrollButtonWidth, scrollButtonArea.height, false);
+ }
+}
+/**
+ * Redraw both scroll buttons
+ */
+void redrawScrollButtons() {
+ Rectangle scrollButtonArea = getScrollButtonArea();
+
+ redraw(
+ scrollButtonArea.x, scrollButtonArea.y,
+ scrollButtonArea.width, scrollButtonArea.height, false);
+}
+/**
+ * Redraw the tabs at the specified indexes.
+ */
+void redrawSelectionChange(int oldSelection, int newSelection) {
+ if (oldSelection != -1) {
+ TabItem tab = items[oldSelection];
+ // since the tab used to be selected, we need to clear its old expanded size
+ redraw(tab.x - SELECTED_TAB_HORIZONTAL_EXPANSION,
+ tab.y - SELECTED_TAB_TOP_EXPANSION,
+ tab.width + 2 * SELECTED_TAB_HORIZONTAL_EXPANSION,
+ tab.height + SELECTED_TAB_TOP_EXPANSION);
+ }
+ if (newSelection != -1) {
+ TabItem tab = items[newSelection];
+ // this tab is already at the expanded size
+ redraw(tab.x, tab.y, tab.width, tab.height);
+ }
+ // make sure the tab is repainted before the new page is made visible.
+ // The latter could take a long time and delay the screen update.
+ update();
+}
+/**
+ * Redraw the whole tab area
+ */
+void redrawTabs() {
+ redraw(0, 0, super.getClientArea().width, getClientArea().y);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection, listener);
+}
+/**
+ * The widget was resized. Adjust the size of the currently selected page.
+ */
+void resize() {
+ if (selectedIndex != -1) {
+ Control control = items[selectedIndex].getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setBounds(getClientArea());
+ }
+ }
+ ensureRightFreeSpaceUsed();
+}
+
+/**
+ * Scroll the tab items to the left.
+ */
+void scrollLeft() {
+ if (topTabIndex > 0) {
+ --topTabIndex;
+ layoutItems();
+ redrawTabs();
+ }
+}
+/**
+ * Scroll the tab items to the right.
+ */
+void scrollRight() {
+ if (items != null && items.length > 0 && topTabIndex < items.length - 1) {
+ TabItem lastTabItem = items[items.length-1];
+ int tabStopX = lastTabItem.x + lastTabItem.width;
+ if (tabStopX > super.getClientArea().width - SCROLL_BUTTON_SIZE * 2) {
+ topTabIndex++;
+ layoutItems();
+ redrawTabs();
+ }
+ }
+}
+/**
+ * The font is changing. Layout the tab items.
+ */
+public void setFont(Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (font != null && font.equals(getFont())) return;
+ super.setFont(font);
+ layoutItems();
+ redrawTabs();
+}
+/**
+ * Set the selection to the tab at the specified index.
+ */
+public void setSelection(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int oldIndex = selectedIndex;
+
+ if (selectedIndex == index || index >= getItemCount()) return;
+ if (selectedIndex != -1) {
+ Control control = items[selectedIndex].control;
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ }
+ if (index < 0) {
+ index = -1; // make sure the index is always -1 if it's negative
+ }
+ selectedIndex = index;
+ layoutItems();
+ ensureVisible(index);
+ redrawSelectionChange(oldIndex, index);
+ if (index >= 0) {
+ Control control = items[index].control;
+ if (control != null && !control.isDisposed()) {
+ control.setBounds(getClientArea());
+ control.setVisible(true);
+ }
+ }
+}
+/**
+ * Set the selection to the specified items.
+ */
+public void setSelection(TabItem selectedItems[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (selectedItems == null) error(SWT.ERROR_NULL_ARGUMENT);
+ int index = -1;
+ if (selectedItems.length > 0) {
+ index = indexOf(selectedItems[0]);
+ }
+ setSelection(index);
+}
+/**
+ * Set the selection to the tab at the specified index.
+ */
+void setSelectionNotify(int index) {
+ int oldSelectedIndex = selectedIndex;
+
+ setSelection(index);
+ if (selectedIndex != oldSelectedIndex && selectedIndex != -1) {
+ Event event = new Event();
+ event.item = getSelection()[0];
+ notifyListeners(SWT.Selection, event);
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabItem.java
new file mode 100755
index 0000000000..012f718cb6
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TabItem.java
@@ -0,0 +1,337 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class emulates a windows TabItem, which represents a tab
+ * that can be used to switch to a page in the TabbedFolder.
+ */
+
+public /*final*/ class TabItem extends Item {
+ TabFolder parent;
+ int x,y,width,height = 0;
+ String toolTipText;
+ Control control; // the tab page
+
+ // internal constants
+ static final int LEFT_HORIZONTAL_MARGIN = 8;
+ static final int RIGHT_HORIZONTAL_MARGIN = 2;
+ static final int VERTICAL_MARGIN = 1; // space between tab shadow and tab content
+ static final int ICON_MARGIN = 6;
+ static final int SHADOW_WIDTH = 2; // width of the tab shadow
+ static final int DEFAULT_TEXT_WIDTH = 36; // preferred text width if there is no text.
+ // Used for preferred item width calculation
+/**
+ * Construct a TabItem with the specified parent and style.
+ */
+public TabItem (TabFolder parent, int style) {
+ this(parent, style, parent.getItemCount());
+}
+/**
+ * Construct a TabItem with the specified parent and style, inserted at
+ * the specified index.
+ */
+public TabItem (TabFolder parent, int style, int index) {
+ super (parent, style);
+ parent.createChild (this, index);
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event event) {disposeItem();}});
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * Dispose the receiver.
+ */
+void disposeItem () {
+ parent.destroyChild(this);
+ parent = null;
+ control = null;
+ toolTipText = null;
+}
+/**
+ * Expand the receiver's bounds by the specified number of pixels on
+ * the left,top,right,and bottom.
+ */
+void expand(int left, int top, int right, int bottom) {
+ if (hasLocation()) {
+ x = x - left;
+ y = y - top;
+ width = width + left + right;
+ height = height + top + bottom;
+ }
+}
+/**
+ * Return the bounds of the TabItem.
+ */
+Rectangle getBounds () {
+ return new Rectangle(x, y, width, height);
+}
+/**
+* Gets the control.
+* <p>
+* @return the control
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Control getControl () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return control;
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ if (parent == null) error(SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay();
+}
+/**
+ * Return the parent of the TabItem.
+ */
+public TabFolder getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return parent;
+}
+/**
+* Gets the tool tip text.
+* <p>
+* @return the tool tip text.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getToolTipText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return toolTipText;
+}
+/**
+ * Answer true if the receiver has been layed out.
+ */
+boolean hasLocation() {
+ return !(width == 0 && height == 0 && x == 0 && y == 0);
+}
+/**
+ * Answer the image height.
+ */
+private int imageHeight() {
+ Image image = getImage();
+
+ if (parent.getImageHeight() != -1) {
+ return parent.getImageHeight();
+ } else if (image != null) {
+ return image.getBounds().height;
+ }
+ else {
+ return 0;
+ }
+}
+/**
+ * Answer the icon width.
+ */
+private int imageWidth() {
+ Image image = getImage();
+
+ if (image != null) {
+ return image.getBounds().width;
+ } else {
+ return 0;
+ }
+}
+/**
+ * Paint the receiver.
+ */
+void paint(GC gc, boolean isSelected) {
+ // high light colored line across left and top
+ gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
+ gc.drawLine(x, y + height - 2, x, y + 2);
+ gc.drawLine(x, y + 2, x + 2, y);
+ gc.drawLine(x + 2, y, x + width - 3, y);
+
+ // light color next to the left and below the top line.
+ // Since tabs expand horizontally when selected, we actually draw
+ // the background color to erase any debris from a selected tab.
+ gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
+ gc.drawLine(x + 1, y + height - 2, x + 1, y + 2);
+ gc.drawLine(x + 2, y + 1, x + width - 3, y + 1);
+
+ // dark colored line at right
+ gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
+ gc.drawLine(x + width - 1, y + 2, x + width - 1, y + height - 1);
+ // dark pixel on top of shadowed line, inside dark line
+ gc.drawLine(x + width - 2, y + 1, x + width - 2, y + 1);
+
+ // shadowed line on right inside the dark line
+ gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
+ gc.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 1);
+
+ // icon and bitmap. Should probably be checking style bits to determine
+ // exactly what to paint. Do we just draw the icon when the icon/text combination
+ // is too wide to fit all tabs?
+ gc.setForeground(parent.getForeground());
+ int xDraw = x + LEFT_HORIZONTAL_MARGIN;
+ int yCenter;
+ int decorationHeight = SHADOW_WIDTH * 2 + VERTICAL_MARGIN * 2;
+ Image image = getImage();
+ Rectangle sourceBounds = null;
+ if (image != null) {
+ sourceBounds = image.getBounds();
+ yCenter = y + SHADOW_WIDTH + VERTICAL_MARGIN + (height - decorationHeight - imageHeight()) / 2;
+ gc.drawImage(
+ image,
+ sourceBounds.x, sourceBounds.y, sourceBounds.width, sourceBounds.height,
+ xDraw, yCenter, sourceBounds.width, parent.getImageHeight());
+ }
+ xDraw = xDraw + ICON_MARGIN;
+ if (sourceBounds != null) {
+ xDraw += sourceBounds.width;
+ }
+ yCenter = y + SHADOW_WIDTH + VERTICAL_MARGIN + (height - decorationHeight - textHeight(gc)) / 2;
+ gc.drawString(getText(), xDraw, yCenter);
+}
+/**
+ * Answer the preferred height of the receiver for the GC.
+ */
+int preferredHeight(GC gc) {
+ int height = textHeight(gc);
+ if (imageHeight() > height) height = imageHeight();
+ height += VERTICAL_MARGIN * 2 + SHADOW_WIDTH * 2;
+ return height;
+}
+/**
+ * Answer the preferred width of the receiver for the GC.
+ */
+int preferredWidth(GC gc) {
+ return imageWidth() + textWidth(gc) + LEFT_HORIZONTAL_MARGIN +
+ RIGHT_HORIZONTAL_MARGIN + ICON_MARGIN + SHADOW_WIDTH * 2;
+}
+/**
+* Sets the control.
+* <p>
+* @param control the new control
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setControl (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (control != null && control.parent != parent) {
+ error (SWT.ERROR_INVALID_PARENT);
+ }
+ Control oldControl = this.control, newControl = control;
+ this.control = control;
+ int index = parent.indexOf (this);
+ if (index != parent.getSelectionIndex ()) {
+ if (newControl != null) newControl.setVisible(false);
+ return;
+ }
+ if (newControl != null) {
+ newControl.setBounds (parent.getClientArea ());
+ newControl.setVisible (true);
+ }
+ if (oldControl != null) oldControl.setVisible (false);
+}
+/**
+* Sets the image.
+* <p>
+* @param image the new image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Image oldImage = this.image;
+
+ super.setImage(image);
+ if (image == null || !image.equals(oldImage)) {
+ parent.itemChanged(this);
+ }
+}
+/**
+* Set the widget text.
+*
+* PARAMETERS
+*
+* string - the new label for the widget
+*
+* REMARKS
+*
+* This method sets the widget label. The label may include
+* the mnemonic characters but must not contain line delimiters.
+*
+**/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ String oldText = text;
+
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText(string);
+ if (!string.equals(oldText)) {
+ parent.itemChanged(this);
+ }
+}
+/**
+* Sets the tool tip text.
+* <p>
+* @param string the new tool tip text (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setToolTipText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ toolTipText = string;
+}
+/**
+ * Answer the text height.
+ */
+private int textHeight(GC gc) {
+ String text = getText();
+
+ if (text == null) {
+ return 0;
+ } else {
+ return gc.stringExtent(text).y;
+ }
+}
+/**
+ * Answer the text width.
+ */
+private int textWidth(GC gc) {
+ String text = getText();
+ int textWidth = 0;
+
+ if (text != null) {
+ textWidth = gc.stringExtent(text).x;
+ }
+ if (textWidth == 0) {
+ textWidth = DEFAULT_TEXT_WIDTH;
+ }
+ return textWidth;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Table.java
new file mode 100755
index 0000000000..c0897e483c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Table.java
@@ -0,0 +1,2361 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class display rows of items arranged in one or more
+ * columns. Items can be selected, columns can be resized.
+ */
+public /*final*/ class Table extends SelectableItemWidget {
+ private static final int COLUMN_RESIZE_OFFSET = 7; // offset from the start and end of each
+ // column at which the resize cursor is displayed
+ // if the mouse is in the column header
+ static final String DOT_STRING = "..."; // used to indicate truncated item labels
+
+ private Header tableHeader;
+ private Control focusProxy; // used as a proxy to take focus in place of the table.
+ // The latter can't get focus because it has a child
+ // (the header widget). The header widget can't be used
+ // as a focus widget because it may be hidden.
+ private Vector items;
+ private Vector columns;
+ private boolean drawGridLines = false;
+ private boolean hasColumnFocus = false; // true if a column currently has focus
+ private boolean firstColumnImage = false; // true if any item in the first column has an image
+ private int columnResizeX; // last position of the cursor in a column resize operation
+ private Cursor columnResizeCursor; // cursor displayed when a column resize is in progress.
+ // Need to keep reference to the cursor in order to dispose it.
+ private boolean isColumnResizeCursor = false; // set to true if the column resize cursor is active
+ private TableColumn resizeColumn; // column that is currently being resized
+ private TableColumn fillColumn; // column used to fill up space that is not used
+ // by user defined columns
+ private TableColumn defaultColumn; // Default column that is created as soon as the table is created.
+ // Fix for 1FUSJY5
+ private int dotsWidth = -1; // width of the static String dots (see above)
+/**
+ * Create a new instance of Table.
+ * @param parent - the parent window of the new instance
+ * @param style - window style for the new instance
+ */
+public Table(Composite parent, int style) {
+ // use NO_MERGE_PAINTS to avoid flashing during column and widget resize redraw
+ super(parent, checkStyle(style| SWT.NO_MERGE_PAINTS));
+}
+/**
+ * Add 'column' to the receiver.
+ * @param column - new table column that should be added to
+ * the receiver
+ */
+void addColumn(TableColumn column) {
+ int index = column.getIndex();
+
+ getColumnVector().insertElementAt(column, index);
+ // has the column been inserted (vs. appended)?
+ if (index < getColumnCount() - 1) {
+ reindexColumns(index + 1);
+ }
+ // is there more than one user created column?
+ // There always is the data and visual of the default column
+ // so we don't need to create those for the first user column
+ if (getColumnCount() > 1) {
+ insertColumnData(column);
+ }
+ else { // first user created column
+ setContentWidth(0); // pretend it's ground zero for column resizings
+ redraw(); // redraw the table and header. The default column
+ getHeader().redraw(); // won't be drawn anymore, because there now is a user created table.
+ }
+ insertColumnVisual(column);
+}
+/**
+ * Add 'item' to the receiver.
+ * @param item - new table item that should be added to
+ * the receiver
+ * @param index - position the new item should be inserted at
+ */
+void addItem(TableItem item, int index) {
+ Vector items = getItemVector();
+
+ if (index < 0 || index > getItemCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ addingItem(item, index);
+ item.setIndex(index);
+ if (index < items.size()) {
+ for (int i = index; i < items.size(); i++) {
+ TableItem anItem = (TableItem) items.elementAt(i);
+ anItem.setIndex(anItem.getIndex() + 1);
+ }
+ items.insertElementAt(item, index);
+ }
+ else {
+ items.addElement(item);
+ }
+ addedItem(item, index);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*/
+public void addSelectionListener (SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ typedListener = new TypedListener(listener);
+ addListener(SWT.Selection, typedListener);
+ addListener(SWT.DefaultSelection, typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * The width of 'column' is about to change.
+ * Adjust the position of all columns behind it.
+ */
+void columnChange(TableColumn column, Rectangle newBounds) {
+ Rectangle columnBounds = column.getBounds();
+ Rectangle clientArea = getClientArea();
+ int oldXPosition = columnBounds.x + columnBounds.width;
+ int newXPosition = newBounds.x + newBounds.width;
+ int widthChange = newBounds.width - columnBounds.width;
+ int headerHeight = getHeaderHeight();
+ int columnIndex = column.getIndex();
+
+ if (widthChange != 0) {
+ if (columnIndex != TableColumn.FILL) {
+ if (getLinesVisible() == true) {
+ oldXPosition -= getGridLineWidth(); // include vertical grid line when scrolling resized column.
+ newXPosition -= getGridLineWidth();
+ }
+ scroll( // physically move all following columns
+ newXPosition, headerHeight, // destination x, y
+ oldXPosition, headerHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+ }
+ column.internalSetBounds(newBounds);
+ if (columnIndex != TableColumn.FILL) {
+ resetTableItems(columnIndex);
+ moveColumns(columnIndex + 1, widthChange); // logically move all following columns (set their bounds)
+ setContentWidth(getContentWidth() + widthChange); // set the width of the receiver's content
+ claimRightFreeSpace();
+ resizeRedraw(column, columnBounds.width, newBounds.width);
+ }
+ }
+ getHeader().widthChange(columnIndex, widthChange);
+}
+/**
+ * The mouse pointer was double clicked on the receiver.
+ * Handle the event according to the position of the mouse click
+ * and the modifier key that was pressed, if any.
+ * @param event - the mouse event
+ */
+void columnMouseDoubleClick(Event event) {
+ int itemHeight = getItemHeight();
+ int itemIndex;
+ TableItem hitItem;
+ TableColumn hitColumn = getColumnAtX(event.x);
+ Event columnDblClickEvent;
+
+ if (isFocusControl() == false) {
+ setFocus(); // focus proxy gets focus here because it's the first child of the receiver
+ }
+ if (hitColumn != null) {
+ itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
+ hitItem = (TableItem) getVisibleItem(itemIndex);
+ if (hitItem != null &&
+ hitColumn.getIndex() == TableColumn.FIRST) {
+ if (hitItem.isSelectionHit(event.x) == true) {
+ columnDblClickEvent = new Event();
+ columnDblClickEvent.item = hitItem;
+ notifyListeners(SWT.DefaultSelection, columnDblClickEvent);
+ }
+ }
+ else {
+ deselectAll();
+ }
+ }
+}
+/**
+ * The mouse pointer was pressed down on the receiver.
+ * Handle the event according to the position of the mouse click
+ * and the modifier key that was pressed, if any.
+ * @param event - the mouse event
+ */
+void columnMouseDown(Event event) {
+ int itemHeight = getItemHeight();
+ int itemIndex;
+ TableItem hitItem;
+ TableColumn hitColumn = getColumnAtX(event.x);
+
+ if (isFocusControl() == false) {
+ setFocus(); // focus proxy gets focus here because it's the first child of the receiver
+ }
+ if (hitColumn != null) {
+ itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
+ hitItem = (TableItem) getVisibleItem(itemIndex);
+ if (hitItem != null) {
+ if (hitItem.isSelectionHit(event.x) == true) {
+ doMouseSelect(hitItem, itemIndex, event.stateMask, event.button);
+ }
+ else
+ if (hitItem.isCheckHit(new Point(event.x, event.y)) == true) {
+ doCheckItem(hitItem);
+ }
+ }
+ else {
+ deselectAll();
+ }
+ }
+}
+/**
+ * The mouse pointer was moved over the receiver.
+ * Reset the column resize cursor if it was active.
+ * @param event - the mouse event
+ */
+void columnMouseMove(Event event) {
+ if (isColumnResizeStarted() == false) {
+ setColumnResizeCursor(false);
+ }
+}
+/**
+ * Answer the size of the receiver needed to display all or
+ * the first 50 items whichever is less.
+ */
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Point size = super.computeSize(wHint, hHint, changed);
+ Point headerSize;
+ GC gc;
+ final int WidthCalculationCount = Math.min(getItemCount(), 50); // calculate item width for the first couple of items only
+ TableItem item;
+ Image itemImage;
+ String itemText;
+ int width;
+ int newItemWidth = 0;
+
+ if (getHeaderVisible() == true) {
+ headerSize = getHeader().computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
+ size.y += headerSize.y;
+ }
+ if (getContentWidth() == 0 && WidthCalculationCount > 0) {
+ gc = new GC(this);
+ for (int i = 0; i < WidthCalculationCount; i++) {
+ item = getItem(i);
+ if (item == null) {
+ break; // no more items
+ }
+ itemImage = item.getImage();
+ itemText = item.getText();
+ width = 0;
+ if (itemImage != null) {
+ width += itemImage.getBounds().width;
+ }
+ if (itemText != null) {
+ width += gc.stringExtent(itemText).x;
+ }
+ newItemWidth = Math.max(newItemWidth, width);
+ }
+ if (newItemWidth > 0) {
+ size.x = newItemWidth;
+ }
+ gc.dispose();
+ }
+ return size;
+}
+/**
+ * Deselect the items identified by the indices stored
+ * in 'indices'.
+ * A SWT.Selection event will not be sent.
+ * @param indices - indices of the items to deselect
+ */
+public void deselect(int indices[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = null;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ for (int i = 0; i < indices.length; i++) {
+ item = getVisibleItem(indices[i]);
+ if (item != null) {
+ deselect(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Deselect the item identified by 'index'.
+ * A SWT.Selection event will not be sent.
+ * @param index - index of the item to deselect
+ */
+public void deselect(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = getVisibleItem(index);
+
+ if (item != null) {
+ deselect(item);
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Deselect a range of items starting at index 'start'
+ * and stopping at index 'end'. Indices that are out of
+ * range are ignored. Indexing is zero based.
+ * @param start - the start of the range
+ * @param end - the end of the range
+ */
+public void deselect(int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = null;
+
+ for (int i=start; i<=end; i++) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ deselect(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Deselect all items of the receiver.
+ */
+public void deselectAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ deselectAllExcept((SelectableItem) null);
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ Vector items = getItemVector();
+
+ super.doDispose();
+ while (items.size() > 0) { // TableItem objects are removed from vector during dispose()
+ ((TableItem) items.lastElement()).dispose();
+ }
+ items = getColumnVector();
+ while (items.size() > 0) { // TableColumn objects are removed from vector during dispose()
+ ((TableColumn) items.lastElement()).dispose();
+ }
+ resizeColumn = null;
+ fillColumn = null;
+ defaultColumn = null;
+ if (columnResizeCursor != null) {
+ columnResizeCursor.dispose();
+ }
+}
+/**
+ * Draw a line tracking the current position of a column
+ * resize operation.
+ * @param xPosition - x coordinate to draw the line at
+ */
+void drawColumnResizeLine(int xPosition) {
+ GC gc = new GC(this);
+ int lineHeight = getClientArea().height;
+
+ redraw(getColumnResizeX(), 0, 1, lineHeight, false);
+ setColumnResizeX(xPosition);
+ gc.drawLine(xPosition, 0, xPosition, lineHeight);
+ gc.dispose();
+}
+/**
+ * Draw the grid lines for the receiver.
+ * @param event - Paint event triggering the drawing operation.
+ * @param drawColumns - The table columns for which the grid
+ * lines should be drawn.
+ */
+void drawGridLines(Event event, Enumeration drawColumns) {
+ GC gc = event.gc;
+ Color oldForeground = getForeground();
+ Rectangle columnBounds;
+ TableColumn column;
+ int lineWidth = getGridLineWidth();
+ int itemHeight = getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int lineXPosition;
+ int lineYPosition = headerHeight + ((event.y-headerHeight) / itemHeight) * itemHeight;
+ int lineYStopPosition = event.y + event.height;
+
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
+ // Draw the horizontal lines
+ if (itemHeight > 0) {
+ while (lineYPosition < lineYStopPosition) {
+ gc.drawLine(
+ event.x, lineYPosition + itemHeight - lineWidth,
+ event.x + event.width, lineYPosition + itemHeight - lineWidth);
+ lineYPosition += itemHeight;
+ }
+ }
+ // Draw the vertical lines at the right border of each column except the fill column
+ while (drawColumns.hasMoreElements() == true) {
+ column = (TableColumn) drawColumns.nextElement();
+ if (column.getIndex() != TableColumn.FILL) {
+ columnBounds = column.getBounds();
+ lineXPosition = columnBounds.x + columnBounds.width - lineWidth;
+ gc.drawLine(
+ lineXPosition, event.y,
+ lineXPosition, event.y + event.height);
+ }
+ }
+ gc.setForeground(oldForeground);
+}
+/**
+ * Draw a filled rectangle indicating the selection state of 'item'
+ * If 'item' is selected the rectangle will be filled with the
+ * selection background color. Otherwise the rectangle will be filled
+ * with the background color to remove selection.
+ * The selection color depends on whether the table widget has
+ * focus or not. See getSelectionBackgroundColor() for details.
+ * The rectangle is drawn in either the first column or in all columns
+ * for full row select.
+ * @param item - item for which the selection state should be drawn
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @param extent - extent of the selection rectangle.
+ */
+void drawSelection(TableItem item, GC gc, Point position, Point extent) {
+ if (item.isSelected() == true) {
+ gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
+ }
+ gc.fillRectangle(position.x, position.y, extent.x, extent.y);
+ if (item.isSelected() == true) {
+ gc.setBackground(getBackground());
+ }
+}
+/**
+ * If the receiver has input focus draw a rectangle enclosing
+ * the label of 'item' to indicate the input focus.
+ * The rectangle is drawn in either the first column or in all columns
+ * for full row select.
+ * @param item - item for which the selection state should be drawn
+ * @param gc - GC to draw on.
+ */
+void drawSelectionFocus(TableItem item, GC gc) {
+ Point extent = item.getSelectionExtent();
+ Point position = new Point(
+ item.getImageStopX(TableColumn.FIRST) + getHorizontalOffset(),
+ getRedrawY(item));
+
+ gc.drawFocus(position.x, position.y, extent.x, extent.y);
+}
+
+/** Not used right now. Replace focusIn/focusOut with this method once
+ * Display.getFocusWindow returns the new focus window on FocusOut event
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusChange(Event event) {
+ TableColumn focusColumn = getColumnAtX(event.x);
+ Control focusWindow = getDisplay().getFocusControl();
+
+ if (focusWindow == getFocusWindow() &&
+ focusColumn != null &&
+ focusColumn.getIndex() == TableColumn.FIRST) {
+ hasColumnFocus = true;
+ }
+ else {
+ hasColumnFocus = false;
+ }
+ super.focusChange(event);
+ event.widget = this; // the ficus event is never sent to the table itself but only to the focus widget
+ notifyListeners(event.type, event); // make sure that listeners of the table get the focus event, too
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * @param event - the focus change event
+ */
+void focusIn(Event event) {
+ TableColumn focusColumn = getColumnAtX(event.x);
+
+ if (focusColumn != null &&
+ focusColumn.getIndex() == TableColumn.FIRST) {
+ hasColumnFocus = true;
+ }
+ super.focusIn(event);
+ event.widget = this; // the focus event is never sent to the table itself but only to the focus widget
+ notifyListeners(event.type, event); // make sure that listeners of the table get the focus event, too
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * @param event - the focus change event
+ */
+void focusOut(Event event) {
+ TableColumn focusColumn = getColumnAtX(event.x);
+
+ if (focusColumn != null &&
+ focusColumn.getIndex() == TableColumn.FIRST) {
+ hasColumnFocus = false;
+ }
+ super.focusOut(event);
+ event.widget = this; // the focus event is never sent to the table itself but only to the focus widget
+ notifyListeners(event.type, event); // make sure that listeners of the table get the focus event, too
+}
+/**
+ * Answer the TableColumn at 'index'.
+ */
+public TableColumn getColumn(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector columns = getColumnVector();
+
+ if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
+ if (index < 0 || index >= columns.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+
+ return (TableColumn) columns.elementAt(index);
+}
+/**
+ * Return the column located at 'xPosition' in the widget.
+ * Return null if xPosition is outside the widget.
+ * @param xPosition - position of the desired column
+ */
+TableColumn getColumnAtX(int xPosition) {
+ Enumeration columns = internalGetColumnVector().elements();
+ TableColumn column;
+ TableColumn hitColumn = null;
+ Rectangle bounds;
+
+ while (columns.hasMoreElements() == true && hitColumn == null) {
+ column = (TableColumn) columns.nextElement();
+ bounds = column.getBounds();
+ if ((xPosition >= bounds.x) &&
+ (xPosition <= bounds.x + bounds.width)) {
+ hitColumn = column;
+ }
+ }
+ if (hitColumn == null) {
+ column = getFillColumn();
+ bounds = column.getBounds();
+ if ((xPosition >= bounds.x) &&
+ (xPosition <= bounds.x + bounds.width)) {
+ hitColumn = column;
+ }
+ }
+ return hitColumn;
+}
+/**
+ * Answer the number of columns in the receiver.
+ */
+public int getColumnCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector columns = getColumnVector();
+ int count = 0;
+
+ if (columns != null) {
+ count = columns.size();
+ }
+ return count;
+}
+/** Replace CURSOR_SIZEWE with real column resize cursor
+ * (no standard cursor-have to load from file)
+ * Answer the cursor displayed during a column resize
+ * operation.
+ * Lazy initialize the cursor since it may never be needed.
+ */
+Cursor getColumnResizeCursor() {
+ if (columnResizeCursor == null) {
+ columnResizeCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEWE);
+ }
+ return columnResizeCursor;
+}
+/**
+ * Answer the current position of the mouse cursor during
+ * a column resize operation.
+ */
+int getColumnResizeX() {
+ return columnResizeX;
+}
+/**
+ * Answer an Array containing all columns of receiver except
+ * the fill column to the right of all content columns.
+ */
+public TableColumn [] getColumns() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector columns = getColumnVector();
+ TableColumn columnArray[] = new TableColumn[columns.size()];
+
+ columns.copyInto(columnArray);
+ return columnArray;
+}
+/**
+ * Answer a Vector containing all columns of receiver except
+ * the fill column to the right of all content columns.
+ */
+Vector getColumnVector() {
+ return columns;
+}
+/**
+ * Return the default column that is created as soon as the table
+ * is created.
+ * Fix for 1FUSJY5
+ */
+TableColumn getDefaultColumn() {
+ return defaultColumn;
+}
+/**
+ * Answer the width of the replacement String used to indicate
+ * truncated items.
+ * Cached to speed up calculation of truncated items.
+ * @param gc - GC used to measure the width of the replacement
+ * String
+ */
+int getDotsWidth(GC gc) {
+ if (dotsWidth == -1) {
+ dotsWidth = gc.stringExtent(DOT_STRING).x;
+ }
+ return dotsWidth;
+}
+/**
+ * Answer the column used to occupy any space left to the
+ * right of all the user created columns.
+ */
+TableColumn getFillColumn() {
+ return fillColumn;
+}
+/**
+ * Answer the widget that is used to hold focus for the receiver.
+ * The receiver can not get focus itself because it has children.
+ */
+Control getFocusWindow() {
+ return focusProxy;
+}
+/**
+* Gets the width of a grid line.
+* <p>
+* @return the width of a grid line
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getGridLineWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return 1;
+}
+/**
+ * Answer the table header widget.
+ */
+Header getHeader() {
+ return tableHeader;
+}
+/**
+ * Answer the header height or 0 if the header is not visible.
+ */
+int getHeaderHeight() {
+ Header header = getHeader();
+ int height = 0;
+
+ if (header.getVisible() == true) {
+ height = header.getBounds().height;
+ }
+ return height;
+}
+/**
+ * Answer whether the header is visible.
+ * @return
+ * true = header is visible. false = header is not visible
+ */
+public boolean getHeaderVisible() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getHeader().getVisible();
+}
+/**
+ * Answer the image extent of 'item'. Use the image of any column.
+ */
+Point getImageExtent(SelectableItem item) {
+ Image image = null;
+ Rectangle imageBounds;
+ Point imageExtent = null;
+ int columnCount = internalGetColumnCount();
+
+ for (int i = 0; i < columnCount && image == null; i++) {
+ image = ((TableItem) item).getImage(i);
+ }
+ if (image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+int getIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null && item.getSelectableParent() == this) {
+ index = ((TableItem) item).getIndex();
+ }
+ return index;
+}
+/**
+ * Answer the TableItem located at 'index' in the receiver.
+ * @param index - location of the TableItem object to return
+ */
+public TableItem getItem(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (!(0 <= index && index < getItemCount())) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ return (TableItem) getVisibleItem(index);
+}
+
+/**
+ * Return the item at the specified position in the widget
+ * Return null if the position is outside the widget or in the header widget.
+ */
+public TableItem getItem(Point point) {
+ int headerHeight = getHeaderHeight();
+ TableColumn column = getColumnAtX(point.x);
+ TableItem item = null;
+
+ if (column != null && column.getIndex() != TableColumn.FILL && point.y - headerHeight > 0) {
+ int itemIndex = (point.y - headerHeight) / getItemHeight() + getTopIndex();
+ item = (TableItem) getVisibleItem(itemIndex);
+ if (item != null) {
+ Point itemSize = item.getItemExtent(column);
+ if (point.x - column.getBounds().x > itemSize.x) {
+ item = null;
+ }
+ }
+ }
+ return item;
+}
+/**
+ * Answer the number of items in the receiver.
+ */
+public int getItemCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getItemVector().size();
+}
+/**
+ * Answer the number of items that can be displayed in the
+ * client area of the receiver without truncating any items.
+ */
+int getItemCountWhole() {
+ int clientAreaHeight = Math.max(0, getClientArea().height - getHeaderHeight());
+
+ return clientAreaHeight / getItemHeight();
+}
+/**
+ * Answer the height of an item in the receiver.
+ * The item height is the greater of the item icon height and
+ * text height of the first item that has text or an image
+ * respectively.
+ * Calculate a default item height based on the font height if
+ * no item height has been calculated yet.
+ */
+public int getItemHeight() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getItemHeight();
+}
+/**
+ * Answer the number of pixels that should be added to the item height.
+ */
+int getItemPadding() {
+ return getGridLineWidth() + getDisplay().textHighlightThickness + 1;
+}
+/**
+ * Answer all items of the receiver as an Array.
+ */
+public TableItem [] getItems() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector items = getItemVector();
+ TableItem itemArray[] = new TableItem[items.size()];
+
+ items.copyInto(itemArray);
+ return itemArray;
+}
+/**
+ * Answer all items of the receiver.
+ */
+Vector getItemVector() {
+ return items;
+}
+/**
+ * Answer whether the receiver is drawing grid lines.
+ * @return
+ * true = receiver draws grid lines
+ * false = receiver does not draw grid lines
+ */
+public boolean getLinesVisible() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return drawGridLines;
+}
+/**
+ * Answer a Vector containing the columns that need repainting
+ * based on the 'paintArea'.
+ * @param paintArea - invalidated rectangle that needs repainting
+ */
+Vector getPaintColumns(Rectangle paintArea) {
+ Enumeration columns = internalGetColumnVector().elements();
+ Vector paintColumns = new Vector();
+ TableColumn column;
+ Rectangle columnBounds;
+ int paintAreaRightBorder = paintArea.x + paintArea.width;
+
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ columnBounds = column.getBounds();
+ if ((columnBounds.x + columnBounds.width >= paintArea.x) && // does the paintArea overlap the current column?
+ (columnBounds.x <= paintAreaRightBorder)) {
+ paintColumns.addElement(column);
+ }
+ }
+ return paintColumns;
+}
+/**
+ * Return the width of the widest item in the column identified by 'columnIndex'
+ * @param columnIndex - index of the column whose preferred width should be
+ * calculated
+ */
+int getPreferredColumnWidth(int columnIndex) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+ int width = 0;
+ int headerWidth;
+
+ if (columnIndex != TableColumn.FILL) {
+ while (tableItems.hasMoreElements() == true) {
+ tableItem = (TableItem) tableItems.nextElement();
+ width = Math.max(width, tableItem.getPreferredWidth(columnIndex));
+ }
+ headerWidth = getHeader().getPreferredWidth(columnIndex);
+ if (width < headerWidth) {
+ width = headerWidth;
+ }
+ }
+ return width;
+}
+/**
+ * Answer the position in the receiver where 'item' is drawn
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is not an item of the receiver
+ */
+int getRedrawY(SelectableItem item) {
+ int redrawY = super.getRedrawY(item);
+
+ if (redrawY != -1) {
+ redrawY += getHeaderHeight();
+ }
+ return redrawY;
+}
+/**
+ * Answer the column that is being resized or null if no
+ * resize operation is in progress.
+ */
+TableColumn getResizeColumn() {
+ return resizeColumn;
+}
+/**
+ * Return the positions at which the column identified by 'columnIndex'
+ * must be redrawn.
+ * These positions may be different for each item since each item may
+ * have a different label
+ * @param columnIndex - the column index
+ * @param columnWidth - width of the column
+ * @return the positions at which the column must be redrawn.
+ * Each item in the widget client area is represented by a slot in
+ * the array. The item at position 'topIndex' is the first item in
+ * the array.
+ */
+int [] getResizeRedrawX(int columnIndex, int columnWidth) {
+ int topIndex = getTopIndex();
+ int bottomIndex = getBottomIndex();
+ int resizeRedrawX[];
+ TableItem item;
+
+ bottomIndex = Math.min(bottomIndex, getItemCount());
+ resizeRedrawX = new int[bottomIndex-topIndex+1];
+ for (int i = topIndex; i < bottomIndex; i++) {
+ item = (TableItem) getVisibleItem(i);
+ resizeRedrawX[i-topIndex] = item.getDotStartX(columnIndex, columnWidth);
+ }
+ return resizeRedrawX;
+}
+/**
+ * Answer the selected items of the receiver.
+ * @return an Array of TableItems containing the selected items.
+ * An empty Array if no items are selected.
+ */
+public TableItem [] getSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector selectionVector = getSelectionVector();
+ TableItem[] selectionArray = new TableItem[selectionVector.size()];
+
+ selectionVector.copyInto(selectionArray);
+ sort(selectionArray, 0, selectionArray.length);
+ return selectionArray;
+}
+
+/**
+ * Answer the number of selected items in the receiver.
+ */
+public int getSelectionCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getSelectionCount();
+}
+/**
+ * Answer the size of the full row selection rectangle for 'item'.
+ */
+Point getFullSelectionExtent(TableItem item) {
+ TableColumn lastColumn = (TableColumn) internalGetColumnVector().lastElement();
+ Point selectionExtent = null;
+ Rectangle columnBounds;
+ int xPosition = item.getImageStopX(TableColumn.FIRST);
+ int gridLineWidth = getGridLineWidth();
+
+ if (lastColumn != null) {
+ columnBounds = lastColumn.getBounds();
+ selectionExtent = new Point(
+ columnBounds.x - getHorizontalOffset() + columnBounds.width - xPosition - gridLineWidth,
+ getItemHeight());
+ if (getLinesVisible() == true) {
+ selectionExtent.y -= gridLineWidth;
+ }
+ }
+ return selectionExtent;
+}
+/**
+ * Answer the index of the first selected item of the receiver.
+ */
+public int getSelectionIndex() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = -1;
+
+ if (getSelectionCount() > 0) {
+ index = getIndex(getSelection()[0]);
+ }
+ return index;
+}
+/**
+ * Answer the indices of the selected items of the receiver.
+ * @return an Array containing the indices of the selected items.
+ * An empty Array if no items are selected.
+ */
+public int [] getSelectionIndices() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TableItem[] items = getSelection();
+ int indices[] = new int[items.length];
+
+ for (int i = 0; i < items.length; i++) {
+ indices[i] = getIndex(items[i]);
+ }
+ return indices;
+}
+/**
+ * Answer the index of the first visible item in the receiver's
+ * client area.
+ * @return 0-based index of the first visible item in the
+ * receiver's client area.
+ */
+public int getTopIndex() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getTopIndex();
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Every item in a table widget should be visible.
+ */
+int getVisibleIndex(SelectableItem item) {
+ return getIndex(item);
+}
+/**
+ * Answer the SelectableItem located at 'itemIndex' in the receiver.
+ * @param itemIndex - location of the SelectableItem object to return
+ */
+SelectableItem getVisibleItem(int itemIndex) {
+ Vector items = getItemVector();
+ TableItem item = null;
+
+ if ((items != null) && (itemIndex >= 0) && (itemIndex < items.size())) {
+ item = (TableItem) items.elementAt(itemIndex);
+ }
+ return item;
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+int getVisibleRedrawY(SelectableItem item) {
+ int redrawY = -1;
+ int index = getTopIndex();
+ int bottomIndex = getBottomIndex();
+
+ if (item == null) {
+ return redrawY;
+ }
+ while (index < bottomIndex && item.equals(getVisibleItem(index)) == false) {
+ index++;
+ }
+ if (index < bottomIndex) {
+ redrawY = getRedrawY(item);
+ }
+ return redrawY;
+}
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.MouseMove:
+ if (event.widget == tableHeader) {
+ headerMouseMove(event);
+ }
+ else {
+ columnMouseMove(event);
+ }
+ break;
+ case SWT.MouseDown:
+ if (event.widget == tableHeader) {
+ headerMouseDown(event);
+ }
+ else {
+ columnMouseDown(event);
+ }
+ break;
+ case SWT.MouseDoubleClick:
+ columnMouseDoubleClick(event);
+ break;
+ case SWT.MouseUp:
+ mouseUp(event);
+ break;
+ case SWT.Paint:
+ paint(event);
+ break;
+ default:
+ super.handleEvents(event);
+ }
+}
+/**
+ * Answer true if any item in the first column has an image.
+ * Answer false otherwise.
+ */
+boolean hasFirstColumnImage() {
+ return firstColumnImage;
+}
+/**
+ * Answer whether the receiver has the input focus.
+ */
+public boolean isFocusControl() {
+ return hasColumnFocus;
+}
+/**
+ * The mouse pointer was pressed down on the receiver's header
+ * widget. Start a column resize operation if apropriate.
+ * @param event - the mouse event that occured over the header
+ * widget
+ */
+void headerMouseDown(Event event) {
+ TableColumn column = getColumnAtX(event.x);
+
+ if (isColumnResize(event) == true) {
+ startColumnResize(event);
+ }
+ else
+ if (column != null) {
+ column.notifyListeners(SWT.Selection, new Event());
+ }
+}
+/**
+ * The mouse pointer was moved over the receiver's header widget.
+ * If a column is currently being resized a vertical line indicating
+ * the new position of the resized column is drawn.
+ * Otherwise, if no column resize operation is in progress, the
+ * column resize cursor is displayed when the mouse is near the border
+ * of a column.
+ */
+void headerMouseMove(Event event) {
+ if (isColumnResizeStarted() == false) { // only check whether cursor is in resize
+ setColumnResizeCursor(isColumnResize(event)); // area if no resize operation is in progress
+ }
+ else
+ if (event.x >= getResizeColumn().getBounds().x) {
+ drawColumnResizeLine(event.x);
+ update(); // looks better if resize line is drawn immediately
+ }
+}
+/**
+ * Answer the index of 'column' in the receiver or -1 if 'column'
+ * does not exist in the receiver.
+ */
+public int indexOf(TableColumn column) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (column == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ return internalGetColumnVector().indexOf(column);
+}
+/**
+ * Answer the index of 'item' in the receiver or -1 if 'item'
+ * does not exist in the receiver.
+ */
+public int indexOf(TableItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (item == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ return getIndex(item);
+}
+/**
+ * Initialize the receiver. Create a header widget and an empty column.
+ */
+void initialize() {
+ columns = new Vector();
+ setItemVector(new Vector());
+ focusProxy = new Button(this, SWT.NULL);
+ focusProxy.setBounds(0, 0, 0, 0); // make the focus proxy invisible
+ tableHeader = new Header(this);
+ tableHeader.setVisible(false); // SWT table header is invisible by default, too
+ fillColumn = TableColumn.createFillColumn(this);
+ setColumnPosition(fillColumn);
+ defaultColumn = TableColumn.createDefaultColumn(this); // Create the default column. Fix for 1FUSJY5
+ super.initialize();
+}
+/**
+ * Insert the new column 'column' into the table data at position
+ * 'index'.
+ */
+void insertColumnData(TableColumn column) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.insertColumn(column);
+ }
+}
+/**
+ * Insert the new column 'column'.
+ * Set the position and move the following columns to the right.
+ */
+void insertColumnVisual(TableColumn column) {
+ Rectangle columnBounds = column.getBounds();
+ Rectangle previousColumnBounds;
+ int index = column.getIndex();
+
+ if (index > 0) {
+ previousColumnBounds = getColumn(index - 1).getBounds();
+ columnBounds.x = previousColumnBounds.x + previousColumnBounds.width;
+ }
+ else {
+ columnBounds.x = 0;
+ }
+ column.setBounds(columnBounds);
+ setColumnPosition(column);
+}
+/**
+ * Set event listeners for the receiver.
+ */
+void installListeners() {
+ Header tableHeader = getHeader();
+ Control focusWindow = getFocusWindow();
+ Listener listener = getListener();
+
+ super.installListeners();
+ tableHeader.addListener(SWT.MouseMove, listener);
+ tableHeader.addListener(SWT.MouseDown, listener);
+ tableHeader.addListener(SWT.MouseUp, listener);
+
+ // HACK: All we're really interested in is focus change and key down
+ // for the table itself. Doesn't work that way because setFocus sets
+ // focus to the first child of the receiver (which is our focus window)
+ removeListener(SWT.FocusOut, listener);
+ removeListener(SWT.FocusIn, listener);
+ focusWindow.addListener(SWT.FocusOut, listener);
+ focusWindow.addListener(SWT.FocusIn, listener);
+ focusWindow.addListener(SWT.KeyDown, listener);
+
+ addListener(SWT.MouseMove, listener);
+ addListener(SWT.MouseDown, listener);
+ addListener(SWT.MouseDoubleClick, listener);
+ addListener(SWT.MouseUp, listener);
+ addListener(SWT.Paint, listener);
+}
+/**
+ * Answer the TableColumn at 'index'.
+ * If the user has not created any columns the default column is
+ * returned if index is 0.
+ * Fix for 1FUSJY5
+ */
+TableColumn internalGetColumn(int index) {
+ Vector columns = internalGetColumnVector();
+
+ if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
+ if (index < 0 || index >= columns.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+
+ return (TableColumn) columns.elementAt(index);
+
+}
+/**
+ * Answer the number of columns in the receiver.
+ * If the user has not created any columns, 1 is returned since there
+ * always is a default column.
+ * Fix for 1FUSJY5
+ */
+int internalGetColumnCount() {
+ Vector columns = internalGetColumnVector();
+ int count = 0;
+
+ if (columns != null) {
+ count = columns.size();
+ }
+ return count;
+}
+/**
+ * Return a Vector containing all columns of the receiver except
+ * the fill column to the right of all content columns.
+ * Return a Vector containing the default column if the user has
+ * not created any columns.
+ * Fix for 1FUSJY5
+ */
+Vector internalGetColumnVector() {
+ Vector internalColumnVector;
+ TableColumn defaultColumn;
+
+ if (columns.isEmpty() == false) {
+ internalColumnVector = columns;
+ }
+ else {
+ internalColumnVector = new Vector(1);
+ defaultColumn = getDefaultColumn();
+ if (defaultColumn != null) {
+ internalColumnVector.addElement(defaultColumn);
+ }
+ }
+ return internalColumnVector;
+}
+/**
+ * Answer whether the mouse pointer is at a position that can
+ * start a column resize operation. A column resize can be
+ * started if the mouse pointer is at either the left or right
+ * border of a column.
+ * @param event - mouse event specifying the location of the
+ * mouse pointer.
+ */
+boolean isColumnResize(Event event) {
+ TableColumn hotColumn = getColumnAtX(event.x);
+ Rectangle bounds = hotColumn.getBounds();
+ int hotColumnIndex = hotColumn.getIndex();
+ int columnX = event.x - bounds.x;
+ boolean isColumnResize = false;
+
+ if (columnX <= COLUMN_RESIZE_OFFSET && // mouse over left side of column? and
+ hotColumnIndex != TableColumn.FIRST) { // it's not the first column)
+ if (hotColumnIndex == TableColumn.FILL) {
+ hotColumn = (TableColumn) internalGetColumnVector().lastElement();
+ }
+ else {
+ hotColumn = internalGetColumn(hotColumnIndex - 1);
+ }
+ isColumnResize = hotColumn.getResizable(); // check whether left column can be resized
+ }
+ else
+ if (columnX >= bounds.width - COLUMN_RESIZE_OFFSET && // mouse over right side of column and
+ hotColumn != getFillColumn()) { // column is a real one (not the right hand fill column)?
+ isColumnResize = hotColumn.getResizable(); // check whether column under cursor can be resized
+ }
+ return isColumnResize;
+}
+/**
+ * Answer whether a column of the receiver is being resized.
+ */
+boolean isColumnResizeStarted() {
+ return (getResizeColumn() != null);
+}
+/**
+ * Answer whether the item identified by 'index' is selected.
+ * @return
+ * true=item identified by 'index' is selected
+ * false=item identified by 'index' is not selected.
+ */
+public boolean isSelected(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TableItem item = getItem(index);
+
+ return (item != null && item.isSelected() == true);
+}
+/**
+ * 'changedItem' has changed. Update the default column width.
+ * @param changedItem - the item that has changed
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ // call super.itemChanged first to make sure that table image size is
+ // calculated if necessary. Fixes 1FYPBBG.
+ super.itemChanged(changedItem, repaintStartX, repaintWidth);
+ // remember if any item ever had an image in the first column.
+ if (firstColumnImage == false && changedItem.getImage() != null) {
+ firstColumnImage = true;
+ }
+ setFirstColumnWidth((TableItem) changedItem);
+}
+/**
+ * A mouse button was released.
+ * Update the display if a column has been resized.
+ * @param event - the mouse event for the button up action
+ */
+void mouseUp(Event event) {
+ TableColumn resizeColumn = getResizeColumn();
+ Rectangle oldColumnBounds;
+ int resizeXPosition;
+ int widthChange;
+
+ if (isColumnResizeStarted() == true) {
+ oldColumnBounds = resizeColumn.getBounds();
+ resizeXPosition = getColumnResizeX();
+ widthChange = resizeXPosition - (oldColumnBounds.x + oldColumnBounds.width);
+ if (widthChange != 0) {
+ if (widthChange > 0) {
+ redraw(resizeXPosition, 0, 1, getClientArea().height, false); // remove resize line
+ update(); // to avoid cheese caused by scrolling the resize line
+ }
+ resizeColumn.setWidth(oldColumnBounds.width + widthChange);
+ }
+ setResizeColumn(null);
+ }
+}
+/**
+ * Adjust the position of all columns starting at 'startIndex'.
+ * @param startIndex - index at which the column move should begin
+ * If this is the index of the fill column all columns are moved,
+ * including the fill column
+ * @param moveDistance - distance that the columns should be moved.
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void moveColumns(int startIndex, int moveDistance) {
+ Vector columns = internalGetColumnVector();
+ TableColumn moveColumn;
+ Rectangle columnBounds;
+
+ if (startIndex == TableColumn.FILL) {
+ moveColumn = getFillColumn();
+ columnBounds = moveColumn.getBounds();
+ columnBounds.x += moveDistance;
+ moveColumn.setBounds(columnBounds);
+ startIndex = 0; // continue with first data column
+ }
+ for (int i = startIndex; i < columns.size(); i++) {
+ moveColumn = (TableColumn) columns.elementAt(i);
+ columnBounds = moveColumn.getBounds();
+ columnBounds.x += moveDistance;
+ moveColumn.setBounds(columnBounds);
+ }
+}
+/**
+ * Adjust the y position of all columns including the fill column.
+ */
+void moveColumnsVertical() {
+ Enumeration columns = internalGetColumnVector().elements();
+ TableColumn column;
+
+ setColumnPosition(getFillColumn());
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ setColumnPosition(column);
+ }
+}
+/**
+ * A paint event has occurred. Paint the invalidated items.
+ * @param event - paint event specifying the invalidated area.
+ */
+void paint(Event event) {
+ int visibleRange[];
+ int headerHeight = getHeaderHeight();
+ Vector paintColumns = getPaintColumns(event.getBounds());
+ TableItem focusItem = null;
+
+ if (paintColumns.size() > 0) {
+ event.y -= headerHeight;
+ visibleRange = getIndexRange(event.getBounds());
+ event.y += headerHeight;
+ // When the top index is > 0 and the receiver is resized
+ // higher so that the top index becomes 0 the invalidated
+ // rectangle doesn't start below the header widget but at
+ // y position 0. Subtraction of the header height (it is
+ // not above the receiver but on top) causes event.y and
+ // subsequently visibleRange[0] to be negative.
+ // Hack to prevent visibleRange[0] from becoming negative.
+ // Need to find out why the invalidated area starts at 0
+ // in the first place.
+ if (visibleRange[0] < 0) {
+ visibleRange[0] = 0;
+ }
+ //
+ visibleRange[1] = Math.min(visibleRange[1], getItemCount()-1-getTopIndex());
+ focusItem = paintItems(event, visibleRange[0], visibleRange[1], paintColumns);
+ }
+ if (getLinesVisible() == true) {
+ drawGridLines(event, paintColumns.elements());
+ }
+ if (focusItem != null) {
+ // draw focus on top of drawing grid lines so that focus rectangle
+ // is not obscured by grid. Fixes 1G5X20B
+ drawSelectionFocus(focusItem, event.gc);
+ }
+}
+
+/**
+ * Paint items of the receiver starting at index 'topPaintIndex' and
+ * ending at 'bottomPaintIndex'.
+ * @param event - holds the GC to draw on and the clipping rectangle
+ * @param topPaintIndex - index of the first item to draw
+ * @param bottomPaintIndex - index of the last item to draw
+ * @param paintColumns - the table columns that should be painted
+ * @return the item that has focus if it was among the rendered items.
+ * null if the focus item was not rendered or if no item has focus (ie.
+ * because the widget does not have focus)
+ */
+TableItem paintItems(Event event, int topPaintIndex, int bottomPaintIndex, Vector paintColumns) {
+ Enumeration columns;
+ TableColumn column;
+ TableItem paintItem;
+ TableItem focusItem = null;
+ Point selectionExtent;
+ Point selectionPosition;
+ int itemHeight = getItemHeight();
+
+ topPaintIndex += getTopIndex();
+ bottomPaintIndex += getTopIndex();
+ for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
+ paintItem = (TableItem) getVisibleItem(i);
+ selectionExtent = paintItem.getSelectionExtent();
+ if (selectionExtent != null) {
+ selectionPosition = new Point(paintItem.getSelectionX(), getRedrawY(paintItem));
+ drawSelection(paintItem, event.gc, selectionPosition, selectionExtent);
+ }
+ columns = paintColumns.elements();
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ paintSubItem(event, paintItem, column, i * itemHeight);
+ }
+ if (hasFocus(paintItem)) {
+ focusItem = paintItem;
+ }
+ }
+ return focusItem;
+}
+
+/**
+ * Paint the table item 'paintItem' in 'column' at y position
+ * 'paintYPosition' of the receiver.
+ * @param event - holds the GC to draw on and the clipping
+ * rectangle.
+ * @param paintItem - the item to draw
+ * @param column - column to draw 'paintItem' in
+ * @param paintYPosition - y position in the receiver to draw
+ * 'paintItem' at.
+ */
+void paintSubItem(Event event, TableItem paintItem, TableColumn column, int paintYPosition) {
+ Rectangle columnBounds = column.getBounds();
+ int gridLineWidth = getGridLineWidth();
+ int itemDrawStopX = columnBounds.x + columnBounds.width - gridLineWidth;
+ int clipX;
+
+ if (event.x + event.width > itemDrawStopX) { // does the invalidated area stretch past the current column's right border?
+ clipX = Math.max(columnBounds.x, event.x);
+ event.gc.setClipping( // clip the drawing area
+ clipX, event.y,
+ itemDrawStopX - clipX, event.height);
+ }
+ column.paint(paintItem, event.gc, paintYPosition);
+ if (event.x + event.width > itemDrawStopX) {
+ event.gc.setClipping(event.x, event.y, event.width, event.height); // restore original clip rectangle
+ }
+}
+/**
+ * Reindex all columns starting at 'startIndex'.
+ * Reindexing is necessary when a new column has been inserted.
+ */
+void reindexColumns(int startIndex) {
+ Vector columns = getColumnVector();
+ TableColumn column;
+
+ for (int i = startIndex; i < getColumnCount(); i++) {
+ column = (TableColumn) columns.elementAt(i);
+ column.setIndex(i);
+ }
+}
+/**
+ * Remove the items identified by the indices stored in
+ * 'indices' from the receiver.
+ * @param indices - indices of the items to dispose
+ */
+public void remove(int indices[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item;
+ int [] sortedIndices;
+ int last = -1;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ sortedIndices = new int[indices.length];
+ System.arraycopy (indices, 0, sortedIndices, 0, indices.length);
+ sort(sortedIndices); // sort indices in descending order
+ for (int i = 0; i < sortedIndices.length; i++) {
+ if (sortedIndices[i] != last) {
+ item = getVisibleItem(sortedIndices[i]);
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ error(SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ last = sortedIndices[i];
+ }
+ }
+}
+/**
+ * Remove the item identified by 'index'.
+ * @param index - index of the item to dispose
+ */
+public void remove(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = getVisibleItem(index);
+
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ error(SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+}
+/**
+ * Remove a range of items starting at index 'start' and
+ * stopping at index 'end'.
+ * This operation will fail when the index is out of range
+ * Indexing is zero based.
+ * @param start - the start of the range
+ * @param end - the end of the range
+ */
+public void remove(int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item;
+
+ for (int i = end; i >= start; i--) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ error(SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ }
+}
+/**
+ * Remove all items of the receiver.
+ */
+public void removeAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector items = getItemVector();
+
+ setRedraw(false);
+ setRemovingAll(true);
+ for (int i = 0; i < items.size(); i++) {
+ ((TableItem) items.elementAt(i)).dispose();
+ }
+ setItemVector(new Vector());
+ reset();
+ calculateVerticalScrollbar();
+ setRemovingAll(false);
+ setRedraw(true);
+}
+/**
+ * Remove 'column' from the receiver.
+ */
+void removeColumn(TableColumn column) {
+ TableColumn lastColumn;
+ int index = column.getIndex();
+ int columnWidth = column.getWidth();
+ int columnCount;
+
+ if (isRemovingAll() == true) {
+ getColumnVector().removeElementAt(index);
+ }
+ else {
+ getColumnVector().removeElementAt(index);
+ columnCount = getColumnCount();
+ // Never remove the data of the last user created column.
+ // SWT for Windows does the same.
+ if (columnCount > 0) {
+ removeColumnData(column);
+ }
+ removeColumnVisual(column);
+ if (index < columnCount) { // is there a column after the removed one?
+ reindexColumns(index);
+ }
+ // last user created column is about to be removed.
+ if (columnCount == 0) {
+ TableColumn defaultColumn = getDefaultColumn();
+ defaultColumn.pack(); // make sure the default column has the right size...
+ setColumnPosition(defaultColumn); // ...and is at the right position
+ }
+ // Fixes for 1G1L0UT
+ // Reduce the content width by the width of the removed column
+ setContentWidth(getContentWidth() - columnWidth);
+ // claim free space
+ claimRightFreeSpace();
+ //
+ }
+}
+/**
+ * Remove the column 'column' from the table data.
+ */
+void removeColumnData(TableColumn column) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.removeColumn(column);
+ }
+}
+/**
+ * Remove the column 'column'.
+ * Set the position of the following columns.
+ */
+void removeColumnVisual(TableColumn column) {
+ int columnWidth = column.getWidth();
+
+ // move following columns to the left
+ moveColumns(column.getIndex() + 1, columnWidth * -1);
+ redraw();
+ getHeader().redraw();
+}
+/**
+ * Remove 'item' from the receiver.
+ * @param item - item that should be removed from the receiver
+ */
+void removeItem(TableItem item) {
+ Vector items = getItemVector();
+ int index = items.indexOf(item);
+
+ if (index != -1) {
+ if (isRemovingAll() == false) {
+ removingItem(item);
+ }
+ items.removeElementAt(index);
+ for (int i = index; i < items.size(); i++) {
+ TableItem anItem = (TableItem) items.elementAt(i);
+ anItem.setIndex(anItem.getIndex() - 1);
+ }
+ if (isRemovingAll() == false) {
+ removedItem(item);
+ }
+ }
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection, listener);
+}
+/**
+ * Reset cached data of column at 'columnIndex' for the items of the receiver.
+ * @param columnIndex - index of the column for which the item data should be
+ * reset.
+ */
+void resetTableItems(int columnIndex) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.reset(columnIndex);
+ }
+}
+/**
+ * The receiver has been resized. Resize the fill column
+ * and the header widget.
+ */
+void resize(Event event) {
+ TableColumn fillColumn = getFillColumn();
+ Rectangle fillColumnBounds;
+
+ super.resize(event);
+ // the x position may change in super.resize.
+ // get the column bounds after calling super.resize. Fixes 1G7ALGG
+ fillColumnBounds = fillColumn.getBounds();
+ fillColumnBounds.width = Math.max(0, getClientArea().width - getContentWidth());
+ fillColumn.setBounds(fillColumnBounds);
+ resizeHeader();
+}
+/**
+ * Resize the header widget to occupy the whole width of the
+ * receiver.
+ */
+void resizeHeader() {
+ Header tableHeader = getHeader();
+ Point size = tableHeader.getSize();
+
+ size.x = Math.max(getContentWidth(), getClientArea().width);
+ tableHeader.setSize(size);
+}
+/**
+ * Redraw 'column' after its width has been changed.
+ * @param column - column whose width has changed.
+ * @param oldColumnWidth - column width before resize
+ * @param oldColumnWidth - column width after resize
+ */
+void resizeRedraw(TableColumn column, int oldColumnWidth, int newColumnWidth) {
+ Rectangle columnBounds = column.getBounds();
+ int columnIndex = column.getIndex();
+ int oldRedrawStartX[] = getResizeRedrawX(columnIndex, oldColumnWidth);
+ int newRedrawStartX[] = getResizeRedrawX(columnIndex, newColumnWidth);
+ int itemHeight = getItemHeight();
+ int widthChange = newColumnWidth - oldColumnWidth;
+ int topIndex = getTopIndex();
+
+ for (int i = 0; i < newRedrawStartX.length; i++) {
+ if (newRedrawStartX[i] != oldRedrawStartX[i]) {
+ if (widthChange > 0) {
+ newRedrawStartX[i] = oldRedrawStartX[i];
+ }
+ redraw(
+ columnBounds.x + newRedrawStartX[i], columnBounds.y + itemHeight * (i + topIndex),
+ columnBounds.width - newRedrawStartX[i], itemHeight, false);
+ }
+ }
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void scrollHorizontal(int numPixel) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+ getHeader().scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+ moveColumns(TableColumn.FILL, numPixel);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+void scrollVertical(int scrollIndexCount) {
+ int scrollAmount = scrollIndexCount * getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int destY;
+ int sourceY;
+ boolean scrollUp = scrollIndexCount < 0;
+ Rectangle clientArea = getClientArea();
+
+ if (scrollIndexCount == 0) {
+ return;
+ }
+ if (scrollUp == true) {
+ destY = headerHeight - scrollAmount;
+ sourceY = headerHeight;
+ }
+ else {
+ destY = headerHeight;
+ sourceY = destY + scrollAmount;
+ }
+ scroll(
+ 0, destY, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll items down to make space for a new item added to
+ * the receiver at position 'index'.
+ * @param index - position at which space for one new item
+ * should be made. This index is relative to the first item
+ * of the receiver.
+ */
+void scrollVerticalAddingItem(int index) {
+ int itemHeight = getItemHeight();
+ int sourceY = getHeaderHeight();
+ Rectangle clientArea = getClientArea();
+
+ if (index >= getTopIndex()) {
+ sourceY += (index-getTopIndex()) * itemHeight;
+ }
+ scroll(
+ 0, sourceY + itemHeight, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll the items below the item at position 'index' up
+ * so that they cover the removed item.
+ * @param index - index of the removed item
+ */
+void scrollVerticalRemovedItem(int index) {
+ int itemHeight = getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int destY;
+ Rectangle clientArea = getClientArea();
+
+ destY = Math.max(headerHeight, headerHeight + (index - getTopIndex()) * itemHeight);
+ scroll(
+ 0, destY, // destination x, y
+ 0, destY + itemHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Select the items identified by the indices stored in
+ * 'indices'.
+ * A SWT.Selection event will not be sent.
+ * @param indices - indices of the items to select
+ */
+public void select(int indices[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = null;
+ int selectionCount;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ selectionCount = indices.length;
+ if (isMultiSelect() == false && selectionCount > 1) {
+ selectionCount = 1;
+ deselectAllExcept(getVisibleItem(indices[0]));
+ }
+ for (int i = selectionCount - 1; i >= 0; --i) {
+ item = getVisibleItem(indices[i]);
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Select the item identified by 'index'.
+ * A SWT.Selection event will not be sent.
+ * @param index - index of the item to select
+ */
+public void select(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = getVisibleItem(index);
+
+ if (isMultiSelect() == false) {
+ deselectAllExcept(getVisibleItem(index));
+ }
+ if (item != null) {
+ select(item);
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Select a range of items starting at index 'start' and
+ * stopping at index 'end'. Indices that are out of range
+ * are ignored. Indexing is zero based.
+ * @param start - the start of the range
+ * @param end - the end of the range
+ */
+public void select(int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item = null;
+ int selectionCount = 1;
+
+ if (isMultiSelect() == false) {
+ if (start < 0 && end >= 0) {
+ start = 0;
+ }
+ end = start;
+ deselectAllExcept(getVisibleItem(end));
+ }
+ // select in the same order as all the other selection and deslection methods.
+ // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
+ // selections of the items, causing flash.
+ for (int i = end; i >= start; i--) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Select all items of the receiver if it is in multiple
+ * selection mode.
+ * A SWT.Selection event will not be sent.
+ * Do nothing if the receiver is in single selection mode.
+ */
+public void selectAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Enumeration items = getItemVector().elements();
+ TableItem item = null;
+
+ if (isMultiSelect() == false) {
+ return;
+ }
+ while (items.hasMoreElements() == true) {
+ item = (TableItem) items.nextElement();
+ select(item);
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Set the y position of 'column'.
+ * @param column - the TableColumn that should be set to
+ * a new y position.
+ */
+void setColumnPosition(TableColumn column) {
+ Rectangle bounds = column.getBounds();
+
+ bounds.y = getHeaderHeight() - getTopIndex() * getItemHeight();
+ column.setBounds(bounds);
+}
+/**
+ * Change the cursor of the receiver.
+ * @param isColumnResizeCursor - indicates whether the column
+ * resize cursor or the regular cursor should be set.
+ */
+void setColumnResizeCursor(boolean isColumnResizeCursor) {
+ if (isColumnResizeCursor != this.isColumnResizeCursor) {
+ this.isColumnResizeCursor = isColumnResizeCursor;
+ if (isColumnResizeCursor == true) {
+ setCursor(getColumnResizeCursor());
+ }
+ else {
+ setCursor(null);
+ }
+ }
+}
+/**
+ * Set the current position of the resized column to 'xPosition'.
+ * @param xPosition - the current position of the resized column
+ */
+void setColumnResizeX(int xPosition) {
+ columnResizeX = xPosition;
+}
+/**
+ * Set the width of the receiver's contents to 'newWidth'.
+ * Content width is used to calculate the horizontal scrollbar.
+ */
+void setContentWidth(int newWidth) {
+ TableColumn fillColumn = getFillColumn();
+ Rectangle fillColumnBounds;
+ int widthDiff = newWidth - getContentWidth();
+
+ super.setContentWidth(newWidth);
+ if (fillColumn != null) {
+ fillColumnBounds = fillColumn.getBounds();
+ fillColumnBounds.x += widthDiff;
+ fillColumnBounds.width = Math.max(0, getClientArea().width - newWidth);
+ fillColumn.setBounds(fillColumnBounds);
+ }
+}
+/**
+ * Set the width of the first column to fit 'item' if it is longer than
+ * the current column width.
+ * Do nothing if the user has already set a width.
+ */
+void setFirstColumnWidth(TableItem item) {
+ int newWidth;
+ TableColumn column;
+
+ if (internalGetColumnCount() > 0) {
+ column = internalGetColumn(TableColumn.FIRST);
+ if (column.isDefaultWidth() == true) {
+ newWidth = Math.max(column.getWidth(), item.getPreferredWidth(TableColumn.FIRST));
+ column.setWidth(newWidth);
+ column.setDefaultWidth(true); // reset to true so that we know when the user has set
+ // the width instead of us setting a default width.
+ }
+ }
+}
+/**
+ * The font is changing. Trigger a recalculation of the item
+ * height using all items of the receiver.
+ */
+public void setFont(Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ SelectableItem item;
+ int itemCount = getItemCount();
+
+ if (font == null || font.equals(getFont()) == true) {
+ return;
+ }
+ setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
+ resetItemData();
+ super.setFont(font);
+ for (int i = 0; i < itemCount; i++) {
+ itemChanged(getItem(i), 0, getClientArea().width);
+ }
+ setRedraw(true); // re-enable redraw
+ getHeader().setFont(font);
+}
+/**
+ * Set whether or not the header is visible.
+ * @param headerVisible -
+ * true = header is visible. false = header is not visible
+ */
+public void setHeaderVisible(boolean headerVisible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (headerVisible != getHeaderVisible()) {
+ getHeader().setLocation(0, 0);
+ getHeader().setVisible(headerVisible);
+ // Windows resets scrolling so do we
+ setTopIndex(0, true);
+ moveColumnsVertical();
+ resizeVerticalScrollbar();
+ redraw();
+ }
+}
+/**
+ * Set the vector that stores the items of the receiver
+ * to 'newVector'.
+ * @param newVector - Vector to use for storing the items of
+ * the receiver.
+ */
+void setItemVector(Vector newVector) {
+ items = newVector;
+}
+/**
+ * Set whether the receiver is drawing grid lines to
+ * 'drawGridLines'.
+ * @param drawGridLines -
+ * true = receiver draws grid lines
+ * false = receiver does not draw grid lines
+ */
+public void setLinesVisible(boolean drawGridLines) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (this.drawGridLines != drawGridLines) {
+ this.drawGridLines = drawGridLines;
+ redraw();
+ }
+}
+/**
+ * Set whether the receiver and it's children should be
+ * drawn or not.
+ * @param redraw -
+ * true = redraw the receiver and its children
+ * false = do not draw the receiver or its children
+ */
+public void setRedraw(boolean redraw) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setRedraw(redraw);
+ getHeader().setRedraw(redraw);
+}
+/**
+ * Set the column that is being resized to 'column'.
+ * @param column - the TableColumn that is being resized.
+ * A null value indicates that no column resize operation is
+ * in progress.
+ */
+void setResizeColumn(TableColumn column) {
+ resizeColumn = column;
+}
+/**
+* Sets the selection.
+* <p>
+* The previous selection is cleared
+* before new items are selected.
+*
+* @see Table#deselectAll()
+* @see Table#select(int [])
+*
+* @param indices the indices of the items
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection(int [] indices) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector keepSelected;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ keepSelected = new Vector(indices.length);
+ for (int i = 0; i < indices.length; i++) {
+ SelectableItem item = getVisibleItem(indices[i]);
+ if (item != null) {
+ keepSelected.addElement(item);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ select(indices);
+}
+/**
+ * Select the items stored in 'items'.
+ * A SWT.Selection event is not going to be sent.
+ * @param selectionItems - Array containing the items that should
+ * be selected
+ */
+public void setSelection(TableItem selectionItems[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (selectionItems == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setSelectableSelection(selectionItems);
+}
+/**
+ * Set the selection to the item identified by 'index'.
+ * SWT.Selection events are not going to be sent.
+ * @param index - index of the item that should be selected
+ */
+public void setSelection(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ deselectAllExcept(getVisibleItem(index));
+ select(index);
+}
+/**
+ * Set the selection to a range of items starting at index
+ * 'start' and stopping at index 'end'. Indices that are out
+ * of range are ignored. Indexing is zero based.
+ * @param start - the start of the range
+ * @param end - the end of the range
+ */
+public void setSelection(int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector keepSelected = new Vector(end - start + 1);
+
+ for (int i = start; i <= end; i++) {
+ SelectableItem item = getVisibleItem(i);
+ if (item != null) {
+ keepSelected.addElement(item);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ select(start, end);
+}
+/**
+ * Scroll the item at position 'index' to the top of the receiver.
+ * If the scroll operation would result in empty space being
+ * displayed below the last item of the receiver, the last item is
+ * scrolled into view. This results in the specified item not being
+ * displayed at the top of the receiver but after the top item.
+ * @param index - 0-based index of the item that should be
+ * displayed at the top of the receiver's client area.
+ */
+public void setTopIndex(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int itemCount = getItemCount();
+ int itemCountWhole = getItemCountWhole();
+
+ if (index < 0 || itemCount == 0) {
+ return;
+ }
+ if (index >= itemCount) {
+ index = itemCount - itemCountWhole;
+ }
+ super.setTopIndex(index, true);
+}
+/**
+ * Set the index of the first visible item in the receiver's client
+ * area to 'index'.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
+ super.setTopIndexNoScroll(index, adjustScrollbar);
+ moveColumnsVertical();
+}
+/**
+ * Make 'item' visible by scrolling it into the receiver's
+ * client area if necessary.
+ * @param item - the item that should be made visible to the
+ * user.
+ */
+public void showItem(TableItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (item == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ showSelectableItem(item);
+}
+/**
+ * Show the selection. If there is no selection or the
+ * selection is already visible, this method does nothing.
+ * If the selection is not visible, the top index of the
+ * widget is changed such that the selection becomes visible.
+ */
+public void showSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.showSelection();
+}
+void sort (int [] items) {
+ /* Shell Sort from K&R, pg 108 */
+ int length = items.length;
+ for (int gap=length/2; gap>0; gap/=2) {
+ for (int i=gap; i<length; i++) {
+ for (int j=i-gap; j>=0; j-=gap) {
+ if (items [j] <= items [j + gap]) {
+ int swap = items [j];
+ items [j] = items [j + gap];
+ items [j + gap] = swap;
+ }
+ }
+ }
+ }
+}
+/**
+ * Start a column resize operation.
+ * @param event - the mouse event that occured over the header
+ * widget
+ */
+void startColumnResize(Event event) {
+ Vector columns = internalGetColumnVector();
+ TableColumn hitColumn = getColumnAtX(event.x);
+ Rectangle hitColumnBounds;
+ int hitIndex = hitColumn.getIndex();
+
+ if (hitColumn == getFillColumn()) { // clicked on the fill column?
+ hitColumn = (TableColumn) columns.lastElement(); // resize the last real column
+ }
+ else
+ if ((event.x - hitColumn.getBounds().x <= COLUMN_RESIZE_OFFSET) && // check if left side of a column was clicked
+ (hitIndex > 0)) {
+ hitColumn = (TableColumn) columns.elementAt(hitIndex - 1); // resize the preceding column
+ }
+ hitColumnBounds = hitColumn.getBounds();
+ setColumnResizeX(hitColumnBounds.x + hitColumnBounds.width);
+ setResizeColumn(hitColumn);
+}
+/**
+ * Return 'text' after it has been checked to be no longer than 'maxWidth'
+ * when drawn on 'gc'.
+ * If it is too long it will be truncated up to the last character.
+ * @param text - the String that should be checked for length
+ * @param maxWidth - maximum width of 'text'
+ * @param gc - GC to use for String measurement
+ */
+String trimItemText(String text, int maxWidth, GC gc) {
+ int textWidth;
+ int dotsWidth;
+
+ if (text != null && text.length() > 1) {
+ textWidth = gc.stringExtent(text).x;
+ if (textWidth >= maxWidth) {
+ dotsWidth = getDotsWidth(gc);
+ while (textWidth + dotsWidth >= maxWidth && text.length() > 1) {
+ text = text.substring(0, text.length() - 1); // chop off one character at the end
+ textWidth = gc.stringExtent(text).x;
+ }
+ text = text.concat(Table.DOT_STRING);
+ }
+ }
+ return text;
+}
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableColumn.java
new file mode 100755
index 0000000000..55c9ba604c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableColumn.java
@@ -0,0 +1,461 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * A TableColumn stores such data as column label, label alignmentand size.
+ * It routes paint requests to the corresponding table item.
+ */
+public /*final*/ class TableColumn extends Item {
+ static final int FIRST = 0; // index of the first column
+ static final int FILL = -1; // index that identifies the column used to
+ // fill space not used by other columns.
+ private static final int DEFAULT_WIDTH = 10;
+
+ private Table parent;
+ private int index; // 0-based column index
+ private Rectangle bounds = new Rectangle(0, 0, 0, 0);
+ private boolean isDefaultWidth = true;
+ private boolean resize = true;
+/**
+ * Create a new TableColumn without adding it to the parent.
+ * Currently used to create fill columns and default columns.
+ * @see createFillColumn
+ * @see createDefaultColumn
+ * @param parent - Table widget the new instance will be a child of.
+ */
+TableColumn(Table parent) {
+ super(parent, SWT.NULL);
+ this.parent = parent;
+}
+/**
+ * Create a new instance of TableColumn and append it to the existing
+ * columns in 'parent'.
+ * @param parent - Table widget the new instance will be a child of.
+ * @param syle - style of the new TableColumn
+ */
+public TableColumn(Table parent, int style) {
+ this(parent, style, checkNull(parent).getColumnCount());
+}
+/**
+ * Create a new instance of TableColumn at position 'index' in the Table
+ * identified by 'parent'.
+ * @param parent - Table widget the new instance will be a child of.
+ * @param index - position in the 'parent' at which the new instance will
+ * be located relative to the other columns.
+ * @param syle - style of the new TableColumn
+ */
+public TableColumn(Table parent, int style, int index) {
+ super(parent, checkStyle (style), index);
+
+ this.parent = parent;
+ if (index < 0 || index > parent.getColumnCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ setIndex(index);
+ parent.addColumn(this);
+ setWidth(DEFAULT_WIDTH);
+ setDefaultWidth(true);
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event event) {disposeColumn();}
+ });
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addControlListener(ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Resize,typedListener);
+ addListener (SWT.Move,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener (SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
+ * Otherwise return 'table'
+ */
+static Table checkNull(Table table) {
+ if (table == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return table;
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * Create a new instance of TableColumn that acts as a default column
+ * if the user does not create a TableColumn.
+ * @param parent - Table widget the new instance will be a child of.
+ */
+static TableColumn createDefaultColumn(Table parent) {
+ TableColumn defaultColumn = new TableColumn(parent);
+
+ defaultColumn.setIndex(FIRST);
+ defaultColumn.setWidth(DEFAULT_WIDTH);
+ defaultColumn.setDefaultWidth(true);
+ return defaultColumn;
+}
+/**
+ * Create a new instance of TableColumn that acts as the rightmost
+ * fill column in a Table. The new object is not added to the parent
+ * like a regular column is.
+ * @param parent - Table widget the new instance will be a child of.
+ */
+static TableColumn createFillColumn(Table parent) {
+ TableColumn fillColumn = new TableColumn(parent);
+
+ fillColumn.setIndex(FILL);
+ return fillColumn;
+}
+/**
+ * Remove the receiver from its parent
+ */
+void disposeColumn() {
+ getParent().removeColumn(this);
+}
+/**
+* Gets the alignment.
+* <p>
+* The alignment of a widget controls the position of the
+* text or image in the widget. The alignment may be one
+* of LEFT, RIGHT or CENTER.
+*
+* @return the alignment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getAlignment () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.LEFT) != 0) return SWT.LEFT;
+ if ((style & SWT.CENTER) != 0) return SWT.CENTER;
+ if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
+ return SWT.LEFT;
+}
+
+/**
+ * Answer the bounding rectangle of the receiver.
+ */
+Rectangle getBounds() {
+ return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); // copy the object to prevent changes
+}
+/**
+ * Gets the Display.
+ */
+public Display getDisplay() {
+ if (parent == null) { // access parent field directly to prevent endless recursion
+ error(SWT.ERROR_WIDGET_DISPOSED);
+ }
+ return parent.getDisplay();
+}
+/**
+ * Answer the index of the receiver. Specifies the position of the
+ * receiver relative to other columns in the parent.
+ */
+int getIndex() {
+ return index;
+}
+/**
+ * Answer the parent widget of the receiver.
+ */
+public Table getParent() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return parent;
+}
+/**
+* Gets the resize attribute.
+* <p>
+* @return the resize attribute
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getResizable() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return resize;
+}
+/**
+* Gets the width.
+* <p>
+* @return the width
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getBounds().width;
+}
+/**
+ * Set the colun bounds.
+ */
+void internalSetBounds(Rectangle newBounds) {
+ bounds = newBounds;
+}
+/**
+ * Answer whether the column has a default width or if a width has been
+ * set by the user.
+ * @return
+ * true=column width is a default width set internally
+ * false=column width has been set by the user.
+ */
+boolean isDefaultWidth() {
+ return isDefaultWidth;
+}
+/**
+* Packs the widget.
+* <p>
+* Packing a widget causes it to be resized to the
+* preferred size for the widget.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void pack() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Table parent = getParent();
+ int index = parent.indexOf(this);
+
+ if (getIndex() != TableColumn.FILL && index != -1) {
+ setWidth(parent.getPreferredColumnWidth(index));
+ }
+}
+/**
+ * Draw the 'item' at 'yPosition' in the receiver column.
+ * @param item - TableItem that should be drawn.
+ * @param gc - GC to draw on
+ * @param yPosition - y position to draw at in the column.
+ */
+void paint(TableItem item, GC gc, int yPosition) {
+ Rectangle bounds = getBounds();
+ Point paintPosition = new Point(bounds.x, bounds.y + yPosition);
+
+ item.paint(gc, paintPosition, this);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeControlListener (ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Move, listener);
+ eventTable.unhook (SWT.Resize, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error(SWT.ERROR_WIDGET_DISPOSED);
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection, listener);
+}
+/**
+* Sets the alignment.
+* <p>
+* The alignment of a widget controls the position of the
+* text or image in the widget. The alignement may be one
+* of LEFT, RIGHT or CENTER.
+*
+* @param alignment the new alignment
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setAlignment(int alignment) {
+ if (!isValidThread ()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error(SWT.ERROR_WIDGET_DISPOSED);
+ int index = getIndex();
+
+ if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) != 0 && index != 0) { // ignore calls for the first column to match Windows behavior
+ style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ getParent().getHeader().redraw(index);
+ }
+}
+/**
+ * Set the bounding rectangle of the receiver to 'newBounds'.
+ * Notify the table widget if the column width changes.
+ * @param newBounds - the new bounding rectangle of the receiver,
+ * consisting of x, y, width, height
+ */
+void setBounds(Rectangle newBounds) {
+ if (newBounds.width != bounds.width) {
+ if (isDefaultWidth() == true) {
+ setDefaultWidth(false);
+ }
+ getParent().columnChange(this, newBounds);
+ }
+ else {
+ // columnChange causes update (via scroll) which may flush redraw
+ // based on old bounds. Setting bounds after notifying table fixes 1GABZR5
+ // Table sets column bounds at appropriate time when called above with
+ // width change. Only set bounds when table was not called. Fixes 1GCGDPB
+ bounds = newBounds;
+ }
+}
+/**
+ * Set whether the column has a default width or if a width has been
+ * set by the user.
+ * @param isDefaultWidth
+ * true=column width is a default width set internally
+ * false=column width has been set by the user
+ */
+void setDefaultWidth(boolean isDefaultWidth) {
+ this.isDefaultWidth = isDefaultWidth;
+}
+/**
+ * Set the index of the receiver to 'newIndex'. The index specifies the
+ * position of the receiver relative to other columns in the parent.
+ */
+void setIndex(int newIndex) {
+ this.index = newIndex;
+}
+/**
+* Sets the resize attribute.
+* <p>
+* @param resizee the resize attribute
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setResizable(boolean resize) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ this.resize = resize;
+}
+/**
+ * Set the text of the receiver to 'text'.
+ */
+public void setText(String newText) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = getIndex();
+
+ if (newText == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (index != FILL && (text == null || text.equals(newText) == false)) {
+ super.setText(newText);
+ getParent().getHeader().redraw(index);
+ }
+}
+/**
+* Sets the width.
+* <p>
+* @param width the width
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setWidth(int width) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Table parent = getParent();
+ Rectangle bounds = getBounds();
+ int oldWidth = bounds.width;
+ int redrawX;
+
+ if (width != oldWidth) {
+ redrawX = bounds.x;
+ bounds.width = width;
+ setBounds(bounds);
+ // redraw at old column position if column was resized wider.
+ // fixes focus rectangle.
+ redrawX += Math.min(width, oldWidth);
+ parent.redraw(
+ redrawX - 2, 0,
+ 2, parent.getClientArea().height, false); // redraw 2 pixels wide to redraw item focus rectangle and grid line
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableItem.java
new file mode 100755
index 0000000000..6919d84766
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TableItem.java
@@ -0,0 +1,1032 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * A table item is a selectable user interface object
+ * that represents an item in a table.
+ * Table items can consist of multiple columns called sub items.
+ */
+public /*final*/ class TableItem extends SelectableItem {
+ private static final int FIRST_COLUMN_IMAGE_INDENT = 2; // Space in front of image - first column only
+ private static final int FIRST_COLUMN_TEXT_INDENT = 4; // Space in front of text - first column only
+ private static final int TEXT_INDENT_NO_IMAGE = 2; // Space in front of item text when no item in the column has an image - first column only
+ private static final int TEXT_INDENT = 6; // Space in front of item text - all other columns
+ private static final int SELECTION_PADDING = 6; // Space behind text in a selected item
+
+ private Vector dataLabels = new Vector(); // Original text set by the user. Items that don't
+ // have a label are represented by a null slot
+ private String[] trimmedLabels = new String[0]; // Text that is actually displayed, may be trimmed
+ // to fit the column
+ private Vector images = new Vector(); // Item images. Items that don't have an image
+ // are represented by a null slot
+ private Point selectionExtent; // Size of the rectangle drawn to indicate a
+ // selected item.
+ private int imageIndent = 0; // the factor by which the item image and check box, if any,
+ // are indented. The multiplier is the image width.
+ private int index; // index of the item in the parent widget
+/**
+ * Create a table item in the table widget 'parent'. Append the new
+ * item to the existing items in 'parent'.
+ * @param parent - table widget the new item is added to.
+ * @param style - widget style. See Widget class for details
+ */
+public TableItem(Table parent, int style) {
+ this(parent, style, checkNull(parent).getItemCount());
+}
+/**
+ * Create a table item in the table widget 'parent'. Add the new
+ * item at position 'index' to the existing items in 'parent'.
+ * @param parent - table widget the new item is added to.
+ * @param style - widget style. See Widget class for details
+ * @param index - position the new item is inserted at in 'parent'
+ */
+public TableItem(Table parent, int style, int index) {
+ super(parent, style);
+ parent.addItem(this, index);
+}
+/**
+ * Calculate the size of the rectangle drawn to indicate a selected
+ * item. This is also used to draw the selection focus rectangle.
+ * The selection extent is calculated for the first column only (the
+ * only column the selection is drawn in).
+ */
+void calculateSelectionExtent() {
+ Table parent = getParent();
+ TableColumn column = parent.internalGetColumn(TableColumn.FIRST);
+ GC gc = new GC(parent);
+ String trimmedText = getText(gc, column);
+ int gridLineWidth = parent.getGridLineWidth();
+
+ if (trimmedText != null) {
+ selectionExtent = new Point(gc.stringExtent(trimmedText).x, parent.getItemHeight());
+ selectionExtent.x += getTextIndent(TableColumn.FIRST) + SELECTION_PADDING;
+ selectionExtent.x = Math.min(
+ selectionExtent.x, column.getWidth() - getImageStopX(column.getIndex()) - gridLineWidth);
+ if (parent.getLinesVisible() == true) {
+ selectionExtent.y -= gridLineWidth;
+ }
+ }
+ gc.dispose();
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
+ * Otherwise return 'table'
+ */
+static Table checkNull(Table table) {
+ if (table == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return table;
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * The receiver is destroyed. Remove it from its parent widget.
+ */
+void disposeItem() {
+ getParent().removeItem(this);
+ dataLabels = null;
+ trimmedLabels = null;
+ images = null;
+ selectionExtent = null;
+ super.disposeItem();
+}
+/**
+ * Draw the image of the receiver for column 'index' at
+ * 'destinationPosition' using 'gc'.
+ * Stretch/shrink the image to the fixed image size of the receiver's
+ * parent.
+ * @param gc - GC to draw on.
+ * @param destinationPosition - position on the GC to draw at.
+ * @param index - index of the image to draw
+ * @return Answer the position where drawing stopped.
+ */
+Point drawImage(GC gc, Point destinationPosition, int index) {
+ Table parent = getParent();
+ Image image = getImage(index);
+ Rectangle sourceImageBounds;
+ Point destinationImageExtent = parent.getImageExtent();
+
+ if (image != null) {
+ sourceImageBounds = image.getBounds();
+ // full row select would obscure transparent images in all but the first column
+ // so always clear the image area in this case. Fixes 1FYNITC
+ if ((parent.getStyle() & SWT.FULL_SELECTION) != 0 && index != TableColumn.FIRST) {
+ gc.fillRectangle(
+ destinationPosition.x, destinationPosition.y,
+ destinationImageExtent.x, destinationImageExtent.y);
+ }
+ gc.drawImage(
+ image, 0, 0, // source x, y
+ sourceImageBounds.width, sourceImageBounds.height, // source width, height
+ destinationPosition.x, destinationPosition.y, // destination x, y
+ destinationImageExtent.x, destinationImageExtent.y); // destination width, height
+ }
+ if (((index == TableColumn.FIRST && // always add the image width for the first column
+ parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
+ (index != TableColumn.FIRST && // add the image width if it's not the first column
+ image != null)) && // only when the item actually has an image
+ destinationImageExtent != null) {
+ destinationPosition.x += destinationImageExtent.x;
+ }
+ return destinationPosition;
+}
+/**
+ * Draw the label of the receiver for column 'index' at 'position'
+ * using 'gc'.
+ * The background color is set to the selection background color if
+ * the item is selected and the text is drawn for the first column.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @param index - specifies which subitem text to draw
+ */
+void drawText(String label, GC gc, Point position, int index) {
+ Table parent = getParent();
+ boolean drawSelection;
+ int textOffset;
+ int textHeight;
+
+ if (label != null) {
+ drawSelection = (index == TableColumn.FIRST || (parent.getStyle() & SWT.FULL_SELECTION) != 0);
+ if (isSelected() == true && drawSelection == true) {
+ gc.setBackground(getSelectionBackgroundColor());
+ gc.setForeground(getSelectionForegroundColor());
+ }
+ textHeight = gc.stringExtent(label).y;
+ textOffset = (parent.getItemHeight() - textHeight) / 2; // vertically center the text
+ gc.drawString(label, position.x, position.y + textOffset);
+ if (isSelected() == true && drawSelection == true) {
+ gc.setBackground(parent.getBackground());
+ gc.setForeground(parent.getForeground());
+ }
+ }
+}
+
+/**
+* Gets the item bounds at an index
+* <p>
+* @return the item bounds
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Rectangle getBounds(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle itemBounds;
+ Rectangle columnBounds;
+ Rectangle checkboxBounds;
+ Table parent = getParent();
+ TableColumn column;
+ int itemIndex = parent.indexOf(this);
+ int itemHeight = parent.getItemHeight();
+ int gridLineWidth = parent.getGridLineWidth();
+ int itemYPos;
+
+ if (itemIndex == -1 || index < 0 || index >= parent.internalGetColumnCount()) {
+ itemBounds = new Rectangle(0, 0, 0, 0);
+ }
+ else {
+ column = parent.internalGetColumn(index);
+ columnBounds = column.getBounds();
+ itemYPos = columnBounds.y + itemHeight * itemIndex;
+ itemBounds = new Rectangle(
+ columnBounds.x, itemYPos,
+ columnBounds.width - gridLineWidth, itemHeight - gridLineWidth);
+ if (index == TableColumn.FIRST) {
+ if (isCheckable() == true) {
+ checkboxBounds = getCheckboxBounds();
+ itemBounds.x += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING; // add checkbox start, width and space behind checkbox
+ itemBounds.width -= itemBounds.x;
+ }
+ else {
+ itemBounds.x += getImageIndentPixel();
+ }
+ }
+ }
+ return itemBounds;
+}
+/**
+ * Return whether or not the receiver is checked.
+ * Always return false if the parent of the receiver does not
+ * have the CHECK style.
+ */
+public boolean getChecked() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getChecked();
+}
+/**
+ * Answer the x position of the item check box
+ */
+int getCheckboxXPosition() {
+ return getImageIndentPixel();
+}
+/**
+ * Answer the item labels set by the user.
+ * These may not be the same as those drawn on the screen. The latter
+ * may be trimmed to fit the column. Items that don't have a label are
+ * represented by a null slot in the vector.
+ * @return Vector - the item labels set by the user.
+ */
+Vector getDataLabels() {
+ return dataLabels;
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ return super.getDisplay();
+}
+/**
+ * Return the position at which the string starts that is used
+ * to indicate a truncated item text.
+ * @param columnIndex - index of the column for which the position of
+ * the truncation replacement should be calculated
+ * @param columnWidth - width of the column for which the position of
+ * the truncation replacement should be calculated
+ * @return -1 when the item text is not truncated
+ */
+int getDotStartX(int columnIndex, int columnWidth) {
+ GC gc;
+ Table parent = getParent();
+ String label = getText(columnIndex);
+ int dotStartX = -1;
+ int maxWidth;
+
+ if (label != null) {
+ gc = new GC(parent);
+ maxWidth = getMaxTextWidth(columnIndex, columnWidth);
+ label = parent.trimItemText(label, maxWidth, gc);
+ if (label.endsWith(Table.DOT_STRING) == true) {
+ dotStartX = gc.stringExtent(label).x - parent.getDotsWidth(gc);
+ // add indents, margins and image width
+ dotStartX += getImageStopX(columnIndex);
+ dotStartX += getTextIndent(columnIndex);
+ }
+ gc.dispose();
+ }
+ return dotStartX;
+}
+/**
+ * Gets the grayed state.
+ * <p>
+ * @return the item grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean getGrayed() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getGrayed();
+}
+/**
+ * Answer the item image of the first column.
+ */
+public Image getImage() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getImage(0);
+}
+/**
+ * Answer the item image of the column identified by 'columnIndex' or
+ * null if no image has been set for that column.
+ * @param columnIndex - the column whose image should be answered
+ */
+public Image getImage(int columnIndex) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Image image = null;
+ Vector images = getImages();
+ int itemIndex = getParent().indexOf(this);
+
+ if (itemIndex != -1 && columnIndex >= 0 && columnIndex < images.size()) {
+ image = (Image) images.elementAt(columnIndex);
+ }
+ return image;
+}
+/**
+* Gets the image bounds at an index
+* <p>
+* @return the item icon's bounds
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Rectangle getImageBounds(int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Table parent = getParent();
+ int itemIndex = parent.indexOf (this);
+ int imageWidth = 0;
+ Point imageExtent = parent.getImageExtent();
+ Rectangle checkboxBounds;
+ Rectangle imageBounds = getBounds(index);
+
+ if (itemIndex == -1) {
+ imageBounds = new Rectangle(0, 0, 0, 0);
+ }
+ else
+ if (imageExtent != null) {
+ if (index == TableColumn.FIRST || getImage(index) != null) {
+ imageWidth = imageExtent.x;
+ }
+ }
+ imageBounds.width = imageWidth;
+ return imageBounds;
+}
+/**
+* Gets the image indent.
+* <p>
+* @return the indent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getImageIndent() {
+ if (isValidThread() == false) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isValidWidget() == false) error(SWT.ERROR_WIDGET_DISPOSED);
+ int index = getParent().indexOf(this);
+
+ if (index == -1) {
+ return 0;
+ }
+ return imageIndent;
+}
+/**
+ * Answer the number of pixels the image in the first column is
+ * indented. Calculation starts at the column start and counts
+ * all pixels except the check box.
+ */
+int getImageIndentPixel() {
+ int indentPixel = FIRST_COLUMN_IMAGE_INDENT;
+ Point imageExtent = getParent().getImageExtent();
+
+ if (imageExtent != null) {
+ indentPixel += imageExtent.x * getImageIndent();
+ }
+ return indentPixel;
+}
+/**
+ * Answer the item images set by the user. Items that don't have an
+ * image are represented by a null slot in the vector.
+ */
+Vector getImages() {
+ return images;
+}
+/**
+ * Calculate the x coordinate where the item image of column
+ * 'columnIndex' stops.
+ * @param columnIndex - the column for which the stop position of the
+ * image should be calculated.
+ */
+int getImageStopX(int columnIndex) {
+ int imageStopX = 0;
+ Table parent = getParent();
+ Rectangle checkboxBounds;
+
+ if (columnIndex == TableColumn.FIRST) {
+ if (isCheckable() == true) {
+ checkboxBounds = getCheckboxBounds();
+ imageStopX += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING;
+ }
+ else {
+ imageStopX = getImageIndentPixel();
+ }
+ }
+ if (((columnIndex == TableColumn.FIRST && // always add the image width for the first column
+ parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
+ (columnIndex != TableColumn.FIRST && // add the image width if it's not the first column
+ getImage(columnIndex) != null)) && // only when the item actually has an image
+ parent.getImageExtent() != null) {
+ imageStopX += parent.getImageExtent().x;
+ }
+ return imageStopX;
+}
+/**
+ * Return the index of the item in its parent widget.
+ */
+int getIndex() {
+ return index;
+}
+/**
+ * Return the item extent in the specified column
+ * The extent includes the actual width of the item including checkbox,
+ * image and text.
+ */
+Point getItemExtent(TableColumn column) {
+ Table parent = getParent();
+ int columnIndex = column.getIndex();
+ Point extent = new Point(getImageStopX(columnIndex), parent.getItemHeight() - parent.getGridLineWidth());
+ GC gc = new GC(parent);
+ String trimmedText = getText(gc, column);
+
+ if (trimmedText != null && trimmedText.length() > 0) {
+ extent.x += gc.stringExtent(trimmedText).x + getTextIndent(columnIndex);
+ }
+ if (columnIndex == TableColumn.FIRST) {
+ extent.x += SELECTION_PADDING;
+ }
+ gc.dispose();
+ return extent;
+}
+/**
+ * Answer the maximum width in pixel of the text that fits in the
+ * column identified by 'columnIndex' without trimming the text.
+ * @param columnIndex - the column for which the maximum text width
+ * should be calculated.
+ * @param columnWidth - width of the column 'columnIndex'
+ */
+int getMaxTextWidth(int columnIndex, int columnWidth) {
+ int itemWidth = getImageStopX(columnIndex) + getTextIndent(columnIndex) * 2;
+
+ return columnWidth - itemWidth;
+}
+/**
+ * Answer the parent widget of the receiver.
+ */
+public Table getParent() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return (Table) super.getSelectableParent();
+}
+/**
+ * Answer the width of the item required to display the complete contents.
+ */
+int getPreferredWidth(int index) {
+ int size = getImageStopX(index);
+ String text = getText(index);
+
+ if (text != null) {
+ size += getParent().getTextWidth(text) + getTextIndent(index) * 2 + 1;
+ }
+ return size;
+}
+/**
+ * Return the size of the rectangle drawn to indicate a selected item.
+ * This is also used to draw the selection focus rectangle and drop
+ * insert marker.
+ * Implements SelectableItem#getSelectionExtent
+ */
+Point getSelectionExtent() {
+ Table parent = getParent();
+ Point extent;
+
+ if ((parent.getStyle() & SWT.FULL_SELECTION) == 0) { // regular, first column, selection?
+ if (selectionExtent == null) {
+ calculateSelectionExtent();
+ }
+ extent = selectionExtent;
+ }
+ else {
+ extent = parent.getFullSelectionExtent(this);
+ }
+ return extent;
+}
+/**
+ * Return the x position of the selection rectangle
+ * Implements SelectableItem#getSelectionX
+ */
+int getSelectionX() {
+ return getImageStopX(TableColumn.FIRST) + getParent().getHorizontalOffset();
+}
+/**
+ * Answer the item text of the first column.
+ */
+public String getText() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getText(0);
+}
+/**
+ * Answer the item tezt of the column identified by 'columnIndex'.
+ * Answer null if no text has been set for that column.
+ * @param columnIndex - the column whose text should be answered.
+ * null if no text has been set for that column.
+ */
+public String getText(int columnIndex) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int itemIndex = getParent().indexOf(this);
+ Vector labels = getDataLabels();
+ String label = null;
+
+ if (itemIndex == -1) {
+ error(SWT.ERROR_CANNOT_GET_TEXT);
+ }
+ if (columnIndex >= 0 && columnIndex < labels.size()) {
+ label = (String) labels.elementAt(columnIndex);
+ }
+ if (label == null) {
+ label = ""; // label vector is initialized with null instead of empty Strings
+ }
+ return label;
+}
+/**
+ * Answer the text that is going to be drawn in 'column'. This
+ * text may be a trimmed copy of the original text set by the
+ * user if it doesn't fit into the column. In that case the last
+ * characters are replaced with Table.DOT_STRING.
+ * A cached copy of the trimmed text is returned if available.
+ * @param gc - GC to use for measuring the text extent
+ * @param column - TableColumn for which the text should be returned
+ */
+String getText(GC gc, TableColumn column) {
+ int columnIndex = column.getIndex();
+ String label = getTrimmedText(columnIndex);
+ int maxWidth;
+
+ if (label == null) {
+ maxWidth = getMaxTextWidth(columnIndex, column.getWidth());
+ label = getParent().trimItemText(getText(columnIndex), maxWidth, gc);
+ }
+ return label;
+}
+/**
+ * Answer the indent of the text in column 'columnIndex' in pixel.
+ * This indent is used in front of and behind the item text.
+ * @param columnIndex - specifies the column for which the indent
+ * should be calculated.
+ */
+int getTextIndent(int columnIndex) {
+ int textIndent;
+
+ if (columnIndex == TableColumn.FIRST) {
+ if (getParent().hasFirstColumnImage() == false) {
+ textIndent = TEXT_INDENT_NO_IMAGE;
+ }
+ else {
+ textIndent = FIRST_COLUMN_TEXT_INDENT;
+ }
+ }
+ else {
+ textIndent = TEXT_INDENT;
+ }
+ return textIndent;
+}
+/**
+ * Answer the cached trimmed text for column 'columnIndex'.
+ * Answer null if it hasn't been calculated yet.
+ * @param columnIndex - specifies the column for which the
+ * trimmed text should be answered.
+ */
+String getTrimmedText(int columnIndex) {
+ String label = null;
+ String labels[] = getTrimmedTexts();
+
+ if (columnIndex < labels.length) {
+ label = labels[columnIndex];
+ }
+ return label;
+}
+/**
+ * Answer an array of cached trimmed labels.
+ */
+String [] getTrimmedTexts() {
+ return trimmedLabels;
+}
+/**
+ * Ensure that the image and label vectors have at least
+ * 'newSize' number of elements.
+ */
+void growVectors(int newSize) {
+ Vector images = getImages();
+ Vector labels = getDataLabels();
+
+ if (newSize > images.size()){
+ images.setSize(newSize);
+ }
+ if (newSize > labels.size()){
+ labels.setSize(newSize);
+ }
+}
+/**
+ * Insert 'column' into the receiver.
+ */
+void insertColumn(TableColumn column) {
+ Vector data = getDataLabels();
+ Vector images = getImages();
+ String stringData[];
+ Image imageData[];
+ int index = column.getIndex();
+
+ if (index < data.size()) {
+ data.insertElementAt(null, index);
+ }
+ else {
+ data.addElement(null);
+ }
+ stringData = new String[data.size()];
+ data.copyInto(stringData);
+ setText(stringData);
+
+ if (index < images.size()) {
+ images.insertElementAt(null, index);
+ }
+ else {
+ images.addElement(null);
+ }
+ imageData = new Image[images.size()];
+ images.copyInto(imageData);
+ setImage(imageData);
+}
+/**
+ * Sets the image at an index.
+ * <p>
+ * @param image the new image (or null)
+ *
+ * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+ * when called from the wrong thread
+ * @exception SWTError(ERROR_WIDGET_DISPOSED)
+ * when the widget has been disposed
+ */
+void internalSetImage(int columnIndex, Image image) {
+ Vector images = getImages();
+ boolean imageWasNull = false;
+ Table parent = getParent();
+
+ if (columnIndex >= 0 &&
+ columnIndex < parent.internalGetColumnCount()) {
+ if (columnIndex >= images.size()) {
+ growVectors(columnIndex + 1);
+ }
+ if (((Image) images.elementAt(columnIndex)) == null && image != null) {
+ imageWasNull = true;
+ }
+ images.setElementAt(image, columnIndex);
+ reset(columnIndex); // new image may cause text to no longer fit in the column
+ notifyImageChanged(columnIndex, imageWasNull);
+ }
+}
+/**
+* Sets the widget text.
+* <p>
+*
+* The widget text for an item is the label of the
+* item or the label of the text specified by a column
+* number.
+*
+* @param index the column number
+* @param text the new text
+*
+*/
+void internalSetText(int columnIndex, String string) {
+ Vector labels = getDataLabels();
+ Table parent = getParent();
+ String oldText;
+
+ if (columnIndex >= 0 &&
+ columnIndex < parent.internalGetColumnCount()) {
+ if (columnIndex >= labels.size()) {
+ growVectors(columnIndex + 1);
+ }
+ oldText = (String) labels.elementAt(columnIndex);
+ if (string.equals(oldText) == false) {
+ labels.setElementAt(string, columnIndex);
+ reset(columnIndex);
+ notifyTextChanged(columnIndex, oldText == null);
+ }
+ }
+}
+/**
+ * Answer whether the click at 'xPosition' on the receiver is a
+ * selection click.
+ * A selection click occurred when the click was behind the image
+ * and before the end of the item text.
+ * @return
+ * true - 'xPosition' is a selection click.
+ * false - otherwise
+ */
+boolean isSelectionHit(int xPosition) {
+ int itemStopX = getImageStopX(TableColumn.FIRST);
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent != null) {
+ itemStopX += selectionExtent.x;
+ }
+ return (xPosition > getCheckboxBounds().x + getCheckboxBounds().width) && (xPosition <= itemStopX);
+}
+/**
+ * The image for the column identified by 'columnIndex' has changed.
+ * Notify the parent widget and supply redraw coordinates, if possible.
+ * @param columnIndex - index of the column that has a new image.
+ */
+void notifyImageChanged(int columnIndex, boolean imageWasNull) {
+ Table parent = getParent();
+ Rectangle changedColumnBounds;
+ int redrawStartX = 0;
+ int redrawWidth = 0;
+ int columnCount = parent.internalGetColumnCount();
+
+ if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
+ changedColumnBounds = parent.internalGetColumn(columnIndex).getBounds();
+ redrawStartX = Math.max(0, getImageBounds(columnIndex).x);
+ if (parent.getImageExtent() != null && imageWasNull == false) {
+ redrawWidth = getImageStopX(columnIndex);
+ }
+ else {
+ redrawWidth = changedColumnBounds.width;
+ }
+ redrawWidth += changedColumnBounds.x - redrawStartX;
+ }
+ parent.itemChanged(this, redrawStartX, redrawWidth);
+}
+
+/**
+ * The label for the column identified by 'columnIndex' has changed.
+ * Notify the parent widget and supply redraw coordinates, if possible.
+ * @param columnIndex - index of the column that has a new label.
+ */
+void notifyTextChanged(int columnIndex, boolean textWasNull) {
+ Table parent = getParent();
+ String text;
+ Rectangle columnBounds;
+ int redrawStartX = 0;
+ int redrawWidth = 0;
+ int columnCount = parent.internalGetColumnCount();
+
+ if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
+ text = (String) getDataLabels().elementAt(columnIndex);
+ columnBounds = parent.internalGetColumn(columnIndex).getBounds();
+ redrawStartX = columnBounds.x;
+ if (getImage(columnIndex) != null) {
+ redrawStartX += getImageStopX(columnIndex);
+ }
+ redrawStartX = Math.max(0, redrawStartX);
+ // don't redraw if text changed from null to empty string
+ if (textWasNull == false || text.length() > 0) {
+ redrawWidth = columnBounds.x + columnBounds.width - redrawStartX;
+ }
+ }
+ parent.itemChanged(this, redrawStartX, redrawWidth);
+}
+/**
+ * Draw the receiver at 'paintPosition' in the column identified by
+ * 'columnIndex' using 'gc'.
+ * @param gc - GC to use for drawing
+ * @param paintPosition - position where the receiver should be drawing.
+ * @param column - the column to draw in
+ */
+void paint(GC gc, Point paintPosition, TableColumn column) {
+ int columnIndex = column.getIndex();
+ String label = getText(gc, column);
+ String oldLabel = getTrimmedText(columnIndex);
+
+ if (label != null && label.equals(oldLabel) == false) {
+ setTrimmedText(label, columnIndex);
+ selectionExtent = null; // force a recalculation next time the selection extent is needed
+ }
+ if (columnIndex == TableColumn.FIRST) {
+ paintPosition.x += getImageIndentPixel();
+ if (isCheckable() == true) {
+ paintPosition = drawCheckbox(gc, paintPosition);
+ }
+ }
+ paintPosition = drawImage(gc, paintPosition, columnIndex);
+ paintPosition.x += getTextIndent(columnIndex);
+ drawText(label, gc, paintPosition, columnIndex);
+}
+/**
+ * Remove 'column' from the receiver.
+ */
+void removeColumn(TableColumn column) {
+ Vector data = getDataLabels();
+ Vector images = getImages();
+ String stringData[];
+ Image imageData[];
+ int index = column.getIndex();
+
+ if (index < data.size()) {
+ data.removeElementAt(index);
+ stringData = new String[data.size()];
+ data.copyInto(stringData);
+ setText(stringData);
+ }
+ if (index < images.size()) {
+ images.removeElementAt(index);
+ imageData = new Image[images.size()];
+ images.copyInto(imageData);
+ setImage(imageData);
+ }
+}
+/**
+ * Reset the cached trimmed label for the sub item identified by
+ * 'index'.
+ * @param index - index of the label that should be reset.
+ */
+void reset(int index) {
+ String trimmedLabels[] = getTrimmedTexts();
+
+ if (index >= 0 && index < trimmedLabels.length) {
+ trimmedLabels[index] = null;
+ }
+ if (index == TableColumn.FIRST) {
+ selectionExtent = null;
+ }
+}
+/**
+* Warning: API under construction.
+*/
+public void setImage(Image [] images) {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+
+ if (images == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) == -1) {
+ return;
+ }
+ for (int i = 0; i < images.length; i++) {
+ internalSetImage(i, images[i]);
+ }
+}
+/**
+ * Sets the image at an index.
+ * <p>
+ * @param image the new image (or null)
+ *
+ * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+ * when called from the wrong thread
+ * @exception SWTError(ERROR_WIDGET_DISPOSED)
+ * when the widget has been disposed
+ */
+public void setImage(int columnIndex, Image image) {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+
+ if (getParent().indexOf(this) != -1) {
+ internalSetImage(columnIndex, image);
+ }
+}
+/**
+ * Set the item image of the first column to 'image'.
+ * @param image - the item image of the first column. Image
+ * will be removed if this is null.
+ */
+public void setImage(Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ setImage(0, image);
+}
+/**
+* Sets the image indent.
+* <p>
+* @param indent the new indent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setImageIndent(int indent) {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+ Table parent = getParent();
+ TableColumn column;
+ int index = parent.indexOf(this);
+
+ if (index != -1 && indent >= 0 && indent != imageIndent) {
+ imageIndent = indent;
+ column = parent.internalGetColumn(TableColumn.FIRST);
+ parent.redraw(
+ 0, parent.getRedrawY(this),
+ column.getWidth(), parent.getItemHeight(), false);
+ }
+}
+/**
+ * Warning: API under construction.
+ */
+public void setText(String [] strings) {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+
+ if (strings == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) == -1) {
+ return;
+ }
+ for (int i = 0; i < strings.length; i++) {
+ String string = strings[i];
+ if (string != null) {
+ internalSetText(i, string);
+ }
+ }
+}
+/**
+* Sets the widget text.
+* <p>
+*
+* The widget text for an item is the label of the
+* item or the label of the text specified by a column
+* number.
+*
+* @param index the column number
+* @param text the new text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (int columnIndex, String string) {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+
+ if (string == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) != -1) {
+ internalSetText(columnIndex, string);
+ }
+}
+/**
+ * Set the item text of the first column to 'text'.
+ * @param text - the item text of the first column. May be null if the
+ * text label should be removed.
+ */
+public void setText(String text) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (text == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setText(0, text);
+}
+/**
+ * Set the trimmed text of column 'columnIndex' to label. The trimmed
+ * text is the one that is displayed in a column. It may be shorter than
+ * the text originally set by the user via setText(...) to fit the
+ * column.
+ * @param label - the text label of column 'columnIndex'. May be trimmed
+ * to fit the column.
+ * @param columnIndex - specifies the column whose text label should be
+ * set.
+ */
+void setTrimmedText(String label, int columnIndex) {
+ String labels[] = getTrimmedTexts();
+
+ if (columnIndex < labels.length) {
+ labels[columnIndex] = label;
+ }
+}
+/**
+ * Set the checked state to 'checked' if the parent of the
+ * receiver has the CHECK style.
+ */
+public void setChecked(boolean checked) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setChecked(checked);
+}
+/**
+ * Sets the grayed state.
+ * <p>
+ * @param grayed the new grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public void setGrayed (boolean grayed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setGrayed(grayed);
+}
+/**
+ * Set the index of this item in its parent widget to 'newIndex'.
+ */
+void setIndex(int newIndex) {
+ index = newIndex;
+}
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
new file mode 100755
index 0000000000..ccb7d4dd5f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
@@ -0,0 +1,1261 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A Text is an editable user interface object that
+* displays a single line of text or multiple lines
+* of text.
+* <p>
+* <b>Styles</b><br>
+* <dd>SINGLE, MULTI,<br>
+* <dd>READ_ONLY, WRAP<br>
+* <br>
+* <b>Events</b><br>
+* <dd>Modify<br>
+* <dd>Verify<br>
+*/
+
+/* Class Definition */
+public class Text extends Scrollable {
+ char echoCharacter;
+ boolean ignoreChange;
+ String hiddenText;
+ XmTextVerifyCallbackStruct textVerify;
+ int drawCount;
+
+ public static final int LIMIT;
+ public static final String DELIMITER;
+
+ /*
+ * These values can be different on different platforms.
+ * Therefore they are not initialized in the declaration
+ * to stop the compiler from inlining.
+ */
+ static {
+ LIMIT = 0x7FFFFFFF;
+ DELIMITER = "\n";
+ }
+/**
+* Creates a new instance of the widget.
+*/
+public Text (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addModifyListener (ModifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Modify, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addVerifyListener (VerifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Verify, typedListener);
+}
+/**
+* Appends a string.
+* <p>
+*
+* @param string the string to be appended
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void append (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int position = OS.XmTextGetLastPosition (handle);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetInsertionPosition (handle, position);
+ OS.XmTextInsert (handle, position, buffer);
+ position = OS.XmTextGetLastPosition (handle);
+ OS.XmTextSetInsertionPosition (handle, position);
+ display.setWarnings(warnings);
+}
+static int checkStyle (int style) {
+ if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
+ if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
+ return style | SWT.MULTI;
+ }
+ return style | SWT.SINGLE;
+}
+/**
+* Clears the selection.
+* <p>
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void clearSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = wHint;
+ int height = hHint;
+ if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
+ int [] argList = {OS.XmNfontList, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = OS.XmTextGetString (handle);
+ if (ptr == 0) return new Point (0, 0);
+ int size = OS.strlen (ptr);
+ if (size == 0) {
+ if (hHint == SWT.DEFAULT) {
+ if ((style & SWT.SINGLE) != 0) {
+ height = getLineHeight ();
+ } else {
+ height = DEFAULT_HEIGHT;
+ }
+ }
+ if (wHint == SWT.DEFAULT) {
+ width = DEFAULT_WIDTH;
+ }
+ } else {
+ byte [] buffer = new byte [size + 1];
+ OS.memmove (buffer, ptr, size);
+ int xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ if (hHint == SWT.DEFAULT) {
+ if ((style & SWT.SINGLE) != 0) {
+ height = getLineHeight ();
+ } else {
+ height = OS.XmStringHeight (argList [1], xmString);
+ }
+ }
+ if (wHint == SWT.DEFAULT) width = OS.XmStringWidth(argList [1], xmString);
+ OS.XmStringFree (xmString);
+ }
+ OS.XtFree (ptr);
+ }
+ if (horizontalBar != null) {
+ int [] argList1 = {OS.XmNheight, 0};
+ OS.XtGetValues (horizontalBar.handle, argList1, argList1.length / 2);
+ height += argList1 [1] + 4;
+ }
+ if (verticalBar != null) {
+ int [] argList1 = {OS.XmNwidth, 0};
+ OS.XtGetValues (verticalBar.handle, argList1, argList1.length / 2);
+ width += argList1 [1] + 4;
+ }
+ XRectangle rect = new XRectangle ();
+ OS.XmWidgetGetDisplayRect (handle, rect);
+ width += rect.x * 2; height += rect.y * 2;
+ if ((style & (SWT.MULTI | SWT.BORDER)) != 0) height++;
+ return new Point (width, height);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle trim = super.computeTrim(x, y, width, height);
+ XRectangle rect = new XRectangle ();
+ OS.XmWidgetGetDisplayRect (handle, rect);
+ trim.x -= rect.x;
+ trim.y -= rect.y;
+ trim.width += rect.x;
+ trim.height += rect.y;
+ if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3;
+ return trim;
+}
+/**
+* Copies the selected text to the clipboard.
+*
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void copy () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay));
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int [] argList1 = {
+ OS.XmNverifyBell, 0,
+ OS.XmNeditMode, (style & SWT.SINGLE) != 0 ? OS.XmSINGLE_LINE_EDIT : OS.XmMULTI_LINE_EDIT,
+ OS.XmNscrollHorizontal, (style & SWT.H_SCROLL) != 0 ? 1 : 0,
+ OS.XmNscrollVertical, (style & SWT.V_SCROLL) != 0 ? 1 : 0,
+ OS.XmNwordWrap, (style & SWT.WRAP) != 0 ? 1: 0,
+ OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
+ OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 && (style & SWT.SINGLE) != 0 ? 0 : 1,
+// OS.XmNmarginWidth, 3,
+// OS.XmNmarginHeight, 1,
+ };
+ if ((style & SWT.SINGLE) != 0) {
+ handle = OS.XmCreateTextField (parent.handle, null, argList1, argList1.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ int [] argList2 = new int [] {
+ OS.XmNcursorPositionVisible, 0,
+ };
+ OS.XtSetValues (handle, argList2, argList2.length / 2);
+ if ((style & SWT.BORDER) == 0) {
+ int [] argList3 = new int [] {
+ OS.XmNmarginHeight, 0,
+ OS.XmNshadowThickness, 0
+ };
+ OS.XtSetValues (handle, argList3, argList3.length / 2);
+ }
+ } else {
+ handle = OS.XmCreateScrolledText (parent.handle, null, argList1, argList1.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ scrolledHandle = OS.XtParent (handle);
+ }
+}
+ScrollBar createScrollBar (int type) {
+ return createStandardBar (type);
+}
+public void cut () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay));
+}
+int defaultBackground () {
+ return getDisplay ().textBackground;
+}
+int defaultFont () {
+ return getDisplay ().textFont;
+}
+int defaultForeground () {
+ return getDisplay ().textForeground;
+}
+/**
+* Gets the line number of the caret.
+* <p>
+* The line number of the caret is returned.
+*
+* @return the line number
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getCaretLineNumber () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getLineNumber (OS.XmTextGetInsertionPosition (handle));
+}
+public Point getCaretLocation () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int position;
+ if (textVerify != null) {
+ position = textVerify.currInsert;
+ } else {
+ position = OS.XmTextGetInsertionPosition (handle);
+ }
+ short [] x = new short [1], y = new short [1];
+ OS.XmTextPosToXY (handle, position, x, y);
+ return new Point (x [0], y [0] - getFontAscent ());
+}
+/**
+* Gets the position of the caret.
+* <p>
+* The character position of the caret is returned.
+*
+* @return the position of the caret
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getCaretPosition () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XmTextGetInsertionPosition (handle);
+}
+/**
+* Gets the number of characters.
+* <p>
+*
+* @return number of characters in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getCharCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XmTextGetLastPosition (handle);
+}
+/**
+* Gets the double click enabled flag.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getDoubleClickEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNselectionArrayCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 1;
+}
+/**
+* Gets the echo character.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public char getEchoChar () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return echoCharacter;
+}
+public boolean getEditable () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /*
+ * Bug in MOTIF. For some reason, when XmTextGetEditable () is called
+ * from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback,
+ * it always returns TRUE. Calls to XmTextGetEditable () outside of
+ * these callbacks return the correct value. The fix is to query the
+ * resource directly instead of using the convenience function.
+ */
+ int [] argList = {OS.XmNeditable, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the number of lines.
+*/
+public int getLineCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getLineNumber (echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle));
+}
+/**
+* Gets the line delimiter.
+* <p>
+* @return a string that is the line delimiter
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getLineDelimiter () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return "\n";
+}
+/**
+* Gets the height of each line.
+* <p>
+* @return the height (in pixels) of each row in the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getLineHeight () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getFontHeight ();
+}
+int getLineNumber (int position) {
+ if (position == 0) return 0;
+ int count = 0, start = 0, page = 1024;
+ char [] buffer = new char [page + 1];
+ /*
+ * Bug in Linux. For some reason, XmTextGetSubstringWcs () does
+ * not copy wchar_t characters into the buffer. Instead, it
+ * copies 4 bytes per character. This does not happen on other
+ * platforms such as AIX. The fix is to call XmTextGetSubstring ()
+ * instead on Linux and rely on the fact that Metrolink Motif 1.2
+ * does not support multibyte locales.
+ */
+ byte [] buffer1 = null;
+ if (IsLinux) buffer1 = new byte [page + 1];
+ int end = ((position + page - 1) / page) * page;
+ while (start < end) {
+ int length = page;
+ if (start + page > position) length = position - start;
+ if (echoCharacter != '\0') {
+ hiddenText.getChars (start, start + length, buffer, 0);
+ } else {
+ if (IsLinux) {
+ OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1);
+ for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i];
+ } else {
+ OS.XmTextGetSubstringWcs (handle, start, length, buffer.length, buffer);
+ }
+ }
+ for (int i=0; i<length; i++) {
+ if (buffer [i] == '\n') count++;
+ }
+ start += page;
+ }
+ return count;
+}
+/**
+* Gets the position of the selected text.
+* <p>
+* @return a point (a pair of ints) that represent the beginning and end of the current selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (textVerify != null) {
+ return new Point (textVerify.startPos, textVerify.endPos);
+ }
+ int [] start = new int [1], end = new int [1];
+ OS.XmTextGetSelectionPosition (handle, start, end);
+ if (start [0] == end [0]) {
+ start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
+ }
+ return new Point (start [0], end [0]);
+}
+/**
+* Gets the number of selected characters.
+* <p>
+* @reurn the number of selected characters.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelectionCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (textVerify != null) {
+ return textVerify.endPos - textVerify.startPos;
+ }
+ int [] start = new int [1], end = new int [1];
+ OS.XmTextGetSelectionPosition (handle, start, end);
+ return end [0] - start [0];
+}
+/**
+* Gets the selected text.
+* <p>
+* If no text is selected an empty string is returned.
+*
+* @return the selected text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getSelectionText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (echoCharacter != '\0' || textVerify != null) {
+ Point selection = getSelection ();
+ return getText (selection.x, selection.y);
+ }
+ int ptr = OS.XmTextGetSelection (handle);
+ if (ptr == 0) return "";
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+/**
+* Gets the number of space characters used to represent one tab.
+* <p>
+* @return the number of space characters that are used to represent one tab ('\t') character
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTabs () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /* Tabs are not supported in MOTIF. */
+ return 8;
+}
+/**
+* Gets the text.
+* <p>
+* If there is no text in the widget, an empty string is returned.
+*
+* @return the content of the widget
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (echoCharacter != '\0') return hiddenText;
+ int ptr = OS.XmTextGetString (handle);
+ if (ptr == 0) return "";
+ int length = OS.strlen (ptr);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, ptr, length);
+ OS.XtFree (ptr);
+ return new String (Converter.mbcsToWcs (null, buffer));
+}
+/**
+* Gets the text.
+* <p>
+* Indexing is zero based. The range of text
+* is from the start index up to and including
+* the end index + 1.
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int numChars = end - start + 1;
+ if (numChars < 0 || start < 0) return "";
+ if (echoCharacter != '\0') {
+ return hiddenText.substring (start, Math.min (hiddenText.length (), end));
+ }
+ int length = (numChars * 4 /* MB_CUR_MAX */) + 1;
+ byte [] buffer = new byte [length];
+ int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer);
+ if (code == OS.XmCOPY_FAILED) return "";
+ char [] unicode = Converter.mbcsToWcs (null, buffer);
+ if (code == OS.XmCOPY_TRUNCATED) {
+ numChars = OS.XmTextGetLastPosition (handle) - start;
+ }
+ return new String (unicode, 0, numChars);
+}
+/**
+* Gets the text limit.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTextLimit () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.XmTextGetMaxLength (handle);
+}
+/**
+* Gets the top index.
+* <p>
+* The top index is the index of the line that
+* is currently at the top of the widget. The
+* top index changes when the widget is scrolled.
+* Indexing is zero based.
+*
+* @return the index of the top line
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTopIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SINGLE) != 0) return 0;
+ if (scrolledHandle == 0) return 0;
+ int [] argList1 = {OS.XmNverticalScrollBar, 0};
+ OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
+ if (argList1 [1] == 0) return 0;
+ int [] argList2 = {OS.XmNvalue, 0};
+ OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
+ return argList2 [1];
+}
+/**
+* Gets the top pixel.
+* <p>
+* The top pixel is the pixel position of the line
+* that is currently at the top of the widget. On
+* some platforms, a text widget can be scrolled by
+* pixels instead of lines so that a partial line
+* is displayed at the top of the widget.
+* <p>
+* The top pixel changes when the widget is scrolled.
+* The top pixel does not include the widget trimming.
+*
+* @return the pixel position of the top line
+*
+* @exception SWTError <ul>
+* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+* </ul>
+*/
+public int getTopPixel () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getTopIndex () * getLineHeight ();
+}
+boolean getWrap () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwordWrap, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, SWT.DefaultSelection);
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Modify);
+ OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, SWT.Verify);
+}
+int inputContext () {
+ /* Answer zero. The text widget uses the default MOTIF input context. */
+ return 0;
+}
+/**
+* Replaces the selection with a string.
+* <p>
+* If the no text is selected (the beginning and the end of the selection are equal)
+* the string is inserted.
+*
+* @param string the string
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void insert (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] start = new int [1], end = new int [1];
+ OS.XmTextGetSelectionPosition (handle, start, end);
+ if (start [0] == end [0]) {
+ start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
+ }
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextReplace (handle, start [0], end [0], buffer);
+ int position = start [0] + buffer.length - 1;
+ OS.XmTextSetInsertionPosition (handle, position);
+ display.setWarnings (warnings);
+}
+public void paste () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ /*
+ * Bug in Motif. Despite the fact that the documentation
+ * claims that XmText functions work for XmTextFields, when
+ * a text field is passed to XmTextPaste, Motif segment faults.
+ * The fix is to call XmTextFieldPaste instead.
+ */
+ if ((style & SWT.SINGLE) != 0) {
+ OS.XmTextFieldPaste (handle);
+ } else {
+ OS.XmTextPaste (handle);
+ }
+ display.setWarnings (warnings);
+}
+int processFocusIn () {
+ super.processFocusIn ();
+ if ((style & SWT.READ_ONLY) != 0) return 0;
+ if ((style & SWT.MULTI) != 0) return 0;
+ int [] argList = {OS.XmNcursorPositionVisible, 1};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ return 0;
+}
+int processFocusOut () {
+ super.processFocusOut ();
+ if ((style & SWT.READ_ONLY) != 0) return 0;
+ if ((style & SWT.MULTI) != 0) return 0;
+ int [] argList = {OS.XmNcursorPositionVisible, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ return 0;
+}
+int processModify (int callData) {
+ if (!ignoreChange) super.processModify (callData);
+ return 0;
+}
+int processVerify (int callData) {
+ super.processVerify (callData);
+ if (echoCharacter == '\0' && !hooks (SWT.Verify)) return 0;
+ XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct ();
+ OS.memmove (textVerify, callData, XmTextVerifyCallbackStruct.sizeof);
+ XmTextBlockRec textBlock = new XmTextBlockRec ();
+ OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
+ byte [] buffer = new byte [textBlock.length];
+ OS.memmove (buffer, textBlock.ptr, textBlock.length);
+ String text = new String (Converter.mbcsToWcs (null, buffer));
+ String newText = text;
+ if (!ignoreChange) {
+ Event event = new Event ();
+ if (textVerify.event != 0) {
+ XKeyEvent xEvent = new XKeyEvent ();
+ OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
+ setKeyState (event, xEvent);
+ }
+ event.start = textVerify.startPos;
+ event.end = textVerify.endPos;
+ event.doit = textVerify.doit == 1;
+ event.text = text;
+ sendEvent (SWT.Verify, event);
+ newText = event.text;
+ textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0);
+ }
+ if (newText != null) {
+ if (echoCharacter != '\0' && (textVerify.doit != 0)) {
+ String prefix = hiddenText.substring (0, textVerify.startPos);
+ String suffix = hiddenText.substring (textVerify.endPos, hiddenText.length ());
+ hiddenText = prefix + newText + suffix;
+ char [] charBuffer = new char [newText.length ()];
+ for (int i=0; i<charBuffer.length; i++) {
+ charBuffer [i] = echoCharacter;
+ }
+ newText = new String (charBuffer);
+ }
+ if (newText != text) {
+ byte [] buffer2 = Converter.wcsToMbcs (null, newText, true);
+ int length = buffer2.length;
+ int ptr = OS.XtMalloc (length);
+ OS.memmove (ptr, buffer2, length);
+ textBlock.ptr = ptr;
+ textBlock.length = buffer2.length - 1;
+ OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof);
+ }
+ }
+ OS.memmove (callData, textVerify, XmTextVerifyCallbackStruct.sizeof);
+ textVerify = null;
+ return 0;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeModifyListener (ModifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Modify, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeVerifyListener (VerifyListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Verify, listener);
+}
+/**
+* Selects all of the text.
+* <p>
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void selectAll () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ /* Clear the highlight before setting the selection. */
+ int position = OS.XmTextGetLastPosition (handle);
+// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
+
+ /*
+ * Bug in MOTIF. XmTextSetSelection () fails to set the
+ * selection when the receiver is not realized. The fix
+ * is to force the receiver to be realized by forcing the
+ * shell to be realized. If the receiver is realized before
+ * the shell, MOTIF fails to draw the text widget and issues
+ * lots of X BadDrawable errors.
+ */
+ if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
+
+ /* Set the selection. */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetSelection (handle, 0, position, OS.XtLastTimestampProcessed (xDisplay));
+
+ /* Force the i-beam to follow the highlight/selection. */
+ OS.XmTextSetInsertionPosition (handle, 0);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the bounds.
+*/
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ /*
+ * Bug in Motif. When the receiver is a Text widget
+ * (not a Text Field) and is resized to be smaller than
+ * the inset that surrounds the text and the selection
+ * is set, the receiver scrolls to the left. When the
+ * receiver is resized larger, the text is not scrolled
+ * back. The fix is to detect this case and scroll the
+ * text back.
+ */
+// inset := self inset.
+// nWidth := self dimensionAt: XmNwidth.
+// self noWarnings: [super resizeWidget].
+// nWidth > inset x ifTrue: [^self].
+// self showPosition: self topCharacter
+}
+/**
+* Sets the double click enabled flag.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setDoubleClickEnabled (boolean doubleClick) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the echo character.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setEchoChar (char echo) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (echoCharacter == echo) return;
+ String newText;
+ if (echo == 0) {
+ newText = hiddenText;
+ hiddenText = null;
+ } else {
+ newText = hiddenText = getText();
+ }
+ echoCharacter = echo;
+ Point selection = getSelection();
+ boolean oldValue = ignoreChange;
+ ignoreChange = true;
+ setText(newText);
+ setSelection(selection);
+ ignoreChange = oldValue;
+}
+public void setEditable (boolean editable) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ OS.XmTextSetEditable (handle, editable);
+ style &= ~SWT.READ_ONLY;
+ if (!editable) style |= SWT.READ_ONLY;
+ if ((style & SWT.MULTI) != 0) return;
+ int [] argList = {OS.XmNcursorPositionVisible, editable && hasFocus () ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the redraw flag.
+*/
+public void setRedraw (boolean redraw) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SINGLE) != 0) return;
+ if (redraw) {
+ if (--drawCount == 0) OS.XmTextEnableRedisplay(handle);
+ } else {
+ if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle);
+ }
+}
+/**
+* Sets the selection.
+* <p>
+* @param start new i-beam position
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int start) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ /* Clear the selection and highlight before moving the i-beam. */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int position = OS.XmTextGetLastPosition (handle);
+ int nStart = Math.min (Math.max (start, 0), position);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
+ OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
+
+ /* Set the i-beam position. */
+ OS.XmTextSetInsertionPosition (handle, nStart);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the selection.
+* <p>
+* Indexing is zero based. The range of text
+* is from the start index up to and including
+* the end index + 1.
+*
+* @param start the start of the range
+* @param end the end of the range
+
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (int start, int end) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ /* Clear the highlight before setting the selection. */
+ int position = OS.XmTextGetLastPosition (handle);
+// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
+
+ /*
+ * Bug in MOTIF. XmTextSetSelection () fails to set the
+ * selection when the receiver is not realized. The fix
+ * is to force the receiver to be realized by forcing the
+ * shell to be realized. If the receiver is realized before
+ * the shell, MOTIF fails to draw the text widget and issues
+ * lots of X BadDrawable errors.
+ */
+ if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
+
+ /* Set the selection. */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int nStart = Math.min (Math.max (Math.min (start, end), 0), position);
+ int nEnd = Math.min (Math.max (Math.max (start, end), 0), position);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
+
+ /* Force the i-beam to follow the highlight/selection. */
+ OS.XmTextSetInsertionPosition (handle, nEnd);
+ display.setWarnings (warnings);
+}
+/**
+* Sets the selection.
+* <p>
+* @param selection the point whose x and y fields specify the beginning and the end
+* of the new selection
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when selection is null
+*/
+public void setSelection (Point selection) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setSelection (selection.x, selection.y);
+}
+/**
+* Sets the size.
+*/
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ /*
+ * Bug in Motif. When the receiver is a Text widget
+ * (not a Text Field) and is resized to be smaller than
+ * the inset that surrounds the text and the selection
+ * is set, the receiver scrolls to the left. When the
+ * receiver is resized larger, the text is not scrolled
+ * back. The fix is to detect this case and scroll the
+ * text back.
+ */
+// inset := self inset.
+// nWidth := self dimensionAt: XmNwidth.
+// self noWarnings: [super resizeWidget].
+// nWidth > inset x ifTrue: [^self].
+// self showPosition: self topCharacter
+}
+/**
+* Sets the number of space characters used to represent one tab.
+* <p>
+* @return the number of space characters that are used to represent one tab ('\t') character
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setTabs (int tabs) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ /* Do nothing. Tabs are not supported in MOTIF. */
+}
+/**
+* Sets the text.
+* <p>
+* @param string the new text.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (handle, buffer);
+ OS.XmTextSetInsertionPosition (handle, 0);
+ display.setWarnings(warnings);
+ /*
+ * Bug in Linux. When the widget is multi-line
+ * it does not send a Modify to notify the application
+ * that the text has changed. The fix is to send the event.
+ */
+ if (IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
+}
+/**
+* Sets the text limit.
+* <p>
+* @param limit the new text limit.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setTextLimit (int limit) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
+ OS.XmTextSetMaxLength (handle, limit);
+}
+/**
+* Sets the top index.
+* <p>
+* The top index is the index of the line that
+* is currently at the top of the widget. The
+* top index changes when the widget is scrolled.
+* Indexing starts from zero.
+*
+* @param index the new top index
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setTopIndex (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SINGLE) != 0) return;
+ if (scrolledHandle == 0) return;
+ int [] argList1 = {OS.XmNverticalScrollBar, 0};
+ OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
+ if (argList1 [1] == 0) return;
+ int [] argList2 = {OS.XmNvalue, 0};
+ OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
+ OS.XmTextScroll (handle, index - argList2 [1]);
+}
+void setWrap (boolean wrap) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwordWrap, wrap ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Shows the selection.
+* <p>
+* If there is no selection or the selection
+* is already visible, this method does nothing.
+* If the selection is scrolled out of view,
+* the top index of the widget is changed such
+* that selection becomes visible.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void showSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ int position = OS.XmTextGetInsertionPosition (handle);
+ OS.XmTextShowPosition (handle, position);
+ display.setWarnings (warnings);
+}
+int traversalCode () {
+ if ((style & SWT.SINGLE) != 0) return super.traversalCode ();
+ return SWT.TRAVERSE_ESCAPE;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java
new file mode 100755
index 0000000000..4ed8ef2251
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java
@@ -0,0 +1,211 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The tool bar class supports the layout of
+* selectable tool bar items.
+*
+* Styles
+*
+* WRAP, FLAT
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/* Class Definition */
+public /*final*/ class ToolBar extends Composite {
+ int drawCount, itemCount;
+ ToolItem [] items;
+/**
+* Creates a new instance of the widget.
+*/
+public ToolBar (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int width = wHint, height = hHint;
+ if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
+ if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
+ int [] result = layout (width, height, false);
+ int border = getBorderWidth () * 2;
+ Point extent = new Point (result [1], result [2]);
+ if (wHint != SWT.DEFAULT) extent.x = wHint;
+ if (hHint != SWT.DEFAULT) extent.y = hHint;
+ extent.x += border;
+ extent.y += border;
+ return extent;
+}
+void createItem (ToolItem item, int index) {
+ if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
+ if (itemCount == items.length) {
+ ToolItem [] newItems = new ToolItem [itemCount + 4];
+ System.arraycopy (items, 0, newItems, 0, items.length);
+ items = newItems;
+ }
+ item.createWidget (index);
+ System.arraycopy (items, index, items, index + 1, itemCount++ - index);
+ items [index] = item;
+}
+
+void createHandle (int index) {
+ super.createHandle (index);
+ state &= ~CANVAS;
+}
+
+void createWidget (int index) {
+ super.createWidget (index);
+ items = new ToolItem [4];
+ itemCount = 0;
+}
+void destroyItem (ToolItem item) {
+ int index = 0;
+ while (index < itemCount) {
+ if (items [index] == item) break;
+ index++;
+ }
+ if (index == itemCount) return;
+ System.arraycopy (items, index + 1, items, index, --itemCount - index);
+ items [itemCount] = null;
+}
+public ToolItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ ToolItem [] items = getItems ();
+ if (0 <= index && index < items.length) return items [index];
+ error (SWT.ERROR_INVALID_RANGE);
+ return null;
+}
+
+public ToolItem getItem (Point pt) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ ToolItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ Rectangle rect = items [i].getBounds ();
+ if (rect.contains (pt)) return items [i];
+ }
+ return null;
+}
+
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return itemCount;
+}
+public ToolItem [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ ToolItem [] result = new ToolItem [itemCount];
+ System.arraycopy (items, 0, result, 0, itemCount);
+ return result;
+}
+public int getRowCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rectangle rect = getClientArea ();
+ return layout (rect.width, rect.height, false) [0];
+}
+public int indexOf (ToolItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ ToolItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ if (items [i] == item) return i;
+ }
+ return -1;
+}
+int [] layout (int nWidth, int nHeight, boolean resize) {
+ int xSpacing = 0, ySpacing = 4;
+ int marginWidth = 0, marginHeight = 0;
+ ToolItem [] children = getItems ();
+ int length = children.length;
+ int x = marginWidth, y = marginHeight;
+ int maxHeight = 0, maxX = 0, rows = 1;
+ boolean wrap = (style & SWT.WRAP) != 0;
+ for (int i=0; i<length; i++) {
+ ToolItem child = children [i];
+ Rectangle rect = child.getBounds ();
+ if (wrap && i != 0 && x + rect.width > nWidth) {
+ rows++;
+ x = marginWidth; y += ySpacing + maxHeight;
+ maxHeight = 0;
+ }
+ maxHeight = Math.max (maxHeight, rect.height);
+ if (resize) {
+ child.setBounds (x, y, rect.width, rect.height);
+ }
+ x += xSpacing + rect.width;
+ maxX = Math.max (maxX, x);
+ }
+ return new int [] {rows, maxX, y + maxHeight};
+}
+void relayout () {
+ if (drawCount > 0) return;
+ Rectangle rect = getClientArea ();
+ layout (rect.width, rect.height, true);
+}
+void relayout (int width, int height) {
+ if (drawCount > 0) return;
+ layout (width, height, true);
+}
+void releaseWidget () {
+ for (int i=0; i<itemCount; i++) {
+ ToolItem item = items [i];
+ if (!item.isDisposed ()) {
+ item.releaseWidget ();
+ item.releaseHandle ();
+ }
+ }
+ items = null;
+ super.releaseWidget ();
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ Rectangle rect = getClientArea ();
+ relayout (rect.width, rect.height);
+}
+public void setRedraw (boolean redraw) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (redraw) {
+ if (--drawCount == 0) relayout();
+ } else {
+ drawCount++;
+ }
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ Rectangle rect = getClientArea ();
+ relayout (rect.width, rect.height);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java
new file mode 100755
index 0000000000..6a84ef8a75
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java
@@ -0,0 +1,31 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.motif.*;
+
+class ToolDrawable implements Drawable {
+
+ Device device;
+ int display;
+ int drawable;
+ int fontList;
+ int colormap;
+
+public int internal_new_GC (GCData data) {
+ int xGC = OS.XCreateGC (display, drawable, 0, null);
+ if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (data != null) {
+ data.device = device;
+ data.display = display;
+ data.drawable = drawable;
+ data.fontList = fontList;
+ data.colormap = colormap;
+ }
+ return xGC;
+}
+
+public void internal_dispose_GC (int xGC, GCData data) {
+ OS.XFreeGC (display, xGC);
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
new file mode 100755
index 0000000000..17b8beac50
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
@@ -0,0 +1,763 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+* A tool item is a selectable user interface object
+* that represents a button in a tool bar.
+*
+* <p>
+* <b>Styles</b><br>
+* <dd>CHECK, PUSH, RADIO, SEPARATOR<br>
+* <b>Events</b><br>
+* <dd>Selection<br>
+*/
+
+/* Class Definition */
+public /*final*/ class ToolItem extends Item {
+ ToolBar parent;
+ Image hotImage, disabledImage;
+ String toolTipText;
+ Control control;
+ boolean set, drawHotImage;
+
+/**
+* Creates a new instance of the widget.
+*/
+public ToolItem (ToolBar parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ parent.createItem (this, parent.getItemCount ());
+}
+/**
+* Creates a new instance of the widget.
+*/
+public ToolItem (ToolBar parent, int style, int index) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ parent.createItem (this, index);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ int parentHandle = parent.handle;
+ if ((style & SWT.SEPARATOR) != 0) {
+ int [] argList = {
+ OS.XmNwidth, 8,
+ OS.XmNheight, 5,
+ OS.XmNrecomputeSize, 0,
+ OS.XmNpositionIndex, index,
+ OS.XmNmappedWhenManaged, 0,
+ };
+ handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ return;
+ }
+ int [] argList = {
+ OS.XmNwidth, 24,
+ OS.XmNheight, 22,
+ OS.XmNrecomputeSize, 0,
+ OS.XmNhighlightThickness, 0,
+ OS.XmNmarginWidth, 2,
+ OS.XmNmarginHeight, 1,
+ OS.XmNtraversalOn, 0,
+ OS.XmNpositionIndex, index,
+ OS.XmNshadowType, OS.XmSHADOW_OUT,
+ };
+ handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((parent.style & SWT.FLAT) != 0) {
+ argList = new int [] {OS.XmNshadowThickness, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+
+Point computeSize () {
+ //if (control != null) return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+
+ int [] argList = {
+ OS.XmNmarginHeight, 0,
+ OS.XmNmarginWidth, 0,
+ OS.XmNshadowThickness, 0,
+ OS.XmNhighlightThickness, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int marginHeight = argList[1];
+ int marginWidth = argList[3];
+ int shadowThickness = 2; //argList[5];
+ int highlightThickness = argList[7];
+
+ int textWidth = 0, textHeight = 0;
+ if (text != null && text.length() > 0) {
+ GC gc = new GC (parent);
+ Point textExtent = gc.textExtent (text);
+ textWidth = textExtent.x;
+ textHeight = textExtent.y;
+ gc.dispose ();
+ }
+ int imageWidth = 0, imageHeight = 0;
+ if (image != null) {
+ Rectangle rect = image.getBounds();
+ imageWidth = rect.width;
+ imageHeight= rect.height;
+ }
+
+ int contentHeight = 0, contentWidth = 0;
+ if ((parent.style & SWT.RIGHT) > 0) {
+ contentHeight = Math.max(imageHeight, textHeight);
+ contentWidth = imageWidth + textWidth;
+ if (imageWidth > 0 && textWidth > 0) contentWidth += marginWidth;
+ } else {
+ contentHeight = imageHeight + textHeight;
+ if (imageHeight > 0 && textHeight > 0) contentHeight += marginHeight;
+ contentWidth = Math.max(imageWidth, textWidth);
+ }
+
+ /* This value comes from Windows */
+ int height = 22;
+ if (contentHeight != 0) {
+ height = contentHeight
+ + (2 * marginHeight)
+ + (2 * shadowThickness)
+ + (2 * highlightThickness);
+ }
+
+ /* This value comes from Windows */
+ int width = 24;
+ if (contentWidth != 0) {
+ width = contentWidth
+ + (2 * marginWidth)
+ + (2 * shadowThickness)
+ + (2 * highlightThickness);
+ }
+
+ return new Point (width, height);
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ toolTipText = "";
+ parent.relayout ();
+}
+public void dispose () {
+ ToolBar parent = this.parent;
+ super.dispose ();
+ parent.relayout ();
+}
+public Rectangle getBounds () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]);
+}
+/**
+* Gets the control.
+* <p>
+* @return the control
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Control getControl () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return control;
+}
+/**
+* Gets the disabled image.
+* <p>
+* @return the image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getDisabledmage () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return disabledImage;
+}
+/**
+* Gets the enabled state.
+* <p>
+* A disabled widget is typically not selectable from
+* the user interface and draws with an inactive or
+* grayed look.
+*
+* @return a boolean that is the enabled state of the widget.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+/**
+* Gets the Display.
+*/
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+* Gets the hot image.
+* <p>
+* @return the image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getHotImage () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return hotImage;
+}
+/**
+* Gets the parent.
+* <p>
+* @return the parent
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public ToolBar getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the selection state.
+* <p>
+* @return the selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
+ return set;
+}
+/**
+* Gets the hover help text.
+* <p>
+* @return the hover help text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getToolTipText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return toolTipText;
+}
+public int getWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNwidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+void hookEvents () {
+ super.hookEvents ();
+ if ((style & SWT.SEPARATOR) != 0) return;
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, SWT.Paint);
+// OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, SWT.Selection);
+ OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, SWT.MouseDown);
+ OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, SWT.MouseUp);
+ OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, SWT.MouseMove);
+ OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, SWT.MouseEnter);
+ OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, SWT.MouseExit);
+}
+/**
+* Gets the enabled status.
+* <p>
+* When an ancestor of the widget is disabled, the enabled
+* stats of the widget in the widget hierarchy is disabled
+* regardless of the actual enabled state of the widget.
+*
+* @param enabled a boolean that is the enabled state.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getEnabled () && parent.isEnabled ();
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+int processSelection (int callData) {
+ if ((style & SWT.RADIO) != 0) {
+ selectRadio ();
+ } else {
+ if ((style & SWT.CHECK) != 0) setSelection(!set);
+ }
+ postEvent (SWT.Selection);
+ return 0;
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+void releaseWidget () {
+ getDisplay ().releaseToolTipHandle (handle);
+ super.releaseWidget ();
+ parent = null;
+ control = null;
+ toolTipText = null;
+ disabledImage = hotImage = null;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Selection, listener);
+ eventTable.unhook(SWT.DefaultSelection,listener);
+}
+void selectRadio () {
+ this.setSelection (true);
+ ToolItem [] items = parent.getItems ();
+ int index = 0;
+ while (index < items.length && items [index] != this) index++;
+ ToolItem item;
+ int i = index;
+ while (--i >= 0 && ((item = items [i]).style & SWT.RADIO) != 0) {
+ item.setSelection (false);
+ }
+ i = index;
+ while (++i < items.length && ((item = items [i]).style & SWT.RADIO) != 0) {
+ item.setSelection (false);
+ }
+}
+void setBounds (int x, int y, int width, int height) {
+ if (control != null) control.setBounds(x, y, width, height);
+ /*
+ * Feature in Motif. Motif will not allow a window
+ * to have a zero width or zero height. The fix is
+ * to ensure these values are never zero.
+ */
+ int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1);
+ OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0);
+}
+/**
+* Sets the control.
+* <p>
+* @param control the new control
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setControl (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (control != null && control.parent != parent) {
+ error (SWT.ERROR_INVALID_PARENT);
+ }
+ if ((style & SWT.SEPARATOR) == 0) return;
+ this.control = control;
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds (getBounds ());
+ }
+}
+/**
+* Sets the enabled state.
+* <p>
+* A disabled widget is typically not selectable from
+* the user interface and draws with an inactive or
+* grayed look.
+*
+* @param enabled the new value of the enabled flag
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+* Sets the hot image.
+* <p>
+* @param image the new image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setDisabledImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ disabledImage = image;
+}
+/**
+* Sets the hot image.
+* <p>
+* @param image the new image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setHotImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ hotImage = image;
+}
+/**
+* Sets the widget image.
+* <p>
+* @param image the widget image (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ super.setImage (image);
+
+ /* Resize */
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ Point size = computeSize();
+ if (argList[1] != size.x || argList[3] != size.y) {
+ OS.XtResizeWidget (handle, size.x, size.y, 0);
+ }
+ parent.relayout ();
+}
+
+/**
+* Sets the selection state.
+* <p>
+* @param selected the new selection state
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setSelection (boolean selected) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
+ if (selected == set) return;
+ set = selected;
+ setDrawPressed(set);
+ if ((parent.style & SWT.FLAT) != 0) {
+ int shadowThickness = set ? getDisplay().buttonShadowThickness : 0;
+ int [] argList = {OS.XmNshadowThickness, shadowThickness};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+* Sets the widget text.
+*/
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ super.setText (string);
+
+ /* Resize */
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ Point size = computeSize();
+ if (argList[1] != size.x || argList[3] != size.y) {
+ OS.XtResizeWidget (handle, size.x, size.y, 0);
+ }
+ parent.relayout ();
+}
+
+/**
+* Sets the hover help text.
+* <p>
+* @param string the hover help text (or null)
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setToolTipText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ toolTipText = string;
+}
+
+public void setWidth (int width) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.SEPARATOR) == 0) return;
+ if (width < 0) return;
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XtResizeWidget (handle, width, argList [1], 0);
+ parent.relayout ();
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds (getBounds ());
+ }
+}
+
+void setDrawPressed (boolean value) {
+ int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT;
+ int [] argList = {OS.XmNshadowType, shadowType};
+ OS.XtSetValues(handle, argList, argList.length / 2);
+}
+
+int processMouseDown (int callData) {
+ getDisplay ().hideToolTip();
+ if (set && (style & SWT.RADIO) != 0) return 0;
+ setDrawPressed(!set);
+ return 0;
+}
+
+int processMouseEnter (int callData) {
+ if ((parent.style & SWT.FLAT) != 0) {
+ int [] argList = {OS.XmNshadowThickness, getDisplay().buttonShadowThickness};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+
+ XCrossingEvent xEvent = new XCrossingEvent ();
+ OS.memmove (xEvent, callData, XCrossingEvent.sizeof);
+ boolean button1Pressed = (xEvent.state & OS.Button1Mask) != 0;
+ if (button1Pressed) {
+ setDrawPressed(!set);
+ }
+ drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null;
+ if (drawHotImage) {
+ OS.XClearArea (xEvent.display, xEvent.window, 0, 0, 0, 0, true);
+ }
+ return 0;
+}
+
+int processMouseExit (int callData) {
+ Display display = getDisplay ();
+ display.removeMouseHoverTimeOut ();
+ display.hideToolTip ();
+
+ if ((parent.style & SWT.FLAT) != 0 && !set) {
+ int [] argList = {OS.XmNshadowThickness, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+
+ XCrossingEvent xEvent = new XCrossingEvent ();
+ OS.memmove (xEvent, callData, XCrossingEvent.sizeof);
+ boolean button1Pressed = (xEvent.state & OS.Button1Mask) != 0;
+ if (button1Pressed) {
+ setDrawPressed(set);
+ }
+ if (drawHotImage) {
+ drawHotImage = false;
+ OS.XClearArea (xEvent.display, xEvent.window, 0, 0, 0, 0, true);
+ }
+ return 0;
+}
+
+Point toControl (Point point) {
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
+ return new Point (point.x - root_x [0], point.y - root_y [0]);
+}
+
+int processMouseHover (int id) {
+ Display display = getDisplay();
+ Point local = toControl(display.getCursorLocation());
+ display.showToolTip(handle, toolTipText);
+ return 0;
+}
+
+int processMouseMove (int callData) {
+ Display display = getDisplay ();
+ display.addMouseHoverTimeOut (handle);
+ return 0;
+}
+
+int processMouseUp (int callData) {
+ getDisplay ().hideToolTip();
+
+ /**
+ * Bug in Motif. The activate callback is unreliable on
+ * drawn buttons. Rather than relying on it to generate
+ * selection events, use the mouseUp event.
+ */
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, callData, XButtonEvent.sizeof);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (xEvent.x >= 0 && xEvent.y >= 0 && xEvent.x <= argList[1] && xEvent.y <= argList[3]) {
+ processSelection(0);
+ }
+
+ setDrawPressed(set);
+ return 0;
+}
+
+int processPaint (int callData) {
+ if ((style & SWT.SEPARATOR) != 0) return 0;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return 0;
+
+ int [] argList = {OS.XmNcolormap, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNmarginWidth, 0, OS.XmNmarginHeight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int x = 0, y = 0, width = argList [3], height = argList [5], marginWidth = argList [7], marginHeight = argList [9];
+
+ ToolDrawable wrapper = new ToolDrawable ();
+ wrapper.device = getDisplay ();
+ wrapper.display = xDisplay;
+ wrapper.drawable = xWindow;
+ wrapper.fontList = parent.getFontList ();
+ wrapper.colormap = argList [1];
+ GC gc = new GC (wrapper);
+
+ XmAnyCallbackStruct cb = new XmAnyCallbackStruct ();
+ OS.memmove (cb, callData, XmAnyCallbackStruct.sizeof);
+ if (cb.event != 0) {
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, cb.event, XExposeEvent.sizeof);
+ Rectangle rect = new Rectangle (xEvent.x, xEvent.y, xEvent.width, xEvent.height);
+ gc.setClipping (rect);
+ }
+
+ Image currentImage = drawHotImage ? hotImage : image;
+ if (!getEnabled()) {
+ Display display = getDisplay ();
+ currentImage = disabledImage;
+ if (currentImage == null) {
+ currentImage = new Image (display, image, SWT.IMAGE_DISABLE);
+ }
+ Color disabledColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ gc.setForeground(disabledColor);
+ } else {
+ gc.setForeground (parent.getForeground ());
+ }
+ gc.setBackground (parent.getBackground ());
+
+ int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
+ if (text != null && text.length() > 0) {
+ Point textExtent = gc.textExtent(text);
+ textWidth = textExtent.x;
+ textHeight = textExtent.y;
+ }
+ int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
+ if (currentImage != null) {
+ Rectangle imageBounds = currentImage.getBounds();
+ imageWidth = imageBounds.width;
+ imageHeight = imageBounds.height;
+ }
+
+ if ((parent.style & SWT.RIGHT) > 0) {
+ imageX = x + ((width - imageWidth - textWidth - marginWidth) / 2) + 1;
+ imageY = y + ((height - imageHeight) / 2);
+ textX = imageX + imageWidth + marginWidth;
+ textY = y + ((height - textHeight) / 2);
+ } else {
+ imageX = x + ((width - imageWidth) / 2) + 1;
+ imageY = y + ((height - imageHeight - textHeight - marginHeight) / 2) + 1;
+ textX = x + ((width - textWidth) / 2) + 2;
+ textY = imageY + imageHeight + marginHeight;
+ }
+
+ if (textWidth > 0) gc.drawText(text, textX, textY, false);
+ if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
+
+ gc.dispose ();
+
+ if (!getEnabled() && disabledImage == null) {
+ if (currentImage != null) currentImage.dispose ();
+ }
+ return 0;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java
new file mode 100755
index 0000000000..3f8db147f9
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java
@@ -0,0 +1,193 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
+/**
+*/
+
+/* Class Definition */
+public /*final*/ class Tracker extends Widget {
+ Composite parent;
+ Display display;
+ boolean tracking, stippled;
+ Rectangle [] rectangles = new Rectangle [0];
+/**
+* Creates a new instance of the widget.
+*/
+public Tracker (Composite parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ display = parent.getDisplay ();
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Tracker (Display display, int style) {
+ if (display == null) display = Display.getCurrent ();
+ if (display == null) display = Display.getDefault ();
+ if (!display.isValidThread ()) {
+ error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ this.style = style;
+ this.display = display;
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addControlListener(ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Move,typedListener);
+}
+public void close () {
+ tracking = false;
+}
+void drawRectangles () {
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ parent.getShell ().update ();
+ } else {
+ display.update ();
+ }
+ int xDisplay = display.xDisplay;
+ int color = OS.XWhitePixel (xDisplay, 0);
+ int xWindow = OS.XDefaultRootWindow (xDisplay);
+ if (parent != null) {
+ xWindow = OS.XtWindow (parent.handle);
+ if (xWindow == 0) return;
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (parent.handle, argList, argList.length / 2);
+ color = argList [1] ^ argList [3];
+ }
+ int gc = OS.XCreateGC (xDisplay, xWindow, 0, null);
+ OS.XSetForeground (xDisplay, gc, color);
+ OS.XSetSubwindowMode (xDisplay, gc, OS.IncludeInferiors);
+ OS.XSetFunction (xDisplay, gc, OS.GXxor);
+ int stipplePixmap = 0;
+ if (stippled) {
+ byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
+ stipplePixmap = OS.XCreateBitmapFromData (xDisplay, xWindow, bits, 8, 8);
+ OS.XSetStipple (xDisplay, gc, stipplePixmap);
+ OS.XSetFillStyle (xDisplay, gc, OS.FillStippled);
+ OS.XSetLineAttributes (xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter);
+ }
+ for (int i=0; i<rectangles.length; i++) {
+ Rectangle rect = rectangles [i];
+ OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
+ }
+ if (stippled) {
+ OS.XFreePixmap (xDisplay, stipplePixmap);
+ }
+ OS.XFreeGC (xDisplay, gc);
+}
+public Display getDisplay () {
+ return display;
+}
+public Rectangle [] getRectangles () {
+ return rectangles;
+}
+public boolean getStippled () {
+ return stippled;
+}
+public boolean open () {
+ int xDisplay = display.xDisplay;
+ int color = OS.XWhitePixel (xDisplay, 0);
+ int xWindow = OS.XDefaultRootWindow (xDisplay);
+ if (parent != null) {
+ xWindow = OS.XtWindow (parent.handle);
+ if (xWindow == 0) return false;
+ }
+ boolean cancelled = false;
+ tracking = true;
+ drawRectangles ();
+ Event event = new Event ();
+ XAnyEvent xEvent = new XAnyEvent ();
+ int [] unused = new int [1];
+ int [] newX = new int [1], newY = new int [1], oldX = new int [1], oldY = new int [1];
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, unused);
+ while (tracking) {
+ if (parent != null && parent.isDisposed ()) break;
+ OS.XtAppNextEvent (xtContext, xEvent);
+ switch (xEvent.type) {
+ case OS.ButtonRelease:
+ case OS.MotionNotify:
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused);
+ if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
+ drawRectangles ();
+ for (int i=0; i<rectangles.length; i++) {
+ rectangles [i].x += newX [0] - oldX [0];
+ rectangles [i].y += newY [0] - oldY [0];
+ }
+ sendEvent (SWT.Move);
+ drawRectangles ();
+ oldX [0] = newX [0]; oldY [0] = newY [0];
+ }
+ tracking = xEvent.type != OS.ButtonRelease;
+ break;
+ case OS.KeyPress:
+ XKeyEvent keyEvent = new XKeyEvent ();
+ OS.memmove (keyEvent, xEvent, XKeyEvent.sizeof);
+ if (keyEvent.keycode != 0) {
+ int [] keysym = new int [1];
+ OS.XLookupString (keyEvent, null, 0, keysym, unused);
+ keysym [0] &= 0xFFFF;
+ tracking = keysym [0] != OS.XK_Escape && keysym [0] != OS.XK_Cancel;
+ cancelled = !tracking;
+ }
+ break;
+ }
+ }
+ drawRectangles ();
+ tracking = false;
+ return !cancelled;
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeControlListener (ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Move, listener);
+}
+public void setRectangles (Rectangle [] rectangles) {
+ this.rectangles = rectangles;
+}
+public void setStippled (boolean stippled) {
+ this.stippled = stippled;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tree.java
new file mode 100755
index 0000000000..463f425b91
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tree.java
@@ -0,0 +1,1469 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import java.io.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * Displays a hierarchy of items that can be selected.
+ * Sub hierarchies can be expanded and collapsed.
+ */
+public /*final*/ class Tree extends SelectableItemWidget {
+ // These constants are used internally for item hit test on mouse click
+ private static final int ActionNone = 0; // The mouse event was not handled
+ private static final int ActionExpandCollapse = 1; // Do an expand/collapse
+ private static final int ActionSelect = 2; // Select the item
+ private static final int ActionCheck = 3; // Toggle checked state of the item
+ private static ImageData CollapsedImageData; // collapsed sub tree image data. used to create an image at run time
+ private static ImageData ExpandedImageData; // expanded sub tree image data. used to create an image at run time
+ static {
+ initializeImageData();
+ }
+
+ private TreeRoots root;
+ private TreeItem expandingItem;
+
+ private Image collapsedImage;
+ private Image expandedImage;
+
+ // The following fields are needed for painting tree items
+ final Color CONNECTOR_LINE_COLOR; // Color constant used during painting. Can't keep this in TreeItem
+ // because we only need one instance per tree widget/display and can't
+ // have it static. Initialized in c'tor and freed in dispose();
+ Rectangle hierarchyIndicatorRect = null; // bounding rectangle of the hierarchy indication image (plus/minus)
+
+/**
+ * Create a new instance of the receiver with 'parent'
+ * as its parent widget.
+ */
+public Tree(Composite parent, int style) {
+ super(parent, checkStyle (style));
+ CONNECTOR_LINE_COLOR = new Color(getDisplay(), 170, 170, 170); // Light gray;
+}
+/**
+ * Add 'item' to the list of root items.
+ * @param 'item' - the tree item that should be added as a root.
+ * @param index - position that 'item' will be inserted at
+ * in the receiver.
+ */
+void addItem(TreeItem item, int index) {
+ if (index < 0 || index > getItemCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ getRoot().add(item, index);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ typedListener = new TypedListener(listener);
+ addListener(SWT.Selection, typedListener);
+ addListener(SWT.DefaultSelection, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void addTreeListener(TreeListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ typedListener = new TypedListener(listener);
+ addListener(SWT.Expand, typedListener);
+ addListener(SWT.Collapse, typedListener);
+}
+/**
+ * The SelectableItem 'item' has been added to the tree.
+ * Prevent screen updates when 'item' is inserted due to an
+ * expand operation.
+ * @param item - item that has been added to the receiver.
+ */
+void addedItem(SelectableItem item, int index) {
+ super.addedItem(item, index);
+ redrawAfterModify(item, index); // redraw plus/minus image, hierarchy lines
+}
+/**
+ * Answer the y position of both the first child of 'item' and
+ * the item following the last child of 'item'.
+ * Used to scroll items on expand/collapse.
+ * @param item - TreeItem to use for calculating the y boundary
+ * of child items.
+ * @return Array - first element is the position of the first
+ * child of 'item'. Second element is the position of the item
+ * following the last child of 'item'.
+ * Both elements are -1 if 'item' is not a child of the receiver.
+ */
+int[] calculateChildrenYPos(TreeItem item) {
+ int itemIndex = item.getVisibleIndex();
+ int itemCount = item.getVisibleItemCount();
+ int itemHeight = getItemHeight();
+ int yPos;
+ int[] yPosition = new int[] {-1, -1};
+
+ if (itemIndex != -1) {
+ itemIndex -= getTopIndex();
+ yPos = (itemIndex + itemCount + 1) * itemHeight; // y position of the item following
+ // the last child of 'item'
+ yPosition = new int[] {yPos - (itemCount * itemHeight), yPos};
+ }
+ return yPosition;
+}
+/**
+ * Calculate the widest of the children of 'item'.
+ * Items that are off screen and that may be scrolled into view are
+ * included in the calculation.
+ * @param item - the tree item that was expanded
+ */
+void calculateWidestExpandingItem(TreeItem item) {
+ int itemIndex = item.getVisibleIndex();
+ int newMaximumItemWidth = getContentWidth();
+ int stopIndex = itemIndex + item.getVisibleItemCount();
+
+ for (int i = itemIndex + 1; i <= stopIndex; i++) {
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+/**
+ * Calculate the width of new items as they are scrolled into view.
+ * Precondition:
+ * topIndex has already been set to the new index.
+ * @param topIndexDifference - difference between old and new top
+ * index.
+ */
+void calculateWidestScrolledItem(int topIndexDifference) {
+ int visibleItemCount = getItemCountTruncated(getClientArea());
+ int newMaximumItemWidth = getContentWidth();
+ int topIndex = getTopIndex();
+ int stopIndex = topIndex;
+
+ if (topIndexDifference < 0) { // scrolled up?
+ if (Math.abs(topIndexDifference) > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
+ topIndexDifference = visibleItemCount * -1;
+ }
+ for (int i = stopIndex - topIndexDifference; i >= stopIndex; i--) { // check item width from old top index up to new one
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ }
+ else
+ if (topIndexDifference > 0) { // scrolled down?
+ if (topIndexDifference > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
+ topIndexDifference = visibleItemCount;
+ }
+ stopIndex += visibleItemCount;
+ for (int i = stopIndex - topIndexDifference; i < stopIndex; i++) {
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+/**
+ * Calculate the maximum item width of all displayed items.
+ */
+void calculateWidestShowingItem() {
+ TreeItem visibleItem;
+ int newMaximumItemWidth = 0;
+ int bottomIndex = getBottomIndex();
+ int paintStopX;
+
+ // add one to the loop end index because otherwise an item covered
+ // by the horizontal scroll bar would not be taken into acount and
+ // may become visible after this calculation. We're in trouble if
+ // that item is wider than the client area.
+ if (getHorizontalBar().getVisible() == true) {
+ bottomIndex++;
+ }
+ for (int i = getTopIndex(); i < bottomIndex; i++) {
+ visibleItem = getRoot().getVisibleItem(i);
+ if (visibleItem != null) {
+ paintStopX = visibleItem.getPaintStopX();
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, paintStopX);
+ }
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+static int checkStyle (int style) {
+ return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * Collapse the tree item identified by 'item' if it is not
+ * already collapsed. Move the selection to the parent item
+ * if one of the collapsed items is currently selected.
+ * @param item - item that should be collapsed.
+ * @param notifyListeners -
+ * true=a Collapse event is sent
+ * false=no event is sent
+ */
+void collapse(TreeItem item, boolean notifyListeners) {
+ Event event;
+ int itemIndex;
+
+ if (item.getExpanded() == false) {
+ return;
+ }
+ collapseNoRedraw(item);
+ itemIndex = item.getVisibleIndex();
+ if (itemIndex != -1) { // if the item's parent is not collapsed (and the item is thus visible) do the screen updates
+ item.redrawExpanded(itemIndex - getTopIndex());
+ showSelectableItem(item);
+ calculateVerticalScrollbar();
+ calculateWidestShowingItem();
+ claimRightFreeSpace();
+ claimBottomFreeSpace();
+ }
+ if (notifyListeners == true) {
+ event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Collapse, event);
+ }
+}
+
+/**
+ * Collapse the tree item identified by 'item' if it is not
+ * already collapsed. Move the selection to the parent item
+ * if one of the collapsed items is currently selected.
+ * This method is used to hide the children if an item is deleted.
+ * certain redraw and scroll operations are not needed for this
+ * case.
+ * @param item - item that should be collapsed.
+ */
+void collapseNoRedraw(TreeItem item) {
+ int itemIndex;
+
+ if (item.getExpanded() == false) {
+ return;
+ }
+ if (isSelectedItemCollapsing(item) == true) {
+ deselectAllExcept(item);
+ selectNotify(item);
+ update(); // call update to make sure that new selection is
+ // drawn before items are collapsed (looks better)
+ }
+ scrollForCollapse(item);
+ item.internalSetExpanded(false);
+}
+
+/**
+ * Answer the size of the receiver needed to display all or
+ * the first 50 items whichever is less.
+ */
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Point size = super.computeSize(wHint, hHint, changed);
+ GC gc;
+ final int WidthCalculationCount = 50; // calculate item width for the first couple of items only
+ TreeRoots root = getRoot();
+ TreeItem item;
+ Image itemImage;
+ String itemText;
+ int width;
+ int newItemWidth = 0;
+
+ if (getContentWidth() == 0 && getItemCount() > 0) {
+ gc = new GC(this);
+ for (int i = 0; i < WidthCalculationCount; i++) {
+ item = root.getVisibleItem(i);
+ if (item == null) {
+ break; // no more items
+ }
+ itemImage = item.getImage();
+ itemText = item.getText();
+ width = 0;
+ if (itemImage != null) {
+ width += itemImage.getBounds().width;
+ }
+ if (itemText != null) {
+ width += gc.stringExtent(itemText).x;
+ }
+ newItemWidth = Math.max(newItemWidth, width);
+ }
+ if (newItemWidth > 0) {
+ size.x = newItemWidth;
+ }
+ gc.dispose();
+ }
+ return size;
+}
+/**
+ * Deselect all items of the receiver.
+ */
+public void deselectAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ getRoot().deselectAll();
+ getSelectionVector().removeAllElements();
+ redraw();
+}
+/**
+ * Modifier Key Action
+ * None Collapse the selected item if expanded. Select
+ * parent item if selected item is already
+ * collapsed and if it's not the root item.
+ * Ctrl super.doArrowLeft(int);
+ * Shift see None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowLeft(int keyMask) {
+ TreeItem focusItem = (TreeItem) getLastFocus();
+ TreeItem parentItem;
+
+ if (focusItem == null) {
+ return;
+ }
+ if (keyMask == SWT.CTRL) {
+ super.doArrowLeft(keyMask);
+ }
+ else
+ if (focusItem.getExpanded() == true) { // collapse if expanded
+ collapse(focusItem, true);
+ }
+ else
+ if (focusItem.isRoot() == false) { // go to the parent if there is one
+ parentItem = focusItem.getParentItem();
+ deselectAllExcept(parentItem);
+ selectNotify(parentItem);
+ }
+}
+/**
+ * Modifier Key Action
+ * None Expand selected item if collapsed. Select
+ * first child item if selected item is
+ * already expanded and there is a child item.
+ * Ctrl super.doArrowRight(keyMask);
+ * Shift see None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowRight(int keyMask) {
+ TreeItem focusItem = (TreeItem) getLastFocus();
+ TreeItem childItem;
+
+ if (focusItem == null) {
+ return;
+ }
+ if (keyMask == SWT.CTRL) {
+ super.doArrowRight(keyMask);
+ }
+ else
+ if (focusItem.isLeaf() == false) {
+ if (focusItem.getExpanded() == false) { // expand if collapsed
+ expand(focusItem, true);
+ }
+ else { // go to the first child if there is one
+ childItem = focusItem.getItems()[0];
+ deselectAllExcept(childItem);
+ selectNotify(childItem);
+ }
+ }
+}
+/**
+ * Expand the selected item and all of its children.
+ */
+void doAsterix() {
+ expandAll((TreeItem) getLastFocus());
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ super.doDispose();
+ if (collapsedImage != null) {
+ collapsedImage.dispose();
+ }
+ if (expandedImage != null) {
+ expandedImage.dispose();
+ }
+ getRoot().dispose();
+ CONNECTOR_LINE_COLOR.dispose();
+ resetHierarchyIndicatorRect();
+}
+/**
+ * Collapse the selected item if it is expanded.
+ */
+void doMinus() {
+ TreeItem selectedItem = (TreeItem) getLastFocus();
+
+ if (selectedItem != null) {
+ collapse(selectedItem, true);
+ }
+}
+/**
+ * Expand the selected item if it is collapsed and if it
+ * has children.
+ */
+void doPlus() {
+ TreeItem selectedItem = (TreeItem) getLastFocus();
+
+ if (selectedItem != null && selectedItem.isLeaf() == false) {
+ expand(selectedItem, true);
+ }
+}
+/**
+ * Expand the tree item identified by 'item' if it is not already
+ * expanded. Scroll the expanded items into view.
+ * @param item - item that should be expanded
+ * @param notifyListeners -
+ * true=an Expand event is sent
+ * false=no event is sent
+ */
+void expand(TreeItem item, boolean notifyListeners) {
+ Event event = new Event();
+ int indexFromTop;
+ boolean nestedExpand = expandingItem != null;
+
+ if (item.getExpanded() == true) {
+ return;
+ }
+ if (nestedExpand == false) {
+ setExpandingItem(item);
+ }
+ scrollForExpand(item);
+ item.internalSetExpanded(true);
+ if (notifyListeners == true) {
+ event.item = item;
+ notifyListeners(SWT.Expand, event);
+ }
+ // redraw hierarchy image
+ item.redrawExpanded(item.getVisibleIndex() - getTopIndex());
+ calculateVerticalScrollbar();
+ if (nestedExpand == false && isVisible() == true) {
+ // Save the index here because showSelectableItem may change it
+ indexFromTop = item.getVisibleIndex() - getTopIndex();
+ showSelectableItem(item); // make expanded item visible. Could be invisible if the expand was caused by a key press.
+ calculateWidestExpandingItem(item);
+ scrollExpandedItemsIntoView(item);
+ }
+ if (nestedExpand == false) {
+ setExpandingItem(null);
+ }
+}
+/**
+ * Expand 'item' and all its children.
+ */
+void expandAll(TreeItem item) {
+ TreeItem items[];
+
+ if (item != null && item.isLeaf() == false) {
+ expand(item, true);
+ update();
+ items = item.getItems();
+ for (int i = 0; i < items.length; i++) {
+ expandAll(items[i]);
+ }
+ }
+}
+/**
+ * Answer the image that is used as a hierarchy indicator
+ * for a collapsed hierarchy.
+ */
+Image getCollapsedImage() {
+ if (collapsedImage == null) {
+ collapsedImage = new Image(getDisplay(), CollapsedImageData);
+ }
+ return collapsedImage;
+}
+/**
+ * Answer the width of the item identified by 'itemIndex'.
+ */
+int getContentWidth(int itemIndex) {
+ TreeItem item = getRoot().getVisibleItem(itemIndex);
+ int paintStopX = 0;
+
+ if (item != null) {
+ paintStopX = item.getPaintStopX();
+ }
+ return paintStopX;
+}
+/**
+ * Answer the image that is used as a hierarchy indicator
+ * for an expanded hierarchy.
+ */
+Image getExpandedImage() {
+ if (expandedImage == null) {
+ expandedImage = new Image(getDisplay(), ExpandedImageData);
+ }
+ return expandedImage;
+}
+/**
+ * Answer the rectangle enclosing the hierarchy indicator of a tree item.
+ *
+ * Note:
+ * Assumes that the hierarchy indicators for expanded and
+ * collapsed state are the same size.
+ * @return
+ * The rectangle enclosing the hierarchy indicator.
+ */
+Rectangle getHierarchyIndicatorRect() {
+ int itemHeight = getItemHeight();
+ Image hierarchyImage;
+ Rectangle imageBounds;
+
+ if (hierarchyIndicatorRect == null && itemHeight != -1) {
+ hierarchyImage = getCollapsedImage();
+ if (hierarchyImage != null) {
+ imageBounds = hierarchyImage.getBounds();
+ }
+ else {
+ imageBounds = new Rectangle(0, 0, 0, 0);
+ }
+ hierarchyIndicatorRect = new Rectangle(
+ 0,
+ (itemHeight - imageBounds.height) / 2 + (itemHeight - imageBounds.height) % 2,
+ imageBounds.width,
+ imageBounds.height);
+ }
+ return hierarchyIndicatorRect;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+int getIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null) {
+ index = ((TreeItem) item).getGlobalIndex();
+ }
+ return index;
+}
+/**
+ * Answer the number of root items.
+ */
+public int getItemCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return getRoot().getItemCount();
+}
+/**
+ * Answer the height of an item in the receiver.
+ * The item height is the greater of the item icon height and
+ * text height of the first item that has text or an image
+ * respectively.
+ * Calculate a default item height based on the font height if
+ * no item height has been calculated yet.
+ */
+public int getItemHeight() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getItemHeight();
+}
+/**
+ * Answer the root items of the receiver as an Array.
+ */
+public TreeItem [] getItems() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TreeItem childrenArray[] = new TreeItem[getItemCount()];
+
+ getRoot().getChildren().copyInto(childrenArray);
+ return childrenArray;
+}
+/**
+ * Answer the number of sub items of 'item' that do not fit in the
+ * tree client area.
+ */
+int getOffScreenItemCount(TreeItem item) {
+ int itemIndexFromTop = item.getVisibleIndex() - getTopIndex();
+ int spaceRemaining = getItemCountWhole()-(itemIndexFromTop+1);
+ int expandedItemCount = item.getVisibleItemCount();
+
+ return expandedItemCount - spaceRemaining;
+}
+/**
+ * Answer the parent item of the receiver.
+ * This is null because the Tree widget does not have a parent item.
+ */
+public TreeItem getParentItem() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return null;
+}
+/**
+ * Answer the object that holds the root items of the receiver.
+ */
+TreeRoots getRoot() {
+ return root;
+}
+/**
+ * Answer the selected tree items.
+ * @return an Array of DrawnTreeItems containing the selected items.
+ * An empty Array if no items are selected.
+ */
+public TreeItem [] getSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector selectionVector = getSelectionVector();
+ TreeItem[] selectionArray = new TreeItem[selectionVector.size()];
+
+ selectionVector.copyInto(selectionArray);
+ sort(selectionArray, 0, selectionArray.length);
+ return selectionArray;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Collapsed items are not visible.
+ */
+int getVisibleIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null) {
+ index = ((AbstractTreeItem) item).getVisibleIndex();
+ }
+ return index;
+}
+/**
+ * Answer the SelectableItem located at 'itemIndex'
+ * in the receiver.
+ * @param itemIndex - location of the SelectableItem
+ * object to return
+ */
+SelectableItem getVisibleItem(int itemIndex) {
+ return getRoot().getVisibleItem(itemIndex);
+}
+/**
+ * Answer the number of visible items of the receiver.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Collapsed items are not visible.
+ */
+int getVisibleItemCount() {
+ return getRoot().getVisibleItemCount();
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+int getVisibleRedrawY(SelectableItem item) {
+ int redrawY = getRedrawY(item);
+
+ if (redrawY < 0 || redrawY > getClientArea().height) {
+ redrawY = -1;
+ }
+ return redrawY;
+}
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.Paint:
+ paint(event);
+ break;
+ case SWT.MouseDown:
+ mouseDown(event);
+ break;
+ case SWT.MouseDoubleClick:
+ mouseDoubleClick(event);
+ break;
+ default:
+ super.handleEvents(event);
+ }
+}
+/**
+ * Initialize the receiver.
+ */
+void initialize() {
+ resetRoot(); // has to be at very top because super class uses
+ // functionality that relies on the TreeRoots object
+ super.initialize();
+}
+/**
+ * Initialize the ImageData used for the expanded/collapsed images.
+ */
+static void initializeImageData() {
+ PaletteData fourBit = new PaletteData(
+ new RGB[] {new RGB(0, 0, 0), new RGB (128, 0, 0), new RGB (0, 128, 0), new RGB (128, 128, 0), new RGB (0, 0, 128), new RGB (128, 0, 128), new RGB (0, 128, 128), new RGB (128, 128, 128), new RGB (192, 192, 192), new RGB (255, 0, 0), new RGB (0, 255, 0), new RGB (255, 255, 0), new RGB (0, 0, 255), new RGB (255, 0, 255), new RGB (0, 255, 255), new RGB (255, 255, 255)});
+
+ CollapsedImageData = new ImageData(
+ 9, 9, 4, // width, height, depth
+ fourBit, 4,
+ new byte[] {119, 119, 119, 119, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, 0, 0, 15, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, 15, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 119, 119, 119, 119, 112, 0, 0, 0});
+ CollapsedImageData.transparentPixel = 15; // use white for transparency
+ ExpandedImageData = new ImageData(
+ 9, 9, 4, // width, height, depth
+ fourBit, 4,
+ new byte[] {119, 119, 119, 119, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, 0, 0, 15, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 127, -1, -1, -1, 112, 0, 0, 0, 119, 119, 119, 119, 112, 0, 0, 0});
+ ExpandedImageData.transparentPixel = 15; // use white for transparency
+}
+/**
+ * Set event listeners for the receiver.
+ */
+void installListeners() {
+ Listener listener = getListener();
+
+ super.installListeners();
+ addListener(SWT.Paint, listener);
+ addListener(SWT.MouseDown, listener);
+ addListener(SWT.MouseDoubleClick, listener);
+}
+/**
+ * Answer whether the receiver is currently expanding a sub tree
+ * with 'item' in it.
+ * Used for performance optimizations.
+ */
+boolean isExpandingItem(SelectableItem item) {
+ TreeItem parentItem;
+
+ if (expandingItem == null || item == null || (item instanceof TreeItem) == false) {
+ return false;
+ }
+ parentItem = ((TreeItem) item).getParentItem();
+ return (parentItem == expandingItem || isExpandingItem(parentItem));
+}
+/**
+ * Answer whether the children of 'collapsingItem' contain
+ * at least one selected item.
+ */
+boolean isSelectedItemCollapsing(TreeItem collapsingItem) {
+ Enumeration selection = getSelectionVector().elements();
+ TreeItem item;
+ int selectedItemIndex;
+ int collapsingItemIndex = collapsingItem.getVisibleIndex();
+ int lastCollapsedItemIndex = collapsingItemIndex + collapsingItem.getVisibleItemCount();
+
+ if (collapsingItemIndex == -1) { // is the collapsing item in a collapsed subtree?
+ return false; // then neither it nor its children are selected
+ }
+ while (selection.hasMoreElements() == true) {
+ item = (TreeItem) selection.nextElement();
+ selectedItemIndex = item.getVisibleIndex();
+ if ((selectedItemIndex > collapsingItemIndex) &&
+ (selectedItemIndex <= lastCollapsedItemIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * Test whether the mouse click specified by 'event' was a
+ * valid selection or expand/collapse click.
+ * @return
+ * One of ActionExpandCollapse, ActionSelect, ActionNone, ActionCheck
+ * specifying the action to be taken on the click.
+ */
+int itemAction(TreeItem item, int x, int y) {
+ int action = ActionNone;
+ int itemHeight = getItemHeight();
+ int offsetX;
+ int offsetY;
+ Point offsetPoint;
+
+ if (item != null) {
+ offsetX = x - item.getPaintStartX();
+ offsetY = y - itemHeight * (y / itemHeight);
+ offsetPoint = new Point(offsetX, offsetY);
+ if ((item.isLeaf() == false) &&
+ (getHierarchyIndicatorRect().contains(offsetPoint) == true)) {
+ action |= ActionExpandCollapse;
+ }
+ else
+ if (item.isSelectionHit(offsetPoint) == true) {
+ action |= ActionSelect;
+ }
+ else
+ if (item.isCheckHit(new Point(x, y)) == true) {
+ action |= ActionCheck;
+ }
+ }
+ return action;
+}
+/**
+ * The table item 'changedItem' has changed. Redraw the whole
+ * item in that column. Include the text in the redraw because
+ * an image set to null requires a redraw of the whole item anyway.
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ int oldItemHeight = getItemHeight();
+ Point oldImageExtent = getImageExtent();
+
+ if (isExpandingItem(changedItem) == false) {
+ super.itemChanged(changedItem, repaintStartX, repaintWidth);
+ }
+ else {
+ calculateItemHeight(changedItem);
+ }
+ if ((oldItemHeight != getItemHeight()) || // only reset items if the item height or
+ (oldImageExtent != getImageExtent())) { // image size has changed. The latter will only change once,
+ // from null to a value-so it's safe to test using !=
+ getRoot().reset(); // reset cached data of all items in the receiver
+ resetHierarchyIndicatorRect();
+ redraw(); // redraw all items if the image extent has changed. Fixes 1FRIHPZ
+ }
+ else {
+ ((AbstractTreeItem) changedItem).reset(); // reset the item that has changed when the tree item
+ // height has not changed (otherwise the item caches old data)
+ // Fixes 1FF6B42
+ }
+ if (repaintWidth != 0) {
+ calculateWidestShowingItem();
+ claimRightFreeSpace(); // otherwise scroll bar may be reset, but not horizontal offset
+ // Fixes 1G4SBJ3
+ }
+}
+/**
+ * A key was pressed.
+ * Call the appropriate key handler method.
+ * @param event - the key event
+ */
+void keyDown(Event event) {
+ super.keyDown(event);
+ switch (event.character) {
+ case '+':
+ doPlus();
+ break;
+ case '-':
+ doMinus();
+ break;
+ case '*':
+ doAsterix();
+ break;
+ }
+}
+
+/**
+ * A mouse double clicked occurred over the receiver.
+ * Expand/collapse the clicked item. Do nothing if no item was clicked.
+ */
+void mouseDoubleClick(Event event) {
+ int hitItemIndex = event.y / getItemHeight();
+ TreeItem hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ Event newEvent;
+
+ if (hitItem == null) {
+ return;
+ }
+ if (hooks(SWT.DefaultSelection) == true) {
+ newEvent = new Event();
+ newEvent.item = hitItem;
+ notifyListeners(SWT.DefaultSelection, newEvent);
+ return;
+ }
+ if (hitItem.getItemCount() == 0) {
+ return; // an item was hit but it does not have children
+ }
+ if (itemAction(hitItem, event.x, event.y) == ActionSelect) {
+ if (hitItem.getExpanded() == true) {
+ collapse(hitItem, true);
+ }
+ else {
+ expand(hitItem, true);
+ }
+ }
+}
+/**
+ * The mouse pointer was pressed down on the receiver.
+ * Handle the event according to the position of the mouse click.
+ */
+void mouseDown(Event event) {
+ int hitItemIndex;
+ TreeItem hitItem;
+ SelectableItem selectionItem = getLastSelection();
+ int itemAction;
+
+ if (event.button != 1) { // only react to button one clicks.
+ return;
+ }
+ hitItemIndex = event.y / getItemHeight();
+ hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ if (hitItem == null) {
+ return;
+ }
+ switch (itemAction = itemAction(hitItem, event.x, event.y)) {
+ case ActionExpandCollapse:
+ if (hitItem.getExpanded() == true) {
+ collapse(hitItem, true);
+ }
+ else {
+ expand(hitItem, true);
+ }
+ break;
+ case ActionSelect:
+ doMouseSelect(hitItem, hitItemIndex + getTopIndex(), event.stateMask, event.button);
+ break;
+ case ActionCheck:
+ doCheckItem(hitItem);
+ break;
+ }
+ if (itemAction != ActionSelect && selectionItem == null) {
+ selectionItem = getRoot().getVisibleItem(getTopIndex()); // select the top item if no item was selected before
+ selectNotify(selectionItem);
+ }
+}
+/**
+ * A paint event has occurred. Display the invalidated items.
+ * @param event - expose event specifying the invalidated area.
+ */
+void paint(Event event) {
+ int visibleRange[] = getIndexRange(event.getBounds());
+
+ paintItems(event.gc, visibleRange[0], visibleRange[1] + 1); // + 1 to paint the vertical line
+ // connection the last item we really
+ // want to paint with the item after that.
+}
+/**
+ * Paint tree items on 'gc' starting at index 'topPaintIndex' and
+ * stopping at 'bottomPaintIndex'.
+ * @param gc - GC to draw tree items on.
+ * @param topPaintIndex - index of the first item to draw
+ * @param bottomPaintIndex - index of the last item to draw
+ */
+void paintItems(GC gc, int topPaintIndex, int bottomPaintIndex) {
+ TreeItem visibleItem;
+ int itemHeight = getItemHeight();
+
+ for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
+ visibleItem = getRoot().getVisibleItem(i + getTopIndex());
+ if (visibleItem != null) {
+ visibleItem.paint(gc, i * itemHeight);
+ }
+ }
+}
+/**
+ * 'item' has been added to or removed from the receiver.
+ * Repaint part of the tree to update the vertical hierarchy
+ * connectors and hierarchy image.
+ * @param modifiedItem - the added/removed item
+ * @param modifiedIndex - index of the added/removed item
+ */
+void redrawAfterModify(SelectableItem modifiedItem, int modifiedIndex) {
+ int redrawStartY;
+ int redrawStopY;
+ int itemChildIndex = ((TreeItem) modifiedItem).getIndex();
+ int topIndex = getTopIndex();
+ int itemHeight = getItemHeight();
+ int redrawItemIndex;
+ int itemCount;
+ AbstractTreeItem parentItem = ((TreeItem) modifiedItem).getParentItem();
+ AbstractTreeItem redrawItem = null;
+
+ if (redrawParentItem(modifiedItem) == false) {
+ return;
+ }
+ if (parentItem == null) { // a root item is added/removed
+ parentItem = getRoot();
+ }
+ itemCount = parentItem.getItemCount();
+ // redraw hierarchy decorations of preceeding item if the last item at a tree
+ // level was added/removed
+ // otherwise, if the first item was removed, redraw the parent to update hierarchy icon
+ if (itemChildIndex > 0) { // more than one item left at this tree level
+ // added/removed last item at this tree level? have to test >=.
+ // when removing last item, item index is outside itemCount
+ if (itemChildIndex >= itemCount - 1) {
+ redrawItem = (AbstractTreeItem) parentItem.getChildren().elementAt(itemChildIndex - 1);
+ }
+ }
+ else
+ if (getVisibleItemCount() > 0 && itemCount < 2) { // last item at this level removed/first item added?
+ redrawItem = parentItem; // redraw parent item to update hierarchy icon
+ }
+ if (redrawItem != null) {
+ redrawItemIndex = redrawItem.getVisibleIndex();
+ if (modifiedIndex == -1) {
+ modifiedIndex = redrawItemIndex + 1;
+ }
+ redrawStartY = (redrawItemIndex - topIndex) * itemHeight;
+ redrawStopY = (modifiedIndex - topIndex) * itemHeight;
+ redraw(
+ 0,
+ redrawStartY,
+ redrawItem.getCheckboxXPosition(), // only redraw up to and including hierarchy icon to avoid flashing
+ redrawStopY - redrawStartY, false);
+ }
+ if (modifiedIndex == 0) { // added/removed first item ?
+ redraw(0, 0, getClientArea().width, getItemHeight() * 2, false);// redraw new first two items to
+ // fix vertical hierarchy line
+ }
+}
+
+/**
+ * Determine if part of the tree hierarchy needs to be redrawn.
+ * The hierarchy icon of the parent item of 'item' needs to be redrawn if
+ * 'item' is added as the first child or removed as the last child.
+ * Hierarchy lines need to be redrawn if 'item' is the last in a series of
+ * children.
+ * @param item - tree item that is added or removed.
+ * @return true=tree hierarchy needs to be redrawn. false=no redraw necessary
+ */
+boolean redrawParentItem(SelectableItem item) {
+ TreeItem parentItem = ((TreeItem) item).getParentItem();
+ TreeItem parentItem2;
+ boolean redraw = false;
+
+ // determine if only the hierarchy icon needs to be redrawn
+ if (parentItem != null) {
+ parentItem2 = parentItem.getParentItem();
+ if ((parentItem2 == null || parentItem2.getExpanded() == true) && parentItem.getChildren().size() < 2) {
+ redraw = true;
+ }
+ }
+ // redraw is only neccessary when the receiver is not currently
+ // expanding 'item' or a parent item or if the parent item is expanded
+ // or if the hierarchy icon of the parent item needs to be redrawn
+ if (isExpandingItem(item) == false && parentItem == null || parentItem.getExpanded() == true || redraw == true) {
+ redraw = true;
+ }
+ else {
+ redraw = false;
+ }
+ return redraw;
+}
+
+/**
+ * Remove all items of the receiver.
+ */
+public void removeAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ setRedraw(false);
+ getRoot().dispose();
+ resetRoot();
+ reset();
+ calculateWidestShowingItem();
+ calculateVerticalScrollbar();
+ setRedraw(true);
+}
+/**
+ * Remove 'item' from the receiver.
+ * @param item - tree item that should be removed from the
+ * receiver-must be a root item.
+ */
+void removeItem(TreeItem item) {
+ getRoot().removeItem(item);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener (SWT.Selection, listener);
+ removeListener (SWT.DefaultSelection, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+*/
+public void removeTreeListener(TreeListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener (SWT.Expand, listener);
+ removeListener (SWT.Collapse, listener);
+}
+/**
+ * 'item' has been removed from the receiver.
+ * Recalculate the content width.
+ */
+void removedItem(SelectableItem item) {
+ if (isExpandingItem(item) == false) {
+ super.removedItem(item);
+ }
+ calculateWidestShowingItem();
+ claimRightFreeSpace();
+}
+/**
+ * Notification that 'item' is about to be removed from the tree.
+ * Update the item selection if neccessary.
+ * @param item - item that is about to be removed from the tree.
+ */
+void removingItem(SelectableItem item) {
+ Vector selection = getSelectionVector();
+ TreeItem parentItem = ((TreeItem) item).getParentItem();
+ TreeItem newSelectionItem = null;
+ boolean isLastSelected = (selection.size() == 1) && (selection.elementAt(0) == item);
+ int itemIndex = getVisibleIndex(item);
+
+ if (isLastSelected == true) {
+ // try selecting the following item
+ newSelectionItem = (TreeItem) getVisibleItem(itemIndex + 1);
+ if (newSelectionItem == null || newSelectionItem.getParentItem() != parentItem) {
+ // select parent item if there is no item following the removed
+ // one on the same tree level
+ newSelectionItem = parentItem;
+ }
+ if (newSelectionItem != null) {
+ selectNotify(newSelectionItem);
+ }
+ }
+ super.removingItem(item);
+ if (isExpandingItem(item) == false) {
+ // redraw plus/minus image, hierarchy lines,
+ // redrawing here assumes that no update happens between now and
+ // after the item has actually been removed. Otherwise this call
+ // would need to be in removedItem and we would need to store the
+ // "itemIndex" here to redraw correctly.
+ redrawAfterModify(item, itemIndex);
+ }
+}
+/**
+ * Reset the rectangle enclosing the hierarchy indicator to null.
+ * Forces a recalculation next time getHierarchyIndicatorRect is called.
+ */
+void resetHierarchyIndicatorRect() {
+ hierarchyIndicatorRect = null;
+}
+/**
+ * Reset state that is dependent on or calculated from the items
+ * of the receiver.
+ */
+void resetItemData() {
+ setContentWidth(0);
+ resetHierarchyIndicatorRect();
+ super.resetItemData();
+}
+/**
+ * Reset the object holding the root items of the receiver.
+ */
+void resetRoot() {
+ root = new TreeRoots(this);
+}
+/**
+ * The receiver has been resized. Recalculate the content width.
+ */
+void resize(Event event) {
+ int oldItemCount = getVerticalBar().getPageIncrement();
+
+ super.resize(event);
+ if (getItemCountWhole() > oldItemCount) { // window resized higher?
+ calculateWidestShowingItem(); // recalculate widest item since a longer item may be visible now
+ }
+}
+/**
+ * Display as many expanded tree items as possible.
+ * Scroll the last expanded child to the bottom if all expanded
+ * children can be displayed.
+ * Otherwise scroll the expanded item to the top.
+ * @param item - the tree item that was expanded
+ */
+void scrollExpandedItemsIntoView(TreeItem item) {
+ int itemCountOffScreen = getOffScreenItemCount(item);
+ int newTopIndex = getTopIndex() + itemCountOffScreen;
+
+ if (itemCountOffScreen > 0) {
+ newTopIndex = Math.min(item.getVisibleIndex(), newTopIndex); // make sure the expanded item is never scrolled out of view
+ setTopIndex(newTopIndex, true);
+ }
+}
+/**
+ * Scroll the items following the children of 'collapsedItem'
+ * below 'collapsedItem' to cover the collapsed children.
+ * @param collapsedItem - item that has been collapsed
+ */
+void scrollForCollapse(TreeItem collapsedItem) {
+ Rectangle clientArea = getClientArea();
+ int topIndex = getTopIndex();
+ int itemCount = collapsedItem.getVisibleItemCount();
+ int scrollYPositions[] = calculateChildrenYPos(collapsedItem);
+
+ if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
+ return;
+ }
+ if (topIndex + getItemCountWhole() == getVisibleItemCount() && itemCount < topIndex) {
+ // scroll from top if last item is at bottom and will stay at
+ // bottom after collapse. Avoids flash caused by too much bit
+ // blitting (which force update and thus premature redraw)
+ int height = scrollYPositions[1] - scrollYPositions[0];
+ scroll(
+ 0, 0, // destination x, y
+ 0, -height, // source x, y
+ clientArea.width, scrollYPositions[0]+height, true);
+ setTopIndexNoScroll(topIndex - itemCount, true);
+ }
+ else {
+ scroll(
+ 0, scrollYPositions[0], // destination x, y
+ 0, scrollYPositions[1], // source x, y
+ clientArea.width, clientArea.height - scrollYPositions[0], true);
+ }
+}
+/**
+ * Scroll the items following 'expandedItem' down to make
+ * space for the children of 'expandedItem'.
+ * @param expandedItem - item that has been expanded.
+ */
+void scrollForExpand(TreeItem expandedItem) {
+ int scrollYPositions[];
+ Rectangle clientArea = getClientArea();
+
+ expandedItem.internalSetExpanded(true);
+ scrollYPositions = calculateChildrenYPos(expandedItem);
+ expandedItem.internalSetExpanded(false);
+ if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
+ return;
+ }
+ scroll(
+ 0, scrollYPositions[1], // destination x, y
+ 0, scrollYPositions[0], // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void scrollHorizontal(int numPixel) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+void scrollVertical(int scrollIndexCount) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ 0, 0, // destination x, y
+ 0, scrollIndexCount * getItemHeight(), // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Select all items of the receiver if it is in multiple
+ * selection mode.
+ * A SWT.Selection event will not be sent.
+ * Do nothing if the receiver is in single selection mode.
+ */
+public void selectAll() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Vector selection = getSelectionVector();
+
+ if (isMultiSelect() == true) {
+ selection = getRoot().selectAll(selection);
+ setSelectionVector(selection);
+ }
+}
+/**
+ * Set the item that is currently being expanded to 'item'.
+ * Used for performance optimizations.
+ */
+void setExpandingItem(TreeItem item) {
+ expandingItem = item;
+}
+/**
+ * The font is changing. Reset and recalculate the item
+ * height using all items of the receiver.
+ */
+public void setFont(Font font) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Stack children = new Stack(); // traverse the tree depth first
+ Enumeration elements;
+ AbstractTreeItem item;
+
+ if (font != null && font.equals(getFont()) == true) {
+ return;
+ }
+ setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
+ resetItemData();
+ super.setFont(font);
+
+ // Call itemChanged for all tree items
+ elements = getRoot().getChildren().elements();
+ while (elements.hasMoreElements() == true) {
+ children.push(elements.nextElement());
+ }
+ while (children.empty() == false) {
+ item = (AbstractTreeItem) children.pop();
+ itemChanged(item, 0, getClientArea().width);
+ elements = item.getChildren().elements();
+ while (elements.hasMoreElements() == true) {
+ children.push(elements.nextElement());
+ }
+ }
+ setRedraw(true); // re-enable redraw
+}
+/**
+ * Display a mark indicating the point at which an item will be inserted.
+ * The drop insert item has a visual hint to show where a dragged item
+ * will be inserted when dropped on the tree.
+ * <p>
+ * @param item the insert item. Null will clear the insertion mark.
+ * @param after true places the insert mark above 'item'. false places
+ * the insert mark below 'item'.
+ */
+public void setInsertMark(TreeItem item, boolean before){
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ motif_setInsertMark(item, !before);
+}
+/**
+ * Select the items stored in 'selectionItems'.
+ * A SWT.Selection event is not going to be sent.
+ * @param selectionItems - Array containing the items that should
+ * be selected
+ */
+public void setSelection(TreeItem selectionItems[]) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (selectionItems == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setSelectableSelection(selectionItems);
+}
+/**
+ * Set the index of the first visible item in the tree client area
+ * to 'index'.
+ * Scroll the new top item to the top of the tree.
+ * @param index - 0-based index of the first visible item in the
+ * tree's client area.
+ * @param adjustScrollbar -
+ * true = the vertical scroll bar is set to reflect the new top index.
+ * false = the vertical scroll bar position is not modified.
+ */
+void setTopIndex(int index, boolean adjustScrollbar) {
+ int indexDiff = index-getTopIndex();
+
+ super.setTopIndex(index, adjustScrollbar);
+ calculateWidestScrolledItem(indexDiff);
+}
+/**
+ * Make 'item' visible by expanding its parent items and scrolling
+ * it into the receiver's client area if necessary.
+ * An SWT.Expand event is going to be sent for every parent item
+ * that is expanded to make 'item' visible.
+ * @param item - the item that should be made visible to the
+ * user.
+ */
+public void showItem(TreeItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (item == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ showSelectableItem(item);
+}
+/**
+ * Make 'item' visible by expanding its parent items and scrolling
+ * it into the receiver's client area if necessary.
+ * An SWT.Expand event is going to be sent for every parent item
+ * that is expanded to make 'item' visible.
+ * @param item - the item that should be made visible to the
+ * user.
+ */
+void showSelectableItem(SelectableItem item) {
+ if (item.getSelectableParent() != this) {
+ return;
+ }
+ if (((TreeItem) item).isVisible() == false) {
+ ((TreeItem) item).makeVisible();
+ }
+ super.showSelectableItem(item);
+}
+/**
+ * Return the item at the specified location in the widget.
+ * Return null if there is no item at the specified location
+ * or if the location is outside the widget client area.
+ */
+public TreeItem getItem(Point point) {
+ int itemHeight;
+ int hitItemIndex;
+ TreeItem hitItem;
+
+ if (getClientArea().contains(point) == false) {
+ return null;
+ }
+ itemHeight = getItemHeight();
+ hitItemIndex = point.y / itemHeight;
+ hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ if (hitItem != null) {
+ point.x -= hitItem.getPaintStartX();
+ point.y -= itemHeight * hitItemIndex;
+ if (hitItem.isSelectionHit(point) == false) {
+ hitItem = null;
+ }
+ }
+ return hitItem;
+}
+/**
+ * Answer the number of selected items in the receiver.
+ */
+public int getSelectionCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getSelectionCount();
+}
+/**
+ * Show the selection. If there is no selection or the
+ * selection is already visible, this method does nothing.
+ * If the selection is not visible, the top index of the
+ * widget is changed such that the selection becomes visible.
+ */
+public void showSelection() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.showSelection();
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeItem.java
new file mode 100755
index 0000000000..cb0aba6a89
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeItem.java
@@ -0,0 +1,1146 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class represents leaf, non-leaf and root tree items.
+ * leaf items don't have any children. non-leaf items have one
+ * or more children.
+ * Root items don't have a parent item. Root items are either
+ * leaf or non-leaf items.
+ *
+ * This class caches geometrical data for drawing..
+ * A description of the cached data follows:
+ *
+ * | 1 || 5 |
+ * | 2 | | 6 |
+ * |3 7|
+ * _____ | 4 |f| |8
+ * | | ____
+ * | - | ===== {image} root 9
+ * |_____| |
+ * |b|c| |d|
+ * | e |
+ *
+ * Widths are measured between vertical lines.
+ *
+ * Cached item rendering data:
+ * 1 = getDecorationsWidth
+ * 2 = getHierarchyIndicatorRect
+ * 3 = getPaintStartX
+ * 4 = getItemConnectorWidth
+ * 5 = getItemWidth
+ * 6 = getSelectionWidth
+ * 7 = getPaintStopX
+ * 8 - getTextXPos
+ * 9 = getTextYPosition
+ *
+ * Rendering constants:
+ * 4 = DEFAULT_ITEM_CONNECTOR_WIDTH, used when no image is set in the tree.
+ * Otherwise it is the image width.
+ * b = IMAGE_PADDING
+ * c = TEXT_INDENT
+ * d = SELECTION_PADDING
+ * e = ITEM_NOIMAGE_OFFSET
+ * f = ITEM_CONNECTOR_PADDING;
+
+ */
+public /*final*/ class TreeItem extends AbstractTreeItem {
+ private static final int DEFAULT_ITEM_CONNECTOR_WIDTH = 8; // Default width of the horizontal line connecting
+ // items with the vertical lines. Only used when
+ // no image is set in the tree. Normally connector
+ // line width is half the image width.
+ private static final int ITEM_CONNECTOR_PADDING = 2; // Added to the calculated item connector width
+ private static final int IMAGE_PADDING = 3; // Space behind bitmap
+ private static final int ITEM_NOIMAGE_OFFSET = 8; // Offset added to the calculated paint position where
+ // an item starts drawing. To be used when no item
+ // image has been set. Otherwise children would start
+ // drawing at the end of the horizontal item connector
+ // of their parent.
+ private static final int ROOT_INDENT = 5; // Indent of root items
+ private static final int SELECTION_PADDING = 2; // Space behind text
+ private static final int TEXT_INDENT = 2; // Identation of the item label
+
+ // basic item info
+ private TreeItem parentItem;
+ private int index; // index in the parent item
+
+ // geometrical item info
+ private int paintStartX = -1; // X coordinate of the upper-left corner of the
+ // receivers bounding rectangle
+ private Point itemExtent; // Size of the item (image + label)
+ private Point imageExtent; // original size of the item image
+ private int textYPosition = -1; // Centered y position of the item text
+/**
+ * Create a root item and add it to the tree widget identified
+ * by 'parent'.
+ * @param parent - Tree widget the receiver is added to
+ * @param swtStyle - widget style. see Widget class for details
+ */
+public TreeItem(Tree parent, int swtStyle) {
+ this(parent, swtStyle, checkNull(parent).getItemCount());
+}
+/**
+ * Create a root item and add it to the tree widget identified
+ * by 'parent'.
+ * @param parent - Tree widget the receiver is added to.
+ * @param swtStyle - widget style. see Widget class for details
+ * @param position - position in 'parentItem' the receiver will
+ * be inserted at
+ */
+public TreeItem(Tree parent, int swtStyle, int position) {
+ super(parent, swtStyle);
+ parent.addItem(this, position);
+}
+/**
+ * Create a root item with 'parentItem' as the parent item.
+ * @param parentItem - the parent item of the receiver
+ * @param swtStyle - widget style. see Widget class for details
+ */
+public TreeItem(TreeItem parentItem, int swtStyle) {
+ this(parentItem, swtStyle, checkNull(parentItem).getItemCount());
+}
+/**
+ * Create a root item with 'parentItem' as the parent item.
+ * @param parentItem - the parent item of the receiver
+ * @param swtStyle - widget style. see Widget class for details
+ * @param position - position in 'parentItem' the receiver will
+ * be inserted at
+ */
+public TreeItem(TreeItem parentItem, int swtStyle, int position) {
+ super(checkNull(parentItem).getParent(), swtStyle);
+ setParentItem(parentItem);
+ parentItem.add(this, position);
+}
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+void calculateVisibleItemCount() {
+ Vector children;
+ TreeItem child;
+ int visibleItemCount = 0;
+
+ // check isExpanded field directly for performance
+ if (internalGetExpanded() == true) {
+ children = getChildren();
+ visibleItemCount = children.size();
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ visibleItemCount += child.getVisibleItemCount();
+ }
+ }
+ setVisibleItemCount(visibleItemCount);
+ calculateVisibleItemCountParent();
+}
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+void calculateVisibleItemCountParent() {
+ TreeItem parentItem = getParentItem();
+
+ if (parentItem != null) {
+ parentItem.calculateVisibleItemCount();
+ }
+ else {
+ getParent().getRoot().calculateVisibleItemCount();
+ }
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'tree' is null.
+ * Otherwise return 'tree'
+ */
+static Tree checkNull(Tree tree) {
+ if (tree == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return tree;
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'item' is null.
+ * Otherwise return 'item'
+ */
+static TreeItem checkNull(TreeItem item) {
+ if (item == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return item;
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+ * Notify the parent that the receiver is being removed.
+ * Reset cached data.
+ */
+void doDispose() {
+ TreeItem parentItem = getParentItem();
+
+ if (parentItem != null) {
+ parentItem.removeItem(this);
+ }
+ else {
+ getParent().removeItem(this);
+ }
+ setParentItem(null);
+ setImageExtent(null);
+ setItemExtent(null);
+ setIndex(-1);
+ setPaintStartX(-1);
+ setTextYPosition(-1);
+}
+/**
+ * Draw the hierarchy indicator at 'position'.
+ *
+ * Note:
+ * Assumes that the hierarchy indicators for the expanded and
+ * collapsed state are the same size.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawHierarchyIndicator(GC gc, Point position) {
+ Tree parent = getParent();
+ Image hierarchyImage;
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int x = position.x;
+ int y = position.y;
+ int yCenter = y + parent.getItemHeight() / 2;
+ Point connectorLinePosition;
+
+ if (isLeaf() == false) {
+ if (getExpanded() == true) {
+ hierarchyImage = parent.getExpandedImage();
+ }
+ else {
+ hierarchyImage = parent.getCollapsedImage();
+ }
+ if (hierarchyImage != null) {
+ gc.drawImage(hierarchyImage, x + indicatorRectangle.x, y + indicatorRectangle.y);
+ }
+ connectorLinePosition = new Point(x + indicatorRectangle.width, yCenter);
+ }
+ else {
+ connectorLinePosition = new Point(
+ x + indicatorRectangle.width / 2
+ + indicatorRectangle.width % 2, yCenter); // % 2 in order to not start the next hierarchy
+ // component at the middle of the icon but after.
+ }
+ return connectorLinePosition;
+}
+/**
+ * Draw a horizontal line connecting the item image (or label
+ * if there is no image) to the vertical line connecting to
+ * the parent.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawHorizontalItemConnector(GC gc, Point position) {
+ int itemConnectorEndPos = position.x + getItemConnectorWidth() - 1; // -1 because the position of the last pixel needs to be calculated
+
+ gc.drawLine(position.x, position.y, itemConnectorEndPos, position.y);
+ return new Point(itemConnectorEndPos + 1, position.y); // + 1 in order to resume drawing after line not on end of line
+}
+/**
+ * Display the item image at 'position' using 'gc'.
+ * @param gc - GC to draw on
+ * @param position - position on the GC to draw at
+ * @return position to continue drawing
+ */
+Point drawImage(GC gc, Point destinationPosition) {
+ Tree parent = getParent();
+ Image image = getImage();
+ Point sourceImageExtent;
+ Point destinationImageExtent = parent.getImageExtent();
+ int yCenter;
+
+ if (image != null) {
+ sourceImageExtent = getImageExtent();
+ yCenter = (parent.getItemHeight() - destinationImageExtent.y) / 2;
+ gc.drawImage(
+ image,
+ 0, 0, // source x, y
+ sourceImageExtent.x, sourceImageExtent.y, // source width, height
+ destinationPosition.x, destinationPosition.y + yCenter, // destination x, y
+ destinationImageExtent.x, destinationImageExtent.y); // destination width, height
+ }
+ if (destinationImageExtent != null) {
+ destinationPosition.x += destinationImageExtent.x + IMAGE_PADDING;
+ }
+ return destinationPosition;
+}
+/**
+ * Draw a filled rectangle indicating the item selection state
+ * The rectangle will be filled with the selection color if the
+ * receiver is selected. Otherwise the rectangle will be filled
+ * in the background color to remove the selection.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ */
+void drawSelection(GC gc, Point position) {
+ Tree parent = getParent();
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent == null) {
+ return;
+ }
+ if (isSelected() == true) {
+ gc.setBackground(getSelectionBackgroundColor());
+ }
+ gc.fillRectangle(position.x, position.y, selectionExtent.x, selectionExtent.y);
+ if (isSelected() == true) {
+ gc.setBackground(parent.getBackground());
+ }
+}
+/**
+ * Draw a rectangle enclosing the item label. The rectangle
+ * indicates that the receiver was selected last and that it has
+ * the input focus.
+ * The rectangle will only be drawn if the receiver is selected.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ */
+void drawSelectionFocus(GC gc, Point position) {
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent == null) {
+ return;
+ }
+ if (getParent().hasFocus(this) == true) {
+ gc.drawFocus(
+ position.x, position.y,
+ selectionExtent.x, selectionExtent.y);
+ }
+}
+/**
+ * Draw the item label at 'position' using 'gc'.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ */
+void drawText(GC gc, Point position) {
+ Tree parent = getParent();
+ String text = getText();
+
+ if (text != null) {
+ if (isSelected() == true) {
+ gc.setBackground(getSelectionBackgroundColor());
+ gc.setForeground(getSelectionForegroundColor());
+ }
+ gc.drawString(text, position.x, position.y);
+ if (isSelected() == true) {
+ gc.setBackground(parent.getBackground());
+ gc.setForeground(parent.getForeground());
+ }
+ }
+}
+/**
+ * Draw a vertical line connecting the horizontal connector line
+ * with that of the previous item.
+ * Called recursively to draw the lines on all tree levels.
+ * @param gc - GC to draw on.
+ * @param yPosition - y position of the upper side of the
+ * receiver's bounding box.
+ * @param isFirstChild - method is called to draw a vertical
+ * line for the first child. Leave room for the hierarchy icon.
+ */
+void drawVerticalItemConnector(GC gc, int yPosition, boolean isFirstChild) {
+ Tree parent = getParent();
+ TreeItem nextDrawItem = getParentItem();
+ AbstractTreeItem parentItem = nextDrawItem;
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int itemHeight = parent.getItemHeight();
+ int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
+ int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
+ int lineX = getPaintStartX() + indicatorRectangle.width / 2;
+ int lineStartY = yPosition - itemHeightDiv2;
+ int lineEndY = yPosition + itemHeightDiv2;
+
+ if (parentItem == null) {
+ parentItem = parent.getRoot();
+ }
+ if (getIndex() != parentItem.getItemCount()-1) { // if item is not the last child
+ if (isFirstChild == true) {
+ lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
+ }
+ gc.drawLine(lineX, lineStartY, lineX, lineEndY);
+ }
+
+ if (nextDrawItem != null) {
+ nextDrawItem.drawVerticalItemConnector(gc, yPosition, false);
+ }
+}
+/**
+ * Draw a vertical line connecting the horizontal connector line
+ * with that of the previous item.
+ * Do this on all tree levels up to the root level.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawVerticalItemConnector(GC gc, Point position) {
+ Tree parent = getParent();
+ TreeItem parentItem = getParentItem();
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int itemHeight = parent.getItemHeight();
+ int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
+ int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
+ int lineX = position.x + indicatorRectangle.width / 2;
+ int lineStartY = position.y - itemHeightDiv2;
+ int lineEndY = position.y + itemHeightDiv2 - itemHeight % 2;
+ TreeItem predecessor;
+ boolean isFirstChild = false;
+
+ if (isRoot() == true) {
+ if (getIndex() == 0) {
+ return position; // first root, don't draw vertical line
+ }
+ }
+ else
+ if (getIndex() == 0) { // if item is first child
+ lineStartY += itemHeightDiv2;
+ isFirstChild = true;
+ }
+ predecessor = getPredecessor();
+ if (predecessor != null && predecessor.isLeaf() == false) {
+ lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
+ }
+ if (isLeaf() == false) {
+ lineEndY -= indicatorHeightDiv2;
+ }
+ gc.drawLine(lineX, lineStartY, lineX, lineEndY);
+ if (parentItem != null) {
+ parentItem.drawVerticalItemConnector(gc, position.y, isFirstChild);
+ }
+ return position;
+}
+
+/**
+ * Gets the widget bounds.
+ * The widget bounds is the rectangle around the item text. It is
+ * the same as the selection rectangle.
+ * <p>
+ * @return a rectangle that is the widget bounds.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public Rectangle getBounds() {
+ if (!isValidThread()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget()) error(SWT.ERROR_WIDGET_DISPOSED);
+ Tree parent = getParent();
+ Point extent = getItemExtent();
+ int x = getTextXPos() - TEXT_INDENT;
+
+ return new Rectangle(x, parent.getRedrawY(this), extent.x - (x - getItemStartX()), extent.y);
+}
+
+/**
+ * Answer the x position of the item check box
+ */
+int getCheckboxXPosition() {
+ return getPaintStartX() + getDecorationsWidth();
+}
+/**
+ * Answer the combined width of the hierarchy indicator and
+ * the horizontal item connector line.
+ */
+int getDecorationsWidth() {
+ int indicatorWidth = getParent().getHierarchyIndicatorRect().width;
+ int width = indicatorWidth + getItemConnectorWidth();
+
+ if (isLeaf() == true) {
+ width -= indicatorWidth / 2;
+ }
+ return width;
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * @return
+ * The index of the receiver relative to the first root item.
+ */
+int getGlobalIndex() {
+ int globalItemIndex = getIndex();
+ AbstractTreeItem item = null;
+
+ if (isRoot() == false) {
+ item = getParentItem();
+ globalItemIndex++; // adjust for 0-based non-root items
+ }
+ else {
+ item = getParent().getRoot();
+ }
+
+ globalItemIndex += item.getVisibleIndex(getIndex());
+ return globalItemIndex;
+}
+/**
+ * Answer the original size of the image of the receiver.
+ */
+Point getImageExtent() {
+ Image image = getImage();
+ Rectangle imageBounds;
+
+ if (imageExtent == null && image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the receiver's index into its parent's list of children
+ */
+int getIndex() {
+ return index;
+}
+/**
+ * Answer the width of the horizontal item connector line.
+ */
+int getItemConnectorWidth() {
+ Tree parent = getParent();
+ Point imageExtent = parent.getImageExtent();
+ int itemConnectorWidth;
+ int indicatorWidth = parent.getHierarchyIndicatorRect().width;
+
+ if (imageExtent != null) {
+ itemConnectorWidth = imageExtent.x / 2 + ITEM_CONNECTOR_PADDING;
+ }
+ else {
+ itemConnectorWidth = DEFAULT_ITEM_CONNECTOR_WIDTH;
+ }
+ if (isLeaf() == false) { // has children = has hierarchy indicator = shorter connector
+ itemConnectorWidth -= indicatorWidth / 2;
+ }
+ return itemConnectorWidth;
+}
+/**
+ * Return the number of children.
+ */
+public int getItemCount() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getItemCount();
+}
+/**
+ * Answer the size of the receiver as displayed on the screen.
+ */
+Point getItemExtent() {
+ Tree parent;
+ Point imageExtent;
+ String text;
+ int itemWidth;
+
+ if (itemExtent == null) {
+ parent = getParent();
+ imageExtent = parent.getImageExtent();
+ text = getText();
+ itemWidth = SELECTION_PADDING;
+ if (text != null) {
+ itemWidth += parent.getTextWidth(text) + TEXT_INDENT;
+ }
+ if (imageExtent != null) {
+ itemWidth += imageExtent.x + IMAGE_PADDING;
+ }
+ itemExtent = new Point(itemWidth, parent.getItemHeight());
+ }
+ return itemExtent;
+}
+/**
+ * Answer the x position at which painting of the receiver's
+ * contents (ie. image, text) can begin.
+ */
+int getItemStartX() {
+ int itemStartX = getPaintStartX() + getDecorationsWidth();
+
+ if (isCheckable() == true) {
+ itemStartX += getCheckboxBounds().width + CHECKBOX_PADDING;
+ }
+ return itemStartX;
+}
+/**
+ * Answer the child items of the receiver as an Array.
+ */
+public TreeItem [] getItems() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ TreeItem childrenArray[] = new TreeItem[getItemCount()];
+
+ getChildren().copyInto(childrenArray);
+ return childrenArray;
+}
+/**
+ * Answer the x position where the receiver is drawn.
+ */
+int getPaintStartX() {
+ Tree parent = getParent();
+ Point imageExtent;
+ TreeItem parentItem;
+
+ if (paintStartX == -1) {
+ if (isRoot() == true) {
+ paintStartX = ROOT_INDENT;
+ }
+ else {
+ parentItem = getParentItem();
+ // subtract parent.getHorizontalOffset() to calculate the cached start
+ // position independent of the horizontal scroll offset. Fixes 1G1L7EU.
+ paintStartX = parentItem.getPaintStartX()
+ - parent.getHorizontalOffset()
+ + parentItem.getDecorationsWidth()
+ - parent.getHierarchyIndicatorRect().width / 2;
+ imageExtent = parent.getImageExtent();
+ if (imageExtent != null) {
+ paintStartX += imageExtent.x / 2;
+ }
+ else {
+ paintStartX += ITEM_NOIMAGE_OFFSET;
+ }
+ }
+ }
+ return paintStartX + parent.getHorizontalOffset();
+}
+/**
+ * Answer the pixel at which the receiver stops drawing.
+ */
+int getPaintStopX() {
+ return (getItemStartX() + getItemExtent().x - getParent().getHorizontalOffset());
+}
+/**
+ * Answer the parent widget of the receiver.
+ */
+public Tree getParent() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return (Tree) super.getSelectableParent();
+}
+/**
+ * Answer the parent item of the receiver or null if the
+ * receiver is a root.
+ */
+public TreeItem getParentItem() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return parentItem;
+}
+/**
+ * Answer the item that directly precedes the receiver.
+ * Answer null if this is the first item in a hierarchy level
+ * or if there are expanded children in the previous item.
+ */
+TreeItem getPredecessor() {
+ AbstractTreeItem parentItem = getParentItem();
+ Vector children;
+ int previousIndex = getIndex() - 1;
+ TreeItem previousItem = null;
+
+ if (parentItem == null) {
+ parentItem = getParent().getRoot();
+ }
+ if (previousIndex >= 0) {
+ children = parentItem.getChildren();
+ previousItem = (TreeItem) children.elementAt(previousIndex);
+ if (previousItem.isLeaf() == false && previousItem.getExpanded() == true) {
+ previousItem = null; // no immediate predecessor because there are expanded children
+ }
+ }
+ return previousItem;
+}
+/**
+ * Answer the size of the rectangle drawn to indicate the
+ * selected state of the receiver.
+ * This is also used to draw the selection focus rectangle.
+ */
+Point getSelectionExtent() {
+ Point selectionExtent = getItemExtent();
+ Point imageExtent = getParent().getImageExtent();
+ int x = selectionExtent.x;
+
+ if (imageExtent != null) {
+ x -= imageExtent.x + IMAGE_PADDING;
+ }
+ return new Point(x, selectionExtent.y);
+}
+/**
+ * Return the x position of the selection rectangle
+ */
+int getSelectionX() {
+ return getTextXPos() - TEXT_INDENT;
+}
+/**
+ * Answer the x position where the receiver draws the item text.
+ * This position is relative to the item start position.
+ */
+int getTextXPos() {
+ Point imageExtent = getParent().getImageExtent();
+ int textXPos = getItemStartX() + TEXT_INDENT;
+
+ if (imageExtent != null) {
+ textXPos += imageExtent.x + IMAGE_PADDING;
+ }
+ return textXPos;
+}
+/**
+ * Answer the y position of the receiver's text.
+ * @param
+ * gc - GC to use for calculating the text y position
+ */
+int getTextYPosition(GC gc) {
+ String text;
+
+ if (textYPosition == -1) {
+ text = getText();
+ if (text != null) {
+ textYPosition = (getParent().getItemHeight() - gc.stringExtent(text).y) / 2;
+ }
+ else {
+ textYPosition = 0;
+ }
+ }
+ return textYPosition;
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * If 'anIndex' is the index of the expanded item 'anItem'
+ * then the following expressions are true:
+ * 'anItem == theRoot.getVisibleItem(anIndex)' and
+ * 'anIndex == anItem.getVisibleIndex()'
+ * @return
+ * The index of the receiver relative to the first root item.
+ * Answer -1 if the receiver is not visible (because the parent
+ * is collapsed).
+ */
+int getVisibleIndex() {
+ int visibleItemIndex = getIndex();
+ AbstractTreeItem item = null;
+
+ if (isRoot() == false) {
+ if (isVisible() == false) {
+ return -1;
+ }
+ item = getParentItem();
+ visibleItemIndex++; // adjust for 0-based non-root items
+ }
+ else {
+ item = getParent().getRoot();
+ }
+
+ visibleItemIndex += item.getVisibleIndex(getIndex());
+ return visibleItemIndex;
+}
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+int getVisibleIndex(int childIndex) {
+ Enumeration children = getChildren().elements();
+ TreeItem child;
+ int visibleItemIndex = getIndex();
+
+ if (isRoot() == false) {
+ visibleItemIndex++; // adjust for 0-based non-root items
+ }
+
+ while (children.hasMoreElements() == true) {
+ child = (TreeItem) children.nextElement();
+ if (child.getIndex() == childIndex) {
+ if (isRoot() == false) {
+ visibleItemIndex += getParentItem().getVisibleIndex(getIndex());
+ }
+ else {
+ visibleItemIndex += getParent().getRoot().getVisibleIndex(getIndex());
+ }
+ break;
+ }
+ visibleItemIndex += child.getVisibleItemCount();
+ }
+ return visibleItemIndex;
+}
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the widget client area.
+ */
+TreeItem getVisibleItem(int searchIndex) {
+ TreeItem child;
+ TreeItem foundItem = null;
+ Enumeration children = getChildren().elements();
+
+ if (searchIndex == 0) {
+ return this;
+ }
+ else
+ if (getExpanded() == false) { // trying to find a child when this item isn't expanded ?
+ return null;
+ }
+
+ // Search for expanded items first. Count all subitems in the process.
+ while (children.hasMoreElements() == true && foundItem == null) {
+ child = (TreeItem) children.nextElement();
+ searchIndex--;
+ if (child.getExpanded() == true) {
+ searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
+ }
+ if (searchIndex <= 0) { // is searched item past child ?
+ // add back children of current item (that's what we want to search)
+ foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
+ }
+ }
+
+ return foundItem;
+}
+/**
+ * Answer whether 'item' is a child, direct or indirect, of the receiver.
+ * It is an indirect child if it is a child of one of the receiver's children.
+ */
+boolean isChild(TreeItem item) {
+ Vector children = getChildren();
+ TreeItem child;
+
+ if (children.contains(item) == true) {
+ return true;
+ }
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ if (child.isChild(item) == true) {
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * Answer whether the receiver is a root item.
+ * The receiver is a root item when it does not have a parent item.
+ * @return
+ * true - the receiver is a root item.
+ * false - the receiver is not a root item.
+ */
+boolean isRoot() {
+ return (getParentItem() == null);
+}
+/**
+ * Answer whether the click at 'position' on the receiver is a selection
+ * click.
+ * @param position - location of the mouse click relative to the
+ * upper left corner of the receiver.
+ * @return true - receiver was clicked.
+ * false - receiver was not clicked.
+ */
+boolean isSelectionHit(Point position) {
+ Point itemExtent = getItemExtent();
+
+ if (itemExtent == null) { // neither image nor text have been set
+ return false;
+ }
+ return (new Rectangle(
+ getItemStartX() - getPaintStartX(), 0,
+ itemExtent.x, itemExtent.y)).contains(position);
+}
+/**
+ * Answer whether the receiver is visible
+ * An item is visible when its parent item is visible and
+ * expanded. Root items are always visible.
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the receiver's parent's
+ * client area.
+ * @return
+ * true - the receiver is visible
+ * false - the receiver is not visible
+ */
+boolean isVisible() {
+ boolean isVisible = true;
+ TreeItem parentItem = getParentItem();
+
+ if (isRoot() == false) {
+ isVisible = parentItem.getExpanded();
+ if (isVisible == true) {
+ isVisible = parentItem.isVisible();
+ }
+ }
+ return isVisible;
+}
+/**
+ * Make this item visible by expanding its parent item.
+ */
+void makeVisible() {
+ TreeItem parentItem = getParentItem();
+
+ if (isVisible() == false && parentItem != null) {
+ getParent().expand(parentItem, true); // have to call Tree.expand directly in order to trigger Expand event
+ parentItem.makeVisible();
+ }
+}
+/**
+ * Draw the receiver at 'yPosition' in the client area of the parent.
+ * @param gc - GC to draw on.
+ * @param yPosition - y coordinate where the receiver should draw at.
+ */
+void paint(GC gc, int yPosition) {
+ Tree parent = getParent();
+ Point paintPosition = new Point(getPaintStartX(), yPosition);
+
+ if (isVisible() == false) {
+ return;
+ }
+ gc.setForeground(parent.CONNECTOR_LINE_COLOR);
+ paintPosition = drawVerticalItemConnector(gc, paintPosition);
+ paintPosition = drawHierarchyIndicator(gc, paintPosition);
+ paintPosition = drawHorizontalItemConnector(gc, paintPosition);
+ gc.setForeground(parent.getForeground());
+ // paint the rest
+ if (isCheckable() == true) {
+ paintPosition = drawCheckbox(gc, new Point(paintPosition.x, yPosition));
+ }
+ paintPosition = drawImage(gc, new Point(paintPosition.x, yPosition));
+ drawSelection(gc, paintPosition);
+ if (this == parent.getInsertItem()) {
+ drawInsertMark(gc, paintPosition);
+ }
+ drawText(gc, new Point(getTextXPos(), paintPosition.y + getTextYPosition(gc)));
+ drawSelectionFocus(gc, paintPosition);
+}
+/**
+ * Update the display to reflect the expanded state of the
+ * receiver.
+ * @param itemIndex - index position in the receiver's client
+ * area where should be drawn.
+ */
+void redrawExpanded(int itemIndex) {
+ Tree parent = getParent();
+ int indicatorWidth = parent.getHierarchyIndicatorRect().width;
+ int itemHeight = parent.getItemHeight();
+
+ parent.redraw(
+ getPaintStartX(), itemIndex * itemHeight,
+ indicatorWidth, itemHeight, false);
+}
+/**
+ * Reset cached size and position data.
+ */
+void reset() {
+ super.reset();
+ setImageExtent(null);
+ setItemExtent(null);
+ setPaintStartX(-1);
+ setTextYPosition(-1);
+}
+/**
+ * Set whether the receiver is expanded or not.
+ * If the receiver is expanded its child items are visible.
+ * @param expand -
+ * true=the receiver will be expanded, making its child items
+ * visible.
+ * false=the receiver will be collapsed, making its child items
+ * invisible
+ */
+public void setExpanded(boolean expand) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ if (isLeaf() == false && expand == true) {
+ getParent().expand(this, false);
+ }
+ else {
+ getParent().collapse(this, false);
+ }
+}
+/**
+ * Set the image of the receiver to 'newImage'.
+ * Reset cached data and notify the parent if the image has changed.
+ */
+public void setImage(Image newImage) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Tree parent = getParent();
+ Image oldImage = getImage();
+ boolean isSameImage;
+ int imageWidth = 0;
+ int redrawX = 0;
+
+ super.setImage(newImage);
+ if (newImage != null && oldImage != null) {
+ isSameImage = newImage.equals(oldImage);
+ }
+ else {
+ isSameImage = newImage == oldImage;
+ }
+ if (isSameImage == false) {
+ if (parent.getVisibleRedrawY(this) != -1) {
+ if (parent.getImageExtent() != null) {
+ imageWidth = parent.getImageExtent().x;
+ }
+ else
+ if (newImage != null) {
+ imageWidth = newImage.getBounds().x;
+ }
+ redrawX = getItemStartX();
+ }
+ parent.itemChanged(this, redrawX, imageWidth);
+ }
+}
+/**
+ * Set the size of the original image of the receiver to 'imageExtent'.
+ */
+void setImageExtent(Point imageExtent) {
+ this.imageExtent = imageExtent;
+}
+/**
+ * Set the index of the receiver to 'index'.
+ * This index is used to reference children in their parent.
+ */
+void setIndex(int index) {
+ this.index = index;
+}
+/**
+ * Set the size of the receiver to 'extent'.
+ */
+void setItemExtent(Point extent) {
+ itemExtent = extent;
+}
+/**
+ * Set the x position where the receiver is drawn to 'startX'.
+ * @param startX - the x position where the receiver is drawn
+ */
+void setPaintStartX(int startX) {
+ paintStartX = startX;
+}
+/**
+ * Set the parent item of the receiver to 'parentItem'.
+ * @param parentItem - the receiver's parent item.
+ * Receiver is a root if this is null.
+ */
+void setParentItem(TreeItem parentItem) {
+ this.parentItem = parentItem;
+}
+/**
+ * Set the label text of the receiver to 'string'.
+ * Reset cached data and notify the parent if the text has
+ * changed.
+ * This label will be displayed to the right of the bitmap,
+ * or, if the receiver doesn't have a bitmap to the right of
+ * the horizontal hierarchy connector line.
+ */
+public void setText(String newText) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Tree parent = getParent();
+ String oldText = getText();
+ int redrawX = 0;
+ int redrawWidth = 0;
+
+ if (newText == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ super.setText(newText);
+ if (newText.equals(oldText) == false) {
+ if (parent.getVisibleRedrawY(this) != -1) {
+ redrawX = getTextXPos();
+ redrawWidth = parent.getClientArea().width - redrawX;
+ }
+ parent.itemChanged(this, redrawX, redrawWidth);
+ }
+}
+/**
+ * Set the y position of the receiver's text to 'yPosition'.
+ */
+void setTextYPosition(int yPosition) {
+ textYPosition = yPosition;
+}
+/**
+ * Destroy all children of the receiver
+ * Collapsing the item speeds up deleting the children.
+ */
+void disposeItem() {
+ Tree parent = getParent();
+
+ // if the tree is being disposed don't bother collapsing the item since all
+ // items in the tree will be deleted and redraws will not be processed anyway
+ if (parent.isRemovingAll() == false) {
+ parent.collapseNoRedraw(this);
+ }
+ super.disposeItem();
+}
+/**
+ * Return whether or not the receiver is checked.
+ * Always return false if the parent of the receiver does not
+ * have the CHECK style.
+ */
+public boolean getChecked() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getChecked();
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ return super.getDisplay();
+}
+/**
+ * Gets the grayed state.
+ * <p>
+ * @return the item grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean getGrayed() {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ return super.getGrayed();
+}
+/**
+ * Set the checked state to 'checked' if the parent of the
+ * receiver has the CHECK style.
+ */
+public void setChecked(boolean checked) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setChecked(checked);
+}
+/**
+ * Sets the grayed state.
+ * <p>
+ * @param grayed the new grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public void setGrayed (boolean grayed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+
+ super.setGrayed(grayed);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeRoots.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeRoots.java
new file mode 100755
index 0000000000..c9e4dea7ab
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/TreeRoots.java
@@ -0,0 +1,157 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+/**
+ * This class is used to store tree root items.
+ * Instances of this class are never displayed.
+ */
+class TreeRoots extends AbstractTreeItem {
+/**
+ * Create a tree item that holds one or more root items
+ * @param parent - Tree widget the receiver belongs to
+ */
+TreeRoots(Tree parent) {
+ super(parent, 0);
+ initialize();
+}
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+void calculateVisibleItemCount() {
+ Vector children = getChildren();
+ TreeItem child;
+ int visibleItemCount = children.size();
+
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ visibleItemCount += child.getVisibleItemCount();
+ }
+ setVisibleItemCount(visibleItemCount);
+}
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+void calculateVisibleItemCountParent() {}
+/**
+ * Destroy all children of the receiver
+ */
+void disposeItem() {
+ Tree parent = (Tree) getSelectableParent();
+
+ // all tree items are removed so we don't need to do
+ // time consuming screen updates for each removed item
+ parent.setRemovingAll(true);
+ super.disposeItem();
+ parent.setRemovingAll(false);
+}
+/**
+ * Answer the x position of the item check box
+ */
+int getCheckboxXPosition() {
+ return 0;
+}
+/**
+ * Implements SelectableItem#getSelectionExtent
+ * Should never be called since objects of this type are never
+ * rendered
+ */
+Point getSelectionExtent() {
+ return new Point(0, 0);
+}
+/**
+ * Implements SelectableItem#getSelectionX
+ * Should never be called since objects of this type are never
+ * rendered
+ */
+int getSelectionX() {
+ return 0;
+}
+/**
+ * Always answer -1 to indicate that the receiver is not visible.
+ */
+int getVisibleIndex() {
+ return -1;
+}
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+int getVisibleIndex(int childIndex) {
+ Enumeration children = getChildren().elements();
+ TreeItem child;
+ int globalItemIndex = 0;
+
+ while (children.hasMoreElements() == true) {
+ child = (TreeItem) children.nextElement();
+ if (child.getIndex() == childIndex) {
+ break;
+ }
+ globalItemIndex += child.getVisibleItemCount();
+ }
+ return globalItemIndex;
+}
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the widget client area.
+ */
+TreeItem getVisibleItem(int searchIndex) {
+ TreeItem child;
+ TreeItem foundItem = null;
+ Enumeration children = getChildren().elements();
+
+ searchIndex++; // skip this fake root item
+
+ // Search for expanded items first. Count all subitems in the process.
+ while (children.hasMoreElements() == true && foundItem == null) {
+ child = (TreeItem) children.nextElement();
+ searchIndex--;
+ if (child.internalGetExpanded() == true) {
+ searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
+ }
+ if (searchIndex <= 0) { // is searched item past child ?
+ // add back children of current item (that's what we want to search)
+ foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
+ }
+ }
+ return foundItem;
+}
+/**
+ * Initialize the receiver
+ */
+void initialize() {
+ internalSetExpanded(true);
+}
+
+/**
+ * Select the receiver and all children
+ */
+Vector selectAll(Vector selectedItems) {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ selectedItems = treeItem.selectAll(selectedItems);
+ }
+ return selectedItems;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
new file mode 100755
index 0000000000..6aaaa08b44
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
@@ -0,0 +1,725 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* See JavaDoc for Windows.
+*/
+
+/* Imports */
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+import java.util.EventListener;
+
+/* Class Definition */
+public abstract class Widget {
+
+ public int handle;
+ int style, state;
+ EventTable eventTable;
+ Object data;
+ String [] keys;
+ Object [] values;
+
+ /* Global state flags */
+// static final int AUTOMATIC = 0x00000001;
+// static final int ACTIVE = 0x00000002;
+// static final int AUTOGRAB = 0x00000004;
+// static final int MULTIEXPOSE = 0x00000008;
+// static final int RESIZEREDRAW = 0x00000010;
+// static final int WRAP = 0x00000020;
+// static final int DISABLED = 0x00000040;
+// static final int HIDDEN = 0x00000080;
+// static final int FOREGROUND = 0x00000100;
+// static final int BACKGROUND = 0x00000200;
+ static final int DISPOSED = 0x00000400;
+ static final int HANDLE = 0x00000800;
+ static final int CANVAS = 0x00001000;
+
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+
+ /* Global widget variables */
+ static final char Mnemonic = '&';
+ static final boolean IsAIX, IsSunOS, IsLinux;
+ static {
+
+ /* Initialize the X/MOTIF flags */
+ String osName = System.getProperty ("os.name");
+ if (osName.equals("Linux")) {
+ IsLinux = true;
+ IsAIX = IsSunOS = false;
+ } else {
+ if (osName.equals("AIX")) {
+ IsAIX = true;
+ IsLinux = IsSunOS = false;
+ } else {
+ if (osName.equals("Solaris")) {
+ IsSunOS = true;
+ IsLinux = IsAIX = false;
+ } else {
+ IsLinux = IsSunOS = IsAIX = false;
+ }
+ }
+ }
+ }
+Widget () {
+ /* Do nothing */
+}
+/**
+* Creates a widget.
+* <p>
+* This method creates a child widget using style bits
+* to select a particular look or set of properties.
+*
+* @param parent a composite widget (cannot be null)
+* @param style the bitwise OR'ing of widget styles
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_ERROR_NULL_ARGUMENT)
+* when the parent is null
+*/
+public Widget (Widget parent, int style) {
+ if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ this.style = style;
+}
+/**
+* Adds a listener for an event.
+* <p>
+* This method adds a listener for an event. When the
+* event occurs in the widget, the listener is notified
+* using <code>handleEvent ()</code>.
+*
+* @param eventType the desired SWT event
+* @param handler the event handler
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when handler is null
+*/
+public void addListener (int eventType, Listener handler) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) eventTable = new EventTable ();
+ eventTable.hook (eventType, handler);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addDisposeListener (DisposeListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Dispose, typedListener);
+}
+static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
+ int mask = int0 | int1 | int2 | int3 | int4 | int5;
+ if ((style & mask) == 0) style |= int0;
+ if ((style & int0) != 0) style = (style & ~mask) | int0;
+ if ((style & int1) != 0) style = (style & ~mask) | int1;
+ if ((style & int2) != 0) style = (style & ~mask) | int2;
+ if ((style & int3) != 0) style = (style & ~mask) | int3;
+ if ((style & int4) != 0) style = (style & ~mask) | int4;
+ if ((style & int5) != 0) style = (style & ~mask) | int5;
+ return style;
+}
+void checkParent (Widget parent) {
+ if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+}
+/**
+ * Checks that this class can be subclassed.
+ * <p>
+ * IMPORTANT: By providing an implementation of this method that
+ * allows subclassing in a subclass of this class, you agree to
+ * be fully responsible for the fact that any such subclass will
+ * likely fail between releases and will be strongly platform
+ * specific. No support is provided for classes which are implemented
+ * as subclasses of this class. The use of subclassing is intended
+ * purely to enable those outside of the development team to implement
+ * a patched version of the class in an emergency. Subclassing should
+ * not be attempted without an intimate and detailed understanding of
+ * the hierarchy.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_ILLEGAL_SUBCLASS when called</li>
+ * </ul>
+ */
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+/**
+* Checks access to a widget.
+* <p>
+* Throws an exception when access to the widget
+* is denied.
+*
+* It is an error to call a method on a widget that
+* has been disposed or to call a method on a widget
+* from a thread that is different from the thread
+* that created the widget. There may be more or
+* less error checks in future or different versions
+* of SWT may issue different errors.
+*
+* This method is intended to be called by widget
+* implementors to enforce the standard SWT error
+* checking prologue in API methods.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+protected void checkWidget () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+void createHandle (int index) {
+ /* Do nothing */
+}
+void createWidget (int index) {
+ createHandle (index);
+ hookEvents ();
+ register ();
+ manageChildren ();
+}
+void deregister () {
+ if (handle == 0) return;
+ WidgetTable.remove (handle);
+}
+void destroyWidget () {
+ int topHandle = topHandle ();
+ releaseHandle ();
+ if (topHandle != 0) {
+ OS.XtDestroyWidget (topHandle);
+ }
+}
+/**
+* Disposes a widget.
+* <p>
+* This method destroys the widget and all children
+* and releases all platform resources associated with
+* the widget tree.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void dispose () {
+ /*
+ * Note: It is valid to attempt to dispose a widget
+ * more than once. If this happens, fail silently.
+ */
+ if (!isValidWidget ()) return;
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ releaseChild ();
+ releaseWidget ();
+ destroyWidget ();
+}
+void error (int code) {
+ SWT.error(code);
+}
+/**
+* Gets the widget data.
+* <p>
+* This method gets the application defined data that
+* is associated with the widget.
+*
+* @return the widget data
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Object getData () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return data;
+}
+
+/**
+ * Searches for the property with the specified name.
+ * If the property is not found, null is returned.
+ *
+ * @param key the name of the property to find
+ * @return the named property value
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * <li>ERROR_NULL_ARGUMENT when the name is null</li>
+ * </ul>
+ */
+public Object getData (String key) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (keys == null) return null;
+ for (int i=0; i<keys.length; i++) {
+ if (keys [i].equals (key)) return values [i];
+ }
+ return null;
+}
+
+/**
+* Gets the Display.
+* <p>
+* This method gets the Display that is associated
+* with the widget.
+*
+* @return the widget data
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public abstract Display getDisplay ();
+String getName () {
+ String string = getClass ().getName ();
+ int index = string.lastIndexOf ('.');
+ if (index == -1) return string;
+ return string.substring (index + 1, string.length ());
+}
+String getNameText () {
+ return "";
+}
+/**
+* Gets the widget style.
+* <p>
+* This method gets the widget style bits.
+*
+* @return an integer that is the widget style bits.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getStyle () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return style;
+}
+void hookEvents () {
+ /* Do nothing */
+}
+boolean hooks (int eventType) {
+ if (eventTable == null) return false;
+ return eventTable.hooks (eventType);
+}
+/**
+* Gets the disposed state.
+* <p>
+* This method gets the dispose state for the widget.
+* When a widget has been disposed, it is an error to
+* to invoke any other method on the widget.
+*
+* @return true when the widget is disposed
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+*/
+public boolean isDisposed () {
+ if (handle != 0) return false;
+ if ((state & HANDLE) != 0) return true;
+ return (state & DISPOSED) != 0;
+}
+/**
+ * Return the listening state.
+ * <p>
+ * Returns true if there is a listener, listening for the eventType.
+ * Otherwise, returns false.
+ *
+ * @param eventType the type of event
+ * @return true if the event is hooked
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * <li>ERROR_NULL_ARGUMENT when the name is null</li>
+ * </ul>
+ */
+protected boolean isListening (int eventType) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return hooks (eventType);
+}
+boolean isValidSubclass () {
+ return Display.isValidClass (getClass ());
+}
+boolean isValidThread () {
+ return getDisplay ().isValidThread ();
+}
+boolean isValidWidget () {
+ if (handle != 0) return true;
+ if ((state & HANDLE) != 0) return false;
+ return (state & DISPOSED) == 0;
+}
+void manageChildren () {
+ /* Do nothing */
+}
+char mbcsToWcs (char ch) {
+ int key = ch & 0xFFFF;
+ if (key <= 0x7F) return ch;
+ byte [] buffer;
+ if (key <= 0xFF) {
+ buffer = new byte [1];
+ buffer [0] = (byte) key;
+ } else {
+ buffer = new byte [2];
+ buffer [0] = (byte) ((key >> 8) & 0xFF);
+ buffer [1] = (byte) (key & 0xFF);
+ }
+ char [] result = Converter.mbcsToWcs (null, buffer);
+ if (result.length == 0) return 0;
+ return result [0];
+}
+/**
+* Notify listeners of an event.
+* <p>
+* This method notifies all listeners that an event
+* has occurred.
+*
+* @param eventType the desired SWT event
+* @param event the event data
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when handler is null
+*/
+public void notifyListeners (int eventType, Event event) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ event.type = eventType;
+ event.widget = this;
+ eventTable.sendEvent (event);
+}
+void postEvent (int eventType) {
+ if (eventTable == null) return;
+ postEvent (eventType, new Event ());
+}
+void postEvent (int eventType, Event event) {
+ if (eventTable == null) return;
+ event.type = eventType;
+ event.widget = this;
+ Display display = getDisplay ();
+ if (event.time == 0) {
+ event.time = OS.XtLastTimestampProcessed (display.xDisplay);
+ }
+ display.postEvent (event);
+}
+int processArm (int callData) {
+ return 0;
+}
+int processDispose (int callData) {
+ return 0;
+}
+int processDefaultSelection (int callData) {
+ return 0;
+}
+int processEvent (int eventNumber, int callData) {
+ switch (eventNumber) {
+ case SWT.Arm: return processArm (callData);
+ case SWT.Dispose: return processDispose (callData);
+ case SWT.DefaultSelection: return processDefaultSelection (callData);
+ case SWT.FocusIn: return processSetFocus (callData);
+ case SWT.Help: return processHelp (callData);
+ case SWT.Hide: return processHide (callData);
+ case SWT.KeyDown: return processKeyDown (callData);
+ case SWT.KeyUp: return processKeyUp (callData);
+ case SWT.Modify: return processModify (callData);
+ case SWT.MouseDown: return processMouseDown (callData);
+ case SWT.MouseEnter: return processMouseEnter (callData);
+ case SWT.MouseExit: return processMouseExit (callData);
+ case SWT.MouseHover: return processMouseHover (callData);
+ case SWT.MouseMove: return processMouseMove (callData);
+ case SWT.MouseUp: return processMouseUp (callData);
+ case SWT.Paint: return processPaint (callData);
+ case SWT.Resize: return processResize (callData);
+ case SWT.Show: return processShow (callData);
+ case SWT.Selection: return processSelection (callData);
+ case SWT.Verify: return processVerify (callData);
+ case -1: return processNonMaskable (callData);
+ }
+ return 0;
+}
+int processHelp (int callData) {
+ return 0;
+}
+int processHide (int callData) {
+ return 0;
+}
+int processKeyDown (int callData) {
+ return 0;
+}
+int processKeyUp (int callData) {
+ return 0;
+}
+int processModify (int callData) {
+ return 0;
+}
+int processMouseDown (int callData) {
+ return 0;
+}
+int processMouseEnter (int callData) {
+ return 0;
+}
+int processMouseExit (int callData) {
+ return 0;
+}
+int processMouseHover (int id) {
+ return 0;
+}
+int processMouseMove (int callData) {
+ return 0;
+}
+int processMouseUp (int callData) {
+ return 0;
+}
+int processNonMaskable (int callData) {
+ return 0;
+}
+int processPaint (int callData) {
+ return 0;
+}
+int processResize (int callData) {
+ return 0;
+}
+int processSelection (int callData) {
+ return 0;
+}
+int processSetFocus (int callData) {
+ return 0;
+}
+int processShow (int callData) {
+ return 0;
+}
+int processVerify (int callData) {
+ return 0;
+}
+void register () {
+ if (handle == 0) return;
+ WidgetTable.put (handle, this);
+}
+void releaseChild () {
+ /* Do nothing */
+}
+void releaseHandle () {
+ handle = 0;
+ state |= DISPOSED;
+}
+void releaseWidget () {
+ sendEvent (SWT.Dispose);
+ deregister ();
+ eventTable = null;
+ data = null;
+ keys = null;
+ values = null;
+}
+/**
+* Removes a listener for an event.
+* <p>
+* This method removes a listener for an event. When the
+* event occurs in the widget, the listener is no longer
+* notified.
+*
+* @param eventType the desired SWT event
+* @param handler the event handler
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when handler is null
+*/
+public void removeListener (int eventType, Listener handler) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (eventType, handler);
+}
+/**
+* Warning: API under construction.
+*/
+protected void removeListener (int eventType, EventListener handler) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (eventType, handler);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeDisposeListener (DisposeListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Dispose, listener);
+}
+void sendEvent (int eventType) {
+ if (eventTable == null) return;
+ sendEvent (eventType, new Event ());
+}
+void sendEvent (int eventType, Event event) {
+ if (eventTable == null) return;
+ event.type = eventType;
+ event.widget = this;
+ if (event.time == 0) {
+ Display display = getDisplay ();
+ event.time = OS.XtLastTimestampProcessed (display.xDisplay);
+ }
+ eventTable.sendEvent (event);
+}
+/**
+* Sets the widget data.
+* <p>
+* This method sets the application defined data that
+* is associated with the widget.
+*
+* @param the widget data
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void setData (Object data) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.data = data;
+}
+
+/**
+ * Maps the specified key to the specified value.
+ * If the key already exists, the old value is replaced.
+ * The key cannot be null.
+ *
+ * @param key the name of the property
+ * @param value the value of the property
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * <li>ERROR_NULL_ARGUMENT when the name is null</li>
+ * </ul>
+ */
+public void setData (String key, Object value) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ /* Remove the key/value pair */
+ if (value == null) {
+ if (keys == null) return;
+ int index = 0;
+ while (index < keys.length && !keys [index].equals (key)) index++;
+ if (index == keys.length) return;
+ if (keys.length == 1) {
+ keys = null;
+ values = null;
+ } else {
+ String [] newKeys = new String [keys.length - 1];
+ Object [] newValues = new Object [values.length - 1];
+ System.arraycopy (keys, 0, newKeys, 0, index);
+ System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
+ System.arraycopy (values, 0, newValues, 0, index);
+ System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
+ keys = newKeys;
+ values = newValues;
+ }
+ return;
+ }
+
+ /* Add the key/value pair */
+ if (keys == null) {
+ keys = new String [] {key};
+ values = new Object [] {value};
+ return;
+ }
+ for (int i=0; i<keys.length; i++) {
+ if (keys [i].equals (key)) {
+ values [i] = value;
+ return;
+ }
+ }
+ String [] newKeys = new String [keys.length + 1];
+ Object [] newValues = new Object [values.length + 1];
+ System.arraycopy (keys, 0, newKeys, 0, keys.length);
+ System.arraycopy (values, 0, newValues, 0, values.length);
+ newKeys [keys.length] = key;
+ newValues [values.length] = value;
+ keys = newKeys;
+ values = newValues;
+}
+
+/**
+* Returns a string representation of the object.
+*/
+public String toString () {
+ String string = "*Disposed*";
+ if (!isDisposed ()) {
+ string = "*Wrong Thread*";
+ if (isValidThread ()) string = getNameText ();
+ }
+ return getName () + " {" + string + "}";
+}
+int topHandle () {
+ return handle;
+}
+char wcsToMbcs (char ch) {
+ int key = ch & 0xFFFF;
+ if (key <= 0x7F) return ch;
+ byte [] buffer = Converter.wcsToMbcs (null, new char [] {ch}, false);
+ if (buffer.length == 1) return (char) buffer [0];
+ if (buffer.length == 2) {
+ return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF));
+ }
+ return 0;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java
new file mode 100755
index 0000000000..e0858ec93b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java
@@ -0,0 +1,121 @@
+package org.eclipse.swt.widgets;
+
+import org.eclipse.swt.internal.motif.*;
+
+/*
+ * Licensed Materials - Property of IBM,
+ * (c) Copyright IBM Corp. 1998, 2000 All Rights Reserved
+ */
+
+class WidgetTable {
+ static int FreeSlot = 0;
+ static int GrowSize = 1024;
+ static int [] IndexTable = new int [GrowSize];
+ static Shell [] Shells = new Shell [GrowSize / 8];
+ static Widget [] WidgetTable = new Widget [GrowSize];
+ static int [] ArgList = {OS.XmNuserData, 0};
+ static {
+ for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1;
+ IndexTable [GrowSize - 1] = -1;
+ }
+public static synchronized Widget get (int handle) {
+ if (handle == 0) return null;
+ if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ Widget shell = Shells [i];
+ if ((shell != null) && (shell.topHandle () == handle)) return shell;
+ }
+ return null;
+ }
+ ArgList [1] = 0;
+ OS.XtGetValues (handle, ArgList, ArgList.length / 2);
+ if (ArgList [1] == 0) return null;
+ int index = ArgList [1] - 1;
+ if (0 <= index && index < WidgetTable.length) return WidgetTable [index];
+ return null;
+}
+public synchronized static void put (int handle, Widget widget) {
+ if (handle == 0) return;
+ if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] == null) {
+ Shells [i] = (Shell) widget;
+ return;
+ }
+ }
+ Shell [] newShells = new Shell [Shells.length + GrowSize / 8];
+ System.arraycopy (Shells, 0, newShells, 0, Shells.length);
+ newShells [Shells.length] = (Shell) widget;
+ Shells = newShells;
+ return;
+ }
+ if (FreeSlot == -1) {
+ int length = (FreeSlot = IndexTable.length) + GrowSize;
+ int [] newIndexTable = new int [length];
+ Widget [] newWidgetTable = new Widget [length];
+ System.arraycopy (IndexTable, 0, newIndexTable, 0, FreeSlot);
+ System.arraycopy (WidgetTable, 0, newWidgetTable, 0, FreeSlot);
+ for (int i=FreeSlot; i<length-1; i++) {
+ newIndexTable [i] = i + 1;
+ }
+ newIndexTable [length - 1] = -1;
+ IndexTable = newIndexTable;
+ WidgetTable = newWidgetTable;
+ }
+ ArgList [1] = FreeSlot + 1;
+ OS.XtSetValues (handle, ArgList, ArgList.length / 2);
+ int oldSlot = FreeSlot;
+ FreeSlot = IndexTable [oldSlot];
+ IndexTable [oldSlot] = -2;
+ WidgetTable [oldSlot] = widget;
+}
+public static synchronized Widget remove (int handle) {
+ if (handle == 0) return null;
+ if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ Widget shell = Shells [i];
+ if ((shell != null) && (shell.topHandle () == handle)) {
+ Shells [i] = null;
+ return shell;
+ }
+ }
+ return null;
+ }
+ ArgList [1] = 0;
+ Widget widget = null;
+ OS.XtGetValues (handle, ArgList, ArgList.length / 2);
+ int index = ArgList [1] - 1;
+ if (0 <= index && index < WidgetTable.length) {
+ widget = WidgetTable [index];
+ WidgetTable [index] = null;
+ IndexTable [index] = FreeSlot;
+ FreeSlot = index;
+ ArgList [1] = 0;
+ OS.XtSetValues (handle, ArgList, ArgList.length / 2);
+ }
+ return widget;
+}
+public static synchronized Shell [] shells () {
+ int length = 0;
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] != null) length++;
+ }
+ int index = 0;
+ Shell [] result = new Shell [length];
+ for (int i=0; i<Shells.length; i++) {
+ Shell widget = Shells [i];
+ if (widget != null) result [index++] = widget;
+ }
+ return result;
+}
+public static synchronized int size () {
+ int length = 0;
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] != null) length++;
+ }
+ for (int i=0; i<WidgetTable.length; i++) {
+ if (WidgetTable [i] != null) length++;
+ }
+ return length;
+}
+}

Back to the top