diff options
author | Steve Northover <steve> | 2003-07-11 19:51:38 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2003-07-11 19:51:38 +0000 |
commit | e191140321c16422e44c47bc2f21064b253b3377 (patch) | |
tree | 64e1416308e0d8a35de19ac333efbbe610c69dad | |
parent | bcd55dd512f5b1bdf742949f657ced196a25bb30 (diff) | |
download | eclipse.platform.swt-e191140321c16422e44c47bc2f21064b253b3377.tar.gz eclipse.platform.swt-e191140321c16422e44c47bc2f21064b253b3377.tar.xz eclipse.platform.swt-e191140321c16422e44c47bc2f21064b253b3377.zip |
SWTinSWT
8 files changed, 125 insertions, 174 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java index 83f3aa26be..ea1ec40aac 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java @@ -919,7 +919,7 @@ void register () { super.register (); int [] argList = {OS.XmNtextField, 0}; OS.XtGetValues (handle, argList, argList.length / 2); - WidgetTable.put(argList[1], this); + display.addWidget (argList[1], this); } /** * Searches the receiver's list starting at the first item @@ -1349,7 +1349,7 @@ void deregister () { super.deregister (); int [] argList = {OS.XmNtextField, 0}; OS.XtGetValues (handle, argList, argList.length / 2); - WidgetTable.remove (argList[1]); + display.removeWidget (argList[1]); } void enableWidget (boolean enabled) { super.enableWidget (enabled); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java index fc800db213..821b5447c0 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java @@ -92,7 +92,7 @@ Control [] _getChildren () { while (i < count) { int handle = handles [i]; if (handle != 0) { - Widget widget = WidgetTable.get (handle); + Widget widget = display.getWidget (handle); if (widget != null && widget != this) { if (widget instanceof Control) { children [j++] = (Control) widget; @@ -229,7 +229,7 @@ int defaultForeground () { } void deregister () { super.deregister (); - if (focusHandle != 0) WidgetTable.remove (focusHandle); + if (focusHandle != 0) display.removeWidget (focusHandle); } int focusHandle () { if (focusHandle == 0) return super.focusHandle (); @@ -487,7 +487,7 @@ void realizeChildren () { } void register () { super.register (); - if (focusHandle != 0) WidgetTable.put (focusHandle, this); + if (focusHandle != 0) display.addWidget (focusHandle, this); } void redrawWidget (int x, int y, int width, int height, boolean all) { super.redrawWidget (x, y, width, height, all); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java index d298f5e29f..d399624efe 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java @@ -109,6 +109,13 @@ public class Display extends Device { EventTable eventTable, filterTable; boolean postFocusOut; + /* Widget Table */ + int freeSlot = 0; + int [] indexTable, userData; + Shell [] shellTable; + Widget [] widgetTable; + static final int GROW_SIZE = 1024; + /* Default Fonts, Colors, Insets, Widths and Heights. */ Font defaultFont; Font listFont, textFont, buttonFont, labelFont; @@ -358,6 +365,41 @@ void addMouseHoverTimeOut (int handle) { mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle); mouseHoverHandle = handle; } +void addWidget (int handle, Widget widget) { + if (handle == 0) return; + if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { + for (int i=0; i<shellTable.length; i++) { + if (shellTable [i] == null) { + shellTable [i] = (Shell) widget; + return; + } + } + Shell [] newShells = new Shell [shellTable.length + GROW_SIZE / 8]; + System.arraycopy (shellTable, 0, newShells, 0, shellTable.length); + newShells [shellTable.length] = (Shell) widget; + shellTable = newShells; + return; + } + if (freeSlot == -1) { + int length = (freeSlot = indexTable.length) + GROW_SIZE; + int [] newIndexTable = new int [length]; + Widget [] newWidgetTable = new Widget [length]; + System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot); + System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot); + for (int i=freeSlot; i<length-1; i++) { + newIndexTable [i] = i + 1; + } + newIndexTable [length - 1] = -1; + indexTable = newIndexTable; + widgetTable = newWidgetTable; + } + userData [1] = freeSlot + 1; + OS.XtSetValues (handle, userData, userData.length / 2); + int oldSlot = freeSlot; + freeSlot = indexTable [oldSlot]; + indexTable [oldSlot] = -2; + widgetTable [oldSlot] = widget; +} public void addFilter (int eventType, Listener listener) { checkDevice (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); @@ -715,7 +757,7 @@ boolean filterEvent (int event) { if (handle == 0) return false; handle = OS.XmGetFocusWidget (handle); if (handle == 0) return false; - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget == null) return false; /* Get the unaffected character and keysym */ @@ -812,7 +854,7 @@ boolean filterEvent (int event) { */ public Widget findWidget (int handle) { checkDevice (); - return WidgetTable.get (handle); + return getWidget (handle); } /** * Returns the currently active <code>Shell</code>, or null @@ -836,7 +878,7 @@ public Shell getActiveShell () { if (handle == 0) return null; do { if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget instanceof Shell) return (Shell) widget; return null; } @@ -895,7 +937,7 @@ public Control getCursorControl () { int handle = OS.XtWindowToWidget (xDisplay, xParent); if (handle == 0) return null; do { - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget != null && widget instanceof Control) { Control control = (Control) widget; if (control.getEnabled ()) return control; @@ -1054,7 +1096,7 @@ public Control getFocusControl () { handle = OS.XmGetFocusWidget (handle); if (handle == 0) return null; do { - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget != null && widget instanceof Control) { Control window = (Control) widget; if (window.getEnabled ()) return window; @@ -1200,28 +1242,15 @@ public Monitor getPrimaryMonitor () { */ public Shell [] getShells () { checkDevice (); - /* - * NOTE: Need to check that the shells that belong - * to another display have not been disposed by the - * other display's thread as the shells list is being - * processed. - */ - int count = 0; - Shell [] shells = WidgetTable.shells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed () && this == shell.display) { - count++; - } + int length = 0; + for (int i=0; i<shellTable.length; i++) { + if (shellTable [i] != null) length++; } - if (count == shells.length) return shells; int index = 0; - Shell [] result = new Shell [count]; - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed () && this == shell.display) { - result [index++] = shell; - } + Shell [] result = new Shell [length]; + for (int i=0; i<shellTable.length; i++) { + Shell widget = shellTable [i]; + if (widget != null) result [index++] = widget; } return result; } @@ -1330,6 +1359,22 @@ public Thread getThread () { if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); return thread; } +Widget getWidget (int handle) { + if (handle == 0) return null; + if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { + for (int i=0; i<shellTable.length; i++) { + Widget shell = shellTable [i]; + if (shell != null && shell.topHandle () == handle) return shell; + } + return null; + } + userData [1] = 0; + OS.XtGetValues (handle, userData, userData.length / 2); + if (userData [1] == 0) return null; + int index = userData [1] - 1; + if (0 <= index && index < widgetTable.length) return widgetTable [index]; + return null; +} void hideToolTip () { if (toolTipHandle != 0) { int shellHandle = OS.XtParent(toolTipHandle); @@ -1359,6 +1404,7 @@ protected void init () { initializeSystemColors (); initializeDefaults (); initializeTranslations (); + initializeWidgetTable (); } void initializeButton () { @@ -1705,6 +1751,14 @@ void initializeTranslations () { byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0"); dragTranslations = OS.XtParseTranslationTable (buffer3); } +void initializeWidgetTable () { + userData = new int [] {OS.XmNuserData, 0}; + indexTable = new int [GROW_SIZE]; + shellTable = new Shell [GROW_SIZE / 8]; + widgetTable = new Widget [GROW_SIZE]; + for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1; + indexTable [GROW_SIZE - 1] = -1; +} /** * Invokes platform specific functionality to allocate a new GC handle. * <p> @@ -1795,7 +1849,7 @@ public Rectangle map (Control from, Control to, int x, int y, int width, int hei } int mouseHoverProc (int handle, int id) { mouseHoverID = mouseHoverHandle = 0; - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget == null) return 0; return widget.hoverProc (id); } @@ -1906,12 +1960,10 @@ static synchronized void register (Display display) { */ protected void release () { sendEvent (SWT.Dispose, new Event ()); - Shell [] shells = WidgetTable.shells (); + Shell [] shells = getShells (); for (int i=0; i<shells.length; i++) { Shell shell = shells [i]; - if (!shell.isDisposed ()) { - if (this == shell.display) shell.dispose (); - } + if (!shell.isDisposed ()) shell.dispose (); } while (readAndDispatch ()) {}; if (disposeList != null) { @@ -2023,6 +2075,32 @@ void removeMouseHoverTimeOut () { if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); mouseHoverID = mouseHoverHandle = 0; } +Widget removeWidget (int handle) { + if (handle == 0) return null; + if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { + for (int i=0; i<shellTable.length; i++) { + Widget shell = shellTable [i]; + if (shell != null && shell.topHandle () == handle) { + shellTable [i] = null; + return shell; + } + } + return null; + } + userData [1] = 0; + Widget widget = null; + OS.XtGetValues (handle, userData, userData.length / 2); + int index = userData [1] - 1; + if (0 <= index && index < widgetTable.length) { + widget = widgetTable [index]; + widgetTable [index] = null; + indexTable [index] = freeSlot; + freeSlot = index; + userData [1] = 0; + OS.XtSetValues (handle, userData, userData.length / 2); + } + return widget; +} public void removeFilter (int eventType, Listener listener) { checkDevice (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); @@ -2580,12 +2658,12 @@ int wakeProc (int closure, int source, int id) { return 0; } int windowTimerProc (int handle, int id) { - Widget widget = WidgetTable.get (handle); + Widget widget = getWidget (handle); if (widget == null) return 0; return widget.timerProc (id); } int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) { - Widget widget = WidgetTable.get (w); + Widget widget = getWidget (w); if (widget == null) return 0; return widget.windowProc (w, client_data, call_data, continue_to_dispatch); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java index ad71c07bb3..fcb04d94ff 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java @@ -353,7 +353,7 @@ public MenuItem getItem (int index) { i++; } if (index != count) error (SWT.ERROR_INVALID_RANGE); - Widget widget = WidgetTable.get (handles [i]); + Widget widget = display.getWidget (handles [i]); if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM); return (MenuItem) widget; } @@ -407,7 +407,7 @@ public MenuItem [] getItems () { MenuItem [] items = new MenuItem [count]; int i = 0, j = 0; while (i < count) { - Widget item = WidgetTable.get (handles [i]); + Widget item = display.getWidget (handles [i]); if (item != null) items [j++] = (MenuItem) item; i++; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java index 876a9975cb..d4f64d08d7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java @@ -140,8 +140,8 @@ void createWidget (int index) { } void deregister () { super.deregister (); - if (formHandle != 0) WidgetTable.remove (formHandle); - if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle); + if (formHandle != 0) display.removeWidget (formHandle); + if (scrolledHandle != 0) display.removeWidget (scrolledHandle); } void enableWidget (boolean enabled) { super.enableWidget (enabled); @@ -276,8 +276,8 @@ void redrawWidget (int x, int y, int width, int height, boolean all) { } void register () { super.register (); - if (formHandle != 0) WidgetTable.put (formHandle, this); - if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this); + if (formHandle != 0) display.addWidget (formHandle, this); + if (scrolledHandle != 0) display.addWidget (scrolledHandle, this); } void releaseHandle () { super.releaseHandle (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java index 64d1102245..0ad916c4a4 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java @@ -670,7 +670,7 @@ void createHandle (int index) { } void deregister () { super.deregister (); - WidgetTable.remove (shellHandle); + display.removeWidget (shellHandle); } void destroyWidget () { /* @@ -965,7 +965,7 @@ void realizeWidget () { } void register () { super.register (); - WidgetTable.put (shellHandle, this); + display.addWidget (shellHandle, this); } void releaseHandle () { super.releaseHandle (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java index eb3b8dae9a..dccab0b336 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java @@ -296,7 +296,7 @@ void createWidget (int index) { } void deregister () { if (handle == 0) return; - WidgetTable.remove (handle); + display.removeWidget (handle); } void destroyWidget () { int topHandle = topHandle (); @@ -588,7 +588,7 @@ void redrawHandle (int x, int y, int width, int height, int widgetHandle) { } void register () { if (handle == 0) return; - WidgetTable.put (handle, this); + display.addWidget (handle, this); } void releaseChild () { /* Do nothing */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java deleted file mode 100755 index b26a0bed92..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; - -class WidgetTable { - static int FreeSlot = 0; - static int GrowSize = 1024; - static int [] IndexTable = new int [GrowSize]; - static Shell [] Shells = new Shell [GrowSize / 8]; - static Widget [] WidgetTable = new Widget [GrowSize]; - static int [] ArgList = {OS.XmNuserData, 0}; - static { - for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1; - IndexTable [GrowSize - 1] = -1; - } -public static synchronized Widget get (int handle) { - if (handle == 0) return null; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<Shells.length; i++) { - Widget shell = Shells [i]; - if ((shell != null) && (shell.topHandle () == handle)) return shell; - } - return null; - } - ArgList [1] = 0; - OS.XtGetValues (handle, ArgList, ArgList.length / 2); - if (ArgList [1] == 0) return null; - int index = ArgList [1] - 1; - if (0 <= index && index < WidgetTable.length) return WidgetTable [index]; - return null; -} -public synchronized static void put (int handle, Widget widget) { - if (handle == 0) return; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<Shells.length; i++) { - if (Shells [i] == null) { - Shells [i] = (Shell) widget; - return; - } - } - Shell [] newShells = new Shell [Shells.length + GrowSize / 8]; - System.arraycopy (Shells, 0, newShells, 0, Shells.length); - newShells [Shells.length] = (Shell) widget; - Shells = newShells; - return; - } - if (FreeSlot == -1) { - int length = (FreeSlot = IndexTable.length) + GrowSize; - int [] newIndexTable = new int [length]; - Widget [] newWidgetTable = new Widget [length]; - System.arraycopy (IndexTable, 0, newIndexTable, 0, FreeSlot); - System.arraycopy (WidgetTable, 0, newWidgetTable, 0, FreeSlot); - for (int i=FreeSlot; i<length-1; i++) { - newIndexTable [i] = i + 1; - } - newIndexTable [length - 1] = -1; - IndexTable = newIndexTable; - WidgetTable = newWidgetTable; - } - ArgList [1] = FreeSlot + 1; - OS.XtSetValues (handle, ArgList, ArgList.length / 2); - int oldSlot = FreeSlot; - FreeSlot = IndexTable [oldSlot]; - IndexTable [oldSlot] = -2; - WidgetTable [oldSlot] = widget; -} -public static synchronized Widget remove (int handle) { - if (handle == 0) return null; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<Shells.length; i++) { - Widget shell = Shells [i]; - if ((shell != null) && (shell.topHandle () == handle)) { - Shells [i] = null; - return shell; - } - } - return null; - } - ArgList [1] = 0; - Widget widget = null; - OS.XtGetValues (handle, ArgList, ArgList.length / 2); - int index = ArgList [1] - 1; - if (0 <= index && index < WidgetTable.length) { - widget = WidgetTable [index]; - WidgetTable [index] = null; - IndexTable [index] = FreeSlot; - FreeSlot = index; - ArgList [1] = 0; - OS.XtSetValues (handle, ArgList, ArgList.length / 2); - } - return widget; -} -public static synchronized Shell [] shells () { - int length = 0; - for (int i=0; i<Shells.length; i++) { - if (Shells [i] != null) length++; - } - int index = 0; - Shell [] result = new Shell [length]; - for (int i=0; i<Shells.length; i++) { - Shell widget = Shells [i]; - if (widget != null) result [index++] = widget; - } - return result; -} -public static synchronized int size () { - int length = 0; - for (int i=0; i<Shells.length; i++) { - if (Shells [i] != null) length++; - } - for (int i=0; i<WidgetTable.length; i++) { - if (WidgetTable [i] != null) length++; - } - return length; -} -} |