void drawItem(GC gc, boolean drawFocus) { int headerHeight = parent.getBandHeight(); Display display = getDisplay(); gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND)); gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.fillGradientRectangle(x, y, width, headerHeight, true); if (expanded) { gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1); gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1); gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight); } int drawX = x; if (image != null) { drawX += ExpandItem.TEXT_INSET; if (imageHeight > headerHeight) { gc.drawImage(image, drawX, y + headerHeight - imageHeight); } else { gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2); } drawX += imageWidth; } if (text.length() > 0) { drawX += ExpandItem.TEXT_INSET; Point size = gc.stringExtent(text); gc.setForeground(parent.getForeground()); gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true); } int chevronSize = ExpandItem.CHEVRON_SIZE; drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2); if (drawFocus) { gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2); } }
static long /*int*/ MenuItemSelectedProc(long /*int*/ widget, long /*int*/ user_data) { Display display = Display.getCurrent(); ToolItem item = (ToolItem) display.getWidget(user_data); if (item != null) { return item.getParent().menuItemSelected(widget, item); } return 0; }
/** * This implementation of <code>nativeToJava</code> converts a platform specific representation of * an image to java <code>ImageData</code>. * * @param transferData the platform specific representation of the data to be converted * @return a java <code>ImageData</code> of the image if the conversion was successful; otherwise * null * @see Transfer#javaToNative */ public Object nativeToJava(TransferData transferData) { ImageData imgData = null; if (transferData.length > 0) { long /*int*/ loader = OS.gdk_pixbuf_loader_new(); try { OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null); OS.gdk_pixbuf_loader_close(loader, null); long /*int*/ pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader); if (pixbuf != 0) { Image img = Image.gtk_new_from_pixbuf(Display.getCurrent(), SWT.BITMAP, pixbuf); imgData = img.getImageData(); img.dispose(); } } finally { OS.g_object_unref(loader); } } return imgData; }
/** * This implementation of <code>javaToNative</code> converts an ImageData object represented by * java <code>ImageData</code> to a platform specific representation. * * @param object a java <code>ImageData</code> containing the ImageData to be converted * @param transferData an empty <code>TransferData</code> object that will be filled in on return * with the platform specific format of the data * @see Transfer#nativeToJava */ public void javaToNative(Object object, TransferData transferData) { if (!checkImage(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } if (OS.GTK_VERSION < OS.VERSION(2, 4, 0)) return; ImageData imgData = (ImageData) object; if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); Image image = new Image(Display.getCurrent(), imgData); long /*int*/ pixbuf = ImageList.createPixbuf(image); if (pixbuf != 0) { String typeStr = ""; if (transferData.type == JPEG_ID) typeStr = "jpeg"; else if (transferData.type == PNG_ID) typeStr = "png"; else if (transferData.type == BMP_ID) typeStr = "bmp"; else if (transferData.type == EPS_ID) typeStr = "eps"; else if (transferData.type == PCX_ID) typeStr = "pcx"; else if (transferData.type == PPM_ID) typeStr = "ppm"; else if (transferData.type == RGB_ID) typeStr = "rgb"; else if (transferData.type == TGA_ID) typeStr = "tga"; else if (transferData.type == XBM_ID) typeStr = "xbm"; else if (transferData.type == XPM_ID) typeStr = "xpm"; else if (transferData.type == XV_ID) typeStr = "xv"; byte[] type = Converter.wcsToMbcs(null, typeStr, true); long /*int*/[] buffer = new long /*int*/[1]; long /*int*/[] len = new long /*int*/[1]; if (type == null) return; OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null); OS.g_object_unref(pixbuf); transferData.pValue = buffer[0]; transferData.length = (int) (len[0] + 3) / 4 * 4; transferData.result = 1; transferData.format = 32; } image.dispose(); }
static Browser findBrowser(long /*int*/ handle) { Display display = Display.getCurrent(); return (Browser) display.findWidget(handle); }
private void drag(Event dragEvent) { DNDEvent event = new DNDEvent(); event.widget = this; event.x = dragEvent.x; event.y = dragEvent.y; event.time = OS.GetMessageTime(); event.doit = true; notifyListeners(DND.DragStart, event); if (!event.doit || transferAgents == null || transferAgents.length == 0) return; int[] pdwEffect = new int[1]; int operations = opToOs(getStyle()); Display display = control.getDisplay(); String key = "org.eclipse.swt.internal.win32.runMessagesInIdle"; // $NON-NLS-1$ Object oldValue = display.getData(key); display.setData(key, Boolean.TRUE); ImageList imagelist = null; Image image = event.image; hwndDrag = 0; topControl = null; if (image != null) { imagelist = new ImageList(SWT.NONE); imagelist.add(image); topControl = control.getShell(); /* * Bug in Windows. The image is inverted if the shell is RIGHT_TO_LEFT. * The fix is to create a transparent window that covers the shell client * area and use it during the drag to prevent the image from being inverted. * On XP if the shell is RTL, the image is not displayed. */ int offsetX = event.offsetX; hwndDrag = topControl.handle; if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) { offsetX = image.getBounds().width - offsetX; RECT rect = new RECT(); OS.GetClientRect(topControl.handle, rect); hwndDrag = OS.CreateWindowEx( OS.WS_EX_TRANSPARENT | OS.WS_EX_NOINHERITLAYOUT, WindowClass, null, OS.WS_CHILD | OS.WS_CLIPSIBLINGS, 0, 0, rect.right - rect.left, rect.bottom - rect.top, topControl.handle, 0, OS.GetModuleHandle(null), null); OS.ShowWindow(hwndDrag, OS.SW_SHOW); } OS.ImageList_BeginDrag(imagelist.getHandle(), 0, offsetX, event.offsetY); /* * Feature in Windows. When ImageList_DragEnter() is called, * it takes a snapshot of the screen If a drag is started * when another window is in front, then the snapshot will * contain part of the other window, causing pixel corruption. * The fix is to force all paints to be delivered before * calling ImageList_DragEnter(). */ if (OS.IsWinCE) { OS.UpdateWindow(topControl.handle); } else { int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; OS.RedrawWindow(topControl.handle, null, 0, flags); } POINT pt = new POINT(); pt.x = dragEvent.x; pt.y = dragEvent.y; OS.MapWindowPoints(control.handle, 0, pt, 1); RECT rect = new RECT(); OS.GetWindowRect(hwndDrag, rect); OS.ImageList_DragEnter(hwndDrag, pt.x - rect.left, pt.y - rect.top); } int result = COM.DRAGDROP_S_CANCEL; try { result = COM.DoDragDrop(iDataObject.getAddress(), iDropSource.getAddress(), operations, pdwEffect); } finally { // ensure that we don't leave transparent window around if (hwndDrag != 0) { OS.ImageList_DragLeave(hwndDrag); OS.ImageList_EndDrag(); imagelist.dispose(); if (hwndDrag != topControl.handle) OS.DestroyWindow(hwndDrag); hwndDrag = 0; topControl = null; } display.setData(key, oldValue); } int operation = osToOp(pdwEffect[0]); if (dataEffect == DND.DROP_MOVE) { operation = (operation == DND.DROP_NONE || operation == DND.DROP_COPY) ? DND.DROP_TARGET_MOVE : DND.DROP_MOVE; } else { if (dataEffect != DND.DROP_NONE) { operation = dataEffect; } } event = new DNDEvent(); event.widget = this; event.time = OS.GetMessageTime(); event.doit = (result == COM.DRAGDROP_S_DROP); event.detail = operation; notifyListeners(DND.DragEnd, event); dataEffect = DND.DROP_NONE; }