Lines 59-64
Link Here
|
59 |
Shell _shell; |
59 |
Shell _shell; |
60 |
|
60 |
|
61 |
static final String PACKAGE_PREFIX = "org.eclipse.swt.custom."; //$NON-NLS-1$ |
61 |
static final String PACKAGE_PREFIX = "org.eclipse.swt.custom."; //$NON-NLS-1$ |
|
|
62 |
static final String SHELL_KEY = "org.eclipse.swt.custom.CCombo.SHELL"; //$NON-NLS-1$ |
62 |
|
63 |
|
63 |
/** |
64 |
/** |
64 |
* Constructs a new instance of this class given its parent |
65 |
* Constructs a new instance of this class given its parent |
Lines 361-377
Link Here
|
361 |
notifyListeners(SWT.Dispose, event); |
362 |
notifyListeners(SWT.Dispose, event); |
362 |
event.type = SWT.None; |
363 |
event.type = SWT.None; |
363 |
|
364 |
|
364 |
if (popup != null && !popup.isDisposed ()) { |
365 |
disposePopup (); |
365 |
list.removeListener (SWT.Dispose, listener); |
|
|
366 |
popup.dispose (); |
367 |
} |
368 |
Shell shell = getShell (); |
366 |
Shell shell = getShell (); |
369 |
shell.removeListener (SWT.Deactivate, listener); |
367 |
shell.removeListener (SWT.Deactivate, listener); |
370 |
Display display = getDisplay (); |
368 |
Display display = getDisplay (); |
371 |
display.removeFilter (SWT.FocusIn, filter); |
369 |
display.removeFilter (SWT.FocusIn, filter); |
372 |
popup = null; |
|
|
373 |
text = null; |
370 |
text = null; |
374 |
list = null; |
|
|
375 |
arrow = null; |
371 |
arrow = null; |
376 |
_shell = null; |
372 |
_shell = null; |
377 |
break; |
373 |
break; |
Lines 432-440
Link Here
|
432 |
checkWidget (); |
428 |
checkWidget (); |
433 |
text.copy (); |
429 |
text.copy (); |
434 |
} |
430 |
} |
435 |
void createPopup(String[] items, int selectionIndex) { |
431 |
void createPopup(String[] items, int selectionIndex) { |
436 |
// create shell and list |
432 |
Shell shell = getShell(); |
437 |
popup = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP); |
433 |
popup = (Shell) shell.getData (SHELL_KEY); |
|
|
434 |
if (popup == null || popup.isDisposed ()) { |
435 |
popup = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP); |
436 |
shell.setData (SHELL_KEY, popup); |
437 |
} |
438 |
|
438 |
int style = getStyle (); |
439 |
int style = getStyle (); |
439 |
int listStyle = SWT.SINGLE | SWT.V_SCROLL; |
440 |
int listStyle = SWT.SINGLE | SWT.V_SCROLL; |
440 |
if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT; |
441 |
if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT; |
Lines 444-449
Link Here
|
444 |
if (font != null) list.setFont (font); |
445 |
if (font != null) list.setFont (font); |
445 |
if (foreground != null) list.setForeground (foreground); |
446 |
if (foreground != null) list.setForeground (foreground); |
446 |
if (background != null) list.setBackground (background); |
447 |
if (background != null) list.setBackground (background); |
|
|
448 |
list.setVisible(false); |
447 |
|
449 |
|
448 |
int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate}; |
450 |
int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate}; |
449 |
for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener); |
451 |
for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener); |
Lines 511-522
Link Here
|
511 |
text.setText(""); //$NON-NLS-1$ |
513 |
text.setText(""); //$NON-NLS-1$ |
512 |
list.deselectAll (); |
514 |
list.deselectAll (); |
513 |
} |
515 |
} |
|
|
516 |
void disposePopup() { |
517 |
if (popup != null && !popup.isDisposed ()) { |
518 |
list.removeListener (SWT.Dispose, listener); |
519 |
list.dispose(); |
520 |
if (popup.getChildren().length == 0) { |
521 |
popup.dispose (); |
522 |
Shell shell = getShell(); |
523 |
if (!shell.isDisposed()) shell.setData(SHELL_KEY, null); |
524 |
} |
525 |
popup = null; |
526 |
list = null; |
527 |
} |
528 |
} |
514 |
void dropDown (boolean drop) { |
529 |
void dropDown (boolean drop) { |
515 |
if (drop == isDropped ()) return; |
530 |
if (drop == isDropped ()) return; |
516 |
if (!drop) { |
531 |
if (!drop) { |
517 |
popup.setVisible (false); |
532 |
popup.setVisible (false); |
518 |
if (!isDisposed () && isFocusControl()) { |
533 |
if (!isDisposed ()) { |
519 |
text.setFocus(); |
534 |
list.setVisible (false); |
|
|
535 |
if (isVisible() && isFocusControl ()) text.setFocus (); |
520 |
} |
536 |
} |
521 |
return; |
537 |
return; |
522 |
} |
538 |
} |
Lines 524-533
Link Here
|
524 |
if (getShell() != popup.getParent ()) { |
540 |
if (getShell() != popup.getParent ()) { |
525 |
String[] items = list.getItems (); |
541 |
String[] items = list.getItems (); |
526 |
int selectionIndex = list.getSelectionIndex (); |
542 |
int selectionIndex = list.getSelectionIndex (); |
527 |
list.removeListener (SWT.Dispose, listener); |
543 |
disposePopup (); |
528 |
popup.dispose(); |
|
|
529 |
popup = null; |
530 |
list = null; |
531 |
createPopup (items, selectionIndex); |
544 |
createPopup (items, selectionIndex); |
532 |
} |
545 |
} |
533 |
|
546 |
|
Lines 552-557
Link Here
|
552 |
if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height; |
565 |
if (y + height > displayRect.y + displayRect.height) y = parentRect.y - height; |
553 |
if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width; |
566 |
if (x + width > displayRect.x + displayRect.width) x = displayRect.x + displayRect.width - listRect.width; |
554 |
popup.setBounds (x, y, width, height); |
567 |
popup.setBounds (x, y, width, height); |
|
|
568 |
list.setVisible (true); |
555 |
popup.setVisible (true); |
569 |
popup.setVisible (true); |
556 |
if (isFocusControl()) list.setFocus (); |
570 |
if (isFocusControl()) list.setFocus (); |
557 |
} |
571 |
} |
Lines 995-1001
Link Here
|
995 |
}); |
1009 |
}); |
996 |
} |
1010 |
} |
997 |
boolean isDropped () { |
1011 |
boolean isDropped () { |
998 |
return popup.getVisible (); |
1012 |
return list.isVisible(); |
999 |
} |
1013 |
} |
1000 |
public boolean isFocusControl () { |
1014 |
public boolean isFocusControl () { |
1001 |
checkWidget(); |
1015 |
checkWidget(); |
Lines 1131-1136
Link Here
|
1131 |
text.paste (); |
1145 |
text.paste (); |
1132 |
} |
1146 |
} |
1133 |
void popupEvent(Event event) { |
1147 |
void popupEvent(Event event) { |
|
|
1148 |
if (!isDropped()) return; |
1134 |
switch (event.type) { |
1149 |
switch (event.type) { |
1135 |
case SWT.Paint: |
1150 |
case SWT.Paint: |
1136 |
// draw black rectangle around list |
1151 |
// draw black rectangle around list |