~ubuntu-branches/debian/sid/swt-gtk/sid

« back to all changes in this revision

Viewing changes to org/eclipse/swt/widgets/TrayItem.java

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Perez
  • Date: 2009-12-07 10:22:24 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20091207102224-70w2tax575mcks1w
Tags: 3.5.1-1
* New upstream release. Closes: #558663.
* debian/control: 
  - Add Vcs-* fields for Git repository.
  - Allow DM-Uploads.
  - Remove "Conflicts", package should live with eclipse.
* debian/rules: Fix default-java path around AWT_LIB_PATH.
* debian/copyright: Minor update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
 
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
3
 * All rights reserved. This program and the accompanying materials
4
4
 * are made available under the terms of the Eclipse Public License v1.0
5
5
 * which accompanies this distribution, and is available at
34
34
 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
35
35
 * 
36
36
 * @since 3.0
 
37
 * @noextend This class is not intended to be subclassed by clients.
37
38
 */
38
39
public class TrayItem extends Item {
39
40
        Tray parent;
150
151
 
151
152
void createHandle (int index) {
152
153
        state |= HANDLE;
153
 
        handle = OS.gtk_plug_new (0);
154
 
        if (handle == 0) error (SWT.ERROR_NO_HANDLES);
155
 
        imageHandle = OS.gtk_image_new ();
156
 
        if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
157
 
        OS.gtk_container_add (handle, imageHandle);
158
 
        OS.gtk_widget_show (handle);
159
 
        OS.gtk_widget_show (imageHandle);
160
 
        int /*long*/ id = OS.gtk_plug_get_id (handle);
161
 
        int monitor = 0;
162
 
        int /*long*/ screen = OS.gdk_screen_get_default ();
163
 
        if (screen != 0) {
164
 
                monitor = OS.gdk_screen_get_number (screen);
 
154
        if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
155
                handle = OS.gtk_status_icon_new ();
 
156
                if (handle == 0) error (SWT.ERROR_NO_HANDLES);
 
157
                imageHandle = OS.gtk_image_new ();
 
158
                OS.gtk_status_icon_set_visible (handle,true);
 
159
        } else {
 
160
                handle = OS.gtk_plug_new (0);
 
161
                if (handle == 0) error (SWT.ERROR_NO_HANDLES);
 
162
                imageHandle = OS.gtk_image_new ();
 
163
                if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
 
164
                OS.gtk_container_add (handle, imageHandle);
 
165
                OS.gtk_widget_show (handle);
 
166
                OS.gtk_widget_show (imageHandle);
 
167
                int /*long*/ id = OS.gtk_plug_get_id (handle);
 
168
                int monitor = 0;
 
169
                int /*long*/ screen = OS.gdk_screen_get_default ();
 
170
                if (screen != 0) {
 
171
                        monitor = OS.gdk_screen_get_number (screen);
 
172
                }
 
173
                byte [] trayBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_S" + monitor, true);
 
174
                int /*long*/ trayAtom = OS.gdk_atom_intern (trayBuffer, true);
 
175
                int /*long*/ xTrayAtom = OS.gdk_x11_atom_to_xatom (trayAtom);
 
176
                int /*long*/ xDisplay = OS.GDK_DISPLAY ();
 
177
                int /*long*/ trayWindow = OS.XGetSelectionOwner (xDisplay, xTrayAtom);
 
178
                byte [] messageBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_OPCODE", true);
 
179
                int /*long*/ messageAtom = OS.gdk_atom_intern (messageBuffer, true);
 
180
                int /*long*/ xMessageAtom = OS.gdk_x11_atom_to_xatom (messageAtom);
 
181
                XClientMessageEvent event = new XClientMessageEvent ();
 
182
                event.type = OS.ClientMessage;
 
183
                event.window = trayWindow;
 
184
                event.message_type = xMessageAtom;
 
185
                event.format = 32;
 
186
                event.data [0] = OS.GDK_CURRENT_TIME;
 
187
                event.data [1] = OS.SYSTEM_TRAY_REQUEST_DOCK;
 
188
                event.data [2] = id;
 
189
                int /*long*/ clientEvent = OS.g_malloc (XClientMessageEvent.sizeof);
 
190
                OS.memmove (clientEvent, event, XClientMessageEvent.sizeof);
 
191
                OS.XSendEvent (xDisplay, trayWindow, false, OS.NoEventMask, clientEvent);
 
192
                OS.g_free (clientEvent);
165
193
        }
166
 
        byte [] trayBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_S" + monitor, true);
167
 
        int /*long*/ trayAtom = OS.gdk_atom_intern (trayBuffer, true);
168
 
        int /*long*/ xTrayAtom = OS.gdk_x11_atom_to_xatom (trayAtom);
169
 
        int /*long*/ xDisplay = OS.GDK_DISPLAY ();
170
 
        int /*long*/ trayWindow = OS.XGetSelectionOwner (xDisplay, xTrayAtom);
171
 
        byte [] messageBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_OPCODE", true);
172
 
        int /*long*/ messageAtom = OS.gdk_atom_intern (messageBuffer, true);
173
 
        int /*long*/ xMessageAtom = OS.gdk_x11_atom_to_xatom (messageAtom);
174
 
        XClientMessageEvent event = new XClientMessageEvent ();
175
 
        event.type = OS.ClientMessage;
176
 
        event.window = trayWindow;
177
 
        event.message_type = xMessageAtom;
178
 
        event.format = 32;
179
 
        event.data [0] = OS.GDK_CURRENT_TIME;
180
 
        event.data [1] = OS.SYSTEM_TRAY_REQUEST_DOCK;
181
 
        event.data [2] = id;
182
 
        int /*long*/ clientEvent = OS.g_malloc (XClientMessageEvent.sizeof);
183
 
        OS.memmove (clientEvent, event, XClientMessageEvent.sizeof);
184
 
        OS.XSendEvent (xDisplay, trayWindow, false, OS.NoEventMask, clientEvent);
185
 
        OS.g_free (clientEvent);
186
194
}
187
195
 
188
196
void deregister () {
246
254
        return toolTipText;
247
255
}
248
256
 
 
257
int /*long*/ gtk_activate (int /*long*/ widget) {
 
258
        postEvent (SWT.Selection);
 
259
        /*
 
260
        * Feature in GTK. GTK will generate a single-click event before sending 
 
261
        * a double-click event. To know when to send a DefaultSelection, look for 
 
262
        * the single-click as the current event and for the double-click in the
 
263
        * event queue.
 
264
        */
 
265
        int /*long*/ nextEvent = OS.gdk_event_peek ();
 
266
        if (nextEvent != 0) {
 
267
                int nextEventType = OS.GDK_EVENT_TYPE (nextEvent);
 
268
                int /*long*/ currEvent = OS.gtk_get_current_event ();
 
269
                int currEventType = 0;
 
270
                if (currEvent != 0) {
 
271
                        currEventType = OS.GDK_EVENT_TYPE (currEvent);
 
272
                        OS.gdk_event_free (currEvent);
 
273
                }
 
274
                OS.gdk_event_free (nextEvent);
 
275
                if (currEventType == OS.GDK_BUTTON_PRESS && nextEventType == OS.GDK_2BUTTON_PRESS) {
 
276
                        postEvent (SWT.DefaultSelection);
 
277
                }
 
278
        }
 
279
        return 0;
 
280
}
 
281
 
249
282
int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
250
283
        GdkEventButton gdkEvent = new GdkEventButton ();
251
284
        OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
295
328
        return 0;
296
329
}
297
330
 
 
331
int /*long*/ gtk_status_icon_popup_menu (int /*long*/ widget, int /*long*/ button, int /*long*/ activate_time) {
 
332
        sendEvent (SWT.MenuDetect);
 
333
        return 0;
 
334
}
 
