Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/eclipse/swt/widgets/Control.java


1   /*******************************************************************************
2    * Copyright (c) 2000, 2004 IBM Corporation and others.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Common Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/cpl-v10.html
7    * 
8    * Contributors:
9    *     IBM Corporation - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.swt.widgets;
12  
13  
14  import org.eclipse.swt.*;
15  import org.eclipse.swt.internal.Converter;
16  import org.eclipse.swt.internal.gtk.*;
17  import org.eclipse.swt.graphics.*;
18  import org.eclipse.swt.events.*;
19  import org.eclipse.swt.accessibility.*;
20  
21  /**
22   * Control is the abstract superclass of all windowed user interface classes.
23   * <p>
24   * <dl>
25   * <dt><b>Styles:</b>
26   * <dd>BORDER</dd>
27   * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
28   * <dt><b>Events:</b>
29   * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
30   *     MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse,
31   *     DragDetect, MenuDetect</dd>
32   * </dl>
33   * <p>
34   * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
35   * </p><p>
36   * IMPORTANT: This class is intended to be subclassed <em>only</em>
37   * within the SWT implementation.
38   * </p>
39   */
40  public abstract class Control extends Widget implements Drawable {
41    long /*int*/ fixedHandle;
42    long /*int*/ redrawWindow, enableWindow;
43    int drawCount;
44    Composite parent;
45    Cursor cursor;
46    Menu menu;
47    Font font;
48    String toolTipText;
49    Object layoutData;
50    Accessible accessible;
51  
52  Control () {
53  }
54  
55  /**
56   * Constructs a new instance of this class given its parent
57   * and a style value describing its behavior and appearance.
58   * <p>
59   * The style value is either one of the style constants defined in
60   * class <code>SWT</code> which is applicable to instances of this
61   * class, or must be built by <em>bitwise OR</em>'ing together 
62   * (that is, using the <code>int</code> "|" operator) two or more
63   * of those <code>SWT</code> style constants. The class description
64   * lists the style constants that are applicable to the class.
65   * Style bits are also inherited from superclasses.
66   * </p>
67   *
68   * @param parent a composite control which will be the parent of the new instance (cannot be null)
69   * @param style the style of control to construct
70   *
71   * @exception IllegalArgumentException <ul>
72   *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
73   * </ul>
74   * @exception SWTException <ul>
75   *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
76   *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
77   * </ul>
78   *
79   * @see SWT#BORDER
80   * @see Widget#checkSubclass
81   * @see Widget#getStyle
82   */
83  public Control (Composite parent, int style) {
84    super (parent, style);
85    this.parent = parent;
86    createWidget (0);
87  }
88  
89  long /*int*/ defaultFont () {
90    return display.defaultFont;
91  }
92  
93  void deregister () {
94    super.deregister ();
95    if (fixedHandle != 0) display.removeWidget (fixedHandle);
96    long /*int*/ imHandle = imHandle ();
97    if (imHandle != 0) display.removeWidget (imHandle);
98  }
99  
100 boolean drawGripper (int x, int y, int width, int height) {
101   long /*int*/ paintHandle = paintHandle ();
102   long /*int*/ window = OS.GTK_WIDGET_WINDOW (paintHandle);
103   if (window == 0) return false;
104   long /*int*/ style = OS.gtk_widget_get_style (paintHandle);
105   if (style == 0) return false;
106   byte[] detail = Converter.wcsToMbcs (null, "", true);
107   OS.gtk_paint_handle (style, window, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_OUT, null, paintHandle, detail, x, y, width, height, OS.GTK_ORIENTATION_VERTICAL);
108   return true;
109 }
110 
111 void enableWidget (boolean enabled) {
112   OS.gtk_widget_set_sensitive (handle, enabled);
113 }
114 
115 long /*int*/ eventHandle () {
116   return handle;
117 }
118 
119 void fixFocus (Control focusControl) {
120   Shell shell = getShell ();
121   Control control = this;
122   while ((control = control.parent) != null) {
123     if (control.setFocus ()) return;
124     if (control == shell) break;
125   }
126   shell.setSavedFocus (focusControl);
127   long /*int*/ focusHandle = shell.fixedHandle;
128   OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
129   OS.gtk_widget_grab_focus (focusHandle);
130   OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
131 }
132 
133 long /*int*/ focusHandle () {
134   return handle;
135 }
136 
137 long /*int*/ fontHandle () {
138   return handle;
139 }
140 
141 boolean hasFocus () {
142   return this == display.getFocusControl();
143 }
144 
145 void hookEvents () {
146   long /*int*/ windowProc2 = display.windowProc2;
147   long /*int*/ windowProc3 = display.windowProc3;
148   
149   /* Connect the keyboard signals */
150   long /*int*/ focusHandle = focusHandle ();
151   int focusMask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK;
152   OS.gtk_widget_add_events (focusHandle, focusMask);
153   OS.g_signal_connect (focusHandle, OS.popup_menu, windowProc2, POPUP_MENU);
154   OS.g_signal_connect (focusHandle, OS.show_help, windowProc3, SHOW_HELP);
155   OS.g_signal_connect (focusHandle, OS.key_press_event, windowProc3, KEY_PRESS_EVENT);
156   OS.g_signal_connect (focusHandle, OS.key_release_event, windowProc3, KEY_RELEASE_EVENT);
157   OS.g_signal_connect (focusHandle, OS.focus, windowProc3, FOCUS);
158   OS.g_signal_connect (focusHandle, OS.focus_in_event, windowProc3, FOCUS_IN_EVENT);
159   OS.g_signal_connect (focusHandle, OS.focus_out_event, windowProc3, FOCUS_OUT_EVENT);
160 
161   /* Connect the mouse signals */
162   long /*int*/ eventHandle = eventHandle ();
163   int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK |
164     OS.GDK_BUTTON_RELEASE_MASK | OS.GDK_ENTER_NOTIFY_MASK |
165     OS.GDK_LEAVE_NOTIFY_MASK;
166   OS.gtk_widget_add_events (eventHandle, eventMask);
167   OS.g_signal_connect (eventHandle, OS.button_press_event, windowProc3, BUTTON_PRESS_EVENT);
168   OS.g_signal_connect (eventHandle, OS.button_release_event, windowProc3, BUTTON_RELEASE_EVENT);
169   OS.g_signal_connect (eventHandle, OS.motion_notify_event, windowProc3, MOTION_NOTIFY_EVENT);
170   OS.g_signal_connect (eventHandle, OS.enter_notify_event, windowProc3, ENTER_NOTIFY_EVENT);
171   OS.g_signal_connect (eventHandle, OS.leave_notify_event, windowProc3, LEAVE_NOTIFY_EVENT);
172   /*
173   * Feature in GTK.  Events such as mouse move are propagate up
174   * the widget hierarchy and are seen by the parent.  This is the
175   * correct GTK behavior but not correct for SWT.  The fix is to
176   * hook a signal after and stop the propagation using a negative
177   * event number to distinguish this case.
178   */
179   OS.g_signal_connect_after (eventHandle, OS.button_press_event, windowProc3, -BUTTON_PRESS_EVENT);
180   OS.g_signal_connect_after (eventHandle, OS.button_release_event, windowProc3, -BUTTON_RELEASE_EVENT);
181   OS.g_signal_connect_after (eventHandle, OS.motion_notify_event, windowProc3, -MOTION_NOTIFY_EVENT);
182 
183   /* Connect the event_after signal for both key and mouse */
184   OS.g_signal_connect (eventHandle, OS.event_after, windowProc3, EVENT_AFTER);
185   if (focusHandle != eventHandle) {
186     OS.g_signal_connect (focusHandle, OS.event_after, windowProc3, EVENT_AFTER);
187   }
188   
189   /* Connect the paint signal */
190   long /*int*/ paintHandle = paintHandle ();
191   int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK;
192   OS.gtk_widget_add_events (paintHandle, paintMask);
193   OS.g_signal_connect (paintHandle, OS.expose_event, windowProc3, -EXPOSE_EVENT);
194   OS.g_signal_connect (paintHandle, OS.visibility_notify_event, windowProc3, VISIBILITY_NOTIFY_EVENT);
195   OS.g_signal_connect_after (paintHandle, OS.expose_event, windowProc3, EXPOSE_EVENT);
196 
197   /* Connect the Input Method signals */
198   OS.g_signal_connect_after (handle, OS.realize, windowProc2, REALIZE);
199   OS.g_signal_connect (handle, OS.unrealize, windowProc2, UNREALIZE);
200   long /*int*/ imHandle = imHandle ();
201   if (imHandle != 0) {
202     OS.g_signal_connect (imHandle, OS.commit, windowProc3, COMMIT);
203     OS.g_signal_connect (imHandle, OS.preedit_changed, windowProc2, PREEDIT_CHANGED);
204   }
205 }
206 
207 long /*int*/ hoverProc (long /*int*/ widget) {
208   Event event = new Event ();
209   int [] x = new int [1], y = new int [1], mask = new int [1];
210   OS.gdk_window_get_pointer (0, x, y, mask);
211   event.x = x [0];
212   event.y = y [0];
213   long /*int*/ eventHandle = eventHandle ();
214   long /*int*/ window = OS.GTK_WIDGET_WINDOW (eventHandle);
215   OS.gdk_window_get_origin (window, x, y);
216   event.x -= x [0];
217   event.y -= y [0];
218   setInputState (event, mask [0]);
219   postEvent (SWT.MouseHover, event);
220   return 0;
221 }
222 
223 long /*int*/ topHandle() {
224   if (fixedHandle != 0) return fixedHandle;
225   return super.topHandle ();
226 }
227 
228 long /*int*/ paintHandle () {
229   long /*int*/ topHandle = topHandle ();
230   long /*int*/ paintHandle = handle;
231   while (paintHandle != topHandle) {
232     if ((OS.GTK_WIDGET_FLAGS (paintHandle) & OS.GTK_NO_WINDOW) == 0) break;
233     paintHandle = OS.gtk_widget_get_parent (paintHandle);
234   }
235   return paintHandle;
236 }
237 
238 long /*int*/ paintWindow () {
239   long /*int*/ paintHandle = paintHandle ();
240   OS.gtk_widget_realize (paintHandle);
241   return OS.GTK_WIDGET_WINDOW (paintHandle);
242 }
243 
244 /**
245  * Returns the preferred size of the receiver.
246  * <p>
247  * The <em>preferred size</em> of a control is the size that it would
248  * best be displayed at. The width hint and height hint arguments
249  * allow the caller to ask a control questions such as "Given a particular
250  * width, how high does the control need to be to show all of the contents?"
251  * To indicate that the caller does not wish to constrain a particular 
252  * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. 
253  * </p>
254  *
255  * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
256  * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
257  * @return the preferred size of the control
258  *
259  * @exception SWTException <ul>
260  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
261  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
262  * </ul>
263  *
264  * @see Layout
265  * @see #getBorderWidth
266  * @see #getBounds
267  * @see #getSize
268  * @see #pack
269  * @see "computeTrim, getClientArea for controls that implement them"
270  */
271 public Point computeSize (int wHint, int hHint) {
272   return computeSize (wHint, hHint, true);
273 }
274 
275 Control computeTabGroup () {
276   if (isTabGroup()) return this;
277   return parent.computeTabGroup ();
278 }
279 
280 Control[] computeTabList() {
281   if (isTabGroup()) {
282     if (getVisible() && getEnabled()) {
283       return new Control[] {this};
284     }
285   }
286   return new Control[0];
287 }
288 
289 Control computeTabRoot () {
290   Control[] tabList = parent._getTabList();
291   if (tabList != null) {
292     int index = 0;
293     while (index < tabList.length) {
294       if (tabList [index] == this) break;
295       index++;
296     }
297     if (index == tabList.length) {
298       if (isTabGroup ()) return this;
299     }
300   }
301   return parent.computeTabRoot ();
302 }
303 
304 void createWidget (int index) {
305   checkOrientation (parent);
306   super.createWidget (index);
307   setInitialSize ();
308   setZOrder (null, false);
309 }
310 
311 /**
312  * Returns the preferred size of the receiver.
313  * <p>
314  * The <em>preferred size</em> of a control is the size that it would
315  * best be displayed at. The width hint and height hint arguments
316  * allow the caller to ask a control questions such as "Given a particular
317  * width, how high does the control need to be to show all of the contents?"
318  * To indicate that the caller does not wish to constrain a particular 
319  * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. 
320  * </p><p>
321  * If the changed flag is <code>true</code>, it indicates that the receiver's
322  * <em>contents</em> have changed, therefore any caches that a layout manager
323  * containing the control may have been keeping need to be flushed. When the
324  * control is resized, the changed flag will be <code>false</code>, so layout
325  * manager caches can be retained. 
326  * </p>
327  *
328  * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
329  * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
330  * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
331  * @return the preferred size of the control.
332  *
333  * @exception SWTException <ul>
334  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
335  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
336  * </ul>
337  *
338  * @see Layout
339  * @see #getBorderWidth
340  * @see #getBounds
341  * @see #getSize
342  * @see #pack
343  * @see "computeTrim, getClientArea for controls that implement them"
344  */
345 public Point computeSize (int wHint, int hHint, boolean changed) {
346   checkWidget();
347   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
348   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
349   return computeNativeSize (handle, wHint, hHint, changed);  
350 }
351 
352 Point computeNativeSize (long /*int*/ h, int wHint, int hHint, boolean changed) {
353   int width = OS.GTK_WIDGET_WIDTH (h);
354   int height = OS.GTK_WIDGET_HEIGHT (h);
355   OS.gtk_widget_set_size_request (h, -1, -1);
356   GtkRequisition requisition = new GtkRequisition ();
357   OS.gtk_widget_size_request (h, requisition);
358   OS.gtk_widget_set_size_request (h, width, height);
359   width = wHint == SWT.DEFAULT ? requisition.width : wHint;
360   height = hHint == SWT.DEFAULT ? requisition.height : hHint;
361   return new Point (width, height);  
362 }
363 
364 /**
365  * Returns the accessible object for the receiver.
366  * If this is the first time this object is requested,
367  * then the object is created and returned.
368  *
369  * @return the accessible object
370  *
371  * @exception SWTException <ul>
372  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
373  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
374  * </ul>
375  * 
376  * @see Accessible#addAccessibleListener
377  * @see Accessible#addAccessibleControlListener
378  * 
379  * @since 2.0
380  */
381 public Accessible getAccessible () {
382   checkWidget ();
383   if (accessible == null) {
384     accessible = Accessible.internal_new_Accessible (this);
385   }
386   return accessible;
387 }
388 
389 /**
390  * Returns a rectangle describing the receiver's size and location
391  * relative to its parent (or its display if its parent is null),
392  * unless the receiver is a shell. In this case, the location is
393  * relative to the display.
394  *
395  * @return the receiver's bounding rectangle
396  *
397  * @exception SWTException <ul>
398  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
399  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
400  * </ul>
401  */
402 public Rectangle getBounds () {
403   checkWidget();
404   long /*int*/ topHandle = topHandle ();
405   int x = OS.GTK_WIDGET_X (topHandle);
406   int y = OS.GTK_WIDGET_Y (topHandle);
407   int width = OS.GTK_WIDGET_WIDTH (topHandle);
408   int height = OS.GTK_WIDGET_HEIGHT (topHandle);
409   return new Rectangle (x, y, width, height);
410 }
411 
412 /**
413  * Sets the receiver's size and location to the rectangular
414  * area specified by the argument. The <code>x</code> and 
415  * <code>y</code> fields of the rectangle are relative to
416  * the receiver's parent (or its display if its parent is null).
417  * <p>
418  * Note: Attempting to set the width or height of the
419  * receiver to a negative number will cause that
420  * value to be set to zero instead.
421  * </p>
422  *
423  * @param rect the new bounds for the receiver
424  *
425  * @exception SWTException <ul>
426  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
427  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
428  * </ul>
429  */
430 public void setBounds (Rectangle rect) {
431   checkWidget ();
432   if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
433   setBounds (rect.x, rect.y, rect.width, rect.height);
434 }
435 
436 /**
437  * Sets the receiver's size and location to the rectangular
438  * area specified by the arguments. The <code>x</code> and 
439  * <code>y</code> arguments are relative to the receiver's
440  * parent (or its display if its parent is null), unless 
441  * the receiver is a shell. In this case, the <code>x</code>
442  * and <code>y</code> arguments are relative to the display.
443  * <p>
444  * Note: Attempting to set the width or height of the
445  * receiver to a negative number will cause that
446  * value to be set to zero instead.
447  * </p>
448  *
449  * @param x the new x coordinate for the receiver
450  * @param y the new y coordinate for the receiver
451  * @param width the new width for the receiver
452  * @param height the new height for the receiver
453  *
454  * @exception SWTException <ul>
455  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
456  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
457  * </ul>
458  */
459 public void setBounds (int x, int y, int width, int height) {
460   checkWidget();
461   setBounds (x, y, width, height, true, true);
462 }
463 
464 void moveHandle (int x, int y) {
465   long /*int*/ topHandle = topHandle ();
466   long /*int*/ parentHandle = parent.parentingHandle ();
467   OS.gtk_fixed_move (parentHandle, topHandle, x, y);
468 }
469 
470 void resizeHandle (int width, int height) {
471   long /*int*/ topHandle = topHandle ();
472   OS.gtk_widget_set_size_request (topHandle, width, height);
473   if (topHandle != handle) {
474     OS.gtk_widget_set_size_request (handle, width, height);
475   }
476 
477   /*
478   * Feature in GTK.  Some widgets do not allocate the size
479   * of their internal children in gtk_widget_size_allocate().
480   * Instead this is done in gtk_widget_size_request().  This
481   * means that the client area of the widget is not correct.
482   * The fix is to call gtk_widget_size_request() (and throw
483   * the results away).
484   *
485   * Note: The following widgets rely on this feature:
486   *   GtkScrolledWindow
487   *   GtkNotebook
488   *   GtkFrame
489   *   GtkCombo
490   */
491   GtkRequisition requisition = new GtkRequisition ();
492   OS.gtk_widget_size_request (handle, requisition);
493 }
494 
495 boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
496   long /*int*/ topHandle = topHandle ();
497   int flags = OS.GTK_WIDGET_FLAGS (topHandle);
498   OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE);
499   boolean sameOrigin = true, sameExtent = true;
500   if (move) {
501     int oldX = OS.GTK_WIDGET_X (topHandle);
502     int oldY = OS.GTK_WIDGET_Y (topHandle);
503     sameOrigin = x == oldX && y == oldY;
504     if (!sameOrigin) {
505       if (enableWindow != 0) {
506         OS.gdk_window_move (enableWindow, x, y);
507       }
508       moveHandle (x, y);
509     }
510   }
511   if (resize) {
512     width = Math.max (1, width);
513     height = Math.max (1, height);
514     int oldWidth = OS.GTK_WIDGET_WIDTH (topHandle);
515     int oldHeight = OS.GTK_WIDGET_HEIGHT (topHandle);
516     sameExtent = width == oldWidth && height == oldHeight;
517     if (!sameExtent) {
518       if (redrawWindow != 0) {
519         OS.gdk_window_resize (redrawWindow, width, height);
520       }
521       if (enableWindow != 0) {
522         OS.gdk_window_resize (enableWindow, width, height);
523       }
524       resizeHandle (width, height);
525     }
526   }
527   if (!sameOrigin || !sameExtent) {
528     /*
529     * Force the container to allocate the size of its children.
530     */
531     long /*int*/ parentHandle = parent.parentingHandle ();
532     OS.gtk_container_resize_children (parentHandle);
533   }
534   if ((flags & OS.GTK_VISIBLE) == 0) {
535     OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE);  
536   }
537   if (!sameOrigin) sendEvent (SWT.Move);
538   if (!sameExtent) sendEvent (SWT.Resize);
539   return !sameOrigin || !sameExtent;
540 }
541 
542 /**
543  * Returns a point describing the receiver's location relative
544  * to its parent (or its display if its parent is null), unless
545  * the receiver is a shell. In this case, the point is 
546  * relative to the display. 
547  *
548  * @return the receiver's location
549  *
550  * @exception SWTException <ul>
551  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
552  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
553  * </ul>
554  */
555 public Point getLocation () {
556   checkWidget();
557   long /*int*/ topHandle = topHandle ();
558   int x = OS.GTK_WIDGET_X (topHandle);
559   int y = OS.GTK_WIDGET_Y (topHandle);
560   return new Point (x, y);
561 }
562 
563 /**
564  * Sets the receiver's location to the point specified by
565  * the arguments which are relative to the receiver's
566  * parent (or its display if its parent is null), unless 
567  * the receiver is a shell. In this case, the point is 
568  * relative to the display. 
569  *
570  * @param location the new location for the receiver
571  *
572  * @exception SWTException <ul>
573  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
574  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
575  * </ul>
576  */
577 public void setLocation (Point location) {
578   checkWidget ();
579   if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
580   setLocation (location.x, location.y);
581 }
582 
583 /**
584  * Sets the receiver's location to the point specified by
585  * the arguments which are relative to the receiver's
586  * parent (or its display if its parent is null), unless 
587  * the receiver is a shell. In this case, the point is 
588  * relative to the display. 
589  *
590  * @param x the new x coordinate for the receiver
591  * @param y the new y coordinate for the receiver
592  *
593  * @exception SWTException <ul>
594  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
595  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
596  * </ul>
597  */
598 public void setLocation(int x, int y) {
599   checkWidget();
600   setBounds (x, y, 0, 0, true, false);
601 }
602 
603 /**
604  * Returns a point describing the receiver's size. The
605  * x coordinate of the result is the width of the receiver.
606  * The y coordinate of the result is the height of the
607  * receiver.
608  *
609  * @return the receiver's size
610  *
611  * @exception SWTException <ul>
612  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
613  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
614  * </ul>
615  */
616 public Point getSize () {
617   checkWidget();
618   long /*int*/ topHandle = topHandle ();
619   int width = OS.GTK_WIDGET_WIDTH (topHandle);
620   int height = OS.GTK_WIDGET_HEIGHT (topHandle);
621   return new Point (width, height);
622 }
623 
624 /**
625  * Sets the receiver's size to the point specified by the argument.
626  * <p>
627  * Note: Attempting to set the width or height of the
628  * receiver to a negative number will cause them to be
629  * set to zero instead.
630  * </p>
631  *
632  * @param size the new size for the receiver
633  *
634  * @exception IllegalArgumentException <ul>
635  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
636  * </ul>
637  * @exception SWTException <ul>
638  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
639  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
640  * </ul>
641  */
642 public void setSize (Point size) {
643   checkWidget ();
644   if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
645   setSize (size.x, size.y);
646 }
647 
648 /**
649  * Sets the receiver's size to the point specified by the arguments.
650  * <p>
651  * Note: Attempting to set the width or height of the
652  * receiver to a negative number will cause that
653  * value to be set to zero instead.
654  * </p>
655  *
656  * @param width the new width for the receiver
657  * @param height the new height for the receiver
658  *
659  * @exception SWTException <ul>
660  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
661  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
662  * </ul>
663  */
664 public void setSize (int width, int height) {
665   checkWidget();
666   setBounds (0, 0, width, height, false, true);
667 }
668 
669 /**
670  * Moves the receiver above the specified control in the
671  * drawing order. If the argument is null, then the receiver
672  * is moved to the top of the drawing order. The control at
673  * the top of the drawing order will not be covered by other
674  * controls even if they occupy intersecting areas.
675  *
676  * @param control the sibling control (or null)
677  *
678  * @exception IllegalArgumentException <ul>
679  *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> 
680  * </ul>
681  * @exception SWTException <ul>
682  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
683  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
684  * </ul>
685  * 
686  * @see #moveBelow
687  */
688 public void moveAbove (Control control) {
689   checkWidget();
690   if (control != null) {
691     if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
692     if (parent != control.parent) return;
693   }
694   setZOrder (control, true);
695 }
696 
697 /**
698  * Moves the receiver below the specified control in the
699  * drawing order. If the argument is null, then the receiver
700  * is moved to the bottom of the drawing order. The control at
701  * the bottom of the drawing order will be covered by all other
702  * controls which occupy intersecting areas.
703  *
704  * @param control the sibling control (or null)
705  *
706  * @exception IllegalArgumentException <ul>
707  *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> 
708  * </ul>
709  * @exception SWTException <ul>
710  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
711  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
712  * </ul>
713  * 
714  * @see #moveAbove
715  */
716 public void moveBelow (Control control) {
717   checkWidget();
718   if (control != null) {
719     if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
720     if (parent != control.parent) return;
721   }
722   setZOrder (control, false);
723 }
724 
725 /**
726  * Causes the receiver to be resized to its preferred size.
727  * For a composite, this involves computing the preferred size
728  * from its layout, if there is one.
729  *
730  * @exception SWTException <ul>
731  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
732  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
733  * </ul>
734  *
735  * @see #computeSize
736  */
737 public void pack () {
738   pack (true);
739 }
740 
741 /**
742  * Causes the receiver to be resized to its preferred size.
743  * For a composite, this involves computing the preferred size
744  * from its layout, if there is one.
745  * <p>
746  * If the changed flag is <code>true</code>, it indicates that the receiver's
747  * <em>contents</em> have changed, therefore any caches that a layout manager
748  * containing the control may have been keeping need to be flushed. When the
749  * control is resized, the changed flag will be <code>false</code>, so layout
750  * manager caches can be retained. 
751  * </p>
752  *
753  * @param changed whether or not the receiver's contents have changed
754  * 
755  * @exception SWTException <ul>
756  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
757  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
758  * </ul>
759  *
760  * @see #computeSize
761  */
762 public void pack (boolean changed) {
763   setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
764 }
765 
766 /**
767  * Sets the layout data associated with the receiver to the argument.
768  * 
769  * @param layoutData the new layout data for the receiver.
770  * 
771  * @exception SWTException <ul>
772  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
773  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
774  * </ul>
775  */
776 public void setLayoutData (Object layoutData) {
777   checkWidget();
778   this.layoutData = layoutData;
779 }
780 
781 /**
782  * Returns a point which is the result of converting the
783  * argument, which is specified in display relative coordinates,
784  * to coordinates relative to the receiver.
785  * <p>
786  * @param x the x coordinate to be translated
787  * @param y the y coordinate to be translated
788  * @return the translated coordinates
789  *
790  * @exception SWTException <ul>
791  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
792  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
793  * </ul>
794  * 
795  * @since 2.1
796  */
797 public Point toControl (int x, int y) {
798   checkWidget ();
799   long /*int*/ eventHandle = eventHandle ();
800   OS.gtk_widget_realize (eventHandle);
801   long /*int*/ window = OS.GTK_WIDGET_WINDOW (eventHandle);
802   int [] origin_x = new int [1], origin_y = new int [1];
803   OS.gdk_window_get_origin (window, origin_x, origin_y);
804   return new Point (x - origin_x [0], y - origin_y [0]);
805 }
806 
807 /**
808  * Returns a point which is the result of converting the
809  * argument, which is specified in display relative coordinates,
810  * to coordinates relative to the receiver.
811  * <p>
812  * @param point the point to be translated (must not be null)
813  * @return the translated coordinates
814  *
815  * @exception IllegalArgumentException <ul>
816  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
817  * </ul>
818  * @exception SWTException <ul>
819  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
820  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
821  * </ul>
822  */
823 public Point toControl (Point point) {
824   checkWidget ();
825   if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
826   return toControl (point.x, point.y);
827 }
828 
829 /**
830  * Returns a point which is the result of converting the
831  * argument, which is specified in coordinates relative to
832  * the receiver, to display relative coordinates.
833  * <p>
834  * @param x the x coordinate to be translated
835  * @param y the y coordinate to be translated
836  * @return the translated coordinates
837  *
838  * @exception SWTException <ul>
839  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
840  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
841  * </ul>
842  * 
843  * @since 2.1
844  */
845 public Point toDisplay (int x, int y) {
846   checkWidget();
847   long /*int*/ eventHandle = eventHandle ();
848   OS.gtk_widget_realize (eventHandle);
849   long /*int*/ window = OS.GTK_WIDGET_WINDOW (eventHandle);
850   int [] origin_x = new int [1], origin_y = new int [1];
851   OS.gdk_window_get_origin (window, origin_x, origin_y);
852   return new Point (origin_x [0] + x, origin_y [0] + y);
853 }
854 
855 /**
856  * Returns a point which is the result of converting the
857  * argument, which is specified in coordinates relative to
858  * the receiver, to display relative coordinates.
859  * <p>
860  * @param point the point to be translated (must not be null)
861  * @return the translated coordinates
862  *
863  * @exception IllegalArgumentException <ul>
864  *    <li>ERROR_NULL_ARGUMENT - if the point is null</li>
865  * </ul>
866  * @exception SWTException <ul>
867  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
868  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
869  * </ul>
870  */
871 public Point toDisplay (Point point) {
872   checkWidget();
873   if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
874   return toDisplay (point.x, point.y);
875 }
876  
877 /**
878  * Adds the listener to the collection of listeners who will
879  * be notified when the control is moved or resized, by sending
880  * it one of the messages defined in the <code>ControlListener</code>
881  * interface.
882  *
883  * @param listener the listener which should be notified
884  *
885  * @exception IllegalArgumentException <ul>
886  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
887  * </ul>
888  * @exception SWTException <ul>
889  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
890  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
891  * </ul>
892  *
893  * @see ControlListener
894  * @see #removeControlListener
895  */
896 public void addControlListener(ControlListener listener) {
897   checkWidget();
898   if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
899   TypedListener typedListener = new TypedListener (listener);
900   addListener (SWT.Resize,typedListener);
901   addListener (SWT.Move,typedListener);
902 }
903 
904 /**
905  * Adds the listener to the collection of listeners who will
906  * be notified when the control gains or loses focus, by sending
907  * it one of the messages defined in the <code>FocusListener</code>
908  * interface.
909  *
910  * @param listener the listener which should be notified
911  *
912  * @exception IllegalArgumentException <ul>
913  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
914  * </ul>
915  * @exception SWTException <ul>
916  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
917  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
918  * </ul>
919  *
920  * @see FocusListener
921  * @see #removeFocusListener
922  */
923 public void addFocusListener(FocusListener listener) {
924   checkWidget();
925   if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
926   TypedListener typedListener = new TypedListener (listener);
927   addListener(SWT.FocusIn,typedListener);
928   addListener(SWT.FocusOut,typedListener);
929 }
930 
931 /**
932  * Adds the listener to the collection of listeners who will
933  * be notified when help events are generated for the control,
934  * by sending it one of the messages defined in the
935  * <code>HelpListener</code> interface.
936  *
937  * @param listener the listener which should be notified
938  *
939  * @exception IllegalArgumentException <ul>
940  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
941  * </ul>
942  * @exception SWTException <ul>
943  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
944  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
945  * </ul>
946  *
947  * @see HelpListener
948  * @see #removeHelpListener
949  */
950 public void addHelpListener (HelpListener listener) {
951   checkWidget();
952   if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
953   TypedListener typedListener = new TypedListener (listener);
954   addListener (SWT.Help, typedListener);
955 }
956 
957 /**
958  * Adds the listener to the collection of listeners who will
959  * be notified when keys are pressed and released on the system keyboard, by sending
960  * it one of the messages defined in the <code>KeyListener</code>
961  * interface.
962  *
963  * @param listener the listener which should be notified
964  *
965  * @exception IllegalArgumentException <ul>
966  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
967  * </ul>
968  * @exception SWTException <ul>
969  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
970  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
971  * </ul>
972  *
973  * @see KeyListener
974  * @see #removeKeyListener
975  */
976 public void addKeyListener(KeyListener listener) {
977   checkWidget();
978   if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
979   TypedListener typedListener = new TypedListener (listener);
980   addListener(SWT.KeyUp,typedListener);
981   addListener(SWT.KeyDown,typedListener);
982 }
983 
984 /**
985  * Adds the listener to the collection of listeners who will
986  * be notified when mouse buttons are pressed and released, by sending
987  * it one of the messages defined in the <code>MouseListener</code>
988  * interface.
989  *
990  * @param listener the listener which should be notified
991  *
992  * @exception IllegalArgumentException <ul>
993  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
994  * </ul>
995  * @exception SWTException <ul>
996  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
997  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
998  * </ul>
999  *
1000 * @see MouseListener
1001 * @see #removeMouseListener
1002 */
1003public void addMouseListener(MouseListener listener) {
1004  checkWidget();
1005  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1006  TypedListener typedListener = new TypedListener (listener);
1007  addListener(SWT.MouseDown,typedListener);
1008  addListener(SWT.MouseUp,typedListener);
1009  addListener(SWT.MouseDoubleClick,typedListener);
1010}
1011
1012/**
1013 * Adds the listener to the collection of listeners who will
1014 * be notified when the mouse moves, by sending it one of the
1015 * messages defined in the <code>MouseMoveListener</code>
1016 * interface.
1017 *
1018 * @param listener the listener which should be notified
1019 *
1020 * @exception IllegalArgumentException <ul>
1021 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1022 * </ul>
1023 * @exception SWTException <ul>
1024 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1025 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1026 * </ul>
1027 *
1028 * @see MouseMoveListener
1029 * @see #removeMouseMoveListener
1030 */
1031public void addMouseMoveListener(MouseMoveListener listener) {
1032  checkWidget();
1033  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1034  TypedListener typedListener = new TypedListener (listener);
1035  addListener(SWT.MouseMove,typedListener);
1036}
1037
1038/**
1039 * Adds the listener to the collection of listeners who will
1040 * be notified when the mouse passes or hovers over controls, by sending
1041 * it one of the messages defined in the <code>MouseTrackListener</code>
1042 * interface.
1043 *
1044 * @param listener the listener which should be notified
1045 *
1046 * @exception IllegalArgumentException <ul>
1047 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1048 * </ul>
1049 * @exception SWTException <ul>
1050 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1051 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1052 * </ul>
1053 *
1054 * @see MouseTrackListener
1055 * @see #removeMouseTrackListener
1056 */
1057public void addMouseTrackListener (MouseTrackListener listener) {
1058  checkWidget();
1059  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1060  TypedListener typedListener = new TypedListener (listener);
1061  addListener (SWT.MouseEnter,typedListener);
1062  addListener (SWT.MouseExit,typedListener);
1063  addListener (SWT.MouseHover,typedListener);
1064}
1065
1066/**
1067 * Adds the listener to the collection of listeners who will
1068 * be notified when the receiver needs to be painted, by sending it
1069 * one of the messages defined in the <code>PaintListener</code>
1070 * interface.
1071 *
1072 * @param listener the listener which should be notified
1073 *
1074 * @exception IllegalArgumentException <ul>
1075 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1076 * </ul>
1077 * @exception SWTException <ul>
1078 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1079 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1080 * </ul>
1081 *
1082 * @see PaintListener
1083 * @see #removePaintListener
1084 */
1085public void addPaintListener(PaintListener listener) {
1086  checkWidget();
1087  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1088  TypedListener typedListener = new TypedListener (listener);
1089  addListener(SWT.Paint,typedListener);
1090}
1091
1092/**
1093 * Adds the listener to the collection of listeners who will
1094 * be notified when traversal events occur, by sending it
1095 * one of the messages defined in the <code>TraverseListener</code>
1096 * interface.
1097 *
1098 * @param listener the listener which should be notified
1099 *
1100 * @exception IllegalArgumentException <ul>
1101 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1102 * </ul>
1103 * @exception SWTException <ul>
1104 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1105 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1106 * </ul>
1107 *
1108 * @see TraverseListener
1109 * @see #removeTraverseListener
1110 */
1111public void addTraverseListener (TraverseListener listener) {
1112  checkWidget();
1113  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1114  TypedListener typedListener = new TypedListener (listener);
1115  addListener (SWT.Traverse,typedListener);
1116}
1117
1118/**
1119 * Removes the listener from the collection of listeners who will
1120 * be notified when the control is moved or resized.
1121 *
1122 * @param listener the listener which should be notified
1123 *
1124 * @exception IllegalArgumentException <ul>
1125 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1126 * </ul>
1127 * @exception SWTException <ul>
1128 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1129 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1130 * </ul>
1131 *
1132 * @see ControlListener
1133 * @see #addControlListener
1134 */
1135public void removeControlListener (ControlListener listener) {
1136  checkWidget();
1137  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1138  if (eventTable == null) return;
1139  eventTable.unhook (SWT.Move, listener);
1140  eventTable.unhook (SWT.Resize, listener);
1141}
1142/**
1143 * Removes the listener from the collection of listeners who will
1144 * be notified when the control gains or loses focus.
1145 *
1146 * @param listener the listener which should be notified
1147 *
1148 * @exception IllegalArgumentException <ul>
1149 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1150 * </ul>
1151 * @exception SWTException <ul>
1152 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1153 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1154 * </ul>
1155 *
1156 * @see FocusListener
1157 * @see #addFocusListener
1158 */
1159public void removeFocusListener(FocusListener listener) {
1160  checkWidget();
1161  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1162  if (eventTable == null) return;
1163  eventTable.unhook (SWT.FocusIn, listener);
1164  eventTable.unhook (SWT.FocusOut, listener);
1165}
1166/**
1167 * Removes the listener from the collection of listeners who will
1168 * be notified when the help events are generated for the control.
1169 *
1170 * @param listener the listener which should be notified
1171 *
1172 * @exception IllegalArgumentException <ul>
1173 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1174 * </ul>
1175 * @exception SWTException <ul>
1176 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1177 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1178 * </ul>
1179 *
1180 * @see HelpListener
1181 * @see #addHelpListener
1182 */
1183public void removeHelpListener (HelpListener listener) {
1184  checkWidget();
1185  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1186  if (eventTable == null) return;
1187  eventTable.unhook (SWT.Help, listener);
1188}
1189/**
1190 * Removes the listener from the collection of listeners who will
1191 * be notified when keys are pressed and released on the system keyboard.
1192 *
1193 * @param listener the listener which should be notified
1194 *
1195 * @exception IllegalArgumentException <ul>
1196 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1197 * </ul>
1198 * @exception SWTException <ul>
1199 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1200 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1201 * </ul>
1202 *
1203 * @see KeyListener
1204 * @see #addKeyListener
1205 */
1206public void removeKeyListener(KeyListener listener) {
1207  checkWidget();
1208  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1209  if (eventTable == null) return;
1210  eventTable.unhook (SWT.KeyUp, listener);
1211  eventTable.unhook (SWT.KeyDown, listener);
1212}
1213/**
1214 * Removes the listener from the collection of listeners who will
1215 * be notified when mouse buttons are pressed and released.
1216 *
1217 * @param listener the listener which should be notified
1218 *
1219 * @exception IllegalArgumentException <ul>
1220 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1221 * </ul>
1222 * @exception SWTException <ul>
1223 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1224 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1225 * </ul>
1226 *
1227 * @see MouseListener
1228 * @see #addMouseListener
1229 */
1230public void removeMouseListener (MouseListener listener) {
1231  checkWidget();
1232  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1233  if (eventTable == null) return;
1234  eventTable.unhook (SWT.MouseDown, listener);
1235  eventTable.unhook (SWT.MouseUp, listener);
1236  eventTable.unhook (SWT.MouseDoubleClick, listener);
1237}
1238/**
1239 * Removes the listener from the collection of listeners who will
1240 * be notified when the mouse moves.
1241 *
1242 * @param listener the listener which should be notified
1243 *
1244 * @exception IllegalArgumentException <ul>
1245 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1246 * </ul>
1247 * @exception SWTException <ul>
1248 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1249 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1250 * </ul>
1251 *
1252 * @see MouseMoveListener
1253 * @see #addMouseMoveListener
1254 */
1255public void removeMouseMoveListener(MouseMoveListener listener) {
1256  checkWidget();
1257  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1258  if (eventTable == null) return;
1259  eventTable.unhook (SWT.MouseMove, listener);
1260}
1261
1262/**
1263 * Removes the listener from the collection of listeners who will
1264 * be notified when the mouse passes or hovers over controls.
1265 *
1266 * @param listener the listener which should be notified
1267 *
1268 * @exception IllegalArgumentException <ul>
1269 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1270 * </ul>
1271 * @exception SWTException <ul>
1272 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1273 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1274 * </ul>
1275 *
1276 * @see MouseTrackListener
1277 * @see #addMouseTrackListener
1278 */
1279public void removeMouseTrackListener(MouseTrackListener listener) {
1280  checkWidget();
1281  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1282  if (eventTable == null) return;
1283  eventTable.unhook (SWT.MouseEnter, listener);
1284  eventTable.unhook (SWT.MouseExit, listener);
1285  eventTable.unhook (SWT.MouseHover, listener);
1286}
1287
1288/**
1289 * Removes the listener from the collection of listeners who will
1290 * be notified when the receiver needs to be painted.
1291 *
1292 * @param listener the listener which should be notified
1293 *
1294 * @exception IllegalArgumentException <ul>
1295 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1296 * </ul>
1297 * @exception SWTException <ul>
1298 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1299 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1300 * </ul>
1301 *
1302 * @see PaintListener
1303 * @see #addPaintListener
1304 */
1305public void removePaintListener(PaintListener listener) {
1306  checkWidget();
1307  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1308  if (eventTable == null) return;
1309  eventTable.unhook(SWT.Paint, listener);
1310}
1311
1312/**
1313 * Removes the listener from the collection of listeners who will
1314 * be notified when traversal events occur.
1315 *
1316 * @param listener the listener which should be notified
1317 *
1318 * @exception IllegalArgumentException <ul>
1319 *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1320 * </ul>
1321 * @exception SWTException <ul>
1322 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1323 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1324 * </ul>
1325 *
1326 * @see TraverseListener
1327 * @see #addTraverseListener
1328 */
1329public void removeTraverseListener(TraverseListener listener) {
1330  checkWidget ();
1331  if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
1332  if (eventTable == null) return;
1333  eventTable.unhook (SWT.Traverse, listener);
1334}
1335
1336boolean filterKey (int keyval, long /*int*/ event) {
1337  long /*int*/ imHandle = imHandle ();
1338  if (imHandle != 0) {
1339    return OS.gtk_im_context_filter_keypress (imHandle, event);
1340  }
1341  return false;
1342}
1343
1344Menu [] findMenus (Control control) {
1345  if (menu != null && this != control) return new Menu [] {menu};
1346  return new Menu [0];
1347}
1348
1349void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
1350  oldShell.fixShell (newShell, this);
1351  oldDecorations.fixDecorations (newDecorations, this, menus);
1352}
1353
1354/**
1355 * Forces the receiver to have the <em>keyboard focus</em>, causing
1356 * all keyboard events to be delivered to it.
1357 *
1358 * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
1359 *
1360 * @exception SWTException <ul>
1361 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1362 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1363 * </ul>
1364 *
1365 * @see #setFocus
1366 */
1367public boolean forceFocus () {
1368  checkWidget();
1369  Shell shell = getShell ();
1370  shell.setSavedFocus (this);
1371  if (!isEnabled () || !isVisible ()) return false;
1372  shell.bringToTop (false);
1373  return forceFocus (focusHandle ());
1374}
1375
1376boolean forceFocus (long /*int*/ focusHandle) {
1377  OS.gtk_widget_grab_focus (focusHandle);
1378  return this == display.getFocusControl();
1379}
1380
1381/**
1382 * Returns the receiver's background color.
1383 *
1384 * @return the background color
1385 *
1386 * @exception SWTException <ul>
1387 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1388 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1389 * </ul>
1390 */
1391public Color getBackground () {
1392  checkWidget();
1393  return Color.gtk_new (display, getBackgroundColor ());
1394}
1395
1396GdkColor getBackgroundColor () {
1397  return getBgColor ();
1398}
1399
1400GdkColor getBgColor () {
1401  long /*int*/ fontHandle = fontHandle ();
1402  OS.gtk_widget_realize (fontHandle);
1403  GdkColor color = new GdkColor ();
1404  OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
1405  return color;
1406}
1407
1408GdkColor getBaseColor () {
1409  long /*int*/ fontHandle = fontHandle ();
1410  OS.gtk_widget_realize (fontHandle);
1411  GdkColor color = new GdkColor ();
1412  OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
1413  return color;
1414}
1415
1416/**
1417 * Returns the receiver's border width.
1418 *
1419 * @return the border width
1420 *
1421 * @exception SWTException <ul>
1422 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1423 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1424 * </ul>
1425 */
1426public int getBorderWidth () {
1427  checkWidget();
1428  return 0;
1429}
1430
1431/**
1432 * Returns <code>true</code> if the receiver is enabled, and
1433 * <code>false</code> otherwise. A disabled control is typically
1434 * not selectable from the user interface and draws with an
1435 * inactive or "grayed" look.
1436 *
1437 * @return the receiver's enabled state
1438 *
1439 * @exception SWTException <ul>
1440 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1441 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1442 * </ul>
1443 * 
1444 * @see #isEnabled
1445 */
1446public boolean getEnabled () {
1447  checkWidget ();
1448  return (state & DISABLED) == 0;
1449}
1450
1451/**
1452 * Returns the font that the receiver will use to paint textual information.
1453 *
1454 * @return the receiver's font
1455 *
1456 * @exception SWTException <ul>
1457 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1458 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1459 * </ul>
1460 */
1461public Font getFont () {
1462  checkWidget();
1463  if (font != null) return font;
1464  return Font.gtk_new (display, defaultFont ());
1465}
1466  
1467long /*int*/ getFontDescription () {
1468  long /*int*/ fontHandle = fontHandle ();
1469  return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle));
1470}
1471
1472/**
1473 * Returns the foreground color that the receiver will use to draw.
1474 *
1475 * @return the receiver's foreground color
1476 *
1477 * @exception SWTException <ul>
1478 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1479 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1480 * </ul>
1481 */
1482public Color getForeground () {
1483  checkWidget();
1484  return Color.gtk_new (display, getForegroundColor ());
1485}
1486
1487GdkColor getForegroundColor () {
1488  return getFgColor ();
1489}
1490
1491GdkColor getFgColor () {
1492  long /*int*/ fontHandle = fontHandle ();
1493  OS.gtk_widget_realize (fontHandle);
1494  GdkColor color = new GdkColor ();
1495  OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
1496  return color;
1497}
1498
1499Point getIMCaretPos () {
1500  return new Point (0, 0);
1501}
1502
1503GdkColor getTextColor () {
1504  long /*int*/ fontHandle = fontHandle ();
1505  OS.gtk_widget_realize (fontHandle);
1506  GdkColor color = new GdkColor ();
1507  OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
1508  return color;
1509}
1510
1511/**
1512 * Returns layout data which is associated with the receiver.
1513 *
1514 * @return the receiver's layout data
1515 *
1516 * @exception SWTException <ul>
1517 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1518 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1519 * </ul>
1520 */
1521public Object getLayoutData () {
1522  checkWidget();
1523  return layoutData;
1524}
1525
1526/**
1527 * Returns the receiver's pop up menu if it has one, or null
1528 * if it does not. All controls may optionally have a pop up
1529 * menu that is displayed when the user requests one for
1530 * the control. The sequence of key strokes, button presses
1531 * and/or button releases that are used to request a pop up
1532 * menu is platform specific.
1533 *
1534 * @return the receiver's menu
1535 *
1536 * @exception SWTException <ul>
1537 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1538 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1539 * </ul>
1540 */
1541public Menu getMenu () {
1542  checkWidget();
1543  return menu;
1544}
1545
1546/**
1547 * Returns the receiver's monitor.
1548 * 
1549 * @return the receiver's monitor
1550 * 
1551 * @since 3.0
1552 */
1553public Monitor getMonitor () {
1554  checkWidget();
1555  Monitor monitor = null;
1556  long /*int*/ screen = OS.gdk_screen_get_default ();
1557  if (screen != 0) {
1558    int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ());
1559    GdkRectangle dest = new GdkRectangle ();
1560    OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
1561    monitor = <