Mercurial > projects > dwt-addons
diff dwtx/jface/viewers/ColumnViewerToolTipSupport.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | ea8ff534f622 |
children | 5df4896124c7 |
line wrap: on
line diff
--- a/dwtx/jface/viewers/ColumnViewerToolTipSupport.d Mon May 19 13:41:06 2008 +0200 +++ b/dwtx/jface/viewers/ColumnViewerToolTipSupport.d Thu May 22 01:36:46 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * bugfix in: 195137, 198089 * Fredy Dobler <fredy@dobler.net> - bug 159600 * Brock Janiczak <brockj@tpg.com.au> - bug 182443 * Port to the D programming language: @@ -22,9 +23,9 @@ import dwtx.jface.viewers.CellLabelProvider; import dwtx.jface.viewers.StructuredSelection; -import dwt.DWT; import dwt.graphics.Image; import dwt.graphics.Point; +import dwt.widgets.Composite; import dwt.widgets.Event; import dwtx.jface.util.Policy; import dwtx.jface.window.DefaultToolTip; @@ -33,7 +34,8 @@ import dwt.dwthelper.utils; /** - * The ColumnViewerTooltipSupport is the class that provides tool tips for ColumnViewers. + * The ColumnViewerTooltipSupport is the class that provides tool tips for + * ColumnViewers. * * @since 3.3 * @@ -41,10 +43,8 @@ public class ColumnViewerToolTipSupport : DefaultToolTip { private ColumnViewer viewer; - private static const String LABEL_PROVIDER_KEY = Policy.JFACE - ~ "_LABEL_PROVIDER"; //$NON-NLS-1$ - - private static const String ELEMENT_KEY = Policy.JFACE ~ "_ELEMENT_KEY"; //$NON-NLS-1$ + private static const String VIEWER_CELL_KEY = Policy.JFACE + ~ "_VIEWER_CELL_KEY"; //$NON-NLS-1$ private static const int DEFAULT_SHIFT_X = 10; @@ -57,14 +57,16 @@ * * @param viewer * the viewer the support is attached to - * @param style style passed to control tool tip behavior + * @param style + * style passed to control tool tip behavior * * @param manualActivation * <code>true</code> if the activation is done manually using * {@link #show(Point)} */ - protected this(ColumnViewer viewer, int style, bool manualActivation ) { - super(viewer.getControl(),style,manualActivation); + protected this(ColumnViewer viewer, int style, + bool manualActivation) { + super(viewer.getControl(), style, manualActivation); this.viewer = viewer; } @@ -77,7 +79,7 @@ * the viewer the support is attached to */ public static void enableFor(ColumnViewer viewer) { - new ColumnViewerToolTipSupport(viewer,ToolTip.NO_RECREATE,false); + new ColumnViewerToolTipSupport(viewer, ToolTip.NO_RECREATE, false); } /** @@ -87,21 +89,57 @@ * * @param viewer * the viewer the support is attached to - * @param style style passed to control tool tip behavior + * @param style + * style passed to control tool tip behavior * * @see ToolTip#RECREATE * @see ToolTip#NO_RECREATE */ public static void enableFor(ColumnViewer viewer, int style) { - new ColumnViewerToolTipSupport(viewer,style,false); + new ColumnViewerToolTipSupport(viewer, style, false); } protected override Object getToolTipArea(Event event) { - return viewer.getCell(new Point(event.x,event.y)); + return viewer.getCell(new Point(event.x, event.y)); + } + + /** + * Instead of overwriting this method subclasses should overwrite + * {@link #createViewerToolTipContentArea(Event, ViewerCell, Composite)} + */ + protected Composite createToolTipContentArea(Event event, Composite parent) { + ViewerCell cell = (ViewerCell) getData(VIEWER_CELL_KEY); + setData(VIEWER_CELL_KEY, null); + + return createViewerToolTipContentArea(event, cell, parent); } - protected override final bool shouldCreateToolTip(Event event) { - if( ! super.shouldCreateToolTip(event) ) { + /** + * Creates the content area of the tool tip giving access to the cell the + * tip is shown for. Subclasses can overload this method to implement their + * own tool tip design. + * + * <p> + * This method is called from + * {@link #createToolTipContentArea(Event, Composite)} and by default calls + * the {@link DefaultToolTip#createToolTipContentArea(Event, Composite)}. + * </p> + * + * @param event + * the event that which + * @param cell + * the cell the tool tip is shown for + * @param parent + * the parent of the control to create + * @return the control to be displayed in the tool tip area + */ + protected Composite createViewerToolTipContentArea(Event event, + ViewerCell cell, Composite parent) { + return super.createToolTipContentArea(event, parent); + } + + protected override bool shouldCreateToolTip(Event event) { + if (!super.shouldCreateToolTip(event)) { return false; } @@ -115,8 +153,9 @@ if (row !is null) { Object element = row.getItem().getData(); - ViewerColumn viewPart = viewer.getViewerColumn(row - .getColumnIndex(point)); + ViewerCell cell = row.getCell(point); + ViewerColumn viewPart = viewer.getViewerColumn(cell + .getColumnIndex()); if (viewPart is null) { return false; @@ -128,11 +167,11 @@ String text = labelProvider.getToolTipText(element); Image img = null; - if( ! useNative ) { + if (!useNative) { img = labelProvider.getToolTipImage(element); } - if( useNative || (text is null && img is null ) ) { + if (useNative || (text is null && img is null)) { viewer.getControl().setToolTipText(text); rv = false; } else { @@ -147,14 +186,15 @@ setShift(new Point(shift.x, shift.y)); } - setData(LABEL_PROVIDER_KEY, labelProvider); - setData(ELEMENT_KEY, element); + setData(VIEWER_CELL_KEY, cell); setText(text); setImage(img); setStyle(labelProvider.getToolTipStyle(element)); - setForegroundColor(labelProvider.getToolTipForegroundColor(element)); - setBackgroundColor(labelProvider.getToolTipBackgroundColor(element)); + setForegroundColor(labelProvider + .getToolTipForegroundColor(element)); + setBackgroundColor(labelProvider + .getToolTipBackgroundColor(element)); setFont(labelProvider.getToolTipFont(element)); // Check if at least one of the values is set @@ -166,12 +206,11 @@ } protected override void afterHideToolTip(Event event) { + super.afterHideToolTip(event); + // Clear the restored value else this could be a source of a leak + setData(VIEWER_CELL_KEY, null); if (event !is null && event.widget !is viewer.getControl()) { - if (event.type is DWT.MouseDown) { - viewer.setSelection(new StructuredSelection()); - } else { - viewer.getControl().setFocus(); - } + viewer.getControl().setFocus(); } } }