335
 
298
336
void hookEvents () {
299
 
        int eventMask = OS.GDK_BUTTON_PRESS_MASK;
300
 
        OS.gtk_widget_add_events (handle, eventMask);
301
 
        OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
302
 
        OS.g_signal_connect_closure_by_id (imageHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
303
 
 }
 
337
        if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
338
                OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
 
339
                OS.g_signal_connect_closure (handle, OS.popup_menu, display.closures [STATUS_ICON_POPUP_MENU], false);
 
340
        } else {
 
341
                int eventMask = OS.GDK_BUTTON_PRESS_MASK;
 
342
                OS.gtk_widget_add_events (handle, eventMask);
 
343
                OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
 
344
                OS.g_signal_connect_closure_by_id (imageHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
 
345
        }
 
346
}
304
347
 
305
348
/**
306
349
 * Returns <code>true</code> if the receiver is visible and 
315
358
 */
316
359
public boolean getVisible () {
317
360
        checkWidget ();
 
361
        if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
362
                return OS.gtk_status_icon_get_visible (handle);
 
363
        }
318
364
        return OS.GTK_WIDGET_VISIBLE (handle);
319
365
}
320
366
 
324
370
}
325
371
 
326
372
void releaseHandle () {
327
 
        if (handle != 0) OS.gtk_widget_destroy (handle);
 
373
        if (handle != 0) {
 
374
                if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
375
                        OS.g_object_unref (handle);
 
376
                } else {
 
377
                        OS.gtk_widget_destroy (handle);
 
378
                }
 
379
        }
