Lines 36-41
Link Here
|
36 |
int imageHandle, textHandle, arrowHandle; |
36 |
int imageHandle, textHandle, arrowHandle; |
37 |
ToolBar parent; |
37 |
ToolBar parent; |
38 |
Control control; |
38 |
Control control; |
|
|
39 |
Menu menu; |
39 |
String toolTipText; |
40 |
String toolTipText; |
40 |
Image disabledImage, hotImage; |
41 |
Image disabledImage, hotImage; |
41 |
boolean ignoreSelection; |
42 |
boolean ignoreSelection; |
Lines 124-129
Link Here
|
124 |
|
125 |
|
125 |
/** |
126 |
/** |
126 |
* Adds the listener to the collection of listeners who will |
127 |
* Adds the listener to the collection of listeners who will |
|
|
128 |
* be notified when the platform-specific drop-down menu trigger |
129 |
* has occurred, by sending it one of the messages defined in |
130 |
* the <code>MenuDetectListener</code> interface. |
131 |
* |
132 |
* @param listener the listener which should be notified |
133 |
* |
134 |
* @exception IllegalArgumentException <ul> |
135 |
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
136 |
* </ul> |
137 |
* @exception SWTException <ul> |
138 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
139 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
140 |
* </ul> |
141 |
* |
142 |
* @see MenuDetectListener |
143 |
* @see #removeMenuDetectListener |
144 |
* |
145 |
* @since 3.4 |
146 |
*/ |
147 |
public void addMenuDetectListener (MenuDetectListener listener) { |
148 |
checkWidget (); |
149 |
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
150 |
TypedListener typedListener = new TypedListener (listener); |
151 |
addListener (SWT.MenuDetect, typedListener); |
152 |
} |
153 |
|
154 |
/** |
155 |
* Adds the listener to the collection of listeners who will |
127 |
* be notified when the control is selected by the user, by sending |
156 |
* be notified when the control is selected by the user, by sending |
128 |
* it one of the messages defined in the <code>SelectionListener</code> |
157 |
* it one of the messages defined in the <code>SelectionListener</code> |
129 |
* interface. |
158 |
* interface. |
Lines 315-320
Link Here
|
315 |
} |
344 |
} |
316 |
|
345 |
|
317 |
/** |
346 |
/** |
|
|
347 |
* Returns the receiver's drop-down menu if it has one, or null |
348 |
* if it does not. |
349 |
* <p> |
350 |
* The drop-down menu is activated when the arrow of an {@link SWT#DROP_DOWN}-styled receiver is pressed. |
351 |
* </p> |
352 |
* |
353 |
* @return the receiver's drop-down menu |
354 |
* @exception SWTException <ul> |
355 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
356 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
357 |
* </ul> |
358 |
* |
359 |
* @since 3.4 |
360 |
*/ |
361 |
public Menu getMenu () { |
362 |
checkWidget(); |
363 |
return menu; |
364 |
} |
365 |
|
366 |
/** |
318 |
* Returns the receiver's disabled image if it has one, or null |
367 |
* Returns the receiver's disabled image if it has one, or null |
319 |
* if it does not. |
368 |
* if it does not. |
320 |
* <p> |
369 |
* <p> |
Lines 454-459
Link Here
|
454 |
if (!checkEvent (e)) return; |
503 |
if (!checkEvent (e)) return; |
455 |
if (ignoreSelection) return; |
504 |
if (ignoreSelection) return; |
456 |
Event event = new Event (); |
505 |
Event event = new Event (); |
|
|
506 |
Point showTheMenuPos = null; |
457 |
if ((style & SWT.DROP_DOWN) != 0) { |
507 |
if ((style & SWT.DROP_DOWN) != 0) { |
458 |
int mousePos = OS.Mouse_GetPosition (handle); |
508 |
int mousePos = OS.Mouse_GetPosition (handle); |
459 |
int zero = OS.gcnew_Point (0, OS.FrameworkElement_ActualHeight (topHandle ())); |
509 |
int zero = OS.gcnew_Point (0, OS.FrameworkElement_ActualHeight (topHandle ())); |
Lines 463-473
Link Here
|
463 |
int location = OS.UIElement_TranslatePoint (handle, zero, parent.handle); |
513 |
int location = OS.UIElement_TranslatePoint (handle, zero, parent.handle); |
464 |
event.x = (int) OS.Point_X (location); |
514 |
event.x = (int) OS.Point_X (location); |
465 |
event.y = (int) OS.Point_Y (location); |
515 |
event.y = (int) OS.Point_Y (location); |
|
|
516 |
if (sendMenuDetectEvent (event.x, event.y, SWT.ARROW)) { |
517 |
showTheMenuPos = parent.toDisplay(event.x, event.y); |
518 |
} |
466 |
OS.GCHandle_Free (location); |
519 |
OS.GCHandle_Free (location); |
467 |
} |
520 |
} |
468 |
OS.GCHandle_Free (arrowPos); |
521 |
OS.GCHandle_Free (arrowPos); |
469 |
OS.GCHandle_Free (zero); |
522 |
OS.GCHandle_Free (zero); |
470 |
OS.GCHandle_Free (mousePos); |
523 |
OS.GCHandle_Free (mousePos); |
|
|
524 |
} else { |
525 |
int zero = OS.gcnew_Point (0, OS.FrameworkElement_ActualHeight (topHandle ())); |
526 |
int location = OS.UIElement_TranslatePoint (handle, zero, parent.handle); |
527 |
int x = (int) OS.Point_X (location); |
528 |
int y = (int) OS.Point_Y (location); |
529 |
if (sendMenuDetectEvent (x, y, 0)) { |
530 |
showTheMenuPos = parent.toDisplay(x, y); |
531 |
} |
532 |
OS.GCHandle_Free(zero); |
533 |
OS.GCHandle_Free(location); |
534 |
} |
535 |
if (showTheMenuPos != null) { |
536 |
menu.setLocation (showTheMenuPos.x, showTheMenuPos.y); |
537 |
menu.setVisible (true); |
538 |
return; |
471 |
} |
539 |
} |
472 |
postEvent (SWT.Selection, event); |
540 |
postEvent (SWT.Selection, event); |
473 |
} |
541 |
} |
Lines 542-547
Link Here
|
542 |
|
610 |
|
543 |
void releaseWidget () { |
611 |
void releaseWidget () { |
544 |
super.releaseWidget (); |
612 |
super.releaseWidget (); |
|
|
613 |
if (menu != null && !menu.isDisposed ()) { |
614 |
menu.dispose (); |
615 |
} |
616 |
menu = null; |
545 |
control = null; |
617 |
control = null; |
546 |
toolTipText = null; |
618 |
toolTipText = null; |
547 |
image = disabledImage = hotImage = null; |
619 |
image = disabledImage = hotImage = null; |
Lines 568-573
Link Here
|
568 |
|
640 |
|
569 |
/** |
641 |
/** |
570 |
* Removes the listener from the collection of listeners who will |
642 |
* Removes the listener from the collection of listeners who will |
|
|
643 |
* be notified when the platform-specific drop-down menu trigger has |
644 |
* occurred. |
645 |
* |
646 |
* @param listener the listener which should no longer be notified |
647 |
* |
648 |
* @exception IllegalArgumentException <ul> |
649 |
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
650 |
* </ul> |
651 |
* @exception SWTException <ul> |
652 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
653 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
654 |
* </ul> |
655 |
* |
656 |
* @see MenuDetectListener |
657 |
* @see #addMenuDetectListener |
658 |
* |
659 |
* @since 3.4 |
660 |
*/ |
661 |
public void removeMenuDetectListener (MenuDetectListener listener) { |
662 |
checkWidget (); |
663 |
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
664 |
if (eventTable == null) return; |
665 |
eventTable.unhook (SWT.MenuDetect, listener); |
666 |
} |
667 |
|
668 |
/** |
669 |
* Removes the listener from the collection of listeners who will |
571 |
* be notified when the control is selected by the user. |
670 |
* be notified when the control is selected by the user. |
572 |
* |
671 |
* |
573 |
* @param listener the listener which should no longer be notified |
672 |
* @param listener the listener which should no longer be notified |
Lines 636-641
Link Here
|
636 |
} |
735 |
} |
637 |
|
736 |
|
638 |
/** |
737 |
/** |
|
|
738 |
* Sets the receiver's drop-down menu to the argument, which may be |
739 |
* null indicating that no drop-down menu should be displayed. |
740 |
* <p> |
741 |
* If this property is null a drop-down menu can still be displayed manually by adding a |
742 |
* {@link SelectionListener} to the receiver and handling{@link SWT#ARROW} events. |
743 |
* <p> |
744 |
* The drop-down menu is activated when the arrow of an {@link SWT#DROP_DOWN}-styled |
745 |
* receiver or any portion of an {@link SWT#PUSH}-styled receiver is pressed. |
746 |
* </p> |
747 |
* |
748 |
* @param menu the drop-down menu to be displayed when the receiver's arrow is pressed |
749 |
* @exception SWTException <ul> |
750 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
751 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
752 |
* </ul> |
753 |
* |
754 |
* @since 3.4 |
755 |
*/ |
756 |
public void setMenu (Menu menu) { |
757 |
checkWidget(); |
758 |
if (menu != null) { |
759 |
if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
760 |
if ((menu.style & SWT.POP_UP) == 0) { |
761 |
error (SWT.ERROR_MENU_NOT_POP_UP); |
762 |
} |
763 |
if (menu.parent != parent.menuShell ()) { |
764 |
error (SWT.ERROR_INVALID_PARENT); |
765 |
} |
766 |
} |
767 |
this.menu = menu; |
768 |
} |
769 |
|
770 |
/** |
639 |
* Enables the receiver if the argument is <code>true</code>, |
771 |
* Enables the receiver if the argument is <code>true</code>, |
640 |
* and disables it otherwise. |
772 |
* and disables it otherwise. |
641 |
* <p> |
773 |
* <p> |
Lines 833-836
Link Here
|
833 |
OS.FrameworkElement_Margin (imageHandle, margin); |
965 |
OS.FrameworkElement_Margin (imageHandle, margin); |
834 |
OS.GCHandle_Free (margin); |
966 |
OS.GCHandle_Free (margin); |
835 |
} |
967 |
} |
|
|
968 |
|
969 |
private boolean sendMenuDetectEvent (int x, int y, int detail) { |
970 |
Event event = new Event (); |
971 |
event.detail = detail; |
972 |
event.x = x; |
973 |
event.y = y; |
974 |
this.sendEvent (SWT.MenuDetect, event); |
975 |
return event.doit && menu != null && !menu.isDisposed (); |
976 |
} |
977 |
|
836 |
} |
978 |
} |