View | Details | Raw Unified | Return to bug 333286 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java (-19 / +39 lines)
Lines 11-16 Link Here
11
package org.eclipse.swt.widgets;
11
package org.eclipse.swt.widgets;
12
12
13
13
14
import java.util.Arrays;
15
14
import org.eclipse.swt.*;
16
import org.eclipse.swt.*;
15
import org.eclipse.swt.internal.*;
17
import org.eclipse.swt.internal.*;
16
import org.eclipse.swt.internal.gtk.*;
18
import org.eclipse.swt.internal.gtk.*;
Lines 571-604 Link Here
571
}
573
}
572
574
573
int /*long*/ findPopupHandle (int /*long*/ oldList) {
575
int /*long*/ findPopupHandle (int /*long*/ oldList) {
576
	// We get two lists of top-level window handles, one before creation of the combo box
577
	// and one after. The first window handle that is present in the second list but not in
578
	// the first one is assumed to be the handle of the popup window of the combo box.
574
	int /*long*/ hdl = 0;
579
	int /*long*/ hdl = 0;
575
	int /*long*/ currentList = OS.gtk_window_list_toplevels();
580
	int /*long*/ newList = OS.gtk_window_list_toplevels();
576
	int /*long*/ oldFromList = oldList;
581
	int[] oldHandles = getSortedListData(oldList, 1000);
577
	int /*long*/ newFromList = currentList;
582
	int[] newHandles = getSortedListData(newList, oldHandles.length);
578
	boolean isFound;
583
	for (int i = 0, j = 0; i < newHandles.length; i++, j++) {
579
	while (newFromList != 0) {
584
		hdl = newHandles[i];
580
		int /*long*/ newToplevel = OS.g_list_data(newFromList);
585
		if (hdl == 0) {
581
		isFound = false;
586
			break;
582
		oldFromList = oldList;
583
		while (oldFromList != 0) {
584
			int /*long*/ oldToplevel = OS.g_list_data(oldFromList);
585
			if (newToplevel == oldToplevel) {
586
				isFound = true;
587
				break;
588
			}
589
			oldFromList = OS.g_list_next(oldFromList);
590
		}
587
		}
591
		if (!isFound) {
588
		int oldHandle = j < oldHandles.length ? oldHandles[j] : 0;
592
			hdl = newToplevel;
589
		if (oldHandle != 0 && oldHandle < hdl) {
590
			i--;
591
		} else if (hdl != oldHandle) {
593
			break;
592
			break;
594
		}
593
		}
595
		newFromList = OS.g_list_next(newFromList);
596
	}
594
	}
597
	OS.g_list_free(oldList);
595
	OS.g_list_free(oldList);
598
	OS.g_list_free(currentList);
596
	OS.g_list_free(newList);
599
	return hdl;
597
	return hdl;
600
}
598
}
601
599
600
/**
601
 * Retrieves data from a list of window handles and returns it in a sorted array.
602
 * The returned array may be padded with zeros.
603
 * 
604
 * @param listHandle a list handle
605
 * @param initialSize initial length of the array.
606
 * @return window handles in ascending order. 
607
 */
608
private int[] getSortedListData(int listHandle, int initialSize) {
609
	int[] data = new int[initialSize];
610
	int count = 0;
611
	for (int item = listHandle; item != 0; item = OS.g_list_next(item)) {
612
		if (count >= data.length) {
613
			int[] oldData = data;
614
			data = new int[data.length * 2];
615
			System.arraycopy(oldData, 0, data, 0, oldData.length);
616
		}
617
		data[count++] = OS.g_list_data(item);
618
	}
619
	Arrays.sort(data, 0, count);
620
	return data;
621
}
602
622
603
void findButtonHandle() {
623
void findButtonHandle() {
604
	/*
624
	/*

Return to bug 333286