diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org')
44 files changed, 1432 insertions, 2322 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java index 9d479b0265..f7ed467d1d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java @@ -29,8 +29,6 @@ public final class Color { */ public GdkColor handle; Device display; - boolean isSystem; - Color() { } /** @@ -90,7 +88,6 @@ public Color(Device display, RGB rgb) { * they allocate. */ public void dispose() { - if (isSystem) return; /** * If this is a palette-based display, * Decrease the reference count for this color. @@ -235,20 +232,13 @@ public static Color gtk_new(GdkColor gdkColor) { Color color = new Color(null, gtk_getRGBIntensities(gdkColor)); return color; } -public static Color gtk_new_system(GdkColor gdkColor) { - Color color = new Color(null, gtk_getRGBIntensities(gdkColor)); - color.isSystem = true; - return color; -} static RGB gtk_getRGBIntensities(GdkColor gdkColor) { boolean intensitiesAreZero = (gdkColor.red==0) && (gdkColor.green==0) && (gdkColor.blue==0); if (!intensitiesAreZero) return new RGB ((gdkColor.red&0xFF00)>>8, (gdkColor.green&0xFF00)>>8, (gdkColor.blue&0xFF00)>>8 ); - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - + GdkVisual visual = new GdkVisual(OS.gdk_visual_get_system()); int r = (gdkColor.pixel&visual.red_mask) >> visual.red_shift; if (visual.red_prec<8) r = r << (8 - visual.red_prec); else r = r >> (visual.red_prec - 8); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DefaultGtkStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DefaultGtkStyle.java deleted file mode 100644 index 952fa9d404..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DefaultGtkStyle.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-
-class DefaultGtkStyle {
-
- private static DefaultGtkStyle instance = null;
- private GtkStyle style = null;
- private int defaultFont;
-
- public Color foregroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.fg0_red)>>8,
- ((short)0xFF00 & style.fg0_green)>>8,
- ((short)0xFF00 & style.fg0_blue)>>8);
- }
-
- public Color backgroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.bg0_red)>>8,
- ((short)0xFF00 & style.bg0_green)>>8,
- ((short)0xFF00 & style.bg0_blue)>>8);
- }
-
- public Color foregroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg1_red)>>8,
- ((short)0xFF00 & style.fg1_green)>>8,
- ((short)0xFF00 & style.fg1_blue)>>8);
- }
-
- public Color backgroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg1_red)>>8,
- ((short)0xFF00 & style.bg1_green)>>8,
- ((short)0xFF00 & style.bg1_blue)>>8);
- }
-
- public Color foregroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.fg2_red)>>8,
- ((short)0xFF00 & style.fg2_green)>>8,
- ((short)0xFF00 & style.fg2_blue)>>8);
- }
-
- public Color backgroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.bg2_red)>>8,
- ((short)0xFF00 & style.bg2_green)>>8,
- ((short)0xFF00 & style.bg2_blue)>>8);
- }
-
- public Color foregroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.fg3_red)>>8,
- ((short)0xFF00 & style.fg3_green)>>8,
- ((short)0xFF00 & style.fg3_blue)>>8);
- }
-
- public Color backgroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.bg3_red)>>8,
- ((short)0xFF00 & style.bg3_green)>>8,
- ((short)0xFF00 & style.bg3_blue)>>8);
- }
-
- public Color foregroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg4_red)>>8,
- ((short)0xFF00 & style.fg4_green)>>8,
- ((short)0xFF00 & style.fg4_blue)>>8);
- }
-
- public Color backgroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg4_red)>>8,
- ((short)0xFF00 & style.bg4_green)>>8,
- ((short)0xFF00 & style.bg4_blue)>>8);
- }
-
- public int loadDefaultFont() {
- if (defaultFont == 0) {
- int fnames = Font.getFontNameList(style.font);
- int slength = OS.g_slist_length(fnames);
- if (slength < 1) SWT.error(SWT.ERROR_UNSPECIFIED);
- int name1 = OS.g_slist_nth_data(fnames, 0);
- int length = OS.strlen(name1);
- byte [] buffer1 = new byte[length];
- OS.memmove(buffer1, name1, length);
- defaultFont = OS.gdk_font_load(buffer1);
- if (defaultFont==0) SWT.error(SWT.ERROR_UNSPECIFIED);
- GdkFont gdkFont = new GdkFont();
- OS.memmove(gdkFont, defaultFont, GdkFont.sizeof);
- if (gdkFont.type != OS.GDK_FONT_FONT) SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return defaultFont;
- }
-
- public static DefaultGtkStyle instance() {
- if (instance==null) instance = new DefaultGtkStyle();
- return instance;
- }
-
- private DefaultGtkStyle() {
- style = new GtkStyle();
- OS.memmove(style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
- }
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java index 5140074d6d..a7953b3750 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java @@ -254,48 +254,31 @@ public Point getDPI () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public FontData [] getFontList (String faceName, boolean scalable) { +public FontData[] getFontList (String faceName, boolean scalable) { checkDevice (); - String xlfd; - if (faceName == null) { - xlfd = "-*"; - } else { - int dashIndex = faceName.indexOf('-'); - if (dashIndex < 0) { - xlfd = "-*-" + faceName + "-*"; - } else { - xlfd = "-" + faceName + "-*"; - } - } - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true); - int [] ret = new int [1]; - int listPtr = OS.XListFonts (buffer1, 65535, ret); - int ptr = listPtr; - int [] intBuf = new int [1]; - FontData [] fd = new FontData [ret [0]]; - int fdIndex = 0; - for (int i = 0; i < ret [0]; i++) { - OS.memmove (intBuf, ptr, 4); - int charPtr = intBuf [0]; - int length = OS.strlen (charPtr); - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, charPtr, length); - /* Use the character encoding for the default locale */ - char [] chars = Converter.mbcsToWcs (null, buffer2); - FontData data = FontData.gtk_new (new String (chars)); - boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0; - if (isScalable == scalable) { - fd [fdIndex++] = data; - } - ptr += 4; - } - // FIXME, leaking font list -// OS.XFreeFontNames (listPtr); - if (fdIndex == ret [0]) return fd; - FontData [] result = new FontData [fdIndex]; - System.arraycopy (fd, 0, result, 0, fdIndex); - return result; + + /* Temporary code. + * For now, we know that on Pango at least three font families are guaranteed + * to be present: Sans, Serif, and Monspace. + */ + if (scalable) return getScalableFontList(faceName); + return getNonScalableFontList(faceName); +} +FontData[] getScalableFontList(String faceName) { + FontData[] answer; +// if (faceName==null) { + answer = new FontData[2]; + answer[0] = new FontData("helvetica", 12, SWT.ROMAN); +// } + return answer; +} +FontData[] getNonScalableFontList(String faceName) { + FontData[] answer; +// if (faceName==null) { + answer = new FontData[1]; + answer[0] = new FontData("fixed", 12, SWT.ROMAN); +// } + return answer; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java index b5a0c1e158..c2fcb65fa6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java @@ -50,15 +50,13 @@ Font() { */ public Font(Device display, FontData fd) { if (fd == null) error(SWT.ERROR_NULL_ARGUMENT); - + /* FIXME */ String xlfd = fd.getXlfd(); byte[] buffer = Converter.wcsToMbcs(null, xlfd, true); handle = OS.gdk_font_load(buffer); if (handle == 0) { - int hStyle = OS.gtk_widget_get_default_style(); - GtkStyle gtkStyle = new GtkStyle(); - OS.memmove(gtkStyle, hStyle, GtkStyle.sizeof); - handle = OS.gdk_font_ref(gtkStyle.font); + handle = OS.gdk_font_load(Converter.wcsToMbcs(null, "fixed", true)); + if (handle == 0) error(SWT.ERROR_NO_HANDLES); } } /** @@ -88,10 +86,10 @@ public Font(Device display, String fontFamily, int height, int style) { byte[] buffer = Converter.wcsToMbcs(null, fd.getXlfd(), true); handle = OS.gdk_font_load(buffer); if (handle == 0) { - int hStyle = OS.gtk_widget_get_default_style(); - GtkStyle gtkStyle = new GtkStyle(); - OS.memmove(gtkStyle, hStyle, GtkStyle.sizeof); - handle = OS.gdk_font_ref(gtkStyle.font); + /* Temporary, FIXME */ + buffer = Converter.wcsToMbcs(null, "fixed", true); + handle = OS.gdk_font_load(buffer); + if (handle == 0) error(SWT.ERROR_NO_HANDLES); } } /** @@ -135,47 +133,25 @@ void error(int code) { * </ul> */ public FontData[] getFontData() { - int index=0; - int fnames = getFontNameList(handle); - int nfonts = OS.g_slist_length(fnames); - FontData[] answer = new FontData[nfonts]; - for (int i=0; i<nfonts; i++) { - FontData data = new FontData(); - - int name = OS.g_slist_nth_data(fnames, index); - int length = OS.strlen(name); - byte [] buffer1 = new byte[length]; - OS.memmove(buffer1, name, length); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - String fontname = new String (buffer2, 0, buffer2.length); - data.setXlfd(fontname); - - // Wild guess, 'a' looks average enough - data.averageWidth = OS.gdk_char_width(handle, (byte)'a'); - - // Wild guess, a progressive font should probably have A wider than l - int widthA = OS.gdk_char_width(handle, (byte)'A'); - int widthl = OS.gdk_char_width(handle, (byte)'l'); - if (widthA == widthl) data.spacing = "m"; - else data.spacing = "p"; - - answer[i] = data; - } + if (handle==0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + /* REWRITE ME. + * THIS WILL NEVER WORK CORRECTLY. + * WE USED TO REACH DOWN TO GDK INTERNAL MEMORY + */ + FontData[] answer = new FontData[1]; + FontData data = new FontData(); + data.fontFamily = "fixed"; + data.weight = "normal"; + data.points = 120; + answer[0] = data; return answer; } -static int getFontNameList(int handle) { - int[] mem = new int[7]; - OS.memmove(mem, handle, 7*4); - int type = mem[0]; - int ascent = mem[1]; - int descent = mem[2]; - int xfont =mem [3]; - int xdisplay = mem[4]; - int ref_count = mem[5]; - int names = mem[6]; - return names; -} + public static Font gtk_new(int handle) { + if (handle == 0) { + handle = OS.gdk_font_load(Converter.wcsToMbcs(null, "fixed", true)); + if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); + } Font font = new Font(); font.handle = handle; return font; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java index 5915c07c64..4006adc083 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java @@ -286,9 +286,10 @@ public String getName() { */
public int getStyle() {
int style = 0;
- if (weight.equals("bold"))
- style |= SWT.BOLD;
- if (slant.equals("i"))
+ if (weight!=null)
+ if (weight.equals("bold")) style |= SWT.BOLD;
+ if (slant!=null)
+ if (slant.equals("i"))
style |= SWT.ITALIC;
return style;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java index b1bd432690..b514f317ec 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java @@ -94,14 +94,11 @@ public int getHeight() { public int getLeading() {
return leading;
}
-public static FontMetrics gtk_new(int fontHandle) {
- GdkFont f = new GdkFont();
- OS.memmove (f, fontHandle, GdkFont.sizeof);
-
+public static FontMetrics gtk_new(int gdk_font) {
FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = f.ascent;
- fontMetrics.descent = f.descent;
- fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
+ fontMetrics.ascent = OS.GDK_FONT_ASCENT(gdk_font);
+ fontMetrics.descent = OS.GDK_FONT_DESCENT(gdk_font);
+ fontMetrics.averageCharWidth = OS.gdk_char_width(gdk_font, (byte)'a');
fontMetrics.leading = 3;
fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
return fontMetrics;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java index 24374928a3..bf80991565 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java @@ -68,9 +68,9 @@ public GC(Drawable drawable) { // The colors we get from the widget are not always right. // Get the default GTK_STATE_NORMAL colors - setBackground( DefaultGtkStyle.instance().backgroundColorNORMAL() ); +/* setBackground( DefaultGtkStyle.instance().backgroundColorNORMAL() ); setForeground( DefaultGtkStyle.instance().foregroundColorNORMAL() ); - +*/ // Feature in GDK. // Sometimes, gdk_gc_new() doesn't get the font from the control, @@ -80,7 +80,7 @@ public GC(Drawable drawable) { GdkGCValues values = new GdkGCValues(); OS.gdk_gc_get_values(handle, values); if (values.font == 0) { - OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() ); +/* OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() );*/ } if (data.image != null) { @@ -241,8 +241,7 @@ public int getCharWidth(char ch) { public Rectangle getClipping() { if (data.clipRgn == 0) { int[] width = new int[1]; int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(data.drawable, unused, unused, width, height, unused); + OS.gdk_drawable_get_size(data.drawable, width, height); return new Rectangle(0, 0, width[0], height[0]); } GdkRectangle rect = new GdkRectangle(); @@ -267,8 +266,7 @@ public void getClipping(Region region) { int hRegion = region.handle; if (data.clipRgn == 0) { int[] width = new int[1]; int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(data.drawable, unused, unused, width, height, unused); + OS.gdk_drawable_get_size(data.drawable, width, height); hRegion = OS.gdk_region_new(); GdkRectangle rect = new GdkRectangle(); rect.x = 0; rect.y = 0; @@ -309,9 +307,6 @@ public FontMetrics getFontMetrics() { if (fontHandle==0) { error(SWT.ERROR_UNSPECIFIED); } - GdkFont gdkFont = new GdkFont(); - OS.memmove(gdkFont, fontHandle, GdkFont.sizeof); - byte [] w = Converter.wcsToMbcs (null, "w", true); return FontMetrics.gtk_new(fontHandle); } @@ -400,13 +395,13 @@ public boolean isClipped() { * </ul> */ public void setClipping(int x, int y, int width, int height) { - if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); +/* if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); GdkRectangle rect = new GdkRectangle(); rect.x = (short)x; rect.y = (short)y; rect.width = (short)width; rect.height = (short)height; OS.gdk_gc_set_clip_rectangle(handle, rect); data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); - data.clipRgn = OS.gdk_region_union_with_rect(data.clipRgn, rect); + data.clipRgn = OS.gdk_region_union_with_rect(data.clipRgn, rect);*/ } /** * Sets the area of the receiver which can be changed @@ -435,7 +430,7 @@ public void setClipping(Rectangle rect) { * </ul> */ public void setClipping(Region region) { - if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); +/* if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); if (region == null) { data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); OS.gdk_gc_set_clip_mask(handle, OS.GDK_NONE); @@ -443,7 +438,7 @@ public void setClipping(Region region) { data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); data.clipRgn = OS.gdk_regions_union(region.handle, data.clipRgn); OS.gdk_gc_set_clip_region(handle, region.handle); - } + }*/ } /** * Sets the font which will be used by the receiver @@ -461,7 +456,7 @@ public void setClipping(Region region) { * </ul> */ public void setFont(Font font) { - int fontHandle = 0; +/* int fontHandle = 0; if (font == null) { GtkStyle gtkStyle = new GtkStyle(); int style = OS.gtk_widget_get_default_style(); @@ -470,7 +465,7 @@ public void setFont(Font font) { } else { fontHandle = font.handle; } - OS.gdk_gc_set_font(handle, fontHandle); + OS.gdk_gc_set_font(handle, fontHandle);*/ } /** @@ -634,7 +629,8 @@ private GdkColor _getBackgroundGdkColor() { private int _getGCFont() { GdkGCValues values = _getGCValues(); if (values.font==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); + values.font = OS.gdk_font_load(Converter.wcsToMbcs(null, "fixed", true)); + if (values.font == 0) SWT.error(SWT.ERROR_NO_HANDLES); } return values.font; } @@ -778,9 +774,7 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int end * @see #drawRectangle */ public void drawFocus(int x, int y, int width, int height) { - GtkStyle style = new GtkStyle(); - int hStyle = OS.gtk_widget_get_default_style(); - OS.memmove(style, hStyle, GtkStyle.sizeof); + GtkStyle style = new GtkStyle(OS.gtk_widget_get_default_style()); GdkColor color = new GdkColor(); color.pixel = style.fg0_pixel; color.red = style.fg0_red; @@ -818,8 +812,8 @@ public void drawFocus(int x, int y, int width, int height) { public void drawImage(Image image, int x, int y) { if (image == null) error(SWT.ERROR_NULL_ARGUMENT); int pixmap = image.pixmap; - int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, unused); + int [] width = new int [1]; int [] height = new int [1]; + OS.gdk_drawable_get_size(pixmap, width, height); drawImage(image, 0, 0, width[0], height[0], x, y, width[0], height[0]); } @@ -866,8 +860,7 @@ public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcH /* source image properties */ int[] width = new int[1]; int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(srcImage.pixmap, unused, unused, width, height, unused); + OS.gdk_drawable_get_size(srcImage.pixmap, width, height); if ((srcY + srcWidth > width[0]) || (srcY + srcHeight > height[0])) { error(SWT.ERROR_INVALID_ARGUMENT); @@ -899,7 +892,7 @@ public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcH double offset_y = - srcY * scale_y; int destSizePixbuf = GDKPIXBUF.gdk_pixbuf_new ( - GDKPIXBUF.GDK_COLORSPACE_RGB, + GDKPIXBUF.GDK_COLORSPACE_RGB(), true, 8, destWidth, destHeight); GDKPIXBUF.gdk_pixbuf_scale( pixbuf.handle, // src, @@ -1390,6 +1383,8 @@ public void fillArc(int x, int y, int width, int height, int startAngle, int end public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if ((width == 0) || (height == 0)) return; + + /* Rewrite this to use GdkPixbuf */ GdkGCValues values = new GdkGCValues(); OS.gdk_gc_get_values(handle, values); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index 8d768231fe..b95ab8104d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -132,12 +132,6 @@ Image() { * gc.drawRectangle(0, 0, 50, 50); * gc.dispose(); * </pre> - * <p> - * Note: Some platforms may have a limitation on the size - * of image that can be created (size depends on width, height, - * and depth). For example, Windows 95, 98, and ME do not allow - * images larger than 16M. - * </p> * * @param device the device on which to create the image * @param width the width of the new image @@ -149,6 +143,8 @@ Image() { */ public Image(Device display, int width, int height) { init(display, width, height); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -198,18 +194,18 @@ public Image(Device device, Image srcImage, int flag) { this.alphaData = srcImage.alphaData; this.alpha = srcImage.alpha; this.transparentPixel = srcImage.transparentPixel; - // bogus - are we sure about memGC? + // FIXME - are we sure about memGC? /* Special case: * If all we want is just a clone of the existing pixmap, it can * be done entirely in the X server, without copying across the net. */ if (flag == SWT.IMAGE_COPY) { - int[] unused = new int[1]; int[] width = new int[1]; int[] height = new int[1]; - int[] depth = new int[1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, depth); - pixmap = OS.gdk_pixmap_new (0, width[0], height[0], depth[0]); + OS.gdk_drawable_get_size(srcImage.pixmap, width, height); + int depth = OS.gdk_drawable_get_depth(srcImage.pixmap); + pixmap = OS.gdk_pixmap_new (0, width[0], height[0], depth); + int gc = OS.gdk_gc_new (pixmap); OS.gdk_draw_pixmap(pixmap, gc, srcImage.pixmap, 0,0,0,0, width[0], height[0]); @@ -234,6 +230,8 @@ public Image(Device device, Image srcImage, int flag) { if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); } + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); return; } @@ -259,12 +257,6 @@ public Image(Device device, Image srcImage, int flag) { * gc.drawRectangle(0, 0, 50, 50); * gc.dispose(); * </pre> - * <p> - * Note: Some platforms may have a limitation on the size - * of image that can be created (size depends on width, height, - * and depth). For example, Windows 95, 98, and ME do not allow - * images larger than 16M. - * </p> * * @param device the device on which to create the image * @param bounds a rectangle specifying the image's width and height (must not be null) @@ -277,6 +269,8 @@ public Image(Device device, Image srcImage, int flag) { public Image(Device display, Rectangle bounds) { if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); init(display, bounds.width, bounds.height); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -294,6 +288,8 @@ public Image(Device display, ImageData image) { if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (display == null) display = Display.getDefault(); init(display, image); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -343,6 +339,8 @@ public Image(Device display, ImageData source, ImageData mask) { image.maskPad = mask.scanlinePad; image.maskData = mask.data; init(display, image); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -374,6 +372,8 @@ public Image(Device display, InputStream stream) { if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (display == null) display = Display.getDefault(); init(display, new ImageData(stream)); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -398,6 +398,8 @@ public Image(Device display, String filename) { if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (display == null) display = Display.getDefault(); init(display, new ImageData(filename)); + + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); } /** @@ -510,8 +512,8 @@ public void setBackground(Color color) { * </ul> */ public Rectangle getBounds() { - int[] unused = new int[1]; int[] width = new int[1]; int[] height = new int[1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, unused); + int[] width = new int[1]; int[] height = new int[1]; + OS.gdk_drawable_get_size(pixmap, width, height); return new Rectangle(0, 0, width[0], height[0]); } @@ -535,6 +537,7 @@ public ImageData getImageData() { public static Image gtk_new(int type, int pixmap, int mask) { Image image = new Image(); + if (pixmap==0) SWT.error(SWT.ERROR_CANNOT_BE_ZERO); // FIXME remove this, this is for debugging only image.type = type; image.pixmap = pixmap; image.mask = mask; @@ -601,8 +604,7 @@ public void internal_dispose_GC (int gc, GCData data) { void init(Device display, int width, int height) { device = display; - GdkVisual visual = new GdkVisual (); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); + GdkVisual visual = new GdkVisual (OS.gdk_visual_get_system()); this.pixmap = OS.gdk_pixmap_new(0, width, height, visual.depth); if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); /* Fill the bitmap with white */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java index 460a3bbb6c..69e519f74b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Pixbuffer.java @@ -47,12 +47,9 @@ final class Pixbuffer { Pixbuffer (Image src) { if (src == null || src.pixmap == 0) SWT.error(SWT.ERROR_NULL_ARGUMENT); - // get the geometry - int[] unused = new int[1]; int[] w = new int[1]; int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(src.pixmap, unused, unused, w, h, unused); + OS.gdk_drawable_get_size(src.pixmap, w, h); int width = w[0]; int height = h[0]; @@ -178,8 +175,7 @@ final class Pixbuffer { if (dest==null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int w = getWidth(); int h = getHeight(); - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); + GdkVisual visual = new GdkVisual(OS.gdk_visual_get_system()); dest.pixmap = OS.gdk_pixmap_new (0, w, h, visual.depth); dest.mask = 0; // for now; we fill it later in this method GDKPIXBUF.gdk_pixbuf_render_to_drawable_alpha(handle, // src @@ -274,24 +270,22 @@ final class Pixbuffer { * an alpha channel. */ private void createHandle(int width, int height) { - handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB, + handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB(), true, 8, width, height); - if (this.handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (this.handle == 0) { + SWT.error(SWT.ERROR_NO_HANDLES); + } data = GDKPIXBUF.gdk_pixbuf_get_pixels(handle); } private void fillAlphaFromPixmapMask(int mask) { hasMask = true; - /* pull the mask data from the X Server */ - // get the geometry - int[] unused = new int[1]; int[] w = new int[1]; int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(mask, unused, unused, w, h, unused); + OS.gdk_drawable_get_size(mask, w, h); int width = Math.min(w[0], getWidth()); int height = Math.min(h[0], getHeight()); /* Get the data */ @@ -315,13 +309,9 @@ final class Pixbuffer { private void fillAlphaFromTransparentPixel(int pm, int pixel) { transparentPixel = pixel; - /* pull the data from the X Server */ - // get the geometry - int[] unused = new int[1]; int[] w = new int[1]; int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(pm, unused, unused, w, h, unused); + OS.gdk_drawable_get_size(pm, w, h); int width = Math.min(w[0], getWidth()); int height = Math.min(h[0], getHeight()); /* Get the data */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index c08b892a20..514ceb9819 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -142,7 +142,7 @@ void createHandle (int index) { void setHandleStyle() {} void configure() { - _connectParent(); + parent._connectChild(topHandle()); OS.gtk_container_add (boxHandle, handle); } @@ -461,10 +461,10 @@ public void setText (String string) { int widget = OS.g_list_nth_data (list, 0); if (widget != 0) OS.gtk_widget_destroy (widget); } - byte [] buffer1 = Converter.wcsToMbcs (null, text); - int label = OS.gtk_label_new (buffer1); - byte [] buffer2 = Converter.wcsToMbcs (null, pattern); - OS.gtk_label_set_pattern (label, buffer2); + /* FIXME - accels */ + int label = OS.gtk_label_new (string); +/* byte [] buffer2 = Converter.wcsToMbcs (null, pattern); + OS.gtk_label_set_pattern (label, buffer2);*/ OS.gtk_container_add (handle, label); OS.gtk_widget_show (label); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java index 3374e5cc65..ae94ecf618 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java @@ -117,8 +117,7 @@ public Caret getCaret () { * </ul> */ public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (width <= 0 || height <= 0) return; int deltaX = destX - x, deltaY = destY - y; @@ -129,10 +128,7 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b boolean isVisible = (caret != null) && (caret.isVisible ()); if (isVisible) caret.hideCaret (); - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, paintHandle(), GtkWidget.sizeof); - int window = widget.window; - if (window == 0) return; + int window = OS.GTK_WIDGET_WINDOW(paintHandle()); /* Emit a NoExpose Event */ int gc = OS.gdk_gc_new (window); @@ -243,8 +239,7 @@ int processMouseUp (int callData, int arg1, int int2) { int processPaint (int callData, int arg1, int int2) { //if (!hooks (SWT.Paint)) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); + GdkEventExpose gdkEvent = new GdkEventExpose (callData); Event event = new Event (); event.count = gdkEvent.count; event.x = gdkEvent.x; event.y = gdkEvent.y; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java index 85c62c27b7..68a74a8f3f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java @@ -88,9 +88,7 @@ boolean drawCaret () { /* The parent is a Canvas; its handle is a GtkDrawingArea. * Get the DA's GDK window to draw on. */ - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, parent.handle, GtkWidget.sizeof); - int window = widget.window; + int window = OS.GTK_WIDGET_WINDOW(parent.handle); /* Create the GC, and set the working color and rop. */ int gc = OS.gdk_gc_new(window); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java index ebe8093461..8a6baadf45 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java @@ -97,10 +97,8 @@ public RGB getRGB () { return rgb;
}
int okFunc (int widget, int callData) {
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, callData, GtkColorSelectionDialog.sizeof);
double [] color = new double [4];
- OS.gtk_color_selection_get_color (dialog.colorsel, color);
+ OS.gtk_color_selection_get_color (OS.GTK_COLOR_SELECTION_COLORSEL(callData), color);
rgb = new RGB ((int)(color [0] * 256), (int)(color [1] * 256), (int)(color [2] * 256));
OS.gtk_widget_destroy (callData);
return 0;
@@ -123,15 +121,13 @@ public RGB open () { byte [] titleBytes;
titleBytes = Converter.wcsToMbcs (null, title, true);
handle = OS.gtk_color_selection_dialog_new (titleBytes);
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, handle, GtkColorSelectionDialog.sizeof);
- OS.gtk_widget_hide (dialog.help_button);
+ OS.gtk_widget_hide (OS.GTK_COLOR_SELECTION_OK_BUTTON(handle));
if (rgb != null) {
double [] color = new double [4];
color [0] = (double)rgb.red / 256;
color [1] = (double)rgb.green / 256;
color [2] = (double)rgb.blue / 256;
- OS.gtk_color_selection_set_color (dialog.colorsel, color);
+ OS.gtk_color_selection_set_color (OS.GTK_COLOR_SELECTION_COLORSEL(handle), color);
}
Callback destroyCallback = new Callback (this, "destroyFunc", 2);
int destroyFunc = destroyCallback.getAddress ();
@@ -142,8 +138,8 @@ public RGB open () { int okFunc = okCallback.getAddress ();
Callback cancelCallback = new Callback (this, "cancelFunc", 2);
int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
+ OS.gtk_signal_connect (OS.GTK_COLOR_SELECTION_OK_BUTTON(handle), clicked, okFunc, handle);
+ OS.gtk_signal_connect (OS.GTK_COLOR_SELECTION_CANCEL_BUTTON(handle), clicked, cancelFunc, handle);
rgb = null;
OS.gtk_widget_show_now (handle);
OS.gtk_main ();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index b192c92336..f11e1ca89f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -46,7 +46,9 @@ import org.eclipse.swt.events.*; */ public class Combo extends Composite { - int padHandle, glist; + int fixedHandle; + int entryHandle, listHandle; + int glist; int textLimit = LIMIT; public final static int LIMIT; @@ -263,46 +265,31 @@ static int checkStyle (int style) { */ public void clearSelection () { checkWidget(); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - int position = OS.gtk_editable_get_position (combo.entry); - OS.gtk_editable_set_position (combo.entry, position); + /*int position = OS.gtk_editable_get_position (entryHandle); + OS.gtk_editable_set_position (entryHandle, position);*/ } void createHandle (int index) { state |= HANDLE; - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - padHandle = OS.gtk_fixed_new (); - if (padHandle == 0) error (SWT.ERROR_NO_HANDLES); + fixedHandle = OS.eclipse_fixed_new(); + if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); handle = OS.gtk_combo_new (); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new(); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); + GtkCombo combo = new GtkCombo (handle); + entryHandle = combo.entry; + listHandle = combo.list; } - void setHandleStyle() { - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); boolean isEditable = (style & SWT.READ_ONLY) == 0; - OS.gtk_entry_set_editable (combo.entry, isEditable); + OS.gtk_entry_set_editable (entryHandle, isEditable); } void configure () { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, padHandle); - OS.gtk_fixed_put (padHandle, fixedHandle, (short)0, (short)0); - OS.gtk_fixed_put (padHandle, handle, (short)0, (short)0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - return _computeSize(wHint, hHint, changed); + parent._connectChild(topHandle()); + OS.gtk_container_add(fixedHandle, handle); } void showHandle() { - OS.gtk_widget_show(eventBoxHandle); - OS.gtk_widget_show(padHandle); OS.gtk_widget_show(fixedHandle); OS.gtk_widget_show(handle); OS.gtk_widget_realize (handle); @@ -310,68 +297,69 @@ void showHandle() { void deregister () { super.deregister (); - WidgetTable.remove (padHandle); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - WidgetTable.remove (combo.entry); - WidgetTable.remove (combo.list); - WidgetTable.remove (combo.button); + WidgetTable.remove (fixedHandle); + WidgetTable.remove (entryHandle); + WidgetTable.remove (listHandle); } void hookEvents () { // TO DO - expose, enter/exit, focus in/out super.hookEvents (); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); // TO DO - fix multiple selection events for one user action - signal_connect (combo.list, "select_child", SWT.Selection, 3); - signal_connect_after (combo.entry, "changed", SWT.Modify, 2); + signal_connect (listHandle, "select_child", SWT.Selection, 3); + signal_connect_after (entryHandle, "changed", SWT.Modify, 2); int mask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK; - int [] handles = new int [] {combo.entry, combo.list, combo.button}; - for (int i=0; i<handles.length; i++) { - int handle = handles [i]; - if (!OS.GTK_WIDGET_NO_WINDOW (handle)) { - OS.gtk_widget_add_events (handle, mask); - } - signal_connect_after (handle, "motion_notify_event", SWT.MouseMove, 3); - signal_connect_after (handle, "button_press_event", SWT.MouseDown, 3); - signal_connect_after (handle, "button_release_event", SWT.MouseUp, 3); - signal_connect_after (handle, "key_press_event", SWT.KeyDown, 3); - signal_connect_after (handle, "key_release_event", SWT.KeyUp, 3); - } + + OS.gtk_widget_add_events (entryHandle, mask); + OS.gtk_widget_add_events (listHandle, mask); + + signal_connect_after (entryHandle, "motion_notify_event", SWT.MouseMove, 3); + signal_connect_after (entryHandle, "button_press_event", SWT.MouseDown, 3); + signal_connect_after (entryHandle, "button_release_event", SWT.MouseUp, 3); + signal_connect_after (entryHandle, "key_press_event", SWT.KeyDown, 3); + signal_connect_after (entryHandle, "key_release_event", SWT.KeyUp, 3); + + signal_connect_after (listHandle, "motion_notify_event", SWT.MouseMove, 3); + signal_connect_after (listHandle, "button_press_event", SWT.MouseDown, 3); + signal_connect_after (listHandle, "button_release_event", SWT.MouseUp, 3); + signal_connect_after (listHandle, "key_press_event", SWT.KeyDown, 3); + signal_connect_after (listHandle, "key_release_event", SWT.KeyUp, 3); + + signal_connect_after (handle, "motion_notify_event", SWT.MouseMove, 3); + signal_connect_after (handle, "button_press_event", SWT.MouseDown, 3); + signal_connect_after (handle, "button_release_event", SWT.MouseUp, 3); + signal_connect_after (handle, "key_press_event", SWT.KeyDown, 3); + signal_connect_after (handle, "key_release_event", SWT.KeyUp, 3); } -int topHandle() { return eventBoxHandle; } +int topHandle() { return fixedHandle; } int parentingHandle() { return fixedHandle; } boolean isMyHandle(int h) { - if (h==eventBoxHandle) return true; - if (h==padHandle) return true; if (h==fixedHandle) return true; if (h==handle) return true; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - if (h== combo.entry) return true; - if (h== combo.list) return true; - if (h== combo.button) return true; + if (h== entryHandle) return true; + if (h== listHandle) return true; return false; } -void _connectChild (int h) { - OS.gtk_fixed_put (fixedHandle, h, (short)0, (short)0); +Point _getClientAreaSize () { + //return _getSize(); + /* FIXME */ + return new Point(70, 20); } -Point _getClientAreaSize () { - return UtilFuncs.getSize(fixedHandle); +void _setSize(int width, int height) { + width = 70; height = 20; + super._setSize(width, height); + OS.eclipse_fixed_set_size(fixedHandle, handle, width, height); } -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height); - UtilFuncs.setSize (fixedHandle, width,height); - UtilFuncs.setSize (handle, width,height); - return differentExtent; +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + return new Point (70,20); } /** @@ -535,11 +523,10 @@ public String [] getItems () { */ public Point getSelection () { checkWidget (); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - GtkEditable editable = new GtkEditable(); - OS.memmove (editable, combo.entry, GtkEditable.sizeof); - return new Point (editable.selection_start_pos, editable.selection_end_pos); +/* GtkEditable editable = new GtkEditable(); + OS.memmove (editable, entryHandle, GtkEditable.sizeof);*/ + /* FIXME */ + return new Point (0,0); } /** @@ -572,9 +559,7 @@ public int getSelectionIndex () { */ public String getText () { checkWidget(); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - int address = OS.gtk_entry_get_text (combo.entry); + int address = OS.gtk_entry_get_text (entryHandle); int length = OS.strlen (address); byte [] buffer1 = new byte [length]; OS.memmove (buffer1, address, length); @@ -700,13 +685,10 @@ int processSelection (int int0, int int1, int int2) { } void register () { - super.register (); - WidgetTable.put (padHandle, this); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - WidgetTable.put (combo.entry, this); - WidgetTable.put (combo.list, this); - WidgetTable.put (combo.button, this); + WidgetTable.put (handle, this); + WidgetTable.put (fixedHandle, this); + WidgetTable.put (entryHandle, this); + WidgetTable.put (listHandle, this); } void releaseHandle () { @@ -891,14 +873,12 @@ public void select (int index) { String [] items = getItems (); if (index >= items.length) return; String selectedText = items [index]; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_block_by_data (combo.list, SWT.Selection); - OS.gtk_list_select_item (combo.list, index); - OS.gtk_entry_set_text (combo.entry, Converter.wcsToMbcs (null, selectedText, true)); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_unblock_by_data (combo.list, SWT.Selection); + OS.gtk_signal_handler_block_by_data (entryHandle, SWT.Modify); + OS.gtk_signal_handler_block_by_data (listHandle, SWT.Selection); + OS.gtk_list_select_item (listHandle, index); + OS.gtk_entry_set_text (entryHandle, Converter.wcsToMbcs (null, selectedText, true)); + OS.gtk_signal_handler_unblock_by_data (entryHandle, SWT.Modify); + OS.gtk_signal_handler_unblock_by_data (listHandle, SWT.Selection); } /** @@ -948,11 +928,9 @@ public void setItem (int index, String string) { */ public void setItems (String [] items) { checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); + /*if (items == null) error (SWT.ERROR_NULL_ARGUMENT); if (items.length == 0) { - OS.gtk_list_clear_items (combo.list, 0, -1); + OS.gtk_list_clear_items (listHandle, 0, -1); //LEAK glist = 0; } else { @@ -966,11 +944,11 @@ public void setItems (String [] items) { OS.memmove (data, buffer, buffer.length); new_glist = OS.g_list_append (new_glist, data); } - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_block_by_data (combo.list, SWT.Selection); + OS.gtk_signal_handler_block_by_data (entryHandle, SWT.Modify); + OS.gtk_signal_handler_block_by_data (listHandle, SWT.Selection); OS.gtk_combo_set_popdown_strings (handle, new_glist); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_unblock_by_data (combo.list, SWT.Selection); + OS.gtk_signal_handler_unblock_by_data (entryHandle, SWT.Modify); + OS.gtk_signal_handler_unblock_by_data (listHandle, SWT.Selection); if (glist != 0) { int count = OS.g_list_length (glist); for (int i=0; i<count; i++) { @@ -981,9 +959,9 @@ public void setItems (String [] items) { } glist = new_glist; } - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_editable_delete_text (combo.entry, 0, -1); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); + OS.gtk_signal_handler_block_by_data (entryHandle, SWT.Modify); + OS.gtk_editable_delete_text (entryHandle, 0, -1); + OS.gtk_signal_handler_unblock_by_data (entryHandle, SWT.Modify);*/ } /** @@ -1004,12 +982,9 @@ public void setItems (String [] items) { */ public void setSelection (Point selection) { checkWidget(); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - GtkCombo gtkCombo = new GtkCombo (); - OS.memmove (gtkCombo, handle, GtkCombo.sizeof); - int entry = gtkCombo.entry; - OS.gtk_editable_set_position (entry, selection.x); - OS.gtk_editable_select_region (entry, selection.x, selection.y); + /*if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); + OS.gtk_editable_set_position (entryHandle, selection.x); + OS.gtk_editable_select_region (entryHandle, selection.x, selection.y);*/ } protected boolean setTabGroupFocus () { @@ -1039,16 +1014,13 @@ protected boolean setTabGroupFocus () { */ public void setText (String string) { checkWidget(); + /*if (string == null) error (SWT.ERROR_NULL_ARGUMENT); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - GtkCombo gtkCombo = new GtkCombo (); - OS.memmove (gtkCombo, handle, GtkCombo.sizeof); - int entry = gtkCombo.entry; - OS.gtk_editable_delete_text (entry, 0, -1); + OS.gtk_editable_delete_text (entryHandle, 0, -1); int [] position = new int [1]; byte [] buffer = Converter.wcsToMbcs (null, string); - OS.gtk_editable_insert_text (entry, buffer, buffer.length, position); - OS.gtk_editable_set_position (entry, 0); + OS.gtk_editable_insert_text (entryHandle, buffer, buffer.length, position); + OS.gtk_editable_set_position (entryHandle, 0);*/ } /** @@ -1069,9 +1041,7 @@ public void setTextLimit (int limit) { checkWidget(); if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); this.textLimit = (short) limit; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - OS.gtk_entry_set_max_length (combo.entry, (short) limit); + OS.gtk_entry_set_max_length (entryHandle, (short) limit); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java index e2cec6ea69..30a8563c95 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java @@ -28,7 +28,8 @@ import org.eclipse.swt.graphics.*; * @see Canvas */ public class Composite extends Scrollable { - int topHandle, eventBoxHandle, fixedHandle, radioHandle; + /* boxHandle is temporarily here, until eclipsefixed gets fixed */ + int boxHandle, fixedHandle, radioHandle; Layout layout; /* @@ -71,19 +72,19 @@ public Composite (Composite parent, int style) { super (parent, style); } +/* + * === Handle code begins === + */ void createHandle (int index) { state |= HANDLE | CANVAS; - topHandle = OS.gtk_event_box_new(); - if (topHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - scrolledHandle = OS.gtk_scrolled_window_new(0,0); if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new (); + boxHandle = OS.gtk_event_box_new(); + if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); + + fixedHandle = OS.eclipse_fixed_new(); if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); handle = OS.gtk_drawing_area_new(); @@ -92,11 +93,10 @@ void createHandle (int index) { } void configure() { - _connectParent(); - OS.gtk_container_add(topHandle, scrolledHandle); - _fillBin(scrolledHandle, eventBoxHandle); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put(fixedHandle, handle, (short)0,(short)0); + parent._connectChild(scrolledHandle); + OS.gtk_container_add(scrolledHandle, boxHandle); + OS.gtk_container_add(boxHandle, fixedHandle); + OS.gtk_container_add(fixedHandle, handle); } void setHandleStyle() { @@ -104,87 +104,62 @@ void setHandleStyle() { } void showHandle() { - OS.gtk_widget_realize (topHandle); - OS.gtk_widget_show_now(topHandle); - - OS.gtk_widget_show (scrolledHandle); - - OS.gtk_widget_realize (eventBoxHandle); - OS.gtk_widget_show_now(eventBoxHandle); - - OS.gtk_widget_realize (fixedHandle); - OS.gtk_widget_show_now(fixedHandle); - + OS.gtk_widget_show_now (scrolledHandle); + OS.gtk_widget_show_now (boxHandle); + OS.gtk_widget_show_now (fixedHandle); OS.gtk_widget_realize (handle); OS.gtk_widget_show_now (handle); } -void register () { - super.register (); - if (topHandle != 0) WidgetTable.put (topHandle, this); - if (eventBoxHandle != 0) WidgetTable.put (eventBoxHandle, this); - if (fixedHandle != 0) WidgetTable.put (fixedHandle, this); -} - -void deregister () { - super.deregister (); - if (topHandle != 0) WidgetTable.remove (topHandle); - if (eventBoxHandle != 0) WidgetTable.remove (eventBoxHandle); - if (fixedHandle != 0) WidgetTable.remove (fixedHandle); -} - -int topHandle() { - return topHandle; -} - -int parentingHandle() { - return fixedHandle; -} - -/** - * Answer whether the argument points to an OS widget that is - * implementing the receiver, i.e., one of my own handles - */ +void hookEvents () { + signal_connect_after (handle, "expose_event", SWT.Paint, 3); + int mask = + OS.GDK_POINTER_MOTION_MASK | + OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | + OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | + OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | + OS.GDK_FOCUS_CHANGE_MASK; + OS.gtk_widget_add_events (handle, mask); + signal_connect_after (handle, "motion_notify_event", SWT.MouseMove, 3); + signal_connect_after (handle, "button_press_event", SWT.MouseDown, 3); + signal_connect_after (handle, "button_release_event", SWT.MouseUp, 3); + signal_connect_after (handle, "enter_notify_event", SWT.MouseEnter, 3); + signal_connect_after (handle, "leave_notify_event", SWT.MouseExit, 3); + signal_connect_after (handle, "key_press_event", SWT.KeyDown, 3); + signal_connect_after (handle, "key_release_event", SWT.KeyUp, 3); + signal_connect_after (handle, "focus_in_event", SWT.FocusIn, 3); + signal_connect_after (handle, "focus_out_event", SWT.FocusOut, 3); +} + +int topHandle() { return scrolledHandle; } +int parentingHandle() { return fixedHandle; } boolean isMyHandle(int h) { - if (h==topHandle) return true; - if (h==eventBoxHandle) return true; - if (h==scrolledHandle) return true; - if (h==fixedHandle) return true; - if (h==handle) return true; - if (h==radioHandle) return true; - return false; + if (h==boxHandle) return true; + if (h==fixedHandle) return true; + return super.isMyHandle(h); } - - /* * === GEOMETRY - PHYSICAL === */ public void setBounds (int x, int y, int width, int height) { - Rectangle old_bounds = _getBounds(); - if ( (x != old_bounds.x) || - (y != old_bounds.y) || - (width != old_bounds.width) || - (height != old_bounds.height) ) { - super.setBounds (x, y, width, height); - layout(); - } else checkWidget(); + super.setBounds (x, y, width, height); + layout(); } public void setSize (int width, int height) { super.setSize(width, height); layout(); } - -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize (topHandle(), width,height); - Point clientSize = UtilFuncs.getSize(fixedHandle); - OS.gtk_drawing_area_size(handle, width, height); - UtilFuncs.setSize (handle, clientSize.x, clientSize.y); - return differentExtent; +void _setSize(int width, int height) { + OS.eclipse_fixed_set_size(parent.parentingHandle(), topHandle(), width, height); + /* FIXME */ + if ((style&SWT.V_SCROLL) != 0) width -= 18; width = Math.max(width, 0); + if ((style&SWT.H_SCROLL) != 0) height -= 18; height = Math.max(height, 0); + OS.eclipse_fixed_set_size(fixedHandle, handle, width, height); } public Point computeSize (int wHint, int hHint, boolean changed) { @@ -207,16 +182,6 @@ public Point computeSize (int wHint, int hHint, boolean changed) { return new Point (trim.width, trim.height); } -void initializeTrim() { - /* Temporary implementation - I just measured the scrollbars - * with one particular theme. The fair thing to do is get - * the real dimensions from gtk. - */ - trim = new Trim(); - if ((style&SWT.H_SCROLL)!=0) trim.bottom=18; - if ((style&SWT.V_SCROLL)!=0) trim.right=18; -} - /* * === GEOMETRY - LAYOUT === @@ -266,17 +231,10 @@ public Control [] getTabList () { * </ul> */ public void setLayout (Layout layout) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); this.layout = layout; } -int _gdkWindow() { - int windowHandle = _gdkWindow(handle); - if (windowHandle==0) error(SWT.ERROR_UNSPECIFIED); - return windowHandle; -} - /** * Returns an array containing the receiver's children. * <p> @@ -294,10 +252,6 @@ int _gdkWindow() { */ public Control [] getChildren () { checkWidget(); - return _getChildren(); -} - -Control [] _getChildren () { return _getChildren(parentingHandle()); } @@ -336,19 +290,16 @@ Control _childFromHandle(int h) { } public Rectangle getClientArea () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - - return _getClientArea (); -} - -public Rectangle _getClientArea () { - Point size = _getClientAreaSize (); - return new Rectangle (0, 0, size.x, size.y); -} - -Point _getClientAreaSize () { - return UtilFuncs.getSize(handle); + checkWidget(); + /* We can not measure the actual size of the client area, + * because it may not have propagated down yet. + */ + Point size = _getSize(); + /* FIXME - this code assumes the scrollbars are to the right */ + /* FIXME - I just measured the size on one particular theme. */ + if ((style & SWT.V_SCROLL) != 0) size.x -= 18; + if ((style & SWT.H_SCROLL) != 0) size.y -= 18; + return new Rectangle(0,0, size.x, size.y); } @@ -386,14 +337,13 @@ public void layout () { * </ul> */ public void layout (boolean changed) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (layout == null) return; layout.layout (this, changed); } Point minimumSize () { - Control [] children = _getChildren (); + Control [] children = _getChildren (parentingHandle()); int width = 0, height = 0; for (int i=0; i<children.length; i++) { Rectangle rect = children [i].getBounds (); @@ -402,23 +352,14 @@ Point minimumSize () { } return new Point (width, height); } -int processResize (int int0, int int1, int int2) { - sendEvent (SWT.Resize); - layout(); - return 0; -} int radioGroup() { if (radioHandle==0) _initializeRadioGroup(); return OS.gtk_radio_button_group(radioHandle); } public void redraw () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); -// Point size = _getSize(); -// GtkWidget widget = new GtkWidget(handle); -// _redraw(0, 0, size.x, size.y, true); -OS.gtk_widget_queue_draw(handle); + checkWidget(); + OS.gtk_widget_queue_draw(paintHandle()); } void _initializeRadioGroup() { @@ -429,11 +370,11 @@ void _initializeRadioGroup() { * Adopt the widget h as our child. */ void _connectChild (int h) { - OS.gtk_fixed_put (parentingHandle(), h, (short)0, (short)0); + OS.gtk_container_add (parentingHandle(), h); } void releaseChildren () { - Control [] children = _getChildren (); + Control [] children = _getChildren (parentingHandle()); for (int i=0; i<children.length; i++) { Control child = children [i]; if (child != null && !child.isDisposed ()) { @@ -449,7 +390,7 @@ void releaseWidget () { } void releaseHandle () { super.releaseHandle (); - topHandle = eventBoxHandle = fixedHandle = radioHandle = 0; + boxHandle = radioHandle = 0; } int processMouseDown (int callData, int arg1, int int2) { @@ -474,9 +415,8 @@ int processFocusOut(int int0, int int1, int int2) { } public boolean setFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - Control [] children = _getChildren (); + checkWidget(); + Control [] children = _getChildren (parentingHandle()); for (int i=0; i<children.length; i++) { Control child = children [i]; if (child.getVisible () && child.setFocus ()) return true; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 14e3082a6f..6a7b34f3ea 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -10,9 +10,6 @@ import org.eclipse.swt.internal.Converter; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.events.*; -/* Start ACCESSIBILITY */ -import org.eclipse.swt.accessibility.*; -/* End ACCESSIBILITY */ /** * Control is the abstract superclass of all windowed user interface classes. @@ -35,11 +32,6 @@ public abstract class Control extends Widget implements Drawable { Menu menu; String toolTipText; Object layoutData; - static private final int aux_info_quark = OS.g_quark_from_string (Converter.wcsToMbcs (null, "gtk-aux-info", true)); -/* Start ACCESSIBILITY */ - Accessible accessible; -/* End ACCESSIBILITY */ - /* * === CONSTRUCTORS === @@ -82,6 +74,10 @@ public Control (Composite parent, int style) { createWidget (0); } +/* + * === HANDLE CODE === + */ + abstract void createHandle(int index); int eventHandle () { @@ -116,39 +112,36 @@ int eventHandle () { * </ul> */ void hookEvents () { - signal_connect (handle, "expose_event", SWT.Paint, 3); + signal_connect_after (handle, "expose_event", SWT.Paint, 3); int mask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK; - int eventHandle = eventHandle (); - if (!OS.GTK_WIDGET_NO_WINDOW (eventHandle)) { - OS.gtk_widget_add_events (eventHandle, mask); + if (!OS.GTK_WIDGET_NO_WINDOW (handle)) { + OS.gtk_widget_add_events (handle, mask); } - signal_connect_after (eventHandle, "motion_notify_event", SWT.MouseMove, 3); - signal_connect_after (eventHandle, "button_press_event", SWT.MouseDown, 3); - signal_connect_after (eventHandle, "button_release_event", SWT.MouseUp, 3); - signal_connect_after (eventHandle, "enter_notify_event", SWT.MouseEnter, 3); - signal_connect_after (eventHandle, "leave_notify_event", SWT.MouseExit, 3); - signal_connect_after (eventHandle, "key_press_event", SWT.KeyDown, 3); - signal_connect_after (eventHandle, "key_release_event", SWT.KeyUp, 3); - signal_connect_after (eventHandle, "focus_in_event", SWT.FocusIn, 3); - signal_connect_after (eventHandle, "focus_out_event", SWT.FocusOut, 3); + signal_connect_after (handle, "motion_notify_event", SWT.MouseMove, 3); + signal_connect_after (handle, "button_press_event", SWT.MouseDown, 3); + signal_connect_after (handle, "button_release_event", SWT.MouseUp, 3); + signal_connect_after (handle, "enter_notify_event", SWT.MouseEnter, 3); + signal_connect_after (handle, "leave_notify_event", SWT.MouseExit, 3); + signal_connect_after (handle, "key_press_event", SWT.KeyDown, 3); + signal_connect_after (handle, "key_release_event", SWT.KeyUp, 3); + signal_connect_after (handle, "focus_in_event", SWT.FocusIn, 3); + signal_connect_after (handle, "focus_out_event", SWT.FocusOut, 3); } abstract void setHandleStyle (); -void setInitialSize() { UtilFuncs.setZeroSize(topHandle()); } +void setInitialSize() { _setSize(5,5); } void configure () { - // Do NOT directly use gtk_fixed_put in configure(), - // because not all composites have GtkFixed as their - // parenting (bottom) handle. - _connectParent(); -} -void _connectParent() { + // Do NOT directly use fixed_put in configure(): + // surprisingly, not all composites have Fixed as their + // parenting (bottom) handle. Should investigate further. parent._connectChild(topHandle()); } + /** * Every Control must implement this to map the gtk widgets, * and also realize those that have to be realized - this means @@ -160,36 +153,25 @@ void _connectParent() { * An exception to this is the Shell, which we do NOT realize * at this point. */ -abstract void showHandle(); - -int topHandle() { - return handle; -} - -int paintHandle() { - return handle; +void showHandle() { + OS.gtk_widget_show (handle); + OS.gtk_widget_realize (handle); } +/** + * This is the handle by which our parent holds us + */ +int topHandle() { return handle; } +/** + * This is where we draw. Every widget must guarantee + * that its paint handle has a Gdk window associated with it. + */ +public int paintHandle() { return handle; } /* REALLY BROKEN, PENDING PANGO */ +boolean isMyHandle(int h) { return h==handle; } /* * === GEOMETRY === */ -int computeHandle () { - return handle; -} - -Point _computeSize (int wHint, int hHint, boolean changed) { - int handle = computeHandle (); - int aux_info = OS.gtk_object_get_data_by_id (handle, aux_info_quark); - OS.gtk_object_set_data_by_id (handle, aux_info_quark, 0); - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (handle, requisition); - OS.gtk_object_set_data_by_id (handle, aux_info_quark, aux_info); - int width = wHint == SWT.DEFAULT ? requisition.width : wHint; - int height = hHint == SWT.DEFAULT ? requisition.height : hHint; - return new Point (width, height); -} - /** * Returns the preferred size of the receiver. * <p> @@ -247,33 +229,16 @@ public Point computeSize (int wHint, int hHint) { */ public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget(); - return _computeSize (wHint, hHint, changed); + return computeNativeSize (handle, wHint, hHint, changed); } -/* Start ACCESSIBILITY */ -/** - * 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 addAccessibleListener - * @see addAccessibleControlListener - */ -public Accessible getAccessible () { - checkWidget (); - if (accessible == null) { - accessible = Accessible.internal_new_Accessible (this); - } - return accessible; +Point computeNativeSize (int h, int wHint, int hHint, boolean changed) { + GtkRequisition requisition = new GtkRequisition (); + OS.gtk_widget_size_request (h, requisition); + int width = wHint == SWT.DEFAULT ? requisition.width : wHint; + int height = hHint == SWT.DEFAULT ? requisition.height : hHint; + return new Point (width, height); } -/* End ACCESSIBILITY */ /** * Returns a rectangle describing the receiver's size and location @@ -288,18 +253,10 @@ public Accessible getAccessible () { */ public Rectangle getBounds () { checkWidget(); - return _getBounds(); -} - -/** - * The actual implementation for getBounds(). - * Concrete controls implement their means to answer the location - * and size by overriding _getLocation() and _getSize(). - */ -final Rectangle _getBounds() { Point location = _getLocation(); Point size = _getSize(); return new Rectangle(location.x, location.y, size.x, size.y); + } /** @@ -348,10 +305,12 @@ public void setBounds (Rectangle rect) { */ public void setBounds (int x, int y, int width, int height) { checkWidget(); - boolean differentOrigin = _setLocation(x,y); - boolean differentExtent = _setSize (width,height); - if (differentOrigin) sendEvent (SWT.Move); - if (differentExtent) sendEvent (SWT.Resize); + Point old_location = _getLocation(); + Point old_size = _getSize(); + _setLocation (x, y); + _setSize (width, height); + if ((x!=old_location.x) || (y!=old_location.y)) sendEvent (SWT.Move); + if ((width!=old_size.x) || (height!=old_size.y)) sendEvent (SWT.Resize); } /** @@ -369,9 +328,10 @@ public Point getLocation () { checkWidget(); return _getLocation(); } - Point _getLocation () { - return UtilFuncs.getLocation(topHandle()); + int[] loc = new int[2]; + OS.eclipse_fixed_get_location(parent.parentingHandle(), topHandle(), loc); + return new Point(loc[0], loc[1]); } /** @@ -406,15 +366,13 @@ public void setLocation (Point location) { */ public void setLocation(int x, int y) { checkWidget(); - if (_setLocation(x,y)) sendEvent(SWT.Move); + Point old_location = _getLocation(); + if ((x==old_location.x) && (y==old_location.y)) return; + _setLocation(x,y); + sendEvent(SWT.Move); } - -boolean _setLocation(int x, int y) { - Point old_loc = _getLocation(); - if ( (x != old_loc.x) || (y != old_loc.y) ) { - UtilFuncs.setLocation(parent.parentingHandle(), topHandle(), x,y); - return true; - } else return false; +void _setLocation(int x, int y) { + OS.eclipse_fixed_set_location(parent.parentingHandle(), topHandle(), x,y); } /** @@ -435,7 +393,9 @@ public Point getSize () { return _getSize(); } Point _getSize() { - return UtilFuncs.getSize(topHandle()); + int[] sz = new int[2]; + OS.eclipse_fixed_get_size(parent.parentingHandle(), topHandle(), sz); + return new Point(sz[0], sz[1]); } /** @@ -480,17 +440,15 @@ public void setSize (Point size) { */ public void setSize (int width, int height) { checkWidget(); - // Even though GTK+ will not let any widget be smaller - // than 3@3, we don't care about it here, as this kind - // of platform weirdness is handled in UtilFuncs. width = Math.max(width, 0); height = Math.max(height, 0); - if (_setSize(width, height)) sendEvent(SWT.Resize); -} -boolean _setSize(int width, int height) { Point old_size = _getSize(); - if ( (width==old_size.x) && (height==old_size.y) ) return false; - return UtilFuncs.setSize(topHandle(), width, height); + if ( (width==old_size.x) && (height==old_size.y) ) return; + _setSize(width, height); + sendEvent(SWT.Resize); +} +void _setSize(int width, int height) { + OS.eclipse_fixed_set_size(parent.parentingHandle(), topHandle(), width, height); } /** @@ -512,10 +470,9 @@ boolean _setSize(int width, int height) { */ public void moveAbove (Control control) { checkWidget(); - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle(), GtkWidget.sizeof); - int topGdkWindow = widget.window; - if (topGdkWindow!=0) OS.gdk_window_raise (topGdkWindow); + int siblingHandle = 0; + if (control != null) siblingHandle = control.topHandle(); + OS.eclipse_fixed_move_above(parent.parentingHandle(), topHandle(), siblingHandle); } /** @@ -537,10 +494,9 @@ public void moveAbove (Control control) { */ public void moveBelow (Control control) { checkWidget(); - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle(), GtkWidget.sizeof); - int topGdkWindow = widget.window; - if (topGdkWindow!=0) OS.gdk_window_lower (topGdkWindow); + int siblingHandle = 0; + if (control != null) siblingHandle = control.topHandle(); + OS.eclipse_fixed_move_below(parent.parentingHandle(), topHandle(), siblingHandle); } /** @@ -579,7 +535,6 @@ public void pack () { * @see #computeSize */ public void pack (boolean changed) { - checkWidget(); setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed)); } @@ -615,11 +570,12 @@ public void setLayoutData (Object layoutData) { */ public Point toControl (Point point) { checkWidget(); - int[] x = new int[1], y = new int[1]; +/* int[] x = new int[1], y = new int[1]; OS.gdk_window_get_origin(_gdkWindow(), x,y); int ctlX = point.x - x[0]; - int ctlY = point.y - y[0]; - return new Point (ctlX, ctlY); + int ctlY = point.y - y[0];*/ + /* FIXME */ + return new Point (0, 0); } /** * Returns a point which is the result of converting the @@ -637,11 +593,14 @@ public Point toControl (Point point) { * </ul> */ public Point toDisplay (Point point) { - checkWidget(); + checkWidget();/* int[] x = new int[1], y = new int[1]; OS.gdk_window_get_origin(_gdkWindow(), x,y); - return new Point (x[0]+point.x, y[0]+point.y); + return new Point (x[0]+point.x, y[0]+point.y);*/ + /* FIXME */ + return new Point (0,0); } + // === End of GEOMETRY Category === @@ -908,8 +867,7 @@ public void addTraverseListener (TraverseListener listener) { * @see #addControlListener */ public void removeControlListener (ControlListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Move, listener); @@ -933,8 +891,7 @@ public void removeControlListener (ControlListener listener) { * @see #addFocusListener */ public void removeFocusListener(FocusListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.FocusIn, listener); @@ -958,8 +915,7 @@ public void removeFocusListener(FocusListener listener) { * @see #addHelpListener */ public void removeHelpListener (HelpListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Help, listener); @@ -982,8 +938,7 @@ public void removeHelpListener (HelpListener listener) { * @see #addKeyListener */ public void removeKeyListener(KeyListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.KeyUp, listener); @@ -1007,8 +962,7 @@ public void removeKeyListener(KeyListener listener) { * @see #addMouseListener */ public void removeMouseListener (MouseListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.MouseDown, listener); @@ -1033,8 +987,7 @@ public void removeMouseListener (MouseListener listener) { * @see #addMouseMoveListener */ public void removeMouseMoveListener(MouseMoveListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.MouseMove, listener); @@ -1058,8 +1011,7 @@ public void removeMouseMoveListener(MouseMoveListener listener) { * @see #addMouseTrackListener */ public void removeMouseTrackListener(MouseTrackListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.MouseEnter, listener); @@ -1085,8 +1037,7 @@ public void removeMouseTrackListener(MouseTrackListener listener) { * @see #addPaintListener */ public void removePaintListener(PaintListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook(SWT.Paint, listener); @@ -1117,27 +1068,6 @@ public void removeTraverseListener(TraverseListener listener) { } -/* - * Return (GTKWIDGET)h->window. - */ -final int _gdkWindow(int h) { - /* Temporary code. - * This check is not necessary as the (internal) callers - * always make sure h!=0. - */ - if (h==0) error(SWT.ERROR_CANNOT_BE_ZERO); - - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, h, GtkWidget.sizeof); - return widget.window; -} - -int _gdkWindow() { - int windowHandle = _gdkWindow(handle); - if (windowHandle==0) error(SWT.ERROR_NO_HANDLES); - return windowHandle; -} - /** * Forces the receiver to have the <em>keyboard focus</em>, causing * all keyboard events to be delivered to it. @@ -1152,8 +1082,7 @@ int _gdkWindow() { * @see #setFocus */ public boolean forceFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); OS.gtk_widget_grab_focus (handle); return true; } @@ -1181,8 +1110,7 @@ GdkColor _getBackgroundGdkColor() { int h = paintHandle(); int hStyle = OS.gtk_widget_get_style (handle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); + GtkStyle style = new GtkStyle (hStyle); GdkColor color = new GdkColor (); color.pixel = style.bg0_pixel; color.red = style.bg0_red; @@ -1202,8 +1130,7 @@ GdkColor _getBackgroundGdkColor() { * </ul> */ public int getBorderWidth () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return (style & SWT.BORDER) == 0 ? 0 : 1; } @@ -1238,8 +1165,7 @@ public Display getDisplay () { */ public boolean getEnabled () { checkWidget (); - int topHandle = topHandle (); - return OS.GTK_WIDGET_SENSITIVE (topHandle); + return OS.GTK_WIDGET_SENSITIVE (handle); } /** @@ -1286,8 +1212,7 @@ GdkColor _getForegroundGdkColor() { int h = paintHandle(); int hStyle = OS.gtk_widget_get_style (handle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); + GtkStyle style = new GtkStyle (hStyle); GdkColor color = new GdkColor (); color.pixel = style.fg0_pixel; color.red = style.fg0_red; @@ -1307,8 +1232,7 @@ GdkColor _getForegroundGdkColor() { * </ul> */ public Object getLayoutData () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return layoutData; } @@ -1328,8 +1252,7 @@ public Object getLayoutData () { * </ul> */ public Menu getMenu () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return menu; } /** @@ -1345,8 +1268,7 @@ public Menu getMenu () { * </ul> */ public Composite getParent () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return parent; } @@ -1366,8 +1288,7 @@ public Composite getParent () { * @see #getParent */ public Shell getShell() { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return _getShell(); } Shell _getShell() { @@ -1386,8 +1307,7 @@ Shell _getShell() { * </ul> */ public String getToolTipText () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return toolTipText; } /** @@ -1409,13 +1329,7 @@ public String getToolTipText () { */ public boolean getVisible () { checkWidget(); - return _getVisible(); -} -boolean _getVisible() { - return _getVisible(topHandle()); -} -boolean _getVisible(int h) { - return (OS.GTK_WIDGET_FLAGS(h) & OS.GTK_VISIBLE) != 0; + return OS.GTK_WIDGET_VISIBLE(topHandle()); } /** @@ -1438,17 +1352,15 @@ public int internal_new_GC (GCData data) { if (paintHandle() == 0) error(SWT.ERROR_UNSPECIFIED); // Create the GC with default values for this control - GtkWidget w = new GtkWidget(); - OS.memmove (w, paintHandle(), GtkWidget.sizeof); - if (w.window == 0) error(SWT.ERROR_UNSPECIFIED); - int gc = OS.gdk_gc_new(w.window); + int window = OS.GTK_WIDGET_WINDOW(paintHandle()); + int gc = OS.gdk_gc_new(window); OS.gdk_gc_set_font(gc, _getFontHandle()); OS.gdk_gc_set_background(gc, _getBackgroundGdkColor()); OS.gdk_gc_set_foreground(gc, _getForegroundGdkColor()); - data.drawable = w.window; + data.drawable = window; return gc; } @@ -1503,8 +1415,7 @@ public boolean isReparentable () { */ public boolean isEnabled () { checkWidget (); - int topHandle = topHandle (); - return OS.GTK_WIDGET_IS_SENSITIVE (topHandle); + return OS.GTK_WIDGET_IS_SENSITIVE (handle); } /** @@ -1519,10 +1430,10 @@ public boolean isEnabled () { * </ul> */ public boolean isFocusControl () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return (OS.GTK_WIDGET_FLAGS(handle)&OS.GTK_HAS_FOCUS)!=0; + checkWidget(); + return OS.GTK_WIDGET_HAS_FOCUS(handle); } + /** * Returns <code>true</code> if the receiver is visible, and * <code>false</code> otherwise. @@ -1541,42 +1452,45 @@ public boolean isFocusControl () { * </ul> */ public boolean isVisible () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); boolean result = getVisible (); - if (parent != null) - result = result && parent.isVisible(); + if (parent != null) result = result && parent.isVisible(); return result; } + Decorations menuShell () { return parent.menuShell (); } int processKeyDown (int callData, int arg1, int int2) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, callData, GdkEventKey.sizeof); - boolean accelResult = OS.gtk_accel_groups_activate(_getShell().topHandle, gdkEvent.keyval, gdkEvent.state); - if (!accelResult) sendKeyEvent (SWT.KeyDown, gdkEvent); + int keyval = OS.gdk_event_key_get_keyval(callData); + int[] pMods = new int[1]; + OS.gdk_event_get_state(callData, pMods); + boolean accelResult = OS.gtk_accel_groups_activate(_getShell().topHandle(), + keyval, + pMods[0]); + if (!accelResult) sendKeyEvent (SWT.KeyDown, callData); return 1; } int processKeyUp (int callData, int arg1, int int2) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, callData, GdkEventKey.sizeof); - sendKeyEvent (SWT.KeyUp, gdkEvent); + sendKeyEvent (SWT.KeyUp, callData); return 1; } int processMouseDown (int callData, int arg1, int int2) { OS.gtk_widget_grab_focus(handle); - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); int eventType = SWT.MouseDown; - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) eventType = SWT.MouseDoubleClick; - sendMouseEvent (eventType, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); - if (gdkEvent.button == 3 && menu != null) { - menu.setVisible (true); - } + if (OS.GDK_EVENT_TYPE(callData) == OS.GDK_2BUTTON_PRESS) eventType = SWT.MouseDoubleClick; + int[] pMod = new int[1]; + OS.gdk_event_get_state(callData, pMod); + int time = OS.gdk_event_get_time(callData); + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int button = OS.gdk_event_button_get_button(callData); + sendMouseEvent (eventType, button, pMod[0], time, (int)(px[0]), (int)(py[0])); + if (button == 3 && menu != null) menu.setVisible (true); return 1; } @@ -1592,24 +1506,29 @@ int processMouseExit (int arg0, int arg1, int int2) { } int processMouseUp (int callData, int arg1, int int2) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - sendMouseEvent (SWT.MouseUp, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); + int[] pMod = new int[1]; + OS.gdk_event_get_state(callData, pMod); + int time = OS.gdk_event_get_time(callData); + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int button = OS.gdk_event_button_get_button(callData); + sendMouseEvent (SWT.MouseUp, button, pMod[0], time, (int)(px[0]), (int)(py[0])); return 1; } int processMouseMove (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - Point where = _gdkWindowGetPointer(); - sendMouseEvent (SWT.MouseMove, 0, gdkEvent.state, gdkEvent.time, where.x, where.y); - return 1; -} -Point _gdkWindowGetPointer() { + /* + GdkEvent gdkEvent = new GdkEvent (callData); int[] px = new int[1], py = new int[1]; - OS.gdk_window_get_pointer(_gdkWindow(), px, py, 0); - return new Point(px[0], py[0]); + OS.gdk_window_get_pointer(_gdkWindow(), px, py, 0); + int time = OS.gdk_event_get_time(callData); + int[] pMods = new int[1]; + OS.gdk_event_get_state(callData, pMods); + sendMouseEvent (SWT.MouseMove, 0, pMods[0], time, px[0], py[0]);*/ + return 1; } + int processFocusIn(int int0, int int1, int int2) { postEvent(SWT.FocusIn); return 0; @@ -1622,8 +1541,7 @@ int processFocusOut(int int0, int int1, int int2) { int processPaint (int callData, int int2, int int3) { if (!hooks (SWT.Paint)) return 1; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); + GdkEventExpose gdkEvent = new GdkEventExpose (callData); Event event = new Event (); event.count = gdkEvent.count; event.x = gdkEvent.x; event.y = gdkEvent.y; @@ -1653,11 +1571,9 @@ int processPaint (int callData, int int2, int int3) { * @see #update */ public void redraw () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); Point size = _getSize(); _redraw(0, 0, size.x, size.y, true); -//OS.gtk_widget_queue_draw(handle); } /** * Causes the rectangular area of the receiver specified by @@ -1683,11 +1599,12 @@ public void redraw () { * @see #update */ public void redraw (int x, int y, int width, int height, boolean all) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); _redraw(x, y, width, height, all); } protected void _redraw(int x, int y, int width, int height, boolean all) { + /* FIXME */ + /* OS.gdk_window_clear_area_e (_gdkWindow(), x, y, width, height); GdkRectangle rect = new GdkRectangle(); @@ -1695,10 +1612,8 @@ rect.x = (short)x; rect.y = (short)y; rect.width = (short)width; rect.height =(short) height; -//OS.gtk_widget_draw(handle, rect); -OS.gtk_widget_queue_draw(handle); +OS.gtk_widget_queue_draw(handle);*/ -// OS.gtk_widget_queue_draw_area (handle, x, y, width, height); } void releaseWidget () { @@ -1708,46 +1623,53 @@ void releaseWidget () { menu = null; layoutData = null; } -void sendKeyEvent (int type, GdkEventKey gdkEvent) { - /* Look up the keysym and character(s) */ - int size = gdkEvent.length; - if (gdkEvent.keyval == 0 && size == 0) return; - - /* If there is no composed string input by keypress, only send the keyvalue */ - if (size == 0 ) { - Event event = new Event (); - event.time = gdkEvent.time; -// event.character = (char) 0; //no character sent - event.keyCode = Display.translateKey (gdkEvent.keyval); + +void sendKeyEvent (int type, int pEventKey) { + Event event = new Event(); + event.time = OS.gdk_event_get_time(pEventKey); + + int size = OS.gdk_event_key_get_length(pEventKey); + if (size==0) { /* No composed string - send the keyvalue */ + int keyval = OS.gdk_event_key_get_keyval(pEventKey) ; + if (keyval==0) return; + event.keyCode = Display.translateKey (keyval); event.character = (char) event.keyCode; //no character sent - if ((gdkEvent.state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((gdkEvent.state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((gdkEvent.state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((gdkEvent.state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; + int[] pModifier = new int[1]; + OS.gdk_event_get_state(pEventKey, pModifier); + int state = pModifier[0]; + if ((state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; + if ((state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; + if ((state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; + if ((state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; + if ((state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; + if ((state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; postEvent (type, event); + return; } - else { - byte [] buffer = new byte [size]; - OS.memmove (buffer, gdkEvent.string, size); - /* Convert from MBCS to UNICODE and send the event */ - char [] result = Converter.mbcsToWcs (null, buffer); - for (int i=0; i<result.length; i++) { - Event event = new Event (); - event.time = gdkEvent.time; - event.character = result [i]; - event.keyCode = result [i]; //0; //no keyCode sent - if ((gdkEvent.state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((gdkEvent.state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((gdkEvent.state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((gdkEvent.state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; - postEvent (type, event); - } - } + + if (size==1) { + int keyval = OS.gdk_event_key_get_keyval(pEventKey) ; + if (keyval==0) return; + event.keyCode = keyval; + event.character = (char) event.keyCode; //no character sent + int[] pModifier = new int[1]; + OS.gdk_event_get_state(pEventKey, pModifier); + int state = pModifier[0]; + if ((state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; + if ((state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; + if ((state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; + if ((state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; + if ((state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; + if ((state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; + postEvent (type, event); + return; + } + + /* Multi-byte key */ + /* The implementation in the GTK1.2 stream, is not correct here. */ + error(SWT.ERROR_NOT_IMPLEMENTED); } + void sendMouseEvent (int type, int button, int mask, int time, int x, int y) { Event event = new Event (); event.time = time; @@ -1784,11 +1706,9 @@ public void setBackground (Color color) { int hStyle = OS.gtk_widget_get_style (handle); boolean makeCopy = hStyle == hDefaultStyle; hStyle = OS.gtk_style_copy (makeCopy ? hDefaultStyle : hStyle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); + GtkStyle style = new GtkStyle (hStyle); if (color == null) { - GtkStyle defaultStyle = new GtkStyle (); - OS.memmove (defaultStyle, hDefaultStyle, GtkStyle.sizeof); + GtkStyle defaultStyle = new GtkStyle (hDefaultStyle); style.bg0_pixel = defaultStyle.bg0_pixel; style.bg0_red = defaultStyle.bg0_red; style.bg0_green = defaultStyle.bg0_green; @@ -1831,8 +1751,10 @@ public void setBackground (Color color) { style.bg4_green = color.handle.green; style.bg4_blue = color.handle.blue; } - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); + /* FIXME */ + /* I believe there is now something like set_color? */ + /*OS.memmove (hStyle, style, GtkStyle.sizeof); + OS.gtk_widget_set_style (handle, hStyle);*/ if (makeCopy) { OS.gtk_style_unref (hStyle); } @@ -1851,8 +1773,8 @@ public void setBackground (Color color) { * </ul> */ public void setCapture (boolean capture) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); + /* FIXME !!!!! */ /* if (capture) { OS.gtk_widget_grab_focus (handle); @@ -1882,9 +1804,7 @@ public void setCapture (boolean capture) { */ public void setCursor (Cursor cursor) { checkWidget(); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, paintHandle(), GtkWidget.sizeof); - int window = widget.window; + int window = OS.GTK_WIDGET_WINDOW(paintHandle()); if (window == 0) return; int hCursor = 0; if (cursor != null) hCursor = cursor.handle; @@ -1904,8 +1824,7 @@ public void setCursor (Cursor cursor) { * </ul> */ public void setEnabled (boolean enabled) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); int topHandle = topHandle (); OS.gtk_widget_set_sensitive (topHandle, enabled); /* @@ -1932,8 +1851,7 @@ public void setEnabled (boolean enabled) { * @see #forceFocus */ public boolean setFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return forceFocus (); } @@ -1964,18 +1882,13 @@ public void setFont (Font font) { } /* The font argument is null, revert to default font */ - GtkStyle style = new GtkStyle(); + /* FIXME */ +/* GtkStyle style = new GtkStyle(); OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); int fontHandle = OS.gdk_font_ref(style.font); if (fontHandle==0) error(SWT.ERROR_NO_HANDLES); - _setFontHandle(fontHandle); + _setFontHandle(fontHandle);*/ } - -/** - * Actually set the receiver's font in the OS. - * Concrete subclasses may override this method to operate - * on a different handle. - */ void _setFontHandle (int f) { UtilFuncs.setFont(handle, f); } @@ -1996,16 +1909,13 @@ void _setFontHandle (int f) { * </ul> */ public void setForeground (Color color) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); int hStyle = OS.gtk_widget_get_style (handle); hStyle = OS.gtk_style_copy (hStyle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); + GtkStyle style = new GtkStyle (hStyle); if (color == null) { int hDefaultStyle = OS.gtk_widget_get_default_style (); - GtkStyle defaultStyle = new GtkStyle (); - OS.memmove (defaultStyle, hDefaultStyle, GtkStyle.sizeof); + GtkStyle defaultStyle = new GtkStyle (hDefaultStyle); style.fg0_pixel = defaultStyle.fg0_pixel; style.fg0_red = defaultStyle.fg0_red; style.fg0_green = defaultStyle.fg0_green; @@ -2048,8 +1958,10 @@ public void setForeground (Color color) { style.fg4_green = color.handle.green; style.fg4_blue = color.handle.blue; } - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); + /* FIXME */ + /* I believe there is now something like set_color? */ + /*OS.memmove (hStyle, style, GtkStyle.sizeof); + OS.gtk_widget_set_style (handle, hStyle);*/ } /** @@ -2073,8 +1985,7 @@ public void setForeground (Color color) { * </ul> */ public void setMenu (Menu menu) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (menu != null) { if ((menu.style & SWT.POP_UP) == 0) { error (SWT.ERROR_MENU_NOT_POP_UP); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java index 1df146eab7..ab475d0904 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java @@ -344,9 +344,8 @@ public void setImage (Image image) { pixmap = image.pixmap;
mask = image.mask;
}
- GtkWidget widget = new GtkWidget ();
- OS.memmove(widget, topHandle(), GtkWidget.sizeof);
- OS.gdk_window_set_icon (widget.window, 0, pixmap, mask);
+ int window = OS.GTK_WIDGET_WINDOW(topHandle());
+ OS.gdk_window_set_icon (window, 0, pixmap, mask);
}
/** * Sets the maximized state of the receiver. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index af330a3f7e..dacd5b361f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -107,11 +107,16 @@ public class Display extends Device { Caret currentCaret; Callback caretCallback; int caretID, caretProc; + + Font systemFont; + int textHighlightThickness = 1; /* for emulated widgets */ /* Colors */ Color NORMAL_fg, NORMAL_bg, NORMAL_dark, NORMAL_mid, NORMAL_light, NORMAL_text, NORMAL_base; - Color SELECTED_bg, SELECTED_dark, SELECTED_light, SELECTED_text, SELECTED_base; - Color INSENSITIVE_fg, INSENSITIVE_bg, INSENSITIVE_dark, INSENSITIVE_mid, INSENSITIVE_light, INSENSITIVE_text; + Color ACTIVE_fg, ACTIVE_bg, ACTIVE_dark, ACTIVE_mid, ACTIVE_light, ACTIVE_text, ACTIVE_base; + Color PRELIGHT_fg, PRELIGHT_bg, PRELIGHT_dark, PRELIGHT_mid, PRELIGHT_light, PRELIGHT_text, PRELIGHT_base; + Color SELECTED_fg, SELECTED_bg, SELECTED_dark, SELECTED_mid, SELECTED_light, SELECTED_text, SELECTED_base; + Color INSENSITIVE_fg, INSENSITIVE_bg, INSENSITIVE_dark, INSENSITIVE_mid, INSENSITIVE_light, INSENSITIVE_text, INSENSITIVE_base; /* Key Mappings */ static final int [] [] KeyTable = { @@ -312,18 +317,14 @@ protected void create (DeviceData data) { } synchronized void createDisplay (DeviceData data) { + OS.gtk_set_locale(); if (!OS.gtk_init_check (new int [] {0}, null)) { - /* - * This code is intentionally commented. - */ -// disposed = true; -// SWT.error (SWT.ERROR_DEVICE_DISPOSED); + SWT.error (SWT.ERROR_DEVICE_DISPOSED); return; } OS.gdk_rgb_init (); - int ptr = OS.gtk_check_version (1, 2, 8); + int ptr = OS.gtk_check_version (2, 0, 0); if (ptr != 0) { - System.out.println ("***WARNING: SWT requires GTK version 1.2.8 or greater"); int length = OS.strlen (ptr); byte [] buffer = new byte [length]; OS.memmove (buffer, ptr, length); @@ -511,11 +512,9 @@ Control findControl(int h) { Widget w = findWidget(h); if (w==null) return null; if (w instanceof Control) return (Control)w; - // w is something like an Item. Go for the parent - - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, h, GtkWidget.sizeof); - return findControl(widget.parent); + + /* w is something like an Item. Go for the parent */ + return findControl(OS.GTK_WIDGET_PARENT(h)); } /** @@ -595,6 +594,7 @@ public Object getData () { checkDevice (); return data; } + /** * Returns a point whose x coordinate is the horizontal * dots per inch of the display, and whose y coordinate @@ -608,9 +608,9 @@ public Object getData () { */ public Point getDPI () { checkDevice (); + /* Apparently, SWT believes pixels are always square */ int widthMM = OS.gdk_screen_width_mm (); int width = OS.gdk_screen_width (); - // compute round(25.4 * width / widthMM) int dpi = Compatibility.round(254 * width, widthMM * 10); return new Point (dpi, dpi); } @@ -670,8 +670,7 @@ public Control getFocusControl () { public int getDepth () { checkDevice (); - GdkVisual visual = new GdkVisual (); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); + GdkVisual visual = new GdkVisual (OS.gdk_visual_get_system()); return visual.depth; } @@ -785,139 +784,116 @@ public Color getSystemColor (int id) { return super.getSystemColor (id); } -void initializeSystemColors() { +final void initializeSystemColors() { /* Get the theme colors */ - GtkStyle defaultStyle = new GtkStyle(); - OS.memmove (defaultStyle, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); + GtkStyle defaultStyle = new GtkStyle(OS.gtk_widget_get_default_style()); GdkColor gdk_NORMAL_dark = new GdkColor(); gdk_NORMAL_dark.pixel = defaultStyle.dark0_pixel; gdk_NORMAL_dark.red = defaultStyle.dark0_red; gdk_NORMAL_dark.green = defaultStyle.dark0_green; gdk_NORMAL_dark.blue = defaultStyle.dark0_blue; - NORMAL_dark = Color.gtk_new_system(gdk_NORMAL_dark); + NORMAL_dark = Color.gtk_new(gdk_NORMAL_dark); GdkColor gdk_NORMAL_mid = new GdkColor(); gdk_NORMAL_mid.pixel = defaultStyle.mid0_pixel; gdk_NORMAL_mid.red = defaultStyle.mid0_red; gdk_NORMAL_mid.green = defaultStyle.mid0_green; gdk_NORMAL_mid.blue = defaultStyle.mid0_blue; - NORMAL_mid = Color.gtk_new_system(gdk_NORMAL_mid); + NORMAL_mid = Color.gtk_new(gdk_NORMAL_mid); GdkColor gdk_NORMAL_light = new GdkColor(); gdk_NORMAL_light.pixel = defaultStyle.light0_pixel; gdk_NORMAL_light.red = defaultStyle.light0_red; gdk_NORMAL_light.green = defaultStyle.light0_green; gdk_NORMAL_light.blue = defaultStyle.light0_blue; - NORMAL_light = Color.gtk_new_system(gdk_NORMAL_light); + NORMAL_light = Color.gtk_new(gdk_NORMAL_light); GdkColor gdk_NORMAL_fg = new GdkColor(); gdk_NORMAL_fg.pixel = defaultStyle.fg0_pixel; gdk_NORMAL_fg.red = defaultStyle.fg0_red; gdk_NORMAL_fg.green = defaultStyle.fg0_green; gdk_NORMAL_fg.blue = defaultStyle.fg0_blue; - NORMAL_fg = Color.gtk_new_system(gdk_NORMAL_fg); + NORMAL_fg = Color.gtk_new(gdk_NORMAL_fg); GdkColor gdk_NORMAL_bg = new GdkColor(); gdk_NORMAL_bg.pixel = defaultStyle.bg0_pixel; gdk_NORMAL_bg.red = defaultStyle.bg0_red; gdk_NORMAL_bg.green = defaultStyle.bg0_green; gdk_NORMAL_bg.blue = defaultStyle.bg0_blue; - NORMAL_bg = Color.gtk_new_system(gdk_NORMAL_bg); + NORMAL_bg = Color.gtk_new(gdk_NORMAL_bg); GdkColor gdk_NORMAL_text = new GdkColor(); gdk_NORMAL_text.pixel = defaultStyle.text0_pixel; gdk_NORMAL_text.red = defaultStyle.text0_red; gdk_NORMAL_text.green = defaultStyle.text0_green; gdk_NORMAL_text.blue = defaultStyle.text0_blue; - NORMAL_text = Color.gtk_new_system(gdk_NORMAL_text); + NORMAL_text = Color.gtk_new(gdk_NORMAL_text); GdkColor gdk_NORMAL_base = new GdkColor(); gdk_NORMAL_base.pixel = defaultStyle.base0_pixel; gdk_NORMAL_base.red = defaultStyle.base0_red; gdk_NORMAL_base.green = defaultStyle.base0_green; gdk_NORMAL_base.blue = defaultStyle.base0_blue; - NORMAL_base = Color.gtk_new_system(gdk_NORMAL_base); + NORMAL_base = Color.gtk_new(gdk_NORMAL_base); GdkColor gdk_SELECTED_text = new GdkColor(); gdk_SELECTED_text.pixel = defaultStyle.text3_pixel; gdk_SELECTED_text.red = defaultStyle.text3_red; gdk_SELECTED_text.green = defaultStyle.text3_green; gdk_SELECTED_text.blue = defaultStyle.text3_blue; - SELECTED_text = Color.gtk_new_system(gdk_SELECTED_text); + SELECTED_text = Color.gtk_new(gdk_SELECTED_text); GdkColor gdk_SELECTED_bg = new GdkColor(); gdk_SELECTED_bg.pixel = defaultStyle.bg3_pixel; gdk_SELECTED_bg.red = defaultStyle.bg3_red; gdk_SELECTED_bg.green = defaultStyle.bg3_green; gdk_SELECTED_bg.blue = defaultStyle.bg3_blue; - SELECTED_bg = Color.gtk_new_system(gdk_SELECTED_bg); + SELECTED_bg = Color.gtk_new(gdk_SELECTED_bg); GdkColor gdk_SELECTED_base = new GdkColor(); gdk_SELECTED_base.pixel = defaultStyle.base3_pixel; gdk_SELECTED_base.red = defaultStyle.base3_red; gdk_SELECTED_base.green = defaultStyle.base3_green; gdk_SELECTED_base.blue = defaultStyle.base3_blue; - SELECTED_base = Color.gtk_new_system(gdk_SELECTED_base); + SELECTED_base = Color.gtk_new(gdk_SELECTED_base); GdkColor gdk_SELECTED_light = new GdkColor(); gdk_SELECTED_light.pixel = defaultStyle.light3_pixel; gdk_SELECTED_light.red = defaultStyle.light3_red; gdk_SELECTED_light.green = defaultStyle.light3_green; gdk_SELECTED_light.blue = defaultStyle.light3_blue; - SELECTED_light = Color.gtk_new_system(gdk_SELECTED_light); - - GdkColor gdk_SELECTED_dark = new GdkColor(); - gdk_SELECTED_dark.pixel = defaultStyle.dark3_pixel; - gdk_SELECTED_dark.red = defaultStyle.dark3_red; - gdk_SELECTED_dark.green = defaultStyle.dark3_green; - gdk_SELECTED_dark.blue = defaultStyle.dark3_blue; - SELECTED_dark = Color.gtk_new_system(gdk_SELECTED_dark); + SELECTED_light = Color.gtk_new(gdk_SELECTED_light); + GdkColor gdk_PRELIGHT_light = new GdkColor(); + gdk_PRELIGHT_light.pixel = defaultStyle.light2_pixel; + gdk_PRELIGHT_light.red = defaultStyle.light2_red; + gdk_PRELIGHT_light.green = defaultStyle.light2_green; + gdk_PRELIGHT_light.blue = defaultStyle.light2_blue; + PRELIGHT_light = Color.gtk_new(gdk_PRELIGHT_light); + GdkColor gdk_INSENSITIVE_light = new GdkColor(); gdk_INSENSITIVE_light.pixel = defaultStyle.light4_pixel; gdk_INSENSITIVE_light.red = defaultStyle.light4_red; gdk_INSENSITIVE_light.green = defaultStyle.light4_green; gdk_INSENSITIVE_light.blue = defaultStyle.light4_blue; - INSENSITIVE_light = Color.gtk_new_system(gdk_INSENSITIVE_light); - - GdkColor gdk_INSENSITIVE_dark = new GdkColor(); - gdk_INSENSITIVE_dark.pixel = defaultStyle.light4_pixel; - gdk_INSENSITIVE_dark.red = defaultStyle.light4_red; - gdk_INSENSITIVE_dark.green = defaultStyle.light4_green; - gdk_INSENSITIVE_dark.blue = defaultStyle.light4_blue; - INSENSITIVE_dark = Color.gtk_new_system(gdk_INSENSITIVE_dark); + INSENSITIVE_light = Color.gtk_new(gdk_INSENSITIVE_light); GdkColor gdk_INSENSITIVE_fg = new GdkColor(); gdk_INSENSITIVE_fg.pixel = defaultStyle.fg4_pixel; gdk_INSENSITIVE_fg.red = defaultStyle.fg4_red; gdk_INSENSITIVE_fg.green = defaultStyle.fg4_green; gdk_INSENSITIVE_fg.blue = defaultStyle.fg4_blue; - INSENSITIVE_fg = Color.gtk_new_system(gdk_INSENSITIVE_fg); + INSENSITIVE_fg = Color.gtk_new(gdk_INSENSITIVE_fg); GdkColor gdk_INSENSITIVE_bg = new GdkColor(); gdk_INSENSITIVE_bg.pixel = defaultStyle.bg4_pixel; gdk_INSENSITIVE_bg.red = defaultStyle.bg4_red; gdk_INSENSITIVE_bg.green = defaultStyle.bg4_green; gdk_INSENSITIVE_bg.blue = defaultStyle.bg4_blue; - INSENSITIVE_bg = Color.gtk_new_system(gdk_INSENSITIVE_bg); - - GdkColor gdk_INSENSITIVE_mid = new GdkColor(); - gdk_INSENSITIVE_mid.pixel = defaultStyle.bg4_pixel; - gdk_INSENSITIVE_mid.red = defaultStyle.bg4_red; - gdk_INSENSITIVE_mid.green = defaultStyle.bg4_green; - gdk_INSENSITIVE_mid.blue = defaultStyle.bg4_blue; - INSENSITIVE_mid = Color.gtk_new_system(gdk_INSENSITIVE_mid); - - GdkColor gdk_INSENSITIVE_text = new GdkColor(); - gdk_INSENSITIVE_text.pixel = defaultStyle.bg4_pixel; - gdk_INSENSITIVE_text.red = defaultStyle.bg4_red; - gdk_INSENSITIVE_text.green = defaultStyle.bg4_green; - gdk_INSENSITIVE_text.blue = defaultStyle.bg4_blue; - INSENSITIVE_text = Color.gtk_new_system(gdk_INSENSITIVE_text); - + INSENSITIVE_bg = Color.gtk_new(gdk_INSENSITIVE_bg); } /** @@ -942,10 +918,8 @@ void initializeSystemColors() { */ public Font getSystemFont () { checkDevice (); - GtkStyle style = new GtkStyle(); - OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); - int gdkFont = style.font; // gives a GdkFont* - return Font.gtk_new (gdkFont); + if (systemFont==null) systemFont = new Font(this, new FontData("fixed", 12, 0)); + return systemFont; } /** @@ -1032,7 +1006,7 @@ public int internal_new_GC (GCData data) { return gc; } -final boolean isValidThread () { +boolean isValidThread () { return thread == Thread.currentThread (); } @@ -1170,8 +1144,11 @@ void releaseDisplay () { messagesSize = windowProc2 = windowProc3 = windowProc4 = windowProc5 = 0; NORMAL_fg = NORMAL_bg = NORMAL_dark = NORMAL_mid = NORMAL_light = NORMAL_text = NORMAL_base = - SELECTED_bg = SELECTED_dark = SELECTED_light = SELECTED_text = SELECTED_base = - INSENSITIVE_fg = INSENSITIVE_bg = INSENSITIVE_dark = INSENSITIVE_mid = INSENSITIVE_light = INSENSITIVE_text =null; + ACTIVE_fg = ACTIVE_bg = ACTIVE_dark = ACTIVE_mid = ACTIVE_light = ACTIVE_text = ACTIVE_base = + PRELIGHT_fg = PRELIGHT_bg = PRELIGHT_dark = PRELIGHT_mid = PRELIGHT_light = PRELIGHT_text = PRELIGHT_base = + SELECTED_fg = SELECTED_bg = SELECTED_dark = SELECTED_mid = SELECTED_light = SELECTED_text = SELECTED_base = + INSENSITIVE_fg = INSENSITIVE_bg = INSENSITIVE_dark = INSENSITIVE_mid = INSENSITIVE_light = INSENSITIVE_text = + INSENSITIVE_base = null; } RunnableLock removeFirst () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java index 940b7427f4..18f68b3f3e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java @@ -6,6 +6,8 @@ package org.eclipse.swt.widgets; */
import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.gtk.*;
/** * Instances of this class allow the user to navigate @@ -21,10 +23,12 @@ import org.eclipse.swt.*; * within the SWT implementation. * </p> */
-public class FileDialog extends GtkFileDialog {
-
- String fullPath, fileName, filterPath;
- String[] filterNames, filterExtensions;
+public class FileDialog extends Dialog {
+ String [] filterNames = new String [0];
+ String [] filterExtensions = new String [0];
+ String filterPath = "", fileName = "";
+ String fullPath = "";
+ boolean cancel = true;
/** * Constructs a new instance of this class given only its @@ -85,7 +89,15 @@ public FileDialog (Shell parent, int style) { super (parent, style);
checkSubclass ();
}
-
+int cancelFunc (int widget, int callData) {
+ cancel = true;
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
+int destroyFunc (int widget, int callData) {
+ OS.gtk_main_quit ();
+ return 0;
+}
/** * Returns the path of the first file that was * selected in the dialog relative to the filter path, @@ -133,7 +145,104 @@ public String [] getFilterNames () { public String getFilterPath () {
return filterPath;
}
+int okFunc (int widget, int callData) {
+ cancel = false;
+ char separator = System.getProperty ("file.separator").charAt (0);
+ int lpFilename = OS.gtk_file_selection_get_filename (callData);
+ int filenameLength = OS.strlen (lpFilename);
+ byte [] filenameBytes = new byte [filenameLength];
+ OS.memmove (filenameBytes, lpFilename, filenameLength);
+ fullPath = new String (Converter.mbcsToWcs (null, filenameBytes));
+
+ /* Calculate fileName and filterPath */
+ int separatorIndex = fullPath.indexOf (separator);
+ int index = separatorIndex;
+ while (index != -1) {
+ separatorIndex = index;
+ index = fullPath.indexOf (separator, index + 1);
+ }
+ fileName = fullPath.substring (separatorIndex + 1, fullPath.length ());
+ filterPath = fullPath.substring (0, separatorIndex);
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
+/** + * Makes the dialog visible and brings it to the front + * of the display. + * + * @return a string describing the absolute path of the first selected file, + * or null if the dialog was cancelled or an error occurred + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> + * </ul> + */ +public String open () {
+ byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
+ int handle = OS.gtk_file_selection_new (titleBytes);
+
+ /* Calculate the fully-specified file name and convert to bytes */
+ StringBuffer stringBuffer = new StringBuffer ();
+ char separator = System.getProperty ("file.separator").charAt (0);
+ if (filterPath == null) {
+ filterPath = "";
+ } else {
+ if (filterPath.length () > 0) {
+ stringBuffer.append (filterPath);
+ if (filterPath.charAt (filterPath.length () - 1) != separator) {
+ stringBuffer.append (separator);
+ }
+ }
+ }
+ if (fileName == null) {
+ fileName = "";
+ } else {
+ stringBuffer.append (fileName);
+ }
+ fullPath = stringBuffer.toString ();
+ byte [] fullPathBytes = Converter.wcsToMbcs (null, fullPath, true);
+ OS.gtk_file_selection_set_filename (handle, fullPathBytes);
+
+ /* Set the extension */
+ if (filterNames == null) filterNames = new String [0];
+ if (filterExtensions == null) filterExtensions = new String [0];
+ if (filterExtensions.length == 1) {
+ String ext = filterExtensions [0];
+ byte [] extBytes = Converter.wcsToMbcs (null, ext, true);
+ OS.gtk_file_selection_complete (handle, extBytes);
+ }
+
+ /* Hook callbacks */
+ Callback destroyCallback = new Callback (this, "destroyFunc", 2);
+ int destroyFunc = destroyCallback.getAddress ();
+ byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
+ OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
+ byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
+ Callback okCallback = new Callback (this, "okFunc", 2);
+ int okFunc = okCallback.getAddress ();
+ Callback cancelCallback = new Callback (this, "cancelFunc", 2);
+ int cancelFunc = cancelCallback.getAddress ();
+ OS.gtk_signal_connect (OS.GTK_FILE_SELECTION_OK_BUTTON(handle), clicked, okFunc, handle);
+ OS.gtk_signal_connect (OS.GTK_FILE_SELECTION_CANCEL_BUTTON(handle), clicked, cancelFunc, handle);
+
+ fileName = null;
+ fullPath = null;
+ filterPath = null;
+
+ /* Show the dialog */
+ cancel = true;
+ OS.gtk_widget_show_now (handle);
+ OS.gtk_main ();
+ destroyCallback.dispose ();
+ okCallback.dispose ();
+ cancelCallback.dispose ();
+
+ /* Return the full path or null */
+ if (cancel) return null;
+ return fullPath;
+}
/** * Set the initial filename which the dialog will * select by default when opened to the argument, @@ -175,14 +284,4 @@ public void setFilterNames (String [] names) { public void setFilterPath (String string) {
filterPath = string;
}
-
-boolean getAnswer() {
- String fileNameFromOS = getFileNameFromOS();
- int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
- if (separatorIndex+1 == fileNameFromOS.length()) return false; // the user selected a directory
- fullPath = answer = fileNameFromOS;
- fileName = fullPath.substring (separatorIndex + 1, fullPath.length ());
- filterPath = fullPath.substring (0, separatorIndex);
- return true;
-}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java index 8f3a57f991..7f9a64ee09 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java @@ -103,7 +103,7 @@ int okFunc (int widget, int callData) { byte [] buffer = new byte [fontSize];
OS.memmove (buffer, hFontName, fontSize);
char [] fontName = Converter.mbcsToWcs (null, buffer);
- fontData = FontData.gtk_new(new String (fontName));
+ //fontData = FontData.gtk_new(new String (fontName));
OS.gtk_widget_destroy (callData);
return 0;
}
@@ -124,15 +124,13 @@ public FontData open () { byte [] titleBytes;
titleBytes = Converter.wcsToMbcs (null, title, true);
handle = OS.gtk_font_selection_dialog_new (titleBytes);
- GtkFontSelectionDialog dialog = new GtkFontSelectionDialog ();
- OS.memmove (dialog, handle, GtkFontSelectionDialog.sizeof);
if (parent!=null) {
OS.gtk_window_set_modal(handle, true);
- OS.gtk_window_set_transient_for(handle, parent.topHandle);
+ OS.gtk_window_set_transient_for(handle, parent.topHandle());
}
if (fontData != null) {
byte[] buffer = Converter.wcsToMbcs(null, fontData.gtk_getXlfd(), true);
- OS.gtk_font_selection_set_font_name(dialog.fontsel, buffer);
+ OS.gtk_font_selection_dialog_set_font_name(handle, buffer);
}
Callback destroyCallback = new Callback (this, "destroyFunc", 2);
int destroyFunc = destroyCallback.getAddress ();
@@ -143,8 +141,8 @@ public FontData open () { int okFunc = okCallback.getAddress ();
Callback cancelCallback = new Callback (this, "cancelFunc", 2);
int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
+ OS.gtk_signal_connect (OS.GTK_FONT_SELECTION_DIALOG_OK_BUTTON(handle), clicked, okFunc, handle);
+ OS.gtk_signal_connect (OS.GTK_FONT_SELECTION_DIALOG_CANCEL_BUTTON(handle), clicked, cancelFunc, handle);
fontData = null;
OS.gtk_widget_show_now (handle);
OS.gtk_main ();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java index 93cc92e46b..4aaa0ff0fd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java @@ -30,8 +30,7 @@ import org.eclipse.swt.graphics.*; */ public class Group extends Composite { int frameHandle; - String text=""; - byte[] TestString = string2bytesConvertMnemonic("Test String"); + String text=""; int bogus; /** * Constructs a new instance of this class given its parent @@ -78,13 +77,13 @@ static int checkStyle (int style) { void createHandle(int index) { state |= HANDLE; - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - frameHandle = OS.gtk_frame_new(null); if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_fixed_new(); + boxHandle = OS.gtk_event_box_new(); + if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); + + handle = OS.eclipse_fixed_new(); if (handle == 0) error (SWT.ERROR_NO_HANDLES); } @@ -98,35 +97,14 @@ void _setHandleStyle() { } void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, frameHandle); - OS.gtk_container_add(frameHandle, handle); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int width = _computeSize(wHint, hHint, changed).x; - int height = 0; - Point size; - if (layout != null) { - size = layout.computeSize (this, wHint, hHint, changed); - } else { - size = minimumSize (); - } - if (size.x == 0) size.x = DEFAULT_WIDTH; - if (size.y == 0) size.y = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) size.x = wHint; - if (hHint != SWT.DEFAULT) size.y = hHint; - width = Math.max (width, size.x); - height = Math.max (height, size.y); - Rectangle trim = computeTrim (0, 0, width, height); - width = trim.width; height = trim.height; - return new Point (width, height); + parent._connectChild(frameHandle); + OS.gtk_container_add(frameHandle, boxHandle); + OS.gtk_container_add(boxHandle, handle); } void showHandle() { - OS.gtk_widget_show (eventBoxHandle); OS.gtk_widget_show (frameHandle); + OS.gtk_widget_show (boxHandle); OS.gtk_widget_show (handle); OS.gtk_widget_realize (handle); } @@ -151,60 +129,69 @@ void deregister () { WidgetTable.remove (frameHandle); } -int topHandle () { return eventBoxHandle; } +int topHandle () { return frameHandle; } int parentingHandle() { return handle; } + /* * === GEOMETRY === */ -public Rectangle _getClientArea () { - /* - * The Group coordinates originate at the client area - */ - int width, height; - Point size = _getSize(); - Trim trim = _getTrim(); - width = size.x - trim.left - trim.right; - height = size.y - trim.top - trim.bottom; - return new Rectangle(0,0, width, height); + +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + if (layout==null) return computeNativeSize(handle, wHint, hHint, changed); + + Point size = layout.computeSize (this, wHint, hHint, changed); + if (size.x == 0) size.x = DEFAULT_WIDTH; + if (size.y == 0) size.y = DEFAULT_HEIGHT; + if (wHint != SWT.DEFAULT) size.x = wHint; + if (hHint != SWT.DEFAULT) size.y = hHint; + Rectangle trim = computeTrim (0, 0, size.x, size.y); + return new Point (trim.width, trim.height); } -Trim _getTrim() { - trim = new Trim(); - - // set up the test widgets - int testWindowHandle = OS.gtk_window_new(0); - int testHandle = OS.gtk_frame_new(TestString); - OS.gtk_container_add(testWindowHandle, testHandle); - OS.gtk_widget_realize(testHandle); - - // get info - GtkFrame frame = new GtkFrame(); - OS.memmove (frame, testHandle, GtkFrame.sizeof); - GtkStyle groupStyle = new GtkStyle(); - OS.memmove (groupStyle, frame.style, GtkStyle.sizeof); - GtkStyleClass styleClass = new GtkStyleClass(); - OS.memmove (styleClass, groupStyle.klass, GtkStyleClass.sizeof); - - // see gtk_frame_size_allocate() - trim.left = trim.right = frame.border_width + styleClass.xthickness; - trim.top = frame.border_width + Math.max(frame.label_height, styleClass.ythickness); - trim.bottom = frame.border_width + styleClass.ythickness; - - // clean up - OS.gtk_widget_destroy(testHandle); - OS.gtk_widget_destroy(testWindowHandle); - return trim; +/** + * Given a desired <em>client area</em> for the receiver + * (as described by the arguments), returns the bounding + * rectangle which would be required to produce that client + * area. + * <p> + * In other words, it returns a rectangle such that, if the + * receiver's bounds were set to that rectangle, the area + * of the receiver which is capable of displaying data + * (that is, not covered by the "trimmings") would be the + * rectangle described by the arguments (relative to the + * receiver's parent). + * </p> + * + * @return the required bounds to produce the given client area + * + * @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 #getClientArea + */ +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + int[] trims = new int[4]; + OS.swt_frame_get_trim(frameHandle, trims); + return new Rectangle (x-trims[1], y-trims[0], width+trims[1]+trims[2], height+trims[0]+trims[3]); } -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize (topHandle(), width,height); - Point clientSize = UtilFuncs.getSize(frameHandle); - // WRONG but it's quite safe - the frame clips it - UtilFuncs.setSize (handle, clientSize.x, clientSize.y); - return differentExtent; +public Rectangle getClientArea () { + checkWidget(); + /* The Group coordinates originate at the client area */ + int width, height; + Point size = _getSize(); + int[] trims = new int[4]; + OS.swt_frame_get_trim(frameHandle, trims); + return new Rectangle(0,0, size.x - trims[1] - trims[2], size.y - trims[0] - trims[3]); } + + /* ========= Model Logic ========= */ String getNameText () { @@ -223,8 +210,7 @@ String getNameText () { * </ul> */ public String getText () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return text; } @@ -245,8 +231,7 @@ public String getText () { * </ul> */ public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); OS.gtk_frame_set_label (frameHandle, string2bytesConvertMnemonic(string)); text=string; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index 84f872b4a8..93f70839f5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -29,7 +29,7 @@ import org.eclipse.swt.graphics.*; */ public class Label extends Control { - int boxHandle, frameHandle; + int frameHandle; Image image; String text; @@ -72,16 +72,13 @@ static int checkStyle (int style) { void createHandle (int index) { state |= HANDLE; - - boxHandle = OS.gtk_event_box_new (); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - + frameHandle = OS.gtk_frame_new(null); if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES); handle = ((style&SWT.SEPARATOR) != 0)? (((style&SWT.HORIZONTAL)!= 0)? OS.gtk_hseparator_new() : OS.gtk_vseparator_new()): - OS.gtk_label_new (new byte [1]); + OS.gtk_label_new (null); if (handle == 0) error (SWT.ERROR_NO_HANDLES); } @@ -113,13 +110,11 @@ void setHandleStyle () { } void configure() { - _connectParent(); - OS.gtk_container_add(boxHandle, frameHandle); + parent._connectChild(topHandle()); OS.gtk_container_add(frameHandle, handle); } void showHandle() { - OS.gtk_widget_show (boxHandle); OS.gtk_widget_show (frameHandle); OS.gtk_widget_show (handle); OS.gtk_widget_realize (handle); @@ -127,20 +122,14 @@ void showHandle() { void register () { super.register (); - WidgetTable.put (boxHandle, this); WidgetTable.put (frameHandle, this); } void deregister () { super.deregister (); - WidgetTable.remove (boxHandle); WidgetTable.remove (frameHandle); } -int eventHandle () { - return boxHandle; -} - void releaseWidget () { super.releaseWidget (); image = null; @@ -149,16 +138,10 @@ void releaseWidget () { void releaseHandle () { super.releaseHandle (); - boxHandle = frameHandle = 0; -} - -int topHandle () { - return boxHandle; + frameHandle = 0; } -int computeHandle () { - return frameHandle; -} +int topHandle () { return frameHandle; } public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); @@ -298,7 +281,7 @@ public void setImage (Image image) { WidgetTable.remove (handle); OS.gtk_widget_destroy (handle); if (image == null) { - handle = OS.gtk_label_new (new byte [1]); + handle = OS.gtk_label_new (null); } else { handle = OS.gtk_pixmap_new (image.pixmap, image.mask); } @@ -340,7 +323,7 @@ public void setText (String string) { //NOT IMPLEMENTED - events and state of handle lost WidgetTable.remove (handle); OS.gtk_widget_destroy (handle); - handle = OS.gtk_label_new (new byte [1]); + handle = OS.gtk_label_new (null); OS.gtk_container_add (frameHandle, handle); WidgetTable.put (handle, this); int alignment = style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java index 053ba6cc28..054e369425 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java @@ -195,7 +195,7 @@ void setHandleStyle() { } void configure() { - _connectParent(); + parent._connectChild(topHandle()); OS.gtk_container_add (scrolledHandle, handle); } @@ -316,8 +316,7 @@ public void deselectAll () { */ public int getFocusIndex () { checkWidget(); - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); return clist.focus_row; } @@ -365,8 +364,7 @@ public String getItem (int index) { */ public int getItemCount () { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); return widget.rows; } @@ -386,8 +384,7 @@ public int getItemCount () { */ public int getItemHeight () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); return clist.row_height; } @@ -441,8 +438,7 @@ public String [] getItems () { */ public String [] getSelection () { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); int list = widget.selection; if (list==0) return new String[0]; int length = OS.g_list_length (list); @@ -475,8 +471,7 @@ public String [] getSelection () { */ public int getSelectionCount () { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); return OS.g_list_length (widget.selection); } @@ -496,8 +491,7 @@ public int getSelectionCount () { */ public int getSelectionIndex () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int list = clist.selection; if (OS.g_list_length (list) == 0) return -1; return OS.g_list_nth_data (list, 0); @@ -523,8 +517,7 @@ public int getSelectionIndex () { */ public int [] getSelectionIndices () { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); int list = widget.selection; int length = OS.g_list_length (list); int [] indices = new int [length]; @@ -548,8 +541,7 @@ public int [] getSelectionIndices () { */ public int getTopIndex () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); return -clist.voffset / (clist.row_height + 1); } @@ -624,8 +616,7 @@ public int indexOf (String string, int start) { */ public boolean isSelected (int index) { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int list = clist.selection; if (list == 0) return false; int length = OS.g_list_length (list); @@ -650,14 +641,14 @@ int processMouseUp (int callData, int arg1, int int2) { * no selection signal was set and issue a fake selection * event. */ - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int x = (int) (px[0]), y = (int) (py[0]); int [] row = new int [1], column = new int [1]; int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); if (code != 0) { - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); if (selected && clist.selection != 0) { int list = clist.selection; int length = OS.g_list_length (list); @@ -674,21 +665,13 @@ int processMouseUp (int callData, int arg1, int int2) { } int processSelection (int int0, int int1, int int2) { - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); if (int0 != clist.focus_row) return 0; if ((style & SWT.MULTI) != 0) selected = false; - boolean single = true; - if (int2 != 0) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, int2, GdkEventButton.sizeof); - single = gdkEvent.type != OS.GDK_2BUTTON_PRESS; - } - if (single) { - postEvent (SWT.Selection); - } else { - postEvent (SWT.DefaultSelection); - } + int type = SWT.Selection; + if (int2 != 0) + if (OS.GDK_EVENT_TYPE(int2) == OS.GDK_2BUTTON_PRESS) type = SWT.DefaultSelection; + postEvent (type); return 0; } @@ -1124,8 +1107,7 @@ public void setTopIndex (int index) { */ public void showSelection () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int list = clist.selection; if (OS.g_list_length (list) == 0) return; int index = OS.g_list_nth_data (list, 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java index 7a77f50dc2..34e9f1e38e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java @@ -164,11 +164,11 @@ public Display getDisplay () { * </ul> */
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
+ checkWidget();
+ /* FIXME - this just checks for the SENSITIVE flag in the widget.
+ * SN: Should we look at the effective sensitivity instead?
+ */
+ return OS.GTK_WIDGET_SENSITIVE(handle);
}
/** * Returns the item at the given, zero-relative index in the @@ -325,11 +325,8 @@ public Shell getShell () { * </ul> */
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_MAPPED) != 0;
+ checkWidget();
+ return OS.GTK_WIDGET_MAPPED(handle);
}
/** * Searches the receiver's list starting at the first item diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java index 1de7188b22..44306c6006 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java @@ -277,11 +277,8 @@ public Display getDisplay () { * </ul> */
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
+ checkWidget();
+ return OS.GTK_WIDGET_SENSITIVE(handle);
}
/** * Returns the receiver's cascade menu if it has one or null @@ -332,12 +329,9 @@ public Menu getParent () { * </ul> */
public boolean getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- GtkCheckMenuItem menuItem = new GtkCheckMenuItem ();
- OS.memmove (menuItem, handle, GtkCheckMenuItem.sizeof);
- return menuItem.active != 0;
+ return OS.gtk_check_menu_item_get_active(handle);
}
void hookEvents () {
super.hookEvents ();
@@ -586,16 +580,14 @@ public void setMenu (Menu menu) { * </ul> */
public void setSelection (boolean selected) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
OS.gtk_check_menu_item_set_active (handle, selected);
OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
text = string;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java index ed3a745f1c..28bc6ad91f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java @@ -171,11 +171,9 @@ private void createHandle() { } } private void createMessage() { - byte[] bytes = Converter.wcsToMbcs (null, getMessage(), true); - label = OS.gtk_label_new (bytes); - GtkDialog dialog = new GtkDialog(); - OS.memmove (dialog, handle, GtkDialog.sizeof); - OS.gtk_box_pack_start (dialog.vbox, label, true, true, 5); // FIXME should we use container_add?? + label = OS.gtk_label_new (message); + if (label==0) error(SWT.ERROR_NO_HANDLES); + OS.gtk_box_pack_start (OS.GTK_DIALOG_VBOX(handle), label, true, true, 5); // FIXME should we use container_add?? } private void createActionButtons() { if ((style & SWT.OK) != 0) buttonOK = createButton("OK"); @@ -197,9 +195,7 @@ private void showHandle() { int decor = 0; if (hasTitle) decor |= OS.GDK_DECOR_TITLE; - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, handle, GtkWidget.sizeof); - int gdkWindow = widget.window; + int gdkWindow = OS.GTK_WIDGET_WINDOW(handle); OS.gdk_window_set_decorations(gdkWindow, decor); if (hasTitle) { byte[] bytes = Converter.wcsToMbcs (null, title, true); @@ -207,12 +203,9 @@ private void showHandle() { } } int createButton(String buttonName) { - System.out.println("Creating button "+buttonName); byte[] bytes = Converter.wcsToMbcs (null, buttonName, true); int buttonHandle = OS.gtk_button_new_with_label(bytes); - GtkDialog dialog = new GtkDialog(); - OS.memmove (dialog, handle, GtkDialog.sizeof); - OS.gtk_box_pack_start (dialog.action_area, buttonHandle, true, true, 0); + OS.gtk_box_pack_start (OS.GTK_DIALOG_ACTION_AREA(handle), buttonHandle, true, true, 0); hookSelection(buttonHandle); return buttonHandle; } @@ -222,7 +215,6 @@ private void hookSelection(int h) { Callback okCallback = new Callback (this, "activateFunc", 2); int okFunc = okCallback.getAddress (); OS.gtk_signal_connect (h, clicked, okFunc, h); - } private static int checkStyle (int style) { int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java index cad77f4868..c779a425f4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java @@ -83,9 +83,7 @@ private void createCursor() { int cursorType = ((style&SWT.VERTICAL)!=0)? OS.GDK_SB_H_DOUBLE_ARROW:OS.GDK_SB_V_DOUBLE_ARROW; cursor = OS.gdk_cursor_new(cursorType); - GtkWidget widget = new GtkWidget (); - OS.memmove(widget, handle, GtkWidget.sizeof); - OS.gdk_window_set_cursor(widget.window, cursor); + OS.gdk_window_set_cursor(OS.GTK_WIDGET_WINDOW(handle), cursor); } public Point computeSize (int wHint, int hHint, boolean changed) { @@ -165,13 +163,16 @@ public void removeSelectionListener(SelectionListener listener) { } int processMouseDown (int callData, int arg1, int int2) { - OS.gtk_grab_add(handle); +/* OS.gtk_grab_add(handle); dragging = true; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - if (gdkEvent.button != 1) return 0; - startX = (int)gdkEvent.x; startY = (int)gdkEvent.y; - start_root_x=(int)gdkEvent.x_root; start_root_y=(int)gdkEvent.y_root; + int button = OS.gdk_event_button_get_button(callData); + if (button != 1) return 0; + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + startX = (int)(px[0]); startY = (int)(py[0]); + OS.gdk_event_get_root_coords(callData, px, py); + start_root_x=(int)(px[0]); start_root_y=(int)(py[0]); drawX=startX; drawY=startY; GtkWidget gtkwidget = new GtkWidget(); OS.memmove(gtkwidget, handle, GtkWidget.sizeof); @@ -179,25 +180,27 @@ int processMouseDown (int callData, int arg1, int int2) { lastX = gtkwidget.alloc_x - border; lastY = gtkwidget.alloc_y - border; Event event = new Event (); event.detail = SWT.DRAG; - event.time = gdkEvent.time; + event.time = OS.gdk_event_get_time(callData); event.x = lastX; event.y = lastY; event.width = width; event.height = height; - sendEvent (SWT.MouseDown, event); + sendEvent (SWT.MouseDown, event);*/ return 0; } int processMouseMove (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); if (!dragging) return 0; - GtkWidget gtkwidget = new GtkWidget(); +/* GtkWidget gtkwidget = new GtkWidget(); OS.memmove(gtkwidget, handle, GtkWidget.sizeof); int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; int x = gtkwidget.alloc_x - border, y = gtkwidget.alloc_y - border; Rectangle rect = parent.getClientArea(); int parentWidth = rect.width - 2; int parentHeight = rect.height - 2; - last_root_x=(int)gdkEvent.x_root; last_root_y=(int)gdkEvent.y_root; + + double px[] = new double[1]; + double py[] = new double[1]; + OS.gdk_event_get_root_coords(callData, px, py); + last_root_x=(int)(px[0]); last_root_y=(int)(py[0]); int newX = lastX, newY = lastY; if ((style & SWT.VERTICAL) != 0) { if (last_root_x<=start_root_x) @@ -211,13 +214,13 @@ int processMouseMove (int callData, int arg1, int int2) { newY = Math.min (Math.max (0, y + (last_root_y-start_root_y) - startY ), parentHeight - height); } if ((newX == lastX) && (newY == lastY)) return 0; - drawBand(newX, newY, width, height); + drawBand(newX, newY, width, height);*/ return 0; } + int processMouseUp (int callData, int arg1, int int2) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - if (gdkEvent.button != 1) return 0; +/* int button = OS.gdk_event_button_get_button(callData); + if (button != 1) return 0; if (!dragging) return 0; GtkWidget gtkwidget = new GtkWidget(); OS.memmove(gtkwidget, handle, GtkWidget.sizeof); @@ -226,7 +229,10 @@ int processMouseUp (int callData, int arg1, int int2) { Rectangle rect = parent.getClientArea(); int parentWidth = rect.width - 2; int parentHeight = rect.height - 2; - last_root_x=(int)gdkEvent.x_root; last_root_y=(int)gdkEvent.y_root; + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + last_root_x=(int)(px[0]); last_root_y=(int)(py[0]); int newX = lastX, newY = lastY; if ((style & SWT.VERTICAL) != 0) { if (last_root_x<=start_root_x) @@ -242,14 +248,14 @@ int processMouseUp (int callData, int arg1, int int2) { if ((newX == lastX) && (newY == lastY)) return 0; Event event = new Event (); - event.time = gdkEvent.time; + event.time = OS.gdk_event_get_time(callData); event.x = newX; event.y = newY; event.width = width; event.height = height; dragging = false; drawBand(newX, newY, width, height); drawing = false; OS.gtk_grab_remove(handle); - sendEvent (SWT.Selection, event); + sendEvent (SWT.Selection, event);*/ return 0; } /* @@ -277,16 +283,14 @@ int processMouseEnter (int callData, int arg1, int int2) { } */ int processMouseExit (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - GtkWidget gtkwidget = new GtkWidget(); +/* GtkWidget gtkwidget = new GtkWidget(); OS.memmove(gtkwidget, handle, GtkWidget.sizeof); int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; Event event = new Event (); - event.time = gdkEvent.time; + event.time = OS.gdk_event_get_time(callData); event.x = lastX; event.y = lastY; event.width = width; event.height = height; - sendEvent (SWT.MouseExit, event); + sendEvent (SWT.MouseExit, event);*/ return 0; } @@ -295,9 +299,7 @@ void drawBand (int x, int y, int width, int height) { if (x == drawX && y == drawY) return; Display display= parent.getDisplay (); if (display == null) return; - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, parent.topHandle(), GtkWidget.sizeof); - int window = gtkwidget.window; + int window = OS.GTK_WIDGET_WINDOW(parent.topHandle()); if (window == 0) return; byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; int stipplePixmap = OS.gdk_bitmap_create_from_data (window, bits, 8, 8); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java index 7baf8ad787..f0357f25cb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java @@ -117,8 +117,7 @@ void showHandle() { void hookEvents () { super.hookEvents (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); signal_connect (hAdjustment, "value_changed", SWT.Selection, 2); } @@ -154,8 +153,7 @@ void deregister () { public int getIncrement () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.step_increment; } @@ -172,8 +170,7 @@ public int getIncrement () { public int getMaximum () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.upper; } @@ -190,8 +187,7 @@ public int getMaximum () { public int getMinimum () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.lower; } @@ -210,8 +206,7 @@ public int getMinimum () { public int getPageIncrement () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.page_increment; } @@ -228,8 +223,7 @@ public int getPageIncrement () { public int getSelection () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.value; } @@ -280,10 +274,9 @@ public void setIncrement (int value) { checkWidget (); if (value < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); adjustment.step_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -305,10 +298,9 @@ public void setMaximum (int value) { checkWidget (); if (value < 0) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); adjustment.upper = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -330,10 +322,9 @@ public void setMinimum (int value) { checkWidget (); if (value < 0) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); adjustment.lower = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -356,10 +347,9 @@ public void setPageIncrement (int value) { checkWidget (); if (value < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); adjustment.page_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java index 861a36e564..e612fc7fba 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java @@ -30,10 +30,10 @@ import org.eclipse.swt.events.*; * <li>an arrow button for incrementing the value</li> * </ol> * Based on their style, scroll bars are either <code>HORIZONTAL</code> - * (which have a left facing button for decrementing the value and a - * right facing button for incrementing it) or <code>VERTICAL</code> - * (which have an upward facing button for decrementing the value - * and a downward facing buttons for incrementing it). + * (which have left and right facing buttons for incrementing and + * decrementing the value) or <code>VERTICAL</code> (which have + * up and down facing buttons for incrementing and decrementing + * the value). * </p><p> * On some platforms, the size of the scroll bar's thumb can be * varied relative to the magnitude of the range of values it @@ -169,8 +169,7 @@ public boolean getEnabled () { */ public int getIncrement () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.step_increment; } @@ -186,8 +185,7 @@ public int getIncrement () { */ public int getMaximum () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.upper; } @@ -203,8 +201,7 @@ public int getMaximum () { */ public int getMinimum () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.lower; } @@ -222,8 +219,7 @@ public int getMinimum () { */ public int getPageIncrement () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.page_increment; } @@ -254,8 +250,7 @@ public Scrollable getParent () { */ public int getSelection () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.value; } @@ -273,9 +268,8 @@ public int getSelection () { */ public Point getSize () { checkWidget (); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_width, widget.alloc_height); + /* FIXME - NOT_IMPLEMENTED. We can no longer look at the allocation. */ + return new Point (10,10); } /** @@ -293,8 +287,7 @@ public Point getSize () { */ public int getThumb () { checkWidget (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); return (int) adjustment.page_size; } @@ -443,10 +436,9 @@ public void setEnabled (boolean enabled) { public void setIncrement (int value) { checkWidget (); if (value < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.step_increment = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); @@ -467,10 +459,9 @@ public void setIncrement (int value) { public void setMaximum (int value) { checkWidget (); if (value < 0) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.upper = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); @@ -491,10 +482,9 @@ public void setMaximum (int value) { public void setMinimum (int value) { checkWidget (); if (value < 0) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.lower = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); @@ -516,10 +506,9 @@ public void setMinimum (int value) { public void setPageIncrement (int value) { checkWidget (); if (value < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.page_increment = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); @@ -562,10 +551,9 @@ public void setSelection (int value) { public void setThumb (int value) { checkWidget (); if (value < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.page_size = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); @@ -601,15 +589,14 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i if (maximum - minimum - thumb < 0) return; if (increment < 1) return; if (pageIncrement < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (handle); adjustment.lower = minimum; adjustment.upper = maximum; adjustment.step_increment = increment; adjustment.page_increment = pageIncrement; adjustment.page_size = thumb; adjustment.value = selection; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); + OS.memmove (handle, adjustment); OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); OS.gtk_adjustment_changed (handle); OS.gtk_adjustment_value_changed (handle); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java index a2405fca32..289ddb8553 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java @@ -28,7 +28,6 @@ public abstract class Scrollable extends Control { int scrolledHandle; ScrollBar horizontalBar, verticalBar; - static Trim trim; /** * Prevents uninitialized instances from being created outside the package. @@ -91,27 +90,23 @@ public Scrollable (Composite parent, int style) { * @see #getClientArea */ public Rectangle computeTrim (int x, int y, int width, int height) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - - Trim t = _getTrim(); - return new Rectangle (x-t.left, y-t.top, width+t.left+t.right, height+t.top+t.bottom); -} - -Trim _getTrim() { - if (trim==null) initializeTrim(); - return trim; + checkWidget(); + int hs=0, vs=0; + /* FIXME - just measured the width on one particular theme */ + if ((style&SWT.H_SCROLL)!=0) hs=18; + if ((style&SWT.V_SCROLL)!=0) vs=18; + return new Rectangle (x, y, width+vs, height+hs); } -void initializeTrim() { trim = new Trim(); } - void _fillBin(int binHandle, int childHandle) { + /* GtkBin bin = new GtkBin(); OS.memmove(bin, binHandle, GtkBin.sizeof); bin.child = childHandle; OS.memmove(binHandle, bin, GtkBin.sizeof); OS.gtk_widget_set_parent(childHandle, binHandle); -} + */ + OS.gtk_container_add(binHandle, childHandle);} /* * Subclasses must only use super.configure() @@ -162,11 +157,9 @@ void deregister () { * @see #computeTrim */ public Rectangle getClientArea () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Rectangle (0, 0, widget.alloc_width, widget.alloc_height); + checkWidget(); + /* FIXME. Why do we do it here, in the first place? Scrollable is abstract... */ + return new Rectangle (0, 0, 10, 10); } /** * Returns the receiver's horizontal scroll bar if it has diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index d93c35d2f6..8f2cd3c97f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -92,10 +92,9 @@ import org.eclipse.swt.events.*; */ public class Shell extends Decorations { Display display; - int vboxHandle; + int shellHandle, vboxHandle; int modal; int accelGroup; - Rectangle lastClientArea; boolean hasFocus; /* @@ -294,9 +293,7 @@ public void addShellListener (ShellListener listener) { addListener (SWT.Activate, typedListener); addListener (SWT.Deactivate, typedListener); } -void bringToTop () { -// OS.gtk_window_activate_focus (shellHandle); -} + /** * Requests that the window manager close the receiver in * the same way it would be closed when the user clicks on @@ -315,7 +312,7 @@ public void close () { } void closeWidget () { Event event = new Event (); - event.time = OS.gdk_time_get (); + event.time = OS.GDK_CURRENT_TIME(); sendEvent (SWT.Close, event); if (event.doit && !isDisposed ()) dispose (); } @@ -327,58 +324,60 @@ void closeWidget () { void createHandle (int index) { state |= HANDLE; - topHandle = OS.gtk_window_new((parent==null)? OS.GTK_WINDOW_TOPLEVEL:OS.GTK_WINDOW_DIALOG); - if (topHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - if (parent!=null) OS.gtk_window_set_transient_for(topHandle, parent.topHandle()); + shellHandle = OS.gtk_window_new((parent==null)? OS.GTK_WINDOW_TOPLEVEL:OS.GTK_WINDOW_DIALOG); + if (shellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); + if (parent!=null) OS.gtk_window_set_transient_for(shellHandle, parent.topHandle()); vboxHandle = OS.gtk_vbox_new(false,0); if (vboxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new (); + + boxHandle = OS.gtk_event_box_new(); + if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); + + fixedHandle = OS.eclipse_fixed_new(); if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); + handle = OS.gtk_drawing_area_new(); if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); + accelGroup = OS.gtk_accel_group_new (); - OS.gtk_window_add_accel_group (topHandle, accelGroup); - OS.gtk_window_set_title (topHandle, new byte [1]); + OS.gtk_window_add_accel_group (shellHandle, accelGroup); + OS.gtk_window_set_title (shellHandle, new byte [1]); } void configure () { - OS.gtk_container_add (topHandle, vboxHandle); - OS.gtk_box_pack_end(vboxHandle, eventBoxHandle, true,true,0); - OS.gtk_container_add (eventBoxHandle, fixedHandle); - OS.gtk_fixed_put(fixedHandle, handle, (short)0,(short)0); + OS.gtk_container_add (shellHandle, vboxHandle); + OS.gtk_box_pack_end(vboxHandle, boxHandle, true,true,0); + OS.gtk_container_add(boxHandle, fixedHandle); + OS.gtk_container_add(fixedHandle, handle); } void showHandle() { - OS.gtk_widget_realize (topHandle); // careful: NOT show + OS.gtk_widget_realize (shellHandle); // careful: NOT show _setStyle(); OS.gtk_widget_realize (vboxHandle); OS.gtk_widget_show_now (vboxHandle); - - OS.gtk_widget_realize (eventBoxHandle); - OS.gtk_widget_show_now (eventBoxHandle); - - OS.gtk_widget_realize (fixedHandle); + OS.gtk_widget_realize (boxHandle); + OS.gtk_widget_show_now (boxHandle); + OS.gtk_widget_realize (fixedHandle); OS.gtk_widget_show_now (fixedHandle); - OS.gtk_widget_realize (handle); OS.gtk_widget_show_now (handle); } void hookEvents () { super.hookEvents (); - signal_connect(topHandle, "map_event", SWT.Deiconify, 3); - signal_connect(topHandle, "unmap_event", SWT.Iconify, 3); - signal_connect(topHandle, "size_allocate", SWT.Resize, 3); - signal_connect(topHandle, "delete_event", SWT.Dispose, 3); + signal_connect_after(shellHandle, "map-event", SWT.Deiconify, 3); + signal_connect_after(shellHandle, "unmap-event", SWT.Iconify, 3); + signal_connect(shellHandle, "size-allocate", SWT.Resize, 3); + signal_connect(shellHandle, "delete-event", SWT.Dispose, 3); } void register () { super.register (); WidgetTable.put (vboxHandle, this); + WidgetTable.put (shellHandle, this); } private void _setStyle() { @@ -386,7 +385,7 @@ private void _setStyle() { ((style&SWT.PRIMARY_MODAL) != 0) || ((style&SWT.APPLICATION_MODAL) != 0) || ((style&SWT.SYSTEM_MODAL) != 0)); - OS.gtk_window_set_modal(topHandle, modal); + OS.gtk_window_set_modal(shellHandle, modal); int decorations = 0; if ((style & SWT.NO_TRIM) == 0) { @@ -404,33 +403,15 @@ private void _setStyle() { */ if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_BORDER; } - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, topHandle, GtkWidget.sizeof); - int w = widget.window; - // PANIC - this must absolutely never happen, so it's not NO_HANDLES actually - if (w == 0) error(SWT.ERROR_NO_HANDLES); - OS.gdk_window_set_decorations(w, decorations); -} - -void _connectChild (int h) { - OS.gtk_fixed_put (fixedHandle, h, (short)0, (short)0); -} - -int topHandle () { - return topHandle; -} - -int parentingHandle() { - return fixedHandle; + OS.gdk_window_set_decorations(OS.GTK_WIDGET_WINDOW(shellHandle), decorations); } +int topHandle () { return shellHandle; } +int parentingHandle() { return fixedHandle; } boolean isMyHandle(int h) { - if (h == topHandle) return true; + if (h == shellHandle) return true; if (h == vboxHandle) return true; - if (h == eventBoxHandle) return true; - if (h == fixedHandle) return true; - if (h == handle) return true; - return false; + return super.isMyHandle(h); } @@ -438,56 +419,46 @@ boolean isMyHandle(int h) { * === GEOMETRY === */ -public Point _getLocation() { - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle, GtkWidget.sizeof); +Point _getLocation() { int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_origin(widget.window, x,y); + OS.gtk_window_get_position(shellHandle, x,y); return new Point(x[0], y[0]); } -public Point _getSize() { - return UtilFuncs.getSize(vboxHandle); -} - -public Rectangle _getClientArea () { - Point clientSize = UtilFuncs.getSize(eventBoxHandle); - return new Rectangle (0, 0, clientSize.x, clientSize.y); +Point _getSize() { + int[] x = new int[1]; int[] y = new int[1]; + OS.gtk_window_get_size(shellHandle, x, y); + return new Point(x[0], y[0]); } -boolean _setSize(int width, int height) { - /* - * API deficiency in GTK 1.2 - lacking gtk_window_resize. - * We work around this by directly resizing the X window. - * - * First, we find out the GDK handle. - */ - GtkWidget gtkWidget = new GtkWidget(); - OS.memmove(gtkWidget, topHandle, GtkWidget.sizeof); - - OS.gtk_signal_handler_block_by_data (topHandle, SWT.Resize); - OS.gdk_window_resize(gtkWidget.window, width, height); - UtilFuncs.setSize(vboxHandle, width, height); - Point sz = UtilFuncs.getSize(eventBoxHandle); - UtilFuncs.setSize(fixedHandle, sz.x, sz.y); - UtilFuncs.setSize(handle, sz.x, sz.y); - OS.gtk_signal_handler_unblock_by_data (topHandle, SWT.Resize); - - return true; +public Rectangle getClientArea () { + checkWidget(); + Point totalSize = _getSize(); + /* FIXME - subtract trim */ + return new Rectangle (0, 0, totalSize.x, totalSize.y); +} + +void _setSize(int width, int height) { + OS.gtk_signal_handler_block_by_data (shellHandle, SWT.Resize); + OS.gtk_window_resize(shellHandle, width, height); + boolean done = false; + Point s = _getSize(); + while ((s.x!=width) || (s.y!=height)) { + OS.gtk_main_iteration(); + s = _getSize(); + } + OS.gtk_signal_handler_unblock_by_data (shellHandle, SWT.Resize); } -boolean _setLocation (int x, int y) { - GtkWidget gtkWidget = new GtkWidget(); - OS.memmove(gtkWidget, topHandle, GtkWidget.sizeof); - OS.gdk_window_move(gtkWidget.window, x, y); - return true; +void _setLocation (int x, int y) { + OS.gtk_window_move(shellHandle, x, y); } void setInitialSize() { int width = OS.gdk_screen_width () * 5 / 8; int height = OS.gdk_screen_height () * 5 / 8; _setSize(width, height); - OS.gtk_window_set_policy (topHandle, 1,1,0); + OS.gtk_window_set_policy (shellHandle, 1,1,0); } /* @@ -518,11 +489,9 @@ public Display getDisplay () { * but the user clicked in a no-entry widget (like Label). */ Control getFocusControl() { - GtkWindow shell = new GtkWindow(); - OS.memmove(shell, topHandle, GtkWindow.sizeof); - int focusHandle = shell.focus_widget; - if (focusHandle==0) return null; - return (Control)this.getDisplay().findWidget(focusHandle); + checkWidget(); + int answer = OS.gtk_window_get_focus(shellHandle); + return (Control)this.getDisplay().findWidget(answer); } /** @@ -602,19 +571,10 @@ public Shell [] getShells () { public void layout (boolean changed) { checkWidget(); -// if (!resizedSinceLastLayout()) return; - lastClientArea=getClientArea(); if (layout == null) return; layout.layout (this, changed); } -/* - * Returns whether the shell has been resized since the last layout() - */ -boolean resizedSinceLastLayout() { - return !getClientArea().equals(lastClientArea); -} - /** * Moves the receiver to the top of the drawing order for * the display on which it was created (so that all other @@ -637,7 +597,7 @@ public void open () { int processDispose (int int0, int int1, int int2) { closeWidget (); - return 1; + return 0; } int processFocusIn(int int0, int int1, int int2) { @@ -653,10 +613,7 @@ int processFocusOut(int int0, int int1, int int2) { } int processPaint (int callData, int int2, int int3) { - //if (!hooks (SWT.Paint)) return 1; - - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); +/* GdkEventExpose gdkEvent = new GdkEventExpose (callData); Event event = new Event (); event.count = gdkEvent.count; event.x = gdkEvent.x; event.y = gdkEvent.y; @@ -669,22 +626,14 @@ int processPaint (int callData, int int2, int int3) { gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); sendEvent (SWT.Paint, event); gc.dispose (); - event.gc = null; - return 1; -/*}else{ - GdkRectangle gdkEvent = new GdkRectangle (); - OS.memmove (gdkEvent, callData, GdkRectangle.sizeof); - Event event = new Event (); -// event.count = gdkEvent.count; - event.x = gdkEvent.x; event.y = gdkEvent.y; - event.width = gdkEvent.width; event.height = gdkEvent.height; - GC gc = event.gc = new GC (this); - OS.gdk_gc_set_clip_rectangle (gc.handle, gdkEvent); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 1; -} */ + event.gc = null;*/ + return 0; +} + +int processResize (int int0, int int1, int int2) { + sendEvent (SWT.Resize); + layout(); + return 0; } /** @@ -737,10 +686,8 @@ public void setImeInputMode (int mode) { public void setMaximized (boolean maximized) { checkWidget(); - - /* - * Out of luck on curent GDK. - */ + if (maximized) OS.gtk_window_maximize(shellHandle); + else OS.gtk_window_unmaximize(shellHandle); } public void setMenuBar (Menu menu) { @@ -766,20 +713,8 @@ public void setMenuBar (Menu menu) { public void setMinimized (boolean minimized) { checkWidget(); - - /* - * In GDK, there is no way to iconify a shell. - * If we wanted it really badly, on pure X this is done - * by sending a client message - see ICCCM L.4.1.4. - */ - if (minimized) return; - - /* - * At least we can force a deiconify - */ - GtkWidget w = new GtkWidget(); - OS.memmove(w, topHandle, w.sizeof); - OS.gdk_window_show(w.window); + if (minimized) OS.gtk_window_iconify(shellHandle); + else OS.gtk_window_deiconify(shellHandle); } /** @@ -798,21 +733,20 @@ public void setModal (int modal) { } public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); super.setText (string); byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_window_set_title (topHandle, buffer); + OS.gtk_window_set_title (shellHandle, buffer); } public void setVisible (boolean visible) { checkWidget(); if (visible) { - OS.gtk_widget_show_now (topHandle); + OS.gtk_widget_show_now (shellHandle); display.update(); sendEvent (SWT.Show); } else { - OS.gtk_widget_hide (topHandle); + OS.gtk_widget_hide (shellHandle); sendEvent (SWT.Hide); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java index f01f6e5ce6..91d2a5fd16 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java @@ -30,10 +30,10 @@ import org.eclipse.swt.events.*; * <li>an arrow button for incrementing the value</li> * </ol> * Based on their style, sliders are either <code>HORIZONTAL</code> - * (which have a left facing button for decrementing the value and a - * right facing button for incrementing it) or <code>VERTICAL</code> - * (which have an upward facing button for decrementing the value - * and a downward facing buttons for incrementing it). + * (which have left and right facing buttons for incrementing and + * decrementing the value) or <code>VERTICAL</code> (which have + * up and down facing buttons for incrementing and decrementing + * the value). * </p><p> * On some platforms, the size of the slider's thumb can be * varied relative to the magnitude of the range of values it @@ -212,8 +212,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { public int getIncrement () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.step_increment; } @@ -230,8 +229,7 @@ public int getIncrement () { public int getMaximum () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.upper; } @@ -248,8 +246,7 @@ public int getMaximum () { public int getMinimum () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.lower; } @@ -268,8 +265,7 @@ public int getMinimum () { public int getPageIncrement () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.page_increment; } @@ -286,8 +282,7 @@ public int getPageIncrement () { public int getSelection () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.value; } @@ -305,8 +300,7 @@ public int getSelection () { public int getThumb () { checkWidget (); int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); return (int) adjustment.page_size; } @@ -357,10 +351,9 @@ public void setIncrement (int value) { checkWidget(); if (value < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.step_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.step_increment = (double) value; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -382,10 +375,9 @@ public void setMaximum (int value) { checkWidget (); if (value < 0) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.upper = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.upper = (double) value; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -407,10 +399,9 @@ public void setMinimum (int value) { checkWidget (); if (value < 0) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.lower = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.lower = (double) value; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -433,10 +424,9 @@ public void setPageIncrement (int value) { checkWidget (); if (value < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.page_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.page_increment = (double) value; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -481,10 +471,9 @@ public void setThumb (int value) { checkWidget (); if (value < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.page_size = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.page_size = (double) value; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); @@ -521,15 +510,14 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i if (increment < 1) return; if (pageIncrement < 1) return; int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.value = (float) selection; - adjustment.lower = (float) minimum; - adjustment.upper = (float) maximum; - adjustment.page_size = (float) thumb; - adjustment.step_increment = (float) increment; - adjustment.page_increment = (float) pageIncrement; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment (hAdjustment); + adjustment.value = (double) selection; + adjustment.lower = (double) minimum; + adjustment.upper = (double) maximum; + adjustment.page_size = (double) thumb; + adjustment.step_increment = (double) increment; + adjustment.page_increment = (double) pageIncrement; + OS.memmove (hAdjustment, adjustment); OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); OS.gtk_adjustment_changed (hAdjustment); OS.gtk_adjustment_value_changed (hAdjustment); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java index 4338e7e92e..d4ea81235a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java @@ -34,10 +34,10 @@ import org.eclipse.swt.events.*; * </p>
*/
public class TabFolder extends Composite {
- int notebookHandle;
+
+ int topHandle;
TabItem [] items;
-
/*
* == CONSTRUCTORS ==
*/
@@ -75,42 +75,40 @@ public TabFolder (Composite parent, int style) { }
/*
- * == HANDLE DANCES, FIRST SPECIES ==
+ * == Handle code ==
*/
void createHandle (int index) {
state |= HANDLE;
- eventBoxHandle = OS.gtk_event_box_new();
- fixedHandle = OS.gtk_fixed_new ();
- notebookHandle = OS.gtk_notebook_new ();
- handle = OS.gtk_fixed_new();
+ topHandle = OS.eclipse_fixed_new();
+ handle = OS.gtk_notebook_new ();
+ boxHandle = OS.gtk_event_box_new();
+ fixedHandle = OS.eclipse_fixed_new ();
}
void configure () {
- _connectParent();
- OS.gtk_container_add(eventBoxHandle, fixedHandle);
- OS.gtk_fixed_put (fixedHandle, notebookHandle, (short)0, (short)0);
- OS.gtk_fixed_put (fixedHandle, handle, (short)2, (short)33);
+ parent._connectChild(topHandle);
+ OS.gtk_container_add(topHandle, handle);
+ OS.gtk_container_add(topHandle, boxHandle);
+ OS.gtk_container_add(boxHandle, fixedHandle);
+ OS.eclipse_fixed_set_location(topHandle, boxHandle, 2, 33); /* FIXME */
}
void showHandle() {
- OS.gtk_widget_show(eventBoxHandle);
- OS.gtk_widget_show(fixedHandle);
- OS.gtk_widget_show(notebookHandle);
+ OS.gtk_widget_show(topHandle);
OS.gtk_widget_show(handle);
- OS.gtk_widget_realize (notebookHandle);
- OS.gtk_widget_realize (handle);
+ OS.gtk_widget_show(boxHandle);
+ OS.gtk_widget_show(fixedHandle);
}
void register () {
super.register ();
- WidgetTable.put (notebookHandle, this);
+ WidgetTable.put (topHandle, this);
}
void hookEvents () {
super.hookEvents ();
- signal_connect (notebookHandle, "size_allocate", SWT.Resize, 3);
- signal_connect (notebookHandle, "switch_page", SWT.Selection, 4);
+ signal_connect (handle, "switch_page", SWT.Selection, 4);
}
void createWidget (int index) {
@@ -118,21 +116,18 @@ void createWidget (int index) { items = new TabItem [4];
}
-int topHandle () { return eventBoxHandle; }
-int paintHandle () { return notebookHandle; }
-int parentingHandle () { return handle; }
+int topHandle () { return topHandle; }
+public int paintHandle () { return boxHandle; } /* can't do much :-( */
+int parentingHandle () { return fixedHandle; }
boolean isMyHandle(int h) {
- if (h==eventBoxHandle) return true;
- if (h==notebookHandle) return true;
- if (h==fixedHandle) return true;
- if (h==handle) return true;
- return false;
+ if (h==topHandle) return true;
+ return super.isMyHandle(h);
}
public Point computeSize (int wHint, int hHint, boolean changed) {
checkWidget ();
//notebookHandle
- int width = _computeSize(wHint, hHint, changed).x;
+/* int width = _computeSize(wHint, hHint, changed).x;
int height = 0;
Point size;
if (layout != null) {
@@ -148,35 +143,37 @@ public Point computeSize (int wHint, int hHint, boolean changed) { height = Math.max (height, size.y);
Rectangle trim = computeTrim (0, 0, width, height);
width = trim.width; height = trim.height;
- return new Point (width, height);
+ return new Point (width, height);*/
+ /* FIXME */
+ return new Point(300,300);
}
/**
-* Computes the widget trim.
-*/
+ * Computes the widget trim.
+ */
public Rectangle computeTrim (int x, int y, int width, int height) {
checkWidget();
return new Rectangle(x-2, y-33, width+4, height+35);
}
/*
- **** Layout code ****
+ * === Layout code ===
*/
-boolean _setSize(int width, int height) {
- boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height);
- UtilFuncs.setSize (fixedHandle, width,height);
- UtilFuncs.setSize (notebookHandle, width,height);
- UtilFuncs.setSize (handle, width-4, height-35);
+void _setSize(int width, int height) {
+ OS.eclipse_fixed_set_size(parent.parentingHandle(), topHandle(), width, height);
+ /* FIXME */
+ int w = Math.max(width - 4, 1);
+ int h = Math.max(height - 35, 1);
+ OS.eclipse_fixed_set_size(topHandle, handle, w, h);
layoutCurrent();
- return differentExtent;
}
-public Rectangle _getClientArea () {
- org.eclipse.swt.graphics.Point size = _getSize();
- int x = Math.max(size.x-4, 3);
- int y = Math.max(size.y-35, 3);
- return new Rectangle(0,0, x, y);
+public Rectangle getClientArea () {
+ checkWidget();
+ int[] sz = new int[2];
+ OS.eclipse_fixed_get_size(topHandle, boxHandle, sz);
+ return new Rectangle(0,0, sz[0], sz[1]);
}
void layoutCurrent() {
@@ -189,7 +186,7 @@ void layoutCurrent() { }
void createItem (TabItem item, int index) {
- int list = OS.gtk_container_children (notebookHandle);
+ int list = OS.gtk_container_children (handle);
int itemCount = OS.g_list_length (list);
if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_ADDED);
if (itemCount == items.length) {
@@ -199,16 +196,15 @@ void createItem (TabItem item, int index) { }
// create a new label
- byte [] buffer = new byte [] {0};
- int labelHandle = OS.gtk_label_new (buffer);
+ int labelHandle = OS.gtk_label_new ("");
// create a new fake page
- int stubPage = OS.gtk_fixed_new();
+ int stubPage = OS.eclipse_fixed_new();
// put the label and the fake page inside the notebook
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_append_page(notebookHandle, stubPage, labelHandle);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
+ OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
+ OS.gtk_notebook_append_page(handle, stubPage, labelHandle);
+ OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
OS.gtk_widget_show(labelHandle);
OS.gtk_widget_show(stubPage);
@@ -217,7 +213,7 @@ void createItem (TabItem item, int index) { item.handle = labelHandle;
System.arraycopy (items, index, items, index + 1, itemCount++ - index);
items [index] = item;
- OS.gtk_notebook_set_show_tabs (notebookHandle, true);
+ OS.gtk_notebook_set_show_tabs (handle, true);
}
/**
@@ -261,7 +257,7 @@ void destroyItem (TabItem item) { index++;
}
if (index == itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED);
- OS.gtk_notebook_remove_page (notebookHandle, index);
+ OS.gtk_notebook_remove_page (handle, index);
System.arraycopy (items, index + 1, items, index, --itemCount - index);
items [itemCount] = null;
item.handle = 0;
@@ -283,9 +279,8 @@ void destroyItem (TabItem item) { */
public TabItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
+ checkWidget();
+ int list = OS.gtk_container_children (handle);
int itemCount = OS.g_list_length (list);
if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM);
return items [index];
@@ -301,10 +296,9 @@ public TabItem getItem (int index) { * </ul> */
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//return itemCount;
- int list = OS.gtk_container_children (notebookHandle);
+ int list = OS.gtk_container_children (handle);
return OS.g_list_length (list);
}
/** @@ -324,9 +318,8 @@ public int getItemCount () { * </ul> */
public TabItem [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
+ checkWidget();
+ int list = OS.gtk_container_children (handle);
int itemCount = OS.g_list_length (list);
TabItem [] result = new TabItem [itemCount];
System.arraycopy (items, 0, result, 0, itemCount);
@@ -349,9 +342,8 @@ public TabItem [] getItems () { * </ul> */
public TabItem [] getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
+ checkWidget();
+ int index = OS.gtk_notebook_get_current_page (handle);
if (index == -1) return new TabItem [0];
return new TabItem [] {items [index]};
}
@@ -367,9 +359,8 @@ public TabItem [] getSelection () { * </ul> */
public int getSelectionIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return OS.gtk_notebook_get_current_page (notebookHandle);
+ checkWidget();
+ return OS.gtk_notebook_get_current_page (handle);
}
/** @@ -390,10 +381,9 @@ public int getSelectionIndex () { * </ul> */
public int indexOf (TabItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int list = OS.gtk_container_children (notebookHandle);
+ int list = OS.gtk_container_children (handle);
int itemCount = OS.g_list_length (list);
for (int i=0; i<itemCount; i++) {
if (items [i] == item) return i;
@@ -402,7 +392,7 @@ public int indexOf (TabItem item) { }
int processSelection (int int0, int int1, int int2) {
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
+ int index = OS.gtk_notebook_get_current_page (handle);
if (index != -1) {
Control control = items [index].getControl ();
if (control != null && !control.isDisposed ()) {
@@ -461,9 +451,9 @@ public void removeSelectionListener (SelectionListener listener) { public void setSelection (int index) {
checkWidget();
if (index == -1) return;
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_set_page (notebookHandle, index);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
+ OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
+ OS.gtk_notebook_set_page (handle, index);
+ OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
}
/** @@ -479,8 +469,7 @@ public void setSelection (int index) { * </ul> */
public void setSelection (TabItem [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
if (items.length == 0) {
setSelection (-1);
@@ -498,11 +487,11 @@ public void setSelection (TabItem [] items) { void deregister () {
super.deregister ();
- WidgetTable.remove (notebookHandle);
+ WidgetTable.remove (topHandle);
}
void releaseChildren() {
- int list = OS.gtk_container_children (notebookHandle);
+ int list = OS.gtk_container_children (handle);
int itemCount = OS.g_list_length (list);
for (int i=0; i<itemCount; i++) {
TabItem item = items [i];
@@ -529,7 +518,7 @@ void releaseChildren() { void releaseHandle () {
super.releaseHandle ();
- notebookHandle = 0;
+ boxHandle = 0;
}
void releaseWidget () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index d45196a62b..efa5cf9075 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -42,7 +42,6 @@ public class Table extends Composite { int check_width, check_height; public static int MAX_COLUMNS = 32; - /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -84,19 +83,25 @@ public Table (Composite parent, int style) { void createHandle (int index) { state |= HANDLE; + + boxHandle = OS.gtk_event_box_new(); + if (boxHandle==0) error(SWT.ERROR_NO_HANDLES); - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - fixedHandle = OS.gtk_fixed_new(); + fixedHandle = OS.eclipse_fixed_new(); if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); handle = OS.gtk_clist_new (MAX_COLUMNS); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - + scrolledHandle = OS.gtk_scrolled_window_new (0, 0); if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); } +void configure() { + parent._connectChild(topHandle()); + OS.gtk_container_add (boxHandle, fixedHandle); + OS.gtk_container_add (fixedHandle, scrolledHandle); + OS.gtk_container_add (scrolledHandle, handle); +} void setHandleStyle () { /* Single or Multiple Selection */ int selectionMode; @@ -118,31 +123,10 @@ void setHandleStyle () { int vscrollbar_policy = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_AUTOMATIC; OS.gtk_scrolled_window_set_policy (scrolledHandle, hscrollbar_policy, vscrollbar_policy); } -void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put (fixedHandle, scrolledHandle, (short)0, (short)0); - OS.gtk_container_add (scrolledHandle, handle); -} -static int checkStyle (int style) { - /* - * To be compatible with Windows, force the H_SCROLL - * and V_SCROLL style bits. On Windows, it is not - * possible to create a table without scroll bars. - */ - style |= SWT.H_SCROLL | SWT.V_SCROLL; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint == SWT.DEFAULT) wHint = 200; - return _computeSize (wHint, hHint, changed); -} void showHandle() { - OS.gtk_widget_show (eventBoxHandle); + OS.gtk_widget_show (boxHandle); OS.gtk_widget_show (fixedHandle); OS.gtk_widget_show (scrolledHandle); OS.gtk_widget_show (handle); @@ -153,18 +137,21 @@ void showHandle() { check = createCheckPixmap(true); } } +void hookEvents () { + //TO DO - get rid of enter/exit for mouse crossing border + super.hookEvents (); + signal_connect (handle, "select_row", SWT.Selection, 5); +} int createCheckPixmap(boolean checked) { /* * The box will occupy the whole item width. */ - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); check_height = clist.row_height-1; check_width = check_height; - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); + GdkVisual visual = new GdkVisual(OS.gdk_visual_get_system()); int pixmap = OS.gdk_pixmap_new(0, check_width, check_height, visual.depth); int gc = OS.gdk_gc_new(pixmap); @@ -199,11 +186,6 @@ int createCheckPixmap(boolean checked) { return pixmap; } -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents (); - signal_connect (handle, "select_row", SWT.Selection, 5); -} void createWidget (int index) { super.createWidget (index); @@ -215,30 +197,24 @@ void createWidget (int index) { /* * HANDLE CODE 2 */ -int topHandle() { return eventBoxHandle; } +int topHandle() { return boxHandle; } int parentingHandle() { return fixedHandle; } -boolean isMyHandle(int h) { - if (h==eventBoxHandle) return true; - if (h==scrolledHandle) return true; - if (h==fixedHandle) return true; - if (h==handle) return true; - return false; - -} - /* * === GEOMETRY === */ -boolean _setSize(int width, int height) { - boolean different = UtilFuncs.setSize(eventBoxHandle, width, height); - if (different) UtilFuncs.setSize(fixedHandle, width, height); - if (different) UtilFuncs.setSize(scrolledHandle, width, height); - return different; +void _setSize(int width, int height) { + OS.eclipse_fixed_set_size(parent.parentingHandle(), topHandle(), width, height); + OS.eclipse_fixed_set_size(fixedHandle, scrolledHandle, width, height); } +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + if (wHint == SWT.DEFAULT) wHint = 200; + return computeNativeSize (scrolledHandle, wHint, hHint, changed); +} /** * Adds the listener to the collection of listeners who will * be notified when the receiver's selection changes, by sending @@ -543,8 +519,7 @@ public TableItem getItem (int index) { public TableItem getItem (Point pt) { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int clientX = pt.x; int clientY = pt.y - clist.column_title_area_height; if (clientY <= 0) return null; @@ -584,8 +559,7 @@ public int getItemCount () { */ public int getItemHeight () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); return clist.row_height; } /** @@ -642,8 +616,7 @@ public TableItem[] getSelection () { * Get the selection from the OS. */ private TableItem[] _getNativeSelection () { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); switch (clist.selection_mode) { case OS.GTK_SELECTION_SINGLE: return getSelection_single(); case OS.GTK_SELECTION_BROWSE: return getSelection_browse(); @@ -655,8 +628,7 @@ private TableItem[] _getNativeSelection () { return null; } private TableItem[] getSelection_single () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); if (clist.selection==0) return new TableItem[0]; int length = OS.g_list_length (clist.selection); if (length == 0) return new TableItem[0]; @@ -665,8 +637,7 @@ private TableItem[] getSelection_single () { } private TableItem[] getSelection_browse () { /* same as single */ - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); if (clist.selection==0) return new TableItem[0]; int length = OS.g_list_length (clist.selection); if (length == 0) return new TableItem[0]; @@ -674,8 +645,7 @@ private TableItem[] getSelection_browse () { return new TableItem [] {items[index]}; } private TableItem[] getSelection_multiple () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); if (clist.selection==0) return new TableItem[0]; int length = OS.g_list_length (clist.selection); TableItem [] result = new TableItem [length]; @@ -686,8 +656,7 @@ private TableItem[] getSelection_multiple () { return result; } private TableItem[] getSelection_extended () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); if (clist.selection==0) return new TableItem[0]; int length = OS.g_list_length (clist.selection); TableItem [] result = new TableItem [length]; @@ -713,8 +682,7 @@ public int getSelectionCount () { return selection.length; } private int _getNativeSelectionCount () { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int selectionList = clist.selection; if (selectionList==0) return 0; return OS.g_list_length (clist.selection); @@ -732,8 +700,7 @@ private int _getNativeSelectionCount () { */ public int getSelectionIndex () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int list = clist.selection; if (OS.g_list_length (list) == 0) return -1; return OS.g_list_nth_data (list, 0); @@ -755,8 +722,7 @@ public int getSelectionIndex () { */ public int [] getSelectionIndices () { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); int list = widget.selection; int length = OS.g_list_length (list); int [] indices = new int [length]; @@ -781,8 +747,7 @@ public int [] getSelectionIndices () { */ public boolean isSelected (int index) { checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); + GtkCList widget = new GtkCList (handle); int list = widget.selection; int length = OS.g_list_length (list); for (int i=0; i<length; i++) { @@ -809,8 +774,7 @@ public boolean isSelected (int index) { */ public int getTopIndex () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); return -clist.voffset / (clist.row_height + 1); } @@ -1148,12 +1112,17 @@ public void setHeaderVisible (boolean show) { */ // boolean isVisibleNow = getHeaderVisible(); // if (show==isVisibleNow) return; - if (show) { + +/* GTK2 FIXME. + * FOR SOME REASON, titles_show CAUSES A SEGFAULT IN show_now ON THE SHELL. + * VERY WEIRD. + */ + +/* if (show) { OS.gtk_clist_column_titles_show (handle); - OS.gtk_clist_column_titles_passive(handle); } else { OS.gtk_clist_column_titles_hide (handle); - } + }*/ } /** * Returns <code>true</code> if the receiver's lines are visible, @@ -1362,33 +1331,37 @@ int processMouseDown (int callData, int arg1, int int2) { OS.gtk_widget_grab_focus(handle); // First, see if we have a single or double click - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - boolean isDoubleClick = (gdkEvent.type == OS.GDK_2BUTTON_PRESS); + boolean isDoubleClick = (OS.gdk_event_button_get_button(callData)==2); // We can't just use the x and y coordinates from the Gdk event, // because the actual items are drawn on a special X window - Point where = _gdkWindowGetPointer(); + int[] ppx = new int[1], ppy = new int[1]; + OS.gdk_window_get_pointer(OS.GTK_WIDGET_WINDOW(handle), ppx, ppy, 0); int eventType; if (isDoubleClick) { eventType = SWT.MouseDoubleClick; Event event = new Event (); event.item=itemBeingSelected; - event.x = where.x; event.y = where.y; + event.x = ppx[0]; event.y = ppy[0]; sendEvent (SWT.DefaultSelection, event); return 1; } eventType = SWT.MouseDown; - sendMouseEvent (eventType, gdkEvent.button, gdkEvent.state, gdkEvent.time, where.x, where.y); - if (gdkEvent.button == 3 && menu != null) menu.setVisible (true); - + int[] pMod = new int[1]; + OS.gdk_event_get_state(callData, pMod); + int time = OS.gdk_event_get_time(callData); + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int button = OS.gdk_event_button_get_button(callData); + sendMouseEvent (eventType, button, pMod[0], time, (int)(px[0]), (int)(py[0])); + if (button == 3 && menu != null) menu.setVisible (true); if ((style&SWT.CHECK) != 0) { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int clientX = where.x; - int clientY = where.y - clist.column_title_area_height; + GtkCList clist = new GtkCList (handle); + int clientX = ppx[0]; + int clientY = ppy[0] - clist.column_title_area_height; if (clientY <= 0) return 1; int[] row = new int[1], column = new int[1]; row[0] = -1; @@ -1408,4 +1381,13 @@ int processMouseDown (int callData, int arg1, int int2) { return 1; } +static int checkStyle (int style) { + /* + * To be compatible with Windows, force the H_SCROLL + * and V_SCROLL style bits. On Windows, it is not + * possible to create a table without scroll bars. + */ + style |= SWT.H_SCROLL | SWT.V_SCROLL; + return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java index eab13dbec9..ab90cadaa8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java @@ -220,11 +220,9 @@ public boolean getResizable () { if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
int index = parent.indexOf (this);
if (index == -1) return false;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
+ GtkCList gtkclist = new GtkCList(parent.handle);
int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
+ GtkCListColumn gtkcolumn = new GtkCListColumn(chandle+index*GtkCListColumn.sizeof);
return (gtkcolumn.resizeable == 1) ? true : false;
}
/** @@ -242,11 +240,9 @@ public int getWidth () { if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
int index = parent.indexOf (this);
if (index == -1) return 0;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
+ GtkCList gtkclist = new GtkCList(parent.handle);
int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
+ GtkCListColumn gtkcolumn = new GtkCListColumn(chandle+index*GtkCListColumn.sizeof);
return gtkcolumn.width;
}
/** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java index 79b36708ce..3bc6be852e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java @@ -100,24 +100,6 @@ public TableItem (Table parent, int style, int index) { parent.createItem (this, index);
_setChecked(false);
}
-/**
- * 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>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- Table parent = getParent();
- return parent.getBackground();
-}
/** * Returns a rectangle describing the receiver's size and location * relative to its parent at a column in the table. @@ -131,20 +113,15 @@ public Color getBackground () { * </ul> */
public Rectangle getBounds (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int CELL_SPACING=1;
- GtkCList table = new GtkCList();
- OS.memmove(table, parent.handle, GtkCList.sizeof);
+ GtkCList table = new GtkCList(parent.handle);
int columnHandle = table.column;
columnHandle= columnHandle+index*GtkCListColumn.sizeof;
- GtkCListColumn column=new GtkCListColumn();
- OS.memmove(column, columnHandle, GtkCListColumn.sizeof);
- GtkAdjustment adjustment=new GtkAdjustment();
- OS.memmove(adjustment, table.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove(adjustment, table.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
+ GtkCListColumn column=new GtkCListColumn(columnHandle);
+
+ double haj = OS.gtk_adjustment_get_value(table.hadjustment);
+ double vaj = OS.gtk_adjustment_get_value(table.vadjustment);
int x=(short)column.area_x+table.hoffset;
int width=(short)column.area_width;
int height=parent.getItemHeight();
@@ -198,24 +175,6 @@ public Display getDisplay () { if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
return parent.getDisplay ();
}
-/**
- * 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>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- Table parent = getParent();
- return parent.getForeground();
-}
/** * Returns <code>true</code> if the receiver is grayed, * and false otherwise. When the parent does not have @@ -337,29 +296,6 @@ void releaseWidget () { super.releaseWidget ();
parent = null;
}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument 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>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
-}
/** * Sets the checked state of the receiver. * @@ -385,30 +321,6 @@ void _setChecked (boolean checked) { else OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.uncheck, 0);
}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument 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>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
/** * Sets the grayed state of the receiver. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index b6f5f5c74e..f9169e60e7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -86,19 +86,17 @@ void createHandle (int index) { } void setHandleStyle() { - OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); + /*OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); if ((style & SWT.SINGLE) == 0) OS.gtk_text_set_word_wrap (handle, (style & SWT.WRAP) != 0 ? 1 : 0); if (scrolledHandle!=0) setScrollingPolicy(); - // When 2.0 arrives, we'll be able to set the flat appearance + // When 2.0 arrives, we'll be able to set the flat appearance*/ } void configure() { - _connectParent(); - if (scrolledHandle != 0) { - OS.gtk_container_add (scrolledHandle, handle); - } + parent._connectChild(topHandle()); + if (scrolledHandle != 0) OS.gtk_container_add (scrolledHandle, handle); } void showHandle() { @@ -109,11 +107,11 @@ void showHandle() { void hookEvents () { //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents(); +/* super.hookEvents(); signal_connect_after (handle, "changed", SWT.Modify, 2); - signal_connect (handle, "insert_text", SWT.Verify, 5); - signal_connect (handle, "delete_text", SWT.Verify, 4); - signal_connect (handle, "activate", SWT.Selection, 2); + signal_connect (handle, "insert-text", SWT.Verify, 5); + signal_connect (handle, "delete-text", SWT.Verify, 4); + signal_connect (handle, "activate", SWT.Selection, 2);*/ } /** @@ -192,8 +190,7 @@ public void addSelectionListener(SelectionListener listener) { * @see #removeVerifyListener */ public void addVerifyListener (VerifyListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Verify, typedListener); @@ -218,7 +215,7 @@ public void addVerifyListener (VerifyListener listener) { */ public void append (String string) { checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + /*if (string == null) error (SWT.ERROR_NULL_ARGUMENT); byte [] buffer = Converter.wcsToMbcs (null, string); if ((style & SWT.SINGLE) != 0) { OS.gtk_entry_append_text(handle, buffer); @@ -227,17 +224,9 @@ public void append (String string) { int [] position = new int [] {length}; OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); OS.gtk_editable_set_position (handle, position [0]); - } + }*/ } -static int checkStyle (int style) { - if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style; - if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { - return style | SWT.MULTI; - } - return style | SWT.SINGLE; -} /** * Clears the selection. * @@ -248,9 +237,9 @@ static int checkStyle (int style) { */ public void clearSelection () { checkWidget (); - int position = OS.gtk_editable_get_position (handle); + /*int position = OS.gtk_editable_get_position (handle); OS.gtk_editable_delete_selection(handle); - OS.gtk_editable_set_position (handle, position); + OS.gtk_editable_set_position (handle, position);*/ } /** @@ -266,14 +255,14 @@ public void clearSelection () { */ public void copy () { checkWidget (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); + /*byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); OS.gtk_selection_owner_set(handle, OS.gdk_atom_intern(clipboard, 0), 0); GtkEditable widget = new GtkEditable (); OS.memmove(widget, handle, GtkEditable.sizeof); int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); widget.clipboard_text = OS.gtk_editable_get_chars(handle, start, end); - OS.memmove (handle, widget, GtkEditable.sizeof); + OS.memmove (handle, widget, GtkEditable.sizeof);*/ } /** * Cuts the selected text. @@ -292,7 +281,7 @@ public void copy () { */ public void cut () { checkWidget (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); + /*byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); OS.gtk_selection_owner_set(handle, OS.gdk_atom_intern(clipboard, 0), 0); GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); @@ -300,7 +289,7 @@ public void cut () { int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); widget.clipboard_text = OS.gtk_editable_get_chars(handle, start, end); OS.memmove (handle, widget, GtkEditable.sizeof); - OS.gtk_editable_delete_text(handle, start, end); + OS.gtk_editable_delete_text(handle, start, end);*/ } /** @@ -321,9 +310,10 @@ public void cut () { */ public int getCaretLineNumber () { checkWidget (); - int addr_index=getCaretPosition(); + /*int addr_index=getCaretPosition(); String tmpString= new String(getText(0,addr_index)); - return getLineNumberInString(tmpString,'\n'); + return getLineNumberInString(tmpString,'\n');*/ + return 0; } /** @@ -341,9 +331,10 @@ public int getCaretLineNumber () { */ public Point getCaretLocation () { checkWidget (); - GtkText gtktext = new GtkText (); + /*GtkText gtktext = new GtkText (); OS.memmove (gtktext, handle, GtkText.sizeof); - return new Point (gtktext.cursor_pos_x, gtktext.cursor_pos_y); + return new Point (gtktext.cursor_pos_x, gtktext.cursor_pos_y);*/ + return new Point (0,0); } /** @@ -361,8 +352,8 @@ public Point getCaretLocation () { */ public int getCaretPosition () { checkWidget (); - //return OS.gtk_text_get_point (handle); - return OS.gtk_editable_get_position (handle); +// return OS.gtk_editable_get_position (handle); +return 0; } @@ -378,13 +369,14 @@ public int getCaretPosition () { */ public int getCharCount () { checkWidget (); - if ((style & SWT.SINGLE) != 0) { + /*if ((style & SWT.SINGLE) != 0) { int address = OS.gtk_editable_get_chars (handle, 0, -1); int length = OS.strlen (address); OS.g_free (address); return length; } - return OS.gtk_text_get_length (handle); + return OS.gtk_text_get_length (handle);*/ + return 0; } /** @@ -446,9 +438,10 @@ public char getEchoChar () { */ public boolean getEditable () { checkWidget (); - GtkEditable widget = new GtkEditable (); + /*GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); - return widget.editable!=0; + return widget.editable!=0;*/ + return true; } /** @@ -463,7 +456,8 @@ public boolean getEditable () { */ public int getLineCount () { checkWidget (); - return getLineNumberInString(new String(getText()),'\n') + 1; + /*return getLineNumberInString(new String(getText()),'\n') + 1;*/ + return 0; } /** * Gets the height of a line. @@ -476,12 +470,13 @@ public int getLineCount () { * </ul> */ public int getLineHeight () { - checkWidget (); + checkWidget ();/* Font font = getFont(); GdkFont gdkfont = new GdkFont(); int fontHandle = font.handle; OS.memmove(gdkfont, fontHandle, GdkFont.sizeof); - return gdkfont.ascent + gdkfont.descent; + return gdkfont.ascent + gdkfont.descent;*/ + return 10; } /** @@ -501,9 +496,10 @@ public int getLineHeight () { */ public Point getSelection () { checkWidget (); - GtkEditable widget = new GtkEditable (); + /*GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); - return new Point (widget.selection_start_pos, widget.selection_end_pos); + return new Point (widget.selection_start_pos, widget.selection_end_pos);*/ + return new Point(0,0); } /** * Gets the number of selected characters. @@ -517,11 +513,12 @@ public Point getSelection () { */ public int getSelectionCount () { checkWidget (); - GtkEditable widget = new GtkEditable (); + /*GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); - return end - start; + return end - start;*/ + return 0; } /** * Gets the selected text. @@ -535,7 +532,7 @@ public int getSelectionCount () { */ public String getSelectionText () { checkWidget (); - GtkEditable widget = new GtkEditable (); + /*GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); int start = Math.min(widget.selection_start_pos,widget.selection_end_pos); int end = Math.max(widget.selection_start_pos,widget.selection_end_pos); @@ -545,7 +542,8 @@ public String getSelectionText () { OS.memmove (buffer1, address, length); OS.g_free (address); char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); + return new String (buffer2, 0, buffer2.length);*/ + return ""; } /** @@ -565,9 +563,10 @@ public String getSelectionText () { */ public int getTabs () { checkWidget (); - GtkText widget= new GtkText(); + /*GtkText widget= new GtkText(); OS.memmove(widget, handle, GtkText.sizeof); - return widget.default_tab_width; + return widget.default_tab_width;*/ + return 8; } /** @@ -585,13 +584,17 @@ public int getTabs () { */ public String getText () { checkWidget (); - int address = OS.gtk_editable_get_chars (handle, 0, -1); - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); + if ((style & SWT.SINGLE) != 0) { + /* FIXME - MIXING LENGTH WITH SIZE! */ + int address = OS.gtk_entry_get_text (handle); + int length = OS.strlen (address); + byte [] buffer1 = new byte [length]; + OS.memmove (buffer1, address, length); + OS.g_free (address); + char [] buffer2 = Converter.mbcsToWcs (null, buffer1); + return new String (buffer2, 0, buffer2.length); + } + return ""; } /** @@ -659,12 +662,13 @@ public int getTextLimit () { */ public int getTopIndex () { checkWidget (); - if ((style & SWT.SINGLE) != 0) return 0; + /*if ((style & SWT.SINGLE) != 0) return 0; GtkText widget = new GtkText (); OS.memmove (widget, handle, GtkText.sizeof); int topCharIndex=widget.first_line_start_index; return (getLineNumberInString(getText(0,topCharIndex), '\n')); - //Since getText uses substring (start, end + 1),so topCharIndex-1 + //Since getText uses substring (start, end + 1),so topCharIndex-1*/ + return 0; } /** @@ -689,10 +693,11 @@ public int getTopIndex () { */ public int getTopPixel () { checkWidget (); - if ((style & SWT.SINGLE) != 0) return 0; + /*if ((style & SWT.SINGLE) != 0) return 0; GtkText widget= new GtkText(); OS.memmove(widget, handle, GtkText.sizeof); - return widget.first_onscreen_ver_pixel; + return widget.first_onscreen_ver_pixel;*/ + return 0; } boolean getWrap () { @@ -715,7 +720,7 @@ boolean getWrap () { */ public void insert (String string) { checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + /*if (string == null) error (SWT.ERROR_NULL_ARGUMENT); byte [] buffer = Converter.wcsToMbcs (null, string); GtkEditable widget = new GtkEditable (); OS.memmove (widget, handle, GtkEditable.sizeof); @@ -723,7 +728,7 @@ public void insert (String string) { int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); OS.gtk_editable_delete_text (handle, start, end); int [] position = new int [] {start}; - OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); + OS.gtk_editable_insert_text (handle, buffer, buffer.length, position);*/ } /** @@ -740,11 +745,11 @@ public void insert (String string) { */ public void paste () { checkWidget (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); + /*byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); byte [] compound = Converter.wcsToMbcs (null, "COMPOUND_TEXT", true); int clipboard_atom = OS.gdk_atom_intern (clipboard, 0); int compound_atom = OS.gdk_atom_intern (compound, 0); - OS.gtk_selection_convert(handle, clipboard_atom, compound_atom, 0); + OS.gtk_selection_convert(handle, clipboard_atom, compound_atom, 0);*/ } int processModify (int arg0, int arg1, int int2) { @@ -753,7 +758,7 @@ int processModify (int arg0, int arg1, int int2) { } int processVerify (int int0, int int1, int int2) { - if (!hooks (SWT.Verify)) return 0; + /*if (!hooks (SWT.Verify)) return 0; if (int2 != 0) { // Insert if (int0 == 0 || int1==0){ @@ -798,7 +803,7 @@ int processVerify (int int0, int int1, int int2) { OS.gtk_signal_emit_stop_by_name (handle, delete_text); return 0; } - } + }*/ return 0; } @@ -890,7 +895,7 @@ public void removeVerifyListener (VerifyListener listener) { */ public void selectAll () { checkWidget (); - OS.gtk_editable_select_region (handle, 0, -1); + /*OS.gtk_editable_select_region (handle, 0, -1);*/ } /** @@ -929,9 +934,9 @@ public void setDoubleClickEnabled (boolean doubleClick) { */ public void setEchoChar (char echo) { checkWidget (); - if ((style & SWT.SINGLE) != 0) { + /*if ((style & SWT.SINGLE) != 0) { OS.gtk_entry_set_visibility (handle, visibility = echo == '\0'); - } + }*/ } /** @@ -946,7 +951,7 @@ public void setEchoChar (char echo) { */ public void setEditable (boolean editable) { checkWidget (); - OS.gtk_editable_set_editable (handle, editable); + /*OS.gtk_editable_set_editable (handle, editable);*/ } /** @@ -977,7 +982,7 @@ public void setEditable (boolean editable) { */ public void setSelection (int start) { checkWidget (); - OS.gtk_editable_set_position (handle, start); + /*OS.gtk_editable_set_position (handle, start);*/ } /** @@ -1009,8 +1014,8 @@ public void setSelection (int start) { */ public void setSelection (int start, int end) { checkWidget (); - OS.gtk_editable_set_position (handle, start); - OS.gtk_editable_select_region (handle, start, end); + /*OS.gtk_editable_set_position (handle, start); + OS.gtk_editable_select_region (handle, start, end);*/ } /** @@ -1042,8 +1047,8 @@ public void setSelection (int start, int end) { public void setSelection (Point selection) { checkWidget (); if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_editable_set_position (handle, selection.x); - OS.gtk_editable_select_region (handle, selection.x, selection.y); + /*OS.gtk_editable_set_position (handle, selection.x); + OS.gtk_editable_select_region (handle, selection.x, selection.y);*/ } /** @@ -1064,9 +1069,9 @@ public void setSelection (Point selection) { */ public void setTabs (int tabs) { checkWidget (); - GtkText widget= new GtkText(); + /*GtkText widget= new GtkText(); widget.default_tab_width=tabs; - OS.memmove(handle, widget, GtkText.sizeof); + OS.memmove(handle, widget, GtkText.sizeof);*/ } /** @@ -1084,12 +1089,12 @@ public void setTabs (int tabs) { */ public void setText (String string) { checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + /*if (string == null) error (SWT.ERROR_NULL_ARGUMENT); OS.gtk_editable_delete_text (handle, 0, -1); int [] position = new int [1]; byte [] buffer = Converter.wcsToMbcs (null, string); OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); - OS.gtk_editable_set_position (handle, 0); + OS.gtk_editable_set_position (handle, 0);*/ } /** @@ -1108,11 +1113,11 @@ public void setText (String string) { */ public void setTextLimit (int limit) { checkWidget (); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); + /*if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); if ((style & SWT.SINGLE) != 0) { textLimit = (short) limit; OS.gtk_entry_set_max_length (handle, (short) limit); - } + }*/ } /** @@ -1129,11 +1134,10 @@ public void setTextLimit (int limit) { */ public void setTopIndex (int index) { checkWidget (); - if ((style & SWT.SINGLE) != 0) return; + /*if ((style & SWT.SINGLE) != 0) return; if (index > getLineCount()) return; - GtkAdjustment adjustment = new GtkAdjustment(); int adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment(scrolledHandle); - OS.memmove(adjustment, adjustmentHandle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment(adjustmentHandle); int adjust = (int)(index*adjustment.upper/getLineCount()); if (adjust <= 0) { adjust = 0; @@ -1149,12 +1153,12 @@ public void setTopIndex (int index) { verticalBar.setSelection(adjust+lineheight); OS.gtk_adjustment_value_changed(verticalBar.handle); topindex=getTopIndex(); - } + } */ } void setWrap (boolean wrap) { checkWidget (); - OS.gtk_text_set_word_wrap(handle, wrap ? 1 : 0); + /*OS.gtk_text_set_word_wrap(handle, wrap ? 1 : 0);*/ } /** @@ -1175,7 +1179,7 @@ void setWrap (boolean wrap) { */ public void showSelection () { checkWidget (); - if ((style & SWT.SINGLE) != 0) return; + /*if ((style & SWT.SINGLE) != 0) return; int start_pos, end_pos, pos; pos = OS.gtk_editable_get_position (handle); GtkEditable widget = new GtkEditable (); @@ -1188,9 +1192,8 @@ public void showSelection () { if ( (topCharIndex > start_pos && topCharIndex < end_pos) || topCharIndex==start_pos || topCharIndex == end_pos) return; if (pos < start_pos || pos > end_pos) { - GtkAdjustment adjustment = new GtkAdjustment(); int adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment(scrolledHandle); - OS.memmove(adjustment, adjustmentHandle, GtkAdjustment.sizeof); + GtkAdjustment adjustment = new GtkAdjustment(adjustmentHandle); String tmpString= new String(getText(0,start_pos)); int currentln=getLineNumberInString(tmpString, '\n'); int adjust = (int)(currentln*adjustment.upper/getLineCount()-adjustment.page_increment); @@ -1202,17 +1205,18 @@ public void showSelection () { OS.gtk_editable_set_position (handle, widget.selection_end_pos); OS.gtk_editable_select_region (handle, widget.selection_start_pos, widget.selection_end_pos); } - +*/ } String verifyText (String string, int start, int end) { - Event event = new Event (); + /*Event event = new Event (); event.text = string; event.start = start; event.end = end; sendEvent (SWT.Verify, event); if (!event.doit) return null; - return event.text; + return event.text;*/ + return ""; } int getLineNumberInString( String string,char delimiter) { @@ -1223,4 +1227,12 @@ int getLineNumberInString( String string,char delimiter) { return count; } +static int checkStyle (int style) { + if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); + if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style; + if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { + return style | SWT.MULTI; + } + return style | SWT.SINGLE; +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index e1e5bedcf0..899344800d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -31,9 +31,7 @@ import org.eclipse.swt.graphics.*; * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ - public class ToolBar extends Composite { - int boxHandle, tempHandle; /** * Constructs a new instance of this class given its parent @@ -67,80 +65,59 @@ public ToolBar (Composite parent, int style) { super (parent, checkStyle (style)); } +/* + * === Handle code === + */ void createHandle (int index) { state |= HANDLE; - /* FIXME - * We do not need an event box here, as event boxes - * have real X windows. - */ - boxHandle = OS.gtk_event_box_new (); + boxHandle = OS.gtk_event_box_new(); if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); + fixedHandle = OS.eclipse_fixed_new(); + if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); + int orientation = ((style&SWT.VERTICAL)!=0)? OS.GTK_ORIENTATION_VERTICAL : OS.GTK_ORIENTATION_HORIZONTAL; - handle = OS.gtk_toolbar_new (orientation, OS.GTK_TOOLBAR_BOTH); + handle = OS.gtk_toolbar_new (); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - tempHandle = OS.gtk_fixed_new(); - if (tempHandle == 0) error (SWT.ERROR_NO_HANDLES); + OS.gtk_toolbar_set_orientation(handle, orientation); } void setHandleStyle() { - int relief = ((style&SWT.FLAT)!=0)? OS.GTK_RELIEF_NONE : OS.GTK_RELIEF_NORMAL; - OS.gtk_toolbar_set_button_relief(handle, relief); +/* int relief = ((style&SWT.FLAT)!=0)? OS.GTK_RELIEF_NONE : OS.GTK_RELIEF_NORMAL; + OS.gtk_toolbar_set_button_relief(handle, relief);*/ } void configure() { - _connectParent(); - OS.gtk_container_add (boxHandle, handle); - // invisible handle to temporarily hold control (non-item) items - OS.gtk_toolbar_insert_widget (handle,tempHandle,new byte[1], new byte[1],0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (layout != null) super.computeSize(wHint, hHint, changed); - return _computeSize (wHint, hHint, changed); -} - -int eventHandle () { - return boxHandle; + parent._connectChild(boxHandle); + OS.gtk_container_add(boxHandle, fixedHandle); + OS.gtk_container_add(fixedHandle, handle); } void showHandle() { OS.gtk_widget_show (boxHandle); + OS.gtk_widget_show (fixedHandle); OS.gtk_widget_show (handle); OS.gtk_widget_realize (handle); - // don't show the temp fixed } void register() { super.register (); - WidgetTable.put (boxHandle, this); } void deregister() { super.deregister (); - WidgetTable.remove (boxHandle); } -int topHandle() { return boxHandle; } -int parentingHandle() { return tempHandle; } +void releaseHandle () { + super.releaseHandle (); +} -/** - * Returns whether the argument points to an OS widget that is - * implementing the receiver, i.e., one of my own handles - */ +int topHandle() { return boxHandle; } +int parentingHandle() { return fixedHandle; } boolean isMyHandle(int h) { - if (h==handle) return true; - if (h==tempHandle) return true; - if (h==boxHandle) return true; - return false; -} -void _connectChild (int h) { - // When we put a widget as a tool item, we don't know which item it is, yet. - OS.gtk_fixed_put(tempHandle, h, (short)0, (short)0); + return super.isMyHandle(h); } @@ -148,8 +125,16 @@ void _connectChild (int h) { * === GEOMETRY === */ -boolean _setSize (int width, int height) { UtilFuncs.setSize(boxHandle, width, height); return true; } +void _setSize (int width, int height) { + OS.eclipse_fixed_set_size(parent.parentingHandle(), boxHandle, width, height); + OS.eclipse_fixed_set_size(fixedHandle, handle, width, height); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + if (layout != null) super.computeSize(wHint, hHint, changed); + return new Point(300,30); +} /** @@ -168,8 +153,7 @@ boolean _setSize (int width, int height) { UtilFuncs.setSize(boxHandle, width, h * </ul> */ public ToolItem getItem (int index) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return getItems()[index]; } @@ -194,6 +178,7 @@ public ToolItem getItem (int index) { public ToolItem getItem (Point point) { return null; } + /** * Returns the number of items contained in the receiver. * @@ -205,17 +190,11 @@ public ToolItem getItem (Point point) { * </ul> */ public int getItemCount () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - /* FIXME - * This code will return the wrong count for items, - * as list includes Window children - */ -// int list = OS.gtk_container_children (handle); -// return OS.g_list_length (list); - // TEMPORARY CODE - return getItems ().length; + checkWidget(); + int list = OS.gtk_container_children (handle); + return OS.g_list_length (list); } + /** * Returns an array of <code>TabItem</code>s which are the items * in the receiver. @@ -233,8 +212,7 @@ public int getItemCount () { * </ul> */ public ToolItem [] getItems () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); int count = 0; int list = OS.gtk_container_children (handle); int length = OS.g_list_length (list); @@ -242,15 +220,11 @@ public ToolItem [] getItems () { for (int i=0; i<length; i++) { int data = OS.g_list_nth_data (list, i); Widget widget = WidgetTable.get (data); - if (widget instanceof ToolItem) { - result [count++] = (ToolItem) widget; - } + result [count++] = (ToolItem) widget; } - if (length == count) return result; - ToolItem [] newResult = new ToolItem [count]; - System.arraycopy (result, 0, newResult, 0, count); - return newResult; + return result; } + /** * Returns the number of rows in the receiver. When * the receiver has the <code>WRAP</code> style, the @@ -264,11 +238,9 @@ public ToolItem [] getItems () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ - public int getRowCount () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return 1; + checkWidget(); + return 1; /* On GTK, toolbars never wrap */ } Control _childFromHandle(int h) { @@ -297,8 +269,7 @@ Control _childFromHandle(int h) { * </ul> */ public int indexOf (ToolItem item) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); // TEMPORARY CODE @@ -308,21 +279,6 @@ public int indexOf (ToolItem item) { } return -1; } -int processResize (int int0, int int1, int int2) { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - Control control = items [i].control; - if (control != null && !control.isDisposed ()) { - control.setBounds (items [i].getBounds ()); - } - } - return 0; -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = tempHandle = 0; -} void releaseWidget () { ToolItem [] items = getItems (); @@ -345,7 +301,7 @@ static int checkStyle (int style) { * widget's client area. The fix is to clear * the SWT style. */ - return style; // & ~(SWT.H_SCROLL | SWT.V_SCROLL); + return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java index e20c76f1c0..8d8c8409c0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java @@ -24,17 +24,15 @@ import org.eclipse.swt.events.*; * </p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. */ - public class ToolItem extends Item { - int boxHandle; ToolBar parent; Control control; Image hotImage, disabledImage; + + int boxHandle, arrowHandle; + int currentpixmap; boolean drawHotImage; - int position; - boolean configured=false; - boolean shown=false; private int tooltipsHandle; /** @@ -70,8 +68,7 @@ public class ToolItem extends Item { public ToolItem (ToolBar parent, int style) { super (parent, checkStyle (style)); this.parent = parent; - position = parent.getItemCount (); - createWidget (position); + createWidget (parent.getItemCount ()); } /** * Constructs a new instance of this class given its parent @@ -111,9 +108,9 @@ public ToolItem (ToolBar parent, int style, int index) { if (!(0 <= index && index <= count)) { error (SWT.ERROR_ITEM_NOT_ADDED); } - position = index; createWidget (index); } + /** * Adds the listener to the collection of listeners who will * be notified when the control is selected, by sending @@ -140,88 +137,69 @@ public ToolItem (ToolBar parent, int style, int index) { * @see SelectionEvent */ public void addSelectionListener(SelectionListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Selection,typedListener); addListener (SWT.DefaultSelection,typedListener); } -static int checkStyle (int style) { - return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0); -} void createHandle (int index) { state |= HANDLE; - int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH; - switch (style & bits) { + switch (style & (SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH)) { + case SWT.PUSH: + case 0: + handle = OS.gtk_toolbar_insert_element (parent.handle, + OS.GTK_TOOLBAR_CHILD_BUTTON(), + 0, new byte[1], null, null, + 0, 0, 0, + index); + return; case SWT.RADIO: + handle = OS.gtk_toolbar_insert_element (parent.handle, + OS.GTK_TOOLBAR_CHILD_RADIOBUTTON(), + 0, new byte[1], null, null, + 0, 0, 0, + index); + return; case SWT.CHECK: - _createToggleHandle(index); return; + handle = OS.gtk_toolbar_insert_element (parent.handle, + OS.GTK_TOOLBAR_CHILD_TOGGLEBUTTON(), + 0, new byte[1], null, null, + 0, 0, 0, + index); + return; case SWT.SEPARATOR: - _createSeparatorHandle(index); return; - case SWT.PUSH: + boxHandle = OS.gtk_event_box_new(); + if (boxHandle==0) error(SWT.ERROR_NO_HANDLES); + boolean isVertical = (parent.getStyle()&SWT.VERTICAL) != 0; + handle = isVertical? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); + if (handle==0) error(SWT.ERROR_NO_HANDLES); + OS.gtk_toolbar_insert_widget ( + parent.handle, + boxHandle, + new byte[1], new byte[1], + index); + OS.gtk_container_add(boxHandle, handle); + OS.gtk_widget_show(boxHandle); + OS.gtk_widget_show(handle); + return; default: - _createPushHandle(index); return; + /* + * Can not specify more than one style + */ + error(SWT.ERROR_ITEM_NOT_ADDED); } } -private void _createSeparatorHandle(int index) { - boxHandle = OS.gtk_event_box_new(); - if (boxHandle==0) error(SWT.ERROR_NO_HANDLES); - boolean isVertical = (parent.getStyle()&SWT.VERTICAL) != 0; - handle = isVertical? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); - if (handle==0) error(SWT.ERROR_NO_HANDLES); -} -private void _createPushHandle(int index) { - handle = OS.gtk_toolbar_insert_element (parent.handle, - OS.GTK_TOOLBAR_CHILD_BUTTON, - 0, new byte[1], null, null, - 0, 0, 0, - index); - configured=true; - shown=true; -} -private void _createToggleHandle(int index) { - handle = OS.gtk_toolbar_insert_element (parent.handle, - OS.GTK_TOOLBAR_CHILD_TOGGLEBUTTON, - 0, new byte[1], null, null, - 0, 0, 0, - index); - configured=true; - shown=true; -} - - -void configure() { - // configure is done for non-separators - if (configured) return; - OS.gtk_toolbar_insert_widget ( - parent.handle, - topHandle(), - new byte[1], new byte[1], - position); - OS.gtk_container_add(boxHandle, handle); -} - -void showHandle() { - if (shown) return; - if ((parent.getStyle()&SWT.VERTICAL)!=0) OS.gtk_widget_set_usize(handle, 15, 3); - else OS.gtk_widget_set_usize(handle, 3, 15); - OS.gtk_widget_show(boxHandle); - OS.gtk_widget_show(handle); -} +/* Already done in createHandle() */ +void configure() {} +void showHandle() {} void register() { super.register (); - if (boxHandle != 0) WidgetTable.put (boxHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = 0; + if (boxHandle != 0) WidgetTable.put(boxHandle, this); } - void deregister() { super.deregister (); if (boxHandle != 0) WidgetTable.remove (boxHandle); @@ -244,12 +222,12 @@ int topHandle() { * </ul> */ public Rectangle getBounds () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Rectangle (widget.alloc_x, widget.alloc_y, widget.alloc_width, widget.alloc_height); + checkWidget(); + /*GtkWidget widget = new GtkWidget (handle); + return new Rectangle (widget.alloc_x, widget.alloc_y, widget.alloc_width, widget.alloc_height);*/ + return new Rectangle(2,2, 15,15); } + /** * Returns the control that is used to fill the bounds of * the item when the items is a <code>SEPARATOR</code>. @@ -262,8 +240,7 @@ public Rectangle getBounds () { * </ul> */ public Control getControl () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return control; } @@ -282,14 +259,12 @@ public Control getControl () { * </ul> */ public Image getDisabledImage () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); error(SWT.ERROR_NOT_IMPLEMENTED); return null; } public Display getDisplay () { - ToolBar parent = this.parent; if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); return parent.getDisplay (); } @@ -309,11 +284,8 @@ public Display getDisplay () { * </ul> */ public boolean getEnabled () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return (widget.flags & OS.GTK_SENSITIVE) != 0; + checkWidget(); + return OS.GTK_WIDGET_SENSITIVE(handle); } /** * Returns the receiver's hot image if it has one, or null @@ -330,10 +302,11 @@ public boolean getEnabled () { * </ul> */ public Image getHotImage () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); + /* NOT IMPLEMENTED */ return null; } + /** * Returns the receiver's parent, which must be a <code>ToolBar</code>. * @@ -345,10 +318,11 @@ public Image getHotImage () { * </ul> */ public ToolBar getParent () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); + if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); return parent; } + /** * Returns <code>true</code> if the receiver is selected, * and false otherwise. @@ -366,8 +340,7 @@ public ToolBar getParent () { * </ul> */ public boolean getSelection () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; return OS.gtk_toggle_button_get_active (handle); } @@ -382,10 +355,10 @@ public boolean getSelection () { * </ul> */ public String getToolTipText () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return ""; } + /** * Gets the width of the receiver. * @@ -397,11 +370,9 @@ public String getToolTipText () { * </ul> */ public int getWidth () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return widget.alloc_width; + checkWidget(); +/* FIXME */ + return 15; } void hookEvents () { if ((style & SWT.SEPARATOR) != 0) return; @@ -409,6 +380,7 @@ void hookEvents () { signal_connect(handle, "enter-notify-event", SWT.MouseEnter, 3); signal_connect(handle, "leave-notify-event", SWT.MouseExit, 3); } + /** * Returns <code>true</code> if the receiver is enabled, and * <code>false</code> otherwise. @@ -425,8 +397,7 @@ void hookEvents () { * </ul> */ public boolean isEnabled () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); return getEnabled () && parent.isEnabled (); } @@ -488,6 +459,7 @@ void releaseWidget () { tooltipsHandle = 0; parent = null; } + /** * Removes the listener from the collection of listeners who will * be notified when the control is selected. @@ -506,13 +478,13 @@ void releaseWidget () { * @see #addSelectionListener */ public void removeSelectionListener(SelectionListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); } + /** * Sets the control that is used to fill the bounds of * the item when the items is a <code>SEPARATOR</code>. @@ -538,11 +510,7 @@ public void setControl (Control control) { Control newControl = control; Control oldControl = this.control; if (oldControl == newControl) return; - if (oldControl != null) { - int topHandle = control.topHandle (); - int tempHandle = parent.tempHandle; - OS.gtk_widget_reparent (topHandle, tempHandle); - } + this.control = newControl; if (newControl != null) { if (handle != boxHandle) { @@ -550,9 +518,7 @@ public void setControl (Control control) { OS.gtk_widget_destroy (handle); handle = boxHandle; } - int topHandle = control.topHandle (); - OS.gtk_widget_reparent (topHandle, boxHandle); - //OS.gtk_widget_show (topHandle); + OS.gtk_widget_reparent (newControl.topHandle(), boxHandle); } else { boolean isVertical = (parent.getStyle () & SWT.VERTICAL) != 0; handle = isVertical ? OS.gtk_hseparator_new () : OS.gtk_vseparator_new (); @@ -578,11 +544,11 @@ public void setControl (Control control) { * </ul> */ public void setDisabledImage (Image image) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; disabledImage = image; } + /** * Enables the receiver if the argument is <code>true</code>, * and disables it otherwise. @@ -600,10 +566,10 @@ public void setDisabledImage (Image image) { * </ul> */ public void setEnabled (boolean enabled) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); OS.gtk_widget_set_sensitive (handle, enabled); } + /** * Sets the receiver's hot image to the argument, which may be * null indicating that no hot image should be displayed. @@ -622,14 +588,12 @@ public void setEnabled (boolean enabled) { * </ul> */ public void setHotImage (Image image) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; hotImage = image; } public void setImage (Image image) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); super.setImage (image); if ((style & SWT.SEPARATOR) != 0) return; int list = OS.gtk_container_children (handle); @@ -668,8 +632,7 @@ public void setSelection (boolean selected) { OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); } public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); if ((style & SWT.SEPARATOR) != 0) return; text = string; @@ -698,8 +661,7 @@ public void setText (String string) { int widget = OS.g_list_nth_data (list, 0); if (widget != 0) OS.gtk_widget_destroy (widget); } - byte [] buffer1 = Converter.wcsToMbcs (null, text); - int label = OS.gtk_label_new (buffer1); + int label = OS.gtk_label_new (string); byte [] buffer2 = Converter.wcsToMbcs (null, pattern); OS.gtk_label_set_pattern (label, buffer2); OS.gtk_container_add (handle, label); @@ -717,8 +679,7 @@ public void setText (String string) { * </ul> */ public void setToolTipText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if (tooltipsHandle == 0) tooltipsHandle = OS.gtk_tooltips_new(); byte [] buffer = Converter.wcsToMbcs (null, string, true); OS.gtk_tooltips_set_tip(tooltipsHandle, handle, buffer, null); @@ -734,11 +695,14 @@ public void setToolTipText (String string) { * </ul> */ public void setWidth (int width) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); + checkWidget(); if ((style & SWT.SEPARATOR) == 0) return; Point size = control.computeSize(width, SWT.DEFAULT); control.setSize(size); } + +static int checkStyle (int style) { + return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0); +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java index 9b0ca5408d..457a15393f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java @@ -172,8 +172,7 @@ public Display getDisplay () { }
/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
+ * Returns the bounds of the Rectangles being drawn.
*
* @return the bounds of the Rectangles being drawn
*
@@ -203,8 +202,7 @@ public boolean getStippled () { }
/**
- * Specify the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
+ * Specify the rectangles that should be drawn.
*
* @param rectangles the bounds of the rectangles to be drawn
*
@@ -379,7 +377,7 @@ private int calculateWindow() { if (parent == null) {
answer = OS.GDK_ROOT_PARENT();
} else {
- answer = parent._gdkWindow();
+ answer = /*parent._gdkWindow();*/ 0;
}
if (answer==0) error(SWT.ERROR_UNSPECIFIED);
return answer;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 95833415cb..c84686edbe 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -89,14 +89,9 @@ static int checkStyle (int style) { return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); } -Point _getClientAreaSize () { - return UtilFuncs.getSize(handle); -} - -boolean _setSize(int width, int height) { - if (!UtilFuncs.setSize (eventBoxHandle, width, height)) return false; - UtilFuncs.setSize (scrolledHandle, width, height); - return true; +void _setSize(int width, int height) { + OS.eclipse_fixed_set_size(parent.parentingHandle(), topHandle(), width, height); + OS.eclipse_fixed_set_size(fixedHandle, scrolledHandle, width, height); } /** @@ -163,23 +158,16 @@ public void addTreeListener(TreeListener listener) { public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint == SWT.DEFAULT) wHint = 200; - return _computeSize (wHint, hHint, changed); -} - -void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put (fixedHandle, scrolledHandle, (short)0, (short)0); - OS.gtk_container_add (scrolledHandle, handle); + return computeNativeSize (scrolledHandle, wHint, hHint, changed); } void createHandle (int index) { state |= HANDLE; - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); + boxHandle = OS.gtk_event_box_new(); + if (boxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new (); + fixedHandle = OS.eclipse_fixed_new (); if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); scrolledHandle = OS.gtk_scrolled_window_new(0,0); @@ -188,18 +176,34 @@ void createHandle (int index) { handle = OS.gtk_ctree_new (1, 0); if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); } +void configure() { + parent._connectChild(topHandle()); + OS.gtk_container_add (boxHandle, fixedHandle); + OS.gtk_container_add (fixedHandle, scrolledHandle); + OS.gtk_container_add (scrolledHandle, handle); +} + +void hookEvents () { + //TO DO - get rid of enter/exit for mouse crossing border + super.hookEvents (); + signal_connect (handle, "tree_select_row", SWT.Selection, 4); + signal_connect (handle, "tree_unselect_row", SWT.Selection, 4); + signal_connect (handle, "tree_expand", SWT.Expand, 3); + signal_connect (handle, "tree_collapse", SWT.Collapse, 3); +} + +int topHandle() { return boxHandle; } +int parentingHandle() { return fixedHandle; } int createCheckPixmap(boolean checked) { /* * The box will occupy the whole item width. */ - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int check_height = clist.row_height-1; int check_width = check_height; - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); + GdkVisual visual = new GdkVisual(OS.gdk_visual_get_system()); int pixmap = OS.gdk_pixmap_new(0, check_width, check_height, visual.depth); int gc = OS.gdk_gc_new(pixmap); @@ -314,8 +318,7 @@ int findSibling (int node, int index) { int depth = 1; if (node != 0) { int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); + GtkCTreeRow row = new GtkCTreeRow (data); depth = row.level + 1; } Index = 0; @@ -384,8 +387,7 @@ int getItemCount (int node) { int depth = 1; if (node != 0) { int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); + GtkCTreeRow row = new GtkCTreeRow (data); depth = row.level + 1; } Count = 0; @@ -409,8 +411,7 @@ int getItemCount (int node) { */ public int getItemHeight () { checkWidget (); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); return clist.row_height + CELL_SPACING; } @@ -440,8 +441,7 @@ TreeItem [] getItems (int node) { int depth = 1; if (node != 0) { int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); + GtkCTreeRow row = new GtkCTreeRow (data); depth = row.level + 1; } Count = 0; @@ -495,8 +495,7 @@ public TreeItem getParentItem () { */ public TreeItem[] getSelection () { checkWidget(); - GtkCList clist = new GtkCList(); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList(handle); if (clist.selection == 0) return new TreeItem [0]; int length = OS.g_list_length (clist.selection); TreeItem [] result = new TreeItem [length]; @@ -520,8 +519,7 @@ public TreeItem[] getSelection () { */ public int getSelectionCount () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); if (clist.selection == 0) return 0; return OS.g_list_length (clist.selection); } @@ -556,25 +554,6 @@ int GtkCTreeDispose (int ctree, int node, int data) { return 0; } -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents (); - signal_connect (handle, "tree_select_row", SWT.Selection, 4); - signal_connect (handle, "tree_unselect_row", SWT.Selection, 4); - signal_connect (handle, "tree_expand", SWT.Expand, 3); - signal_connect (handle, "tree_collapse", SWT.Collapse, 3); -} - -int topHandle() { return eventBoxHandle; } -int parentingHandle() { return fixedHandle; } - -boolean isMyHandle(int h) { - if (h==fixedHandle) return true; - if (h==scrolledHandle) return true; - if (h==handle) return true; - return false; -} - int processCollapse (int int0, int int1, int int2) { int index = OS.gtk_ctree_node_get_row_data (handle, int0) - 1; Event event = new Event (); @@ -610,10 +589,11 @@ int processExpand (int int0, int int1, int int2) { int processMouseDown (int callData, int arg1, int int2) { doubleSelected = false; int result = super.processMouseDown (callData, arg1, int2); - if ((style & SWT.MULTI) != 0) selected = true; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; +/* if ((style & SWT.MULTI) != 0) selected = true; + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int x = (int)(px[0]), y = (int)(py[0]); if ((style & SWT.CHECK) != 0) { if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { int [] row = new int [1], column = new int [1]; @@ -621,10 +601,8 @@ int processMouseDown (int callData, int arg1, int int2) { if (code != 0) { int node = OS.gtk_ctree_node_nth (handle, row [0]); int crow = OS.g_list_nth_data (node, 0); - GtkCTreeRow row_data = new GtkCTreeRow (); - OS.memmove (row_data, crow, GtkCTreeRow.sizeof); - GtkCTree ctree = new GtkCTree(); - OS.memmove (ctree, handle, GtkCTree.sizeof); + GtkCTreeRow row_data = new GtkCTreeRow (crow); + GtkCTree ctree = new GtkCTree(handle); int nX = ctree.hoffset + ctree.tree_indent * row_data.level - 2; int nY = ctree.voffset + (ctree.row_height + 1) * row [0] + 2; int [] unused = new int [1], check_width = new int [1], check_height = new int [1]; @@ -648,13 +626,14 @@ int processMouseDown (int callData, int arg1, int int2) { } } } + GdkEvent gdkEvent = new GdkEvent(callData); if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) { if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { int [] row = new int [1], column = new int [1]; int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); if (code != 0) doubleSelected = true; } - } + }*/ return result; } @@ -672,13 +651,13 @@ int processMouseUp (int callData, int arg1, int int2) { * that caused the select signal is not included when the select * signal is issued. */ - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; + double[] px = new double[1]; + double[] py = new double[1]; + OS.gdk_event_get_coords(callData, px, py); + int x = (int)(px[0]), y = (int)(py[0]); if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { if ((style & SWT.SINGLE) != 0) { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int list = clist.selection; if (list != 0 && OS.g_list_length (list) != 0) { int node = OS.g_list_nth_data (list, 0); @@ -698,8 +677,7 @@ int processMouseUp (int callData, int arg1, int int2) { int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); if (code != 0) { int focus = OS.gtk_ctree_node_nth (handle, row [0]); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); if (selected && clist.selection != 0) { int length = OS.g_list_length (clist.selection); for (int i=0; i<length; i++) { @@ -729,8 +707,7 @@ int processSelection (int int0, int int1, int int2) { selected = true; return 0; } - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); int focus = OS.gtk_ctree_node_nth (handle, clist.focus_row); if (focus != int0) return 0; if ((style & SWT.MULTI) != 0) selected = false; @@ -886,19 +863,6 @@ public void setSelection (TreeItem [] items) { if (index != length) error (SWT.ERROR_INVALID_ARGUMENT); } -void showHandle() { - OS.gtk_widget_show (eventBoxHandle); - OS.gtk_widget_show (fixedHandle); - OS.gtk_widget_show (scrolledHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); - - if ((style & SWT.CHECK) != 0) { - uncheck = createCheckPixmap(false); - check = createCheckPixmap(true); - } -} - /** * Shows the selection. If the selection is already showing in the receiver, * this method simply returns. Otherwise, the items are scrolled until @@ -916,8 +880,7 @@ void showHandle() { */ public void showSelection () { checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); + GtkCList clist = new GtkCList (handle); if (clist.selection == 0) return; if (OS.g_list_length (clist.selection) == 0) return; int node = OS.g_list_nth_data (clist.selection, 0); @@ -952,11 +915,11 @@ public void showItem (TreeItem item) { if (visibility != OS.GTK_VISIBILITY_NONE) return; if (!OS.gtk_ctree_is_viewable (handle, node)) { int parent = node; - GtkCTreeRow row = new GtkCTreeRow (); + GtkCTreeRow row; OS.gtk_signal_handler_block_by_data (handle, SWT.Expand); do { int data = OS.g_list_nth_data (parent, 0); - OS.memmove (row, data, GtkCTreeRow.sizeof); + row = new GtkCTreeRow(data); if ((parent = row.parent) == 0) break; OS.gtk_ctree_expand (handle, parent); } while (true); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index 68088a703e..ed65b5a39e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -181,25 +181,6 @@ static TreeItem checkNull (TreeItem item) { return item;
}
-/**
- * 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>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- Tree parent = getParent();
- return parent.getBackground();
-}
-
/** * Returns a rectangle describing the receiver's size and location * relative to its parent. @@ -213,16 +194,12 @@ public Color getBackground () { */ public Rectangle getBounds () {
int ctree = parent.handle;
- GtkCTree tree = new GtkCTree();
- OS.memmove(tree, ctree, GtkCTree.sizeof);
-
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, tree.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove (adjustment, tree.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
+ GtkCTree tree = new GtkCTree(ctree);
+/*
+ double haj = OS.gtk_adjustment_get_value(tree.hadjustment);
+ double vaj = OS.gtk_adjustment_get_value(tree.vadjustment);
+
int columnHandle = tree.column;
-
int height=parent.getItemHeight();
int row_list = tree.row_list; int level=0;
@@ -251,14 +228,14 @@ public Rectangle getBounds () { int styleHandle = OS.gtk_ctree_node_get_row_style(ctree, handle);
if (styleHandle == 0)
styleHandle = OS.gtk_widget_get_style(ctree);
- GtkStyle style = new GtkStyle();
- OS.memmove(style, styleHandle, GtkStyle.sizeof);
- int width = OS.gdk_string_width(style.font, buffer1);
+ GtkStyle style = new GtkStyle(styleHandle);*/
+ /* FIXME */
+ int width = 50; /*OS.gdk_string_width(style.font, buffer1);*/
// x = (short)column.area_x+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
- int x = 33+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
+/* int x = 33+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;*/
- return new Rectangle (x, y, width, height);
+ return new Rectangle (0, 0, 40, 10);
}
/** @@ -308,25 +285,6 @@ public boolean getExpanded () { return buffer [0];
}
-/**
- * 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>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- Tree parent = getParent();
- return parent.getForeground();
-}
-
/** * Returns <code>true</code> if the receiver is grayed, * and false otherwise. When the parent does not have @@ -412,8 +370,7 @@ public Tree getParent () { public TreeItem getParentItem () {
checkWidget();
int data = OS.g_list_nth_data (handle, 0);
- GtkCTreeRow row = new GtkCTreeRow ();
- OS.memmove (row, data, GtkCTreeRow.sizeof);
+ GtkCTreeRow row = new GtkCTreeRow (data);
if (row.parent == 0) return null;
int ctree = parent.handle;
int index = OS.gtk_ctree_node_get_row_data (ctree, row.parent) - 1;
@@ -430,30 +387,6 @@ void releaseWidget () { parent = null;
}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument 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>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
/** * Sets the checked state of the receiver. * <p> @@ -480,32 +413,6 @@ public void setChecked (boolean checked) { OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]);
}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument 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>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
/** * Sets the grayed state of the receiver. * <p> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/UtilFuncs.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/UtilFuncs.java index 0ab42ea7c5..afe935eaa7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/UtilFuncs.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/UtilFuncs.java @@ -15,110 +15,13 @@ import org.eclipse.swt.internal.gtk.*; */ class UtilFuncs { -/* - * === GEOMETRY === - */ - -static Point getLocation (int handle) { - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_x, widget.alloc_y); -} - -static void setLocation(int parentHandle, int handle, int x, int y) { - // GtkFixed does not leave us alone. - // Instead, it maintains its own list of geometries for the children. - // Moreover, it will post a RESIZE on the queue that will cause - // disturbance to all our brother; to avoid that, we temporarily - // clear the VISIBLE flag, and do the synchronous update ourselves - GtkObject gtkChild = new GtkObject(); - OS.memmove (gtkChild, handle, GtkObject.sizeof); - OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_VISIBLE); - OS.gtk_fixed_move(parentHandle, handle, (short)x, (short)y ); - OS.memmove(handle, gtkChild, GtkObject.sizeof); - - // force allocation update NOW - // unfortunately, due to the shape of our PI, - // we can't selectively update only x and y. - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - GtkAllocation alloc = new GtkAllocation(); - alloc.x = (short) x; - alloc.y = (short) y; - alloc.width = (short) widget.alloc_width; - alloc.height = (short) widget.alloc_height; - OS.memmove(handle, widget, GtkWidget.sizeof); - OS.gtk_widget_size_allocate(handle, alloc); -} - -static Point getSize (int handle) { - if (handle==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); - } - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_width, widget.alloc_height); -} - - -static boolean setSize(int handle, int width, int height) { - if (handle==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); - } - - /* Feature in Gtk. - * Gtk will refuse to set the size of any widget to anything smaller than 3x3. - */ - if (height <= 3) height = 3; - if (width <= 3) width = 3; - // first, see if we actually need to change anything - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - int alloc_width = widget.alloc_width & 0xFFFF; - int alloc_height = widget.alloc_height & 0xFFFF; - if (alloc_width == width && alloc_height == height) { - return false; - } - OS.gtk_widget_set_usize (handle, width, height); - // force child allocation update - GtkAllocation alloc = new GtkAllocation(); - alloc.x = (short) widget.alloc_x; - alloc.y = (short) widget.alloc_y; - alloc.width = (short) width; - alloc.height = (short) height; - OS.gtk_widget_size_allocate(handle, alloc); - return true; -} - -static void setZeroSize(int handle) { - // CHEATING. For some reason, - // the it will refuse to change its size to anything smaller - setSize(handle, 3,3); -} - static int getFont(int widget) { - int hStyle = OS.gtk_widget_get_style(widget); - GtkStyle style = new GtkStyle(); - OS.memmove(style, hStyle, GtkStyle.sizeof); - return style.font; + /* FIXME */ + return 0; } static void setFont(int handle, int font) { - OS.gtk_widget_ensure_style(handle); - // We can't just get the widget's style and set - // its font, because the style slot may point to the - // default font; therefore we have to obtain a clone - // of the style - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - int hStyle = OS.gtk_style_copy(widget.style); - GtkStyle style = new GtkStyle(); - OS.memmove(style, hStyle, GtkStyle.sizeof); - - OS.gdk_font_unref(style.font); - style.font = font; - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); + /* FIXME */ } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index 70c419d725..1a8997a702 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -224,7 +224,7 @@ protected void checkSubclass () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -protected final void checkWidget () { +protected void checkWidget () { if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); } @@ -485,7 +485,7 @@ boolean hooks (int eventType) { return eventTable.hooks (eventType); } -final boolean isValidThread () { +boolean isValidThread () { return getDisplay ().isValidThread (); } public boolean isValidWidget () { @@ -494,7 +494,7 @@ public boolean isValidWidget () { return (state & DISPOSED) == 0; } -final boolean isValidSubclass() { +boolean isValidSubclass() { return Display.isValidClass(getClass()); } @@ -550,6 +550,7 @@ void postEvent (int eventType, Event event) { } int processEvent (int eventNumber, int int0, int int1, int int2) { + System.out.println("event: "+eventNumber+" in "+this); switch (eventNumber) { case SWT.Arm: return processArm (int0, int1, int2); case SWT.Collapse: return processCollapse (int0, int1, int2); @@ -680,7 +681,6 @@ int processVerify (int int0, int int1, int int2) { } void signal_connect (int handle, String eventName, int swtEvent, int numArgs) { - byte [] buffer = Converter.wcsToMbcs (null, eventName, true); int proc=0; switch (numArgs) { case 2: proc=getDisplay().windowProc2; break; @@ -689,7 +689,9 @@ void signal_connect (int handle, String eventName, int swtEvent, int numArgs) { case 5: proc=getDisplay().windowProc5; break; default: error(SWT.ERROR_INVALID_ARGUMENT); } - OS.gtk_signal_connect (handle, buffer, proc, swtEvent); + /*OS.g_signal_connect (handle, eventName, proc, swtEvent);*/ + byte [] buffer = Converter.wcsToMbcs (null, eventName, true); + OS.gtk_signal_connect(handle, buffer, proc, swtEvent); } void signal_connect_after (int handle, String eventName, int swtEvent, int numArgs) { byte [] buffer = Converter.wcsToMbcs (null, eventName, true); @@ -910,7 +912,7 @@ char wcsToMbcs (char ch) { return 0; } -static byte[] string2bytesConvertMnemonic(String string) { +byte[] string2bytesConvertMnemonic(String string) { //FIXME need to double _'s char [] t = new char [string.length ()]; string.getChars (0, t.length, t, 0); |