summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
diff options
context:
space:
mode:
authorVeronika Irvine <torres>2001-05-11 13:46:50 +0000
committerVeronika Irvine <torres>2001-05-11 13:46:50 +0000
commit3275970ab8046022b8d2069b5c21bf117c223db7 (patch)
tree23ac5a3259be894e958f59fdd4103679c544e889 /bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
downloadeclipse.platform.swt-3275970ab8046022b8d2069b5c21bf117c223db7.tar.gz
eclipse.platform.swt-3275970ab8046022b8d2069b5c21bf117c223db7.tar.xz
eclipse.platform.swt-3275970ab8046022b8d2069b5c21bf117c223db7.zip
initializing database with SWT 0.105
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java439
1 files changed, 439 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
new file mode 100755
index 0000000000..5177c3bccd
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
@@ -0,0 +1,439 @@
+package org.eclipse.swt.widgets;
+
+/*
+* Licensed Materials - Property of IBM,
+* SWT - The Simple Widget Toolkit,
+* (c) Copyright IBM Corp 1998, 1999.
+*/
+
+/**
+* The composite class represents a user interface object
+* that contains other widgets.
+*
+* Styles
+*
+* H_SCROLL, V_SCROLL
+*
+* Events
+*
+**/
+
+/* Imports */
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/* Class Definition */
+public class Composite extends Scrollable {
+ Layout layout;
+ int damagedRegion;
+
+Composite () {
+ /* Do nothing */
+}
+public Composite (Composite parent, int style) {
+ super (parent, style);
+}
+Control [] _getChildren () {
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return new Control [0];
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ Control [] children = new Control [count];
+ int i = 0, j = 0;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle != 0) {
+ Widget widget = WidgetTable.get (handle);
+ if (widget != null && widget != this) {
+ if (widget instanceof Control) {
+ children [j++] = (Control) widget;
+ }
+ }
+ }
+ i++;
+ }
+ if (i == j) return children;
+ Control [] newChildren = new Control [j];
+ System.arraycopy (children, 0, newChildren, 0, j);
+ return newChildren;
+}
+/**
+* Computes the preferred size.
+*/
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Point size;
+ if (layout != null) {
+ if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } else {
+ size = new Point (wHint, hHint);
+ }
+ } else {
+ size = minimumSize ();
+ }
+ if (size.x == 0) size.x = DEFAULT_WIDTH;
+ if (size.y == 0) size.y = DEFAULT_HEIGHT;
+ if (wHint != SWT.DEFAULT) size.x = wHint;
+ if (hHint != SWT.DEFAULT) size.y = hHint;
+ Rectangle trim = computeTrim (0, 0, size.x, size.y);
+ return new Point (trim.width, trim.height);
+}
+protected void checkSubclass () {
+ /* Do nothing - Subclassing is allowed */
+}
+void createHandle (int index) {
+ state |= HANDLE | CANVAS;
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
+ int border = (style & SWT.BORDER) != 0 ? 1 : 0;
+ int [] argList = {
+ OS.XmNborderWidth, border,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (parent.handle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ Display display = getDisplay ();
+ OS.XtOverrideTranslations (handle, display.tabTranslations);
+ OS.XtOverrideTranslations (handle, display.arrowTranslations);
+ } else {
+ createScrolledHandle (parent.handle);
+ }
+}
+void createScrolledHandle (int topHandle) {
+ scrolledHandle = OS.XmCreateMainWindow (topHandle, null, null, 0);
+ if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
+ int [] argList1 = {
+ OS.XmNmarginWidth, 3,
+ OS.XmNmarginHeight, 3,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNshadowType, OS.XmSHADOW_IN,
+ OS.XmNshadowThickness, 2,
+ };
+ formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2);
+ if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int [] argList2 = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtopAttachment, OS.XmATTACH_FORM,
+ OS.XmNbottomAttachment, OS.XmATTACH_FORM,
+ OS.XmNleftAttachment, OS.XmATTACH_FORM,
+ OS.XmNrightAttachment, OS.XmATTACH_FORM,
+ OS.XmNresizable, 0,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
+ } else {
+ int [] argList = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList, argList.length / 2);
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ Display display = getDisplay ();
+ OS.XtOverrideTranslations (handle, display.tabTranslations);
+ OS.XtOverrideTranslations (handle, display.arrowTranslations);
+}
+int defaultBackground () {
+ return getDisplay ().compositeBackground;
+}
+int defaultForeground () {
+ return getDisplay ().compositeForeground;
+}
+public boolean forceFocus () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Control [] children = _getChildren ();
+ int [] traversals = new int [children.length];
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ for (int i=0; i<children.length; i++) {
+ OS.XtGetValues (children [i].handle, argList, argList.length / 2);
+ traversals [i] = argList [1];
+ argList [1] = 0;
+ OS.XtSetValues (children [i].handle, argList, argList.length / 2);
+ }
+ boolean result = super.forceFocus ();
+ for (int i=0; i<children.length; i++) {
+ argList [1] = traversals [i];
+ OS.XtSetValues (children [i].handle, argList, argList.length / 2);
+ }
+ return result;
+}
+public Control [] getChildren () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return _getChildren ();
+}
+int getChildrenCount () {
+ // BOGUS - could count non-registered children or gadgets
+ int [] argList = {OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+public Layout getLayout () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return layout;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ if ((state & CANVAS) != 0) {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddEventHandler (handle, 0, true, windowProc, -1);
+ }
+}
+
+/**
+* Lays out the children.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void layout () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ layout (true);
+}
+public void layout (boolean changed) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (layout == null) return;
+ int count = getChildrenCount ();
+ if (count == 0) return;
+ layout.layout (this, changed);
+}
+Point minimumSize () {
+ Control [] children = _getChildren ();
+ int width = 0, height = 0;
+ for (int i=0; i<children.length; i++) {
+ Rectangle rect = children [i].getBounds ();
+ width = Math.max (width, rect.x + rect.width);
+ height = Math.max (height, rect.y + rect.height);
+ }
+ return new Point (width, height);
+}
+void moveAbove (int handle1, int handle2) {
+ if (handle1 == handle2) return;
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return;
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ if (handle2 == 0) handle2 = handles [0];
+ int i = 0, index1 = -1, index2 = -1;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle == handle1) index1 = i;
+ if (handle == handle2) index2 = i;
+ if (index1 != -1 && index2 != -1) break;
+ i++;
+ }
+ if (index1 == -1 || index2 == -1) return;
+ if (index1 == index2) return;
+ if (index1 < index2) {
+ System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1);
+ handles [index2 - 1] = handle1;
+ } else {
+ System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2);
+ handles [index2] = handle1;
+ }
+ OS.memmove (ptr, handles, count * 4);
+}
+void moveBelow (int handle1, int handle2) {
+ if (handle1 == handle2) return;
+ int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int ptr = argList [1], count = argList [3];
+ if (count == 0 || ptr == 0) return;
+ int [] handles = new int [count];
+ OS.memmove (handles, ptr, count * 4);
+ if (handle2 == 0) handle2 = handles [count - 1];
+ int i = 0, index1 = -1, index2 = -1;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle == handle1) index1 = i;
+ if (handle == handle2) index2 = i;
+ if (index1 != -1 && index2 != -1) break;
+ i++;
+ }
+ if (index1 == -1 || index2 == -1) return;
+ if (index1 == index2) return;
+ if (index1 < index2) {
+ System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1);
+ handles [index2] = handle1;
+ } else {
+ System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1);
+ handles [index2 + 1] = handle1;
+ }
+ OS.memmove (ptr, handles, count * 4);
+}
+
+int processNonMaskable (int callData) {
+ if ((state & CANVAS) != 0) {
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, callData, XExposeEvent.sizeof);
+ if (xEvent.type == OS.GraphicsExpose) processPaint (callData);
+ }
+ return 0;
+}
+int processPaint (int callData) {
+ if ((state & CANVAS) == 0) {
+ return super.processPaint (callData);
+ }
+ if (!hooks (SWT.Paint)) return 0;
+ if ((style & SWT.NO_MERGE_PAINTS) != 0) {
+ return super.processPaint (callData);
+ }
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, callData, XExposeEvent.sizeof);
+ int exposeCount = xEvent.count;
+ if (damagedRegion == 0 && exposeCount == 0) {
+ XAnyEvent event = new XAnyEvent ();
+ Display display = getDisplay ();
+ display.exposeCount = 0;
+ int checkExposeProc = display.checkExposeProc;
+ OS.XCheckIfEvent (xEvent.display, event, checkExposeProc, xEvent.window);
+ if (display.exposeCount == 0) return super.processPaint (callData);
+ exposeCount = display.exposeCount;
+ }
+ if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
+ OS.XtAddExposureToRegion (callData, damagedRegion);
+ if (exposeCount != 0) return 0;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ Event event = new Event ();
+ GC gc = event.gc = new GC (this);
+ OS.XSetRegion (xDisplay, gc.handle, damagedRegion);
+ XRectangle rect = new XRectangle ();
+ OS.XClipBox (damagedRegion, rect);
+ OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+ event.time = OS.XtLastTimestampProcessed (xDisplay);
+ event.x = rect.x; event.y = rect.y;
+ event.width = rect.width; event.height = rect.height;
+ sendEvent (SWT.Paint, event);
+ gc.dispose ();
+ event.gc = null;
+ return 0;
+}
+
+void propagateChildren (boolean enabled) {
+ super.propagateChildren (enabled);
+ Control [] children = _getChildren ();
+ for (int i = 0; i < children.length; i++) {
+ Control child = children [i];
+ if (child.getEnabled ()) {
+ child.propagateChildren (enabled);
+ }
+ }
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ children [i].realizeChildren ();
+ }
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ int flags = 0;
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ if ((style & SWT.NO_BACKGROUND) != 0) {
+ flags |= OS.CWBackPixmap;
+ attributes.background_pixmap = OS.None;
+ }
+ if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
+ flags |= OS.CWBitGravity;
+ attributes.bit_gravity = OS.ForgetGravity;
+ }
+ if (flags != 0) {
+ OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes);
+ }
+ }
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ if (!all) return;
+ Control [] children = _getChildren ();
+ for (int i = 0; i < children.length; i++) {
+ Control child = children [i];
+ Point location = child.getClientLocation ();
+ child.redrawWidget (x - location.x, y - location.y, width, height, all);
+ }
+}
+void releaseChildren () {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (!child.isDisposed ()) {
+ child.releaseWidget ();
+ child.releaseHandle ();
+ }
+ }
+}
+void releaseWidget () {
+ releaseChildren ();
+ super.releaseWidget ();
+ layout = null;
+ if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) != 0) {
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.background_pixmap = OS.None;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes);
+ }
+ }
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ if (layout != null) layout (false);
+}
+public void setLayout (Layout layout) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.layout = layout;
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ if (layout != null) layout (false);
+}
+int traversalCode () {
+ if ((state & CANVAS) != 0 && hooks (SWT.KeyDown)) return 0;
+ return super.traversalCode ();
+}
+boolean traverseMnemonic (char key) {
+ if (super.traverseMnemonic (key)) return true;
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.traverseMnemonic (key)) return true;
+ }
+ return false;
+}
+}