summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
diff options
context:
space:
mode:
authorAlexander Kurtakov <akurtako@redhat.com>2012-01-20 11:14:14 +0200
committerSilenio Quarti <silenio_quarti@ca.ibm.com>2012-01-20 13:03:38 -0500
commit704f9377fdfbc3f0c12e11665b0fc2e8c6f9b051 (patch)
tree17dc198d2a65e9578740e7b17b550d3c54a86234 /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
parenta07db21f2dc02d806d74ab0e60154800444f5429 (diff)
downloadeclipse.platform.swt-704f9377fdfbc3f0c12e11665b0fc2e8c6f9b051.tar.gz
eclipse.platform.swt-704f9377fdfbc3f0c12e11665b0fc2e8c6f9b051.tar.xz
eclipse.platform.swt-704f9377fdfbc3f0c12e11665b0fc2e8c6f9b051.zip
Cleanup pre GTK 2.4 leftovers.
This is a lot of code that can not be used nowadays but just makes it harder to kill deprecated functions in order to use newer GTK versions.
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java367
1 files changed, 67 insertions, 300 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
index ed692d2f7e..7950613463 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
@@ -114,85 +114,34 @@ protected void checkSubclass () {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- int border = OS.gtk_container_get_border_width (handle);
- size.x += 2 * border;
- size.y += 2 * border;
- return size;
- } else {
- int height = 0, width = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if (itemCount > 0) {
- height += spacing;
- GC gc = new GC (this);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- height += item.getHeaderHeight ();
- if (item.expanded) height += item.height;
- height += spacing;
- width = Math.max (width, item.getPreferredWidth (gc));
- }
- gc.dispose ();
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
- }
+ if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
+ if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
+ Point size = computeNativeSize (handle, wHint, hHint, changed);
+ int border = OS.gtk_container_get_border_width (handle);
+ size.x += 2 * border;
+ size.y += 2 * border;
+ return size;
}
void createHandle (int index) {
state |= HANDLE;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_vbox_new (false, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.V_SCROLL) != 0) {
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, OS.GTK_POLICY_AUTOMATIC);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_scrolled_window_add_with_viewport (scrolledHandle, handle);
- int /*long*/ viewport = OS.gtk_bin_get_child (scrolledHandle);
- OS.gtk_viewport_set_shadow_type (viewport, OS.GTK_SHADOW_NONE);
- } else {
- OS.gtk_container_add (fixedHandle, handle);
- }
- OS.gtk_container_set_border_width (handle, 0);
+ fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
+ if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ OS.gtk_fixed_set_has_window (fixedHandle, true);
+ handle = OS.gtk_vbox_new (false, 0);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & SWT.V_SCROLL) != 0) {
+ scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
+ if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, OS.GTK_POLICY_AUTOMATIC);
+ OS.gtk_container_add (fixedHandle, scrolledHandle);
+ OS.gtk_scrolled_window_add_with_viewport (scrolledHandle, handle);
+ int /*long*/ viewport = OS.gtk_bin_get_child (scrolledHandle);
+ OS.gtk_viewport_set_shadow_type (viewport, OS.GTK_SHADOW_NONE);
} else {
- int /*long*/ topHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (topHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (topHandle, true);
- if ((style & SWT.V_SCROLL) != 0) {
- fixedHandle = topHandle;
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (handle, true);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
-
- /*
- * Force the scrolledWindow to have a single child that is
- * not scrolled automatically. Calling gtk_container_add()
- * seems to add the child correctly but cause a warning.
- */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.gtk_container_add (scrolledHandle, handle);
- display.setWarnings (warnings);
- } else {
- handle = topHandle;
- }
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
+ OS.gtk_container_add (fixedHandle, handle);
}
+ OS.gtk_container_set_border_width (handle, 0);
}
void createItem (ExpandItem item, int style, int index) {
@@ -205,9 +154,6 @@ void createItem (ExpandItem item, int style, int index) {
System.arraycopy (items, index, items, index + 1, itemCount - index);
items [index] = item;
itemCount++;
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus == null) lastFocus = item;
- }
item.width = Math.max (0, getClientArea ().width - spacing * 2);
layoutItems (index, true);
}
@@ -224,17 +170,6 @@ void destroyItem (ExpandItem item) {
index++;
}
if (index == itemCount) return;
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (item == lastFocus) {
- int focusIndex = index > 0 ? index - 1 : 1;
- if (focusIndex < itemCount) {
- lastFocus = items [focusIndex];
- lastFocus.redraw ();
- } else {
- lastFocus = null;
- }
- }
- }
System.arraycopy (items, index + 1, items, index, --itemCount - index);
items [itemCount] = null;
item.redraw ();
@@ -242,36 +177,30 @@ void destroyItem (ExpandItem item) {
}
int /*long*/ eventHandle () {
- return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle;
+ return fixedHandle;
}
boolean forceFocus (int /*long*/ focusHandle) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.setFocus ()) return true;
- }
+ if (lastFocus != null && lastFocus.setFocus ()) return true;
+ for (int i = 0; i < itemCount; i++) {
+ ExpandItem item = items [i];
+ if (item.setFocus ()) return true;
}
return super.forceFocus (focusHandle);
}
boolean hasFocus () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i=0; i<itemCount; i++) {
- ExpandItem item = items [i];
- if (item.hasFocus ()) return true;
- }
+ for (int i=0; i<itemCount; i++) {
+ ExpandItem item = items [i];
+ if (item.hasFocus ()) return true;
}
return super.hasFocus();
}
void hookEvents () {
super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (scrolledHandle != 0) {
- OS.g_signal_connect_closure (scrolledHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true);
- }
+ if (scrolledHandle != 0) {
+ OS.g_signal_connect_closure (scrolledHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true);
}
}
@@ -284,10 +213,8 @@ int getBandHeight () {
}
GdkColor getForegroundColor () {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if ((state & FOREGROUND) == 0) {
- return display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND).handle;
- }
+ if ((state & FOREGROUND) == 0) {
+ return display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND).handle;
}
return super.getForegroundColor ();
}
@@ -366,142 +293,36 @@ public int getSpacing () {
return spacing;
}
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int x = (int)gdkEvent.x;
- int y = (int)gdkEvent.y;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight ());
- if (hover && item != lastFocus) {
- lastFocus.redraw ();
- lastFocus = item;
- lastFocus.redraw ();
- forceFocus ();
- break;
- }
- }
- }
- return super.gtk_button_press_event (widget, event);
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int x = (int)gdkEvent.x;
- int y = (int)gdkEvent.y;
- boolean hover = lastFocus.x <= x && x < (lastFocus.x + lastFocus.width) && lastFocus.y <= y && y < (lastFocus.y + getBandHeight ());
- if (hover) {
- Event ev = new Event ();
- ev.item = lastFocus;
- notifyListeners (lastFocus.expanded ? SWT.Collapse : SWT.Expand, ev);
- lastFocus.expanded = !lastFocus.expanded;
- showItem (lastFocus);
- }
- }
- }
- return super.gtk_button_release_event (widget, event);
-}
-
int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
if ((state & OBSCURED) != 0) return 0;
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof);
- GCData data = new GCData ();
- data.damageRgn = gdkEvent.region;
- GC gc = GC.gtk_new (this, data);
- boolean hasFocus = isFocusControl ();
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.drawItem (gc, hasFocus && item == lastFocus);
- }
- gc.dispose ();
- }
return super.gtk_expose_event (widget, eventPtr);
}
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) lastFocus.redraw ();
+int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
+ if (!hasFocus ()) return 0;
+ int /*long*/ result = super.gtk_key_press_event (widget, event);
+ if (result != 0) return result;
+ int index = 0;
+ while (index < itemCount) {
+ if (items [index].hasFocus ()) break;
+ index++;
}
- return super.gtk_focus_in_event(widget, event);
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) lastFocus.redraw ();
+ GdkEventKey gdkEvent = new GdkEventKey ();
+ OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
+ boolean next = false;
+ switch (gdkEvent.keyval) {
+ case OS.GDK_Up:
+ case OS.GDK_Left: next = false; break;
+ case OS.GDK_Down:
+ case OS.GDK_Right: next = true; break;
+ default: return result;
}
- return super.gtk_focus_out_event (widget, event);
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (!hasFocus ()) return 0;
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) return result;
- int index = 0;
- while (index < itemCount) {
- if (items [index].hasFocus ()) break;
- index++;
- }
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
- boolean next = false;
- switch (gdkEvent.keyval) {
- case OS.GDK_Up:
- case OS.GDK_Left: next = false; break;
- case OS.GDK_Down:
- case OS.GDK_Right: next = true; break;
- default: return result;
- }
- int start = index, offset = next ? 1 : -1;
- while ((index = (index + offset + itemCount) % itemCount) != start) {
- ExpandItem item = items [index];
- if (item.setFocus ()) return result;
- }
- return result;
- } else {
- if (lastFocus != null) {
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, event, GdkEventKey.sizeof);
- switch (keyEvent.keyval) {
- case OS.GDK_Return:
- case OS.GDK_space:
- Event ev = new Event ();
- ev.item = lastFocus;
- sendEvent (lastFocus.expanded ? SWT.Collapse :SWT.Expand, ev);
- lastFocus.expanded = !lastFocus.expanded;
- showItem (lastFocus);
- break;
- case OS.GDK_Up:
- case OS.GDK_KP_Up: {
- int focusIndex = indexOf (lastFocus);
- if (focusIndex > 0) {
- lastFocus.redraw ();
- lastFocus = items [focusIndex - 1];
- lastFocus.redraw ();
- }
- break;
- }
- case OS.GDK_Down:
- case OS.GDK_KP_Down: {
- int focusIndex = indexOf (lastFocus);
- if (focusIndex < itemCount - 1) {
- lastFocus.redraw ();
- lastFocus = items [focusIndex + 1];
- lastFocus.redraw ();
- }
- break;
- }
- }
- }
+ int start = index, offset = next ? 1 : -1;
+ while ((index = (index + offset + itemCount) % itemCount) != start) {
+ ExpandItem item = items [index];
+ if (item.setFocus ()) return result;
}
- return super.gtk_key_press_event (widget, event);
+ return result;
}
/**
@@ -532,27 +353,9 @@ public int indexOf (ExpandItem item) {
}
void layoutItems (int index, boolean setScrollbar) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item != null) item.resizeControl (yCurrentScroll);
- }
- } else {
- if (index < itemCount) {
- int y = spacing - yCurrentScroll;
- for (int i = 0; i < index; i++) {
- ExpandItem item = items [i];
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- for (int i = index; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.setBounds (spacing, y, 0, 0, true, false);
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- }
- if (setScrollbar) setScrollbar ();
+ for (int i = 0; i < itemCount; i++) {
+ ExpandItem item = items [i];
+ if (item != null) item.resizeControl (yCurrentScroll);
}
}
@@ -563,7 +366,7 @@ int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
}
int /*long*/ parentingHandle () {
- return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle;
+ return fixedHandle;
}
void releaseChildren (boolean destroy) {
@@ -611,42 +414,18 @@ void reskinChildren (int flags) {
super.reskinChildren (flags);
}
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (resize) {
- if ((style & SWT.V_SCROLL) != 0) {
- setScrollbar ();
- } else {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- int newWidth = Math.max (0, getClientArea ().width - spacing * 2);
- if (item.width != newWidth) {
- item.setBounds (0, 0, newWidth, item.height, false, true);
- }
- }
- }
- }
- }
- return result;
-}
-
void setFontDescription (int /*long*/ font) {
super.setFontDescription (font);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- items[i].setFontDescription (font);
- }
- layoutItems (0, true);
+ for (int i = 0; i < itemCount; i++) {
+ items[i].setFontDescription (font);
}
+ layoutItems (0, true);
}
void setForegroundColor (GdkColor color) {
super.setForegroundColor (color);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- items[i].setForegroundColor (color);
- }
+ for (int i = 0; i < itemCount; i++) {
+ items[i].setForegroundColor (color);
}
}
@@ -714,20 +493,8 @@ public void setSpacing (int spacing) {
if (spacing < 0) return;
if (spacing == this.spacing) return;
this.spacing = spacing;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_box_set_spacing (handle, spacing);
- OS.gtk_container_set_border_width (handle, spacing);
- } else {
- if ((style & SWT.V_SCROLL) == 0) {
- int width = Math.max (0, getClientArea ().width - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.width != width) item.setBounds (0, 0, width, item.height, false, true);
- }
- }
- layoutItems (0, true);
- redraw ();
- }
+ OS.gtk_box_set_spacing (handle, spacing);
+ OS.gtk_container_set_border_width (handle, spacing);
}
void showItem (ExpandItem item) {