diff options
10 files changed, 424 insertions, 11 deletions
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cde.CDE.properties b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cde.CDE.properties index ad9871fe63..cb0818b46f 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cde.CDE.properties +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.cde.CDE.properties @@ -52,6 +52,43 @@ CDE__DtDtsFreeDataType_0=cast=char * CDE__DtDtsFreeDataTypeNames= CDE__DtDtsFreeDataTypeNames_0=cast=char ** +CDE__XtAppCreateShell= +CDE__XtAppCreateShell_0=cast=(String) +CDE__XtAppCreateShell_1=cast=(String) +CDE__XtAppCreateShell_2=cast=(WidgetClass) +CDE__XtAppCreateShell_3=cast=(Display *) +CDE__XtAppCreateShell_4=cast=(ArgList) +CDE__XtAppCreateShell_5= + +CDE__XtCreateApplicationContext= + +CDE__XtDisplayInitialize= +CDE__XtDisplayInitialize_0=cast=(XtAppContext) +CDE__XtDisplayInitialize_1=cast=(Display *) +CDE__XtDisplayInitialize_2=cast=(String) +CDE__XtDisplayInitialize_3=cast=(String) +CDE__XtDisplayInitialize_4=cast=(XrmOptionDescRec *) +CDE__XtDisplayInitialize_5=cast=(Cardinal) +CDE__XtDisplayInitialize_6=cast=(int *) +CDE__XtDisplayInitialize_7=cast=(String *) + +CDE__XtRealizeWidget= +CDE__XtRealizeWidget_0=cast=(Widget) + +CDE__XtResizeWidget= +CDE__XtResizeWidget_0=cast=(Widget) +CDE__XtResizeWidget_1= +CDE__XtResizeWidget_2= +CDE__XtResizeWidget_3= + +CDE__XtSetMappedWhenManaged= +CDE__XtSetMappedWhenManaged_0=cast=(Widget) +CDE__XtSetMappedWhenManaged_1= + +CDE__XtToolkitInitialize= + +CDE__topLevelShellWidgetClass=flags=const + org_eclipse_swt_internal_cde_DtActionArg= DtActionArg_argClass= diff --git a/bundles/org.eclipse.swt/.classpath_gtk b/bundles/org.eclipse.swt/.classpath_gtk index 7145c982ab..b97872990d 100644 --- a/bundles/org.eclipse.swt/.classpath_gtk +++ b/bundles/org.eclipse.swt/.classpath_gtk @@ -20,6 +20,7 @@ <classpathentry kind="src" path="Eclipse SWT Program/gtk"/> <classpathentry kind="src" path="Eclipse SWT Program/common"/> <classpathentry kind="src" path="Eclipse SWT Program/gnome"/> + <classpathentry kind="src" path="Eclipse SWT Program/cde"/> <classpathentry kind="src" path="Eclipse SWT Program/kde"/> <classpathentry kind="src" path="Eclipse SWT Custom Widgets/common"/> <classpathentry kind="src" path="Eclipse SWT Browser/common"/> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh index 0e6c614bb9..ee5617e6b1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh @@ -102,6 +102,9 @@ case $OS in if [ "${JAVA_HOME}" = "" ]; then JAVA_HOME=/usr/j2se fi + if [ "${CDE_HOME}" = "" ]; then + CDE_HOME=/usr/dt + fi AWT_LIB_PATH=$JAVA_HOME/jre/lib/sparc PATH=/usr/ccs/bin:/usr/local/bin:$PATH export PATH @@ -119,6 +122,6 @@ case $OS in ;; esac -export CC LD JAVA_HOME QT_HOME AWT_LIB_PATH XTEST_LIB_PATH GECKO_SDK GECKO_INCLUDES GECKO_LIBS SWT_PTR_CFLAGS KDE_LIB_PATH KDE_INCLUDE_PATH OUTPUT_DIR +export CC LD JAVA_HOME QT_HOME AWT_LIB_PATH XTEST_LIB_PATH GECKO_SDK GECKO_INCLUDES GECKO_LIBS SWT_PTR_CFLAGS CDE_HOME KDE_LIB_PATH KDE_INCLUDE_PATH OUTPUT_DIR make -f $makefile ${1} ${2} ${3} ${4} diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_solaris.mak b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_solaris.mak index 20297b76bd..f43371457b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_solaris.mak +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_solaris.mak @@ -18,11 +18,14 @@ SWT_VERSION=$(maj_ver)$(min_ver) # Define the various shared libraries to be build. WS_PREFIX = gtk SWT_PREFIX = swt +CDE_PREFIX = swt-cde AWT_PREFIX = swt-awt SWTPI_PREFIX = swt-pi ATK_PREFIX = swt-atk MOZILLA_PREFIX = swt-mozilla + SWT_LIB = lib$(SWT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so +CDE_LIB = lib$(CDE_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so AWT_LIB = lib$(AWT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so SWTPI_LIB = lib$(SWTPI_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so ATK_LIB = lib$(ATK_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so @@ -32,6 +35,8 @@ MOZILLA_LIB = lib$(MOZILLA_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so GTKCFLAGS = `pkg-config --cflags gtk+-2.0` GTKLIBS = `pkg-config --libs-only-L gtk+-2.0 gthread-2.0` -lgtk-x11-2.0 -lgthread-2.0 -L$(XTEST_LIB_PATH) -Wl,-R -Wl,$(XTEST_LIB_PATH) -lXtst +CDE_LIBS = -L$(CDE_HOME)/lib -R$(CDE_HOME)/lib -lXt -lX11 -lDtSvc + AWT_LIBS = -L$(AWT_LIB_PATH) -ljawt -shared ATKCFLAGS = `pkg-config --cflags atk gtk+-2.0` @@ -64,6 +69,7 @@ MOZILLALIBS = -shared -Wl,--version-script=mozilla_exports -Bsymbolic \ -L$(GECKO_SDK)/nspr/bin -lnspr4 -lplds4 -lplc4 SWT_OBJECTS = swt.o callback.o +CDE_OBJECTS = swt.o cde.o cde_structs.o cde_stats.o AWT_OBJECTS = swt_awt.o SWTPI_OBJECTS = swt.o os.o os_structs.o os_custom.o os_stats.o ATK_OBJECTS = swt.o atk.o atk_structs.o atk_custom.o atk_stats.o @@ -72,15 +78,16 @@ MOZILLA_OBJECTS = swt.o xpcom.o xpcom_custom.o xpcom_structs.o xpcom_stats.o CFLAGS = -O -Wall \ -DSWT_VERSION=$(SWT_VERSION) \ $(NATIVE_STATS) \ - -DSOLARIS -DGTK \ + -DSOLARIS -DGTK -DCDE \ -I$(JAVA_HOME)/include \ -I$(JAVA_HOME)/include/solaris \ -fpic \ - ${SWT_PTR_CFLAGS} + ${SWT_PTR_CFLAGS} \ + -I$(CDE_HOME)/include LIBS = -shared -fpic -all: make_swt make_atk make_awt +all: make_swt make_atk make_awt make_cde # # SWT libs @@ -108,6 +115,15 @@ os_stats.o: os_stats.c os_structs.h os.h os_stats.h swt.h $(CC) $(CFLAGS) $(GTKCFLAGS) -c os_stats.c # +# CDE lib +# + +make_cde: $(CDE_LIB) + +$(CDE_LIB): $(CDE_OBJECTS) + $(LD) $(LIBS) $(CDE_LIBS) -o $(CDE_LIB) $(CDE_OBJECTS) + +# # AWT lib # make_awt:$(AWT_LIB) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.c b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.c index 6b1f36ed29..1197637903 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.c +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.c @@ -168,3 +168,109 @@ JNIEXPORT void JNICALL CDE_NATIVE(_1DtDtsFreeDataTypeNames) } #endif +#ifndef NO__1XtAppCreateShell +JNIEXPORT jint JNICALL CDE_NATIVE(_1XtAppCreateShell) + (JNIEnv *env, jclass that, jbyteArray arg0, jbyteArray arg1, jint arg2, jint arg3, jintArray arg4, jint arg5) +{ + jbyte *lparg0=NULL; + jbyte *lparg1=NULL; + jint *lparg4=NULL; + jint rc = 0; + CDE_NATIVE_ENTER(env, that, _1XtAppCreateShell_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail; + rc = (jint)XtAppCreateShell((String)lparg0, (String)lparg1, (WidgetClass)arg2, (Display *)arg3, (ArgList)lparg4, arg5); +fail: + if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + CDE_NATIVE_EXIT(env, that, _1XtAppCreateShell_FUNC); + return rc; +} +#endif + +#ifndef NO__1XtCreateApplicationContext +JNIEXPORT jint JNICALL CDE_NATIVE(_1XtCreateApplicationContext) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + CDE_NATIVE_ENTER(env, that, _1XtCreateApplicationContext_FUNC); + rc = (jint)XtCreateApplicationContext(); + CDE_NATIVE_EXIT(env, that, _1XtCreateApplicationContext_FUNC); + return rc; +} +#endif + +#ifndef NO__1XtDisplayInitialize +JNIEXPORT void JNICALL CDE_NATIVE(_1XtDisplayInitialize) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jbyteArray arg2, jbyteArray arg3, jint arg4, jint arg5, jintArray arg6, jint arg7) +{ + jbyte *lparg2=NULL; + jbyte *lparg3=NULL; + jint *lparg6=NULL; + CDE_NATIVE_ENTER(env, that, _1XtDisplayInitialize_FUNC); + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL)) == NULL) goto fail; + if (arg6) if ((lparg6 = (*env)->GetIntArrayElements(env, arg6, NULL)) == NULL) goto fail; + XtDisplayInitialize((XtAppContext)arg0, (Display *)arg1, (String)lparg2, (String)lparg3, (XrmOptionDescRec *)arg4, (Cardinal)arg5, (int *)lparg6, (String *)arg7); +fail: + if (arg6 && lparg6) (*env)->ReleaseIntArrayElements(env, arg6, lparg6, 0); + if (arg3 && lparg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0); + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0); + CDE_NATIVE_EXIT(env, that, _1XtDisplayInitialize_FUNC); +} +#endif + +#ifndef NO__1XtRealizeWidget +JNIEXPORT void JNICALL CDE_NATIVE(_1XtRealizeWidget) + (JNIEnv *env, jclass that, jint arg0) +{ + CDE_NATIVE_ENTER(env, that, _1XtRealizeWidget_FUNC); + XtRealizeWidget((Widget)arg0); + CDE_NATIVE_EXIT(env, that, _1XtRealizeWidget_FUNC); +} +#endif + +#ifndef NO__1XtResizeWidget +JNIEXPORT void JNICALL CDE_NATIVE(_1XtResizeWidget) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3) +{ + CDE_NATIVE_ENTER(env, that, _1XtResizeWidget_FUNC); + XtResizeWidget((Widget)arg0, arg1, arg2, arg3); + CDE_NATIVE_EXIT(env, that, _1XtResizeWidget_FUNC); +} +#endif + +#ifndef NO__1XtSetMappedWhenManaged +JNIEXPORT void JNICALL CDE_NATIVE(_1XtSetMappedWhenManaged) + (JNIEnv *env, jclass that, jint arg0, jboolean arg1) +{ + CDE_NATIVE_ENTER(env, that, _1XtSetMappedWhenManaged_FUNC); + XtSetMappedWhenManaged((Widget)arg0, arg1); + CDE_NATIVE_EXIT(env, that, _1XtSetMappedWhenManaged_FUNC); +} +#endif + +#ifndef NO__1XtToolkitInitialize +JNIEXPORT void JNICALL CDE_NATIVE(_1XtToolkitInitialize) + (JNIEnv *env, jclass that) +{ + CDE_NATIVE_ENTER(env, that, _1XtToolkitInitialize_FUNC); + XtToolkitInitialize(); + CDE_NATIVE_EXIT(env, that, _1XtToolkitInitialize_FUNC); +} +#endif + +#ifndef NO__1topLevelShellWidgetClass +JNIEXPORT jint JNICALL CDE_NATIVE(_1topLevelShellWidgetClass) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + CDE_NATIVE_ENTER(env, that, _1topLevelShellWidgetClass_FUNC); + rc = (jint)topLevelShellWidgetClass; + CDE_NATIVE_EXIT(env, that, _1topLevelShellWidgetClass_FUNC); + return rc; +} +#endif + diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.h b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.h index 1fdd0119a3..671e38ab92 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.h +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde.h @@ -9,8 +9,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ -#ifndef INC_kde_H -#define INC_kde_H +#ifndef INC_cde_H +#define INC_cde_H #define NDEBUG @@ -21,4 +21,7 @@ #include <Dt/Dts.h> #include <Dt/Action.h> -#endif /* INC_kde_H */ +#include <X11/IntrinsicP.h> +#include <X11/Shell.h> + +#endif /* INC_cde_H */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.c b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.c index b87d24a7b6..775f7a3165 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.c @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int CDE_nativeFunctionCount = 10; -int CDE_nativeFunctionCallCount[10]; +int CDE_nativeFunctionCount = 18; +int CDE_nativeFunctionCallCount[18]; char * CDE_nativeFunctionNames[] = { "_1DtActionInvoke", "_1DtAppInitialize", @@ -27,6 +27,14 @@ char * CDE_nativeFunctionNames[] = { "_1DtDtsFreeAttributeValue", "_1DtDtsFreeDataType", "_1DtDtsFreeDataTypeNames", + "_1XtAppCreateShell", + "_1XtCreateApplicationContext", + "_1XtDisplayInitialize", + "_1XtRealizeWidget", + "_1XtResizeWidget", + "_1XtSetMappedWhenManaged", + "_1XtToolkitInitialize", + "_1topLevelShellWidgetClass", }; #define STATS_NATIVE(func) Java_org_eclipse_swt_tools_internal_NativeStats_##func diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.h b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.h index 74d41f5834..8f371db890 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/library/cde_stats.h @@ -31,4 +31,12 @@ typedef enum { _1DtDtsFreeAttributeValue_FUNC, _1DtDtsFreeDataType_FUNC, _1DtDtsFreeDataTypeNames_FUNC, + _1XtAppCreateShell_FUNC, + _1XtCreateApplicationContext_FUNC, + _1XtDisplayInitialize_FUNC, + _1XtRealizeWidget_FUNC, + _1XtResizeWidget_FUNC, + _1XtSetMappedWhenManaged_FUNC, + _1XtToolkitInitialize_FUNC, + _1topLevelShellWidgetClass_FUNC, } CDE_FUNCS; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/org/eclipse/swt/internal/cde/CDE.java b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/org/eclipse/swt/internal/cde/CDE.java index c7bd72f1f2..a14e99c000 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cde/org/eclipse/swt/internal/cde/CDE.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cde/org/eclipse/swt/internal/cde/CDE.java @@ -30,7 +30,7 @@ public static final boolean DtAppInitialize(int appContext, int display, int top } finally { lock.unlock(); } -} +} public static final native void _DtDbLoad(); public static final void DtDbLoad() { lock.lock(); @@ -112,5 +112,76 @@ public static final int DtActionInvoke(int topWidget, byte[] action, DtActionArg lock.unlock(); } } - +public static final native int _topLevelShellWidgetClass(); +public static final int topLevelShellWidgetClass() { + lock.lock(); + try { + return _topLevelShellWidgetClass(); + } finally { + lock.unlock(); + } +} +public static final native int _XtAppCreateShell(byte[] appName, byte[] appClass, int widgetClass, int display, int[] argList, int argCount); +public static final int XtAppCreateShell(byte[] appName, byte[] appClass, int widgetClass, int display, int[] argList, int argCount) { + lock.lock(); + try { + return _XtAppCreateShell(appName, appClass, widgetClass, display, argList, argCount); + } finally { + lock.unlock(); + } +} +public static final native int _XtCreateApplicationContext(); +public static final int XtCreateApplicationContext() { + lock.lock(); + try { + return _XtCreateApplicationContext(); + } finally { + lock.unlock(); + } +} +public static final native void _XtDisplayInitialize(int app_context, int display, byte[] appName, byte[] appClass, int options, int num_options, int[] argc, int argv); +public static final void XtDisplayInitialize(int appContext, int display, byte[] appName, byte[] appClass, int options, int num_options, int[] argc, int argv) { + lock.lock(); + try { + _XtDisplayInitialize(appContext, display, appName, appClass, options, num_options, argc, argv); + } finally { + lock.unlock(); + } +} +public static final native void _XtRealizeWidget(int widget); +public static final void XtRealizeWidget(int widget) { + lock.lock(); + try { + _XtRealizeWidget(widget); + } finally { + lock.unlock(); + } +} +public static final native void _XtResizeWidget(int widget, int width, int height, int borderWidth); +public static final void XtResizeWidget(int widget, int width, int height, int borderWidth) { + lock.lock(); + try { + _XtResizeWidget(widget, width, height, borderWidth); + } finally { + lock.unlock(); + } +} +public static final native void _XtSetMappedWhenManaged(int widget, boolean flag); +public static final void XtSetMappedWhenManaged(int widget, boolean flag) { + lock.lock(); + try { + _XtSetMappedWhenManaged(widget, flag); + } finally { + lock.unlock(); + } +} +public static final native void _XtToolkitInitialize(); +public static final void XtToolkitInitialize() { + lock.lock(); + try { + _XtToolkitInitialize(); + } finally { + lock.unlock(); + } +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java index 8d8f67a0e3..e6c266ce8a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java @@ -14,6 +14,7 @@ package org.eclipse.swt.program; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.cde.*; import org.eclipse.swt.internal.gnome.*; import org.eclipse.swt.internal.kde.*; import org.eclipse.swt.internal.gtk.*; @@ -38,7 +39,11 @@ public final class Program { * false if expects a path */ boolean gnomeExpectUri; + + static int cdeShell; + static final String[] CDE_ICON_EXT = { ".m.pm", ".l.pm", ".s.pm", ".t.pm" }; + static final String[] CDE_MASK_EXT = { ".m_m.bm", ".l_m.bm", ".s_m.bm", ".t_m.bm" }; static final String DESKTOP_DATA = "Program_DESKTOP"; static final int DESKTOP_UNKNOWN = 0; static final int DESKTOP_GNOME = 1; @@ -99,10 +104,158 @@ static int getDesktop(Display display) { } } + /* + * On CDE, the atom below may exist without DTWM running. If the atom + * below is defined, the CDE database exists and the available + * applications can be queried. + */ + if (desktop == DESKTOP_UNKNOWN) { + byte[] cdeName = Converter.wcsToMbcs(null, "_DT_SM_PREFERENCES", true); + int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName, true); + for (int index = 0; desktop == DESKTOP_UNKNOWN && index < property.length; index++) { + if (property[index] == OS.None) continue; /* do not match atoms that do not exist */ + if (property[index] == cde && cde_init(display)) desktop = DESKTOP_CDE; + } + } + display.setData(DESKTOP_DATA, new Integer(desktop)); return desktop; } +boolean cde_execute(String fileName) { + /* Use the character encoding for the default locale */ + byte[] action = Converter.wcsToMbcs(null, command, true); + byte[] fileArg = Converter.wcsToMbcs(null, fileName, true); + int actionID = 0; + int /*long*/ ptr = OS.g_malloc(fileArg.length); + OS.memmove(ptr, fileArg, fileArg.length); + DtActionArg args = new DtActionArg(); + args.argClass = CDE.DtACTION_FILE; + args.name = ptr; + actionID = CDE.DtActionInvoke(cdeShell, action, args, 1, null, null, null, 1, 0, 0); + OS.g_free(ptr); + return actionID != 0; +} + +static String cde_getAction(String dataType) { + String action = null; + String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); + if (actions != null) { + int index = actions.indexOf("Open"); + if (index != -1) { + action = actions.substring(index, index + 4); + } else { + index = actions.indexOf(","); + action = index != -1 ? actions.substring(0, index) : actions; + } + } + return action; +} + +static String cde_getAttribute(String dataType, String attrName) { + /* Use the character encoding for the default locale */ + byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true); + byte[] attrNameBuf = Converter.wcsToMbcs(null, attrName, true); + byte[] optNameBuf = null; + int /*long*/ attrValue = CDE.DtDtsDataTypeToAttributeValue(dataTypeBuf, attrNameBuf, optNameBuf); + if (attrValue == 0) return null; + int length = OS.strlen(attrValue); + byte[] attrValueBuf = new byte[length]; + OS.memmove(attrValueBuf, attrValue, length); + CDE.DtDtsFreeAttributeValue(attrValue); + /* Use the character encoding for the default locale */ + return new String(Converter.mbcsToWcs(null, attrValueBuf)); +} + +static Hashtable cde_getDataTypeInfo() { + Hashtable dataTypeInfo = new Hashtable(); + int index; + int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames(); + if (dataTypeList != 0) { + /* For each data type name in the list */ + index = 0; + int /*long*/ [] dataType = new int /*long*/ [1]; + OS.memmove(dataType, dataTypeList + (index++ * 4), 4); + while (dataType[0] != 0) { + int length = OS.strlen(dataType[0]); + byte[] dataTypeBuf = new byte[length]; + OS.memmove(dataTypeBuf, dataType[0], length); + /* Use the character encoding for the default locale */ + String dataTypeName = new String(Converter.mbcsToWcs(null, dataTypeBuf)); + + /* The data type is valid if it is not an action, and it has an extension and an action. */ + String extension = cde_getExtension(dataTypeName); + if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) && + extension != null && cde_getAction(dataTypeName) != null) { + Vector exts = new Vector(); + exts.addElement(extension); + dataTypeInfo.put(dataTypeName, exts); + } + OS.memmove(dataType, dataTypeList + (index++ * 4), 4); + } + CDE.DtDtsFreeDataTypeNames(dataTypeList); + } + + return dataTypeInfo; +} + +static String cde_getExtension(String dataType) { + String fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); + if (fileExt == null || fileExt.indexOf("%s.") == -1) return null; + int dot = fileExt.indexOf("."); + return fileExt.substring(dot); +} + +/** + * CDE - Get Image Data + * + * This method returns the image data of the icon associated with + * the data type. Since CDE supports multiple sizes of icons, several + * attempts are made to locate an icon of the desired size and format. + * CDE supports the sizes: tiny, small, medium and large. The best + * search order is medium, large, small and then tiny. Althoug CDE supports + * colour and monochrome bitmaps, only colour icons are tried. (The order is + * defined by the cdeIconExt and cdeMaskExt arrays above.) + */ +ImageData cde_getImageData() { + // TODO + return null; +} + +static Program cde_getProgram(Display display, String mimeType) { + Program program = new Program(); + program.display = display; + program.name = mimeType; + program.command = cde_getAction(mimeType); + program.iconPath = cde_getAttribute(program.name, CDE.DtDTS_DA_ICON); + return program; +} + +static boolean cde_init(Display display) { + try { + Library.loadLibrary("swt-cde"); + } catch (Throwable e) { + return false; + } + + /* Use the character encoding for the default locale */ + CDE.XtToolkitInitialize(); + int /*long*/ xtContext = CDE.XtCreateApplicationContext (); + int /*long*/ xDisplay = OS.GDK_DISPLAY(); + byte[] appName = Converter.wcsToMbcs(null, "CDE", true); + byte[] appClass = Converter.wcsToMbcs(null, "CDE", true); + int /*long*/ [] argc = new int /*long*/ [] {0}; + CDE.XtDisplayInitialize(xtContext, xDisplay, appName, appClass, 0, 0, argc, 0); + int /*long*/ widgetClass = CDE.topLevelShellWidgetClass (); + cdeShell = CDE.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + CDE.XtSetMappedWhenManaged (cdeShell, false); + CDE.XtResizeWidget (cdeShell, 10, 10, 0); + CDE.XtRealizeWidget (cdeShell); + boolean initOK = CDE.DtAppInitialize(xtContext, xDisplay, cdeShell, appName, appName); + if (initOK) CDE.DtDbLoad(); + return initOK; +} + static String[] parseCommand(String cmd) { Vector args = new Vector(); int sIndex = 0; @@ -519,6 +672,7 @@ static Program findProgram(Display display, String extension) { switch (desktop) { case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; case DESKTOP_KDE: mimeInfo = kde_getMimeInfo(); break; + case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; } if (mimeInfo == null) return null; String mimeType = null; @@ -538,6 +692,7 @@ static Program findProgram(Display display, String extension) { switch (desktop) { case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; case DESKTOP_KDE: program = kde_getProgram(display, mimeType); break; + case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break; } return program; } @@ -563,6 +718,7 @@ static String[] getExtensions(Display display) { switch (desktop) { case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; case DESKTOP_KDE: mimeInfo = kde_getMimeInfo(); break; + case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; } if (mimeInfo == null) return new String[0]; @@ -608,6 +764,7 @@ static Program[] getPrograms(Display display) { switch (desktop) { case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; case DESKTOP_KDE: mimeInfo = kde_getMimeInfo(); break; + case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; } if (mimeInfo == null) return new Program[0]; Vector programs = new Vector(); @@ -618,6 +775,7 @@ static Program[] getPrograms(Display display) { switch (desktop) { case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; case DESKTOP_KDE: program = kde_getProgram(display, mimeType); break; + case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break; } if (program != null) programs.addElement(program); } @@ -705,6 +863,7 @@ public boolean execute(String fileName) { switch (desktop) { case DESKTOP_GNOME: return gnome_execute(fileName); case DESKTOP_KDE: return kde_execute(fileName); + case DESKTOP_CDE: return cde_execute(fileName); } return false; } @@ -720,6 +879,7 @@ public ImageData getImageData() { switch (getDesktop(display)) { case DESKTOP_GNOME: return gnome_getImageData(); case DESKTOP_KDE: return kde_getImageData(); + case DESKTOP_CDE: return cde_getImageData(); } return null; } |