?? button.java
字號(hào):
return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);}void releaseWidget () { super.releaseWidget (); image = null;}/** * Removes the listener from the collection of listeners who will * be notified when the control is selected. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @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 SelectionListener * @see #addSelectionListener */public void removeSelectionListener (SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); }void selectRadio () { /* * This code is intentionally commented. When two groups * of radio buttons with the same parent are separated by * another control, the correct behavior should be that * the two groups act independently. This is consistent * with radio tool and menu items. The commented code * implements this behavior. */// int index = 0;// Control [] children = parent._getChildren ();// while (index < children.length && children [index] != this) index++;// int i = index - 1;// while (i >= 0 && children [i].setRadioSelection (false)) --i;// int j = index + 1;// while (j < children.length && children [j].setRadioSelection (false)) j++;// setSelection (true); Control [] children = parent._getChildren (); for (int i=0; i<children.length; i++) { Control child = children [i]; if (this != child) child.setRadioSelection (false); } setSelection (true);}/** * Controls how text, images and arrows will be displayed * in the receiver. The argument should be one of * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> * unless the receiver is an <code>ARROW</code> button, in * which case, the argument indicates the direction of * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, * <code>UP</code> or <code>DOWN</code>). * * @param alignment the new alignment * * @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 void setAlignment (int alignment) { checkWidget (); if ((style & SWT.ARROW) != 0) { if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return; style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); OS.InvalidateRect (handle, null, true); return; } if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); bits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT); if ((style & SWT.LEFT) != 0) bits |= OS.BS_LEFT; if ((style & SWT.CENTER) != 0) bits |= OS.BS_CENTER; if ((style & SWT.RIGHT) != 0) bits |= OS.BS_RIGHT; OS.SetWindowLong (handle, OS.GWL_STYLE, bits); OS.InvalidateRect (handle, null, true);}void setDefault (boolean value) { if ((style & SWT.PUSH) == 0) return; int hwndShell = menuShell ().handle; int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if (value) { bits |= OS.BS_DEFPUSHBUTTON; OS.SendMessage (hwndShell, OS.DM_SETDEFID, handle, 0); } else { bits &= ~OS.BS_DEFPUSHBUTTON; OS.SendMessage (hwndShell, OS.DM_SETDEFID, 0, 0); } OS.SendMessage (handle, OS.BM_SETSTYLE, bits, 1);}/** * Sets the receiver's image to the argument, which may be * null indicating that no image should be displayed. * * @param image the image to display on the receiver (may be null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> * </ul> * @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 void setImage (Image image) { checkWidget (); int hImage = 0, imageBits = 0, fImageType = 0; if (image != null) { if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); hImage = image.handle; switch (image.type) { case SWT.BITMAP: imageBits = OS.BS_BITMAP; fImageType = OS.IMAGE_BITMAP; break; case SWT.ICON: imageBits = OS.BS_ICON; fImageType = OS.IMAGE_ICON; break; default: return; } } this.image = image; int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE); int oldBits = newBits; newBits &= ~(OS.BS_BITMAP | OS.BS_ICON); newBits |= imageBits; if (newBits != oldBits) { OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); } OS.SendMessage (handle, OS.BM_SETIMAGE, fImageType, hImage);}boolean setRadioFocus () { if ((style & SWT.RADIO) == 0 || !getSelection ()) return false; return setFocus ();}boolean setRadioSelection (boolean value) { if ((style & SWT.RADIO) == 0) return false; if (getSelection () != value) { setSelection (value); postEvent (SWT.Selection); } return true;}boolean setSavedFocus () { /* * Feature in Windows. When a radio button gets focus, * it selects the button in WM_SETFOCUS. If the previous * saved focus widget was a radio button, allowing the shell * to automatically restore the focus to the previous radio * button will unexpectedly check that button. The fix is * to disallow focus to be restored to radio button that is * not selected. */ if ((style & SWT.RADIO) != 0 && !getSelection ()) return false; return super.setSavedFocus ();}/** * Sets the selection state of the receiver, if it is of type <code>CHECK</code>, * <code>RADIO</code>, or <code>TOGGLE</code>. * * <p> * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, * it is selected when it is checked. When it is of type <code>TOGGLE</code>, * it is selected when it is pushed in. * * @param selected the new selection 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> */public void setSelection (boolean selected) { checkWidget (); if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return; int flags = selected ? OS.BST_CHECKED : OS.BST_UNCHECKED; /* * Feature in Windows. When BM_SETCHECK is used * to set the checked state of a radio or check * button, it sets the WM_TABSTOP style. This * is undocumented and unwanted. The fix is * to save and restore the window style bits. */ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); OS.SendMessage (handle, OS.BM_SETCHECK, flags, 0); OS.SetWindowLong (handle, OS.GWL_STYLE, bits); }/** * Sets the receiver's text. * <p> * This method sets the button label. The label may include * the mnemonic character but must not contain line delimiters. * </p> * <p> * Mnemonics are indicated by an '&' that causes the next * character to be the mnemonic. When the user presses a * key sequence that matches the mnemonic, a selection * event occurs. On most platforms, the mnemonic appears * underlined but may be emphasised in a platform specific * manner. The mnemonic indicator character '&' can be * escaped by doubling it in the string, causing a single *'&' to be displayed. * </p> * * @param string the new text * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the text is null</li> * </ul> * @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 void setText (String string) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); if ((style & SWT.ARROW) != 0) return; int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE); int oldBits = newBits; newBits &= ~(OS.BS_BITMAP | OS.BS_ICON); if (newBits != oldBits) { OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); } TCHAR buffer = new TCHAR (getCodePage (), string, true); OS.SetWindowText (handle, buffer);}int widgetStyle () { int bits = super.widgetStyle (); if ((style & SWT.FLAT) != 0) bits |= OS.BS_FLAT; if ((style & SWT.ARROW) != 0) return bits | OS.BS_OWNERDRAW; if ((style & SWT.LEFT) != 0) bits |= OS.BS_LEFT; if ((style & SWT.CENTER) != 0) bits |= OS.BS_CENTER; if ((style & SWT.RIGHT) != 0) bits |= OS.BS_RIGHT; if ((style & SWT.PUSH) != 0) return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP; if ((style & SWT.CHECK) != 0) return bits | OS.BS_CHECKBOX | OS.WS_TABSTOP; if ((style & SWT.RADIO) != 0) return bits | OS.BS_RADIOBUTTON; if ((style & SWT.TOGGLE) != 0) return bits | OS.BS_PUSHLIKE | OS.BS_CHECKBOX; return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;}TCHAR windowClass () { return ButtonClass;}int windowProc () { return ButtonProc;}LRESULT WM_GETDLGCODE (int wParam, int lParam) { LRESULT result = super.WM_GETDLGCODE (wParam, lParam); if (result != null) return result; if ((style & SWT.ARROW) != 0) { return new LRESULT (OS.DLGC_STATIC); } return result;}LRESULT WM_KILLFOCUS (int wParam, int lParam) { LRESULT result = super.WM_KILLFOCUS (wParam, lParam); if ((style & SWT.PUSH) != 0 && getDefault ()) { menuShell ().setDefaultButton (null, false); } return result;}LRESULT WM_SETFOCUS (int wParam, int lParam) { /* * Feature in Windows. When Windows sets focus to * a radio button, it sets the WM_TABSTOP style. * This is undocumented and unwanted. The fix is * to save and restore the window style bits. */ int bits = 0; if ((style & SWT.RADIO) != 0) { bits = OS.GetWindowLong (handle, OS.GWL_STYLE); } LRESULT result = super.WM_SETFOCUS (wParam, lParam); if ((style & SWT.RADIO) != 0) { OS.SetWindowLong (handle, OS.GWL_STYLE, bits); } if ((style & SWT.PUSH) != 0) { menuShell ().setDefaultButton (this, false); } return result;}LRESULT wmCommandChild (int wParam, int lParam) { int code = wParam >> 16; switch (code) { case OS.BN_CLICKED: case OS.BN_DOUBLECLICKED: if ((style & (SWT.CHECK | SWT.TOGGLE)) != 0) { setSelection (!getSelection ()); } else { if ((style & SWT.RADIO) != 0) { if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) { setSelection (!getSelection ()); } else { selectRadio (); } } } postEvent (SWT.Selection); } return super.wmCommandChild (wParam, lParam);}LRESULT wmDrawChild (int wParam, int lParam) { if ((style & SWT.ARROW) == 0) return super.wmDrawChild (wParam, lParam); DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT (); OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof); int uState = OS.DFCS_SCROLLLEFT; switch (style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) { case SWT.UP: uState = OS.DFCS_SCROLLUP; break; case SWT.DOWN: uState = OS.DFCS_SCROLLDOWN; break; case SWT.LEFT: uState = OS.DFCS_SCROLLLEFT; break; case SWT.RIGHT: uState = OS.DFCS_SCROLLRIGHT; break; } if (!getEnabled ()) uState |= OS.DFCS_INACTIVE; if ((style & SWT.FLAT) == SWT.FLAT) uState |= OS.DFCS_FLAT; if ((struct.itemState & OS.ODS_SELECTED) != 0) uState |= OS.DFCS_PUSHED; RECT rect = new RECT (); OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom); OS.DrawFrameControl (struct.hDC, rect, OS.DFC_SCROLL, uState); return null;}}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -