@@ -386,6 +386,8 @@ public class Display extends Device {
386386
387387 DesktopItem [] desktopItems ;
388388
389+ static String bodyOverflow , htmlOverflow ;
390+
389391 static int AUTO_HIDE_DELAY = 2000 ;
390392
391393 /* Private SWT Window Messages */
@@ -404,6 +406,7 @@ public class Display extends Device {
404406
405407 /* Package Name */
406408 static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets." ; //$NON-NLS-1$
409+ private RunnableCompatibility mouseMoveListener ;
407410 /*
408411 * This code is intentionally commented. In order
409412 * to support CLDC, .class cannot be used because
@@ -941,6 +944,14 @@ protected void destroy () {
941944void destroyDisplay () {
942945}
943946
947+ public void dispose () {
948+ Shell [] shells = getShells ();
949+ if (shells == null || shells .length == 0 ) {
950+ super .dispose ();
951+ }
952+ //super.dispose();
953+ }
954+
944955/**
945956 * Causes the <code>run()</code> method of the runnable to
946957 * be invoked by the user-interface thread just before the
@@ -1767,6 +1778,10 @@ Shell getModalDialogShell () {
17671778 Monitor monitor = new Monitor ();
17681779 monitor .handle = document .body ;
17691780 monitor .clientWidth = document .body .clientWidth ;
1781+ int parentWidth = OS .getContainerWidth (document .body .parentNode );
1782+ if (parentWidth > monitor .clientWidth ) {
1783+ monitor .clientWidth = parentWidth ;
1784+ }
17701785 monitor .width = window .screen .availWidth ;
17711786 monitor .clientHeight = OS .getFixedBodyClientHeight (); //document.body.clientHeight;
17721787 monitor .height = window .screen .availHeight ;
@@ -2261,13 +2276,20 @@ public Tray getSystemTray () {
22612276 if (tray != null ) return tray ;
22622277 for (int i = 0 ; i < Displays .length ; i ++) {
22632278 Display disp = Displays [i ];
2264- if (disp != null ) {
2265- if (disp .tray != null ) {
2266- return disp .tray ;
2279+ if (disp != null && disp .tray != null && !disp .tray .isDisposed ()) {
2280+ tray = disp .tray ;
2281+ if (disp .trayCorner != null ) {
2282+ disp .trayCorner .tray = tray ;
22672283 }
2284+ return tray ;
22682285 }
22692286 }
2270- return tray = new Tray (this , SWT .NONE );
2287+ tray = new Tray (this , SWT .NONE );
2288+ if (trayCorner != null ) {
2289+ trayCorner .tray = tray ;
2290+ trayCorner .initialize ();
2291+ }
2292+ return tray ;
22712293}
22722294
22732295/**
@@ -2445,7 +2467,8 @@ protected void init () {
24452467void initializeDekstop () {
24462468 for (int i = 0 ; i < Displays .length ; i ++) {
24472469 Display disp = Displays [i ];
2448- if (disp != this && disp != null && !disp .isDisposed ()) {
2470+ if (disp != this && disp != null && !disp .isDisposed ()
2471+ && disp .taskBar != null && disp .topBar != null ) {
24492472 taskBar = disp .taskBar ;
24502473 topBar = disp .topBar ;
24512474 shortcutBar = disp .shortcutBar ;
@@ -2454,22 +2477,33 @@ void initializeDekstop() {
24542477 return ;
24552478 }
24562479 }
2457-
24582480 if (desktopItems != null ) return ;
24592481
2482+ taskBar = new TaskBar (this );
2483+ topBar = new MaximizedTitle (this );
2484+ if (QuickLaunch .defaultQuickLaunch != null ) {
2485+ shortcutBar = QuickLaunch .defaultQuickLaunch ;
2486+ } else {
2487+ shortcutBar = new QuickLaunch (this );
2488+ }
2489+ if (NotificationCorner .defaultNotificationCorner != null ) {
2490+ trayCorner = NotificationCorner .defaultNotificationCorner ;
2491+ } else {
2492+ trayCorner = new NotificationCorner (this );
2493+ }
2494+
24602495 desktopItems = new DesktopItem [] {
2461- taskBar = new TaskBar ( this ) ,
2462- topBar = new MaximizedTitle ( this ) ,
2463- shortcutBar = new QuickLaunch ( this ) ,
2464- trayCorner = new NotificationCorner ( this )
2496+ taskBar ,
2497+ topBar ,
2498+ shortcutBar ,
2499+ trayCorner
24652500 };
24662501 for (int i = 0 ; i < desktopItems .length ; i ++) {
24672502 desktopItems [i ].initialize ();
24682503 }
24692504
2470- RunnableCompatibility listener = new RunnableCompatibility (){
2505+ mouseMoveListener = new RunnableCompatibility (){
24712506
2472- @ Override
24732507 public void run () {
24742508 HTMLEvent e = (HTMLEvent ) getEvent ();
24752509 for (int i = 0 ; i < desktopItems .length ; i ++) {
@@ -2483,15 +2517,14 @@ public void run() {
24832517 }
24842518
24852519 };
2486-
24872520 /**
24882521 * @j2sNative
24892522 if (document.addEventListener) {
2490- document.addEventListener ("mousemove", listener , false);
2523+ document.addEventListener ("mousemove", this.mouseMoveListener , false);
24912524 } else if (document.attachEvent) {
2492- document.attachEvent ("onmousemove", listener );
2525+ document.attachEvent ("onmousemove", this.mouseMoveListener );
24932526 }
2494- */ { listener .run (); }
2527+ */ { mouseMoveListener .run (); }
24952528
24962529}
24972530
@@ -3333,7 +3366,16 @@ protected void release () {
33333366 Shell shell = shells [i ];
33343367 if (!shell .isDisposed ()) shell .dispose ();
33353368 }
3336- if (tray != null ) tray .dispose ();
3369+ int trayRefs = 1 ;
3370+ for (int i = 0 ; i < Displays .length ; i ++) {
3371+ Display disp = Displays [i ];
3372+ if (disp != this && disp != null && !disp .isDisposed ()) {
3373+ if (disp .tray != null ) {
3374+ trayRefs ++;
3375+ }
3376+ }
3377+ }
3378+ if (tray != null && trayRefs < 2 ) tray .dispose ();
33373379 tray = null ;
33383380 /*
33393381 * Don't loop this "while"!
@@ -3363,6 +3405,24 @@ protected void release () {
33633405 releaseDesktop ();
33643406 releaseDisplay ();
33653407 super .release ();
3408+
3409+ if (NotificationCorner .defaultNotificationCorner != null ) {
3410+ new Display ().getSystemTray ();
3411+ NotificationCorner corner = NotificationCorner .defaultNotificationCorner ;
3412+ document .body .removeChild (corner .handle );
3413+ document .body .appendChild (corner .handle );
3414+ }
3415+ if (NotificationCorner .defaultNotificationCorner == null
3416+ && QuickLaunch .defaultQuickLaunch == null ) {
3417+ if (htmlOverflow != null ) {
3418+ document .body .parentNode .style .overflow = htmlOverflow ;
3419+ htmlOverflow = null ;
3420+ }
3421+ if (bodyOverflow != null ) {
3422+ document .body .style .overflow = bodyOverflow ;
3423+ bodyOverflow = null ;
3424+ }
3425+ }
33663426}
33673427
33683428void releaseDesktop () {
@@ -3375,17 +3435,51 @@ void releaseDesktop () {
33753435 }
33763436 }
33773437 if (existed ) {
3438+ existed = false ;
3439+ for (int i = 0 ; i < Displays .length ; i ++) {
3440+ Display disp = Displays [i ];
3441+ if (disp != this && disp != null && !disp .isDisposed ()
3442+ && disp .tray != null && !disp .tray .isDisposed ()) {
3443+ existed = true ;
3444+ break ;
3445+ }
3446+ }
3447+ if (!existed && trayCorner .handle != null ) {
3448+ trayCorner .handle .style .display = "none" ;
3449+ }
33783450 return ;
33793451 }
33803452
3453+ int trayRefs = 1 ;
3454+ for (int i = 0 ; i < Displays .length ; i ++) {
3455+ Display disp = Displays [i ];
3456+ if (disp != this && disp != null && !disp .isDisposed ()) {
3457+ if (disp .tray != null ) {
3458+ trayRefs ++;
3459+ }
3460+ }
3461+ }
3462+
33813463 for (int i = 0 ; i < desktopItems .length ; i ++) {
3464+ if (trayRefs > 1 && desktopItems [i ] == trayCorner ) {
3465+ continue ;
3466+ }
33823467 desktopItems [i ].releaseWidget ();
33833468 }
33843469 desktopItems = null ;
33853470 trayCorner = null ;
33863471 taskBar = null ;
33873472 shortcutBar = null ;
33883473 topBar = null ;
3474+
3475+ /**
3476+ * @j2sNative
3477+ if (document.removeEventListener) {
3478+ document.removeEventListener ("mousemove", this.mouseMoveListener, false);
3479+ } else if (document.detachEvent) {
3480+ document.detachEvent ("onmousemove", this.mouseMoveListener);
3481+ }
3482+ */ { mouseMoveListener .run (); }
33893483}
33903484
33913485void releaseDisplay () {
@@ -3655,14 +3749,21 @@ void removeBar (Menu menu) {
36553749Control removeControl (Object handle ) {
36563750 if (handle == null ) return null ;
36573751 Control control = null ;
3658- int index = 0 ;
3752+ int index = - 1 ;
36593753 /*
36603754 if (USE_PROPERTY) {
36613755 index = OS.RemoveProp (handle, SWT_OBJECT_INDEX) - 1;
36623756 } else {
36633757 index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1;
36643758 }
36653759 */
3760+ for (int i = 0 ; i < controlTable .length ; i ++) {
3761+ Control ctrl = controlTable [i ];
3762+ if (ctrl != null && ctrl .handle == handle ) {
3763+ index = i ;
3764+ break ;
3765+ }
3766+ }
36663767 if (0 <= index && index < controlTable .length ) {
36673768 control = controlTable [index ];
36683769 controlTable [index ] = null ;
@@ -4393,14 +4494,12 @@ static Tray getTray() {
43934494 if (Default != null ) {
43944495 tray = Default .tray ;
43954496 }
4396- if (tray != null ) {
4497+ if (tray == null || tray . isDisposed () ) {
43974498 for (int i = 0 ; i < Displays .length ; i ++){
43984499 Display disp = Displays [i ];
4399- if (disp != null ) {
4400- if (disp .tray != null ){
4401- tray = disp .tray ;
4402- break ;
4403- }
4500+ if (disp != null && disp .tray != null && !disp .tray .isDisposed ()){
4501+ tray = disp .tray ;
4502+ break ;
44044503 }
44054504 }
44064505 }
0 commit comments