📄 control.java
字号:
Control computeTabRoot () { Control [] tabList = parent._getTabList (); if (tabList != null) { int index = 0; while (index < tabList.length) { if (tabList [index] == this) break; index++; } if (index == tabList.length) { if (isTabGroup ()) return this; } } return parent.computeTabRoot ();}Control [] computeTabList () { if (isTabGroup ()) { if (getVisible () && getEnabled ()) { return new Control [] {this}; } } return new Control [0];}void createHandle () { int hwndParent = widgetParent (); handle = OS.CreateWindowEx ( widgetExtStyle (), windowClass (), null, widgetStyle (), OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0, hwndParent, 0, OS.GetModuleHandle (null), widgetCreateStruct ()); if (handle == 0) error (SWT.ERROR_NO_HANDLES); int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.WS_CHILD) != 0) { OS.SetWindowLong (handle, OS.GWL_ID, handle); } if (OS.IsDBLocale && hwndParent != 0) { int hIMC = OS.ImmGetContext (hwndParent); OS.ImmAssociateContext (handle, hIMC); OS.ImmReleaseContext (hwndParent, hIMC); }}void createWidget () { foreground = background = -1; checkOrientation (parent); createHandle (); register (); subclass (); setDefaultFont (); checkMirrored ();}int defaultBackground () { if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW); return OS.GetSysColor (OS.COLOR_BTNFACE);}int defaultFont () { return display.systemFont ();}int defaultForeground () { return OS.GetSysColor (OS.COLOR_WINDOWTEXT);}void deregister () { display.removeControl (handle);}void destroyWidget () { int hwnd = handle; releaseHandle (); if (hwnd != 0) { OS.DestroyWindow (hwnd); }}void drawBackground (int hDC) { RECT rect = new RECT (); OS.GetClientRect (handle, rect); drawBackground (hDC, rect);}void drawBackground (int hDC, RECT rect) { int hPalette = display.hPalette; if (hPalette != 0) { OS.SelectPalette (hDC, hPalette, false); OS.RealizePalette (hDC); } int pixel = getBackgroundPixel (); int hBrush = findBrush (pixel); OS.FillRect (hDC, rect, hBrush);}void enableWidget (boolean enabled) { OS.EnableWindow (handle, enabled);}int findBrush (int pixel) { return parent.findBrush (pixel);}Cursor findCursor () { if (cursor != null) return cursor; return parent.findCursor ();}Menu [] findMenus (Control control) { if (menu != null && this != control) return new Menu [] {menu}; return new Menu [0];}char findMnemonic (String string) { int index = 0; int length = string.length (); do { while (index < length && string.charAt (index) != '&') index++; if (++index >= length) return '\0'; if (string.charAt (index) != '&') return string.charAt (index); index++; } while (index < length); return '\0';}void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { oldShell.fixShell (newShell, this); oldDecorations.fixDecorations (newDecorations, this, menus);}void fixFocus (Control focusControl) { Shell shell = getShell (); Control control = this; while ((control = control.parent) != null) { if (control.setFocus ()) return; if (control == shell) break; } shell.setSavedFocus (focusControl); OS.SetFocus (0);}/** * Forces the receiver to have the <em>keyboard focus</em>, causing * all keyboard events to be delivered to it. * * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to. * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #setFocus */public boolean forceFocus () { checkWidget (); Decorations shell = menuShell (); shell.setSavedFocus (this); if (!isEnabled () || !isVisible () || !isActive ()) return false; if (isFocusControl ()) return true; shell.setSavedFocus (null); /* * This code is intentionally commented. * * When setting focus to a control, it is * possible that application code can set * the focus to another control inside of * WM_SETFOCUS. In this case, the original * control will no longer have the focus * and the call to setFocus() will return * false indicating failure. * * We are still working on a solution at * this time. */// if (OS.GetFocus () != OS.SetFocus (handle)) return false; OS.SetFocus (handle); if (isDisposed ()) return false; shell.setSavedFocus (this); return isFocusControl ();}void forceResize () { if (parent == null) return; WINDOWPOS [] lpwp = parent.lpwp; if (lpwp == null) return; for (int i=0; i<lpwp.length; i++) { WINDOWPOS wp = lpwp [i]; if (wp != null && wp.hwnd == handle) { /* * This code is intentionally commented. All widgets that * are created by SWT have WS_CLIPSIBLINGS to ensure that * application code does not draw outside of the control. */ // int count = parent.getChildrenCount ();// if (count > 1) {// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);// if ((bits & OS.WS_CLIPSIBLINGS) == 0) wp.flags |= OS.SWP_NOCOPYBITS;// } SetWindowPos (wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags); lpwp [i] = null; return; } }}/** * Returns the accessible object for the receiver. * If this is the first time this object is requested, * then the object is created and returned. * * @return the accessible object * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see Accessible#addAccessibleListener * @see Accessible#addAccessibleControlListener * * @since 2.0 */public Accessible getAccessible () { checkWidget (); if (accessible == null) accessible = new_Accessible (this); return accessible;}/** * Returns the receiver's background color. * * @return the background color * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Color getBackground () { checkWidget (); return Color.win32_new (display, getBackgroundPixel ());}int getBackgroundPixel () { if (background == -1) return defaultBackground (); return background;}/** * Returns the receiver's border width. * * @return the border width * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public int getBorderWidth () { checkWidget (); int bits1 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); if ((bits1 & OS.WS_EX_CLIENTEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXEDGE); if ((bits1 & OS.WS_EX_STATICEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXBORDER); int bits2 = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits2 & OS.WS_BORDER) != 0) return OS.GetSystemMetrics (OS.SM_CXBORDER); return 0;}/** * Returns a rectangle describing the receiver's size and location * relative to its parent (or its display if its parent is null), * unless the receiver is a shell. In this case, the location is * relative to the display. * * @return the receiver's bounding rectangle * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Rectangle getBounds () { checkWidget (); forceResize (); RECT rect = new RECT (); OS.GetWindowRect (handle, rect); int hwndParent = parent == null ? 0 : parent.handle; OS.MapWindowPoints (0, hwndParent, rect, 2); int width = rect.right - rect.left; int height = rect.bottom - rect.top; return new Rectangle (rect.left, rect.top, width, height);}int getCodePage () { if (OS.IsUnicode) return OS.CP_ACP; int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); OS.GetObject (hFont, LOGFONT.sizeof, logFont); int cs = logFont.lfCharSet & 0xFF; int [] lpCs = new int [8]; if (OS.TranslateCharsetInfo (cs, lpCs, OS.TCI_SRCCHARSET)) { return lpCs [1]; } return OS.GetACP ();}/** * Returns <code>true</code> if the receiver is enabled, and * <code>false</code> otherwise. A disabled control is typically * not selectable from the user interface and draws with an * inactive or "grayed" look. * * @return the receiver's enabled state * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #isEnabled */public boolean getEnabled () { checkWidget (); return OS.IsWindowEnabled (handle);}/** * Returns the font that the receiver will use to paint textual information. * * @return the receiver's font * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Font getFont () { checkWidget (); int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); if (hFont == 0) hFont = defaultFont (); return Font.win32_new (display, hFont);}/** * Returns the foreground color that the receiver will use to draw. * * @return the receiver's foreground color * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Color getForeground () { checkWidget (); return Color.win32_new (display, getForegroundPixel ());}int getForegroundPixel () { if (foreground == -1) return defaultForeground (); return foreground;}/** * Returns layout data which is associated with the receiver. * * @return the receiver's layout data * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Object getLayoutData () { checkWidget (); return layoutData;}/** * Returns a point describing the receiver's location relative * to its parent (or its display if its parent is null), unless * the receiver is a shell. In this case, the point is * relative to the display. * * @return the receiver's location * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Point getLocation () { checkWidget (); forceResize (); RECT rect = new RECT (); OS.GetWindowRect (handle, rect); int hwndParent = parent == null ? 0 : parent.handle; OS.MapWindowPoints (0, hwndParent, rect, 2); return new Point (rect.left, rect.top);}/** * Returns the receiver's pop up menu if it has one, or null * if it does not. All controls may optionally have a pop up * menu that is displayed when the user requests one for * the control. The sequence of key strokes, button presses * and/or button releases that are used to request a pop up * menu is platform specific. * * @return the receiver's menu * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Menu getMenu () {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -