comparison dwt/widgets/TrayItem.d @ 149:36ae710173d9

Selection is now working for TrayItems
author Jacob Carlborg <doob@me.com>
date Tue, 09 Jun 2009 21:05:40 +0200
parents c74ba20de292
children
comparison
equal deleted inserted replaced
148:8944c1d87c63 149:36ae710173d9
32 import dwt.internal.cocoa.OS; 32 import dwt.internal.cocoa.OS;
33 import dwt.internal.cocoa.SWTImageView; 33 import dwt.internal.cocoa.SWTImageView;
34 34
35 import dwt.dwthelper.utils; 35 import dwt.dwthelper.utils;
36 import dwt.internal.cocoa.NSView; 36 import dwt.internal.cocoa.NSView;
37 import Carbon = dwt.internal.c.Carbon;
37 import objc = dwt.internal.objc.runtime; 38 import objc = dwt.internal.objc.runtime;
38 import dwt.widgets.Item; 39 import dwt.widgets.Item;
39 import dwt.widgets.ToolTip; 40 import dwt.widgets.ToolTip;
40 import dwt.widgets.Tray; 41 import dwt.widgets.Tray;
41 import dwt.widgets.TypedListener; 42 import dwt.widgets.TypedListener;
65 String toolTipText; 66 String toolTipText;
66 bool visible = true, highlight; 67 bool visible = true, highlight;
67 NSStatusItem item; 68 NSStatusItem item;
68 NSImageView view; 69 NSImageView view;
69 70
70 static final float BORDER = 8f; 71 static const float BORDER = 8f;
71 72
72 /** 73 /**
73 * Constructs a new instance of this class given its parent 74 * Constructs a new instance of this class given its parent
74 * (which must be a <code>Tray</code>) and a style value 75 * (which must be a <code>Tray</code>) and a style value
75 * describing its behavior and appearance. The item is added 76 * describing its behavior and appearance. The item is added
361 public void setImage (Image image) { 362 public void setImage (Image image) {
362 checkWidget (); 363 checkWidget ();
363 if (image !is null && image.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); 364 if (image !is null && image.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT);
364 super.setImage (image); 365 super.setImage (image);
365 view.setImage(image !is null ? image.handle : null); 366 view.setImage(image !is null ? image.handle : null);
366 float /*double*/ width = image !is null && visible ? image.handle.size().width + BORDER : 0; 367 Carbon.CGFloat width = image !is null && visible ? image.handle.size().width + BORDER : 0;
367 item.setLength(width); 368 item.setLength(width);
368 } 369 }
369 370
370 /** 371 /**
371 * Sets the receiver's tool tip to the argument, which 372 * Sets the receiver's tool tip to the argument, which
428 if (visible) { 429 if (visible) {
429 sendEvent (DWT.Show); 430 sendEvent (DWT.Show);
430 if (isDisposed ()) return; 431 if (isDisposed ()) return;
431 } 432 }
432 this.visible = visible; 433 this.visible = visible;
433 float /*double*/ width = image !is null && visible ? image.handle.size().width + BORDER : 0; 434 Carbon.CGFloat width = image !is null && visible ? image.handle.size().width + BORDER : 0;
434 item.setLength(width); 435 item.setLength(width);
435 if (!visible) sendEvent (DWT.Hide); 436 if (!visible) sendEvent (DWT.Hide);
436 } 437 }
437 438
438 void showMenu () { 439 void showMenu () {
453 (cast(NSView)view).setNeedsDisplay(true); 454 (cast(NSView)view).setNeedsDisplay(true);
454 postEvent(nsEvent.clickCount() is 2 ? DWT.DefaultSelection : DWT.Selection); 455 postEvent(nsEvent.clickCount() is 2 ? DWT.DefaultSelection : DWT.Selection);
455 } 456 }
456 } 457 }
457 458
458 void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 459 void mouseUp(objc.id id, objc.SEL sel, objc.id theEvent) {
459 highlight = false; 460 highlight = false;
460 (cast(NSView)view).setNeedsDisplay(true); 461 (cast(NSView)view).setNeedsDisplay(true);
461 } 462 }
462 463
463 void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { 464 void rightMouseDown(objc.id id, objc.SEL sel, objc.id theEvent) {
464 showMenu(); 465 showMenu();
465 } 466 }
466 467
467 void drawRect(objc.id id, objc.SEL sel, NSRect rect) { 468 void drawRect(objc.id id, objc.SEL sel, NSRect rect) {
468 item.drawStatusBarBackgroundInRect(rect, highlight); 469 item.drawStatusBarBackgroundInRect(rect, highlight);