diff options
author | Veronika Irvine <veronika> | 2002-10-30 21:04:13 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2002-10-30 21:04:13 +0000 |
commit | 60bdd070c5ec14c10c91df7cde237b89fddc0025 (patch) | |
tree | b87c5bc9b0511ac9ac1813d2a12bc521f65c1ffb | |
parent | 2db8c98b49ce9b21a96899926df3345a6e84853e (diff) | |
download | eclipse.platform.swt-60bdd070c5ec14c10c91df7cde237b89fddc0025.tar.gz eclipse.platform.swt-60bdd070c5ec14c10c91df7cde237b89fddc0025.tar.xz eclipse.platform.swt-60bdd070c5ec14c10c91df7cde237b89fddc0025.zip |
*** empty log message ***
33 files changed, 1 insertions, 17675 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt.c index 65fc303f41..07c3c468eb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt.c @@ -12,8 +12,6 @@ #include "swt.h" #include "structs.h" -#include "swt2.c" - #define OS_NATIVE(func) Java_org_eclipse_swt_internal_carbon_OS_##func #ifndef NO_AddDataBrowserItems diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt2.c b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt2.c deleted file mode 100644 index b355eeba64..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt2.c +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -/** - * SWT OS custom natives implementation. - */ - -//#define USE_ATSUI 1 - -static const Rect NULL_RECT; - -#ifdef DEBUG -#define RC(f) checkStatus(__LINE__, (f)) - -static int checkStatus(int line, int rc) { - switch (rc) { - case 0: - case eventNotHandledErr: - case eventLoopTimedOutErr: - case errControlIsNotEmbedder: - break; - default: - //fprintf(stderr, "OS: line: %d %d\n", line, rc); - break; - } - return rc; -} -#else -#define RC(f) f -#endif - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_NewCursor(JNIEnv *env, jclass zz, - jshort hotX, jshort hotY, jshortArray data, jshortArray mask) { - - jshort *sa= (*env)->GetShortArrayElements(env, data, 0); - jshort *sb= (*env)->GetShortArrayElements(env, mask, 0); - - Cursor *c= (Cursor*) NewPtrClear(sizeof(Cursor)); - memcpy(&c->data, sa, sizeof (Bits16)); - memcpy(&c->mask, sb, sizeof (Bits16)); - c->hotSpot.h= hotX; - c->hotSpot.v= hotY; - - (*env)->ReleaseShortArrayElements(env, data, sa, 0); - (*env)->ReleaseShortArrayElements(env, mask, sb, 0); - - return (jint) c; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_NewPixMap(JNIEnv *env, jclass zz, - jshort width, jshort height, jshort rowbytes, - jshort pixelType, jshort pixelSize, jshort cmpSize, jshort cmpCount, jshort pixelFormat) { - - PixMapHandle pmh= NewPixMap(); - PixMap *pm= *pmh; - - pm->baseAddr= NULL; - pm->rowBytes= rowbytes | 0x8000; // mark as PixMap - pm->bounds.top= 0; - pm->bounds.left= 0; - pm->bounds.bottom= height; - pm->bounds.right= width; - pm->pmVersion= baseAddr32; // 32 Bit clean - pm->packType= 0; - pm->packSize= 0; - pm->hRes= 0x00480000; - pm->vRes= 0x00480000; - pm->pixelType= pixelType; - pm->pixelSize= pixelSize; - pm->cmpCount= cmpCount; - pm->cmpSize= cmpSize; - pm->pixelFormat= pixelFormat; - pm->pmTable= NULL; - pm->pmExt= NULL; - - return (jint) pmh; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getRowBytes(JNIEnv *env, jclass zz, jint pHandle) { - BitMap **bmh= (BitMap**) pHandle; - return (jint) (*bmh)->rowBytes; -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_setRowBytes(JNIEnv *env, jclass zz, - jint pHandle, jshort rowBytes) { - BitMap **bmh= (BitMap**) pHandle; - (*bmh)->rowBytes= rowBytes; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getBaseAddr(JNIEnv *env, jclass zz, jint pHandle) { - BitMap **bmh= (BitMap**) pHandle; - return (jint) (*bmh)->baseAddr; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getColorTableSize(JNIEnv *env, jclass zz, - jint pixMapHandle) { - PixMapHandle srch= (PixMapHandle) pixMapHandle; - PixMap *src= *srch; - if (src->pmTable != NULL) { - ColorTable *ct= *src->pmTable; - return ct->ctSize + 1; - } - return -1; -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getColorTable(JNIEnv *env, jclass zz, - jint pixMapHandle, jshortArray colorspec) { - PixMapHandle srch= (PixMapHandle) pixMapHandle; - PixMap *src= *srch; - int n= (*env)->GetArrayLength(env, colorspec) / 4; - if (src->pmTable != NULL) { - ColorTable *ct= *src->pmTable; - jshort *sa= (*env)->GetShortArrayElements(env, colorspec, 0); - memcpy(sa, ct->ctTable, n * sizeof(ColorSpec)); - (*env)->ReleaseShortArrayElements(env, colorspec, sa, 0); - } -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_setColorTable(JNIEnv *env, jclass zz, - jint pixMapHandle, jshortArray colorspec) { - - PixMapHandle ph= (PixMapHandle) pixMapHandle; - PixMap *pm= *ph; - ColorTable *ct; - jshort *sa; - int n= (*env)->GetArrayLength(env, colorspec) / 4; - - if (pm->pmTable != NULL) - DisposeHandle((Handle)pm->pmTable); - pm->pmTable= (ColorTable**) NewHandle(sizeof(ColorTable)+sizeof(ColorSpec)*(n-1)); - ct= *pm->pmTable; - ct->ctSize= (n-1); - ct->ctFlags= 0; - ct->ctSeed= GetCTSeed(); - - sa= (*env)->GetShortArrayElements(env, colorspec, 0); - memcpy(ct->ctTable, sa, n * sizeof(ColorSpec)); - (*env)->ReleaseShortArrayElements(env, colorspec, sa, 0); -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_setBaseAddr(JNIEnv *env, jclass zz, - jint bitMapHandle, jint ptr) { - BitMap **bmh= (BitMap**) bitMapHandle; - (*bmh)->baseAddr= (void*) ptr; -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_DisposePixMap(JNIEnv *env, jclass zz, jint pixMapHandle) { - PixMapHandle ph= (PixMapHandle) pixMapHandle; - PixMap *pm= *ph; - - if (pm->baseAddr != NULL) { - DisposePtr(pm->baseAddr); - pm->baseAddr= NULL; - } - - if ((pm->rowBytes & 0x8000) != 0) { // Pixmap - DisposePixMap(ph); - } else { // Bitmap - fprintf(stderr, "OS.DisposePixMap: warning: pixmap is bitmap\n"); - } -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_duplicatePixMap(JNIEnv *env, jclass zz, jint srcPixmap) { - - PixMapHandle srch= (PixMapHandle) srcPixmap; - PixMapHandle dsth= NewPixMap(); - - PixMap *src= *srch; - PixMap *dst= *dsth; - - *dst= *src; - dst->pmExt= NULL; - - if (src->baseAddr != NULL) { - Size dataSize= GetPtrSize(src->baseAddr); - //fprintf(stderr, "duplicatePixMap: data %ld\n", dataSize); - dst->baseAddr= NewPtr(dataSize); - memcpy(dst->baseAddr, src->baseAddr, dataSize); - } - - if ((dst->rowBytes & 0x8000) != 0) { // pixmap - if (src->pmTable != NULL) { - ColorTable *ct; - Size dataSize= GetHandleSize((Handle)src->pmTable); - //fprintf(stderr, "duplicatePixMap: ctab %ld\n", dataSize); - dst->pmTable= (ColorTable**) NewHandle(dataSize); - ct= *dst->pmTable; - memcpy(ct, *src->pmTable, dataSize); - //fprintf(stderr, "duplicatePixMap: ctab size %d\n", ct->ctSize); - } - } - - return (jint) dsth; -} - -JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_carbon_OS2_setPixBounds(JNIEnv *env, jclass zz, - jint pHandle, jshort top, jshort left, jshort bottom, jshort right) { - BitMap **bmh= (BitMap**) pHandle; - BitMap *bm= *bmh; - bm->bounds.top= top; - bm->bounds.left= left; - bm->bounds.bottom= bottom; - bm->bounds.right= right; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getPixHRes(JNIEnv *env, jclass zz, jint pHandle) { - PixMapHandle pmh= (PixMapHandle) pHandle; - return (jint) (*pmh)->hRes; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getPixVRes(JNIEnv *env, jclass zz, jint pHandle) { - PixMapHandle pmh= (PixMapHandle) pHandle; - return (jint) (*pmh)->vRes; -} - -static jmp_buf jmpbuf; - -static void jumper() { - longjmp(jmpbuf, 1); -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_CopyMask(JNIEnv *env, jclass zz, jint srcBits, - jint maskBits, jint dstBits, jobject srcRect, jobject maskRect, jobject dstRect) { - - Rect ra; - Rect rb; - Rect rc; - - getRectFields(env, srcRect, &ra); - getRectFields(env, maskRect, &rb); - getRectFields(env, dstRect, &rc); - - if (setjmp(jmpbuf) != 0) { - SysBeep(100); - fprintf(stderr, "OS.CopyMask: signal %08x %08x %08x\n", srcBits, maskBits, dstBits); - return -1; - } - - if (signal(SIGSEGV, jumper) == BADSIG) - fprintf(stderr, "OS.CopyMask: error in signal1\n"); - CopyMask((BitMap*)srcBits, (BitMap*)maskBits, (BitMap*)dstBits, &ra, &rb, &rc); - if (signal(SIGSEGV, SIG_DFL) == BADSIG) - fprintf(stderr, "OS.CopyMask: error in signal2\n"); - return 0; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_NewCIcon(JNIEnv *env, jclass zz, - jint pixMapHandle, jint maskHandle) { - CIcon *icon; - CIconHandle cih; - PixMap *ph= NULL; - BitMap *mh= NULL; - int pixmapRowbytes, pixmapWidth, pixmapHeight, pixmapSize; - int maskRowbytes, maskHeight, maskSize; - Size ctsize; - int size; - - if (pixMapHandle == 0) - return 0; - ph= *((PixMap**) pixMapHandle); - if (ph == NULL) - return 0; - - // calculate the CIcon size - - pixmapRowbytes= ph->rowBytes & 0x3fff; - pixmapHeight= ph->bounds.bottom - ph->bounds.top; - pixmapWidth= ph->bounds.right - ph->bounds.left; - pixmapSize= pixmapRowbytes * pixmapHeight; - - mh= *((BitMap**) maskHandle); - if (mh == NULL) - return 0; - - maskRowbytes= mh->rowBytes & 0x3fff; - maskHeight= mh->bounds.bottom - mh->bounds.top; - maskSize= maskRowbytes * maskHeight; - - // allocate the CIcon - cih= (CIconHandle) NewHandleClear(sizeof(CIcon) + maskSize); - if (cih == NULL) - return 0; - icon= *cih; - if (icon == NULL) - return 0; - - // copy the pixmap - memcpy(&icon->iconPMap, ph, sizeof(PixMap)); - icon->iconPMap.baseAddr= 0; // this is documented nowhere! - - // allocate the handle for the pixmap's data - icon->iconData= NewHandle(pixmapSize); - if (icon->iconData == 0) - return 0; - - // copy the pixmap's data - memcpy(*icon->iconData, ph->baseAddr, pixmapSize); - - // copy ctable (if any) - if (ph->pmTable != NULL) { - ctsize= GetHandleSize((Handle)ph->pmTable); - if (ctsize > 0) { - Handle h= NewHandle(ctsize); - memcpy(*h, *ph->pmTable, ctsize); - icon->iconPMap.pmTable= (ColorTable**) h; - } - } - - memcpy(&icon->iconMask, mh, sizeof(BitMap)); - // copy mask data to end of CIcon - memcpy(&icon->iconMaskData, icon->iconMask.baseAddr, maskSize); - icon->iconMask.baseAddr= 0; - - return (jint) cih; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getCIconIconData(JNIEnv *env, jclass zz, jint cIconHandle) { - CIcon *icon= *((CIconHandle) cIconHandle); - return (jint) icon->iconData; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getCIconColorTable(JNIEnv *env, jclass zz, jint cIconHandle) { - CIcon *icon= *((CIconHandle) cIconHandle); - return (jint) icon->iconPMap.pmTable; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_getgdPMap(JNIEnv *env, jclass zz, jint gdHandle) { - GDHandle h= (GDHandle) gdHandle; - return (jint) (*h)->gdPMap; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_DerefHandle(JNIEnv *env, jclass zz, jint handle) { - Handle h= (Handle) handle; - return (jint) *h; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_NewGWorldFromPtr(JNIEnv *env, jclass zz, - jintArray offscreenGWorld, jint pixMapHandle) { - - PixMapHandle pm= (PixMapHandle) pixMapHandle; - jint *sa= (*env)->GetIntArrayElements(env, offscreenGWorld, 0); - - jint status= (jint) RC(NewGWorldFromPtr( - (GWorldPtr*) sa, - (*pm)->pixelFormat, - &((*pm)->bounds), - (*pm)->pmTable, - (GDHandle) NULL, - (GWorldFlags) 0, - (*pm)->baseAddr, - (*pm)->rowBytes & 0x3FFF)); - - (*env)->ReleaseIntArrayElements(env, offscreenGWorld, sa, 0); - return status; -} - -////////////////////////////////////////// -// added by AW while merging HIView stuff - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_HIViewSetBoundsOrigin(JNIEnv *env, jclass zz, - jint inView, jfloat x, jfloat y) { - return RC(HIViewSetBoundsOrigin((HIViewRef) inView, x, y)); -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_HIViewGetPartHit(JNIEnv *env, jclass zz, - jint inView, jfloatArray where, jshortArray outPart) { - jfloat *sa= (*env)->GetFloatArrayElements(env, where, 0); - jshort *sb= (*env)->GetShortArrayElements(env, outPart, 0); - jint status= RC(HIViewGetPartHit((HIViewRef) inView, (const HIPoint*) sa, (HIViewPartCode*) sb)); - (*env)->ReleaseFloatArrayElements(env, where, sa, 0); - (*env)->ReleaseShortArrayElements(env, outPart, sb, 0); - return status; -} - -JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS2_HIViewGetSubviewHit(JNIEnv *env, jclass zz, - jint inView, jfloatArray where, jboolean deep, jintArray outView) { - jfloat *sa= (*env)->GetFloatArrayElements(env, where, 0); - jint *sb= (*env)->GetIntArrayElements(env, outView, 0); - jint status= RC(HIViewGetSubviewHit((HIViewRef) inView, (const HIPoint*) sa, deep, (HIViewRef*) sb)); - (*env)->ReleaseFloatArrayElements(env, where, sa, 0); - (*env)->ReleaseIntArrayElements(env, outView, sb, 0); - return status; -} - - - diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java index 98c1a502fd..c461a24cd7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java @@ -9,7 +9,7 @@ package org.eclipse.swt.internal.carbon; import org.eclipse.swt.internal.Library; -public class OS extends OS2 { +public class OS { /* Load the SWT library. */ static { diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS2.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS2.java deleted file mode 100644 index 6764436e54..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS2.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.eclipse.swt.internal.carbon; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -class OS2 { - -/** Custom natives - pixmap */ -public static final native int CopyMask(int srcPixMapHandle, int maskPixMapHandle, int dstPixMapHandle, Rect srcRect, Rect maskRect, Rect dstRect); -public static final native int DerefHandle(int handle); -public static final native void DisposePixMap(int pHandle); -public static native int NewGWorldFromPtr(int[] offscreenGWorld, int pHandle); -public static final native int NewCIcon(int pixmapHandle, int maskHandle); -public static final native int NewCursor(short hotX, short hotY, short[] data, short[] mask); -public static final native int NewPixMap(short w, short h, short rowBytes, short pixelType, short pixelSize, short cmpSize, short cmpCount, short pixelFormat); -public static final native int duplicatePixMap(int srcPixmap); -public static final native int getBaseAddr(int pHandle); -public static final native int getCIconColorTable(int iconHandle); -public static final native int getCIconIconData(int iconHandle); -public static final native void getColorTable(int pHandle, short[] colorSpec); -public static final native int getColorTableSize(int pHandle); -public static final native int getPixHRes(int pHandle); -public static final native int getPixVRes(int pHandle); -public static final native int getRowBytes(int pHandle); -public static final native int getgdPMap(int gdHandle); -public static final native void setBaseAddr(int pHandle, int data); -public static final native void setColorTable(int pHandle, short[] colorSpec); -public static final native void setPixBounds(int pHandle, short top, short left, short bottom, short right); -public static final native void setRowBytes(int pHandle, short rowBytes); - -/** Custom helpers */ -public static int CFStringCreateWithCharacters(String string) { - char [] chars = new char [string.length()]; - string.getChars(0, chars.length, chars, 0); - return OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length); -} - -////////////////////////////////////////// -// added by AW while merging HIView stuff - -public static native int HIViewSetBoundsOrigin(int inView, float x, float y); -public static native int HIViewGetPartHit(int inView, float[] where, short[] outPart); -public static native int HIViewGetSubviewHit(int inView, float[] inPoint, boolean inDeep, int[] outView); -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java deleted file mode 100644 index 59b351420f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java +++ /dev/null @@ -1,244 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide a surface for drawing - * arbitrary graphics. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * This class may be subclassed by custom control implementors - * who are building controls that are <em>not</em> constructed - * from aggregates of other controls. That is, they are either - * painted using SWT graphics calls or are handled by native - * methods. - * </p> - * - * @see Composite - */ -public class Canvas extends Composite { - Caret caret; - -Canvas () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Canvas (Composite parent, int style) { - super (parent, style); -} -/** - * Returns the caret. - * <p> - * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - * </p> - * - * @return the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Caret getCaret () { - checkWidget(); - return caret; -} -/* AW -short [] getIMECaretPos () { - if (caret == null) return super.getIMECaretPos (); - int width = caret.width; - if (width <= 0) width = 2; - return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)}; -} -*/ -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 (Object 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(); -} - -/** - * Scrolls a rectangular area of the receiver by first copying - * the source area to the destination and then causing the area - * of the source which is not covered by the destination to - * be repainted. Children that intersect the rectangle are - * optionally moved during the operation. In addition, outstanding - * paint events are flushed before the source area is copied to - * ensure that the contents of the canvas are drawn correctly. - * - * @param destX the x coordinate of the destination - * @param destY the y coordinate of the destination - * @param x the x coordinate of the source - * @param y the y coordinate of the source - * @param width the width of the area - * @param height the height of the area - * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { - checkWidget(); - 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 */ - getDisplay().update (); - - GC gc= new GC(this); - gc.copyArea(x, y, width, height, destX, destY); - gc.dispose(); - - /* Show the caret */ - if (isFocus) caret.setFocus (); -} -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - super.setBounds (x, y, width, height); - if (isFocus) caret.setFocus (); -} -/** - * Sets the receiver's caret. - * <p> - * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - * </p> - * @param caret the new caret for the receiver, may be null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCaret (Caret caret) { - checkWidget(); - Caret newCaret = caret; - Caret oldCaret = this.caret; - this.caret = newCaret; - if (hasFocus ()) { - if (oldCaret != null) oldCaret.killFocus (); - if (newCaret != null) { - if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - newCaret.setFocus (); - } - } -} - -public void setLocation (int x, int y) { - checkWidget(); - 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) { - checkWidget(); - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - super.setSize (width, height); - if (isFocus) caret.setFocus (); -} -void updateCaret () { - if (caret == null) return; - /* AW - if (!IsDBLocale) return; - short [] point = getIMECaretPos (); - int ptr = OS.XtMalloc (4); - OS.memmove (ptr, point, 4); - int[] argList = {OS.XmNspotLocation, ptr}; - OS.XmImSetValues (handle, argList, argList.length / 2); - if (ptr != 0) OS.XtFree (ptr); - */ -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java deleted file mode 100644 index ba0d3bba1b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java +++ /dev/null @@ -1,482 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; - -/** - * Instances of this class provide an i-beam that is typically used - * as the insertion point for text. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class Caret extends Widget { - Canvas parent; - Image image; - int x, y, width, height; - boolean moved, resized; - boolean isVisible, isShowing; - int blinkRate = (OS.GetCaretTime() * 1000) / 60; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -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 nWidth = width, nHeight = height; - if (image != null) { - Rectangle rect = image.getBounds (); - nWidth = rect.width; - nHeight = rect.height; - } - if (nWidth <= 0) nWidth = 2; - GC gc= new GC(parent); - gc.setXORMode(true); - gc.fillRectangle(x, y, nWidth, nHeight); - gc.dispose(); - return true; -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null). - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - rect.x= x; - rect.y= y; - return rect; - } - 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 (); -} -/** - * Returns the font that the receiver will use to paint textual information. - * - * @return the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Font getFont () { - checkWidget(); - return parent.getFont (); -} -/** - * Returns the image that the receiver will use to paint the caret. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null). - * - * @return the receiver's location - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getLocation () { - checkWidget(); - return new Point (x, y); -} -/** - * Returns the receiver's parent, which must be a <code>Canvas</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Canvas getParent () { - checkWidget(); - return parent; -} -/** - * Returns a point describing the receiver's size. - * - * @return the receiver's size - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSize () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - return new Point (rect.width, rect.height); - } - return new Point (width, height); -} -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget(); - return isVisible; -} -boolean hideCaret () { - Display display = getDisplay (); - if (display.currentCaret != this) return false; - if (!isShowing) return true; - isShowing = false; - return drawCaret (); -} -/** - * Returns <code>true</code> if the receiver is visible and all - * of the receiver's ancestors are visible and <code>false</code> - * otherwise. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget(); - 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; - image = null; -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The <code>x</code> and - * <code>y</code> arguments are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - boolean samePosition, sameExtent; - 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; - parent.updateCaret (); - } - } else { - resized = true; - if (isVisible ()) { - moved = false; - parent.updateCaret (); - resized = false; - } - } - if (isShowing) showCaret (); -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the argument. The <code>x</code> and - * <code>y</code> fields of the rectangle are relative to - * the receiver's parent (or its display if its parent is null). - * - * @param rect the new bounds for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (Rectangle rect) { - checkWidget(); - 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 font that the receiver will use to paint textual information - * to the font specified by the argument, or to the default font for that - * kind of control if the argument is null. - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setFont (Font font) { - checkWidget(); - if (font != null && font.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } -} -/** - * Sets the image that the receiver will use to paint the caret - * to the image specified by the argument, or to the default - * which is a filled rectangle if the argument is null - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - if (isShowing) hideCaret (); - this.image = image; - if (isShowing) showCaret (); - System.out.println("Caret.setImage: nyi"); -} -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (int x, int y) { - checkWidget(); - setBounds (x, y, width, height); -} -/** - * Sets the receiver's location to the point specified by - * the argument which is relative to the receiver's - * parent (or its display if its parent is null). - * - * @param location the new location for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (Point location) { - checkWidget(); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); -} -/** - * Sets the receiver's size to the point specified by the arguments. - * - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (int width, int height) { - checkWidget(); - setBounds (x, y, width, height); -} -/** - * Sets the receiver's size to the point specified by the argument. - * - * @param size the new extent for the receiver - * @param height the new height for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (Point size) { - checkWidget(); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setSize (size.x, size.y); -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - 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/carbon/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java deleted file mode 100644 index 9d5bafa2ad..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.carbon.*; -import org.eclipse.swt.graphics.RGB; - -/** - * Instances of this class allow the user to select a color - * from a predefined set of available colors. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class ColorDialog extends Dialog { - - private RGB rgb; - private short[] fColor= new short[3]; - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog(Shell parent) { - this(parent, SWT.NULL); -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog(Shell parent, int style) { - super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); -} - -/** - * Returns the currently selected color in the receiver. - * - * @return the RGB value for the selected color, may be null - * - * @see PaletteData#getRGBs - */ -public RGB getRGB() { - return rgb; -} -/** - * Makes the receiver visible and brings it to the front - * of the display. - * - * @return the selected color, or null if the dialog was - * cancelled, no color was selected, or an error - * occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public RGB open() { - - org.eclipse.swt.internal.carbon.Point mp= new org.eclipse.swt.internal.carbon.Point(); - OS.GetGlobalMouse(mp); - - ColorPickerInfo info = new ColorPickerInfo(); - if (fColor != null) { - info.red= fColor[0]; - info.green= fColor[1]; - info.blue= fColor[2]; - } - info.flags= OS.kColorPickerDialogIsMoveable | OS.kColorPickerDialogIsModal; - info.placeWhere= (short)OS.kAtSpecifiedOrigin; - info.v= mp.v; - info.h= mp.h; - byte[] buffer = MacUtil.Str255(title); - System.arraycopy(buffer, 0, info.prompt, 0, Math.min(info.prompt.length, buffer.length)); - if ((OS.PickColor(info)) == OS.noErr) { - if (info.newColorChosen) { - if (rgb == null) - rgb= new RGB(0, 0, 0); - rgb.red= (info.red >> 8) & 0xff; - rgb.green= (info.green >> 8) & 0xff; - rgb.blue= (info.blue >> 8) & 0xff; - } else - rgb= null; - } else - rgb= null; - - return rgb; -} -/** - * Returns the receiver's selected color to be the argument. - * - * @param rgb the new RGB value for the selected color, may be - * null to let the platform to select a default when - * open() is called - * - * @see PaletteData#getRGBs - */ -public void setRGB(RGB rgb) { - this.rgb = rgb; - fColor[0]= (short) (rgb.red * 257); - fColor[1]= (short) (rgb.green * 257); - fColor[2]= (short) (rgb.blue * 257); - -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java deleted file mode 100644 index 1a94aa2ca1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java +++ /dev/null @@ -1,1429 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.internal.carbon.CGRect; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of this class are controls that allow the user - * to choose an item from a list of items, or optionally - * enter a new value by typing it into an editable text - * field. Often, <code>Combo</code>s are used in the same place - * where a single selection <code>List</code> widget could - * be used but space is limited. A <code>Combo</code> takes - * less space than a <code>List</code> widget and shows - * similar information. - * <p> - * Note: Since <code>Combo</code>s can contain both a list - * and an editable text field, it is possible to confuse methods - * which access one versus the other (compare for example, - * <code>clearSelection()</code> and <code>deselectAll()</code>). - * The API documentation is careful to indicate either "the - * receiver's list" or the "the receiver's text field" to - * distinguish between the two cases. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add children to it, or set a layout on it. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Modify, Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles DROP_DOWN and SIMPLE - * may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see List - */ -public /*final*/ class Combo extends Composite { - - /** - * the operating system limit for the number of characters - * that the text field in an instance of this class can hold - */ - public static int LIMIT; - private static int fgCommandID= 6000; - private static final int FOCUS_BORDER= 3; - private static final int MARGIN= 2; - - private int menuHandle; - private int textLimit= 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; - } - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see SWT#READ_ONLY - * @see SWT#SIMPLE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Combo (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the argument to the end of the receiver's list. - * - * @param string the new item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - if (menuHandle != 0) { - if (OS.AppendMenuItemTextWithCFString(menuHandle, sHandle, 0, fgCommandID++, null) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - OS.SetControl32BitMaximum(handle, OS.CountMenuItems(menuHandle)); - } else { - if (OS.HIComboBoxAppendTextItem(handle, sHandle, null) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - } - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } -} -/** - * Adds the argument to the receiver's list at the given - * zero-relative index. - * <p> - * Note: To add an item at the end of the list, use the - * result of calling <code>getItemCount()</code> as the - * index or use <code>add(String)</code>. - * </p> - * - * @param string the new item - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - if (menuHandle != 0) { - if (OS.InsertMenuItemTextWithCFString(menuHandle, sHandle, (short)index, 0, fgCommandID++) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - OS.SetControl32BitMaximum(handle, OS.CountMenuItems(menuHandle)); - } else { - OS.HIComboBoxInsertTextItemAtIndex(handle, index, sHandle); - } - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the <code>ModifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the combo's list selection changes. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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) { - - // AW only READ_ONLY is implemented - style &= ~SWT.DROP_DOWN; - style &= ~SWT.SIMPLE; - // AW - - /* - * 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); -} -/** - * Sets the selection in the receiver's text field to an empty - * selection starting just before the first character. If the - * text field is editable, this has the effect of placing the - * i-beam at the start of the text. - * <p> - * Note: To clear the selected items in the receiver's list, - * use <code>deselectAll()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #deselectAll - */ -public void clearSelection () { - checkWidget(); - if (menuHandle == 0) - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, new short[] { 0, 0 }); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - /* AW - 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; - */ - - int width = wHint; - int height = hHint; - - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - - Point e= MacUtil.computeSize(handle); - if (wHint == SWT.DEFAULT) - width= e.x; - if (hHint == SWT.DEFAULT) - height= e.y; - } - - width= 150; - height--; - -// width += 2*MARGIN; -// height += 2*MARGIN; -// if ((style & SWT.BORDER) != 0) { - width += 2*FOCUS_BORDER; - height += 2*FOCUS_BORDER; -// } - - return new Point (width, height); -} -/** - * Copies the selected text. - * <p> - * The current selection is copied to the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void copy () { - checkWidget (); - selectionToClipboard(); -} -void createHandle (int index) { - state |= HANDLE; - if ((style & SWT.READ_ONLY) != 0) { - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)-12345, (short)-1, (short)(OS.kControlPopupButtonProc+1), 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - int[] menuRef= new int[1]; - OS.CreateNewMenu((short)20000, 0, menuRef); - menuHandle= menuRef[0]; - if (menuHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.SetControlPopupMenuHandle(handle, menuHandle); - } else { - int[] outComboBox= new int[1]; - OS.HIComboBoxCreate(new CGRect(), 0, null, 0, OS.kHIComboBoxAutoSizeListAttribute, outComboBox); - handle= outComboBox[0]; - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - } - OS.HIViewSetVisible(handle, true); -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void cut () { - checkWidget (); - selectionToClipboard(); - _replaceTextSelection(""); -} -/* AW -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - int [] argList = { - OS.XmNlist, 0, - OS.XmNtextField, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - enableHandle (enabled, argList [1]); - enableHandle (enabled, argList [3]); -} -*/ -/** - * Deselects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. - * - * @param index the index of the item to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int index) { - checkWidget(); - if (index == -1) return; - /* AW - 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]); - } - */ - System.out.println("Combo.deselect: nyi"); -} -/** - * Deselects all selected items in the receiver's list. - * <p> - * Note: To clear the selection in the receiver's text field, - * use <code>clearSelection()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #clearSelection - */ -public void deselectAll () { - checkWidget(); - /* AW - 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]); - */ - System.out.println("Combo.deselectAll: nyi"); -} -/** - * Returns the item at the given, zero-relative index in the - * receiver's list. Throws an exception if the index is out - * of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - return _getItem(index); -} -/** - * Returns the number of items contained in the receiver's list. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - return _getItemCount(); -} -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the receiver's list. - * - * @return the height of one item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - /* AW - 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 */ - /* AW - return getFontHeight () + spacing + (2 * highlight); - */ - return MacUtil.computeSize(handle).y; -} -/** - * Returns an array of <code>String</code>s which are the items - * in the receiver's list. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver's list - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - int itemCount= _getItemCount(); - String[] result= new String [itemCount]; - for (int i= 0; i < itemCount; i++) - result[i]= _getItem(i); - return result; -} -/** - * Returns a <code>Point</code> whose x coordinate is the start - * of the selection in the receiver's text field, and whose y - * coordinate is the end of the selection. The returned values - * are zero-relative. An "empty" selection as indicated by - * the the x and y coordinates having the same value. - * - * @return a point representing the selection start and end - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSelection () { - checkWidget(); - Point selection= new Point(0, 0); - if (menuHandle == 0) { - short[] s= new short[2]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, s.length*2, s, null); - selection.x= (short) s[0]; - selection.y= (short) s[1]; - } - return selection; -} -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver's list, or -1 if no item is selected. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget(); - if (menuHandle != 0) - return OS.GetControlValue(handle)-1; - return indexOf(getText()); -} -/** - * Returns a string containing a copy of the contents of the - * receiver's text field. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - if (menuHandle != 0) { - int index= getSelectionIndex(); - if (index >= 0) - return _getItem(index); - return ""; - } - int[] t= new int[1]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, t.length*4, t, null); - return MacUtil.getStringAndRelease(t[0]); -} -/** - * Returns the height of the receivers's text field. - * - * @return the text height - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getTextHeight () { - checkWidget(); - 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. - */ - /* AW - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWHeight; - OS.XtQueryGeometry (handle, null, result); - return result.height; - */ - return 26; - } else { - /* Calculate text field height. */ - /* AW - 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. */ - /* AW - 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; - */ - return 26; - } -} -/** - * Returns the maximum number of characters that the receiver's - * text field is capable of holding. If this has not been changed - * by <code>setTextLimit()</code>, it will be the constant - * <code>Combo.LIMIT</code>. - * - * @return the text limit - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTextLimit () { - checkWidget(); - return textLimit; -} -void hookEvents () { - super.hookEvents (); - /* AW - 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); - */ -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int itemCount= _getItemCount(); - for (int i= 0; i < itemCount; i++) { - String s= _getItem(i); - if (s != null && string.equals(s)) - return i; - } - return -1; -} -/** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string, int start) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int itemCount= _getItemCount(); - if (!((0 <= start) && (start < itemCount))) return -1; - for (int i= start; i < itemCount; i++) { - String s= _getItem(i); - if (string.equals(s)) - return i; - } - return -1; -} -/** - * Pastes text from clipboard. - * <p> - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void paste () { - checkWidget (); - if (menuHandle == 0) { - Clipboard clipboard= new Clipboard(getDisplay()); - TextTransfer textTransfer= TextTransfer.getInstance(); - String clipBoard= (String)clipboard.getContents(textTransfer); - clipboard.dispose(); - _replaceTextSelection(clipBoard); - } -} -/** - * Removes the item from the receiver's list at the given - * zero-relative index. - * - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int itemCount= _getItemCount(); - if (!(0 <= index && index < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - if (menuHandle != 0) { - OS.DeleteMenuItems(menuHandle, (short)(index+1), 1); - OS.SetControl32BitMaximum(handle, OS.CountMenuItems(menuHandle)); - } else { - OS.HIComboBoxRemoveItemAtIndex(handle, index); - } -} -/** - * Removes the items from the receiver's list which are - * between the given zero-relative start and end - * indices (inclusive). - * - * @param start the start of the range - * @param end the end of the range - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - if (start > end) return; - int itemCount= _getItemCount(); - if (!(0 <= start && start < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - int newEnd = Math.min (end, itemCount - 1); - if (menuHandle != 0) { - OS.DeleteMenuItems(menuHandle, (short)(start+1), newEnd-start+1); - OS.SetControl32BitMaximum(handle, OS.CountMenuItems(menuHandle)); - } else { - for (int i= end; i >= start; i--) - OS.HIComboBoxRemoveItemAtIndex(handle, i); - } -} -/** - * Searches the receiver's list starting at the first item - * until an item is found that is equal to the argument, - * and removes that item from the list. - * - * @param string the item to remove - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int itemCount= _getItemCount(); - for (int i= 0; i < itemCount; i++) { - String s= _getItem(i); - if (s != null && string.equals(s)) { - remove(i); - return; - } - } - error (SWT.ERROR_INVALID_ARGUMENT); -} -/** - * Removes all of the items from the receiver's list. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - int itemCount= _getItemCount(); - if (itemCount > 0) { - if (menuHandle != 0) { - OS.DeleteMenuItems(menuHandle, (short)1, itemCount); - OS.SetControl32BitMaximum(handle, OS.CountMenuItems(menuHandle)); - } else { - for (int i= itemCount-1; i >= 0; i--) - OS.HIComboBoxRemoveItemAtIndex(handle, i); - } - } -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} -/** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int index) { - checkWidget(); - - int itemCount= _getItemCount(); - if (!(0 <= index && index < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - - if (menuHandle != 0) - OS.SetControl32BitValue(handle, index+1); - else { - String string= _getItem(index); - _setText(string); - _selectAll(); - //sendEvent(SWT.Modify); - } -} -/** -* Sets the widget bounds. -*/ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height; - super.setBounds (x, y, width, newHeight); -} -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to <code>remove</code>'ing the old item at the index, and then - * <code>add</code>'ing the new item at that index. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li> - * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - /* AW - 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 (getCodePage (), 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); - */ - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - if (menuHandle != 0) { - if (OS.SetMenuItemTextWithCFString(menuHandle, (short)(index+1), sHandle) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - } else { - OS.HIComboBoxInsertTextItemAtIndex(handle, index, sHandle); - OS.HIComboBoxRemoveItemAtIndex(handle, index+1); - } - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } -} -/** - * Sets the receiver's list to be the given array of items. - * - * @param items the array of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - - if (items.length == 0) { - removeAll(); - return; - } - - /* AW - int index = 0; - int [] table = new int [items.length]; - String codePage = getCodePage (); - while (index < items.length) { - String string = items [index]; - if (string == null) break; - byte [] buffer = Converter.wcsToMbcs (codePage, 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); - */ - - if (menuHandle != 0) { - for (int i= 0; i < items.length; i++) { - String string= items[i]; - if (string == null) - break; - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - if (OS.AppendMenuItemTextWithCFString(menuHandle, sHandle, 0, fgCommandID++, null) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - } - OS.SetControl32BitMaximum(handle, items.length); - } else { - removeAll(); - for (int i= 0; i < items.length; i++) { - String string= items[i]; - if (string == null) - break; - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - if (OS.HIComboBoxAppendTextItem(handle, sHandle, null) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - } - } -} -/** - * Sets the selection in the receiver's text field to the - * range specified by the argument whose x coordinate is the - * start of the selection and whose y coordinate is the end - * of the selection. - * - * @param a point representing the new selection start and end - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (Point selection) { - checkWidget(); - if (menuHandle == 0) { - short[] s= new short[] { (short)selection.x, (short)selection.y }; - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, s.length*2, s); - } -} -/** -* Sets the widget size. -*/ -public void setSize (int width, int height) { - checkWidget(); - int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight () : height; - super.setSize (width, newHeight); -} -/** - * Sets the contents of the receiver's text field to the - * given string. - * <p> - * Note: The text field in a <code>Combo</code> is typically - * only capable of displaying a single line of text. Thus, - * setting the text to a string containing line breaks or - * other special characters will probably cause it to - * display incorrectly. - * </p> - * - * @param text the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - - int index= indexOf (string); - if (index != -1) { - select(index); - } else { - if ((style & SWT.READ_ONLY) == 0) { - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, new int[]{sHandle}); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - sendEvent(SWT.Modify); - } - } -} -/** - * Sets the maximum number of characters that the receiver's - * text field is capable of holding to be the argument. - * - * @param limit new text limit - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - textLimit= limit; -} - -//////////////////////////////////////////////////////// -// Mac stuff -//////////////////////////////////////////////////////// - - private void _setText (String string) { - if ((style & SWT.READ_ONLY) == 0) { - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(string); - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, new int[]{sHandle}); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - sendEvent(SWT.Modify); - } - } - - private int _getItemCount () { - if (menuHandle != 0) - return OS.CountMenuItems(menuHandle); - return OS.HIComboBoxGetItemCount(handle); - } - - private String _getItem (int index) { - int itemCount= _getItemCount(); - if (!(0 <= index && index < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - int[] sHandle= new int[1]; - int rc; - if (menuHandle != 0) - rc= OS.CopyMenuItemTextAsCFString(menuHandle, (short)(index+1), sHandle); - else - rc= OS.HIComboBoxCopyTextItemAtIndex(handle, index, sHandle); - if (rc != OS.noErr) - error(SWT.ERROR_CANNOT_GET_ITEM); - return MacUtil.getStringAndRelease(sHandle[0]); - } - - /** - * Overridden from Control. - * x and y are relative to window! - */ - void handleResize(int hndl, Rect bounds) { - bounds.left+= FOCUS_BORDER; - bounds.top+= FOCUS_BORDER; - bounds.right-= FOCUS_BORDER; - bounds.bottom-= FOCUS_BORDER; - super.handleResize(hndl, bounds); - } - - void internalGetControlBounds(int hndl, Rect bounds) { - super.internalGetControlBounds(hndl, bounds); - bounds.left+= -FOCUS_BORDER; - bounds.top+= -FOCUS_BORDER; - bounds.right-= -FOCUS_BORDER; - bounds.bottom-= -FOCUS_BORDER; - } - - private void _selectAll() { - String s= getText(); - short[] selection= new short[] { 0, (short) s.length() }; - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, selection.length*2, selection); - } - - int sendKeyEvent (int type, MacEvent mEvent, Event event) { - - /* AW: other platforms call super - LRESULT result = super.WM_CHAR (wParam, lParam); - if (result != null) return result; - */ - -// if (translateTraversal(mEvent)) -// return 0; - - int kind= mEvent.getKind(); - int mcc= mEvent.getMacCharCodes(); - int code= mEvent.getKeyCode(); - - // return key -> DefaultSelection - if (mcc == SWT.CR) { - if (kind == OS.kEventRawKeyDown) - postEvent (SWT.DefaultSelection); - return OS.noErr; - } - - if ((mEvent.getModifiers() & OS.cmdKey) != 0) { - switch (code) { - case 0: // select all - if (kind == OS.kEventRawKeyDown) - _selectAll(); - return OS.noErr; - case 7: - if (kind == OS.kEventRawKeyDown) - cut(); - return OS.noErr; - case 8: - if (kind == OS.kEventRawKeyDown) - copy(); - return OS.noErr; - case 9: - if (kind == OS.kEventRawKeyDown || kind == OS.kEventRawKeyRepeat) - paste(); - return OS.noErr; - default: - break; - } - } - - String oldText= getText(); - - int status= OS.CallNextEventHandler(mEvent.getNextHandler(), mEvent.getEventRef()); - - if (kind == OS.kEventRawKeyDown) { - String newText= getText(); - if (!oldText.equals(newText)) - sendEvent (SWT.Modify); - } - - return status; - } - - private void selectionToClipboard() { - short[] s= new short[2]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, s.length*2, s, null); - if (s[0] != s[1]) { - int[] t= new int[1]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, t.length*4, t, null); - String txt= MacUtil.getStringAndRelease(t[0]); - txt= txt.substring(s[0], s[1]); - - Clipboard clipboard= new Clipboard(getDisplay()); - clipboard.setContents(new Object[] { txt }, new Transfer[]{ TextTransfer.getInstance() }); - clipboard.dispose(); - } - } - - /** - * Replace current text selection with given string. - * If selection is empty, inserts string. - * If string is empty, selection is deleted. - */ - private void _replaceTextSelection(String newText) { - - short[] s= new short[2]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, s.length*2, s, null); - - boolean selEmpty= s[0] == s[1]; - if (newText.length() == 0 && selEmpty) - return; - - int[] t= new int[1]; - OS.GetControlData(handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, t.length*4, t, null); - String txt= MacUtil.getStringAndRelease(t[0]); - - String pre= ""; - if (selEmpty) - pre= txt.substring(0, s[0]); - else if (s[0] > 0) - pre= txt.substring(0, s[0]-1); - - String post= txt.substring(s[1]); - - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(pre + newText + post); - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, new int[]{sHandle}); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - - s[0]= s[1]= (short)(pre.length() + newText.length()); - OS.SetControlData(handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, s.length*2, s); - - sendEvent(SWT.Modify); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java deleted file mode 100644 index 550149b437..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java +++ /dev/null @@ -1,209 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.internal.carbon.*; -import org.eclipse.swt.*; - -/** - * Instances of this class allow the user to navigate - * the file system and select a directory. - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class DirectoryDialog extends Dialog { - String filterPath = ""; - String message = ""; -/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public DirectoryDialog (Shell parent) { - this (parent, SWT.PRIMARY_MODAL); -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public DirectoryDialog (Shell parent, int style) { - super (parent, style); - checkSubclass (); -} -/** - * Returns the path which the dialog will use to filter - * the directories it shows. - * - * @return the filter path - */ -public String getFilterPath () { - return filterPath; -} -/** - * Returns the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @return the message - */ -public String getMessage () { - return message; -} -private String interpretOsAnswer(int dialog) { - String result= null; - NavReplyRecord record= new NavReplyRecord(); - OS.NavDialogGetReply(dialog, record); - AEDesc selection= new AEDesc(); - selection.descriptorType= record.selection_descriptorType; - selection.dataHandle= record.selection_dataHandle; - int[] count= new int[1]; - OS.AECountItems(selection, count); - - if (count[0] > 0) { - int[] theAEKeyword = new int[1]; - int[] typeCode = new int[1]; - int maximumSize = 80; // size of FSRef - int dataPtr = OS.NewPtr(maximumSize); - int[] actualSize = new int[1]; - int status = OS.AEGetNthPtr(selection, 1, OS.typeFSRef, theAEKeyword, typeCode, dataPtr, maximumSize, actualSize); - if (status == OS.noErr && typeCode[0] == OS.typeFSRef) { - byte[] fsRef = new byte[actualSize[0]]; - OS.memcpy(fsRef, dataPtr, actualSize[0]); - int anURL= OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault, fsRef); - int shandle= OS.CFURLCopyFileSystemPath(anURL, OS.kCFURLPOSIXPathStyle); - result= MacUtil.getStringAndRelease(shandle); - } - OS.DisposePtr(dataPtr); - } - return result; -} -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a string describing the absolute path of the selected directory, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public String open () { - int dialog= 0; - int titleHandle= 0; - int messageHandle= 0; - try { - int[] dialogHandle= new int[1]; - - int parentWindowHandle= 0; - if (parent != null) - parentWindowHandle= parent.shellHandle; - - titleHandle= OS.CFStringCreateWithCharacters(title); - messageHandle= OS.CFStringCreateWithCharacters(message); - - NavDialogCreationOptions options = new NavDialogCreationOptions(); - OS.NavGetDefaultDialogCreationOptions(options); - options.parentWindow= parentWindowHandle; - options.windowTitle= titleHandle; - options.message= messageHandle; - OS.NavCreateChooseFolderDialog(options, 0, 0, 0, dialogHandle); - dialog= dialogHandle[0]; - - if (dialog != 0) { - - OS.NavDialogRun(dialog); - - switch (OS.NavDialogGetUserAction(dialog)) { - case OS.kNavUserActionCancel: - break; - - case OS.kNavUserActionOpen: - case OS.kNavUserActionChoose: - return interpretOsAnswer(dialog); - } - } - - return null; - - } finally { - if (titleHandle != 0) - OS.CFRelease(titleHandle); - if (messageHandle != 0) - OS.CFRelease(messageHandle); - if (dialog != 0) - OS.NavDialogDispose(dialog); - } -} -/** - * Sets the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @param string the message - */ -public void setMessage (String string) { - message = string; -} -/** - * Sets the path which the dialog will use to filter - * the directories it shows to the argument, which may be - * null. - * - * @param string the filter path - */ -public void setFilterPath (String string) { - filterPath = string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java deleted file mode 100644 index 8b95a15f23..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java +++ /dev/null @@ -1,400 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.carbon.*; -import org.eclipse.swt.internal.Callback; - -/** - * Instances of this class allow the user to navigate - * the file system and select or enter a file name. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SAVE, OPEN, MULTI</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class FileDialog extends Dialog { - String [] filterNames = new String [0]; - String [] filterExtensions = new String [0]; - String filterPath = ""; - String [] fileNames = new String[] { "" }; - static final String FILTER = "*"; - -/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FileDialog (Shell parent) { - this (parent, SWT.PRIMARY_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FileDialog (Shell parent, int style) { - super (parent, style); -} - -/** - * Returns the path of the first file that was - * selected in the dialog relative to the filter path, - * or empty string if the dialog was cancelled. - * - * @return the relative path of the file - */ -public String getFileName () { - if (fileNames.length > 0) - return fileNames[0]; - return ""; -} - -/** - * Returns the paths of all files that were selected - * in the dialog relative to the filter path, or null - * if none are available. - * - * @return the relative paths of the files - */ -public String [] getFileNames () { - return fileNames; -} - -/** - * Returns the file extensions which the dialog will - * use to filter the files it shows. - * - * @return the file extensions filter - */ -public String [] getFilterExtensions () { - return filterExtensions; -} - -/** - * Returns the file names which the dialog will - * use to filter the files it shows. - * - * @return the file name filter - */ -public String [] getFilterNames () { - return filterNames; -} -/** - * Returns the path which the dialog will use to filter - * the directories it shows. - * - * @return the filter path - */ -public String getFilterPath () { - return filterPath; -} -private String interpretOsAnswer(int dialog) { - String separator= System.getProperty ("file.separator"); - String firstResult= null; - - NavReplyRecord record= new NavReplyRecord(); - OS.NavDialogGetReply(dialog, record); - AEDesc selection= new AEDesc(); - selection.descriptorType= record.selection_descriptorType; - selection.dataHandle= record.selection_dataHandle; - int[] theCount = new int[1]; - OS.AECountItems(selection, theCount); - int count= theCount[0]; - - String commonPath= null; - if (count == 0) { - fileNames= null; - } else { - fileNames= new String[count]; - int maximumSize = 80; // size of FSRef - int dataPtr= OS.NewPtr(maximumSize); - for (int i= 0; i < count; i++) { - int[] aeKeyword= new int[1]; - int[] typeCode= new int[1]; - int[] actualSize= new int[1]; - int status= OS.AEGetNthPtr(selection, i+1, OS.typeFSRef, aeKeyword, typeCode, dataPtr, maximumSize, actualSize); - if (status == OS.noErr && typeCode[0] == OS.typeFSRef) { - byte[] fsRef= new byte[actualSize[0]]; - OS.memcpy(fsRef, dataPtr, actualSize[0]); - int url= OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault, fsRef); - int shandle= OS.CFURLCopyFileSystemPath(url, OS.kCFURLPOSIXPathStyle); - String fullPath= MacUtil.getStringAndRelease(shandle); - if (firstResult == null) - firstResult= fullPath; - if (fullPath != null && fullPath.length() > 0) { - String fileName= null; - int separatorIndex= fullPath.lastIndexOf(separator); - if (separatorIndex >= 0) { - fileName= fullPath.substring(separatorIndex+separator.length()); - String fp= fullPath.substring(0, separatorIndex); - if (commonPath == null) - commonPath= fp; // remember common filterPath - else { - if (!commonPath.equals(fp)) // verify that filterPath is in fact common - System.out.println("FileDialog.getPaths: mismatch in filterPaths"); - } - } else { - fileName= fullPath; - } - fileNames[i]= fileName; - } - } - } - OS.DisposePtr(dataPtr); - } - - filterPath= (commonPath != null) ? commonPath : ""; - - return firstResult; -} -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a string describing the absolute path of the first selected file, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public String open () { - - String separator= System.getProperty("file.separator"); - int dialog= 0; - String result= null; - Callback eventCallback= null; - Callback filterCallback= null; - - int titleHandle= 0; - try { - int parentWindowHandle= 0; - if (parent != null) - parentWindowHandle= parent.shellHandle; - - titleHandle= OS.CFStringCreateWithCharacters(title); - - int status= 0; - int flags= 0; - int[] dialogHandle= new int[1]; - - NavDialogCreationOptions options = new NavDialogCreationOptions(); - OS.NavGetDefaultDialogCreationOptions(options); - options.optionFlags |= flags; - options.windowTitle= titleHandle; - options.parentWindow= parentWindowHandle; - if ((style & SWT.SAVE) != 0) { - status= OS.NavCreatePutFileDialog(options, MacUtil.OSType("TEXT"), - MacUtil.OSType("KAHL"), 0, 0, dialogHandle); - } else /* if ((style & SWT.OPEN) != 0) */ { - - eventCallback= new Callback(this, "eventProc", 3); - int eventProc= eventCallback.getAddress(); - if (eventProc == 0) - error (SWT.ERROR_NO_MORE_CALLBACKS); - - filterCallback= new Callback(this, "filterProc", 4); - int filterProc= filterCallback.getAddress(); - if (filterProc == 0) - error (SWT.ERROR_NO_MORE_CALLBACKS); - - if ((style & SWT.MULTI) != 0) - options.optionFlags |= OS.kNavAllowMultipleFiles; - options.optionFlags |= OS.kNavSupportPackages; - options.optionFlags |= OS.kNavAllowOpenPackages; - options.optionFlags |= OS.kNavAllowInvisibleFiles; - status= OS.NavCreateGetFileDialog(options, 0/*titleHandle*/, eventProc, 0, filterProc, 12345, dialogHandle); - } - - if (status == 0) { - dialog= dialogHandle[0]; - } else { - //System.out.println("FileDialog.open: status " + status); - } - - if (dialog != 0) { - //System.out.println("FileDialog.open: got dialog"); - - if ((style & SWT.SAVE) != 0) { - String directoryName; - String fileName; - String pathName= fileNames[0]; - if (pathName == null) - pathName= ""; - // if fileName is a path, separate directory from filename - int separatorIndex= pathName.lastIndexOf(separator); - if (separatorIndex >= 0) { - fileName= pathName.substring(separatorIndex+separator.length()); - directoryName= pathName.substring(0, separatorIndex); - } else { - fileName= pathName; - directoryName= null; - } - - int fileNameHandle= 0; - try { - fileNameHandle= OS.CFStringCreateWithCharacters(fileNames[0]); - OS.NavDialogSetSaveFileName(dialog, fileNameHandle); - } finally { - if (fileNameHandle != 0) - OS.CFRelease(fileNameHandle); - } - } - - //System.out.println("FileDialog.open: vor run"); - OS.NavDialogRun(dialog); - //System.out.println("FileDialog.open: nach run"); - - int action= OS.NavDialogGetUserAction(dialog); - switch (action) { - case OS.kNavUserActionCancel: - break; - - case OS.kNavUserActionOpen: - case OS.kNavUserActionChoose: - result= interpretOsAnswer(dialog); - break; - - case OS.kNavUserActionSaveAs: - String directory= interpretOsAnswer(dialog); - String file= MacUtil.getStringAndRelease(OS.NavDialogGetSaveFileName(dialog)); - result= directory + separator + file; - break; - } - } else { - //System.out.println("FileDialog.open: dialog == null"); - } - - } finally { - if (titleHandle != 0) - OS.CFRelease(titleHandle); - if (dialog != 0) - OS.NavDialogDispose(dialog); - } - - if (eventCallback != null) - eventCallback.dispose(); - if (filterCallback != null) - filterCallback.dispose(); - return result; -} - -private int eventProc(int selector, int params, int callBackUD) { - //System.out.println("FileDialog.eventProc: selector: " + selector); - switch (selector) { - case OS.kNavCBNewLocation: - // NavCustomControl() - break; - default: - break; - } - return 0; -} - -private int filterProc(int theItem, int info, int callBackUD, int filterMode) { - /* AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode */ - //System.out.println("FileDialog.filterProc: UD: " + callBackUD); - return 1; -} - -/** - * Set the initial filename which the dialog will - * select by default when opened to the argument, - * which may be null. The name will be prefixed with - * the filter path when one is supplied. - * - * @param string the file name - */ -public void setFileName (String string) { - fileNames = new String[] { string }; -} - -/** - * Set the file extensions which the dialog will - * use to filter the files it shows to the argument, - * which may be null. - * - * @param extensions the file extension filter - */ -public void setFilterExtensions (String [] extensions) { - filterExtensions = extensions; -} - -/** - * Sets the file names which the dialog will - * use to filter the files it shows to the argument, - * which may be null. - * - * @param names the file name filter - */ -public void setFilterNames (String [] names) { - filterNames = names; -} -/** - * Sets the path which the dialog will use to filter - * the directories it shows to the argument, which may be - * null. - * - * @param string the filter path - */ -public void setFilterPath (String string) { - filterPath = string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java deleted file mode 100644 index ae8c91cdfd..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java +++ /dev/null @@ -1,943 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; - -import java.util.*; - -/** - * Instances of this class allow the user to select a font - * from all available fonts in the system. - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class FontDialog extends Dialog { - /* - * Table containing all available fonts as FontData objects. - * The table is structured as a series of embedded Hashtables as follows: - * <br>characterRegistryName -> faceName -> extendedStyle -> size -> style - */ - private Hashtable characterSets = new Hashtable (); - private FontData initialFontData; - private Font sampleFont; // the current displayed sample font - private boolean okSelected = false; - private boolean ignoreEvents = false; - - // widgets - private Shell shell; - private Combo charSetCombo; - private Combo faceNameCombo; - private Combo fontSizeCombo; - private Combo fontStyleCombo; - private Combo extStyleCombo; - private Label sampleLabel; - private Button okButton; - private Button cancelButton; - - // constants - private static final String TEXT_SAMPLE = "AaBbYyZz"; - private static final String SCALABLE_SIZES[] = new String[] {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"}; - private static final int DEFAULT_SIZE = 14; - private static final String DEFAULT_STYLE = "medium"; - private static final Integer SCALABLE_KEY = new Integer (0); - private static final Integer NO_SELECTION = new Integer (-1); - private static final int COLUMN1_WIDTH = 200; - private static final int COLUMN2_WIDTH = 150; - private static final int COLUMN3_WIDTH = 100; - private static final String PREFIX_ISO8859 = "iso8859"; - private static final String PREFIX_ISO646 = "iso646"; - private static final String PREFIX_UNICODE = "ucs"; - private static final String PREFIX_JAPANESE = "jis"; - private static final String PREFIX_SIMPLIFIEDCHINESE = "gb"; - private static final String PREFIX_TRADITIONALCHINESE = "cns"; - private static final String PREFIX_KOREAN = "ks"; - private static final String [] ISO_CHARSETS = new String [] { - "", // undefined - SWT.getMessage ("SWT_Charset_Western"), - SWT.getMessage ("SWT_Charset_EastEuropean"), - SWT.getMessage ("SWT_Charset_SouthEuropean"), - SWT.getMessage ("SWT_Charset_NorthEuropean"), - SWT.getMessage ("SWT_Charset_Cyrillic"), - SWT.getMessage ("SWT_Charset_Arabic"), - SWT.getMessage ("SWT_Charset_Greek"), - SWT.getMessage ("SWT_Charset_Hebrew"), - SWT.getMessage ("SWT_Charset_Turkish"), - SWT.getMessage ("SWT_Charset_Nordic"), - SWT.getMessage ("SWT_Charset_Thai"), - "", // undefined - SWT.getMessage ("SWT_Charset_BalticRim"), - SWT.getMessage ("SWT_Charset_Celtic"), - SWT.getMessage ("SWT_Charset_Euro") - }; - - RGB rgb; -/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FontDialog (Shell parent) { - this (parent, SWT.NONE); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FontDialog (Shell parent, int style) { - super (parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); - checkSubclass (); -} - -/** - * 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[]) { - - for (int i = 0; i < fonts.length; i++) { - FontData font = fonts [i]; - - String charSetName = getTranslatedCharSet (font); - Hashtable charSet = (Hashtable) characterSets.get (charSetName); - if (charSet == null) { - charSet = new Hashtable (9); - characterSets.put (charSetName, charSet); - } - - String faceName = getTranslatedFaceName (font); - Hashtable faceSet = (Hashtable) charSet.get (faceName); - if (faceSet == null) { - faceSet = new Hashtable (9); - charSet.put (faceName, faceSet); - } - - String extStyleName = font.addStyle; - Hashtable extStyleSet = (Hashtable) faceSet.get (extStyleName); - if (extStyleSet == null) { - extStyleSet = new Hashtable (9); - faceSet.put (extStyleName, extStyleSet); - } - - Integer sizeValue = new Integer (font.getHeight ()); - Hashtable sizeSet = (Hashtable) extStyleSet.get (sizeValue); - if (sizeSet == null) { - sizeSet = new Hashtable (9); - extStyleSet.put (sizeValue, sizeSet); - } - - String style = font.weight; - sizeSet.put (style,font); - } -} - -/** - * Create the widgets of the dialog. - */ -void createChildren () { - Label characterSetLabel = new Label (shell, SWT.NONE); - Label faceNameLabel = new Label (shell, SWT.NONE); - Label extendedStyleLabel = new Label (shell, SWT.NONE); - GridLayout layout = new GridLayout (); - - layout.numColumns = 4; - layout.marginWidth = 15; - layout.marginHeight = 15; - layout.horizontalSpacing = 10; - layout.verticalSpacing = 2; - shell.setLayout (layout); - - // row one - characterSetLabel.setText (SWT.getMessage ("SWT_Character_set") + ":"); - faceNameLabel.setText (SWT.getMessage ("SWT_Font") + ":"); - extendedStyleLabel.setText (SWT.getMessage ("SWT_Extended_style") + ":"); - - new Label (shell, SWT.NONE); - - // row two - charSetCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); - GridData gridData = new GridData (); - gridData.widthHint = COLUMN1_WIDTH; - gridData.heightHint = 150; - gridData.verticalSpan = 2; - charSetCombo.setLayoutData (gridData); - charSetCombo.setData (NO_SELECTION); - - faceNameCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); - gridData = new GridData (); - gridData.widthHint = COLUMN2_WIDTH; - gridData.heightHint = 150; - gridData.verticalSpan = 2; - gridData.verticalAlignment = GridData.FILL; - faceNameCombo.setLayoutData (gridData); - faceNameCombo.setData (NO_SELECTION); - - extStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); - gridData = new GridData (); - gridData.widthHint = COLUMN3_WIDTH; - gridData.heightHint = 150; - gridData.verticalSpan = 2; - gridData.verticalAlignment = GridData.FILL; - extStyleCombo.setLayoutData (gridData); - extStyleCombo.setData (NO_SELECTION); - - // create ok and cancel buttons (row two and three) - createOkCancel (); - - // row four - createEmptyRow (); - - // row five - Label fontSizeLabel = new Label (shell, SWT.NONE); - fontSizeLabel.setText (SWT.getMessage ("SWT_Size") + ":"); - Label fontStyleLabel = new Label (shell, SWT.NONE); - fontStyleLabel.setText (SWT.getMessage ("SWT_Style") + ":"); - - Label fillLabel = new Label (shell, SWT.NONE); - gridData = new GridData (); - gridData.horizontalSpan = 2; - fillLabel.setLayoutData (gridData); - - // row six - fontSizeCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); - gridData = new GridData (); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.heightHint = 110; - fontSizeCombo.setLayoutData (gridData); - fontSizeCombo.setData (NO_SELECTION); - - fontStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); - gridData = new GridData (); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - fontStyleCombo.setLayoutData (gridData); - fontStyleCombo.setData (NO_SELECTION); - - fillLabel = new Label (shell, SWT.NONE); - gridData = new GridData (); - gridData.horizontalSpan = 2; - fillLabel.setLayoutData (gridData); - - // row seven - createEmptyRow (); - - // row eight - Group sampleGroup = new Group (shell, SWT.NONE); - sampleGroup.setText (SWT.getMessage ("SWT_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); - shell.setSize (445, 410); -} - -/** - * 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 () { - Label fillLabel = new Label (shell, SWT.NONE); - GridData gridData = new GridData (); - - gridData.heightHint = 5; - gridData.horizontalSpan = ((GridLayout) shell.getLayout ()).numColumns; - fillLabel.setLayoutData (gridData); -} - -/** - * Create the widgets of the dialog. - */ -void createOkCancel () { - okButton = new Button (shell, SWT.PUSH); - okButton.setText (SWT.getMessage ("SWT_OK")); - shell.setDefaultButton (okButton); - GridData gridData = new GridData (); - gridData.horizontalAlignment = GridData.FILL; - gridData.widthHint = 70; - okButton.setLayoutData (gridData); - - cancelButton = new Button (shell, SWT.PUSH); - cancelButton.setText (SWT.getMessage ("SWT_Cancel")); - gridData = new GridData (); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - cancelButton.setLayoutData (gridData); -} - -Hashtable getExtStyles (String charsetName, String faceName) { - Hashtable faces = getFaces (charsetName); - if (faces == null) return null; - return (Hashtable) faces.get (faceName); -} - -Hashtable getFaces (String charsetName) { - return (Hashtable) getFonts ().get (charsetName); -} - -/** - * Returns a FontData object describing the font that was - * selected in the dialog, or null if none is available. - * - * @return the FontData for the selected font, or null - */ -public FontData getFontData () { - if (sampleFont != null) { - return sampleFont.getFontData ()[0]; - } - return initialFontData; -} - -FontData getFontData (String charsetName, String faceName, String extStyle, int size, String style) { - Hashtable styles = getStyles (charsetName, faceName, extStyle, size); - if (styles == null) return null; - return (FontData) styles.get (style); -} - -/** - * Returns 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; -} - -/** - * Returns the currently selected color in the receiver. - * - * @return the RGB value for the selected color, may be null - * - * @see PaletteData#getRGBs - */ -public RGB getRGB () { - return rgb; -} - -/** - * Returns a FontData object that can be used to load the selected - * font. - */ -FontData getSelectionFontData () { - String charSetName = charSetCombo.getText (); - String faceName = faceNameCombo.getText (); - String extStyle = extStyleCombo.getText (); - int size = DEFAULT_SIZE; - try { - size = Integer.valueOf (fontSizeCombo.getText ()).intValue (); - } catch (NumberFormatException e) { - /* - * This block is purposely left empty since a default - * value is already specified above. - */ - } - String style = fontStyleCombo.getText (); - FontData result = getFontData (charSetName, faceName, extStyle, size, style); - - if (result == null) { - /* - * One or more of the dialog's widgets contain custom typed values. - * Create a FontData that mirrors these values so that the Font created - * below will try to find the best match. - */ - result = new FontData (); - result.characterSetRegistry = charSetName; - result.setName(faceName); - result.addStyle = extStyle; - result.weight = style; - } - result.setHeight (size); - return result; -} - -Hashtable getSizes (String charsetName, String faceName, String extStyle) { - Hashtable extStyles = getExtStyles (charsetName, faceName); - if (extStyles == null) return null; - return (Hashtable) extStyles.get (extStyle); -} - -Hashtable getStyles (String charsetName, String faceName, String extStyle, int size) { - Hashtable sizes = getSizes (charsetName, faceName, extStyle); - if (sizes == null) return null; - Hashtable result = (Hashtable) sizes.get (new Integer (size)); - if (result == null) - result = (Hashtable) sizes.get (SCALABLE_KEY); - return result; -} - -/** - * Returns 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 (PREFIX_ISO8859)) { - int charSetName = 1; - try { - charSetName = Integer.valueOf (fontData.characterSetName).intValue (); - } catch (NumberFormatException e) { - /* - * This block is purposely left empty since a default - * value is already specified above. - */ - } - - characterSet += "-" + charSetName; - translatedCharSet = ISO_CHARSETS [charSetName]; - } - else - if (characterSet.startsWith (PREFIX_ISO646)) { - translatedCharSet = SWT.getMessage("SWT_Charset_ASCII"); - } - else - if (characterSet.startsWith (PREFIX_UNICODE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Unicode"); - } - else - if (characterSet.startsWith (PREFIX_JAPANESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Japanese"); - } - else - if (characterSet.startsWith (PREFIX_SIMPLIFIEDCHINESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_SimplifiedChinese"); - } - else - if (characterSet.startsWith (PREFIX_TRADITIONALCHINESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_TraditionalChinese"); - } - else - if (characterSet.startsWith (PREFIX_KOREAN)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Korean"); - } - if (translatedCharSet != null) { - translatedCharSet += " (" + characterSet + ')'; - } - else { - translatedCharSet = characterSet; - } - return translatedCharSet; -} - -/** - * Returns 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 handleEvent (Event event) { - if (ignoreEvents) return; - if (event.widget instanceof Combo) { - Combo combo = (Combo) event.widget; - int prevSelectIndex = ((Integer) combo.getData ()).intValue (); - String text = combo.getText (); - int newSelectIndex = combo.indexOf (text); - if (prevSelectIndex != newSelectIndex || newSelectIndex == -1) { - ignoreEvents = true; - combo.setData (new Integer (newSelectIndex)); - if (combo == charSetCombo) initFaceNameCombo (); - else if (combo == faceNameCombo) initExtStyleCombo (); - else if (combo == extStyleCombo) initSizeCombo (); - else if (combo == fontSizeCombo) initStyleCombo (); - updateSampleFont (); - if (newSelectIndex != -1) { - // in case it came by typing the name - combo.select (newSelectIndex); - } - ignoreEvents = false; - } - } - else - if (event.widget == okButton) { - okSelected = true; - shell.close (); - } - else - if (event.widget == cancelButton) { - okSelected = false; - shell.close (); - } -} - -/** - * 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 oldSelect = extStyleCombo.getText (); - extStyleCombo.removeAll (); - - String characterSet = charSetCombo.getText (); - String faceName = faceNameCombo.getText (); - Hashtable extStyles = getExtStyles (characterSet, faceName); - if (extStyles == null) return; - setItemsSorted (extStyleCombo, extStyles); - - int selectIndex = extStyleCombo.indexOf (oldSelect); - selectIndex = Math.max (0, selectIndex); - extStyleCombo.select (selectIndex); - extStyleCombo.setData (new Integer (selectIndex)); - initSizeCombo (); -} - -/** - * 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 () { - String oldSelect = faceNameCombo.getText (); - faceNameCombo.removeAll (); - - Hashtable faceNames = getFaces (charSetCombo.getText ()); - setItemsSorted (faceNameCombo, faceNames); - - int selectIndex = faceNameCombo.indexOf (oldSelect); - selectIndex = Math.max (0, selectIndex); - faceNameCombo.select (selectIndex); - faceNameCombo.setData (new Integer (selectIndex)); - initExtStyleCombo (); -} - -/** - * 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 () { - Display display = shell.getDisplay (); - addFonts (display.getFontList (null, false)); // get all fonts availabe on the current display - addFonts (display.getFontList (null, true)); - setItemsSorted (charSetCombo, getFonts ()); - if (initialFontData != null) { - Font initialFont = new Font (display, initialFontData); // verify that the initial font data is a valid font - initialFontData = null; - ignoreEvents = true; - setFontCombos (initialFont.getFontData ()[0]); - ignoreEvents = false; - initialFont.dispose (); - updateSampleFont (); - } -} - -/** - * 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 () { - String oldSelect = fontSizeCombo.getText (); - fontSizeCombo.removeAll (); - - String characterSet = charSetCombo.getText (); - String faceName = faceNameCombo.getText (); - String extStyle = extStyleCombo.getText (); - Hashtable sizes = getSizes (characterSet, faceName, extStyle); - if (sizes == null) return; - if (sizes.get (SCALABLE_KEY) == null) { - /* - * Font is not scalable so just present the provided sizes. - */ - setSizeItemsSorted (sizes.keys ()); - } else { - /* - * Font is scalable so present the provided sizes and scalable - * sizes for selection. - */ - Vector allSizes = new Vector (); - /* - * Add the scalable sizes. - */ - for (int i = 0; i < SCALABLE_SIZES.length; i++) { - allSizes.addElement (new Integer (SCALABLE_SIZES [i])); - } - /* - * Add the provided sizes. - */ - Enumeration providedSizes = sizes.keys (); - while (providedSizes.hasMoreElements ()) { - Integer size = (Integer) providedSizes.nextElement (); - if (!size.equals (SCALABLE_KEY) && !allSizes.contains (size)) { - allSizes.addElement (size); - } - } - setSizeItemsSorted (allSizes.elements ()); - } - - int selectIndex = fontSizeCombo.indexOf (oldSelect); - if (selectIndex == -1) { - selectIndex = fontSizeCombo.indexOf (String.valueOf (DEFAULT_SIZE)); - } - selectIndex = Math.max (0, selectIndex); - fontSizeCombo.select (selectIndex); - fontSizeCombo.setData (new Integer (selectIndex)); - initStyleCombo (); -} - -/** - * Initialize the styles combo with the styles the selected font - * is available in. - */ -void initStyleCombo () { - String oldSelect = fontStyleCombo.getText (); - fontStyleCombo.removeAll (); - - String characterSet = charSetCombo.getText (); - String faceName = faceNameCombo.getText (); - String extStyle = extStyleCombo.getText (); - int size = DEFAULT_SIZE; - try { - size = Integer.valueOf (fontSizeCombo.getText ()).intValue (); - } catch (NumberFormatException e) { - /* - * This block is purposely left empty since a default - * value is already specified above. - */ - } - Hashtable styles = getStyles (characterSet, faceName, extStyle, size); - if (styles == null) return; - setItemsSorted (fontStyleCombo, styles); - - int selectIndex = fontStyleCombo.indexOf (oldSelect); - if (selectIndex == -1) { - selectIndex = fontStyleCombo.indexOf (String.valueOf (DEFAULT_STYLE)); - } - selectIndex = Math.max (0, selectIndex); - fontStyleCombo.select (selectIndex); - fontStyleCombo.setData (new Integer (selectIndex)); - fontStyleCombo.select (Math.max (0, selectIndex)); -} - -/** - * Register the receiver to receive events. - */ -void installListeners () { - Listener listener = new Listener () { - public void handleEvent (Event event) { - FontDialog.this.handleEvent (event); - } - }; - okButton.addListener (SWT.Selection, listener); - cancelButton.addListener (SWT.Selection, listener); - charSetCombo.addListener (SWT.Selection, listener); - charSetCombo.addListener (SWT.Modify, listener); - faceNameCombo.addListener (SWT.Modify, listener); - fontStyleCombo.addListener (SWT.Modify, listener); - extStyleCombo.addListener (SWT.Modify, listener); - fontSizeCombo.addListener (SWT.Modify, listener); -} - -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a FontData object describing the font that was selected, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public FontData open () { - shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); - createChildren (); - installListeners (); - - initializeWidgets (); - setFontData (null); - openDialog (); - Display display = shell.getDisplay (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - - FontData result = null; - if (okSelected) result = getFontData (); - if (sampleFont != null) sampleFont.dispose (); - return result; -} - -/** - * Open the receiver and set its size to the size calculated by - * the layout manager. - */ -void openDialog () { - // Start everything off by setting the shell size to its computed size. - Point pt = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false); - - // Ensure that the width of the shell fits the display. - Rectangle displayRect = shell.getDisplay().getBounds(); - int widthLimit = displayRect.width * 7 / 8; - int heightLimit = displayRect.height * 7 / 8; - if (pt.x > widthLimit) { - pt = shell.computeSize (widthLimit, SWT.DEFAULT, false); - } - - // centre the dialog on its parent, and ensure that the - // whole dialog appears within the screen bounds - Rectangle parentBounds = getParent ().getBounds (); - int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x; - originX = Math.max (originX, 0); - originX = Math.min (originX, widthLimit - pt.x); - int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y; - originY = Math.max (originY, 0); - originY = Math.min (originY, heightLimit - pt.y); - shell.setBounds (originX, originY, pt.x, pt.y); - - String title = getText (); - if (title.length () == 0) title = SWT.getMessage ("SWT_FontDialog_Title"); - shell.setText(title); - - // Open the window. - shell.open(); -} - -/** - * 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); - charSetCombo.setText (characterSet); - charSetCombo.setData (new Integer (charSetCombo.indexOf (characterSet))); - - initFaceNameCombo (); - faceNameCombo.setText (faceName); - faceNameCombo.setData (new Integer (faceNameCombo.indexOf (faceName))); - - initExtStyleCombo (); - extStyleCombo.setText (fontData.addStyle); - extStyleCombo.setData (new Integer (extStyleCombo.indexOf (fontData.addStyle))); - - initSizeCombo (); - String value = String.valueOf (fontData.getHeight ()); - fontSizeCombo.setText (value); - fontSizeCombo.setData (new Integer (fontSizeCombo.indexOf (value))); - - initStyleCombo (); - fontStyleCombo.setText (fontData.weight); - fontStyleCombo.setData (new Integer (fontStyleCombo.indexOf (fontData.weight))); -} - -/** - * Sets a FontData object describing the font to be - * selected by default in the dialog, or null to let - * the platform choose one. - * - * @param fontData the FontData to use initially, or null - */ -public void setFontData (FontData fontData) { - initialFontData = fontData; -} - -/** - * Returns the receiver's selected color to be the argument. - * - * @param rgb the new RGB value for the selected color, may be - * null to let the platform to select a default when - * open() is called - * - * @see PaletteData#getRGBs - */ -public void setRGB (RGB rgb) { - this.rgb = rgb; -} - -/** - * 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 [] sortedItems = new String[items.size ()]; - int index = 0; - while (itemKeys.hasMoreElements ()) { - String item = (String) itemKeys.nextElement (); - if (item.length () != 0) sortedItems[index++] = item; - } - if (index != sortedItems.length) { - String [] newItems = new String[index]; - System.arraycopy (sortedItems, 0, newItems, 0, index); - sortedItems = newItems; - } - sort (sortedItems); - combo.setItems (sortedItems); -} - -/** - * Set the contents of the size combo to the keys of 'items'. - * Keys are sorted in ascending order first and have to be Integers. - */ -void setSizeItemsSorted (Enumeration itemsEnum) { - Vector items = new Vector (); - while (itemsEnum.hasMoreElements ()) { - items.addElement (itemsEnum.nextElement ()); - } - Integer[] sortedItems = new Integer [items.size ()]; - items.copyInto (sortedItems); - sort (sortedItems); - String[] sortedItemStrings = new String [items.size ()]; - for (int i = 0; i < sortedItemStrings.length; i++) { - sortedItemStrings [i] = String.valueOf (sortedItems [i].intValue ()); - } - fontSizeCombo.setItems (sortedItemStrings); -} - -/** - * Sort 'items' in ascending order. - */ -void sort (Integer[] 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].intValue () > items [j + gap].intValue ()) { - Integer swap = items [j]; - items[j] = items [j + gap]; - items[j + gap] = swap; - } - } - } - } -} - -/** - * Sort 'items' in ascending order. - */ -void sort (String 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].compareTo (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 updateSampleFont () { - FontData selectionFontData = getSelectionFontData (); - /* - * sampleFont may not be the same as the one specified in selectionFontData. - * This happens when selectionFontData specifies a font alias. - */ - Font newSampleFont = new Font (shell.getDisplay (), selectionFontData); - sampleLabel.setFont (newSampleFont); - if (sampleFont != null) sampleFont.dispose (); - sampleFont = newSampleFont; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java deleted file mode 100644 index 1abe22076b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java +++ /dev/null @@ -1,236 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of this class provide an etched border - * with an optional title. - * <p> - * Shadow styles are hints and may not be honoured - * by the platform. To create a group with the - * default shadow style for the platform, do not - * specify a shadow style. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the above styles may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public /*final*/ class Group extends Composite { - - private static final int LABEL_HEIGHT= 20; - private static final int MARGIN= 4; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SHADOW_ETCHED_IN - * @see SWT#SHADOW_ETCHED_OUT - * @see SWT#SHADOW_IN - * @see SWT#SHADOW_OUT - * @see SWT#SHADOW_NONE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -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) { - checkWidget(); - /* AW - 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]; - int borderWidth = getBorderWidth (); - trimX = x - marginWidth + thickness - borderWidth; - trimY = y - marginHeight + thickness - borderWidth; - trimWidth = width + ((marginWidth + thickness + borderWidth) * 2); - trimHeight = height + ((marginHeight + thickness + borderWidth) * 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 (x-MARGIN, y-LABEL_HEIGHT, width+(2*MARGIN), height+LABEL_HEIGHT+MARGIN); -} -void createHandle (int index) { - state |= HANDLE; - /* - formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - */ - /* AW - 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); - */ - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)0, (short)OS.kControlGroupBoxTextTitleProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - OS.HIViewSetVisible(handle, true); - setFont(defaultFont()); -} -Font defaultFont () { - return getDisplay ().groupFont; -} -public Rectangle getClientArea () { - checkWidget(); - /* AW - 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); - */ - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - Rectangle r= new Rectangle (MARGIN, LABEL_HEIGHT, - bounds.right-bounds.left-(2*MARGIN), bounds.bottom-bounds.top-(LABEL_HEIGHT+MARGIN)); - // never return negative values - if (r.x < 0) r.x= 0; - if (r.y < 0) r.y= 0; - if (r.width < 0) r.width= 0; - if (r.height < 0) r.height= 0; - return r; -} -/** - * Returns the receiver's text, which is the string that the - * is used as the <em>title</em>. If the text has not previously - * been set, returns an empty string. - * - * @return the text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - int[] sHandle= new int[1]; - OS.CopyControlTitleAsCFString(handle, sHandle); - return MacUtil.getStringAndRelease(sHandle[0]); -} -/* AW -boolean mnemonicHit (char key) { - return setFocus (); -} -boolean mnemonicMatch (char key) { - char mnemonic = findMnemonic (getText ()); - if (mnemonic == '\0') return false; - return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); -} -*/ -/** - * Sets the receiver's text, which is the string that will - * be displayed as the receiver's <em>title</em>, to the argument, - * which may not be null. - * - * @param text the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(MacUtil.removeMnemonics(string)); - OS.SetControlTitleWithCFString(handle, sHandle); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java deleted file mode 100644 index 316332d691..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java +++ /dev/null @@ -1,429 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of this class represent a non-selectable - * user interface object that displays a string or image. - * When SEPARATOR is specified, displays a single - * vertical or horizontal line. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd> - * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> - * <dd>CENTER, LEFT, RIGHT, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. - * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified. - * Only one of CENTER, LEFT and RIGHT may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class Label extends Control { - String text = ""; - Image image, disabled; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SEPARATOR - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see SWT#SHADOW_IN - * @see SWT#SHADOW_OUT - * @see SWT#SHADOW_NONE - * @see SWT#CENTER - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#WRAP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -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); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = 0, height = 0; - - if ((style & SWT.SEPARATOR) != 0) { - if ((style & SWT.HORIZONTAL) != 0) { - width += DEFAULT_WIDTH; - height += 3; - } else { - width += 3; - height += DEFAULT_HEIGHT; - } - } else { - if (image != null) { - Rectangle r = image.getBounds(); - width= r.width; - height= r.height; - } else { - short[] bounds= new short[2]; - short[] baseLine= new short[1]; - boolean wrap= false; - if ((style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) { - wrap= true; - bounds[1]= (short) wHint; // If we are wrapping text, calculate the height based on wHint. - } - String string= MacUtil.removeMnemonics(text); - char [] chars= new char [string.length()]; - string.getChars(0, chars.length, chars, 0); - int sHandle= OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length); - - GC gc= new GC(this); - gc.carbon_installFont(); - OS.GetThemeTextDimensions(sHandle, (short)OS.kThemeCurrentPortFont, OS.kThemeStateActive, wrap, bounds, baseLine); - gc.dispose(); - - OS.CFRelease(sHandle); - width = bounds[1]; - height = bounds[0]; - } - /* - * Feature in Motif. If a label'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. - */ - /* AW - if (text.length () == 0) { - height += getFontHeight (); - width = 0; - } - */ - } - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - return new Point (width + 2*border, height + 2*border); -} -void createHandle (int index) { - state |= HANDLE; - int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; - if ((style & SWT.SEPARATOR) != 0) - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)100, (short)OS.kControlSeparatorLineProc, 0); - else - handle= OS.NewControl(0, new Rect(), null, false, (short)(OS.kControlSupportsFocus | OS.kControlGetsFocusOnClick), (short)0, (short)0, (short)OS.kControlUserPaneProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - if ((style & SWT.SEPARATOR) != 0) { - if ((style & SWT.HORIZONTAL) != 0) - OS.SizeControl(handle, (short) 20, (short) 1); - else - OS.SizeControl(handle, (short) 1, (short) 20); - } - OS.HIViewSetVisible(handle, true); -} -int defaultBackground () { - return getDisplay ().labelBackground; -} -Font defaultFont () { - return getDisplay ().labelFont; -} -int defaultForeground () { - return getDisplay ().labelForeground; -} -/** - * Returns a value which describes the position of the - * text or image in the receiver. The value will be one of - * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> - * unless the receiver is a <code>SEPARATOR</code> label, in - * which case, <code>NONE</code> is returned. - * - * @return the alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getAlignment () { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) - return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) - return SWT.RIGHT; - return SWT.LEFT; -} -public int getBorderWidth () { - checkWidget(); - return (style & SWT.BORDER) != 0 ? 1 : 0; -} -/** - * Returns the receiver's image if it has one, or null - * if it does not. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -String getNameText () { - return getText (); -} -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set or if the receiver is - * a <code>SEPARATOR</code> label. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return ""; - return text; -} -void hookEvents () { - super.hookEvents (); - if ((style & SWT.SEPARATOR) != 0) - return; - Display display= getDisplay(); - int[] mask= new int[] { - OS.kEventClassControl, OS.kEventControlDraw, - }; - OS.InstallEventHandler(OS.GetControlEventTarget(handle), display.fControlProc, mask.length/2, mask, handle, null); -} -/* AW -boolean mnemonicHit (char key) { - 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); -} -*/ -int processPaint (Object callData) { - if ((style & SWT.SEPARATOR) != 0) return OS.eventNotHandledErr; - - GC gc= new GC(this); - MacControlEvent me= (MacControlEvent) callData; - Rectangle r= gc.carbon_focus(me.getDamageRegionHandle(), me.getGCContext()); - if (! r.isEmpty()) { - - Rect bounds= new Rect(); - int hndl= topHandle(); - OS.GetControlBounds(hndl, bounds); - - int w= bounds.right - bounds.left; - int h= bounds.bottom - bounds.top; - int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; - - gc.fillRectangle(0, 0, r.width, r.height); - - boolean enabled= OS.IsControlEnabled(handle); - - if (image != null) { - Rectangle imageBounds= image.getBounds(); - Image im; - if (enabled) - im= image; - else { - if (disabled == null) - disabled = new Image (getDisplay(), image, SWT.IMAGE_DISABLE); - im= disabled; - } - gc.drawImage(im, (w-imageBounds.width) / 2, (h-imageBounds.height) / 2); - } else { - int sHandle= OS.CFStringCreateWithCharacters(MacUtil.removeMnemonics(text)); - boolean wrap= (style & SWT.WRAP) != 0; - short just= 0; - if ((style & SWT.RIGHT) != 0) - just= 2; - else if ((style & SWT.CENTER) != 0) - just= 1; - MacUtil.RGBForeColor(enabled ? 0x000000 : 0x808080); - gc.carbon_installFont(); - OS.SetRect(bounds, (short)borderWidth, (short)borderWidth, (short)(w-borderWidth), (short)(h-borderWidth)); - OS.DrawThemeTextBox(sHandle, (short)OS.kThemeCurrentPortFont, OS.kThemeStateActive, wrap, bounds, just, 0); - OS.CFRelease(sHandle); - } - - if (borderWidth > 0) { - gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY)); - gc.drawRectangle(0, 0, w-1, h-1); - } - } - - gc.carbon_unfocus(); - gc.dispose(); - - return OS.noErr; -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - /* - * Labels never participate in focus traversal when - * either enabled or disabled. - */ - /* AW - if (enabled) { - int [] argList = {OS.XmNtraversalOn, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - } - */ -} -void releaseWidget () { - super.releaseWidget (); - if (disabled != null) disabled.dispose (); - image = disabled = null; -} -/* AW -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; -} -*/ -/** - * Controls how text and images will be displayed in the receiver. - * The argument should be one of <code>LEFT</code>, <code>RIGHT</code> - * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code> - * label, the argument is ignored and the alignment is not changed. - * - * @param alignment the new alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAlignment (int alignment) { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return; - int mask= SWT.LEFT | SWT.CENTER | SWT.RIGHT; - int newAlignment= alignment & mask; - int currentAlignment= style & mask; - if (currentAlignment != newAlignment) { - style &= ~mask; - style |= newAlignment; - redrawWidget (0, 0, 0, 0, false); - } -} -public void setBounds (int x, int y, int width, int height) { - super.setBounds (x, y, width, height); - if ((style & SWT.WRAP) != 0) setText (text); -} -public void setFont (Font font) { - super.setFont (font); - if ((style & SWT.WRAP) != 0) setText (text); -} -/** - * Sets the receiver's image to the argument, which may be - * null indicating that no image should be displayed. - * - * @param image the image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - this.image = image; - if (disabled != null) disabled.dispose (); - disabled = null; - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - redrawWidget (0, 0, 0, 0, false); -} -public void setSize (int width, int height) { - super.setSize (width, height); - if ((style & SWT.WRAP) != 0) setText (text); -} -/** - * Sets the receiver's text. - * <p> - * This method sets the widget label. The label may include - * the mnemonic characters and line delimiters. - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - text = string; - redrawWidget (0, 0, 0, 0, false); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java deleted file mode 100644 index 9c41ff516d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java +++ /dev/null @@ -1,1297 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.DataBrowserListViewColumnDesc; -import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; - -/** - * Instances of this class represent a selectable user interface - * object that displays a list of strings and issues notificiation - * when a string selected. A list may be single or multi select. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SINGLE, MULTI</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection</dd> - * </dl> - * <p> - * Note: Only one of SINGLE and MULTI may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public /*final*/ class List extends Scrollable { - - // AW - private static final int COL_ID= 12345; - private ArrayList fData= new ArrayList(); - private int fRowID= 1000; - - private class Pair { - int fId; - String fValue; - - Pair(String v) { - fValue= v; - fId= fRowID++; - } - - } - // AW - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SINGLE - * @see SWT#MULTI - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public List (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the argument to the end of the receiver's list. - * - * @param string the new item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - Pair p= new Pair(string); - fData.add(p); - OS.AddDataBrowserItems(handle, OS.kDataBrowserNoItem, 1, new int[] { p.fId }, 0); -} -/** - * Adds the argument to the receiver's list at the given - * zero-relative index. - * <p> - * Note: To add an item at the end of the list, use the - * result of calling <code>getItemCount()</code> as the - * index or use <code>add(String)</code>. - * </p> - * - * @param string the new item - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int size= fData.size(); - if (!(0 <= index && index <= size)) { - error (SWT.ERROR_INVALID_RANGE); - } - Pair p= new Pair(string); - fData.add(index, p); - if (OS.AddDataBrowserItems(handle, OS.kDataBrowserNoItem, 1, new int[] { p.fId }, 0) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the selection changes. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - /* AW - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWWidth; - OS.XtQueryGeometry (handle, null, result); - int width = result.width, height = 0; - */ - int width = 300, height = 0; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) { - /* AW - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList [1]; - */ - int count = fData.size(); - 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); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - int border = getBorderWidth (); - int trimX = x - border; - int trimY = y - border; - int trimWidth = width + (border * 2); - int trimHeight = height + (border * 2); - Display display= getDisplay(); - if (horizontalBar != null) { - trimHeight += 15; - trimY -= display.scrolledInsetY; - if (verticalBar != null) { - trimX -= display.scrolledInsetX; - } - } - if (verticalBar != null) { - trimWidth += 15; - trimX -= display.scrolledInsetX; - if (horizontalBar != null) { - trimY -= display.scrolledInsetY; - } - } - /* AW - 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; - - int parentHandle= parent.handle; - int windowHandle= OS.GetControlOwner(parentHandle); - int[] controlRef= new int[1]; - OS.CreateDataBrowserControl(windowHandle, null, OS.kDataBrowserListView, controlRef); - handle= controlRef[0]; - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - DataBrowserCallbacks callbacks= new DataBrowserCallbacks(); - callbacks.version= OS.kDataBrowserLatestCallbacks; - OS.InitDataBrowserCallbacks(callbacks); - OS.SetDataBrowserCallbacks(handle, callbacks); - - //OS.HIViewAddSubview(parentHandle, handle); - MacUtil.insertControl(handle, parentHandle, -1); - - /* Single or Multiple Selection */ - int mode= OS.kDataBrowserSelectOnlyOne; - if ((style & SWT.MULTI) != 0) - mode= OS.kDataBrowserDragSelect | OS.kDataBrowserCmdTogglesSelection; - OS.SetDataBrowserSelectionFlags(handle, mode); - - /* hide the neader */ - OS.SetDataBrowserListViewHeaderBtnHeight(handle, (short) 0); - - /* enable scrollbars */ - OS.SetDataBrowserHasScrollBars(handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0); - if ((style & SWT.H_SCROLL) == 0) - OS.AutoSizeDataBrowserListViewColumns(handle); - - DataBrowserListViewColumnDesc columnDesc= new DataBrowserListViewColumnDesc(); - columnDesc.propertyDesc_propertyID= COL_ID; - columnDesc.propertyDesc_propertyType= OS.kDataBrowserTextType; - columnDesc.propertyDesc_propertyFlags= OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags; - - columnDesc.headerBtnDesc_version= OS.kDataBrowserListViewLatestHeaderDesc; - columnDesc.headerBtnDesc_minimumWidth= 0; - columnDesc.headerBtnDesc_maximumWidth= 2000; - - columnDesc.headerBtnDesc_titleOffset= 0; - columnDesc.headerBtnDesc_titleString= 0; - columnDesc.headerBtnDesc_initialOrder= OS.kDataBrowserOrderIncreasing; - - /* - columnDesc.headerBtnDesc_titleAlignment= teCenter; - columnDesc.headerBtnDesc_titleFontTypeID= OS.kControlFontViewSystemFont; - columnDesc.headerBtnDesc_btnFontStyle= normal; - */ - - OS.AddDataBrowserListViewColumn(handle, columnDesc, 10000); -} -ScrollBar createScrollBar (int type) { - return createStandardBar (type); -} -/* AW -int defaultBackground () { - return getDisplay ().listBackground; -} -int defaultFont () { - return getDisplay ().listFont; -} -int defaultForeground () { - return getDisplay ().listForeground; -} -*/ -/** - * Deselects the item at the given zero-relative index in the receiver. - * If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. - * - * @param index the index of the item to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int index) { - checkWidget(); - if (index >= 0 && index < fData.size()) { - Pair p= (Pair) fData.get(index); - if (p != null) - OS.SetDataBrowserSelectedItems(handle, 1, new int[] { p.fId }, OS.kDataBrowserItemsRemove); - } -} -/** - * Deselects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is selected, it is deselected. If the item at the index - * was not selected, it remains deselected. The range of the - * indices is inclusive. Indices that are out of range are ignored. - * - * @param start the start index of the items to deselect - * @param end the end index of the items to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int start, int end) { - checkWidget(); - if (start > end) return; - int[] ids= getIds(start, end); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsRemove); -} -/** - * Deselects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is selected, it is deselected. If the item at the index - * was not selected, it remains deselected. Indices that are out - * of range and duplicate indices are ignored. - * - * @param indices the array of indices for the items to deselect - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - int[] ids= getIds(indices); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsRemove); -} -/** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselectAll () { - checkWidget(); - int n= fData.size(); - if (n <= 0) return; - int[] ids= getIds(0, n-1); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsRemove); -} -/** - * Returns the zero-relative index of the item which is currently - * has the focus in the receiver, or -1 if no item is has focus. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getFocusIndex () { - checkWidget(); - /* AW - return OS.XmListGetKbdItemPos (handle) - 1; - */ - return -1; -} -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - int size= fData.size(); - if (!(0 <= index && index < size)) - error (SWT.ERROR_INVALID_RANGE); - Pair p= (Pair) fData.get(index); - return p.fValue; -} -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - return fData.size(); -} -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the tree. - * - * @return the height of one item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - return 15; // AW FIXME -} -/** - * Returns an array of <code>String</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver's list - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - String[] result= new String[fData.size()]; - Iterator iter= fData.iterator(); - for (int i= 0; iter.hasNext(); i++) { - Pair p= (Pair) iter.next(); - result[i]= p.fValue; - } - return result; -} -/** - * Returns an array of <code>String</code>s that are currently - * selected in the receiver. An empty array indicates that no - * items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return an array representing the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li> - * </ul> - */ -public String [] getSelection () { - checkWidget(); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, false); - String[] result= new String[ids.length]; - for (int i= 0; i < ids.length; i++) - result[i]= get(ids[i]); - return result; -} -/** - * Returns the number of selected items contained in the receiver. - * - * @return the number of selected items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget(); - int[] result= new int[1]; - if (OS.GetDataBrowserItemCount(handle, OS.kDataBrowserNoItem, false, OS.kDataBrowserItemIsSelected, result) != OS.noErr) - error (SWT.ERROR_CANNOT_GET_COUNT); - return result[0]; -} -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver, or -1 if no item is selected. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget(); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, false); - if (ids.length > 0) - return getIndex(ids[0]); - return -1; -} -/** - * Returns the zero-relative indices of the items which are currently - * selected in the receiver. The array is empty if no items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return the array of indices of the selected items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int [] getSelectionIndices () { - checkWidget(); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, false); - int[] result= new int[ids.length]; - for (int i= 0; i < ids.length; i++) - result[i]= getIndex(ids[i]); - return result; -} -/** - * Returns the zero-relative index of the item which is currently - * at the top of the receiver. This index can change when items are - * scrolled or new items are added or removed. - * - * @return the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopIndex () { - checkWidget(); - int[] top= new int[1]; - int[] left= new int[1]; - OS.GetDataBrowserScrollPosition(handle, top, left); - return top[0] / getItemHeight(); -} -void hookEvents () { - super.hookEvents (); - Display display= getDisplay(); - DataBrowserCallbacks callbacks= new DataBrowserCallbacks(); - OS.GetDataBrowserCallbacks(handle, callbacks); - callbacks.v1_itemDataCallback= display.fDataBrowserDataProc; - callbacks.v1_itemCompareCallback= display.fDataBrowserCompareProc; - callbacks.v1_itemNotificationCallback= display.fDataBrowserItemNotificationProc; - OS.SetDataBrowserCallbacks(handle, callbacks); -} -/** - * 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 IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string) { - checkWidget(); - return getIndex(string, 0); -} -/** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li> - * </ul> - */ -public int indexOf (String string, int start) { - checkWidget(); - return getIndex(string, start); -} -/** - * Returns <code>true</code> if the item is selected, - * and <code>false</code> otherwise. Indices out of - * range are ignored. - * - * @param index the index of the item - * @return the visibility state of the item at the index - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean isSelected (int index) { - checkWidget(); - if (index >= 0 && index < fData.size()) { - Pair p= (Pair) fData.get(index); - if (p != null) - return OS.IsDataBrowserItemSelected(handle, p.fId); - } - return false; -} -/** - * Removes the item from the receiver at the given - * zero-relative index. - * - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int size= fData.size(); - if (!(0 <= index && index < size)) { - error (SWT.ERROR_INVALID_RANGE); - } - Pair p= (Pair) fData.remove(index); - OS.RemoveDataBrowserItems(handle, OS.kDataBrowserNoItem, 1, new int[] { p.fId }, 0); -} -/** - * Removes the items from the receiver which are - * between the given zero-relative start and end - * indices (inclusive). - * - * @param start the start of the range - * @param end the end of the range - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - if (start > end) return; - int n= fData.size(); - if (start < 0 || start >= n || end < 0 || end >= n) - error (SWT.ERROR_INVALID_RANGE); - int[] ids= getIds(start, end); - if (OS.RemoveDataBrowserItems(handle, OS.kDataBrowserNoItem, ids.length, ids, 0) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_REMOVED); -} -/** - * Searches the receiver's list starting at the first item - * until an item is found that is equal to the argument, - * and removes that item from the list. - * - * @param string the item to remove - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - Pair p= getPair(string); - if (p == null) error (SWT.ERROR_INVALID_ARGUMENT); - fData.remove(p); - if (OS.RemoveDataBrowserItems(handle, OS.kDataBrowserNoItem, 1, new int[] { p.fId }, 0) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_REMOVED); -} -/** - * Removes the items from the receiver at the given - * zero-relative indices. - * - * @param indices the array of indices of the items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - int[] ids= getIds(indices); - if (OS.RemoveDataBrowserItems(handle, OS.kDataBrowserNoItem, ids.length, ids, 0) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_REMOVED); -} -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - fData.clear(); - OS.RemoveDataBrowserItems(handle, OS.kDataBrowserNoItem, 0, null, 0); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int index) { - checkWidget(); - if (index == -1) return; - Pair p= (Pair) fData.get(index); - if (p != null) - OS.SetDataBrowserSelectedItems(handle, 1, new int[] { p.fId }, OS.kDataBrowserItemsAssign); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the index was already selected, it remains - * selected. The range of the indices is inclusive. Indices that are - * out of range are ignored. - * - * @param start the start of the range - * @param end the end of the range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int start, int end) { - checkWidget(); - if (start > end) return; - if ((style & SWT.SINGLE) != 0) { - /* AW - 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; - } - int[] ids= getIds(start, end); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is not selected, it is selected. If the item at the index - * was selected, it remains selected. Indices that are out - * of range and duplicate indices are ignored. - * - * @param indices the array of indices for the items to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SINGLE) != 0) { - /* AW - 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; - } - int[] ids= getIds(indices); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} -void select (String [] items) { - checkWidget(); - int[] ids= getIds(items); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} -/** - * Selects all the items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void selectAll () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - int n= fData.size(); - if (n <= 0) return; - int[] ids= getIds(0, n-1); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} -void setFocusIndex (int index) { - /* AW - OS.XmListSetKbdItemPos (handle, index + 1); - */ - System.out.println("List.setFocusIndex: nyi"); -} -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to <code>remove</code>'ing the old item at the index, and then - * <code>add</code>'ing the new item at that index. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li> - * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int size= fData.size(); - if (!(0 <= index && index < size)) { - error (SWT.ERROR_INVALID_RANGE); - } - Pair p= (Pair) fData.get(index); - p.fValue= string; - OS.UpdateDataBrowserItems(handle, OS.kDataBrowserNoItem, 1, new int[] { p.fId }, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem); -} -/** - * Sets the receiver's items to be the given array of items. - * - * @param items the array of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - - fData.clear(); - int count= items.length; - int[] ids= new int[count]; - for (int i= 0; i < count; i++) { - Pair p= new Pair(items[i]); - fData.add(p); - ids[i]= p.fId; - } - if (OS.AddDataBrowserItems(handle, OS.kDataBrowserNoItem, ids.length, ids, 0) != OS.noErr) - error (SWT.ERROR_ITEM_NOT_ADDED); -} -/** - * Selects the item at the given zero-relative index in the receiver. - * If the item at the index was already selected, it remains selected. - * The current selected is first cleared, then the new items are selected. - * Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @see List#deselectAll() - * @see List#select(int) - */ -public void setSelection (int index) { - if ((style & SWT.MULTI) != 0) deselectAll (); - select (index); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selected if first cleared, then the new items are selected. - * - * @param start the start index of the items to select - * @param end the end index of the items to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Table#deselectAll() - * @see Table#select(int,int) - */ -public void setSelection (int start, int end) { - if ((style & SWT.MULTI) != 0) deselectAll (); - select (start, end); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selection is first cleared, then the new items are selected. - * - * @param indices the indices of the items to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#deselectAll() - * @see List#select(int[]) - */ -public void setSelection(int[] indices) { - if ((style & SWT.MULTI) != 0) deselectAll (); - select (indices); -} -/** - * Sets the receiver's selection to be the given array of items. - * The current selected is first cleared, then the new items are - * selected. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#deselectAll() - * @see List#select(int) - */ -public void setSelection (String [] items) { - checkWidget(); - int[] ids= getIds(items); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} -/** - * Sets the zero-relative index of the item which is currently - * at the top of the receiver. This index can change when items - * are scrolled or new items are added and removed. - * - * @param index the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTopIndex (int index) { - checkWidget(); - int[] top= new int[1]; - int[] left= new int[1]; - OS.GetDataBrowserScrollPosition(handle, top, left); - top[0]= index * getItemHeight() + 4; - OS.SetDataBrowserScrollPosition(handle, top[0], left[0]); -} -/** - * Shows the selection. If the selection is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled until - * the selection is visible. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void showSelection () { - checkWidget(); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, false); - if (ids.length > 0 && ids[0] != 0) - OS.RevealDataBrowserItem(handle, ids[0], COL_ID, false); -} - -//////////////////////////////////// -// Mac stuff -//////////////////////////////////// - - int processSelection (Object callData) { - //System.out.println("List.processSelection: " + getSelectionIndex()); - return super.processSelection(callData); - } - - int sendKeyEvent (int type, MacEvent mEvent, Event event) { - //processEvent (type, new MacEvent(eRefHandle)); - return OS.eventNotHandledErr; - } - - int handleItemCallback(int rowID, int colID, int item) { - - if (colID != COL_ID) { - //System.out.println("List.handleItemCallback: wrong column id: " + colID); - return OS.noErr; - } - - String s= get(rowID); - if (s == null) { - System.out.println("List.handleItemCallback: can't find row with id: " + rowID); - return -1; - } - - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(s); - OS.SetDataBrowserItemDataText(item, sHandle); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - return OS.noErr; - } - - int handleCompareCallback(int item1ID, int item2ID, int item) { - if (getIndex(item1ID) < getIndex(item2ID)) - return 1; - return 0; - } - - int handleItemNotificationCallback(int item, int message) { - return OS.noErr; - } - - /** - * Returns string value of row with the given ID - */ - private String get(int id) { - Iterator iter= fData.iterator(); - while (iter.hasNext()) { - Pair p= (Pair) iter.next(); - if (p.fId == id) - return p.fValue; - } - return null; - } - - /** - * Returns the index of row with the given ID - */ - private int getIndex(int id) { - Iterator iter= fData.iterator(); - for (int i= 0; iter.hasNext(); i++) { - Pair p= (Pair) iter.next(); - if (p.fId == id) - return i; - } - return -1; - } - - /** - * Returns the index of the first row that matches the given string - */ - private int getIndex(String s, int start) { - if (s == null) error (SWT.ERROR_NULL_ARGUMENT); - int n= fData.size(); - for (int i= start; i < n; i++) { - Pair p= (Pair) fData.get(i); - if (s.equals(p.fValue)) - return i; - } - return -1; - } - - /** - * Returns the ID of the first row that matches the given string - */ - private Pair getPair(String s) { - Iterator iter= fData.iterator(); - while (iter.hasNext()) { - Pair p= (Pair) iter.next(); - if (s.equals(p.fValue)) - return p; - } - return null; - } - - /** - * Returns the ID of the first row that matches the given string - */ - private int getID(String s) { - Iterator iter= fData.iterator(); - while (iter.hasNext()) { - Pair p= (Pair) iter.next(); - if (s.equals(p.fValue)) - return p.fId; - } - return 0; - } - - private int[] getIds(int[] indices) { - int count= fData.size(); - int[] ids= new int[indices.length]; - for (int i= 0; i < indices.length; i++) { - int index= indices[i]; - if (!(0 <= index && index < count)) break; - Pair p= (Pair) fData.get(index); - ids[i]= p.fId; - } - return ids; - } - - private int[] getIds(String[] items) { - int count= items.length; - int[] ids= new int[count]; - for (int i=0; i<count; i++) { - int id= getID(items[i]); - ids[i]= id; - } - return ids; - } - - private int[] getIds(int start, int end) { - int n= fData.size(); - if (start < 0 && start >= n) - error (SWT.ERROR_INVALID_RANGE); - if (end >= n) - error (SWT.ERROR_INVALID_RANGE); - int count= end-start+1; - int[] ids= new int[count]; - for (int i= 0; i < count; i++) { - Pair p= (Pair) fData.get(start+i); - ids[i]= p.fId; - } - return ids; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacControlEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacControlEvent.java deleted file mode 100644 index 0b0771d554..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacControlEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.swt.widgets; - -class MacControlEvent { - - private int fControlhandle; - private int fPartCode; - private boolean fMouseDown; - private int fDamageRegion; - private int fGCContext; - - public MacControlEvent(int handle, int partCode, boolean mouseDown) { - fControlhandle= handle; - fPartCode= partCode; - fMouseDown= mouseDown; - } - - public MacControlEvent(int handle, int damageRegion, int gccontext) { - fControlhandle= handle; - fDamageRegion= damageRegion; - fGCContext= gccontext; - } - - public int getControlHandle() { - return fControlhandle; - } - - public int getPartCode() { - return fPartCode; - } - - public int getDamageRegionHandle() { - return fDamageRegion; - } - - public int getGCContext() { - return fGCContext; - } - - public boolean isMouseDown() { - return fMouseDown; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacEvent.java deleted file mode 100644 index 18b01ff53f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacEvent.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Andre Weinand, OTI - Initial version - */ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.internal.carbon.OS; - -class MacEvent { - - private static int fgMouseButtonState; - - static final boolean EMULATE_RIGHT_BUTTON= true; - - private int fEventRef; - private int fNextHandler; - - public MacEvent() { - fEventRef= -1; - } - - public MacEvent(int eventRef) { - fEventRef= eventRef; - } - - public MacEvent(int eventRef, int nextHandler) { - fEventRef= eventRef; - fNextHandler= nextHandler; - } - - public int getEventRef() { - return fEventRef; - } - - public int getNextHandler() { - return fNextHandler; - } - - public int getKind() { - if (fEventRef != -1) - return OS.GetEventKind(fEventRef); - System.out.println("MacEvent.getKind: no EventRef"); - return 0; - } - - public int getWhen() { - if (fEventRef != -1) - return (int)(OS.GetEventTime(fEventRef) * 1000.0); - System.out.println("MacEvent.getModifierKeys: no EventRef"); - return 0; - } - - public org.eclipse.swt.internal.carbon.Point getWhere() { - if (fEventRef != -1) { - short[] loc= new short[2]; - if (OS.GetEventParameter(fEventRef, OS.kEventParamMouseLocation, OS.typeQDPoint, null, loc.length*2, null, loc) == OS.noErr) { - org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point(); - OS.SetPt(pt, loc[1], loc[0]); - return pt; - } - } - System.out.println("MacEvent.getWhere: no EventRef"); - return new org.eclipse.swt.internal.carbon.Point(); - } - - /** - * Returns the Mac modifiers for this event - */ - public int getModifiers() { - if (fEventRef != -1) - return getEventModifiers(fEventRef); - System.out.println("MacEvent.getModifiers: no EventRef"); - return 0; - } - - /** - * Returns the SWT modifiers for this event - */ - public int getStateMask() { - int stateMask= fgMouseButtonState; - int modifiers= getModifiers (); - if ((modifiers & OS.shiftKey) != 0) stateMask |= SWT.SHIFT; - if ((modifiers & OS.controlKey) != 0) { - if (EMULATE_RIGHT_BUTTON) { - // we only report CONTROL, iff it was not used to emulate the right mouse button - if ((stateMask & SWT.BUTTON3) == 0) stateMask |= SWT.CONTROL; - } else { - stateMask |= SWT.CONTROL; - } - } - if ((modifiers & OS.cmdKey) != 0) stateMask |= SWT.COMMAND; - if ((modifiers & OS.optionKey) != 0) stateMask |= SWT.ALT; - return stateMask; - } - - public int getKeyCode() { - if (fEventRef != -1) - return getKeyCode(fEventRef); - System.out.println("MacEvent.getKeyCode: no EventRef"); - return 0; - } - - /** - * Returns the SWT mouse button - */ - public int getButton() { - if (fEventRef != -1) - return getEventMouseButton(fEventRef); - - System.out.println("MacEvent.getButton: no EventRef"); - return 0; - } - - public boolean isShowContextualMenuClick() { - if (fEventRef == -1) { - System.out.println("MacEvent.isShowContextualMenuClick: no EventRef"); - return false; - } - return (OS.GetEventClass(fEventRef) == OS.kEventClassMouse) && - (getKind() == OS.kEventMouseDown) && - (getButton() == 3); - // return OS.IsShowContextualMenuClick(getData()); - } - - public int getMacCharCodes() { - if (fEventRef != -1) - return getCharCode(fEventRef); - System.out.println("MacEvent.getMacCharCodes: no EventRef"); - return -1; - } - - public String getText() { - if (fEventRef == -1) { - System.out.println("MacEvent.getText: no EventRef"); - return null; - } - int[] actualSize= new int[1]; - OS.GetEventParameter(fEventRef, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, 0, actualSize, (char[])null); - int size= actualSize[0] / 2; - if (size > 0) { - char[] buffer= new char[size]; - OS.GetEventParameter(fEventRef, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, buffer.length*2, null, buffer); - return new String(buffer); - } - return ""; - } - - //---- Carbon event accessors - - public static int getDirectObject(int eRefHandle) { - int[] wHandle= new int[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamDirectObject, OS.typeWindowRef, null, wHandle.length*4, null, wHandle) == OS.noErr) - return wHandle[0]; - return 0; - } - - public static short getWindowDefPart(int eRefHandle) { - short[] part= new short[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamWindowDefPart, OS.typeWindowDefPartCode, null, part.length*2, null, part) == OS.noErr) - return part[0]; - return 0; - } - - public static int getControlRef(int eRefHandle) { - int[] cHandle= new int[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamControlRef, OS.typeControlRef, null, cHandle.length*4, null, cHandle) == OS.noErr) - return cHandle[0]; - return 0; - } - - public static int getEventModifiers(int eRefHandle) { - int[] modifierKeys= new int[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamKeyModifiers, OS.typeUInt32, null, modifierKeys.length*4, null, modifierKeys) == OS.noErr) { - return modifierKeys[0]; - } - System.out.println("MacEvent.getModifierKeys: getEventModifiers error"); - return -1; - } - - private static int getMouseChord(int eRefHandle) { - int[] mouseChord= new int[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamMouseChord, OS.typeUInt32, null, mouseChord.length*4, null, mouseChord) == OS.noErr) { - return mouseChord[0]; - } - System.out.println("MacEvent.getMouseChord: getMouseChord error"); - return -1; - } - - public static int getKeyCode(int eRefHandle) { - int[] keyCode= new int[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length*4, null, keyCode) == OS.noErr) - return keyCode[0]; - System.out.println("MacEvent.getMouseChord: getKeyCode error"); - return -1; - } - - public static int getCharCode(int eRefHandle) { - byte[] charCode= new byte[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamKeyMacCharCodes, OS.typeChar, null, charCode.length, null, charCode) == OS.noErr) - return charCode[0]; - return -1; - } - - private static short getEventMouseButton(int eRefHandle) { - short[] mouseButtons= new short[1]; - if (OS.GetEventParameter(eRefHandle, OS.kEventParamMouseButton, OS.typeMouseButton, null, mouseButtons.length*2, null, mouseButtons) == OS.noErr) { - short button= mouseButtons[0]; - switch (button) { - case OS.kEventMouseButtonPrimary: // left mouse button - if (EMULATE_RIGHT_BUTTON) { - if ((getEventModifiers(eRefHandle) & OS.controlKey) != 0) - return 3; - } - return 1; - case OS.kEventMouseButtonSecondary: // right mouse button - return 3; - case OS.kEventMouseButtonTertiary: // middle mouse button - return 2; - default: - return button; - } - } - return 0; - } - - public static void trackStateMask(int event, int kind) { - switch (kind) { - case OS.kEventMouseDown: - case OS.kEventMouseDragged: - case OS.kEventMouseUp: - int chord= getMouseChord(event); - if (chord != -1) { - fgMouseButtonState= 0; - if ((chord & 1) != 0) { - int modifiers= getEventModifiers(event); - if (EMULATE_RIGHT_BUTTON && ((modifiers & OS.controlKey) != 0)) { - fgMouseButtonState |= SWT.BUTTON3; - } else { - fgMouseButtonState |= SWT.BUTTON1; - } - } - if ((chord & 2) != 0) - fgMouseButtonState |= SWT.BUTTON3; - if ((chord & 4) != 0) - fgMouseButtonState |= SWT.BUTTON2; - } - break; - case OS.kEventMouseMoved: - fgMouseButtonState= 0; - break; - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacMouseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacMouseEvent.java deleted file mode 100644 index fb591b9ce6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacMouseEvent.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Andre Weinand, OTI - Initial version - */ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.SWT; -import org.eclipse.swt.internal.carbon.OS; - -class MacMouseEvent { - - private int fWhen; - private Point fWhere; - private int fState; - private int fButton; - private MacEvent fMacEvent; - - public MacMouseEvent() { - } - - public MacMouseEvent(int button, Point where) { - fButton= button; - fWhere= where; - fState= SWT.BUTTON1; - } - - public MacMouseEvent(MacEvent me) { - fMacEvent= me; - fWhen= me.getWhen(); - - short[] loc= new short[2]; - OS.GetEventParameter(me.getEventRef(), OS.kEventParamMouseLocation, OS.typeQDPoint, null, loc.length*2, null, loc); - fWhere= new Point(loc[1], loc[0]); - - fState= me.getStateMask(); - fButton= me.getButton(); - } - - public int getWhen() { - return fWhen; - } - - public Point getWhere() { - return fWhere; - } - - public int getState() { - return fState; - } - - public int getButton() { - return fButton; - } - - public int getEventRef() { - return fMacEvent.getEventRef(); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacUtil.java deleted file mode 100644 index 5ef7ddd43a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MacUtil.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Andre Weinand, OTI - Initial version - */ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTError; -import org.eclipse.swt.internal.carbon.CFRange; -import org.eclipse.swt.internal.carbon.CGPoint; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Point; -import org.eclipse.swt.internal.carbon.Rect; -import org.eclipse.swt.internal.carbon.RGBColor; - -public class MacUtil { - - public final static boolean USE_MENU_ICONS; - - /** Prevent use of standard Mac shortcuts Cmd-Q, Cmd-H */ - public final static boolean KEEP_MAC_SHORTCUTS; - public final static boolean FULL_KBD_NAV; - - static final char MNEMONIC = '&'; - - static { - USE_MENU_ICONS= true; - KEEP_MAC_SHORTCUTS= true; - FULL_KBD_NAV= true; - } - - //---- HIView utilities - - /* - static void dump(int control, int level) { - for (int j= 0; j < level; j++) - System.out.print(' '); - - int id= OS.HIObjectCopyClassID(control); - String s= getStringAndRelease(id); - System.out.print(control + "(" + s + "): "); - - if ("com.apple.hiwindowcontentview".equals(s)) { - int[] id0= new int[2]; - id0[0]= OSType("wind"); - id0[1]= 1; - OS.SetControlID(control, id0); - } - - Rect b= new Rect(); - OS.GetControlBounds(control, b); - System.out.print(new Rectangle(b.left, b.top, b.right-b.left, b.bottom-b.top)); - - int[] id2= new int[2]; - OS.GetControlID(control, id2); - System.out.println(" " + toString(id2[0]) + " " + id2[1]); - - int n= countSubControls(control); - int[] outControl= new int[1]; - for (int i= 0; i < n; i++) { - if (getChild(control, outControl, n, i) == OS.noErr) { - dump(outControl[0], level+1); - } - } - } - */ - - /** - * Returns the HIView that represents the contents of the given window or - * the root HIView if no contents HIView could be found. - */ - private static int getContentView(int windowHandle) { - int rootControl= OS.HIViewGetRoot(windowHandle); - if (rootControl == 0) { - System.out.println("getContentView: could not find root control"); - return 0; - } - int[] contentView= new int[1]; - int rc= OS.HIViewFindByID(rootControl, OS.kHIViewWindowContentID(), contentView); - if (rc != OS.noErr) { - if (rc != OS.errUnknownControl) - System.out.println("getContentView: errNo: " + rc); - return rootControl; - } - return contentView[0]; - } - - //---- control utilities - - static int getChild(int controlHandle, int[] tmp, int n, int i) { - int index= (n-1 - i); - int status= OS.GetIndexedSubControl(controlHandle, (short)(index+1), tmp); - if (status != OS.noErr) - System.out.println("MacUtil.getChild: error"); - return status; - } - - static int indexOf(int parentHandle, int handle) { - int n= countSubControls(parentHandle); - int[] outControl= new int[1]; - for (int i= 0; i < n; i++) { - if (getChild(parentHandle, outControl, n, i) == OS.noErr) - if (outControl[0] == handle) - return i; - } - return -1; - } - - /** - * Inserts the given child at position in the parent. - * If pos is out of range the child is added at the end (below all other). - */ - static void insertControl(int controlHandle, int parent, int pos) { - - int parentHandle= parent; - - // make sure that parentHandle really refers to a Control - if (OS.IsValidControlHandle(parent)) { - // it is a Control - parentHandle= parent; - } else if (OS.IsValidWindowPtr(parentHandle)) { - // it is a Window: get the Window's content Control - parentHandle= getContentView(parent); - if (parentHandle == 0) - parentHandle= getContentView(parent); - } else { - System.out.println("MacUtil.insertControl: parentHandle is neither control nor window"); - } - int n= countSubControls(parentHandle); - - int should= pos; - if (should < 0 || should > n) - should= n; - - boolean add= false; - if (getSuperControl(controlHandle) != parentHandle) { - add= true; - } else { - System.out.println("MacUtil.insertControl: already there"); - if (n == 1) - return; - } - - if (n == 0) { - if (OS.HIViewAddSubview(parentHandle, controlHandle) != OS.noErr) - System.out.println("MacUtil.insertControl: error in HIViewAddSubview"); - pos= 0; - } else { - if (pos >= 0 && pos < n) { - int[] where= new int[1]; - getChild(parentHandle, where, n, pos); - if (add) - OS.HIViewAddSubview(parentHandle, controlHandle); - OS.HIViewSetZOrder(controlHandle, OS.kHIViewZOrderAbove, where[0]); - } else { - if (add) - OS.HIViewAddSubview(parentHandle, controlHandle); - if (OS.HIViewSetZOrder(controlHandle, OS.kHIViewZOrderBelow, 0) != OS.noErr) - System.out.println("error 2"); - pos= n; - } - } - - // verify correct position - int i= indexOf(parentHandle, controlHandle); - if (i != should) - System.out.println("MacUtil.insertControl: is: "+i+" should: "+ should + " n:" + n + " add: " + add); - } - - /** - * Returns the bounds of a view relative to its window's local coordinate system. - */ - public static void getControlBounds(int cHandle, Rect bounds) { - OS.GetControlBounds(cHandle, bounds); - org.eclipse.swt.graphics.Point offset= getLocation(cHandle); - bounds.left+= offset.x; - bounds.top+= offset.y; - bounds.right+= offset.x; - bounds.bottom+= offset.y; - } - - /** - * Returns location of given Control relative to the window.
*/ - static org.eclipse.swt.graphics.Point getLocation(int cHandle) { - -// int windowHandle= OS.GetControlOwner(cHandle); -// CGPoint p= new CGPoint(); -// OS.HIViewConvertPoint(p, cHandle, 0 /*getContentView(windowHandle)*/); -// int xx= (int) p.x; -// int yy= (int) p.y; - - int x= 0, y= 0; - Rect tmp= new Rect(); - int parent= cHandle; - while (true) { - parent= getSuperControl(parent); - if (parent == 0) - break; - if (getSuperControl(parent) == 0) - break; - OS.GetControlBounds(parent, tmp); - x+= tmp.left; - y+= tmp.top; - } - -// if (x != xx || y != yy) -// System.out.println("MacUtil.getLocation: differ " + x+"/"+y + " " + xx+"/"+yy); - return new org.eclipse.swt.graphics.Point(x, y); - } - - static void getControlBounds(int cHandle, short part, int rgn) { - OS.GetControlRegion(cHandle, part, rgn); - Rect tmp= new Rect(); - int parent= cHandle; - while (true) { - parent= getSuperControl(parent); - if (parent == 0) - break; - if (getSuperControl(parent) == 0) - break; - OS.GetControlBounds(parent, tmp); - OS.OffsetRgn(rgn, (short)tmp.left, (short)tmp.top); - } - } - - public static int getVisibleRegion(int cHandle, int result, boolean includingTop) { - - getControlRegion(cHandle, OS.kControlEntireControl, result); - - int tmpRgn= OS.NewRgn(); - int parent= cHandle; - - while (true) { - parent= getSuperControl(parent); - if (parent == 0) - break; - if (getSuperControl(parent) == 0) - break; - getControlRegion(parent, OS.kControlContentMetaPart, tmpRgn); - OS.SectRgn(result, tmpRgn, result); - } - - if (includingTop) { - int n= countSubControls(cHandle); - if (n > 0) { - //System.out.println("have children on top"); - int[] outHandle= new int[1]; - for (int i= 0; i < n; i++) { - int index= i; // was: n-1-i - if (OS.GetIndexedSubControl(cHandle, (short)(index+1), outHandle) == 0) { // indices are 1 based - if (OS.IsControlVisible(outHandle[0])) { - if (true) - getControlRegion(outHandle[0], OS.kControlStructureMetaPart, tmpRgn); - else - OS.GetControlRegion(outHandle[0], (short)OS.kControlEntireControl, tmpRgn); - OS.DiffRgn(result, tmpRgn, result); - } - } else - throw new SWTError(); - } - } - } - OS.DisposeRgn(tmpRgn); - - return OS.noErr; - } - - static org.eclipse.swt.graphics.Point toControl(int cHandle, org.eclipse.swt.graphics.Point point) { - Point mp= new Point(); - mp.h= (short)point.x; - mp.v= (short)point.y; - // convert from screen to window coordinates - int wHandle= OS.GetControlOwner(cHandle); - Rect bounds= new Rect(); - OS.GetWindowBounds(wHandle, (short)OS.kWindowContentRgn, bounds); - mp.h-= bounds.left; - mp.v-= bounds.top; - // convert from window to control coordinates - CGPoint p= new CGPoint(); - p.x= mp.h; - p.y= mp.v; - OS.HIViewConvertPoint(p, getContentView(wHandle), cHandle); - return new org.eclipse.swt.graphics.Point((int)p.x, (int)p.y); - } - - static org.eclipse.swt.graphics.Point toDisplay(int cHandle, org.eclipse.swt.graphics.Point point) { - int wHandle= OS.GetControlOwner(cHandle); - // convert from control to window coordinates - CGPoint p= new CGPoint(); - p.x= point.x; - p.y= point.y; - OS.HIViewConvertPoint(p, cHandle, getContentView(wHandle)); - Point mp= new Point(); - mp.h= (short)p.x; - mp.v= (short)p.y; - // convert from window to screen coordinates - Rect bounds= new Rect(); - OS.GetWindowBounds(wHandle, (short)OS.kWindowContentRgn, bounds); - mp.h+= bounds.left; - mp.v+= bounds.top; - return new org.eclipse.swt.graphics.Point(mp.h, mp.v); - } - - private static void getControlRegion(int cHandle, int part, int rgn) { - Rect bounds= new Rect(); - getControlBounds(cHandle, bounds); - OS.RectRgn(rgn, bounds); - } - - // Hit detection on the Mac is reversed and doesn't consider clipping, - // so we have to do it ourselves - - static int findControlUnderMouse(int wHandle, MacEvent me, short[] cpart) { - - int root= OS.HIViewGetRoot(wHandle); - int[] ov= new int[1]; - - if (me.getKind() == OS.kEventMouseMoved) { - org.eclipse.swt.internal.carbon.Point pp= me.getWhere(); - org.eclipse.swt.graphics.Point w= toControl(root, new org.eclipse.swt.graphics.Point(pp.h, pp.v)); - OS.HIViewGetSubviewHit(root, new float[] { w.x, w.y }, true, ov); - } else { - OS.HIViewGetViewForMouseEvent(root, me.getEventRef(), ov); - } - - int control= ov[0]; - - if (control != 0) { - Widget ww= WidgetTable.get(control); - if (cpart != null && ww != null) { - org.eclipse.swt.internal.carbon.Point where= me.getWhere(); - org.eclipse.swt.graphics.Point w= toControl(control, new org.eclipse.swt.graphics.Point(where.h, where.v)); - OS.HIViewGetPartHit(control, new float[] { w.x, w.y }, cpart); - } - } - - return control; - } - - private static int countSubControls(int cHandle) { - short[] cnt= new short[1]; - int status= OS.CountSubControls(cHandle, cnt); - switch (status) { - case OS.noErr: - return cnt[0]; - case OS.errControlIsNotEmbedder: - //System.out.println("MacUtil.countSubControls: errControlIsNotEmbedder"); - break; - case -30599: // OS.controlHandleInvalidErr - System.out.println("MacUtil.countSubControls: controlHandleInvalidErr"); - break; - default: - System.out.println("MacUtil.countSubControls: " + status); - break; - } - return 0; - } - - /** - * Returns the parent of the given control or null if the control is the window's content control. - */ - static int getSuperControl(int cHandle) { - - int wHandle= OS.GetControlOwner(cHandle); - if (wHandle == 0) { - //System.out.println("MacUtil.getSuperControl: GetControlOwner error"); - return 0; - } - if (cHandle == getContentView(wHandle)) - return 0; - - int[] parentHandle= new int[1]; - int rc= OS.GetSuperControl(cHandle, parentHandle); - if (rc != OS.noErr) - System.out.println("MacUtil.getSuperControl: " + rc); - return parentHandle[0]; - } - - static org.eclipse.swt.graphics.Point computeSize(int handle) { - if (OS.IsValidControlHandle(handle)) { - Rect rect= new Rect(); - short[] base= new short[1]; - OS.GetBestControlRect(handle, rect, base); - if (OS.EmptyRect(rect)) - System.out.println("MacUtil.computeSize: 0 size"); - return new org.eclipse.swt.graphics.Point(rect.right - rect.left, rect.bottom - rect.top); - } - System.out.println("MacUtil.computeSize: unknown handle type"); - return new org.eclipse.swt.graphics.Point(50, 50); - } - - //---- Strings utilities - - static String getStringAndRelease(int sHandle) { - int length= OS.CFStringGetLength(sHandle); - char[] buffer= new char[length]; - CFRange range = new CFRange(); - range.length = length; - OS.CFStringGetCharacters(sHandle, range, buffer); - OS.CFRelease(sHandle); - return new String(buffer); - } - - /** - * Converts the given String into a Pascal Str255 type.
*/ - public static byte[] Str255(String s) { - int l= 0; - if (s != null) - l= s.length(); - if (l > 255) { - throw new SWTError(SWT.ERROR_INVALID_RANGE); - //System.out.println("MacUtil.Str255: string length > 255"); - } - byte[] b= new byte[l+1]; - b[0]= (byte) l; - for (int i= 0; i < l; i++) - b[i+1]= (byte) s.charAt(i); - return b; - } - - /** - * Converts the given Pascal Str255 type into a String. - */ - public static String toString(byte[] str255) { - int n= str255[0]; - char[] c= new char[n]; - for (int i= 0; i < n; i++) - c[i]= (char) str255[i+1]; - return new String(c); - } - - /** - * Converts the given String into an OSType. - */ - static int OSType(String s) { - return ((s.charAt(0) & 0xff) << 24) | ((s.charAt(1) & 0xff) << 16) | ((s.charAt(2) & 0xff) << 8) | (s.charAt(3) & 0xff); - } - - /** - * Converts the given OSType into a String. - */ - public static String toString(int i) { - StringBuffer sb= new StringBuffer(); - sb.append((char)((i & 0xff000000) >> 24)); - sb.append((char)((i & 0x00ff0000) >> 16)); - sb.append((char)((i & 0x0000ff00) >> 8)); - sb.append((char)((i & 0x000000ff) >> 0)); - return sb.toString(); - } - - static String removeMnemonics(String s) { - if (s != null) { - int l= s.length(); - if (l > 0) { - char[] buf= new char[l]; - int j= 0; - for (int i= 0; i < l; i++) { - char c= s.charAt(i); - if (c != MNEMONIC) - buf[j++]= c; - } - return new String(buf, 0, j); - } - } - return s; - } - - //---- color utilities - - public static void RGBBackColor(int packed) { - if ((packed & 0xff000000) == 0) { - RGBColor color = new RGBColor(); - color.red = (short)(((packed >> 16) & 0xFF) * 257); - color.green = (short)(((packed >> 8) & 0xFF) * 257); - color.blue = (short)(((packed) & 0xFF) * 257); - OS.RGBBackColor(color); - } else { - RGBColor color = new RGBColor(); - color.red = (short)0xFFFF; - color.green = (short)0xFFFF; - color.blue = (short)0xFFFF; - OS.RGBBackColor(color); - } - } - - public static void RGBForeColor(int packed) { - if ((packed & 0xff000000) == 0) { - RGBColor color = new RGBColor(); - color.red = (short)(((packed >> 16) & 0xFF) * 257); - color.green = (short)(((packed >> 8) & 0xFF) * 257); - color.blue = (short)(((packed) & 0xFF) * 257); - OS.RGBForeColor(color); - } else { - RGBColor color = new RGBColor(); - color.red = (short)0xFFFF; - color.green = (short)0xFFFF; - color.blue = (short)0xFFFF; - OS.RGBForeColor(color); - } - } - - //---- data browser utilities - - static int[] getDataBrowserItems(int dataBrowserHandle, int containerID, int state, boolean recurse) { - int[] resultIDs= new int[0]; - int resultHandle= OS.NewHandle(0); - if (OS.GetDataBrowserItems(dataBrowserHandle, containerID, recurse, state, resultHandle) == OS.noErr) { - int itemCount= OS.GetHandleSize(resultHandle) / 4; // sizeof(int) - if (itemCount > 0) { - resultIDs= new int[itemCount]; - OS.HLock(resultHandle); - int[] ptr= new int[1]; - OS.memcpy(ptr, resultHandle, 4); - OS.memcpy(resultIDs, ptr[0], itemCount*4); - OS.HUnlock(resultHandle); - } - } - OS.DisposeHandle(resultHandle); - return resultIDs; - } - - static int[] getSelectionIDs(int dataBrowserHandle, int containerID, boolean recurse) { - return getDataBrowserItems(dataBrowserHandle, containerID, OS.kDataBrowserItemIsSelected, recurse); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java deleted file mode 100644 index a6beea58b8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java +++ /dev/null @@ -1,906 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.internal.carbon.*; - -/** - * Instances of this class are user interface objects that contain - * menu items. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BAR, DROP_DOWN, POP_UP</dd> - * <dt><b>Events:</b></dt> - * <dd>Help, Hide, Show </dd> - * </dl> - * <p> - * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Menu extends Widget { - int x, y; - boolean hasLocation; - MenuItem cascade, defaultItem; - Decorations parent; - -/** - * Constructs a new instance of this class given its parent, - * and sets the style for the instance so that the instance - * will be a popup menu on the given parent's shell. - * - * @param parent a control which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#POP_UP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Control parent) { - this (checkNull (parent).getShell (), SWT.POP_UP); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Decorations</code>) and a style value - * describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a decorations control which will be the parent of the new instance (cannot be null) - * @param style the style of menu to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BAR - * @see SWT#DROP_DOWN - * @see SWT#POP_UP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Decorations parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>) and sets the style - * for the instance so that the instance will be a drop-down - * menu on the given parent's parent. - * - * @param parent a menu which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Menu parentMenu) { - this (checkNull (parentMenu).parent, SWT.DROP_DOWN); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>MenuItem</code>) and sets the style - * for the instance so that the instance will be a drop-down - * menu on the given parent's parent menu. - * - * @param parent a menu item which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (MenuItem parentItem) { - this (checkNull (parentItem).parent); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when help events are generated for the control, - * by sending it one of the messages defined in the - * <code>HelpListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when menus are hidden or shown, by sending it - * one of the messages defined in the <code>MenuListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuListener - * @see #removeMenuListener - */ -public void addMenuListener (MenuListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Hide,typedListener); - addListener (SWT.Show,typedListener); -} - -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; -} - -static int checkStyle (int style) { - return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0); -} - -void createHandle () { - state |= HIDDEN; - Display display= getDisplay(); - int menuHandle[]= new int[1]; - if (OS.CreateNewMenu(display.nextMenuId(), 0, menuHandle) == OS.noErr) - handle= menuHandle[0]; - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.RetainMenu(handle); - int[] mask = new int[] { - OS.kEventClassMenu, OS.kEventMenuOpening, - OS.kEventClassMenu, OS.kEventMenuClosed - }; - OS.InstallEventHandler(OS.GetMenuEventTarget(handle), display.fMenuProc, mask.length / 2, mask, handle, null); -} - -void createItem (MenuItem item, int index) { - checkWidget (); - int count = OS.CountMenuItems (handle); - if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); - parent.add (item); - boolean success = false; - /* - if (OS.IsWinCE) { - int flags = OS.MF_BYPOSITION; - if ((style & SWT.SEPARATOR) != 0) flags |= OS.MF_SEPARATOR; - success = OS.InsertMenu (handle, index, flags, item.id, null); - } else { - int hHeap = OS.GetProcessHeap (); - int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof); - MENUITEMINFO info = new MENUITEMINFO (); - info.cbSize = MENUITEMINFO.sizeof; - info.fMask = OS.MIIM_ID | OS.MIIM_TYPE; - info.wID = item.id; - info.fType = item.widgetStyle (); - info.dwTypeData = pszText; - success = OS.InsertMenuItem (handle, index, true, info); - if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); - } - */ - - /* - if ((style & SWT.SEPARATOR) != 0) return OS.MFT_SEPARATOR; - if ((style & SWT.RADIO) != 0) return OS.MFT_RADIOCHECK; - return OS.MFT_STRING; - */ - - int attributes= 0; - if ((item.style & SWT.SEPARATOR) != 0) - attributes= OS.kMenuItemAttrSeparator; - if (OS.InsertMenuItemTextWithCFString(handle, 0, (short) index, attributes, item.id) == OS.noErr) - success= true; - - if (!success) { - parent.remove (item); - error (SWT.ERROR_ITEM_NOT_ADDED); - } - /* AW - redraw (); - */ -} - -void createWidget () { - createHandle (); - parent.add (this); - register (); -} - -void destroyAcceleratorTable () { - /* AW - parent.destroyAcceleratorTable (); - */ -} - -void destroyItem (MenuItem item) { - /* AW - if (!OS.RemoveMenu (handle, item.id, OS.MF_BYCOMMAND)) { - error (SWT.ERROR_ITEM_NOT_REMOVED); - } - */ - short[] index= new short[1]; - OS.GetIndMenuItemWithCommandID(handle, item.id, 1, null, index); - if (index[0] >= 1) { - OS.DeleteMenuItem(handle, index[0]); - } else - error (SWT.ERROR_ITEM_NOT_REMOVED); - - redraw (); -} - -void destroyWidget () { - int hMenu = handle; - releaseHandle (); - if (hMenu != 0) { - /* AW - OS.DestroyMenu (hMenu); - */ - OS.DisposeMenu (hMenu); - } -} - -/** - * Returns the default menu item or null if none has - * been previously set. - * - * @return the default menu item. - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getDefaultItem () { - checkWidget(); - return defaultItem; -} - -public Display getDisplay () { - Decorations parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} - -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getEnabled () { - checkWidget (); - /* AW - return (state & DISABLED) == 0; - */ - return OS.IsMenuItemEnabled(handle, (short)0); -} - -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getItem (int index) { - checkWidget (); - int[] commandID= new int[1]; - if (OS.GetMenuItemCommandID(handle, (short)(index+1), commandID) != OS.noErr) - error (SWT.ERROR_INVALID_RANGE); - return parent.findMenuItem (commandID[0]); -} - -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget (); - return OS.CountMenuItems (handle); -} - -/** - * Returns an array of <code>MenuItem</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem [] getItems () { - checkWidget (); - int index = 0; - int length = OS.CountMenuItems(handle); - MenuItem [] items = new MenuItem [length]; - /* AW - MENUITEMINFO info = new MENUITEMINFO (); - info.cbSize = MENUITEMINFO.sizeof; - info.fMask = OS.MIIM_ID; - while (OS.GetMenuItemInfo (handle, index, true, info)) { - */ - int[] commandID= new int[1]; - while (OS.GetMenuItemCommandID(handle, (short)(index+1), commandID) == OS.noErr) { - if (index == items.length) { - MenuItem [] newItems = new MenuItem [index + 4]; - System.arraycopy (newItems, 0, items, 0, index); - items = newItems; - } - items [index] = parent.findMenuItem (commandID [0]); - if (items [index] != null) - index++; - } - if (index == items.length) return items; - MenuItem [] result = new MenuItem [index]; - System.arraycopy (result, 0, items, 0, index); - return result; -} - -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; -} - -/** - * Returns the receiver's parent, which must be a <code>Decorations</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Decorations getParent () { - checkWidget (); - return parent; -} - -/** - * Returns the receiver's parent item, which must be a - * <code>MenuItem</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getParentItem () { - checkWidget (); - return cascade; -} - -/** - * Returns the receiver's parent item, which must be a - * <code>Menu</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getParentMenu () { - checkWidget (); - if (cascade != null) return cascade.parent; - return null; -} - -/** - * Returns the receiver's shell. For all controls other than - * shells, this simply returns the control's nearest ancestor - * shell. Shells return themselves, even if they are children - * of other shells. - * - * @return the receiver's shell - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getParent - */ -public Shell getShell () { - checkWidget (); - return parent.getShell (); -} - -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget (); - if ((style & SWT.BAR) != 0) { - return this == parent.menuShell ().menuBar; - } - return (state & HIDDEN) == 0; -} - -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (MenuItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - - /* AW - int index = 0; - MENUITEMINFO info = new MENUITEMINFO (); - info.cbSize = MENUITEMINFO.sizeof; - info.fMask = OS.MIIM_ID; - while (OS.GetMenuItemInfo (handle, index, true, info)) { - if (info.wID == item.id) return index; - index++; - } - */ - - int[] menu= new int[1]; - short[] index= new short[1]; - if (OS.GetIndMenuItemWithCommandID(handle, item.id, 1, menu, index) == OS.noErr) { - if (handle == menu[0]) // ensure that we found item not in submenu - return index[0]; - } - return -1; -} - -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget (); - Menu parentMenu = getParentMenu (); - if (parentMenu == null) return getEnabled (); - return getEnabled () && parentMenu.isEnabled (); -} - -/** - * Returns <code>true</code> if the receiver is visible and all - * of the receiver's ancestors are visible and <code>false</code> - * otherwise. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget (); - return getVisible (); -} - -int processHide (Object callData) { - //sendEvent (SWT.Hide); - state |= HIDDEN; - postEvent (SWT.Hide); // fix for #23947 - return 0; -} - -int processShow (Object callData) { - state &= ~HIDDEN; - sendEvent (SWT.Show); - return 0; -} - -void redraw () { - if ((style & SWT.BAR) != 0) { - //AW OS.DrawMenuBar (parent.handle); - return; - } - /* AW - if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) { - return; - } - boolean hasCheck = false, hasImage = false; - MenuItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - MenuItem item = items [i]; - if (item.getImage () != null) { - if ((hasImage = true) && hasCheck) break; - } - if ((item.getStyle () & (SWT.CHECK | SWT.RADIO)) != 0) { - if ((hasCheck = true) && hasImage) break; - } - } - if (OS.IsWinCE) return; - MENUINFO lpcmi = new MENUINFO (); - lpcmi.cbSize = MENUINFO.sizeof; - lpcmi.fMask = OS.MIM_STYLE; - OS.GetMenuInfo (handle, lpcmi); - if (hasImage && !hasCheck) { - lpcmi.dwStyle |= OS.MNS_CHECKORBMP; - } else { - lpcmi.dwStyle &= ~OS.MNS_CHECKORBMP; - } - OS.SetMenuInfo (handle, lpcmi); - */ -} - -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 = null; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the menu events are generated for the control. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuListener - * @see #addMenuListener - */ -public void removeMenuListener (MenuListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Hide, listener); - eventTable.unhook (SWT.Show, listener); -} - -/** - * Sets the default menu item to the argument or removes - * the default emphasis when the argument is <code>null</code>. - * - * @param item the default menu item or null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDefaultItem (MenuItem item) { - checkWidget(); - if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - defaultItem = item; -} - -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget (); - /* AW - state &= ~DISABLED; - if (!enabled) state |= DISABLED; - */ - if (enabled) - OS.EnableMenuItem(handle, (short)0); - else - OS.DisableMenuItem(handle, (short)0); -} - -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the display. - * <p> - * Note: This is different from most widgets where the - * location of the widget is relative to the parent. - * </p> - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (int x, int y) { - checkWidget (); - this.x = x; this.y = y; - hasLocation = true; -} - -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget (); - if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; - /* AW - int hwndParent = parent.handle; - */ - if (!visible) { - /* AW - OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0); - */ - return; - } - /* AW - int flags = OS.TPM_LEFTBUTTON | OS.TPM_RIGHTBUTTON | OS.TPM_LEFTALIGN; - */ - int nX = x, nY = y; - if (!hasLocation) { - /* AW - int pos = OS.GetMessagePos (); - nX = (short) (pos & 0xFFFF); - nY = (short) (pos >> 16); - */ - System.out.println("Menu.setVisible: nyi"); - } - /* - * Feature in Windows. It is legal use TrackPopupMenu () - * to display an empty menu as long menu items are added - * inside of WM_INITPOPUPMENU. If no items are added, then - * TrackPopupMenu () fails and does not send an indication - * that the menu has been closed. This is not strictly a - * bug but leads to unwanted behavior when application code - * assumes that every WM_INITPOPUPMENU will eventually result - * in a WM_MENUSELECT, wParam=0xFFFF0000, lParam=0 to indicate - * that the menu has been closed. The fix is to detect the - * case when TrackPopupMenu fails and the number of items in - * the menu is zero and issue a fake WM_MENUSELECT. - */ - /* AW - boolean success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null); - if (!success && GetMenuItemCount (handle) == 0) { - OS.SendMessage (hwndParent, OS.WM_MENUSELECT, 0xFFFF0000, 0); - } - */ - int defaultIndex= -1; - if (defaultItem != null) - defaultIndex= indexOf(defaultItem); - getDisplay().menuIsVisible(true); - int result= OS.PopUpMenuSelect(handle, (short)nY, (short)nX, (short)(defaultIndex+1)); - getDisplay().menuIsVisible(false); - short menuID= OS.HiWord(result); - if (menuID != 0) { - System.out.println("Menu.setVisible: should not happen"); - /* - Menu menu= getShell().findMenu(menuID); - if (menu != null) - menu.handleMenu(result); - */ - } -} - -/////////////////////////////////////////////////// -// Mac stuff -/////////////////////////////////////////////////// - - void handleMenu(int menuResult) { - int index= OS.LoWord(menuResult)-1; - if (index >= 0 && index < getItemCount()) { - MenuItem item= getItem(index); - if (item != null) - item.handleMenuSelect(); - } - } - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java deleted file mode 100644 index c3ac9d6e47..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java +++ /dev/null @@ -1,694 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.internal.carbon.*; - -/** - * Instances of this class represent a selectable user interface object - * that issues notification when pressed and released. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd> - * <dt><b>Events:</b></dt> - * <dd>Arm, Help, Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR - * may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class MenuItem extends Item { - Menu parent, menu; - int id, accelerator; - int cIconHandle; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>) and a style value - * describing its behavior and appearance. The item is added - * to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a menu control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#CHECK - * @see SWT#CASCADE - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public MenuItem (Menu parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, parent.getItemCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>), a style value - * describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a menu control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#CHECK - * @see SWT#CASCADE - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public MenuItem (Menu parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, index); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the arm events are generated for the control, by sending - * it one of the messages defined in the <code>ArmListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ArmListener - * @see #removeArmListener - */ -public void addArmListener (ArmListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Arm, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the help events are generated for the control, by sending - * it one of the messages defined in the <code>HelpListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener (SWT.Selection,typedListener); - addListener (SWT.DefaultSelection,typedListener); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -static int checkStyle (int style) { - return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0); -} - -/** - * Return the widget accelerator. An accelerator is the bit-wise - * OR of zero or more modifier masks and a key. Examples: - * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>. - * - * @return the accelerator - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getAccelerator () { - checkWidget (); - return accelerator; -} - -public Display getDisplay () { - Menu parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} - -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getEnabled () { - checkWidget (); - return OS.IsMenuCommandEnabled (parent.handle, id); -} - -/** - * Returns the receiver's cascade menu if it has one or null - * if it does not. Only <code>CASCADE</code> menu items can have - * a pull down menu. The sequence of key strokes, button presses - * and/or button releases that are used to request a pull down - * menu is platform specific. - * - * @return the receiver's menu - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getMenu () { - checkWidget (); - return menu; -} - -String getNameText () { - if ((style & SWT.SEPARATOR) != 0) return "|"; - return super.getNameText (); -} - -/** - * Returns the receiver's parent, which must be a <code>Menu</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getParent () { - checkWidget (); - return parent; -} - -/** - * Returns <code>true</code> if the receiver is selected, - * and false otherwise. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. - * - * @return the selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getSelection () { - checkWidget (); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; - char [] outMark = new char [1]; - if (OS.GetMenuCommandMark (parent.handle, id, outMark) != OS.noErr) { - error (SWT.ERROR_CANNOT_GET_SELECTION); - } - return outMark [0] != 0; -} - -void handleMenuSelect () { - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - setSelection (!getSelection ()); - } - Event event = new Event (); - /* AW - if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT; - if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= SWT.SHIFT; - if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= SWT.CONTROL; - if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= SWT.BUTTON1; - if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= SWT.BUTTON2; - if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= SWT.BUTTON3; - */ - postEvent (SWT.Selection, event); -} - -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - return getEnabled () && parent.isEnabled (); -} - -int keyGlyph (int key) { - switch (key) { - case SWT.BS: return OS.kMenuDeleteLeftGlyph; - case SWT.CR: return OS.kMenuReturnGlyph; - case SWT.DEL: return OS.kMenuDeleteRightGlyph; - case SWT.ESC: return OS.kMenuEscapeGlyph; - case SWT.LF: return OS.kMenuReturnGlyph; - case SWT.TAB: return OS.kMenuTabRightGlyph; - case ' ': return OS.kMenuBlankGlyph; -// case ' ': return OS.kMenuSpaceGlyph; - case SWT.ALT: return OS.kMenuOptionGlyph; - case SWT.SHIFT: return OS.kMenuShiftGlyph; - case SWT.CONTROL: return OS.kMenuControlISOGlyph; - case SWT.COMMAND: return OS.kMenuCommandGlyph; - case SWT.ARROW_UP: return OS.kMenuUpArrowGlyph; - case SWT.ARROW_DOWN: return OS.kMenuDownArrowGlyph; - case SWT.ARROW_LEFT: return OS.kMenuLeftArrowGlyph; - case SWT.ARROW_RIGHT: return OS.kMenuRightArrowGlyph; - case SWT.PAGE_UP: return OS.kMenuPageUpGlyph; - case SWT.PAGE_DOWN: return OS.kMenuPageDownGlyph; - case SWT.F1: return OS.kMenuF1Glyph; - case SWT.F2: return OS.kMenuF2Glyph; - case SWT.F3: return OS.kMenuF3Glyph; - case SWT.F4: return OS.kMenuF4Glyph; - case SWT.F5: return OS.kMenuF5Glyph; - case SWT.F6: return OS.kMenuF6Glyph; - case SWT.F7: return OS.kMenuF7Glyph; - case SWT.F8: return OS.kMenuF8Glyph; - case SWT.F9: return OS.kMenuF9Glyph; - case SWT.F10: return OS.kMenuF10Glyph; - case SWT.F11: return OS.kMenuF11Glyph; - case SWT.F12: return OS.kMenuF12Glyph; - } - return OS.kMenuNullGlyph; -} - -void releaseChild () { - super.releaseChild (); - if (menu != null) menu.dispose (); - menu = null; - parent.destroyItem (this); -} - -void releaseWidget () { - if (menu != null) { - menu.releaseWidget (); - menu.releaseHandle (); - } - menu = null; - super.releaseWidget (); - accelerator = 0; - Decorations shell = parent.parent; - shell.remove (this); - parent = null; - if (cIconHandle != 0) { - Image.disposeCIcon (cIconHandle); - cIconHandle = 0; - } -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the arm events are generated for the control. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ArmListener - * @see #addArmListener - */ -public void removeArmListener (ArmListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Arm, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} - -/** - * Sets the widget accelerator. An accelerator is the bit-wise - * OR of zero or more modifier masks and a key. Examples: - * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>. - * - * @param accelerator an integer that is the bit-wise OR of masks and a key - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAccelerator (int accelerator) { - checkWidget (); - short [] outIndex = new short [1]; - if (OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex) != OS.noErr) { - return; - } - boolean update = (this.accelerator == 0 && accelerator != 0) || (this.accelerator != 0 && accelerator == 0); - this.accelerator = accelerator; - boolean inSetVirtualKey = false; - int inModifiers = OS.kMenuNoModifiers, inGlyph = OS.kMenuNullGlyph, inKey = 0; - if (accelerator != 0) { - inKey = accelerator & ~(SWT.SHIFT | SWT.CONTROL | SWT.ALT | SWT.COMMAND); - if (MacUtil.KEEP_MAC_SHORTCUTS) { - if ((accelerator & SWT.COMMAND) != 0) - if (inKey == 'H' || inKey == 'Q') return; - } - inGlyph = keyGlyph (inKey); - int virtualKey = Display.untranslateKey (inKey); - if (virtualKey != 0) { - inSetVirtualKey = true; - inKey = virtualKey; - } else { - inKey = Character.toUpperCase ((char)inKey); - } - inModifiers = (byte) OS.kMenuNoCommandModifier; - if ((accelerator & SWT.SHIFT) != 0) inModifiers |= OS.kMenuShiftModifier; - if ((accelerator & SWT.CONTROL) != 0) inModifiers |= OS.kMenuControlModifier; - if ((accelerator & SWT.COMMAND) != 0) inModifiers &= ~OS.kMenuNoCommandModifier; - if ((accelerator & SWT.ALT) != 0) inModifiers |= OS.kMenuOptionModifier; - } - OS.SetMenuItemModifiers (parent.handle, outIndex [0], (byte)inModifiers); - OS.SetMenuItemCommandKey (parent.handle, outIndex [0], inSetVirtualKey, (char)inKey); - OS.SetMenuItemKeyGlyph (parent.handle, outIndex [0], (short)inGlyph); - if (update) updateText (); -} - -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget (); - if (enabled) { - OS.EnableMenuCommand (parent.handle, id); - } else { - OS.DisableMenuCommand (parent.handle, id); - } -} - -/** - * Sets the image the receiver will display to the argument. - * <p> - * Note: This feature is not available on all window systems (for example, Window NT), - * in which case, calling this method will silently do nothing. - * - * @param menu the image to display - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget (); - if ((style & SWT.SEPARATOR) != 0) return; - super.setImage (image); - if (cIconHandle != 0) Image.disposeCIcon (cIconHandle); - cIconHandle = Image.carbon_createCIcon (image); - if (cIconHandle != 0) { - short [] outIndex = new short[1]; - if (OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex) == OS.noErr) { - OS.SetMenuItemIconHandle (parent.handle, outIndex [0], (byte)4, cIconHandle); - } - } -} - -/** - * Sets the receiver's pull down menu to the argument. - * Only <code>CASCADE</code> menu items can have a - * pull down menu. The sequence of key strokes, button presses - * and/or button releases that are used to request a pull down - * menu is platform specific. - * - * @param menu the new pull down menu - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li> - * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li> - * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMenu (Menu menu) { - checkWidget (); - - /* 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.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - 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 */ - if (this.menu == menu) return; - if (this.menu != null) this.menu.cascade = null; - short [] outIndex = new short [1]; - if (OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex) != OS.noErr) { - error (SWT.ERROR_CANNOT_SET_MENU); - } - int inHierMenu = menu != null ? menu.handle : 0; - if (OS.SetMenuItemHierarchicalMenu (parent.handle, outIndex [0], inHierMenu) != OS.noErr) { - error (SWT.ERROR_CANNOT_SET_MENU); - } - if ((this.menu = menu) != null) { - menu.cascade = this; - int [] outString = new int [1]; - if (OS.CopyMenuItemTextAsCFString (parent.handle, outIndex [0], outString) != OS.noErr) { - error (SWT.ERROR_CANNOT_SET_MENU); - } - OS.SetMenuTitleWithCFString (inHierMenu, outString [0]); - OS.CFRelease (outString [0]); - } -} - -/** - * Sets the selection state of the receiver. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. - * - * @param selected the new selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (boolean selected) { - checkWidget (); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; - int inMark = selected ? ((style & SWT.RADIO) != 0) ? OS.diamondMark : OS.checkMark : 0; - if (OS.SetMenuCommandMark (parent.handle, id, (char) inMark) != OS.noErr) { - error (SWT.ERROR_CANNOT_SET_SELECTION); - } -} - -public void setText (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - super.setText (string); - updateText (); -} - -void updateText () { - if ((style & SWT.SEPARATOR) != 0) return; - short [] outIndex = new short [1]; - if (OS.GetIndMenuItemWithCommandID (parent.handle, id, 1, null, outIndex) != OS.noErr) { - error (SWT.ERROR_CANNOT_SET_TEXT); - } - char [] buffer = new char [text.length ()]; - text.getChars (0, buffer.length, buffer, 0); - int i=0, j=0; - while (i < buffer.length) { - if (accelerator != 0 && buffer [i] == '\t') break; - if ((buffer [j++] = buffer [i++]) == Mnemonic) { - if (i == buffer.length) {continue;} - if (buffer [i] == Mnemonic) {i++; continue;} - j--; - } - } - int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, j); - if (str == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - OS.SetMenuItemTextWithCFString (parent.handle, outIndex [0], str); - int [] outHierMenu = new int [1]; - OS.GetMenuItemHierarchicalMenu (parent.handle, outIndex [0], outHierMenu); - if (outHierMenu [0] != 0) OS.SetMenuTitleWithCFString (outHierMenu [0], str); - OS.CFRelease (str); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java deleted file mode 100644 index 15e2f30edf..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java +++ /dev/null @@ -1,285 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.carbon.*; - -/** - * Instances of this class are used used to inform or warn the user. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd> - * <dd>OK, OK | CANCEL</dd> - * <dd>YES | NO, YES | NO | CANCEL</dd> - * <dd>RETRY | CANCEL</dd> - * <dd>ABORT | RETRY | IGNORE</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, - * ICON_WARNING and ICON_WORKING may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class MessageBox extends Dialog { - String message = ""; - -/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public MessageBox (Shell parent) { - this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public MessageBox (Shell parent, int style) { - super (parent, checkStyle (style)); -} - -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; -} - -/** - * Returns the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @return the message - */ -public String getMessage () { - return message; -} - -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return the ID of the button that was selected to dismiss the - * message box (e.g. SWT.OK, SWT.CANCEL, etc...) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public int open () { - - /* Compute the MessageBox style */ - /* AW - int buttonBits = 0; - if ((style & SWT.OK) == SWT.OK) buttonBits = OS.MB_OK; - if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) buttonBits = OS.MB_OKCANCEL; - if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) buttonBits = OS.MB_YESNO; - if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) buttonBits = OS.MB_YESNOCANCEL; - if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) buttonBits = OS.MB_RETRYCANCEL; - if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) buttonBits = OS.MB_ABORTRETRYIGNORE; - if (buttonBits == 0) buttonBits = OS.MB_OK; - - int iconBits = 0; - if ((style & SWT.ICON_ERROR) != 0) iconBits = OS.MB_ICONERROR; - if ((style & SWT.ICON_INFORMATION) != 0) iconBits = OS.MB_ICONINFORMATION; - if ((style & SWT.ICON_QUESTION) != 0) iconBits = OS.MB_ICONQUESTION; - if ((style & SWT.ICON_WARNING) != 0) iconBits = OS.MB_ICONWARNING; - if ((style & SWT.ICON_WORKING) != 0) iconBits = OS.MB_ICONINFORMATION; - - int modalBits = 0; - if ((style & SWT.PRIMARY_MODAL) != 0) modalBits = OS.MB_APPLMODAL; - if ((style & SWT.APPLICATION_MODAL) != 0) modalBits = OS.MB_TASKMODAL; - if ((style & SWT.SYSTEM_MODAL) != 0) modalBits = OS.MB_SYSTEMMODAL; - - int bits = buttonBits | iconBits | modalBits; - */ - - short alertType; - if ((style & SWT.ICON_ERROR) != 0) - alertType= OS.kAlertStopAlert; - else if ((style & SWT.ICON_INFORMATION) != 0) - alertType= OS.kAlertNoteAlert; - else if ((style & SWT.ICON_QUESTION) != 0) - alertType= OS.kAlertNoteAlert; - else if ((style & SWT.ICON_WARNING) != 0) - alertType= OS.kAlertCautionAlert; - else if ((style & SWT.ICON_WORKING) != 0) - alertType= OS.kAlertNoteAlert; - else - alertType= OS.kAlertPlainAlert; - - - /* - * Feature in Windows. System modal is not supported - * on Windows 95 and NT. The fix is to convert system - * modal to task modal. - */ - /* AW - if ((bits & OS.MB_SYSTEMMODAL) != 0) { - bits |= OS.MB_TASKMODAL; - bits &= ~OS.MB_SYSTEMMODAL; - } - */ - - /* - * Bug in Windows. In order for MB_TASKMODAL to work, - * the parent HWND of the MessageBox () call must be NULL. - * The fix is to force the parent to be NULL when this - * style is set. - */ - /* AW - int hwndOwner = 0; - if (parent != null && (bits & OS.MB_TASKMODAL) == 0) { - hwndOwner = parent.handle; - } - */ - - /* - * Feature in Windows. The focus window is not saved and - * and restored automatically by the call to MessageBox(). - * The fix is to save and restore the focus window. - */ - /* AW - int hwndFocus = OS.GetFocus (); - */ - - /* Open the message box */ - /* Use the character encoding for the default locale */ - /* AW - TCHAR buffer1 = new TCHAR (0, message, true); - TCHAR buffer2 = new TCHAR (0, title, true); - int code = OS.MessageBox (hwndOwner, buffer1, buffer2, bits); - */ - - int errorMessage= 0; - int[] dialogRef= new int[1]; - try { - errorMessage= OS.CFStringCreateWithCharacters(message); - OS.CreateStandardAlert(alertType, errorMessage, 0, 0, dialogRef); - } finally { - if (errorMessage != 0) - OS.CFRelease(errorMessage); - } - - short[] itemHit= new short[1]; - if (dialogRef[0] != 0) - OS.RunStandardAlert(dialogRef[0], 0, itemHit); - - System.out.println("Alert code: " + itemHit[0]); - - /* Restore focus */ - /* AW - OS.SetFocus (hwndFocus); - */ - - /* - * This code is intentionally commented. On some - * platforms, the owner window is repainted right - * away when a dialog window exits. This behavior - * is currently unspecified. - */ -// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner); - - /* Compute and return the result */ - /* AW - if (code != 0) { - int type = bits & 0x0F; - if (type == OS.MB_OK) return SWT.OK; - if (type == OS.MB_OKCANCEL) { - return (code == OS.IDOK) ? SWT.OK : SWT.CANCEL; - } - if (type == OS.MB_YESNO) { - return (code == OS.IDYES) ? SWT.YES : SWT.NO; - } - if (type == OS.MB_YESNOCANCEL) { - if (code == OS.IDYES) return SWT.YES; - if (code == OS.IDNO) return SWT.NO; - return SWT.CANCEL; - } - if (type == OS.MB_RETRYCANCEL) { - return (code == OS.IDRETRY) ? SWT.RETRY : SWT.CANCEL; - } - if (type == OS.MB_ABORTRETRYIGNORE) { - if (code == OS.IDRETRY) return SWT.RETRY; - if (code == OS.IDABORT) return SWT.ABORT; - return SWT.IGNORE; - } - } - */ - return SWT.CANCEL; -} - -/** - * Sets the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @param string the message - */ -public void setMessage (String string) { - message = string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java deleted file mode 100644 index 4c4ebad6e9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java +++ /dev/null @@ -1,264 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of the receiver represent is an unselectable - * user interface object that is used to display progress, - * typically in the form of a bar. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SMOOTH, HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class ProgressBar extends Control { - - // AW - private static final int SIZE= 16; - private int fTopMargin; - private int fBottomMargin; - // AW - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SMOOTH - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ProgressBar (Composite parent, int style) { - super (parent, checkStyle (style)); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.HORIZONTAL) != 0) { - width += SIZE * 10; - height += SIZE; - } else { - width += SIZE; - height += SIZE * 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 parentHandle = parent.handle; - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)100, (short)OS.kControlProgressBarProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parentHandle, -1); - if ((style & SWT.INDETERMINATE) != 0) - OS.SetControlData(handle, (short)0, OS.kControlProgressBarIndeterminateTag, 4, new int[]{-1}); - OS.HIViewSetVisible(handle, true); -} -/* AW -void disableButtonPress () { - 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); -} -void disableTraversal () { - int [] argList = {OS.XmNtraversalOn, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -*/ -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - return OS.GetControl32BitMaximum(handle); -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - return OS.GetControl32BitMinimum(handle); -} -/** - * Returns the single <em>selection</em> that is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - return OS.GetControl32BitValue(handle); -} -/* AW -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - /* - * ProgressBars never participate in focus traversal when - * either enabled or disabled. - */ - /* AW - if (enabled) { - disableTraversal (); - disableButtonPress (); - } -} -void realizeChildren () { - super.realizeChildren (); - disableButtonPress (); -} -*/ -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitMaximum(handle, value); -} -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitMinimum(handle, value); -} -/** - * Sets the single <em>selection</em> that is the receiver's - * position to the argument which must be greater than or equal - * to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitValue(handle, value); -} - -//////////////////////////////////////////////////////// -// Mac stuff -//////////////////////////////////////////////////////// - -/** - * Overridden from Control since we want to center the bar within its area. - */ -void handleResize(int hndl, Rect bounds) { - if ((style & SWT.HORIZONTAL) != 0) { // horizontal - int diff= bounds.bottom-bounds.top-SIZE; - fTopMargin= diff/2; - fBottomMargin= diff-fTopMargin; - bounds.top+= fTopMargin; - bounds.bottom-= fBottomMargin; - } else { // vertical - int diff= bounds.right-bounds.left-SIZE; - fTopMargin= diff/2; - fBottomMargin= diff-fTopMargin; - bounds.left+= fTopMargin; - bounds.right-= fBottomMargin; - } - super.handleResize(hndl, bounds); -} - -void internalGetControlBounds(int hndl, Rect bounds) { - super.internalGetControlBounds(hndl, bounds); - if ((style & SWT.HORIZONTAL) != 0) { // horizontal - bounds.top+= -fTopMargin; - bounds.bottom-= -fBottomMargin; - } else { // vertical - bounds.left+= -fTopMargin; - bounds.right-= -fBottomMargin; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java deleted file mode 100644 index 54ccb2a25b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java +++ /dev/null @@ -1,329 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of the receiver represent a selectable user interface object - * that allows the user to drag a rubber banded outline of the sash within - * the parent control. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class Sash extends Control { - boolean dragging; - int startX, startY, lastX, lastY; - - private static final int SASH_WIDTH= 3; - - private static int H_ARROW; - private static int V_ARROW; - - static { - short[] h= new short[] { - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x2310, - (short) 0x6318, - (short) 0xFB7C, - (short) 0x6318, - (short) 0x2310, - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x0300, - (short) 0x0000 - }; - H_ARROW= OS.NewCursor((short)6, (short)7, h, h); - - h= new short[] { - (short) 0x0100, - (short) 0x0380, - (short) 0x07C0, - (short) 0x0100, - (short) 0x0100, - (short) 0x0000, - (short) 0xFFFE, - (short) 0xFFFE, - (short) 0x0000, - (short) 0x0100, - (short) 0x0100, - (short) 0x07C0, - (short) 0x0380, - (short) 0x0100, - (short) 0x0000, - (short) 0x0000 - }; - V_ARROW= OS.NewCursor((short)7, (short)6, h, h); - } - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Sash (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid. - * If the reciever is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.HORIZONTAL) != 0) { - width += DEFAULT_WIDTH; height += SASH_WIDTH; - } else { - width += SASH_WIDTH; 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; - /* AW - int [] argList = { - OS.XmNborderWidth, border, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNancestorSensitive, 1, - }; - */ - handle= OS.NewControl(0, new Rect(), null, false, (short)(OS.kControlSupportsFocus | OS.kControlGetsFocusOnClick), (short)0, (short)0, (short)OS.kControlUserPaneProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - OS.HIViewSetVisible(handle, true); -} -int defaultBackground () { - return getDisplay ().labelBackground; -} -void drawBand (int x, int y, int width, int height) { - GC gc= new GC(getParent()); // we draw outside of the Sash's bounds in its parent - gc.carbon_setClipAgainstChildren(false); // we don't want to be clipped against our children - gc.setXORMode(true); - gc.fillRectangle(x, y, width, height); - gc.dispose(); -} -void hookEvents () { - super.hookEvents (); - Display display= getDisplay(); - - final int SIZEOF_INT= 4; - int[] data= new int[] { display.fUserPaneHitTestProc }; - OS.SetControlData(handle, OS.kControlEntireControl, OS.kControlUserPaneHitTestProcTag, data.length*SIZEOF_INT, data); - - int[] mask= new int[] { - OS.kEventClassControl, OS.kEventControlDraw, - }; - OS.InstallEventHandler(OS.GetControlEventTarget(handle), display.fControlProc, mask.length/2, mask, handle, null); -} -int processMouseDown (MacMouseEvent mmEvent) { - super.processMouseDown (mmEvent); - - Point mp= MacUtil.toControl(parent.handle, mmEvent.getWhere()); - startX = mp.x; startY = mp.y; - - Rect bounds= new Rect(); - MacUtil.getControlBounds(handle, bounds); - int width = bounds.right-bounds.left, height = bounds.bottom-bounds.top; - - Rect parentBounds= new Rect(); - MacUtil.getControlBounds(parent.handle, parentBounds); - - lastX = bounds.left-parentBounds.left; - lastY = bounds.top-parentBounds.top; - - 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; - drawBand (lastX = event.x, lastY = event.y, width, height); - } - return 0; -} -int processMouseMove (MacMouseEvent mmEvent) { - super.processMouseMove (mmEvent); - - getDisplay().setCursor((style & SWT.VERTICAL) != 0 ? H_ARROW : V_ARROW); - - if (!dragging || (mmEvent.getButton() != 1)) return 0; - Point mp= MacUtil.toControl(parent.handle, mmEvent.getWhere()); - - Rect bounds= new Rect(); - MacUtil.getControlBounds(handle, bounds); - int width = bounds.right-bounds.left, height = bounds.bottom-bounds.top; - - Rect parentBounds= new Rect(); - MacUtil.getControlBounds(parent.handle, parentBounds); - - int x = bounds.left-parentBounds.left, y = bounds.top-parentBounds.top; - - int newX = lastX, newY = lastY; - if ((style & SWT.VERTICAL) != 0) { - newX = Math.min (Math.max (0, x + (mp.x - startX)), parentBounds.right - parentBounds.left - width); - } else { - newY = Math.min (Math.max (0, y + (mp.y - startY)), parentBounds.bottom - parentBounds.top - 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; - drawBand (lastX, lastY, width, height); - } - return 0; -} -int processMouseUp (MacMouseEvent mmEvent) { - super.processMouseUp (mmEvent); - - if (mmEvent.getButton() != 1) return 0; - if (!dragging) return 0; - dragging = false; - - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - int width = bounds.right-bounds.left, height = bounds.bottom-bounds.top; - - 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; -} -int processPaint (Object callData) { - GC gc= new GC(this); - MacControlEvent me= (MacControlEvent) callData; - Rectangle r= gc.carbon_focus(me.getDamageRegionHandle(), me.getGCContext()); - if (! r.isEmpty()) { - Point e= getSize(); - gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY)); - if (e.x < e.y) // vertical - gc.fillRectangle ((e.x-1)/2, (e.y-20)/2, 1, 20); - else // horizontal - gc.fillRectangle ((e.x-20)/2, (e.y-1)/2, 20, 1); - } - gc.carbon_unfocus(); - gc.dispose(); - return OS.noErr; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - 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/carbon/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java deleted file mode 100644 index 226aedbea1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java +++ /dev/null @@ -1,363 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of the receiver represent a selectable user - * interface object that present a range of continuous - * numeric values. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public /*final*/ class Scale extends Control { - - private int increment= 1; - private int pageIncrement= 10; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Scale (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's value changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - 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; - /* AW - 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, - OS.XmNancestorSensitive, 1, - }; - */ - short procID= (short)(OS.kControlSliderProc + OS.kControlSliderLiveFeedback + OS.kControlSliderNonDirectional); - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)100, procID, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - OS.HIViewSetVisible(handle, true); -} - -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget(); - return increment; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - return OS.GetControl32BitMaximum(handle); -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - return OS.GetControl32BitMinimum(handle); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget(); - return pageIncrement; -} -/** - * Returns the single <em>selection</em> that is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - return OS.GetControl32BitValue(handle); -} -void hookEvents () { - super.hookEvents (); - /* AW - int windowProc = getDisplay ().windowProc; - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection); - OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection); - */ - OS.SetControlAction(handle, getDisplay().fControlActionProc); -} -int processSelection (Object callData) { - - MacControlEvent macEvent= (MacControlEvent) callData; - - Event event = new Event (); - if (macEvent.getPartCode() == OS.kControlIndicatorPart) { // end of drag or continuos drag - if (macEvent.isMouseDown()) { - event.detail = SWT.DRAG; // continuos drag - } else { - /* - * Do not set the detail field to SWT.DRAG - * to indicate that the dragging has ended. - */ - } - } - - sendEvent (SWT.Selection, event); - - /* AW FIXME: may be we need the following here too... - if (macEvent.isMouseDown()) { - int wHandle= OS.GetControlOwner(handle); - if (wHandle != 0) { - getDisplay().updateWindow(wHandle); - } - } - */ - return 0; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's value changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed to the argument, which must be at least - * one. - * - * @param value the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int value) { - checkWidget(); - if (value < 1) return; - increment= value; -} -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - if (OS.GetControl32BitValue(handle) > value) - OS.SetControl32BitValue(handle, value); - OS.SetControl32BitMaximum(handle, value); -} -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - if (OS.GetControl32BitValue(handle) < value) - OS.SetControl32BitValue(handle, value); - OS.SetControl32BitMinimum(handle, value); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected to the argument, which must be at least - * one. - * - * @return the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int value) { - checkWidget(); - if (value < 1) return; - pageIncrement= value; -} -/** - * Sets the single <em>selection</em> that is the receiver's - * value to the argument which must be greater than or equal - * to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitValue(handle, value); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java deleted file mode 100644 index 9db1e96489..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java +++ /dev/null @@ -1,494 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; - -/** - * Instances of this class are selectable user interface - * objects that represent a range of positive, numeric values. - * <p> - * At any given moment, a given slider will have a - * single <em>selection</em> that is considered to be its - * value, which is constrained to be within the range of - * values the slider represents (that is, between its - * <em>minimum</em> and <em>maximum</em> values). - * </p><p> - * Typically, sliders will be made up of five areas: - * <ol> - * <li>an arrow button for decrementing the value</li> - * <li>a page decrement area for decrementing the value by a larger amount</li> - * <li>a <em>thumb</em> for modifying the value by mouse dragging</li> - * <li>a page increment area for incrementing the value by a larger amount</li> - * <li>an arrow button for incrementing the value</li> - * </ol> - * Based on their style, sliders are either <code>HORIZONTAL</code> - * (which have a left facing button for decrementing the value and a - * right facing button for incrementing it) or <code>VERTICAL</code> - * (which have an upward facing button for decrementing the value - * and a downward facing buttons for incrementing it). - * </p><p> - * On some platforms, the size of the slider's thumb can be - * varied relative to the magnitude of the range of values it - * represents (that is, relative to the difference between its - * maximum and minimum values). Typically, this is used to - * indicate some proportional value such as the ratio of the - * visible area of a document to the total amount of space that - * it would take to display it. SWT supports setting the thumb - * size even if the underlying platform does not, but in this - * case the appearance of the slider will not change. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see ScrollBar - */ -public /*final*/ class Slider extends Control { - private int fIncrement= 1; // AW - private int fPageIncrement= 10; // AW -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Slider (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's value changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values: - * <code>0</code> - for the end of a drag. - * <code>SWT.DRAG</code>. - * <code>SWT.HOME</code>. - * <code>SWT.END</code>. - * <code>SWT.ARROW_DOWN</code>. - * <code>SWT.ARROW_UP</code>. - * <code>SWT.PAGE_DOWN</code>. - * <code>SWT.PAGE_UP</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - 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; - /* AW - int [] argList = { - OS.XmNancestorSensitive, 1, - 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); - */ - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)100, (short)OS.kControlScrollBarLiveProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - OS.HIViewSetVisible(handle, true); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget(); - return fIncrement; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - return OS.GetControl32BitMaximum(handle); -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - return OS.GetControl32BitMinimum(handle); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget(); - return fPageIncrement; -} -/** - * Returns the single <em>selection</em> that is the receiver's value. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - return OS.GetControl32BitValue(handle); -} -/** - * Returns the size of the receiver's thumb relative to the - * difference between its maximum and minimum values. - * - * @return the thumb value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getThumb () { - checkWidget(); - return OS.GetControlViewSize(handle); -} -void hookEvents () { - super.hookEvents (); - /* AW - 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); - */ - OS.SetControlAction(handle, getDisplay().fControlActionProc); -} -int processSelection (Object callData) { - - MacControlEvent macEvent= (MacControlEvent) callData; - if (! macEvent.isMouseDown()) - return 0; - - Event event = new Event (); - switch (macEvent.getPartCode()) { - case OS.kControlUpButtonPart: - OS.SetControl32BitValue(handle, OS.GetControl32BitValue(handle) - fIncrement); - event.detail = SWT.ARROW_UP; - break; - case OS.kControlPageUpPart: - OS.SetControl32BitValue(handle, OS.GetControl32BitValue(handle) - fPageIncrement); - event.detail = SWT.PAGE_UP; - break; - case OS.kControlPageDownPart: - OS.SetControl32BitValue(handle, OS.GetControl32BitValue(handle) + fPageIncrement); - event.detail = SWT.PAGE_DOWN; - break; - case OS.kControlDownButtonPart: - OS.SetControl32BitValue(handle, OS.GetControl32BitValue(handle) + fIncrement); - event.detail = SWT.ARROW_DOWN; - break; - case OS.kControlIndicatorPart: // end of drag or continuos drag - if (macEvent.isMouseDown()) - event.detail = SWT.DRAG; // continuos drag - else { - /* - * Do not set the detail field to SWT.DRAG - * to indicate that the dragging has ended. - */ - } - break; - } - - sendEvent (SWT.Selection, event); - - /* AW FIXME: may be we need the following here too... - if (macEvent.isMouseDown()) { - int wHandle= OS.GetControlOwner(handle); - if (wHandle != 0) { - getDisplay().updateWindow(wHandle); - } - } - */ - - return 0; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's value changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed to the argument, which must be at least - * one. - * - * @param value the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int value) { - checkWidget(); - if (value < 1) return; - fIncrement= value; -} -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitMaximum(handle, value); -} -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitMinimum(handle, value); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected to the argument, which must be at least - * one. - * - * @return the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int value) { - checkWidget(); - if (value < 1) return; - fPageIncrement= value; -} -/** - * Sets the single <em>selection</em> that is the receiver's - * value to the argument which must be greater than or equal - * to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget(); - if (value < 0) return; - OS.SetControl32BitValue(handle, value); -} -/** - * Sets the size of the receiver's thumb relative to the - * difference between its maximum and minimum values to the - * argument which must be at least one. - * - * @param value the new thumb value (must be at least one) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ScrollBar - */ -public void setThumb (int value) { - checkWidget(); - if (value < 1) return; - OS.SetControlViewSize(handle, value); -} -/** - * Sets the receiver's selection, minimum value, maximum - * value, thumb, increment and page increment all at once. - * <p> - * Note: This is equivalent to setting the values individually - * using the appropriate methods, but may be implemented in a - * more efficient fashion on some platforms. - * </p> - * - * @param selection the new selection value - * @param minimum the new minimum value - * @param maximum the new maximum value - * @param thumb the new thumb value - * @param increment the new increment value - * @param pageIncrement the new pageIncrement value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { - checkWidget(); - 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; - OS.SetControl32BitMinimum(handle, minimum); - OS.SetControl32BitMaximum(handle, maximum); - OS.SetControlViewSize(handle, thumb); - OS.SetControl32BitValue(handle, selection); - fIncrement= increment; - fPageIncrement= pageIncrement; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java deleted file mode 100644 index 7d1101d141..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java +++ /dev/null @@ -1,682 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; -import org.eclipse.swt.internal.carbon.ControlTabInfoRecV1; - -/** - * Instances of this class implement the notebook user interface - * metaphor. It allows the user to select a notebook page from - * set of pages. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TabItem</code>. - * <code>Control</code> children are created and then set into a - * tab item using <code>TabItem#setControl</code>. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class TabFolder extends Composite { - - private static final int TAB_HEIGHT= 32; - private static final int TOP_MARGIN= 1; - private static final int MARGIN= 4; - - TabItem [] items; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabFolder (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the item field of the event object is valid. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget (); - 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) { - /* - * 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 Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - /* AW - RECT insetRect = new RECT (), itemRect = new RECT (); - OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, insetRect); - int width = insetRect.left - insetRect.right, height = 0; - int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0); - if (count != 0) { - OS.SendMessage (handle, OS.TCM_GETITEMRECT, count - 1, itemRect); - width = Math.max (width, itemRect.right - insetRect.right); - } - */ - int width= 100; // AW a bogus guess - int height= 0; - - Point size; - 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); - width = trim.width; height = trim.height; - return new Point (width, height); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget (); - /* AW - RECT rect = new RECT (); - OS.SetRect (rect, x, y, x + width, y + height); - OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 1, rect); - */ - /* AW - int border = getBorderWidth (); - rect.left -= border; rect.right += border; - rect.top -= border; rect.bottom += border; - int newWidth = rect.right - rect.left; - int newHeight = rect.bottom - rect.top; - return new Rectangle (rect.left, rect.top, newWidth, newHeight); - */ - return new Rectangle (x-MARGIN, y-TOP_MARGIN-TAB_HEIGHT, width+(2*MARGIN), height+TOP_MARGIN+TAB_HEIGHT+MARGIN); -} - -void createItem (TabItem item, int index) { - int count = OS.GetControl32BitMaximum(handle); - - if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); - if (count == items.length) { - TabItem [] newItems = new TabItem [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - /* AW - TCITEM tcItem = new TCITEM (); - if (OS.SendMessage (handle, OS.TCM_INSERTITEM, index, tcItem) == -1) { - error (SWT.ERROR_ITEM_NOT_ADDED); - } - */ - OS.SetControl32BitMaximum(handle, count+1); - - System.arraycopy (items, index, items, index + 1, count - index); - items [index] = item; - - /* - * Send a selection event when the item that is added becomes - * the new selection. This only happens when the first item - * is added. - */ - if (count == 0) { - Event event = new Event (); - event.item = items [0]; - sendEvent (SWT.Selection, event); - // the widget could be destroyed at this point - } -} -void createHandle (int index) { - state |= HANDLE; - state &= ~CANVAS; - handle= OS.NewControl(0, new Rect(), null, false, (short)0, (short)0, (short)0, (short)OS.kControlTabSmallProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parent.handle, -1); - OS.HIViewSetVisible(handle, true); -} - -void createWidget (int index) { - super.createWidget (index); - items = new TabItem [4]; -} - -void destroyItem (TabItem item) { - int count = OS.GetControl32BitMaximum(handle); - int index = 0; - while (index < count) { - if (items [index] == item) break; - index++; - } - if (index == count) return; // not found - int selectionIndex = OS.GetControl32BitValue(handle)-1; - - /* AW - if (OS.SendMessage (handle, OS.TCM_DELETEITEM, index, 0) == 0) { - error (SWT.ERROR_ITEM_NOT_REMOVED); - } - */ - OS.SetControl32BitMaximum(handle, count-1); - - System.arraycopy (items, index + 1, items, index, --count - index); - items [count] = null; - if (count == 0) { - /* AW - if (imageList != null) { - OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0); - Display display = getDisplay (); - display.releaseImageList (imageList); - } - imageList = null; - */ - items = new TabItem [4]; - } - - updateCarbon(index); - - if (count > 0 && index == selectionIndex) { - setSelection (Math.max (0, selectionIndex - 1)); - selectionIndex = getSelectionIndex (); - if (selectionIndex != -1) { - Event event = new Event (); - event.item = items [selectionIndex]; - sendEvent (SWT.Selection, event); - // the widget could be destroyed at this point - } - } -} - -public Rectangle getClientArea () { - checkWidget (); - /* AW - if (parent.hdwp != 0) { - int oldHdwp = parent.hdwp; - parent.hdwp = 0; - OS.EndDeferWindowPos (oldHdwp); - int count = parent.getChildrenCount (); - parent.hdwp = OS.BeginDeferWindowPos (count); - } - RECT rect = new RECT (); - OS.GetClientRect (handle, rect); - OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, rect); - int width = rect.right - rect.left; - int height = rect.bottom - rect.top; - return new Rectangle (rect.left, rect.top, width, height); - */ - Rect inner= new Rect(); - OS.GetControlData(handle, (short)OS.kControlEntireControl, OS.kControlTabContentRectTag, Rect.sizeof, inner, null); - Rectangle r= new Rectangle(inner.left, inner.top, inner.right-inner.left, inner.bottom-inner.top); - // never return negative values - if (r.x < 0) r.x= 0; - if (r.y < 0) r.y= 0; - if (r.width < 0) r.width= 0; - if (r.height < 0) r.height= 0; - return r; -} - -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TabItem getItem (int index) { - checkWidget (); - int count = OS.GetControl32BitMaximum(handle); - if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); - return items [index]; -} - -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget (); - return OS.GetControl32BitMaximum(handle); -} - -/** - * Returns an array of <code>TabItem</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TabItem [] getItems () { - checkWidget (); - int count = OS.GetControl32BitMaximum(handle); - int n= 0; - for (int i=0; i < count; i++) - if (items[i] != null) - n++; - if (n < count) - System.out.println("TabFolder.getItems: found null slots"); - TabItem [] result = new TabItem [n]; - for (int i=0; i < n; i++) - if (items[i] != null) - result[i]= items[i]; - //System.arraycopy (items, 0, result, 0, count); - return result; -} - -/** - * Returns an array of <code>TabItem</code>s that are currently - * selected in the receiver. An empty array indicates that no - * items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return an array representing the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TabItem [] getSelection () { - checkWidget (); - int index= OS.GetControl32BitValue(handle)-1; - if (index == -1) return new TabItem [0]; - return new TabItem [] {items [index]}; -} - -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver, or -1 if no item is selected. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget (); - return OS.GetControl32BitValue(handle)-1; -} -void hookEvents () { - super.hookEvents (); - int[] mask= new int[] { - OS.kEventClassControl, OS.kEventControlHit, - }; - OS.InstallEventHandler(OS.GetControlEventTarget(handle), getDisplay().fControlProc, mask.length/2, mask, handle, null); -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (TabItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - int count = OS.GetControl32BitMaximum(handle); - for (int i=0; i<count; i++) { - if (items [i] == item) return i; - } - return -1; -} -/* AW -boolean mnemonicHit (char key) { - for (int i=0; i<items.length; i++) { - TabItem item = items [i]; - if (item != null) { - char ch = findMnemonic (item.getText ()); - if (Character.toUpperCase (key) == Character.toUpperCase (ch)) { - if (setFocus ()) { - setSelection (i, true); - return true; - } - } - } - } - return false; -} -boolean mnemonicMatch (char key) { - for (int i=0; i<items.length; i++) { - TabItem item = items [i]; - if (item != null) { - char ch = findMnemonic (item.getText ()); - if (Character.toUpperCase (key) == Character.toUpperCase (ch)) { - return true; - } - } - } - return false; -} -*/ -int processSelection (Object callData) { - int newIndex= OS.GetControl32BitValue(handle)-1; - for (int i= 0; i < items.length; i++) { - if (i != newIndex && items[i] != null) { - Control control = items[i].control; - if (control != null && !control.isDisposed ()) - control.setVisible (false); - } - } - TabItem item = null; - if (newIndex != -1) item = items [newIndex]; - if (item != null) { - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); - control.setVisible (true); - } - } - Event event = new Event (); - event.item = item; - postEvent (SWT.Selection, event); - redraw(); - return OS.noErr; -} -void releaseWidget () { - int count = OS.GetControl32BitMaximum(handle); - for (int i=0; i<count; i++) { - TabItem item = items [i]; - if (item != null && !item.isDisposed ()) item.releaseWidget (); - } - items = null; - super.releaseWidget (); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} - -/** - * Sets the receiver's selection to be the given array of items. - * The current selected is first cleared, then the new items are - * selected. - * - * @param items the array of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (TabItem [] items) { - checkWidget (); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - if (items.length == 0) { - setSelection (-1); - return; - } - for (int i=items.length-1; i>=0; --i) { - int index = indexOf (items [i]); - if (index != -1) setSelection (index); - } -} - -/** - * Selects the item at the given zero-relative index in the receiver. - * If the item at the index was already selected, it remains selected. - * The current selected is first cleared, then the new items are - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int index) { - checkWidget (); - setSelection (index, false); -} - -void setSelection (int index, boolean notify) { - int currentIndex = OS.GetControl32BitValue(handle) - 1; - if (currentIndex != -1) { - TabItem item = items [currentIndex]; - if (item != null) { - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setVisible (false); - } - } - } - OS.SetControl32BitValue(handle, index+1); - index = OS.GetControl32BitValue(handle)-1; - if (index != -1) { - TabItem item = items [index]; - if (item != null) { - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); - control.setVisible (true); - } - if (notify) { - Event event = new Event (); - event.item = item; - sendEvent (SWT.Selection, event); - } - } - } - redraw(); -} - -void setTabText(int index, String string) { - int sHandle= 0; - try { - String t= MacUtil.removeMnemonics(string); - sHandle= OS.CFStringCreateWithCharacters(t); - ControlTabInfoRecV1 tab= new ControlTabInfoRecV1(); - tab.version= (short) OS.kControlTabInfoVersionOne; - tab.iconSuiteID= 0; - tab.name= sHandle; - OS.SetControlData(handle, index+1, OS.kControlTabInfoTag, ControlTabInfoRecV1.sizeof, tab); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } -} - -void setTabImage(int index, Image image) { - /* AW: does not work yet... - int icon= Image.carbon_createCIcon(image); - if (icon != 0) - if (OS.setTabIcon(handle, index+1, icon) != OS.noErr) - System.err.println("TabFolder.setTabImage: error"); - */ -} - -boolean traversePage (boolean next) { - int count = getItemCount (); - if (count == 0) return false; - int index = getSelectionIndex (); - if (index == -1) { - index = 0; - } else { - int offset = (next) ? 1 : -1; - index = (index + offset + count) % count; - } - setSelection (index, true); - return index == getSelectionIndex (); -} - -////////////////////////////////////////////////// -// Mac stuff -////////////////////////////////////////////////// - -private void updateCarbon(int startIndex) { - int n= OS.GetControl32BitMaximum(handle); - for (int i= startIndex; i < n; i++) { - TabItem item= items[i]; - if (item != null) - setTabText(i, item.getText()); - } -} - -void internalGetControlBounds(int hndl, Rect bounds) { - super.internalGetControlBounds(hndl, bounds); - bounds.left += -MARGIN; - bounds.top += -TOP_MARGIN; - bounds.right -= -MARGIN; - bounds.bottom -= -MARGIN; -} - -/** - * Overridden from Control. - * x and y are relative to window! - */ -void handleResize(int hndl, Rect bounds) { - - bounds.left+= MARGIN; - bounds.right-= MARGIN; - bounds.top+= TOP_MARGIN; - bounds.bottom-= MARGIN; - super.handleResize(hndl, bounds); - - if (handle != 0) { - int selectedIndex= OS.GetControl32BitValue(handle)-1; - if (selectedIndex != -1) { - Control control = items[selectedIndex].getControl(); - if (control != null && !control.isDisposed()) { - control.setBounds(getClientArea()); - } - } - redraw(); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java deleted file mode 100644 index b0e34f0ae5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java +++ /dev/null @@ -1,248 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a selectable user interface object - * corresponding to a tab for a page in a tab folder. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class TabItem extends Item { - TabFolder parent; - Control control; - String toolTipText; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>TabFolder</code>) and a style value - * describing its behavior and appearance. The item is added - * to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabItem (TabFolder parent, int style) { - super (parent, style); - this.parent = parent; - parent.createItem (this, parent.getItemCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>TabFolder</code>), a style value - * describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabItem (TabFolder 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); -} - -/** - * Returns the control that is used to fill the client area of - * the tab folder when the user selects the tab item. If no - * control has been set, return <code>null</code>. - * <p> - * @return the control - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Control getControl () { - checkWidget(); - return control; -} - -public Display getDisplay () { - TabFolder parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} -/** - * Returns the receiver's parent, which must be a <code>TabFolder</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TabFolder getParent () { - checkWidget(); - return parent; -} - -/** - * Returns the receiver's tool tip text, or null if it has - * not been set. - * - * @return the receiver's tool tip text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getToolTipText () { - checkWidget(); - return toolTipText; -} - -void releaseChild () { - super.releaseChild (); - int index = parent.indexOf (this); - if (index == parent.getSelectionIndex ()) { - if (control != null) control.setVisible (false); - } - parent.destroyItem (this); -} - -void releaseWidget () { - super.releaseWidget (); - control = null; - parent = null; -} - -/** - * Sets the control that is used to fill the client area of - * the tab folder when the user selects the tab item. - * <p> - * @param control the new control (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setControl (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); - } - if (this.control != null && this.control.isDisposed ()) { - this.control = null; - } - 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); -} - -public void setImage (Image image) { - checkWidget(); - int index = parent.indexOf (this); - if (index == -1) return; - super.setImage (image); - getParent().setTabImage(index, image); -} - -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int index = parent.indexOf (this); - if (index == -1) return; - super.setText (string); - //getParent().updateCarbon(index); - getParent().setTabText(index, string); -} - -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that no tool tip text should be shown. - * - * @param string the new tool tip text (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setToolTipText (String string) { - checkWidget(); - toolTipText = string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java deleted file mode 100644 index d95d5647cf..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java +++ /dev/null @@ -1,1628 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; -import org.eclipse.swt.internal.carbon.EventRecord; -import org.eclipse.swt.internal.carbon.TXNLongRect; - -/** - * Instances of this class are selectable user interface - * objects that allow the user to enter and modify text. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>MULTI, SINGLE, READ_ONLY, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Modify, Verify</dd> - * </dl> - * <p> - * Note: Only one of the styles MULTI and SINGLE may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Text extends Scrollable { - private static final int FOCUS_BORDER= 3; - private static final int MARGIN= 0; // 2; - - private int textLimit= LIMIT; - private int tx; - private int txFrameID; - private Rectangle txFrameBounds; - private boolean txVisible= true; - - char echoCharacter; - - 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"; - } - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SINGLE - * @see SWT#MULTI - * @see SWT#READ_ONLY - * @see SWT#WRAP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Text (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the <code>ModifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is not called for texts. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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 the collection of listeners who will - * be notified when the receiver's text is verified, by sending - * it one of the messages defined in the <code>VerifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #removeVerifyListener - */ -public void addVerifyListener (VerifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Verify, typedListener); -} -/** - * Appends a string. - * <p> - * The new text is appended to the text at - * the end of the widget. - * </p> - * - * @param string the string to be appended - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void append (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - string = Display.convertToLf (string); - int length = OS.TXNDataSize(tx) / 2; - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - string = verifyText (string, length, length); - if (string == null) return; - } - replaceTXNText(OS.kTXNEndOffset, OS.kTXNEndOffset, string); -} -static int checkStyle (int style) { - style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); - 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. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void clearSelection () { - checkWidget(); - syncBounds(); - OS.TXNSetSelection(tx, OS.kTXNStartOffset, OS.kTXNStartOffset); // AW todo: wrong -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int width = wHint; - int height = hHint; - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - int size= OS.TXNDataSize(tx); - if (size == 0) { - if (hHint == SWT.DEFAULT) { - if ((style & SWT.SINGLE) != 0) { - TXNLongRect oTextRect= new TXNLongRect(); - OS.TXNGetRectBounds(tx, null, null, oTextRect); - height= oTextRect.bottom - oTextRect.top; - } else { - height= DEFAULT_HEIGHT; - } - } - if (wHint == SWT.DEFAULT) - width= DEFAULT_WIDTH; - } else { - TXNLongRect oTextRect = new TXNLongRect(); - OS.TXNGetRectBounds(tx, null, null, oTextRect); - if (hHint == SWT.DEFAULT) - height= oTextRect.bottom - oTextRect.top; - if (wHint == SWT.DEFAULT) - width= oTextRect.right - oTextRect.left; - } - } - if (horizontalBar != null) { - height += 15; - } - if (verticalBar != null) { - width += 15; - } - /* AW - XRectangle rect = new XRectangle (); - OS.XmWidgetGetDisplayRect (handle, rect); - width += rect.x * 2; height += rect.y * 2; - if ((style & (SWT.MULTI | SWT.BORDER)) != 0) height++; - */ - // AW - width += 2*MARGIN; - height += 2*MARGIN; - if ((style & SWT.BORDER) != 0) { - width += 2*FOCUS_BORDER; - height += 2*FOCUS_BORDER; - } - // AW - return new Point (width, height); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - Rectangle trim = super.computeTrim(x, y, width, height); - /* AW - XRectangle rect = new XRectangle (); - OS.XmWidgetGetDisplayRect (handle, rect); - trim.x -= rect.x; - trim.y -= rect.y; - trim.width += rect.x; - trim.height += rect.y; - */ - /* AW - if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3; - */ - // AW - if ((style & SWT.BORDER) != 0) { - trim.x -= FOCUS_BORDER; - trim.y -= FOCUS_BORDER; - trim.width += FOCUS_BORDER; - trim.height += FOCUS_BORDER; - } - // AW - return trim; -} -/** - * Copies the selected text. - * <p> - * The current selection is copied to the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void copy () { - checkWidget(); - OS.TXNCopy(tx); -} -void createHandle (int index) { - state |= HANDLE; - /* AW - 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.XmNancestorSensitive, 1, - }; - */ - int frameOptions= OS.kTXNDontDrawCaretWhenInactiveMask | OS.kTXNMonostyledTextMask; - if ((style & SWT.H_SCROLL) != 0) - frameOptions |= OS.kTXNWantHScrollBarMask; - if ((style & SWT.V_SCROLL) != 0) - frameOptions |= OS.kTXNWantVScrollBarMask; - if ((style & SWT.SINGLE) != 0) - frameOptions |= OS.kTXNSingleLineOnlyMask; - if ((style & SWT.READ_ONLY) != 0) - frameOptions |= OS.kTXNReadOnlyMask; - if ((style & SWT.WRAP) != 0) - frameOptions |= OS.kTXNAlwaysWrapAtViewEdgeMask; - - int parentHandle= parent.handle; - handle= OS.NewControl(0, new Rect(), null, false, (short)(OS.kControlSupportsEmbedding | OS.kControlSupportsFocus | OS.kControlGetsFocusOnClick), (short)0, (short)0, (short)OS.kControlUserPaneProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parentHandle, -1); - OS.HIViewSetVisible(handle, true); - - /* - * Since MLTE is no real control it must embed its scrollbars in the root control. - * However, this breaks SWT assumption that everything is a nice and clean hierarchy. - * To work around this problem we try to move the scrollbars from the root control - * to the real parent of the Text widget. - * This is done in two steps: before creating the MLTE object with TXNNewObject - * we count the number of controls under the root control. Second step: see below. - */ - int wHandle= OS.GetControlOwner(parentHandle); - int[] rootHandle= new int[1]; - OS.GetRootControl(wHandle, rootHandle); - int root= rootHandle[0]; - short[] cnt= new short[1]; - OS.CountSubControls(root, cnt); - short oldCount= cnt[0]; - - /* - * Create the MLTE object (and possibly 0-2 scrollbars) - */ - int frameType= OS.kTXNTextEditStyleFrameType; - int iFileType= OS.kTXNUnicodeTextFile; - int iPermanentEncoding= OS.kTXNSystemDefaultEncoding; - int[] tnxObject= new int[1]; - int[] frameID= new int[1]; - Rect bounds= new Rect(); - MacUtil.getControlBounds(handle, bounds); - int status= OS.TXNNewObject(0, wHandle, bounds, frameOptions, frameType, iFileType, - iPermanentEncoding, tnxObject, frameID, handle); - if (status != OS.noErr) - error(SWT.ERROR_NO_HANDLES); - - /* - * Second step: count the controls under root again to find out how many - * scrollbars had been added. Then move these new controls under the user pane - */ - short[] newCnt= new short[1]; - OS.CountSubControls(root, newCnt); - short newCount= newCnt[0]; - int[] child= new int[1]; - for (short i= newCount; i > oldCount; i--) { - int rc= OS.GetIndexedSubControl(root, i, child); - //OS.HIViewRemoveFromSuperview(child[0]); - OS.HIViewAddSubview(handle, child[0]); - //WidgetTable.put(child[0], this); - } - - tx= tnxObject[0]; - txFrameID= frameID[0]; - OS.TXNActivate(tx, txFrameID, OS.kScrollBarsSyncWithFocus); - - OS.TXNFocus(tx, false); - /* - * If the widget remains empty the caret will be too short. - * As a workaround initialize the widget with a single character - * and immediately remove it afterwards. - */ - OS.TXNSetData(tx, OS.kTXNUnicodeTextData, new char[] { ' ' }, 2, 0, 0); - OS.TXNSetData(tx, OS.kTXNUnicodeTextData, new char[0], 0, 0, 1); - - Rect margins= new Rect(); - margins.top= margins.left= margins.bottom= margins.right= MARGIN; - int ptr= OS.NewPtr(Rect.sizeof); - OS.memcpy(ptr, margins, Rect.sizeof); - OS.TXNSetTXNObjectControls(tx, false, 1, new int[] { OS.kTXNMarginsTag }, new int[] {ptr}); - OS.DisposePtr(ptr); - OS.TXNSetTXNObjectControls(tx, false, 1, new int[] { OS.kTXNDoFontSubstitution }, new int[] { 1 }); -} -ScrollBar createScrollBar (int type) { - return createStandardBar (type); -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void cut () { - checkWidget(); - syncBounds(); - OS.TXNCut(tx); -} -void destroyWidget () { - super.destroyWidget(); - if (tx != 0) { - //System.out.println("Text.destroyWidget"); - OS.TXNDeleteObject(tx); - tx= 0; - } -} -int defaultBackground () { - return getDisplay ().textBackground; -} -Font 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. - * </p> - * - * @return the line number - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCaretLineNumber () { - checkWidget(); - /* AW - return getLineNumber (OS.XmTextGetInsertionPosition (handle)); - */ - System.out.println("Text.getCaretLineNumber: nyi"); - return 1; -} -/** - * Gets the location the caret. - * <p> - * The location of the caret is returned. - * </p> - * - * @return a point, the location of the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getCaretLocation () { - checkWidget(); - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - int [] start= new int [1], end= new int [1]; - OS.TXNGetSelection(tx, start, end); - org.eclipse.swt.internal.carbon.Point loc= new org.eclipse.swt.internal.carbon.Point(); - OS.TXNOffsetToPoint(tx, end[0], loc); - Point p= new Point(loc.h, loc.v); - p.x-= bounds.left; - p.y-= bounds.top; - return p; -} -/** - * Gets the position of the caret. - * <p> - * The character position of the caret is returned. - * </p> - * - * @return the position of the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCaretPosition () { - checkWidget(); - /* AW - return OS.XmTextGetInsertionPosition (handle); - */ - int [] start= new int [1], end= new int [1]; - OS.TXNGetSelection(tx, start, end); - return end[0]; -} -/** - * Gets the number of characters. - * - * @return number of characters in the widget - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCharCount () { - checkWidget(); - return OS.TXNDataSize(tx) / 2; -} -/** - * Gets the double click enabled flag. - * <p> - * The double click flag enables or disables the - * default action of the text widget when the user - * double clicks. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getDoubleClickEnabled () { - checkWidget(); - System.out.println("Text.getDoubleClickEnabled: nyi"); - return true; -} -/** - * Gets the echo character. - * <p> - * The echo character is the character that is - * displayed when the user enters text or the - * text is changed by the programmer. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public char getEchoChar () { - checkWidget(); - return echoCharacter; -} -/** - * Gets the editable state. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getEditable () { - checkWidget(); - /* - * 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. - */ - /* AW - int [] argList = {OS.XmNeditable, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; - */ - System.out.println("Text.getEditable: nyi"); - return true; -} -/** - * Gets the number of lines. - * - * @return the number of lines in the widget - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getLineCount () { - checkWidget(); - int[] lineTotal= new int[1]; - OS.TXNGetLineCount(tx, lineTotal); - return lineTotal[0]; -} -/** - * Gets the line delimiter. - * - * @return a string that is the line delimiter - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getLineDelimiter () { - checkWidget(); - return DELIMITER; -} -/** - * Gets the height of a line. - * - * @return the height of a row of text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getLineHeight () { - checkWidget(); - return getFontHeight (); -} -int getLineNumber (int position) { - if (position == 0) return 0; - int count = 0; - /* AW - 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. - */ - /* AW - byte [] buffer1 = null; - if (OS.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 (OS.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; - } - */ - System.out.println("Text.getLineNumber: nyi"); - return count; -} -/** - * Gets the position of the selected text. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p> - * - * @return the start and end of the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSelection () { - checkWidget(); - int [] start = new int [1], end = new int [1]; - OS.TXNGetSelection(tx, start, end); - return new Point (start [0], end [0]); -} -/** - * Gets the number of selected characters. - * - * @return the number of selected characters. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget(); - int [] start = new int [1], end = new int [1]; - OS.TXNGetSelection(tx, start, end); - return end [0] - start [0]; -} -/** - * Gets the selected text. - * - * @return the selected text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getSelectionText () { - checkWidget(); - return getTXNText(OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection); -} -/** - * Gets the number of tabs. - * <p> - * Tab stop spacing is specified in terms of the - * space (' ') character. The width of a single - * tab stop is the pixel width of the spaces. - * </p> - * - * @return the number of tab characters - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTabs () { - checkWidget(); - System.out.println("Text.getTabs: nyi"); - return 8; -} -/** - * Gets the widget text. - * <p> - * The text for a text widget is the characters in the widget. - * </p> - * - * @return the widget text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - return getTXNText(OS.kTXNStartOffset, OS.kTXNEndOffset); -} -/** - * Gets a range of text. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N-1 where N is - * the number of characters in the widget. - * </p> - * - * @param start the start of the range - * @param end the end of the range - * @return the range of text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText (int start, int end) { - checkWidget(); - int numChars = end - start + 1; - if (numChars < 0 || start < 0) return ""; - return getTXNText(start, end); -} -/** - * Returns the maximum number of characters that the receiver is capable of holding. - * <p> - * If this has not been changed by <code>setTextLimit()</code>, - * it will be the constant <code>Text.LIMIT</code>. - * </p> - * - * @return the text limit - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTextLimit () { - checkWidget(); - return textLimit; -} -/** - * Returns the zero-relative index of the line which is currently - * at the top of the receiver. - * <p> - * This index can change when lines are scrolled or new lines are added or removed. - * </p> - * - * @return the index of the top line - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopIndex () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return 0; - if (scrolledHandle == 0) return 0; - /* AW - 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]; - */ - System.out.println("Text.getTopIndex: nyi"); - return 0; -} -/** - * 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><p> - * The top pixel changes when the widget is scrolled. - * The top pixel does not include the widget trimming. - * </p> - * - * @return the pixel position of the top line - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopPixel () { - checkWidget(); - return getTopIndex () * getLineHeight (); -} -boolean getWrap () { - checkWidget(); - /* AW - int [] argList = {OS.XmNwordWrap, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; - */ - System.out.println("Text.getWrap: nyi"); - return false; -} -void hookEvents () { - super.hookEvents (); - /* AW - 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); - */ - Display display= getDisplay(); - OS.SetControlData(handle, OS.kControlEntireControl, OS.kControlUserPaneHitTestProcTag, 4, new int[]{display.fUserPaneHitTestProc}); - int[] mask= new int[] { - OS.kEventClassControl, OS.kEventControlDraw, - }; - OS.InstallEventHandler(OS.GetControlEventTarget(handle), display.fControlProc, mask.length/2, mask, handle, null); -} -/** - * Inserts a string. - * <p> - * The old selection is replaced with the new text. - * </p> - * - * @param string the string - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void insert (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - string = Display.convertToLf (string); - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - int [] start = new int [1], end = new int [1]; - OS.TXNGetSelection(tx, start, end); - string = verifyText (string, start [0], end [0]); - if (string == null) return; - } - /* AW - TCHAR buffer = new TCHAR (getCodePage (), string, true); - OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer); - */ - replaceTXNText(OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection, string); -} -/** - * Pastes text from clipboard. - * <p> - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void paste () { - checkWidget(); - syncBounds(); - OS.TXNPaste(tx); -} -int processFocusIn () { - super.processFocusIn (); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.READ_ONLY) != 0) return 0; - - syncBounds(); - drawFrame(0); - OS.TXNFocus(tx, true); - - if ((style & SWT.MULTI) != 0) return 0; - /* AW - int [] argList = {OS.XmNcursorPositionVisible, 1}; - OS.XtSetValues (handle, argList, argList.length / 2); - */ - return 0; -} -int processFocusOut () { - super.processFocusOut (); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.READ_ONLY) != 0) return 0; - - //fgTextInFocus= null; - syncBounds(); - OS.TXNFocus(tx, false); - drawFrame(0); - - if ((style & SWT.MULTI) != 0) return 0; - /* AW - int [] argList = {OS.XmNcursorPositionVisible, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - */ - return 0; -} -int processMouseDown (MacMouseEvent mmEvent) { - if (isEnabled()) { - EventRecord eventRecord = new EventRecord(); - if (OS.ConvertEventRefToEventRecord(mmEvent.getEventRef(), eventRecord)) { - OS.TXNClick(tx, eventRecord); - } - } - return OS.noErr; -} -int processPaint (Object callData) { - syncBounds(); - int damageRegion= 0; - if (callData instanceof MacControlEvent) - damageRegion= ((MacControlEvent)callData).getDamageRegionHandle(); - drawFrame(damageRegion); - return OS.noErr; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - 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 from the collection of listeners who will - * be notified when the control is verified. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #addVerifyListener - */ -public void removeVerifyListener (VerifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Verify, listener); -} -/** - * Selects all the text in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void selectAll () { - checkWidget(); - syncBounds(); - OS.TXNSelectAll(tx); -} -/** - * Sets the double click enabled flag. - * <p> - * The double click flag enables or disables the - * default action of the text widget when the user - * double clicks. - * </p> - * - * @param doubleClick the new double click flag - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDoubleClickEnabled (boolean doubleClick) { - checkWidget(); - System.out.println("Text.setDoubleClickEnabled: nyi"); -} -/** - * Sets the echo character. - * <p> - * The echo character is the character that is - * displayed when the user enters text or the - * text is changed by the programmer. Setting - * the echo character to '\0' clears the echo - * character and redraws the original text. - * If for any reason the echo character is invalid, - * the default echo character for the platform - * is used. - * </p> - * - * @param echo the new echo character - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEchoChar (char echo) { - checkWidget(); - if (echoCharacter == echo) return; - echoCharacter = echo; - syncBounds(); - OS.TXNEchoMode(tx, echo, 0, echo != '\0'); -} -/** - * Sets the editable state. - * - * @param editable the new editable state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEditable (boolean editable) { - checkWidget(); - /* AW - OS.XmTextSetEditable (handle, editable); - int isEditable= editable ? 1 : 0; - */ - 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) { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - syncBounds(); - super.setRedraw(redraw); -// AW -// if (redraw) { -// if (--drawCount == 0) ; /* AW OS.XmTextEnableRedisplay(handle); */ -// } else { -// if (drawCount++ == 0) ; /* AW OS.XmTextDisableRedisplay(handle); */ -// } -// AW -} -/** - * Sets the selection. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * regular array indexing rules. - * </p> - * - * @param start new caret position - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int start) { - checkWidget(); - syncBounds(); - OS.TXNSetSelection(tx, start, start); -} -/** - * Sets the selection. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * usual array indexing rules. - * </p> - * - * @param start the start of the range - * @param end the end of the range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int start, int end) { - checkWidget(); - syncBounds(); - OS.TXNSetSelection(tx, start, end); -} -/** - * Sets the selection. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * usual array indexing rules. - * </p> - * - * @param selection the point - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (Point selection) { - checkWidget(); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - setSelection (selection.x, selection.y); -} - /** - * Sets the number of tabs. - * <p> - * Tab stop spacing is specified in terms of the - * space (' ') character. The width of a single - * tab stop is the pixel width of the spaces. - * </p> - * - * @param tabs the number of tabs - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTabs (int tabs) { - checkWidget(); - System.out.println("Text.setTabs: nyi"); -} -/** - * Sets the contents of the receiver to the given string. If the receiver has style - * SINGLE and the argument contains multiple lines of text, the result of this - * operation is undefined and may vary from platform to platform. - * - * @param text the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - string = Display.convertToLf (string); - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - int length = OS.TXNDataSize(tx) / 2; - string = verifyText (string, 0, length); - if (string == null) return; - } - replaceTXNText(OS.kTXNStartOffset, OS.kTXNEndOffset, string); - revealBeginning(); -} -/** - * Sets the maximum number of characters that the receiver - * is capable of holding to be the argument. - * <p> - * Instead of trying to set the text limit to zero, consider - * creating a read-only text widget. - * </p><p> - * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>. - * </p> - * - * @param limit new text limit - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - textLimit= limit; -} -/** - * Sets the zero-relative index of the line which is currently - * at the top of the receiver. This index can change when lines - * are scrolled or new lines are added and removed. - * - * @param index the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTopIndex (int index) { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - if (scrolledHandle == 0) return; - /* AW - 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]); - */ - System.out.println("Text.setTopIndex: nyi"); -} -void setWrap (boolean wrap) { - checkWidget(); - /* AW - int [] argList = {OS.XmNwordWrap, wrap ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - */ - System.out.println("Text.setWrap: nyi"); -} -/** - * Shows the selection. - * <p> - * If the selection is already showing - * in the receiver, this method simply returns. Otherwise, - * lines are scrolled until the selection is visible. - * </p> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void showSelection () { - checkWidget(); - syncBounds(); - OS.TXNShowSelection(tx, false); -} -int traversalCode () { - int bits = super.traversalCode (); - if ((style & SWT.READ_ONLY) != 0) return bits; - if ((style & SWT.MULTI) != 0) { - bits &= ~SWT.TRAVERSE_RETURN; - /* AW - if (key == OS.XK_Tab && xEvent != null) { - boolean next = (xEvent.state & OS.ShiftMask) == 0; - if (next && (xEvent.state & OS.ControlMask) == 0) { - bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); - } - } - */ - } - return bits; -} -String verifyText (String string, int start, int end) { - return verifyText (string, start, end, null); -} -String verifyText (String string, int start, int end, Event keyEvent) { - - int size= (OS.TXNDataSize(tx) / 2) - (end-start); - if (size + string.length() > textLimit) - return null; - - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - if (keyEvent != null) { - event.character = keyEvent.character; - event.keyCode = keyEvent.keyCode; - event.stateMask = keyEvent.stateMask; - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the verify - * event. If this happens, answer null to cancel - * the operation. - */ - sendEvent (SWT.Verify, event); - if (!event.doit || isDisposed ()) return null; - return event.text; -} -/////////////////////////////////////////// -// Mac Stuff -/////////////////////////////////////////// - - private void replaceTXNText(int start, int end, String s) { - - // before touch anything we have to synch visibility - syncBounds(); - - int l= s.length(); - char[] chars= new char[l]; - s.getChars(0, l, chars, 0); - OS.TXNSetData(tx, OS.kTXNUnicodeTextData, chars, chars.length * 2, start, end); - - sendEvent (SWT.Modify); - } - - private String getTXNText(int start, int end) { - int[] dataHandle= new int[1]; - OS.TXNGetData(tx, start, end, dataHandle); - int length= OS.GetHandleSize(dataHandle[0]); - if (length <= 0) - return ""; - int[] ptr= new int[1]; - OS.HLock(dataHandle[0]); - OS.memcpy(ptr, dataHandle[0], 4); - char[] chars= new char[length/2]; - OS.memcpy(chars, ptr[0], length); - OS.HUnlock(dataHandle[0]); - OS.DisposeHandle(dataHandle[0]); - return new String(chars); - } - - int sendKeyEvent(int type, MacEvent mEvent, Event event) { - - int status= OS.noErr; // we handled the event - - if ((mEvent.getModifiers() & OS.cmdKey) != 0) { - int kind= mEvent.getKind(); - int code= mEvent.getKeyCode(); - switch (code) { - case 0: - if (kind == OS.kEventRawKeyDown) - selectAll(); - return status; - case 7: - if (kind == OS.kEventRawKeyDown) - cut(); - return status; - case 8: - if (kind == OS.kEventRawKeyDown) - copy(); - return status; - case 9: - if (kind == OS.kEventRawKeyDown || kind == OS.kEventRawKeyRepeat) - paste(); - return status; - default: - break; - } - } - - int eRefHandle= mEvent.getEventRef(); - int nextHandler= mEvent.getNextHandler(); - - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - - // extract characters from event - String unicode= mEvent.getText(); - String text= unicode != null ? unicode : ""; - String original= new String(text); - - // send verify event - int[] start= new int[1], end= new int[1]; - OS.TXNGetSelection(tx, start, end); - - if (text.length() == 1) { - switch (text.charAt(0)) { - case 0x08: - if (start[0] == end[0]) { - if (start[0] == 0) - return status; - if (start[0] > 0) - start[0]--; - } - break; - } - } - - String string= verifyText(original, start[0], end[0], event); - if (string == null) - return status; // ignore event - - int l= string.length(); - char[] newChars= new char[l]; - string.getChars(0, l, newChars, 0); - if (true) { - OS.SetEventParameter(eRefHandle, OS.kEventParamTextInputSendText, OS.typeUnicodeText, newChars.length * 2, newChars); - status= OS.CallNextEventHandler(nextHandler, eRefHandle); - } else { - OS.TXNSetSelection(tx, start[0], end[0]); - OS.TXNSetData(tx, OS.kTXNUnicodeTextData, newChars, newChars.length * 2, OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection); - OS.TXNSetSelection(tx, start[0], start[0]+newChars.length); - } - } else { - status= OS.CallNextEventHandler(nextHandler, eRefHandle); - } - - sendEvent (SWT.Modify); - - return status; - } - - void handleResize(int hndl, Rect bounds) { - super.handleResize(hndl, bounds); - syncBounds(); - } - - /** - * Synchronize the size and visibilty of the MLTEtext with the underlying user pane.
*/ - private void syncBounds() { - - if (tx == 0) - return; - - boolean isShowing= isShowing(); - if (isShowing != txVisible) { - txVisible= isShowing; - int[] tags= new int[] { OS.kTXNVisibilityTag }; - int[] data= new int[] { txVisible ? 1 : 0 }; - OS.TXNSetTXNObjectControls(tx, false, tags.length, tags, data); - } - - if (!isShowing) - return; - - Rect b= new Rect(); - MacUtil.getControlBounds(handle, b); - - // this is just too hard to explain... - OS.HIViewSetBoundsOrigin(handle, b.left, b.top); - - if ((style & SWT.BORDER) != 0) { - b.left+= FOCUS_BORDER; - b.top+= FOCUS_BORDER; - b.right-= FOCUS_BORDER; - b.bottom-= FOCUS_BORDER; - } - - Rectangle newBounds= new Rectangle(b.left, b.top, b.right-b.left, b.bottom-b.top); - if (txFrameBounds == null || !txFrameBounds.equals(newBounds)) { - OS.TXNSetFrameBounds(tx, b.top, b.left, b.bottom, b.right, txFrameID); - OS.HIViewSetNeedsDisplay(handle, true); - txFrameBounds= newBounds; - } - - OS.TXNDraw(tx, 0); - } - - private void drawFrame(int damageRegion) { - - if ((style & SWT.BORDER) == 0) - return; - - GC gc= new GC(this); - Rectangle r= gc.carbon_focus(damageRegion); - if (!r.isEmpty()) { - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - OS.SetRect(bounds, (short)0, (short)0, (short)(bounds.right - bounds.left), (short)(bounds.bottom - bounds.top)); - int m= FOCUS_BORDER; - bounds.left+= m; - bounds.top+= m; - bounds.right-= m; - bounds.bottom-= m+1; - - Rect fbounds= new Rect(); - OS.GetControlBounds(handle, fbounds); - OS.SetRect(fbounds, (short)0, (short)0, (short)(fbounds.right - fbounds.left), (short)(fbounds.bottom - fbounds.top)); - int fm= FOCUS_BORDER; - fbounds.left+= fm; - fbounds.top+= fm+1; - fbounds.right-= fm; - fbounds.bottom-= fm+1; - - if ((style & SWT.READ_ONLY) == 0) { - if (getDisplay().getFocusControl() == this) { - OS.DrawThemeEditTextFrame(bounds, OS.kThemeStateActive); - OS.DrawThemeFocusRect(fbounds, true); - } else { - OS.DrawThemeFocusRect(fbounds, false); - OS.DrawThemeEditTextFrame(bounds, OS.kThemeStateActive); - } - } else { - OS.DrawThemeEditTextFrame(bounds, OS.kThemeStateActive); - } - - } - gc.carbon_unfocus(); - revealBeginning(); - } - - private void revealBeginning() { - int[] start= new int[1], end= new int [1]; - OS.TXNGetSelection(tx, start, end); - if (start[0] != 0 || end[0] != 0) { - OS.TXNSetSelection(tx, 0, 0); - OS.TXNShowSelection(tx, false); - OS.TXNSetSelection(tx, start[0], end[0]); - } else { - OS.TXNShowSelection(tx, false); - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java deleted file mode 100644 index 8d893f935a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java +++ /dev/null @@ -1,410 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class support the layout of selectable - * tool bar items. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>ToolItem</code>. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add <code>Control</code> children to it, - * or set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class ToolBar extends Composite { - int itemCount; - ToolItem [] items; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#FLAT - * @see SWT#WRAP - * @see SWT#RIGHT - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolBar (Composite parent, int style) { - super (parent, checkStyle (style)); - - /* - * Ensure that either of HORIZONTAL or VERTICAL is set. - * NOTE: HORIZONTAL and VERTICAL have the same values - * as H_SCROLL and V_SCROLL so it is necessary to first - * clear these bits to avoid scroll bars and then reset - * the bits using the original style supplied by the - * programmer. - */ - this.style = checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -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 Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - 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 createHandle (int index) { - super.createHandle (index); - state &= ~CANVAS; -} -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 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; -} -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem getItem (int index) { - checkWidget(); - ToolItem [] items = getItems (); - if (0 <= index && index < items.length) return items [index]; - error (SWT.ERROR_INVALID_RANGE); - return null; -} - -/** - * Returns the item at the given point in the receiver - * or null if no such item exists. The point is in the - * coordinate system of the receiver. - * - * @param point the point used to locate the item - * @return the item at the given point - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem getItem (Point pt) { - checkWidget(); - 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; -} - -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - return itemCount; -} -/** - * Returns an array of <code>TabItem</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem [] getItems () { - checkWidget(); - ToolItem [] result = new ToolItem [itemCount]; - System.arraycopy (items, 0, result, 0, itemCount); - return result; -} -/** - * Returns the number of rows in the receiver. When - * the receiver has the <code>WRAP</code> style, the - * number of rows can be greater than one. Otherwise, - * the number of rows is always one. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getRowCount () { - checkWidget(); - Rectangle rect = getClientArea (); - return layout (rect.width, rect.height, false) [0]; -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (ToolItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - if (items [i] == item) return i; - } - return -1; -} -int [] layoutHorizontal (int nWidth, int nHeight, boolean resize) { - int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2; - 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}; -} -int [] layoutVertical (int nWidth, int nHeight, boolean resize) { - int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0; - int marginWidth = 0, marginHeight = 0; - ToolItem [] children = getItems (); - int length = children.length; - int x = marginWidth, y = marginHeight; - int maxWidth = 0, maxY = 0, cols = 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 && y + rect.height > nHeight) { - cols++; - x += xSpacing + maxWidth; y = marginHeight; - maxWidth = 0; - } - maxWidth = Math.max (maxWidth, rect.width); - if (resize) { - child.setBounds (x, y, rect.width, rect.height); - } - y += ySpacing + rect.height; - maxY = Math.max (maxY, y); - } - return new int [] {cols, x + maxWidth, maxY}; -} -int [] layout (int nWidth, int nHeight, boolean resize) { - if ((style & SWT.VERTICAL) != 0) { - return layoutVertical (nWidth, nHeight, resize); - } else { - return layoutHorizontal (nWidth, nHeight, resize); - } -} -/* AW -boolean mnemonicHit (char key) { - for (int i = 0; i < items.length; i++) { - ToolItem item = items [i]; - if (item != null) { - char mnemonic = findMnemonic (item.getText ()); - if (mnemonic != '\0') { - if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { - OS.XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT); - item.click (false, null); - return true; - } - } - } - } - return false; -} -boolean mnemonicMatch (char key) { - for (int i = 0; i < items.length; i++) { - ToolItem item = items [i]; - if (item != null) { - char mnemonic = findMnemonic (item.getText ()); - if (mnemonic != '\0') { - if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { - return true; - } - } - } - } - return false; -} -*/ -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - for (int i=0; i<itemCount; i++) { - items [i].propagateWidget (enabled); - } -} -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) { - checkWidget(); - 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); -} -/* AW -int traversalCode (int key, XKeyEvent xEvent) { - return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC; -} -*/ -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java deleted file mode 100644 index bc0054812e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java +++ /dev/null @@ -1,1093 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTError; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.Rect; -import org.eclipse.swt.internal.carbon.ThemeButtonDrawInfo; - -/** - * Instances of this class represent a selectable user interface object - * that represents a button in a tool bar. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN - * may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class ToolItem extends Item { - ToolBar parent; - Image hotImage, disabledImage; - String toolTipText; - Control control; - boolean set; - boolean pressed; - - static final int DEFAULT_WIDTH = 24; - static final int DEFAULT_HEIGHT = 22; - static final int DEFAULT_SEPARATOR_WIDTH = 8; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>ToolBar</code>) and a style value - * describing its behavior and appearance. The item is added - * to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#PUSH - * @see SWT#CHECK - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolItem (ToolBar parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, parent.getItemCount ()); - parent.relayout (); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>ToolBar</code>), a style value - * describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#PUSH - * @see SWT#CHECK - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolItem (ToolBar parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, index); - parent.relayout (); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool, - * the event object detail field contains the value <code>SWT.ARROW</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - 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; - /* AW - int [] argList = { - OS.XmNwidth, DEFAULT_WIDTH, - OS.XmNheight, DEFAULT_HEIGHT, - OS.XmNrecomputeSize, 0, - OS.XmNhighlightThickness, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, - OS.XmNmarginWidth, 2, - OS.XmNmarginHeight, 1, - OS.XmNtraversalOn, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, - OS.XmNpositionIndex, index, - OS.XmNshadowType, OS.XmSHADOW_OUT, - OS.XmNancestorSensitive, 1, - }; - handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2); - */ - int width= DEFAULT_WIDTH; - int height= DEFAULT_HEIGHT; - if ((style & SWT.SEPARATOR) != 0) { - if ((parent.style & SWT.HORIZONTAL) != 0) - width= DEFAULT_SEPARATOR_WIDTH; - else - height= DEFAULT_SEPARATOR_WIDTH; - } - - Rect bounds= new Rect(); - OS.SetRect(bounds, (short)0, (short)0, (short)width, (short)height); - handle= OS.NewControl(0, bounds, null, false, (short)(OS.kControlSupportsFocus | OS.kControlGetsFocusOnClick), (short)0, (short)0, (short)OS.kControlUserPaneProc, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - MacUtil.insertControl(handle, parentHandle, index); - OS.HIViewSetVisible(handle, true); -} -void click (boolean dropDown, MacMouseEvent mmEvent) { - if ((style & SWT.RADIO) != 0) { - selectRadio (); - } else { - if ((style & SWT.CHECK) != 0) setSelection(!set); - } - Event event = new Event (); - if ((style & SWT.DROP_DOWN) != 0) { - if (dropDown) event.detail = SWT.ARROW; - } - if (mmEvent != null) { - // AW setInputState (event, mEvent); - event.stateMask= mmEvent.getState(); - } - postEvent (SWT.Selection, event); -} -Point computeSize () { - if ((style & SWT.SEPARATOR) != 0) { - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - return new Point(bounds.right - bounds.left, bounds.bottom - bounds.top); - } - /* AW - int [] argList = { - OS.XmNmarginHeight, 0, - OS.XmNmarginWidth, 0, - OS.XmNshadowThickness, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int marginHeight = argList [1], marginWidth = argList [3]; - int shadowThickness = argList [5]; - */ - int marginHeight = 2, marginWidth = 2; - int shadowThickness = 1; - if ((parent.style & SWT.FLAT) != 0) { - Display display = getDisplay (); - shadowThickness = Math.min (2, display.buttonShadowThickness); - } - int textWidth = 0, textHeight = 0; - if (text.length () != 0) { - GC gc = new GC (parent); - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; - Point textExtent = gc.textExtent (text, flags); - 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 width = 0, height = 0; - if ((parent.style & SWT.RIGHT) != 0) { - width = imageWidth + textWidth; - height = Math.max (imageHeight, textHeight); - if (imageWidth != 0 && textWidth != 0) width += 2; - } else { - height = imageHeight + textHeight; - if (imageHeight != 0 && textHeight != 0) height += 2; - width = Math.max (imageWidth, textWidth); - } - if ((style & SWT.DROP_DOWN) != 0) width += 12; - - if (width != 0) { - width += (marginWidth + shadowThickness) * 2 + 2; - } else { - width = DEFAULT_WIDTH; - } - if (height != 0) { - height += (marginHeight + shadowThickness) * 2 + 2; - } else { - height = DEFAULT_HEIGHT; - } - return new Point (width, height); -} -void createWidget (int index) { - super.createWidget (index); - toolTipText = ""; - parent.relayout (); -} -public void dispose () { - if (isDisposed()) return; - ToolBar parent = this.parent; - parent.redraw(); // AW workaround for Toolbar update problem - super.dispose (); - parent.relayout (); -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent. - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget(); - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - return new Rectangle(bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top); -} -/** - * Returns the control that is used to fill the bounds of - * the item when the items is a <code>SEPARATOR</code>. - * - * @return the control - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Control getControl () { - checkWidget(); - return control; -} -/** - * Returns the receiver's disabled image if it has one, or null - * if it does not. - * <p> - * The disabled image is displayed when the receiver is disabled. - * </p> - * - * @return the receiver's disabled image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getDisabledImage () { - checkWidget(); - return disabledImage; -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. - * <p> - * A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * </p> - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getEnabled () { - checkWidget(); - return OS.IsControlEnabled(handle); -} -public Display getDisplay () { - Composite parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} -/** - * Returns the receiver's hot image if it has one, or null - * if it does not. - * <p> - * The hot image is displayed when the mouse enters the receiver. - * </p> - * - * @return the receiver's hot image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getHotImage () { - checkWidget(); - return hotImage; -} -/** - * Returns the receiver's parent, which must be a <code>ToolBar</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolBar getParent () { - checkWidget(); - return parent; -} -/** - * Returns <code>true</code> if the receiver is selected, - * and false otherwise. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked (which some platforms draw as a - * pushed in button). If the receiver is of any other type, this method - * returns false. - * </p> - * - * @return the selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getSelection () { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; - return set; -} -/** - * Returns the receiver's tool tip text, or null if it has not been set. - * - * @return the receiver's tool tip text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getToolTipText () { - checkWidget(); - return toolTipText; -} -/** - * Gets the width of the receiver. - * - * @return the width - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getWidth () { - checkWidget(); - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - return bounds.right - bounds.left; -} -boolean hasCursor () { - Display display= getDisplay(); - org.eclipse.swt.internal.carbon.Point mp= new org.eclipse.swt.internal.carbon.Point(); - mp.h= display.lastGlobalMouseXPos; - mp.v= display.lastGlobalMouseYPos; - int wHandle= OS.GetControlOwner(handle); - Rect bounds= new Rect(); - OS.GetWindowBounds(wHandle, (short)OS.kWindowContentRgn, bounds); - mp.h-= bounds.left; - mp.v-= bounds.top; - MacUtil.getControlBounds(handle, bounds); - return OS.PtInRect(mp, bounds); -} -void hookEvents () { - super.hookEvents (); - /* AW - 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.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, SWT.Paint); - */ - Display display= getDisplay(); - int[] mask= new int[] { - OS.kEventClassControl, OS.kEventControlDraw, - }; - OS.InstallEventHandler(OS.GetControlEventTarget(handle), display.fControlProc, mask.length/2, mask, handle, null); - if ((style & SWT.SEPARATOR) != 0) return; - OS.SetControlData(handle, OS.kControlEntireControl, OS.kControlUserPaneHitTestProcTag, 4, new int[]{display.fUserPaneHitTestProc}); -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget(); - return getEnabled () && parent.isEnabled (); -} -/* AW -void manageChildren () { - OS.XtManageChild (handle); -} -*/ -void redraw () { - redrawHandle (0, 0, 0, 0, handle, true); -} -void releaseChild () { - super.releaseChild (); - parent.destroyItem (this); -} -void releaseWidget () { - Display display = getDisplay (); - display.releaseToolTipHandle (handle); - super.releaseWidget (); - parent = null; - control = null; - toolTipText = null; - image = disabledImage = hotImage = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - 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); - } -} -/* - * This setBounds is only called from ToolBar.relayout() - */ -void setBounds (int x, int y, int width, int height) { - - if (control != null) - control.setBounds(x, y, width, height); - - width = Math.max(width, 0); - height = Math.max(height, 0); - - Rect bounds= new Rect(); - OS.SetRect(bounds, (short)x, (short)y, (short)(x+width), (short)(y+height)); - OS.SetControlBounds(handle, bounds); -} -/** - * Sets the control that is used to fill the bounds of - * the item when the items is a <code>SEPARATOR</code>. - * - * @param control the new control - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setControl (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (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 ()); - } -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. - * <p> - * A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * </p> - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - if (enabled) - OS.EnableControl(handle); - else - OS.DisableControl(handle); -} -/** - * Sets the receiver's disabled image to the argument, which may be - * null indicating that no disabled image should be displayed. - * <p> - * The disbled image is displayed when the receiver is disabled. - * </p> - * - * @param image the disabled image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDisabledImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - disabledImage = image; - if (!getEnabled ()) redraw (); -} -/** - * Sets the receiver's hot image to the argument, which may be - * null indicating that no hot image should be displayed. - * <p> - * The hot image is displayed when the mouse enters the receiver. - * </p> - * - * @param image the hot image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setHotImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - hotImage = image; - if ((parent.style & SWT.FLAT) != 0) redraw (); -} -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - super.setImage (image); - Point size = computeSize (); - setSize (size.x, size.y); - //redraw (); -} - -/** - * Sets the selection state of the receiver. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked (which some platforms draw as a - * pushed in button). - * </p> - * - * @param selected the new selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (boolean selected) { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; - if (selected == set) return; - set = selected; - setDrawPressed (set); -} - -void setSize (int width, int height) { - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - if ((bounds.right - bounds.left) != width || (bounds.bottom - bounds.top) != height) { - OS.SizeControl(handle, (short) width, (short) height); - parent.relayout(); - } -} -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - super.setText (string); - Point size = computeSize (); - setSize (size.x, size.y); -} - -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that no tool tip text should be shown. - * - * @param string the new tool tip text (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setToolTipText (String string) { - checkWidget(); - toolTipText = string; -} -/** - * Sets the width of the receiver. - * - * @param width the new width - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setWidth (int width) { - checkWidget(); - if ((style & SWT.SEPARATOR) == 0) return; - if (width < 0) return; - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - setSize (width, bounds.bottom-bounds.top); - if (control != null && !control.isDisposed ()) { - control.setBounds (getBounds ()); - } -} -void setDrawPressed (boolean value) { - if (pressed != value) { - pressed= value; - redraw(); - } -} -int processKeyDown (Object callData) { - /* AW - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, callData, XKeyEvent.sizeof); - */ - /* - * Forward the key event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - /* AW - xEvent.window = OS.XtWindow (parent.handle); -// OS.memmove (callData, xEvent, XKeyEvent.sizeof); - */ - parent.processKeyDown (callData); - return 0; -} -int processKeyUp (Object callData) { - /* AW - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, callData, XKeyEvent.sizeof); - int [] keysym = new int [1]; - OS.XLookupString (xEvent, null, 0, keysym, null); - keysym [0] &= 0xFFFF; - switch (keysym [0]) { - case OS.XK_space: - case OS.XK_Return: - click (keysym [0] == OS.XK_Return, xEvent); - break; - } - */ - /* - * Forward the key event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - /* AW - xEvent.window = OS.XtWindow (parent.handle); -// OS.memmove (callData, xEvent, XKeyEvent.sizeof); - */ - parent.processKeyUp (callData); - return 0; -} -int processMouseDown (MacMouseEvent mmEvent) { - Display display = getDisplay (); -// Shell shell = parent.getShell (); - display.hideToolTip (); - - /* AW - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, callData, XButtonEvent.sizeof); - */ - if (mmEvent.getButton() == 1) { - if (!set && (style & SWT.RADIO) == 0) { - setDrawPressed (!set); - } - } - - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - /* AW - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - xEvent.window = OS.XtWindow (parent.handle); - xEvent.x += argList [1]; xEvent.y += argList [3]; - OS.memmove (callData, xEvent, XButtonEvent.sizeof); - */ - parent.processMouseDown (mmEvent); - /* - * It is possible that the shell may be - * disposed at this point. If this happens - * don't send the activate and deactivate - * events. - */ -// if (!shell.isDisposed()) { -// shell.setActiveControl (parent); -// } - return 0; -} -int processMouseEnter (MacMouseEvent mme) { - if (mme.getButton() == 1) setDrawPressed (!set); - else if ((parent.style & SWT.FLAT) != 0) redraw (); - return 0; -} -int processMouseExit (MacMouseEvent mme) { - parent.processMouseExit(mme); - Display display = getDisplay (); - display.removeMouseHoverTimeOut (); - display.hideToolTip (); - if (mme.getButton() == 1) setDrawPressed (set); - else if ((parent.style & SWT.FLAT) != 0) redraw (); - return 0; -} -/* AW -boolean translateTraversal (int key, XKeyEvent xEvent) { - return parent.translateTraversal (key, xEvent); -} -*/ -int processMouseHover (MacMouseEvent mmEvent) { - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - parent.processMouseHover(mmEvent); - getDisplay().showToolTip(handle, toolTipText); - return OS.noErr; -} -int processMouseMove (MacMouseEvent mmEvent) { - Display display = getDisplay (); - display.addMouseHoverTimeOut (handle); - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ -// parent.processMouseMove (mmEvent); - parent.sendMouseEvent (SWT.MouseMove, 0, mmEvent); - return OS.noErr; -} -int processMouseUp (MacMouseEvent mmEvent) { - Display display = getDisplay (); - display.hideToolTip(); - if (mmEvent.getButton() == 1) { - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - int width = bounds.right - bounds.left, height = bounds.bottom - bounds.top; - Point mp= MacUtil.toControl(handle, mmEvent.getWhere()); - if (0 <= mp.x && mp.x < width && 0 <= mp.y && mp.y < height) { - click (mp.x > width - 12, mmEvent); - } - setDrawPressed(set); - } - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - parent.processMouseUp (mmEvent); - return OS.noErr; -} -int processPaint (Object callData) { - - if ((style & SWT.SEPARATOR) != 0 && control != null) - return OS.noErr; - - Rect bounds= new Rect(); - OS.GetControlBounds(handle, bounds); - int width= bounds.right - bounds.left; - int height= bounds.bottom - bounds.top; - OS.SetRect(bounds, (short)0, (short)0, (short)width, (short)height); - - final Display display = getDisplay (); - - Drawable drawable= new Drawable() { - public int internal_new_GC (GCData data) { - data.device = display; - data.foreground = parent.getForegroundPixel(); - data.background = parent.getBackgroundPixel(); - data.font = parent.font.handle; - data.controlHandle = handle; - int port= OS.GetWindowPort(OS.GetControlOwner(handle)); - if (port == 0) SWT.error(SWT.ERROR_NO_HANDLES); - return port; - } - public void internal_dispose_GC (int xGC, GCData data) { - } - }; - - boolean hasCursor= hasCursor (); - - GC gc= new GC(drawable); - MacControlEvent me= (MacControlEvent) callData; - Rectangle r= gc.carbon_focus(me.getDamageRegionHandle(), me.getGCContext()); - - if (!r.isEmpty()) { - - // erase background - gc.fillRectangle(0, 0, width, height); - - if ((style & SWT.SEPARATOR) != 0) { - - OS.DrawThemeSeparator(bounds, OS.kThemeStateActive); - - } else { - - if ((parent.style & SWT.FLAT) != 0 && set) { - gc.setBackground(Color.carbon_new(display, 0xE0E0E0, false)); - gc.fillRoundRectangle(1, 1, width-2, height-2, 8, 8); - gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY)); - gc.drawRoundRectangle(1, 1, width-3, height-3, 8, 8); - } - - Image currentImage = image; - boolean enabled = getEnabled(); - - ThemeButtonDrawInfo newInfo= new ThemeButtonDrawInfo(); - newInfo.value= (short)(set ? OS.kThemeButtonOn : OS.kThemeButtonOff); - - if ((parent.style & SWT.FLAT) != 0) { - - if (hasCursor && enabled) { - newInfo.state= (short)(OS.StillDown() ? OS.kThemeStatePressed : OS.kThemeStateActive); - } else { - newInfo= null; - } - - /* Determine if hot image should be used */ - if (enabled && hasCursor && hotImage != null) { - currentImage = hotImage; - } - } else { - newInfo.state= (short)((hasCursor && OS.StillDown()) ? OS.kThemeStatePressed : OS.kThemeStateActive); - } - - if (newInfo != null) { - Rect b= new Rect(); - OS.SetRect(b, (short)1, (short)1, (short)(width-1), (short)(height-1)); - OS.DrawThemeButton(b, (short)OS.kThemeSmallBevelButton, newInfo, null, 0, 0, 0); - } - - if (enabled) { - gc.setForeground (parent.getForeground()); - } else { - currentImage = disabledImage; - if (currentImage == null && image != null) { - currentImage = new Image (display, image, SWT.IMAGE_DISABLE); - } - Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW); - gc.setForeground (disabledColor); - } - - int textX = 0, textY = 0, textWidth = 0, textHeight = 0; - if (text.length() > 0) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; - Point textExtent = gc.textExtent (text, flags); - textWidth = textExtent.x; - textHeight = textExtent.y; - } - int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0; - if (currentImage != null) { - try { // AW FIXME - Rectangle imageBounds = currentImage.getBounds (); - imageWidth = imageBounds.width; - imageHeight = imageBounds.height; - } catch (SWTError e) { - System.out.println("ToolItem.processPaint: error in image.getBounds: " + e); - } - } - - int spacing = 0; - if (textWidth != 0 && imageWidth != 0) spacing = 2; - if ((parent.style & SWT.RIGHT) != 0) { - imageX = (width - imageWidth - textWidth - spacing) / 2; - imageY = (height - imageHeight) / 2; - textX = spacing + imageX + imageWidth; - textY = (height - textHeight) / 2; - } else { - imageX = (width - imageWidth) / 2; - imageY = (height - imageHeight - textHeight - spacing) / 2; - textX = (width - textWidth) / 2; - textY = spacing + imageY + imageHeight; - } - - if ((style & SWT.DROP_DOWN) != 0) { - textX -= 6; imageX -=6; - } - if (textWidth > 0) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT; - gc.drawText(text, textX, textY, flags); - } - if (imageWidth > 0) - gc.drawImage(currentImage, imageX, imageY); - - if ((style & SWT.DROP_DOWN) != 0) { - int startX = width - 12, startY = (height - 2) / 2; - int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY}; - gc.setBackground (gc.getForeground ()); - gc.fillPolygon (arrow); - gc.drawPolygon (arrow); - } - if (!enabled && disabledImage == null) { - if (currentImage != null) currentImage.dispose (); - } - } - } - gc.carbon_unfocus(); - gc.dispose (); - - return OS.noErr; -} -void propagateWidget (boolean enabled) { - propagateHandle (enabled, handle); - /* - * Tool items participate in focus traversal only when - * the tool bar takes focus. - */ - /* AW - if ((parent.style & SWT.NO_FOCUS) != 0) { - if (enabled) { - int [] argList = {OS.XmNtraversalOn, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - } - } - */ -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java deleted file mode 100644 index a4eeb8c421..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java +++ /dev/null @@ -1,668 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class implement rubber banding rectangles that are - * drawn onto a parent <code>Composite</code> or <code>Display</code>. - * These rectangles can be specified to respond to mouse and key events - * by either moving or resizing themselves accordingly. Trackers are - * typically used to represent window geometries in a lightweight manner. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd> - * <dt><b>Events:</b></dt> - * <dd>Move, Resize</dd> - * </dl> - * <p> - * Note: Rectangle move behavior is assumed unless RESIZE is specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Tracker extends Widget { - Composite parent; - Display display; - boolean tracking, stippled; - Rectangle [] rectangles, proportions; - int cursorOrientation = SWT.NONE; - int cursor; - final static int STEPSIZE_SMALL = 1; - final static int STEPSIZE_LARGE = 9; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of widget to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#RESIZE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Tracker (Composite parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - display = parent.getDisplay (); -} - -/** - * Constructs a new instance of this class given the display - * to create it on and a style value describing its behavior - * and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p><p> - * Note: Currently, null can be passed in for the display argument. - * This has the effect of creating the tracker on the currently active - * display if there is one. If there is no current display, the - * tracker is created on a "default" display. <b>Passing in null as - * the display argument is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param display the display to create the tracker on - * @param style the style of control to construct - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#RESIZE - */ -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 = checkStyle (style); - this.display = display; -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is moved or resized, by sending - * it one of the messages defined in the <code>ControlListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #removeControlListener - */ -public void addControlListener (ControlListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Move,typedListener); -} - -Point adjustMoveCursor (int xDisplay, int xWindow) { - int actualX[] = new int[1]; - int actualY[] = new int[1]; - - /* AW - Rectangle bounds = computeBounds (); - int newX = bounds.x + bounds.width / 2; - int newY = bounds.y; - */ - - /* AW - OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, newX, newY); - */ - /* - * The call to XWarpPointer does not always place the pointer on the - * exact location that is specified, so do a query (below) to get the - * actual location of the pointer after it has been moved. - */ - /* AW - OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused); - */ - return new Point (actualX[0], actualY[0]); -} -Point adjustResizeCursor (int xDisplay, int xWindow) { - /* AW - int newX, newY; - Rectangle bounds = computeBounds (); - - if ((cursorOrientation & SWT.LEFT) != 0) { - newX = bounds.x; - } else if ((cursorOrientation & SWT.RIGHT) != 0) { - newX = bounds.x + bounds.width; - } else { - newX = bounds.x + bounds.width / 2; - } - - if ((cursorOrientation & SWT.UP) != 0) { - newY = bounds.y; - } else if ((cursorOrientation & SWT.DOWN) != 0) { - newY = bounds.y + bounds.height; - } else { - newY = bounds.y + bounds.height / 2; - } - */ - - int actualX[] = new int[1]; - int actualY[] = new int[1]; - /* AW - OS.XWarpPointer (xDisplay, SWT.NONE, xWindow, 0, 0, 0, 0, newX, newY); - */ - /* - * The call to XWarpPointer does not always place the pointer on the - * exact location that is specified, so do a query (below) to get the - * actual location of the pointer after it has been moved. - */ - /* AW - OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused); - */ - return new Point (actualX[0], actualY[0]); -} -static int checkStyle (int style) { - if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) { - style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN; - } - return style; -} -/** - * Stops displaying the tracker rectangles. Note that this is not considered - * to be a cancelation by the user. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void close () { - checkWidget (); - tracking = false; -} -Rectangle computeBounds () { - int xMin = rectangles [0].x; - int yMin = rectangles [0].y; - int xMax = rectangles [0].x + rectangles [0].width; - int yMax = rectangles [0].y + rectangles [0].height; - - for (int i = 1; i < rectangles.length; i++) { - if (rectangles [i].x < xMin) xMin = rectangles [i].x; - if (rectangles [i].y < yMin) yMin = rectangles [i].y; - int rectRight = rectangles [i].x + rectangles [i].width; - if (rectRight > xMax) xMax = rectRight; - int rectBottom = rectangles [i].y + rectangles [i].height; - if (rectBottom > yMax) yMax = rectBottom; - } - - return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin); -} - -Rectangle [] computeProportions (Rectangle [] rects) { - Rectangle [] result = new Rectangle [rects.length]; - Rectangle bounds = computeBounds (); - for (int i = 0; i < rects.length; i++) { - result[i] = new Rectangle ( - (rects[i].x - bounds.x) * 100 / bounds.width, - (rects[i].y - bounds.y) * 100 / bounds.height, - rects[i].width * 100 / bounds.width, - rects[i].height * 100 / bounds.height); - } - return result; -} - -void drawRectangles () { - if (parent != null) { - if (parent.isDisposed ()) return; - parent.getShell ().update (); - } else { - display.update (); - } - /* AW - 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; -} -/** - * Returns the bounds that are being drawn, expressed relative to the parent - * widget. If the parent is a <code>Display</code> then these are screen - * coordinates. - * - * @return the bounds of the Rectangles being drawn - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle [] getRectangles () { - checkWidget (); - return rectangles; -} -/** - * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise. - * - * @return the stippled effect of the rectangles - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getStippled () { - checkWidget (); - return stippled; -} - -void moveRectangles (int xChange, int yChange) { - if (xChange < 0 && ((style & SWT.LEFT) == 0)) return; - if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return; - if (yChange < 0 && ((style & SWT.UP) == 0)) return; - if (yChange > 0 && ((style & SWT.DOWN) == 0)) return; - for (int i = 0; i < rectangles.length; i++) { - rectangles [i].x += xChange; - rectangles [i].y += yChange; - } -} - -/** - * Displays the Tracker rectangles for manipulation by the user. Returns when - * the user has either finished manipulating the rectangles or has cancelled the - * Tracker. - * - * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean open () { - checkWidget (); - if (rectangles == null) return false; - /* AW - 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 (); - int [] oldX = new int [1], oldY = new int [1]; - int [] unused = new int [1]; - Point cursorPos; - if ((style & SWT.MENU) != 0) { - if ((style & SWT.RESIZE) != 0) { - cursorPos = adjustResizeCursor (xDisplay, xWindow); - } else { - cursorPos = adjustMoveCursor (xDisplay, xWindow); - } - oldX [0] = cursorPos.x; oldY [0] = cursorPos.y; - } else { - OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, unused); - } - - XAnyEvent xEvent = new XAnyEvent (); - int [] newX = new int [1], newY = new int [1]; - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - - int ptrGrabResult = OS.XGrabPointer ( - xDisplay, - xWindow, - 0, - OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, - OS.GrabModeAsync, - OS.GrabModeAsync, - OS.None, - OS.None, - OS.CurrentTime); - int kbdGrabResult = OS.XGrabKeyboard ( - xDisplay, - xWindow, - 0, - OS.GrabModeAsync, - OS.GrabModeAsync, - OS.CurrentTime); - */ - /* - * Tracker behaves like a Dialog with its own OS event loop. - */ - /* AW - while (tracking) { - if (parent != null && parent.isDisposed ()) break; - OS.XtAppNextEvent (xtContext, xEvent); - switch (xEvent.type) { - case OS.MotionNotify: - if (cursor != 0) { - OS.XChangeActivePointerGrab ( - xDisplay, - OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, - cursor, - OS.CurrentTime); - } - // fall through - case OS.ButtonRelease: - OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused); - if (oldX [0] != newX [0] || oldY [0] != newY [0]) { - drawRectangles (); - Event event = new Event (); - event.x = newX [0]; - event.y = newY [0]; - if ((style & SWT.RESIZE) != 0) { - resizeRectangles (newX [0] - oldX [0], newY [0] - oldY [0]); - sendEvent (SWT.Resize, event); - cursorPos = adjustResizeCursor (xDisplay, xWindow); - newX [0] = cursorPos.x; newY [0] = cursorPos.y; - } else { - moveRectangles (newX [0] - oldX [0], newY [0] - oldY [0]); - sendEvent (SWT.Move, event); - } - */ - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the move event. - * If this happens then return false to indicate that - * the move failed. - */ - /* AW - if (isDisposed ()) { - if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); - if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); - return false; - } - 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, null); - keysym [0] &= 0xFFFF; - int xChange = 0, yChange = 0; - int stepSize = ((keyEvent.state & OS.ControlMask) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE; - switch (keysym [0]) { - case OS.XK_Return: - tracking = false; - */ - /* - * Eat the subsequent KeyRelease event - */ - /* AW - OS.XtAppNextEvent (xtContext, xEvent); - break; - case OS.XK_Escape: - case OS.XK_Cancel: - tracking = false; - cancelled = true; - */ - /* - * Eat the subsequent KeyRelease event - */ - /* AW - OS.XtAppNextEvent (xtContext, xEvent); - break; - case OS.XK_Left: - xChange = -stepSize; - break; - case OS.XK_Right: - xChange = stepSize; - break; - case OS.XK_Up: - yChange = -stepSize; - break; - case OS.XK_Down: - yChange = stepSize; - break; - } - if (xChange != 0 || yChange != 0) { - drawRectangles (); - Event event = new Event (); - event.x = oldX[0] + xChange; - event.y = oldY[0] + yChange; - if ((style & SWT.RESIZE) != 0) { - resizeRectangles (xChange, yChange); - sendEvent (SWT.Resize, event); - cursorPos = adjustResizeCursor (xDisplay, xWindow); - } else { - moveRectangles (xChange, yChange); - sendEvent (SWT.Move, event); - cursorPos = adjustMoveCursor (xDisplay, xWindow); - } - */ - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the move event. - * If this happens then return false to indicate that - * the move failed. - */ - /* AW - if (isDisposed ()) { - if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); - if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); - return false; - } - drawRectangles (); - oldX[0] = cursorPos.x; oldY[0] = cursorPos.y; - } - } - break; - case OS.EnterNotify: - case OS.LeaveNotify: - */ - /* - * Do not dispatch these - */ - /* AW - break; - default: - OS.XtDispatchEvent (xEvent); - } - } - drawRectangles (); - tracking = false; - if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); - if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); - return !cancelled; - */ - return false; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is moved or resized. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #addControlListener - */ -public void removeControlListener (ControlListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Move, listener); -} -void resizeRectangles (int xChange, int yChange) { - /* - * If the cursor orientation has not been set in the orientation of - * this change then try to set it here. - */ - if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) { - cursorOrientation |= SWT.LEFT; - } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) { - cursorOrientation |= SWT.RIGHT; - } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) { - cursorOrientation |= SWT.UP; - } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) { - cursorOrientation |= SWT.DOWN; - } - Rectangle bounds = computeBounds (); - if ((cursorOrientation & SWT.LEFT) != 0) { - bounds.x += xChange; - bounds.width -= xChange; - } else if ((cursorOrientation & SWT.RIGHT) != 0) { - bounds.width += xChange; - } - if ((cursorOrientation & SWT.UP) != 0) { - bounds.y += yChange; - bounds.height -= yChange; - } else if ((cursorOrientation & SWT.DOWN) != 0) { - bounds.height += yChange; - } - /* - * The following are conditions under which the resize should not be applied - */ - if (bounds.width < 0 || bounds.height < 0) return; - - Rectangle [] newRects = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle proportion = proportions[i]; - newRects[i] = new Rectangle ( - proportion.x * bounds.width / 100 + bounds.x, - proportion.y * bounds.height / 100 + bounds.y, - proportion.width * bounds.width / 100, - proportion.height * bounds.height / 100); - } - rectangles = newRects; -} - -/** - * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code> - * then the cursor reverts to the default. - * - * @param newCursor the new <code>Cursor</code> to display - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCursor (Cursor value) { - checkWidget (); - cursor = 0; - if (value != null) cursor = value.handle; -} -/** - * Specifies the rectangles that should be drawn, expressed relative to the parent - * widget. If the parent is a Display then these are screen coordinates. - * - * @param rectangles the bounds of the rectangles to be drawn - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setRectangles (Rectangle [] rectangles) { - checkWidget (); - this.rectangles = rectangles; - proportions = computeProportions (rectangles); -} -/** - * Changes the appearance of the line used to draw the rectangles. - * - * @param stippled <code>true</code> if rectangle should appear stippled - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setStippled (boolean stippled) { - checkWidget (); - this.stippled = stippled; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree2.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree2.java deleted file mode 100644 index 066288a7bc..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree2.java +++ /dev/null @@ -1,1669 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TreeListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.internal.carbon.OS; -import org.eclipse.swt.internal.carbon.DataBrowserListViewColumnDesc; -import org.eclipse.swt.internal.carbon.DataBrowserCallbacks; - -/** - * Instances of this class provide a selectable user interface object - * that displays a hierarchy of items and issue notificiation when an - * item in the hierarchy is selected. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TreeItem2</code>. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add <code>Control</code> children to it, - * or set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SINGLE, MULTI, CHECK</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection, Collapse, Expand</dd> - * </dl> - * <p> - * Note: Only one of the styles SINGLE and MULTI may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Tree2 extends Composite { - /* AW - int hAnchor; - */ - TreeItem2 [] items; - - // AW - static final int CHECK_COL_ID= 12345; - static final int COL_ID= 12346; - private static final int FIRST_ROW_ID= 1000; - - TreeItem2 fRoot; - // AW - - /* AW - ImageList imageList; - boolean dragStarted; - boolean ignoreSelect, ignoreExpand, ignoreDeselect; - boolean customDraw; - */ - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SINGLE - * @see SWT#MULTI - * @see SWT#CHECK - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Tree2 (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the item field of the event object is valid. - * If the reciever has <code>SWT.CHECK</code> style set and the check selection changes, - * the event object detail field contains the value <code>SWT.CHECK</code>. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * The item field of the event object is valid for default selection, but the detail field is not used. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget (); - 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 the collection of listeners who will - * be notified when an item in the receiver is expanded or collapsed - * by sending it one of the messages defined in the <code>TreeListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see TreeListener - * @see #removeTreeListener - */ -public void addTreeListener(TreeListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Expand, typedListener); - addListener (SWT.Collapse, typedListener); -} - -static int checkStyle (int style) { - /* - * Feature in Windows. It is not possible to create - * a tree that scrolls and does not have scroll bars. - * The TVS_NOSCROLL style will remove the scroll bars - * but the tree will never scroll. Therefore, no matter - * what style bits are specified, set the H_SCROLL and - * V_SCROLL bits so that the SWT style will match the - * widget that Windows creates. - */ - style |= SWT.H_SCROLL | SWT.V_SCROLL; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int width = 0, height = 0; - /* AW - RECT rect = new RECT (); - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); - while (hItem != 0) { - rect.left = hItem; - if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect) != 0) { - width = Math.max (width, rect.right - rect.left); - height += rect.bottom - rect.top; - } - hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem); - } - width = width * 2; - if (width == 0) width = DEFAULT_WIDTH; - if (height == 0) height = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - int border = getBorderWidth (); - width += border * 2; height += border * 2; - if ((style & SWT.V_SCROLL) != 0) { - width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); - } - if ((style & SWT.H_SCROLL) != 0) { - height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); - } - */ - width= 200; - height= 200; - return new Point (width, height); -} - -void createHandle (int index) { - /* AW FIXME!!!! - super.createHandle (); - */ - state |= HANDLE; - state &= ~CANVAS; - - int parentHandle= parent.handle; - int windowHandle= OS.GetControlOwner(parentHandle); - int[] controlRef= new int[1]; - OS.CreateDataBrowserControl(windowHandle, null, OS.kDataBrowserListView, controlRef); - handle= controlRef[0]; - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - DataBrowserCallbacks callbacks= new DataBrowserCallbacks(); - callbacks.version= OS.kDataBrowserLatestCallbacks; - OS.InitDataBrowserCallbacks(callbacks); - OS.SetDataBrowserCallbacks(controlRef[0], callbacks); - - //OS.HIViewAddSubview(parentHandle, handle); - MacUtil.insertControl(handle, parentHandle, -1); - - /* Single or Multiple Selection */ - int mode= OS.kDataBrowserSelectOnlyOne | OS.kDataBrowserNeverEmptySelectionSet; - if ((style & SWT.MULTI) != 0) - mode= OS.kDataBrowserDragSelect | OS.kDataBrowserCmdTogglesSelection; - OS.SetDataBrowserSelectionFlags(handle, mode); - - /* hide the header */ - OS.SetDataBrowserListViewHeaderBtnHeight(handle, (short) 0); - - /* enable scrollbars */ - OS.SetDataBrowserHasScrollBars(handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0); - if ((style & SWT.H_SCROLL) == 0) - OS.AutoSizeDataBrowserListViewColumns(handle); - - if ((style & SWT.CHECK) != 0) { - DataBrowserListViewColumnDesc checkColumnDesc= new DataBrowserListViewColumnDesc(); - checkColumnDesc.propertyDesc_propertyID= CHECK_COL_ID; - checkColumnDesc.propertyDesc_propertyType= OS.kDataBrowserCheckboxType; - checkColumnDesc.propertyDesc_propertyFlags= OS.kDataBrowserPropertyIsMutable; - - checkColumnDesc.headerBtnDesc_version= OS.kDataBrowserListViewLatestHeaderDesc; - checkColumnDesc.headerBtnDesc_minimumWidth= 40; - checkColumnDesc.headerBtnDesc_maximumWidth= 40; - - checkColumnDesc.headerBtnDesc_titleOffset= 0; - checkColumnDesc.headerBtnDesc_titleString= 0; - checkColumnDesc.headerBtnDesc_initialOrder= OS.kDataBrowserOrderIncreasing; - - /* - checkColumnDesc.headerBtnDesc_titleAlignment= teCenter; - checkColumnDesc.headerBtnDesc_titleFontTypeID= OS.kControlFontViewSystemFont; - checkColumnDesc.headerBtnDesc_btnFontStyle= normal; - */ - OS.AddDataBrowserListViewColumn(handle, checkColumnDesc, 1999); - } - - DataBrowserListViewColumnDesc columnDesc= new DataBrowserListViewColumnDesc(); - columnDesc.propertyDesc_propertyID= COL_ID; - columnDesc.propertyDesc_propertyType= OS.kDataBrowserTextType; // OS.kDataBrowserIconAndTextType - columnDesc.propertyDesc_propertyFlags= OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags; - - columnDesc.headerBtnDesc_version= OS.kDataBrowserListViewLatestHeaderDesc; - columnDesc.headerBtnDesc_minimumWidth= 0; - columnDesc.headerBtnDesc_maximumWidth= 300; - - columnDesc.headerBtnDesc_titleOffset= 0; - columnDesc.headerBtnDesc_titleString= 0; - columnDesc.headerBtnDesc_initialOrder= OS.kDataBrowserOrderIncreasing; - - /* - columnDesc.headerBtnDesc_titleAlignment= teCenter; - columnDesc.headerBtnDesc_titleFontTypeID= OS.kControlFontViewSystemFont; - columnDesc.headerBtnDesc_btnFontStyle= normal; - */ - OS.AddDataBrowserListViewColumn(handle, columnDesc, 2000); - OS.SetDataBrowserListViewDisclosureColumn(handle, COL_ID, false); - - /* - Display disp= getDisplay(); - Font font= Font.carbon_new (disp, disp.getThemeFont(OS.kThemeSmallSystemFont)); - if (OS.SetControlFontStyle(handle, font.handle.fID, font.handle.fSize, font.handle.fFace) != OS.noErr) - System.out.println("Tree2.setFont("+this+"): error"); - */ -} - -void createItem (TreeItem2 item, TreeItem2 itemParent, int hInsertAfter) { - item.foreground = item.background = -1; - - int id = 0; - while (id < items.length && items [id] != null) id++; - if (id == items.length) { - TreeItem2 [] newItems = new TreeItem2 [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - items [id] = item; - - item.handle= id + FIRST_ROW_ID; - - if (itemParent != null) - itemParent.addChild(item); -} - -ScrollBar createScrollBar (int type) { - return createStandardBar (type); -} - -void createWidget (int index) { - super.createWidget (index); - items = new TreeItem2 [4]; - - fRoot= new TreeItem2(this); - fRoot.setText("Root"); - fRoot.fIsOpen= true; - //OS.SetDataBrowserTarget(handle, fRoot.handle); // opens node -} - -int defaultBackground () { - /* AW - return OS.GetSysColor (OS.COLOR_WINDOW); - */ - return 0x00FFFFFF; -} - -/** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselectAll () { - checkWidget (); - /* AW - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_SELECTED; - if ((style & SWT.SINGLE) != 0) { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem != 0) { - tvItem.hItem = hItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - return; - } - int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); - OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc); - for (int i=0; i<items.length; i++) { - TreeItem2 item = items [i]; - if (item != null) { - tvItem.hItem = item.handle; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - } - OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc); - */ - /* - int n= fData.size(); - if (n <= 0) return; - int[] ids= getIds(0, n-1); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsRemove); - */ -} - -void destroyItem (TreeItem2 item) { - int hItem = item.handle; - /* AW - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; - */ - releaseItems (new TreeItem2 [] {item} /*, tvItem */); - /* AW - boolean fixRedraw = false; - if (drawCount == 0 && OS.IsWindowVisible (handle)) { - RECT rect = new RECT (); - rect.left = hItem; - fixRedraw = OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) == 0; - } - if (fixRedraw) { - OS.UpdateWindow (handle); - OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); - } - OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem); - */ - TreeItem2 parent= item.getParentItem(); - if (parent != null) - parent.removeChild(item); - /* - if (fixRedraw) { - OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); - OS.ValidateRect (handle, null); - } - int count = OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0); - if (count == 0) { - if (imageList != null) { - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0); - Display display = getDisplay (); - display.releaseImageList (imageList); - } - imageList = null; - customDraw = false; - items = new TreeItem2 [4]; - } - */ -} - -int getBackgroundPixel () { - /* AW - if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW); - int pixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0); - if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOW); - return pixel; - */ - return 0x00ffffff; -} - -int getForegroundPixel () { - /* AW - if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOWTEXT); - int pixel = OS.SendMessage (handle, OS.TVM_GETTEXTCOLOR, 0, 0); - if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOWTEXT); - return pixel; - */ - return 0x00000000; -} - -/** - * Returns the item at the given point in the receiver - * or null if no such item exists. The point is in the - * coordinate system of the receiver. - * - * @param point the point used to locate the item - * @return the item at the given point - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 getItem (Point point) { - checkWidget (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - /* AW - TVHITTESTINFO lpht = new TVHITTESTINFO (); - lpht.x = point.x; lpht.y = point.y; - OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht); - if (lpht.hItem != 0 && (lpht.flags & OS.TVHT_ONITEM) != 0) { - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; - tvItem.hItem = lpht.hItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - return items [tvItem.lParam]; - } - */ - return null; -} - -/** - * Returns the number of items contained in the receiver - * that are direct item children of the receiver. The - * number that is returned is the number of roots in the - * tree. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget (); - return fRoot.getItemCount(); -} - -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the tree. - * - * @return the height of one item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemHeight () { - checkWidget (); - /* AW - return OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0); - */ - return 15; -} - -/** - * Returns the number of items contained in the receiver - * that are direct item children of the receiver. These - * are the roots of the tree. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 [] getItems () { - checkWidget (); - return fRoot.getItems(); -} - -/** - * Returns the receiver's parent item, which must be a - * <code>TreeItem2</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 getParentItem () { - checkWidget (); - return null; -} - -/** - * Returns an array of <code>TreeItem2</code>s that are currently - * selected in the receiver. An empty array indicates that no - * items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return an array representing the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 [] getSelection () { - checkWidget (); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, true); - TreeItem2[] result= new TreeItem2[ids.length]; - for (int i= 0; i < ids.length; i++) - result[i]= find(ids[i]); - return result; -} - -/** - * Returns the number of selected items contained in the receiver. - * - * @return the number of selected items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget (); - int[] result= new int[1]; - if (OS.GetDataBrowserItemCount(handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, result) != OS.noErr) - error (SWT.ERROR_CANNOT_GET_COUNT); - return result[0]; -} - -void hookEvents () { - super.hookEvents (); - Display display= getDisplay(); - DataBrowserCallbacks callbacks= new DataBrowserCallbacks(); - OS.GetDataBrowserCallbacks(handle, callbacks); - callbacks.v1_itemDataCallback= display.fDataBrowserDataProc; - callbacks.v1_itemCompareCallback= display.fDataBrowserCompareProc; - callbacks.v1_itemNotificationCallback= display.fDataBrowserItemNotificationProc; - OS.SetDataBrowserCallbacks(handle, callbacks); -} - -/* AW -int imageIndex (Image image) { - if (image == null) return OS.I_IMAGENONE; - if (imageList == null) { - int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0); - if (hOldList != 0) OS.ImageList_Destroy (hOldList); - Rectangle bounds = image.getBounds (); - imageList = getDisplay ().getImageList (new Point (bounds.width, bounds.height)); - int index = imageList.indexOf (image); - if (index == -1) index = imageList.add (image); - int hImageList = imageList.getHandle (); - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList); - return index; - } - int index = imageList.indexOf (image); - if (index != -1) return index; - return imageList.add (image); -} -*/ - -void releaseItems (TreeItem2 [] nodes /*, TVITEM tvItem */) { - for (int i=0; i<nodes.length; i++) { - TreeItem2 item = nodes [i]; - TreeItem2 [] sons = item.getItems (); - if (sons.length != 0) { - releaseItems (sons /*, tvItem */); - } - int hItem = item.handle; - /* AW - if (hItem == hAnchor) hAnchor = 0; - */ - if (!item.isDisposed ()) { - /* AW - tvItem.hItem = hItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - items [tvItem.lParam] = null; - */ - items [hItem - FIRST_ROW_ID] = null; - item.releaseResources (); - } - } -} - -void releaseWidget () { - for (int i=0; i<items.length; i++) { - TreeItem2 item = items [i]; - if (item != null && !item.isDisposed ()) { - item.releaseResources (); - } - } - /* - * Feature in Windows. For some reason, when - * TVM_GETIMAGELIST or TVM_SETIMAGELIST is sent, - * the tree issues NM_CUSTOMDRAW messages. This - * behavior is unwanted when the tree is being - * disposed. The fix is to ingore NM_CUSTOMDRAW - * messages by usnig the custom draw flag. - * - * NOTE: This only happens on Windows XP. - */ - /* AW - customDraw = false; - items = null; - if (imageList != null) { - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0); - Display display = getDisplay (); - display.releaseImageList (imageList); - } else { - int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0); - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0); - if (hOldList != 0) OS.ImageList_Destroy (hOldList); - } - imageList = null; - int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0); - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, 0); - if (hOldList != 0) OS.ImageList_Destroy (hOldList); - */ - super.releaseWidget (); -} - - -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget (); - /* AW - ignoreDeselect = ignoreSelect = true; - int result = OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, OS.TVI_ROOT); - ignoreDeselect = ignoreSelect = false; - if (result == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); - */ - for (int i=0; i<items.length; i++) { - TreeItem2 item = items [i]; - if (item != null && !item.isDisposed ()) { - item.releaseResources (); - } - } - /* AW - if (imageList != null) { - OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0); - Display display = getDisplay (); - display.releaseImageList (imageList); - } - imageList = null; - customDraw = false; - */ - items = new TreeItem2 [4]; - /* AW - hAnchor = 0; - */ -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when items in the receiver are expanded or collapsed.. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see TreeListener - * @see #addTreeListener - */ -public void removeTreeListener(TreeListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Expand, listener); - eventTable.unhook (SWT.Collapse, listener); -} - -/** - * 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. - * - * @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'. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setInsertMark (TreeItem2 item, boolean before) { - checkWidget (); - int hItem = 0; - if (item != null) { - if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - hItem = item.handle; - } - /* AW - OS.SendMessage (handle, OS.TVM_SETINSERTMARK, (before) ? 0 : 1, hItem); - */ -} - -/** - * Selects all the items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void selectAll () { - checkWidget (); - if ((style & SWT.SINGLE) != 0) return; - int[] ids= MacUtil.getDataBrowserItems(handle, OS.kDataBrowserNoItem, 0, true); - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} - -void setBackgroundPixel (int pixel) { - if (background == pixel) return; - background = pixel; - /* - * Bug in Windows. When TVM_GETBKCOLOR is used more - * than once to set the background color of a tree, - * the background color of the lines and the plus/minus - * does not change to the new color. The fix is to set - * the background color to the default before setting - * the new color. - */ - /* AW - int oldPixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0); - if (oldPixel != -1) OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1); - OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, pixel); - if ((style & SWT.CHECK) != 0) setCheckboxImageList (); - */ -} - -void setForegroundPixel (int pixel) { - if (foreground == pixel) return; - foreground = pixel; - /* AW - OS.SendMessage (handle, OS.TVM_SETTEXTCOLOR, 0, pixel); - */ -} - -public void setRedraw (boolean redraw) { - checkWidget (); - /* - * Bug in Windows. For some reason, when WM_SETREDRAW - * is used to turn redraw on for a tree and the tree - * contains no items, the last item in the tree does - * not redraw properly. If the tree has only one item, - * that item is not drawn. If another window is dragged - * on top of the item, parts of the item are redrawn - * and erased at random. The fix is to ensure that this - * case doesn't happen by inserting and deleting an item - * when redraw is turned on and there are no items in - * the tree. - */ - /* AW - int hItem = 0; - if (redraw) { - int count = OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0); - if (count == 0) { - TVINSERTSTRUCT tvInsert = new TVINSERTSTRUCT (); - tvInsert.hInsertAfter = OS.TVI_FIRST; - hItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert); - } - } - super.setRedraw (redraw); - if (hItem != 0) { - OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem); - } - */ -} - -/** - * Sets the receiver's selection to be the given array of items. - * The current selected is first cleared, then the new items are - * selected. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Tree2#deselectAll() - */ -public void setSelection (TreeItem2 [] items) { - checkWidget (); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - int[] ids= new int[items.length]; - for (int i= 0; i < items.length; i++) - ids[i]= items[i].handle; - OS.SetDataBrowserSelectedItems(handle, ids.length, ids, OS.kDataBrowserItemsAssign); -} - -void showItem (int hItem) { - if (OS.RevealDataBrowserItem(handle, hItem, COL_ID, false) != OS.noErr) - System.out.println("Tree2.RevealDataBrowserItem"); -} - -/** - * Shows the item. If the item is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled - * and expanded until the item is visible. - * - * @param item the item to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Tree2#showSelection() - */ -public void showItem (TreeItem2 item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - showItem (item.handle); -} - -/** - * Shows the selection. If the selection is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled until - * the selection is visible. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Tree2#showItem(TreeItem2) - */ -public void showSelection () { - checkWidget (); - int[] ids= MacUtil.getSelectionIDs(handle, OS.kDataBrowserNoItem, true); - if (ids.length > 0 && ids[0] != 0) - OS.RevealDataBrowserItem(handle, ids[0], COL_ID, false); -} - -///////////////////////////////////////////////////////////////////////////////////////////////// - -/* AW -LRESULT WM_KEYDOWN (int wParam, int lParam) { - LRESULT result = super.WM_KEYDOWN (wParam, lParam); - if (result != null) return result; - switch (wParam) { - case OS.VK_SPACE: { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem != 0) { - hAnchor = hItem; - OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem); - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE | OS.TVIF_PARAM; - tvItem.hItem = hItem; - if ((style & SWT.CHECK) != 0) { - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - int state = tvItem.state >> 12; - if ((state & 0x1) != 0) { - state++; - } else { - --state; - } - tvItem.state = state << 12; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - tvItem.stateMask = OS.TVIS_SELECTED; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - if ((style & SWT.MULTI) != 0 && OS.GetKeyState (OS.VK_CONTROL) < 0) { - if ((tvItem.state & OS.TVIS_SELECTED) != 0) { - tvItem.state &= ~OS.TVIS_SELECTED; - } else { - tvItem.state |= OS.TVIS_SELECTED; - } - } else { - tvItem.state |= OS.TVIS_SELECTED; - } - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - Event event = new Event (); - event.item = items [tvItem.lParam]; - postEvent (SWT.Selection, event); - if ((style & SWT.CHECK) != 0) { - event = new Event (); - event.item = items [tvItem.lParam]; - event.detail = SWT.CHECK; - postEvent (SWT.Selection, event); - } - return LRESULT.ZERO; - } - break; - } - case OS.VK_UP: - case OS.VK_DOWN: - case OS.VK_PRIOR: - case OS.VK_NEXT: - case OS.VK_HOME: - case OS.VK_END: { - if ((style & SWT.SINGLE) != 0) break; - if (OS.GetKeyState (OS.VK_SHIFT) < 0) { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem != 0) { - if (hAnchor == 0) hAnchor = hItem; - ignoreSelect = ignoreDeselect = true; - int code = callWindowProc (OS.WM_KEYDOWN, wParam, lParam); - ignoreSelect = ignoreDeselect = false; - int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_SELECTED; - int hDeselectItem = hItem; - RECT rect1 = new RECT (); - rect1.left = hAnchor; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); - RECT rect2 = rect2 = new RECT (); - rect2.left = hDeselectItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); - int flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE; - while (hDeselectItem != hAnchor) { - tvItem.hItem = hDeselectItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - hDeselectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hDeselectItem); - } - int hSelectItem = hAnchor; - rect1.left = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); - rect2.left = hSelectItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); - tvItem.state = OS.TVIS_SELECTED; - flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE; - while (hSelectItem != hNewItem) { - tvItem.hItem = hSelectItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - hSelectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hSelectItem); - } - tvItem.hItem = hNewItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - tvItem.mask = OS.TVIF_PARAM; - tvItem.hItem = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - Event event = new Event (); - event.item = items [tvItem.lParam]; - postEvent (SWT.Selection, event); - return new LRESULT (code); - } - } - if (OS.GetKeyState (OS.VK_CONTROL) < 0) { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem != 0) { - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_SELECTED; - tvItem.hItem = hItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - boolean oldSelected = (tvItem.state & OS.TVIS_SELECTED) != 0; - int hNewItem = 0; - switch (wParam) { - case OS.VK_UP: - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUSVISIBLE, hItem); - break; - case OS.VK_DOWN: - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem); - break; - case OS.VK_HOME: - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); - break; - case OS.VK_PRIOR: - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); - if (hNewItem == hItem) { - OS.SendMessage (handle, OS.WM_VSCROLL, OS.SB_PAGEUP, 0); - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); - } - break; - case OS.VK_NEXT: - RECT rect = new RECT (), clientRect = new RECT (); - OS.GetClientRect (handle, clientRect); - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); - do { - int hVisible = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hNewItem); - if (hVisible == 0) break; - rect.left = hVisible; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect); - if (rect.bottom > clientRect.bottom) break; - if ((hNewItem = hVisible) == hItem) { - OS.SendMessage (handle, OS.WM_VSCROLL, OS.SB_PAGEDOWN, 0); - } - } while (hNewItem != 0); - break; - case OS.VK_END: - hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0); - break; - } - if (hNewItem != 0) { - OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hNewItem); - tvItem.hItem = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - boolean newSelected = (tvItem.state & OS.TVIS_SELECTED) != 0; - if (!newSelected && drawCount == 0) { - OS.UpdateWindow (handle); - OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); - */ - /* - * This code is intentionally commented. - */ -// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); -/* AW } - ignoreSelect = true; - OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem); - ignoreSelect = false; - if (oldSelected) { - tvItem.state = OS.TVIS_SELECTED; - tvItem.hItem = hItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - if (!newSelected) { - tvItem.state = 0; - tvItem.hItem = hNewItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - if (!newSelected && drawCount == 0) { - RECT rect1 = new RECT (), rect2 = new RECT (); - rect1.left = hItem; rect2.left = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); - */ - /* - * This code is intentionally commented. - */ -// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); -/* AW - OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); - if (OS.IsWinCE) { - OS.InvalidateRect (handle, rect1, false); - OS.InvalidateRect (handle, rect2, false); - OS.UpdateWindow (handle); - } else { - int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE; - OS.RedrawWindow (handle, rect1, 0, flags); - OS.RedrawWindow (handle, rect2, 0, flags); - } - } - return LRESULT.ZERO; - } - } - } - int code = callWindowProc (OS.WM_KEYDOWN, wParam, lParam); - hAnchor = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - return new LRESULT (code); - } - } - return result; -} -*/ - -/* AW -LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { - */ - /* - * Feature in Windows. When a tree item is - * reselected, Windows does not issue a WM_NOTIFY. - * This is inconsistent with the list widget and - * other widgets in Windows. The fix is to detect - * the case when an item is reselected and issue - * the notification. The first part of this work - * around is to ensure that the user has selected - * an item. - */ - /* AW - TVHITTESTINFO lpht = new TVHITTESTINFO (); - lpht.x = (short) (lParam & 0xFFFF); - lpht.y = (short) (lParam >> 16); - OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht); - if (lpht.hItem == 0 || (lpht.flags & OS.TVHT_ONITEM) == 0) { - sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam); - int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam); - if (OS.GetCapture () != handle) OS.SetCapture (handle); - return new LRESULT (code); - } - */ - - /* Look for check/uncheck */ - /* AW - if ((style & SWT.CHECK) != 0) { - if ((lpht.flags & OS.TVHT_ONITEMSTATEICON) != 0) { - TVITEM tvItem = new TVITEM (); - tvItem.hItem = lpht.hItem; - tvItem.mask = OS.TVIF_PARAM | OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - int state = tvItem.state >> 12; - if ((state & 0x1) != 0) { - state++; - } else { - --state; - } - tvItem.state = state << 12; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - Event event = new Event (); - event.item = items [tvItem.lParam]; - event.detail = SWT.CHECK; - postEvent (SWT.Selection, event); - sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam); - if (OS.GetCapture () != handle) OS.SetCapture (handle); - return LRESULT.ZERO; - } - } - */ - - /* Get the selected state of the item under the mouse */ - /* AW - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_SELECTED; - boolean hittestSelected = false; - if ((style & SWT.MULTI) != 0) { - tvItem.hItem = lpht.hItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - hittestSelected = (tvItem.state & OS.TVIS_SELECTED) != 0; - } - */ - - /* Get the selected state of the last selected item */ - /* AW - int hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if ((style & SWT.MULTI) != 0) { - tvItem.hItem = hOldItem; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - */ - /* Check for CONTROL or drag selection */ - /* AW - if (hittestSelected || (wParam & OS.MK_CONTROL) != 0) { - if (drawCount == 0) { - OS.UpdateWindow (handle); - OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); - /* - * This code is intentionally commented. - */ -// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); -/* AW - } - } else { - deselectAll (); - } - } -*/ - /* Do the selection */ - /* AW - sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam); - dragStarted = false; - ignoreDeselect = ignoreSelect = true; - int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam); - ignoreDeselect = ignoreSelect = false; - if (dragStarted && OS.GetCapture () != handle) OS.SetCapture (handle); - int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - */ - - /* - * Feature in Windows. When the old and new focused item - * are the same, Windows does not check to make sure that - * the item is actually selected, not just focused. The - * fix is to force the item to draw selected by setting - * the state mask. This is only necessary when the tree - * is single select. - */ - /* AW - if ((style & SWT.SINGLE) != 0) { - if (hOldItem == hNewItem) { - tvItem.mask = OS.TVIF_STATE; - tvItem.state = OS.TVIS_SELECTED; - tvItem.stateMask = OS.TVIS_SELECTED; - tvItem.hItem = hNewItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - } - */ - - /* Reselect the last item that was unselected */ - /* AW - if ((style & SWT.MULTI) != 0) { - - /* Check for CONTROL and reselect the last item */ - /* AW - if (hittestSelected || (wParam & OS.MK_CONTROL) != 0) { - if (hOldItem == hNewItem && hOldItem == lpht.hItem) { - if ((wParam & OS.MK_CONTROL) != 0) { - tvItem.state ^= OS.TVIS_SELECTED; - if (dragStarted) tvItem.state = OS.TVIS_SELECTED; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - } else { - if ((tvItem.state & OS.TVIS_SELECTED) != 0) { - tvItem.state = OS.TVIS_SELECTED; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - if ((wParam & OS.MK_CONTROL) != 0 && !dragStarted) { - if (hittestSelected) { - tvItem.state = 0; - tvItem.hItem = lpht.hItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - } - } - if (drawCount == 0) { - RECT rect1 = new RECT (), rect2 = new RECT (); - rect1.left = hOldItem; rect2.left = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1); - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); - /* - * This code is intentionally commented. - */ -// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); -/* AW - OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); - if (OS.IsWinCE) { - OS.InvalidateRect (handle, rect1, false); - OS.InvalidateRect (handle, rect2, false); - OS.UpdateWindow (handle); - } else { - int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE; - OS.RedrawWindow (handle, rect1, 0, flags); - OS.RedrawWindow (handle, rect2, 0, flags); - } - } - } - - /* Check for SHIFT or normal select and delect/reselect items */ -/* AW - if ((wParam & OS.MK_CONTROL) == 0) { - if (!hittestSelected || !dragStarted) { - tvItem.state = 0; - int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); - OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc); - for (int i=0; i<items.length; i++) { - TreeItem2 item = items [i]; - if (item != null && item.handle != hNewItem) { - tvItem.hItem = item.handle; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - } - } - tvItem.hItem = hNewItem; - tvItem.state = OS.TVIS_SELECTED; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc); - if ((wParam & OS.MK_SHIFT) != 0) { - RECT rect1 = new RECT (); - if (hAnchor == 0) hAnchor = hNewItem; - rect1.left = hAnchor; - if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1) != 0) { - RECT rect2 = rect2 = new RECT (); - rect2.left = hNewItem; - OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2); - int flags = rect1.top < rect2.top ? OS.TVGN_NEXTVISIBLE : OS.TVGN_PREVIOUSVISIBLE; - tvItem.state = OS.TVIS_SELECTED; - int hItem = tvItem.hItem = hAnchor; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - while (hItem != hNewItem) { - tvItem.hItem = hItem; - OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem); - hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hItem); - } - } - } - } - } - } - if ((wParam & OS.MK_SHIFT) == 0) hAnchor = hNewItem; - - /* Issue notification */ - /* AW - tvItem.hItem = hNewItem; - tvItem.mask = OS.TVIF_PARAM; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - Event event = new Event (); - event.item = items [tvItem.lParam]; - postEvent (SWT.Selection, event); - - /* - * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN, - * the widget starts a modal loop to determine if the user wants - * to begin a drag/drop operation or marque select. Unfortunately, - * this modal loop eats the corresponding mouse up. The fix is to - * detect the cases when the modal loop has eaten the mouse up and - * issue a fake mouse up. - */ - /* AW - if (dragStarted) { - postEvent (SWT.DragDetect); - } else { - sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam); - } - dragStarted = false; - return new LRESULT (code); -} -*/ - - -/* AW -LRESULT wmNotifyChild (int wParam, int lParam) { - NMHDR hdr = new NMHDR (); - OS.MoveMemory (hdr, lParam, NMHDR.sizeof); - int code = hdr.code; - switch (code) { - case OS.NM_CUSTOMDRAW: { - if (!customDraw) break; - NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW (); - OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof); - switch (nmcd.dwDrawStage) { - case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW); - case OS.CDDS_ITEMPREPAINT: - TreeItem2 item = items [nmcd.lItemlParam]; - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_STATE; - tvItem.hItem = item.handle; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - if ((tvItem.state & OS.TVIS_SELECTED) != 0) break; - int clrText = item.foreground, clrTextBk = item.background; - if (clrText == -1 && clrTextBk == -1) break; - nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText; - nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk; - OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof); - return new LRESULT (OS.CDRF_NEWFONT); - } - break; - } - case OS.NM_DBLCLK: - int pos = OS.GetMessagePos (); - TVHITTESTINFO lpht = new TVHITTESTINFO (); - POINT pt = new POINT (); - pt.x = (short) (pos & 0xFFFF); - pt.y = (short) (pos >> 16); - OS.ScreenToClient (handle, pt); - lpht.x = pt.x; lpht.y = pt.y; - OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht); - if ((lpht.flags & OS.TVHT_ONITEM) == 0) break; - // fall through - case OS.NM_RETURN: - case OS.TVN_SELCHANGEDA: - case OS.TVN_SELCHANGEDW: - if (!ignoreSelect) { - TVITEM tvItem = null; - if (code == OS.TVN_SELCHANGED) { - tvItem = new TVITEM (); - int offset = NMHDR.sizeof + 4 + TVITEM.sizeof; - OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof); - hAnchor = tvItem.hItem; - } else { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem != 0) { - tvItem = new TVITEM (); - tvItem.hItem = hItem; - tvItem.mask = OS.TVIF_PARAM; - OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem); - } - } - Event event = new Event (); - if (tvItem != null) { - event.item = items [tvItem.lParam]; - } - if (code == OS.TVN_SELCHANGED) { - postEvent (SWT.Selection, event); - } else { - postEvent (SWT.DefaultSelection, event); - } - } - if (code == OS.NM_DBLCLK && hooks (SWT.DefaultSelection)) { - return LRESULT.ONE; - } - break; - case OS.TVN_SELCHANGINGA: - case OS.TVN_SELCHANGINGW: - if (!ignoreSelect && !ignoreDeselect) { - hAnchor = 0; - if ((style & SWT.MULTI) != 0) deselectAll (); - } - break; - case OS.TVN_ITEMEXPANDINGA: - case OS.TVN_ITEMEXPANDINGW: - if (!ignoreExpand) { - TVITEM tvItem = new TVITEM (); - int offset = NMHDR.sizeof + 4 + TVITEM.sizeof; - OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof); - int [] action = new int [1]; - OS.MoveMemory (action, lParam + NMHDR.sizeof, 4); - Event event = new Event (); - event.item = items [tvItem.lParam]; - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the expand - * or collapse event. If this happens, end the - * processing of the Windows message by returning - * zero as the result of the window proc. - */ - /* AW - if (action [0] == OS.TVE_EXPAND) { - sendEvent (SWT.Expand, event); - if (isDisposed ()) return LRESULT.ZERO; - } - if (action [0] == OS.TVE_COLLAPSE) { - sendEvent (SWT.Collapse, event); - if (isDisposed ()) return LRESULT.ZERO; - } - } - break; - case OS.TVN_BEGINDRAGA: - case OS.TVN_BEGINDRAGW: - case OS.TVN_BEGINRDRAGA: - case OS.TVN_BEGINRDRAGW: - TVITEM tvItem = new TVITEM (); - int offset = NMHDR.sizeof + 4 + TVITEM.sizeof; - OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof); - if (tvItem.hItem != 0 && (tvItem.state & OS.TVIS_SELECTED) == 0) { - ignoreSelect = ignoreDeselect = true; - OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, tvItem.hItem); - ignoreSelect = ignoreDeselect = false; - } - dragStarted = true; - break; - } - return super.wmNotifyChild (wParam, lParam); -} -*/ - -///////////////////////////////////////////////////////////////////////////////////////////////// -// Mac stuff -///////////////////////////////////////////////////////////////////////////////////////////////// - - int sendKeyEvent(int type, MacEvent mEvent, Event event) { - //processEvent (type, new MacEvent(eRefHandle)); - return OS.eventNotHandledErr; - } - - int handleItemCallback(int item, int property, int itemData, int setValue) { - - TreeItem2 ti= find(item); - if (ti == null) { - System.out.println("handleItemCallback: can't find row with id: " + item); - return OS.noErr; - } - - switch (property) { - - case OS.kDataBrowserItemIsActiveProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, true); // defaults to true - break; - - case OS.kDataBrowserItemIsSelectableProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, true); // defaults to true - break; - - case OS.kDataBrowserItemIsEditableProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, false); // defaults to false - break; - - case OS.kDataBrowserItemIsContainerProperty: - OS.SetDataBrowserItemDataBooleanValue(itemData, ti.isContainerProperty()); - break; - - case OS.kDataBrowserContainerIsOpenableProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, true); // defaults to true - break; - - case OS.kDataBrowserContainerIsClosableProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, true); // defaults to true - break; - - case OS.kDataBrowserContainerIsSortableProperty: - // OS.SetDataBrowserItemDataBooleanValue(itemData, true); // defaults to true - break; - - case OS.kDataBrowserItemParentContainerProperty: /* DataBrowserItemID (the parent of the specified item, used by ColumnView) */ - TreeItem2 parent= ti.getParentItem(); - if (parent != null) - OS.SetDataBrowserItemDataItemID(itemData, parent.handle); - break; - - case CHECK_COL_ID: // our column - //OS.SetDataBrowserItemDataButtonValue(itemData, OS.kThemeButtonOn); - OS.SetDataBrowserItemDataButtonValue(itemData, (short)(item % 3)); - break; - - case COL_ID: // our column - ti.updateContent(itemData); - break; - - default: - System.out.println("handleDataCallback: wrong property: " + property); - break; - } - - return OS.noErr; - } - - int handleCompareCallback(int item1ID, int item2ID, int item) { -// if (getIndex(item1ID) < getIndex(item2ID)) -// return 1; - return 0; - } - - int handleItemNotificationCallback(int item, int message) { - - //System.out.println("handleItemNotificationCallback: message: " + message + " item: " + item); - TreeItem2 ti= find(item); - if (ti == null) { - System.out.println("handleItemNotificationCallback: can't find row with id: " + item); - return OS.noErr; - } - - Event event= null; - - switch (message) { - - case OS.kDataBrowserContainerOpened: /* Container is open */ - event= new Event (); - event.item= ti; - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the expand - * or collapse event. If this happens, end the - * processing of the Windows message by returning - * zero as the result of the window proc. - */ - sendEvent (SWT.Expand, event); - //if (isDisposed ()) return LRESULT.ZERO; - ti.open(); - break; - - case OS.kDataBrowserContainerClosing: /* Container is about to be closed */ - int[] ids= MacUtil.getSelectionIDs(handle, ti.handle, true); - if (ids.length > 0 && ids[0] != 0) - OS.SetDataBrowserSelectedItems(handle, 1, new int[] { ti.handle }, OS.kDataBrowserItemsAssign); - break; - - case OS.kDataBrowserContainerClosed: /* Container is closed */ - ti.close(); - event= new Event (); - event.item= ti; - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the expand - * or collapse event. If this happens, end the - * processing of the Windows message by returning - * zero as the result of the window proc. - */ - sendEvent (SWT.Collapse, event); - //if (isDisposed ()) return LRESULT.ZERO; - break; - } - - return OS.noErr; - } - - TreeItem2 find(int id) { - int index= 0; - if (id >= FIRST_ROW_ID) - index= id - FIRST_ROW_ID; - if (index < 0 || index >= items.length) - return null; - TreeItem2 ti= items[index]; - if (ti == null || ti.handle != index + FIRST_ROW_ID) - return null; - return ti; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem2.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem2.java deleted file mode 100644 index de5865e87a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem2.java +++ /dev/null @@ -1,778 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.carbon.*; - -/** - * Instances of this class represent a selectable user interface object - * that represents a hierarchy of tree items in a tree widget. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ - -public class TreeItem2 extends Item { - Tree2 parent; - int background, foreground; - - // AW - private TreeItem2 fParentItem; - ArrayList fChildren; - boolean fIsOpen; - // AW - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree2</code> or a <code>TreeItem2</code>) - * and a style value describing its behavior and appearance. - * The item is added to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem2 (Tree2 parent, int style) { - /* AW - super (parent, style); - this.parent = parent; - fParentItem = parent.fRoot; - parent.createItem (this, 0, 99999); - */ - this(parent.fRoot, style); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree2</code> or a <code>TreeItem2</code>), - * a style value describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem2 (Tree2 parent, int style, int index) { - /* AW - super (parent, style); - if (index < 0) error (SWT.ERROR_INVALID_RANGE); - this.parent = parent; - fParentItem = parent.fRoot; - int hItem = 0; // OS.TVI_FIRST; - if (index != 0) { - int count = 1, hwnd = parent.handle; - hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); - while (hItem != 0 && count < index) { - hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem); - count++; - } - if (hItem == 0) error (SWT.ERROR_INVALID_RANGE); - }; - parent.createItem (this, 0, hItem); - */ - this(parent.fRoot, style, index); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree2</code> or a <code>TreeItem2</code>) - * and a style value describing its behavior and appearance. - * The item is added to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parentItem a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem2 (TreeItem2 parentItem, int style) { - super (checkNull (parentItem).parent, style); - fParentItem = parentItem; - parent = parentItem.parent; - parent.createItem (this, parentItem, 99999); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree2</code> or a <code>TreeItem2</code>), - * a style value describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parentItem a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem2 (TreeItem2 parentItem, int style, int index) { - super (checkNull (parentItem).parent, style); - if (index < 0) error (SWT.ERROR_INVALID_RANGE); - parent = parentItem.parent; - fParentItem = parentItem; - int hItem = 0; // OS.TVI_FIRST; - if (index != 0) { - int count = 1, hwnd = parent.handle; - /* AW - hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent); - while (hItem != 0 && count < index) { - hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem); - count++; - } - */ - if (hItem == 0) error (SWT.ERROR_INVALID_RANGE); - } - parent.createItem (this, parentItem, hItem); -} - -static TreeItem2 checkNull (TreeItem2 item) { - if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return item; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -/** - * Returns the receiver's background color. - * - * @return the background color - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * - */ -public Color getBackground () { - checkWidget (); - int pixel = (background == -1) ? parent.getBackgroundPixel() : background; - return Color.carbon_new(getDisplay (), pixel, false); -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent. - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget (); - Rect bounds= new Rect(); - OS.GetDataBrowserItemPartBounds(parent.handle, handle, Tree2.COL_ID, - OS.kDataBrowserPropertyEnclosingPart, bounds); - int width = bounds.right - bounds.left; - int height = bounds.bottom - bounds.top; - return new Rectangle(bounds.left, bounds.top, width, height); -} - -/** - * Returns <code>true</code> if the receiver is checked, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * <p> - * - * @return the checked state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getChecked () { - checkWidget (); - if ((parent.style & SWT.CHECK) == 0) return false; - /* AW - int hwnd = parent.handle; - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - tvItem.hItem = handle; - int result = OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); - return (result != 0) && (((tvItem.state >> 12) & 1) == 0); - */ - return false; -} - -public Display getDisplay () { - Tree2 parent = this.parent; - if (parent == null) - error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} - -/** - * Returns <code>true</code> if the receiver is expanded, - * and false otherwise. - * <p> - * - * @return the expanded state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getExpanded () { - checkWidget (); - return fIsOpen; -} - -/** - * Returns the foreground color that the receiver will use to draw. - * - * @return the receiver's foreground color - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * - */ -public Color getForeground () { - checkWidget (); - int pixel = (foreground == -1) ? parent.getForegroundPixel() : foreground; - return Color.carbon_new (getDisplay (), pixel, false); -} - -/** - * Returns <code>true</code> if the receiver is grayed, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * <p> - * - * @return the grayed state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getGrayed () { - checkWidget (); - if ((parent.style & SWT.CHECK) == 0) return false; - int hwnd = parent.handle; - /* AW - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - tvItem.hItem = handle; - int result = OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); - return (result != 0) && ((tvItem.state >> 12) > 2); - */ - return false; -} - -/** - * Returns the number of items contained in the receiver - * that are direct item children of the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget (); - if (fChildren != null) - return fChildren.size(); - return 0; -} - -/** - * Returns an array of <code>TreeItem2</code>s which are the - * direct item children of the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the receiver's items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 [] getItems () { - checkWidget (); - if (fChildren != null) - return (TreeItem2[]) fChildren.toArray(new TreeItem2[fChildren.size()]); - return new TreeItem2[0]; -} - -/** - * Returns the receiver's parent, which must be a <code>Tree2</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Tree2 getParent () { - checkWidget (); - return parent; -} - -/** - * Returns the receiver's parent item, which must be a - * <code>TreeItem2</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem2 getParentItem () { - checkWidget (); - if (fParentItem == parent.fRoot) - return null; - return fParentItem; -} - -void redraw () { - /* AW - if (parent.drawCount > 0) return; - int hwnd = parent.handle; - if (!OS.IsWindowVisible (hwnd)) return; - RECT rect = new RECT (); - rect.left = handle; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) != 0) { - OS.InvalidateRect (hwnd, rect, true); - } - */ - update(OS.kDataBrowserItemNoProperty); -} - -void releaseChild () { - super.releaseChild (); - parent.destroyItem (this); -} - -void releaseHandle () { - super.releaseHandle (); - handle = 0; -} - -// AW -void releaseResources() { -} -// AW - -void releaseWidget () { - super.releaseWidget (); - parent = null; -} - -/** - * Sets the receiver's background color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @param color the new color (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * - */ -public void setBackground (Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - int pixel = -1; - if (color != null) { - /* AW - parent.customDraw = true; - */ - pixel = color.handle; - } - background = pixel; - redraw (); -} - -/** - * Sets the checked state of the receiver. - * <p> - * - * @param checked the new checked state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setChecked (boolean checked) { - checkWidget (); - if ((parent.style & SWT.CHECK) == 0) return; - /* AW - int hwnd = parent.handle; - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - tvItem.hItem = handle; - OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); - int state = tvItem.state >> 12; - if (checked) { - if ((state & 0x1) != 0) state++; - } else { - if ((state & 0x1) == 0) --state; - } - tvItem.state = state << 12; - OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem); - */ -} - -/** - * Sets the expanded state of the receiver. - * <p> - * - * @param expanded the new expanded state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setExpanded (boolean expanded) { - checkWidget (); - int hwnd = parent.handle; - /* - * Feature in Windows. When the user collapses the root - * of a subtree that has the focus item, Windows moves - * the selection to the root of the subtree and issues - * a TVN_SELCHANGED to inform the programmer that the - * seletion has changed. When the programmer collapses - * the same subtree using TVM_EXPAND, Windows does not - * send the selection changed notification. This is not - * stricly wrong but is inconsistent. The fix is to notice - * that the selection has changed and issue the event. - */ - /* AW - int hOldItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - parent.ignoreExpand = true; - OS.SendMessage (hwnd, OS.TVM_EXPAND, expanded ? OS.TVE_EXPAND : OS.TVE_COLLAPSE, handle); - parent.ignoreExpand = false; - int hNewItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hNewItem != hOldItem) { - Event event = new Event (); - if (hNewItem != 0) { - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; - tvItem.hItem = hNewItem; - if (OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem) != 0) { - event.item = parent.items [tvItem.lParam]; - } - } - parent.sendEvent (SWT.Selection, event); - } - */ - if (expanded) - OS.OpenDataBrowserContainer(parent.handle, handle); - else - OS.CloseDataBrowserContainer(parent.handle, handle); -} - -/** - * Sets the receiver's foreground color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @param color the new color (or null) - * - * @since 2.0 - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * - */ -public void setForeground (Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - int pixel = -1; - if (color != null) { - /* AW - parent.customDraw = true; - */ - pixel = color.handle; - } - foreground = pixel; - redraw (); -} - -/** - * Sets the grayed state of the receiver. - * <p> - * - * @param checked the new grayed state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setGrayed (boolean grayed) { - checkWidget (); - if ((parent.style & SWT.CHECK) == 0) return; - int hwnd = parent.handle; - /* AW - TVITEM tvItem = new TVITEM (); - tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE; - tvItem.stateMask = OS.TVIS_STATEIMAGEMASK; - tvItem.hItem = handle; - OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); - int state = tvItem.state >> 12; - if (grayed) { - if (state <= 2) state +=2; - } else { - if (state > 2) state -=2; - } - tvItem.state = state << 12; - OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem); - */ -} - -public void setImage (Image image) { - checkWidget (); - super.setImage (image); - update(OS.kDataBrowserItemNoProperty); -} - -/** - * 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 string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - super.setText (string); - update(OS.kDataBrowserItemNoProperty); -} - -///////////////////////////////////////////////////////////// -// Mac stuff -///////////////////////////////////////////////////////////// - -/** - * Only used for creating the root item - */ -TreeItem2 (Tree2 parent) { - super (parent, SWT.NONE); - this.parent = parent; - parent.createItem (this, null, 99999); -} - -void addChild(TreeItem2 child) { - if (fChildren == null) - fChildren= new ArrayList(); - fChildren.add(child); - if (fIsOpen) { - if (OS.AddDataBrowserItems(parent.handle, getContainerID(), 1, new int[] { child.handle }, 0) != OS.noErr) { - System.out.println("SWT.ERROR_ITEM_NOT_ADDED"); - //error (SWT.ERROR_ITEM_NOT_ADDED); - } - } else { - update(OS.kDataBrowserItemIsContainerProperty); - } -} - -void removeChild(TreeItem2 child) { - if (fChildren != null) - fChildren.remove(child); - if (fIsOpen) { - if (OS.RemoveDataBrowserItems(parent.handle, getContainerID(), 1, new int[] { child.handle }, 0) != OS.noErr) { - System.out.println("SWT.ERROR_ITEM_NOT_REMOVED"); - //error (SWT.ERROR_ITEM_NOT_REMOVED); - } - } else { - update(OS.kDataBrowserItemIsContainerProperty); - } -} - -int getContainerID() { - if (this == parent.fRoot) - return 0; - return handle; -} - -void open() { - fIsOpen= true; - if (fChildren != null) { - int n= fChildren.size(); - int[] ids= new int[n]; - Iterator iter= fChildren.iterator(); - for (int i= 0; iter.hasNext(); i++) { - TreeItem2 e= (TreeItem2) iter.next(); - ids[i]= e.handle; - } - if (OS.AddDataBrowserItems(parent.handle, getContainerID(), ids.length, ids, 0) != OS.noErr) { - System.out.println("SWT.ERROR_ITEM_NOT_ADDED"); - //error (SWT.ERROR_ITEM_NOT_ADDED); - } - } -} - -void close() { - fIsOpen= false; -} - -void updateContent(int itemData) { - String text= getText(); - if (text != null) { - int sHandle= 0; - try { - sHandle= OS.CFStringCreateWithCharacters(text); - OS.SetDataBrowserItemDataText(itemData, sHandle); - } finally { - if (sHandle != 0) - OS.CFRelease(sHandle); - } - } - /* - if (fIcon != 0) { - OS.SetDataBrowserItemDataIcon(itemData, fIcon); - } - */ -} - -void update(int property) { - int containerID= 0; - if (fParentItem != null) - containerID= fParentItem.handle; - OS.UpdateDataBrowserItems(parent.handle, containerID, 1, new int[] { handle }, property, OS.kDataBrowserNoItem); -} - -boolean isContainerProperty() { - return fChildren != null; -} - -} |