return OS.GetWindowPort(OS.GetControlOwner(handle));
int port= OS.GetWindowPort(OS.GetControlOwner(handle)); if (port == 0) SWT.error(SWT.ERROR_NO_HANDLES); return port;
int processPaint (Object callData) {	if ((style & SWT.SEPARATOR) != 0 && control != null)		return 0;			Rect bounds= new Rect();	OS.GetControlBounds(handle, bounds);	int width= bounds.right - bounds.left;	int height= bounds.bottom - bounds.top;	OS.SetRect(bounds, (short)0, (short)0, (short)width, (short)height);		final Display display = getDisplay ();	Drawable drawable= new Drawable() {		public int internal_new_GC (GCData data) {			data.device = display;			data.foreground = parent.getForegroundPixel();			data.background = parent.getBackgroundPixel();			data.font = parent.font.handle;			data.controlHandle = handle;			return OS.GetWindowPort(OS.GetControlOwner(handle));		}		public void internal_dispose_GC (int xGC, GCData data) {		}	};		boolean hasCursor= hasCursor ();	GC gc= new GC(drawable);	MacControlEvent me= (MacControlEvent) callData;	Rectangle r= gc.carbon_focus(me.getDamageRegionHandle(), me.getGCContext());	if (!r.isEmpty()) {				// erase background		gc.fillRectangle(0, 0, width, height);				if ((style & SWT.SEPARATOR) != 0) {					OS.DrawThemeSeparator(bounds, OS.kThemeStateActive);					} else {								if ((parent.style & SWT.FLAT) != 0 && set) {				gc.setBackground(Color.carbon_new(display, 0xE0E0E0, false));				gc.fillRoundRectangle(1, 1, width-2, height-2, 8, 8);				gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY));				gc.drawRoundRectangle(1, 1, width-3, height-3, 8, 8);			}					Image currentImage = image;			boolean enabled = getEnabled();					short[] newInfo= new short[3];								newInfo[1]= (short)(set ? OS.kThemeButtonOn : OS.kThemeButtonOff);						if ((parent.style & SWT.FLAT) != 0) {								if (hasCursor && enabled) {					if (OS.StillDown())						newInfo[0]= (short)OS.kThemeStatePressed;					else						newInfo[0]= (short)OS.kThemeStateActive;				} else					newInfo= null;								/* Determine if hot image should be used */				if (enabled && hasCursor && hotImage != null) {					currentImage = hotImage;				}			} else {				newInfo[0]= (short)((hasCursor && OS.StillDown()) ? OS.kThemeStatePressed : OS.kThemeStateActive);			}				if (newInfo != null) {				Rect b= new Rect();				OS.SetRect(b, (short)1, (short)1, (short)(width-1), (short)(height-1));				OS.DrawThemeButton(b, (short)OS.kThemeSmallBevelButton, newInfo, fPrevInfo, 0, 0, 0);			}			fPrevInfo= newInfo;							if (enabled) {				gc.setForeground (parent.getForeground());			} else {				currentImage = disabledImage;				if (currentImage == null && image != null) {					currentImage = new Image (display, image, SWT.IMAGE_DISABLE);				}				Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW);				gc.setForeground (disabledColor);			}						int textX = 0, textY = 0, textWidth = 0, textHeight = 0;			if (text.length() > 0) {				int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;				Point textExtent = gc.textExtent (text, flags);				textWidth = textExtent.x;				textHeight = textExtent.y;			}				int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;			if (currentImage != null) {				try { // AW FIXME					Rectangle imageBounds = currentImage.getBounds ();					imageWidth = imageBounds.width;					imageHeight = imageBounds.height;				} catch (SWTError e) {					System.out.println("ToolItem.processPaint: error in image.getBounds: " + e);				}			}						int spacing = 0;			if (textWidth != 0 && imageWidth != 0) spacing = 2;			if ((parent.style & SWT.RIGHT) != 0) {				imageX = (width - imageWidth - textWidth - spacing) / 2;				imageY = (height - imageHeight) / 2;				textX = spacing + imageX + imageWidth;				textY = (height - textHeight) / 2;			} else {						imageX = (width - imageWidth) / 2;				imageY = (height - imageHeight - textHeight - spacing) / 2;				textX = (width - textWidth) / 2;				textY = spacing + imageY + imageHeight;			}						if ((style & SWT.DROP_DOWN) != 0) {				textX -= 6;  imageX -=6;			}			if (textWidth > 0) {				int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;				gc.drawText(text, textX, textY, flags);			}			if (imageWidth > 0)				gc.drawImage(currentImage, imageX, imageY);							if ((style & SWT.DROP_DOWN) != 0) {				int startX = width - 12, startY = (height - 2) / 2;				int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};				gc.setBackground (gc.getForeground ());				gc.fillPolygon (arrow);				gc.drawPolygon (arrow);			}			if (!enabled && disabledImage == null) {				if (currentImage != null) currentImage.dispose ();			}		}	}	gc.carbon_unfocus();	gc.dispose ();		return 0;}