328
380
        handle = imageHandle = 0;
329
381
        super.releaseHandle ();
330
382
        parent = null;
409
461
        if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
410
462
        this.image = image;
411
463
        if (image != null) {
412
 
                Rectangle rect = image.getBounds ();
413
 
                OS.gtk_widget_set_size_request (handle, rect.width, rect.height);
414
464
                if (imageList == null) imageList = new ImageList ();
415
465
                int imageIndex = imageList.indexOf (image);
416
466
                if (imageIndex == -1) {
419
469
                        imageList.put (imageIndex, image);
420
470
                }
421
471
                int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
422
 
                OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
423
 
                OS.gtk_widget_show (imageHandle);
 
472
                if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
473
                        OS.gtk_status_icon_set_from_pixbuf (handle, pixbuf);
 
474
                        OS.gtk_status_icon_set_visible (handle, true);
 
475
                } else {
 
476
                        Rectangle rect = image.getBounds ();
 
477
                        OS.gtk_widget_set_size_request (handle, rect.width, rect.height);
 
478
                        OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
 
479
                        OS.gtk_widget_show (imageHandle);
 
480
                }
424
481
        } else {
425
482
                OS.gtk_widget_set_size_request (handle, 1, 1);
426
 
                OS.gtk_image_set_from_pixbuf (imageHandle, 0);
427
 
                OS.gtk_widget_hide (imageHandle);
 
483
                if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
484
                        OS.gtk_status_icon_set_from_pixbuf (handle, 0);
 
485
                        OS.gtk_status_icon_set_visible (handle, false);
 
486
                } else {
 
487
                        OS.gtk_image_set_from_pixbuf (imageHandle, 0);
 
488
                        OS.gtk_widget_hide (imageHandle);
 
489
                }
428
490
        }
429
491
}
430
492
 
451
513
 
452
514
/**
453
515
 * Sets the receiver's tool tip text to the argument, which
454
 
 * may be null indicating that no tool tip text should be shown.
455
 
 *
456
 
 * @param value the new tool tip text (or null)
 
516
 * may be null indicating that the default tool tip for the 
 
517
 * control will be shown. For a control that has a default
 
518
 * tool tip, such as the Tree control on Windows, setting
 
519
 * the tool tip text to an empty string replaces the default,
 
520
 * causing no tool tip text to be shown.
 
521
 * <p>
 
522
 * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
 
523
 * To display a single '&amp;' in the tool tip, the character '&amp;' can be 
 
524
 * escaped by doubling it in the string.
 
525
 * </p>
 
526
 * 
 
527
 * @param string the new tool tip text (or null)
457
528
 *
458
529
 * @exception SWTException <ul>
459
530
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
473
544
                OS.g_object_ref (tooltipsHandle);
474
545
                OS.gtk_object_sink (tooltipsHandle);
475
546
        }
476
 
        OS.gtk_tooltips_set_tip (tooltipsHandle, handle, buffer, null);
 
547
        if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
548
                OS.gtk_status_icon_set_tooltip (handle, buffer);
 
549
        } else
 
550
                OS.gtk_tooltips_set_tip (tooltipsHandle, handle, buffer, null);
477
551
}
478
552
 
479
553
/**
489
563
 */
490
564
public void setVisible (boolean visible) {
491
565
        checkWidget ();
492
 
        if (OS.GTK_WIDGET_VISIBLE (handle) == visible) return;
 
566
        if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
567
                if(OS.gtk_status_icon_get_visible (handle) == visible) return;  
 
568
        } else {
 
569
                if (OS.GTK_WIDGET_VISIBLE (handle) == visible) return;
 
570
        }
493
571
        if (visible) {
494
572
                /*
495
573
                * It is possible (but unlikely), that application
498
576
                */
499
577
                sendEvent (SWT.Show);
500
578
                if (isDisposed ()) return;
501
 
                OS.gtk_widget_show (handle);
 
579
                if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
580
                        OS.gtk_status_icon_set_visible (handle, visible);
 
581
                } else
 
582
                        OS.gtk_widget_show (handle);
502
583
        } else {
503
 
                OS.gtk_widget_hide (handle);
 
584
                if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
 
585
                        OS.gtk_status_icon_set_visible (handle, visible);
 
586
                } else
 
587
                        OS.gtk_widget_hide (handle);
504
588
                sendEvent (SWT.Hide);
505
589
        }
506
590
}
507
 
}
 
591
}
 
 
b'\\ No newline at end of file'