/*******************************************************************************
* Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.widgets;
import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
/**
* Instances of this class represent the "windows"
* which the desktop or "window manager" is managing.
* Instances that do not have a parent (that is, they
* are built using the constructor, which takes a
* Display
as the argument) are described
* as top level shells. Instances that do have
* a parent are described as secondary or
* dialog shells.
*
* Instances are always displayed in one of the maximized, * minimized or normal states: *
RESIZE
) until it is
* no longer maximized.
*
* The modality of an instance may be specified using
* style bits. The modality style bits are used to determine
* whether input is blocked for other shells on the display.
* The PRIMARY_MODAL
style allows an instance to block
* input to its parent. The APPLICATION_MODAL
style
* allows an instance to block input to every other shell in the
* display. The SYSTEM_MODAL
style allows an instance
* to block input to all shells, including shells belonging to
* different applications.
*
* Note: The styles supported by this class are treated
* as HINTs, since the window manager for the
* desktop on which the instance is visible has ultimate
* control over the appearance and behavior of decorations
* and modality. For example, some window managers only
* support resizable windows and will always assume the
* RESIZE style, even if it is not set. In addition, if a
* modality style is not supported, it is "upgraded" to a
* more restrictive modality style that is supported. For
* example, if PRIMARY_MODAL
is not supported,
* it would be upgraded to APPLICATION_MODAL
.
* A modality style may also be "downgraded" to a less
* restrictive style. For example, most operating systems
* no longer support SYSTEM_MODAL
because
* it can freeze up the desktop, so this is typically
* downgraded to APPLICATION_MODAL
.
*
SWT
provides two "convenience constants"
* for the most commonly required style combinations:
* SHELL_TRIM
CLOSE | TITLE | MIN | MAX | RESIZE
)
* DIALOG_TRIM
TITLE | CLOSE | BORDER
)
* * Note: Only one of the styles APPLICATION_MODAL, MODELESS, * PRIMARY_MODAL and SYSTEM_MODAL may be specified. *
* IMPORTANT: This class is not intended to be subclassed. *
* * @see Decorations * @see SWT * @see Shell snippets * @see SWT Example: ControlExample * @see Sample code and further information * @noextend This class is not intended to be subclassed by clients. */ public class Shell extends Decorations { long /*int*/ shellHandle, tooltipsHandle, tooltipWindow, group, modalGroup; boolean mapped, moved, resized, opened, fullScreen, showWithParent, modified, center; int oldX, oldY, oldWidth, oldHeight; int minWidth, minHeight; Control lastActive; ToolTip [] toolTips; static final int MAXIMUM_TRIM = 128; static final int BORDER = 3; /** * Constructs a new instance of this class. This is equivalent * to callingShell((Display) null)
.
*
* @exception SWTException Shell((Display) null, style)
.
*
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
*
SWT.SHELL_TRIM
.
* * Note: Currently, null can be passed in for the display argument. * This has the effect of creating the shell on the currently active * display if there is one. If there is no current display, the * shell is created on a "default" display. Passing in null as * the display argument is not considered to be good coding style, * and may not be supported in a future release of SWT. *
* * @param display the display to create the shell on * * @exception SWTException
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
*
* Note: Currently, null can be passed in for the display argument. * This has the effect of creating the shell on the currently active * display if there is one. If there is no current display, the * shell is created on a "default" display. Passing in null as * the display argument is not considered to be good coding style, * and may not be supported in a future release of SWT. *
* * @param display the display to create the shell on * @param style the style of control to construct * * @exception SWTExceptionSWT.DIALOG_TRIM
.
* * Note: Currently, null can be passed in for the parent. * This has the effect of creating the shell on the currently active * display if there is one. If there is no current display, the * shell is created on a "default" display. Passing in null as * the parent is not considered to be good coding style, * and may not be supported in a future release of SWT. *
* * @param parent a shell which will be the parent of the new instance * * @exception IllegalArgumentException
* The style value is either one of the style constants defined in
* class SWT
which is applicable to instances of this
* class, or must be built by bitwise OR'ing together
* (that is, using the int
"|" operator) two or more
* of those SWT
style constants. The class description
* lists the style constants that are applicable to the class.
* Style bits are also inherited from superclasses.
*
* Note: Currently, null can be passed in for the parent. * This has the effect of creating the shell on the currently active * display if there is one. If there is no current display, the * shell is created on a "default" display. Passing in null as * the parent is not considered to be good coding style, * and may not be supported in a future release of SWT. *
* * @param parent a shell which will be the parent of the new instance * @param style the style of control to construct * * @exception IllegalArgumentException
* IMPORTANT: This method is not part of the public
* API for Shell
. It is marked public only so that it
* can be shared within the packages provided by SWT. It is not
* available on all platforms, and should never be called from
* application code.
*
* IMPORTANT: This method is not part of the public
* API for Shell
. It is marked public only so that it
* can be shared within the packages provided by SWT. It is not
* available on all platforms, and should never be called from
* application code.
*
ShellListener
interface.
*
* @param listener the listener which should be notified
*
* @exception IllegalArgumentException null
if the platform does not support tool bars that
* are not part of the content area of the shell, or if the Shell's style does not support
* having a tool bar.
*
*
* @return a ToolBar object representing the Shell's tool bar, or
*
* @return the fullscreen state
*
* @exception SWTException
* @return the dialog shells
*
* @exception SWTException
* This operation requires the operating system's advanced
* widgets subsystem which may not be available on some
* platforms.
*
* Note: The result of intermixing calls to
*
*
* @since 3.7
*/
public ToolBar getToolBar() {
checkWidget ();
return null;
}
boolean hasBorder () {
return false;
}
void hookEvents () {
super.hookEvents ();
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [WINDOW_STATE_EVENT], 0, display.closures [WINDOW_STATE_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [CONFIGURE_EVENT], 0, display.closures [CONFIGURE_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [DELETE_EVENT], 0, display.closures [DELETE_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MAP_EVENT], 0, display.shellMapProcClosure, false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
OS.g_signal_connect_closure (shellHandle, OS.move_focus, display.closures [MOVE_FOCUS], false);
if (!OS.GTK3) {
long /*int*/ window = gtk_widget_get_window (shellHandle);
OS.gdk_window_add_filter (window, display.filterProc, shellHandle);
} else {
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false);
}
if (isCustomResize ()) {
int mask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK;
OS.gtk_widget_add_events (shellHandle, mask);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures[EXPOSE_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false);
OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
}
}
public boolean isEnabled () {
checkWidget ();
return getEnabled ();
}
boolean isUndecorated () {
return
(style & (SWT.SHELL_TRIM | SWT.BORDER)) == SWT.NONE ||
(style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0;
}
boolean isCustomResize () {
return (style & SWT.NO_TRIM) == 0 && (style & (SWT.RESIZE | SWT.ON_TOP)) == (SWT.RESIZE | SWT.ON_TOP);
}
public boolean isVisible () {
checkWidget();
return getVisible ();
}
void register () {
super.register ();
display.addWidget (shellHandle, this);
}
void releaseParent () {
/* Do nothing */
}
long /*int*/ topHandle () {
return shellHandle;
}
void fixActiveShell () {
if (display.activeShell == this) {
Shell shell = null;
if (parent != null && parent.isVisible ()) shell = parent.getShell ();
if (shell == null && isUndecorated ()) {
Shell [] shells = display.getShells ();
for (int i = 0; i < shells.length; i++) {
if (shells [i] != null && shells [i].isVisible ()) {
shell = shells [i];
break;
}
}
}
if (shell != null) shell.bringToTop (false);
}
}
void fixShell (Shell newShell, Control control) {
if (this == newShell) return;
if (control == lastActive) setActiveControl (null);
String toolTipText = control.toolTipText;
if (toolTipText != null) {
control.setToolTipText (this, null);
control.setToolTipText (newShell, toolTipText);
}
}
long /*int*/ fixedSizeAllocateProc(long /*int*/ widget, long /*int*/ allocationPtr) {
int clientWidth = 0;
if ((style & SWT.MIRRORED) != 0) clientWidth = getClientWidth ();
long /*int*/ result = super.fixedSizeAllocateProc (widget, allocationPtr);
if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth);
return result;
}
void fixStyle (long /*int*/ handle) {
}
void forceResize () {
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (vboxHandle, allocation);
forceResize (allocation.width, allocation.height);
}
void forceResize (int width, int height) {
GtkRequisition requisition = new GtkRequisition ();
gtk_widget_get_preferred_size (vboxHandle, requisition);
GtkAllocation allocation = new GtkAllocation ();
int border = OS.gtk_container_get_border_width (shellHandle);
allocation.x = border;
allocation.y = border;
allocation.width = width;
allocation.height = height;
OS.gtk_widget_size_allocate (vboxHandle, allocation);
}
/**
* Returns the receiver's alpha value. The alpha value
* is between 0 (transparent) and 255 (opaque).
*
* @return the alpha value
*
* @exception SWTException
*
*
* @since 3.4
*/
public int getAlpha () {
checkWidget ();
if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
if (OS.gtk_widget_is_composited (shellHandle)) {
return (int) (OS.gtk_window_get_opacity (shellHandle) * 255);
}
}
return 255;
}
int getResizeMode (double x, double y) {
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (shellHandle, allocation);
int width = allocation.width;
int height = allocation.height;
int border = OS.gtk_container_get_border_width (shellHandle);
int mode = 0;
if (y >= height - border) {
mode = OS.GDK_BOTTOM_SIDE ;
if (x >= width - border - 16) mode = OS.GDK_BOTTOM_RIGHT_CORNER;
else if (x <= border + 16) mode = OS.GDK_BOTTOM_LEFT_CORNER;
} else if (x >= width - border) {
mode = OS.GDK_RIGHT_SIDE;
if (y >= height - border - 16) mode = OS.GDK_BOTTOM_RIGHT_CORNER;
else if (y <= border + 16) mode = OS.GDK_TOP_RIGHT_CORNER;
} else if (y <= border) {
mode = OS.GDK_TOP_SIDE;
if (x <= border + 16) mode = OS.GDK_TOP_LEFT_CORNER;
else if (x >= width - border - 16) mode = OS.GDK_TOP_RIGHT_CORNER;
} else if (x <= border) {
mode = OS.GDK_LEFT_SIDE;
if (y <= border + 16) mode = OS.GDK_TOP_LEFT_CORNER;
else if (y >= height - border - 16) mode = OS.GDK_BOTTOM_LEFT_CORNER;
}
return mode;
}
/**
* Returns true
if the receiver is currently
* in fullscreen state, and false otherwise.
*
*
*
* @since 3.4
*/
public boolean getFullScreen () {
checkWidget();
return fullScreen;
}
public Point getLocation () {
checkWidget ();
int [] x = new int [1], y = new int [1];
OS.gtk_window_get_position (shellHandle, x,y);
return new Point (x [0], y [0]);
}
public boolean getMaximized () {
checkWidget();
return !fullScreen && super.getMaximized ();
}
/**
* Returns a point describing the minimum receiver's size. The
* x coordinate of the result is the minimum width of the receiver.
* The y coordinate of the result is the minimum height of the
* receiver.
*
* @return the receiver's size
*
* @exception SWTException
*
*
* @since 3.1
*/
public Point getMinimumSize () {
checkWidget ();
int width = Math.max (1, minWidth + trimWidth ());
int height = Math.max (1, minHeight + trimHeight ());
return new Point (width, height);
}
Shell getModalShell () {
Shell shell = null;
Shell [] modalShells = display.modalShells;
if (modalShells != null) {
int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
int index = modalShells.length;
while (--index >= 0) {
Shell modal = modalShells [index];
if (modal != null) {
if ((modal.style & bits) != 0) {
Control control = this;
while (control != null) {
if (control == modal) break;
control = control.parent;
}
if (control != modal) return modal;
break;
}
if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
if (shell == null) shell = getShell ();
if (modal.parent == shell) return modal;
}
}
}
}
return null;
}
/**
* Gets the receiver's modified state.
*
* @return true
if the receiver is marked as modified, or false
otherwise
*
* @exception SWTException
*
*
* @since 3.5
*/
public boolean getModified () {
checkWidget ();
return modified;
}
public Point getSize () {
checkWidget ();
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (vboxHandle, allocation);
int width = allocation.width;
int height = allocation.height;
int border = 0;
if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
border = OS.gtk_container_get_border_width (shellHandle);
}
return new Point (width + trimWidth () + 2*border, height + trimHeight () + 2*border);
}
public boolean getVisible () {
checkWidget();
return gtk_widget_get_visible (shellHandle);
}
/**
* Returns the region that defines the shape of the shell,
* or null
if the shell has the default shape.
*
* @return the region that defines the shape of the shell, or null
*
* @exception SWTException
*
*
* @since 3.0
*
*/
public Region getRegion () {
/* This method is needed for @since 3.0 Javadoc */
checkWidget ();
return region;
}
/**
* Returns the receiver's input method editor mode. This
* will be the result of bitwise OR'ing together one or
* more of the following constants defined in class
* SWT
:
* NONE
, ROMAN
, DBCS
,
* PHONETIC
, NATIVE
, ALPHA
.
*
* @return the IME mode
*
* @exception SWTException
*
*
* @see SWT
*/
public int getImeInputMode () {
checkWidget();
return SWT.NONE;
}
Shell _getShell () {
return this;
}
/**
* Returns an array containing all shells which are
* descendants of the receiver.
*
*
*/
public Shell [] getShells () {
checkWidget();
int count = 0;
Shell [] shells = display.getShells ();
for (int i=0; i
*
* @exception SWTException
*
*
* @see ShellListener
* @see #addShellListener
*/
public void removeShellListener (ShellListener listener) {
checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Close, listener);
eventTable.unhook (SWT.Iconify,listener);
eventTable.unhook (SWT.Deiconify,listener);
eventTable.unhook (SWT.Activate, listener);
eventTable.unhook (SWT.Deactivate, listener);
}
void removeTooTip (ToolTip toolTip) {
if (toolTips == null) return;
for (int i=0; i
*
*
* @since 3.4
*/
public void setAlpha (int alpha) {
checkWidget ();
if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
if (OS.gtk_widget_is_composited (shellHandle)) {
alpha &= 0xFF;
OS.gtk_window_set_opacity (shellHandle, alpha / 255f);
}
}
}
void resizeBounds (int width, int height, boolean notify) {
if (redrawWindow != 0) {
OS.gdk_window_resize (redrawWindow, width, height);
}
if (enableWindow != 0) {
OS.gdk_window_resize (enableWindow, width, height);
}
int border = OS.gtk_container_get_border_width (shellHandle);
int boxWidth = width - 2*border;
int boxHeight = height - 2*border;
if (!OS.GTK3 || (style & SWT.RESIZE) == 0) {
OS.gtk_widget_set_size_request (vboxHandle, boxWidth, boxHeight);
}
forceResize (boxWidth, boxHeight);
if (notify) {
resized = true;
sendEvent (SWT.Resize);
if (isDisposed ()) return;
if (layout != null) {
markLayout (false, false);
updateLayout (false);
}
}
}
int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
if (fullScreen) setFullScreen (false);
/*
* Bug in GTK. When either of the location or size of
* a shell is changed while the shell is maximized, the
* shell is moved to (0, 0). The fix is to explicitly
* unmaximize the shell before setting the bounds to
* anything different from the current bounds.
*/
if (getMaximized ()) {
Rectangle rect = getBounds ();
boolean sameOrigin = !move || (rect.x == x && rect.y == y);
boolean sameExtent = !resize || (rect.width == width && rect.height == height);
if (sameOrigin && sameExtent) return 0;
setMaximized (false);
}
int result = 0;
if (move) {
int [] x_pos = new int [1], y_pos = new int [1];
OS.gtk_window_get_position (shellHandle, x_pos, y_pos);
OS.gtk_window_move (shellHandle, x, y);
if (x_pos [0] != x || y_pos [0] != y) {
moved = true;
oldX = x;
oldY = y;
sendEvent (SWT.Move);
if (isDisposed ()) return 0;
result |= MOVED;
}
}
if (resize) {
width = Math.max (1, Math.max (minWidth, width - trimWidth ()));
height = Math.max (1, Math.max (minHeight, height - trimHeight ()));
/*
* If the shell is created without a RESIZE style bit, and the
* minWidth/minHeight has been set, allow the resize.
*/
if ((style & SWT.RESIZE) != 0 || (minHeight != 0 || minWidth != 0)) OS.gtk_window_resize (shellHandle, width, height);
boolean changed = width != oldWidth || height != oldHeight;
if (changed) {
oldWidth = width;
oldHeight = height;
result |= RESIZED;
}
resizeBounds (width, height, changed);
}
return result;
}
void setCursor (long /*int*/ cursor) {
if (enableWindow != 0) {
OS.gdk_window_set_cursor (enableWindow, cursor);
if (!OS.GDK_WINDOWING_X11 ()) {
OS.gdk_flush ();
} else {
long /*int*/ xDisplay = OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default());
OS.XFlush (xDisplay);
}
}
super.setCursor (cursor);
}
public void setEnabled (boolean enabled) {
checkWidget();
if (((state & DISABLED) == 0) == enabled) return;
Display display = this.display;
Control control = null;
boolean fixFocus = false;
if (!enabled) {
if (display.focusEvent != SWT.FocusOut) {
control = display.getFocusControl ();
fixFocus = isFocusAncestor (control);
}
}
if (enabled) {
state &= ~DISABLED;
} else {
state |= DISABLED;
}
enableWidget (enabled);
if (isDisposed ()) return;
if (enabled) {
if (enableWindow != 0) {
OS.gdk_window_set_user_data (enableWindow, 0);
OS.gdk_window_destroy (enableWindow);
enableWindow = 0;
}
} else {
long /*int*/ parentHandle = shellHandle;
OS.gtk_widget_realize (parentHandle);
long /*int*/ window = gtk_widget_get_window (parentHandle);
Rectangle rect = getBounds ();
GdkWindowAttr attributes = new GdkWindowAttr ();
attributes.width = rect.width;
attributes.height = rect.height;
attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask);
attributes.wclass = OS.GDK_INPUT_ONLY;
attributes.window_type = OS.GDK_WINDOW_CHILD;
enableWindow = OS.gdk_window_new (window, attributes, 0);
if (enableWindow != 0) {
if (cursor != null) {
OS.gdk_window_set_cursor (enableWindow, cursor.handle);
if (!OS.GDK_WINDOWING_X11 ()) {
OS.gdk_flush ();
} else {
long /*int*/ xDisplay = OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default());
OS.XFlush (xDisplay);
}
}
OS.gdk_window_set_user_data (enableWindow, parentHandle);
OS.gdk_window_show (enableWindow);
}
}
if (fixFocus) fixFocus (control);
if (enabled && display.activeShell == this) {
if (!restoreFocus ()) traverseGroup (false);
}
}
/**
* Sets the full screen state of the receiver.
* If the argument is true
causes the receiver
* to switch to the full screen state, and if the argument is
* false
and the receiver was previously switched
* into full screen state, causes the receiver to switch back
* to either the maximized or normal states.
* setFullScreen(true)
,
* setMaximized(true)
and setMinimized(true)
will
* vary by platform. Typically, the behavior will match the platform user's
* expectations, but not always. This should be avoided if possible.
*
*
*
* @since 3.4
*/
public void setFullScreen (boolean fullScreen) {
checkWidget();
if (fullScreen) {
OS.gtk_window_fullscreen (shellHandle);
} else {
OS.gtk_window_unfullscreen (shellHandle);
if (maximized) {
setMaximized (true);
}
}
this.fullScreen = fullScreen;
}
/**
* Sets the input method editor mode to the argument which
* should be the result of bitwise OR'ing together one or more
* of the following constants defined in class SWT
:
* NONE
, ROMAN
, DBCS
,
* PHONETIC
, NATIVE
, ALPHA
.
*
* @param mode the new IME mode
*
* @exception SWTException
*
*
* @see SWT
*/
public void setImeInputMode (int mode) {
checkWidget();
}
void setInitialBounds () {
int width, height;
if ((state & FOREIGN_HANDLE) != 0) {
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (shellHandle, allocation);
width = allocation.width;
height = allocation.height;
} else {
width = OS.gdk_screen_width () * 5 / 8;
height = OS.gdk_screen_height () * 5 / 8;
long /*int*/ screen = OS.gdk_screen_get_default ();
if (screen != 0) {
if (OS.gdk_screen_get_n_monitors (screen) > 1) {
int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ());
GdkRectangle dest = new GdkRectangle ();
OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
width = dest.width * 5 / 8;
height = dest.height * 5 / 8;
}
}
if ((style & SWT.RESIZE) != 0) {
OS.gtk_window_resize (shellHandle, width, height);
}
}
resizeBounds (width, height, false);
}
public void setMaximized (boolean maximized) {
checkWidget();
super.setMaximized (maximized);
if (maximized) {
OS.gtk_window_maximize (shellHandle);
} else {
OS.gtk_window_unmaximize (shellHandle);
}
}
public void setMenuBar (Menu menu) {
checkWidget();
if (menuBar == menu) return;
boolean both = menu != null && menuBar != null;
if (menu != null) {
if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
}
if (menuBar != null) {
long /*int*/ menuHandle = menuBar.handle;
OS.gtk_widget_hide (menuHandle);
destroyAccelGroup ();
}
menuBar = menu;
if (menuBar != null) {
long /*int*/ menuHandle = menu.handle;
OS.gtk_widget_show (menuHandle);
createAccelGroup ();
menuBar.addAccelerators (accelGroup);
}
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (vboxHandle, allocation);
int width = allocation.width;
int height = allocation.height;
resizeBounds (width, height, !both);
}
public void setMinimized (boolean minimized) {
checkWidget();
if (this.minimized == minimized) return;
super.setMinimized (minimized);
if (minimized) {
OS.gtk_window_iconify (shellHandle);
} else {
OS.gtk_window_deiconify (shellHandle);
bringToTop (false);
}
}
/**
* Sets the receiver's minimum size to the size specified by the arguments.
* If the new minimum size is larger than the current size of the receiver,
* the receiver is resized to the new minimum size.
*
* @param width the new minimum width for the receiver
* @param height the new minimum height for the receiver
*
* @exception SWTException
*
*
* @since 3.1
*/
public void setMinimumSize (int width, int height) {
checkWidget ();
GdkGeometry geometry = new GdkGeometry ();
minWidth = geometry.min_width = Math.max (width, trimWidth ()) - trimWidth ();
minHeight = geometry.min_height = Math.max (height, trimHeight ()) - trimHeight ();
OS.gtk_window_set_geometry_hints (shellHandle, 0, geometry, OS.GDK_HINT_MIN_SIZE);
}
/**
* Sets the receiver's minimum size to the size specified by the argument.
* If the new minimum size is larger than the current size of the receiver,
* the receiver is resized to the new minimum size.
*
* @param size the new minimum size for the receiver
*
* @exception IllegalArgumentException
*
* @exception SWTException
*
*
* @since 3.1
*/
public void setMinimumSize (Point size) {
checkWidget ();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setMinimumSize (size.x, size.y);
}
/**
* Sets the receiver's modified state as specified by the argument.
*
* @param modified the new modified state for the receiver
*
*
* @exception SWTException
*
*
* @since 3.5
*/
public void setModified (boolean modified) {
checkWidget ();
this.modified = modified;
}
/**
* Sets the shape of the shell to the region specified
* by the argument. When the argument is null, the
* default shape of the shell is restored. The shell
* must be created with the style SWT.NO_TRIM in order
* to specify a region.
*
* @param region the region that defines the shape of the shell (or null)
*
* @exception IllegalArgumentException
*
* @exception SWTException
*
*
* @since 3.0
*
*/
public void setRegion (Region region) {
checkWidget ();
if ((style & SWT.NO_TRIM) == 0) return;
super.setRegion (region);
}
/*
* Shells are never labelled by other widgets, so no initialization is needed.
*/
void setRelations() {
}
public void setText (String string) {
super.setText (string);
/*
* GTK bug 82013. For some reason, if the title string
* is less than 7 bytes long and is not terminated by
* a space, some window managers occasionally draw
* garbage after the last character in the title.
* The fix is to pad the title.
*/
int length = string.length ();
char [] chars = new char [Math.max (6, length) + 1];
string.getChars (0, length , chars, 0);
for (int i=length; i
*
*
* @since 2.0
* @see Control#moveAbove
* @see Control#setFocus
* @see Control#setVisible
* @see Display#getActiveShell
* @see Decorations#setDefaultButton(Button)
* @see Shell#open
* @see Shell#setActive
*/
public void forceActive () {
checkWidget ();
bringToTop (true);
}
public Rectangle getBounds () {
checkWidget ();
int [] x = new int [1], y = new int [1];
OS.gtk_window_get_position (shellHandle, x, y);
GtkAllocation allocation = new GtkAllocation ();
gtk_widget_get_allocation (vboxHandle, allocation);
int width = allocation.width;
int height = allocation.height;
int border = 0;
if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
border = OS.gtk_container_get_border_width (shellHandle);
}
return new Rectangle (x [0], y [0], width + trimWidth () + 2*border, height + trimHeight () + 2*border);
}
void releaseHandle () {
super.releaseHandle ();
shellHandle = 0;
}
void releaseChildren (boolean destroy) {
Shell [] shells = getShells ();
for (int i=0; i